1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
11 * argv3 = proxyuser:password
18 #ifdef CURL_DOES_CONVERSIONS
19 /* ASCII representation with escape sequences for non-ASCII platforms */
20 # define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \
21 "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \
22 "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a"
24 # define UPLOADTHIS "this is the blurb we want to upload\n"
28 static size_t readcallback(void *ptr,
33 int *counter = (int *)clientp;
36 /* only do this once and then require a clearing of this */
37 fprintf(stderr, "READ ALREADY DONE!\n");
40 (*counter)++; /* bump */
42 if(size * nmemb > strlen(UPLOADTHIS)) {
43 fprintf(stderr, "READ!\n");
44 strcpy(ptr, UPLOADTHIS);
45 return strlen(UPLOADTHIS);
47 fprintf(stderr, "READ NOT FINE!\n");
50 static curlioerr ioctlcallback(CURL *handle,
54 int *counter = (int *)clientp;
55 (void)handle; /* unused */
56 if(cmd == CURLIOCMD_RESTARTREAD) {
57 fprintf(stderr, "REWIND!\n");
58 *counter = 0; /* clear counter to make the read callback restart */
75 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
76 fprintf(stderr, "curl_global_init() failed\n");
77 return TEST_ERR_MAJOR_BAD;
80 if ((curl = curl_easy_init()) == NULL) {
81 fprintf(stderr, "curl_easy_init() failed\n");
82 curl_global_cleanup();
83 return TEST_ERR_MAJOR_BAD;
86 test_setopt(curl, CURLOPT_URL, URL);
87 test_setopt(curl, CURLOPT_VERBOSE, 1L);
88 test_setopt(curl, CURLOPT_HEADER, 1L);
90 /* set the data to POST with a mere pointer to a zero-terminated string */
91 test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
93 /* 547 style, which means reading the POST data from a callback */
94 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
95 test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
96 test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
97 test_setopt(curl, CURLOPT_READDATA, &counter);
98 /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
99 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
101 test_setopt(curl, CURLOPT_POST, 1L);
102 test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
103 test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
104 test_setopt(curl, CURLOPT_PROXYAUTH,
105 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
107 res = curl_easy_perform(curl);
111 curl_easy_cleanup(curl);
112 curl_global_cleanup();