1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 * argv3 = proxyuser:password
31 #ifdef CURL_DOES_CONVERSIONS
32 /* ASCII representation with escape sequences for non-ASCII platforms */
33 # define UPLOADTHIS "\x74\x68\x69\x73\x20\x69\x73\x20\x74\x68\x65\x20\x62" \
34 "\x6c\x75\x72\x62\x20\x77\x65\x20\x77\x61\x6e\x74\x20" \
35 "\x74\x6f\x20\x75\x70\x6c\x6f\x61\x64\x0a"
37 # define UPLOADTHIS "this is the blurb we want to upload\n"
41 static size_t readcallback(void *ptr,
46 int *counter = (int *)clientp;
49 /* only do this once and then require a clearing of this */
50 fprintf(stderr, "READ ALREADY DONE!\n");
53 (*counter)++; /* bump */
55 if(size * nmemb > strlen(UPLOADTHIS)) {
56 fprintf(stderr, "READ!\n");
57 strcpy(ptr, UPLOADTHIS);
58 return strlen(UPLOADTHIS);
60 fprintf(stderr, "READ NOT FINE!\n");
63 static curlioerr ioctlcallback(CURL *handle,
67 int *counter = (int *)clientp;
68 (void)handle; /* unused */
69 if(cmd == CURLIOCMD_RESTARTREAD) {
70 fprintf(stderr, "REWIND!\n");
71 *counter = 0; /* clear counter to make the read callback restart */
88 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
89 fprintf(stderr, "curl_global_init() failed\n");
90 return TEST_ERR_MAJOR_BAD;
93 if ((curl = curl_easy_init()) == NULL) {
94 fprintf(stderr, "curl_easy_init() failed\n");
95 curl_global_cleanup();
96 return TEST_ERR_MAJOR_BAD;
99 test_setopt(curl, CURLOPT_URL, URL);
100 test_setopt(curl, CURLOPT_VERBOSE, 1L);
101 test_setopt(curl, CURLOPT_HEADER, 1L);
103 /* set the data to POST with a mere pointer to a zero-terminated string */
104 test_setopt(curl, CURLOPT_POSTFIELDS, UPLOADTHIS);
106 /* 547 style, which means reading the POST data from a callback */
107 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctlcallback);
108 test_setopt(curl, CURLOPT_IOCTLDATA, &counter);
109 test_setopt(curl, CURLOPT_READFUNCTION, readcallback);
110 test_setopt(curl, CURLOPT_READDATA, &counter);
111 /* We CANNOT do the POST fine without setting the size (or choose chunked)! */
112 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(UPLOADTHIS));
114 test_setopt(curl, CURLOPT_POST, 1L);
115 test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
116 test_setopt(curl, CURLOPT_PROXYUSERPWD, libtest_arg3);
117 test_setopt(curl, CURLOPT_PROXYAUTH,
118 (long) (CURLAUTH_NTLM | CURLAUTH_DIGEST | CURLAUTH_BASIC) );
120 res = curl_easy_perform(curl);
124 curl_easy_cleanup(curl);
125 curl_global_cleanup();