Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / tests / libtest / lib547.c
blobf375ed309d58f52964c417c44eb864b0686200c2
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: lib547.c,v 1.1.1.1 2008-09-23 16:32:06 hoffman Exp $
10 * argv1 = URL
11 * argv2 = proxy
12 * argv3 = proxyuser:password
15 #include "test.h"
17 #define UPLOADTHIS "this is the blurb we want to upload\n"
19 #ifndef LIB548
20 static size_t readcallback(void *ptr,
21 size_t size,
22 size_t nmemb,
23 void *clientp)
25 int *counter = (int *)clientp;
27 if(*counter) {
28 /* only do this once and then require a clearing of this */
29 fprintf(stderr, "READ ALREADY DONE!\n");
30 return 0;
32 (*counter)++; /* bump */
34 if(size * nmemb > strlen(UPLOADTHIS)) {
35 fprintf(stderr, "READ!\n");
36 strcpy(ptr, UPLOADTHIS);
37 return strlen(UPLOADTHIS);
39 fprintf(stderr, "READ NOT FINE!\n");
40 return 0;
42 static curlioerr ioctlcallback(CURL *handle,
43 int cmd,
44 void *clientp)
46 int *counter = (int *)clientp;
47 (void)handle; /* unused */
48 if(cmd == CURLIOCMD_RESTARTREAD) {
49 fprintf(stderr, "REWIND!\n");
50 *counter = 0; /* clear counter to make the read callback restart */
52 return CURLIOE_OK;
57 #endif
59 int test(char *URL)
61 CURLcode res;
62 CURL *curl;
63 #ifndef LIB548
64 int counter=0;
65 #endif
67 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
68 fprintf(stderr, "curl_global_init() failed\n");
69 return TEST_ERR_MAJOR_BAD;
72 if ((curl = curl_easy_init()) == NULL) {
73 fprintf(stderr, "curl_easy_init() failed\n");
74 curl_global_cleanup();
75 return TEST_ERR_MAJOR_BAD;
78 curl_easy_setopt(curl, CURLOPT_URL, URL);
79 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
80 curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
81 #ifdef LIB548
82 /* set the data to POST with a mere pointer to a zero-terminated string */
83 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
84 #else
85 /* 547 style, which means reading the POST data from a callback */
86 curl_easy_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
87 curl_easy_setopt(curl, CURLOPT_IOCTLDATA, &counter);
88 curl_easy_setopt(curl, CURLOPT_READFUNCTION, readcallback);
89 curl_easy_setopt(curl, CURLOPT_READDATA, &counter);
90 /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
91 curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
92 #endif
93 curl_easy_setopt(curl, CURLOPT_POST, 1L);
94 curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
95 curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
96 curl_easy_setopt(curl, CURLOPT_PROXYAUTH,
97 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
99 res = curl_easy_perform(curl);
101 curl_easy_cleanup(curl);
102 curl_global_cleanup();
104 return (int)res;