1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2016, 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 ***************************************************************************/
23 * argv2 = proxy with embedded user+password
32 char trace_ascii; /* 1 or 0 */
36 void dump(const char *text,
37 FILE *stream, unsigned char *ptr, size_t size,
43 unsigned int width=0x10;
46 /* without the hex output, we can fit more on screen */
49 fprintf(stream, "%s, %d bytes (0x%x)\n", text, (int)size, (int)size);
51 for(i=0; i<size; i+= width) {
53 fprintf(stream, "%04x: ", (int)i);
56 /* hex not disabled, show it */
57 for(c = 0; c < width; c++)
59 fprintf(stream, "%02x ", ptr[i+c]);
64 for(c = 0; (c < width) && (i+c < size); c++) {
65 /* check for 0D0A; if found, skip past and start a new line of output */
66 if(nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
71 (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.');
72 /* check again for 0D0A, to avoid an extra \n if it's at width */
73 if(nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
78 fputc('\n', stream); /* newline */
84 int my_trace(CURL *handle, curl_infotype type,
85 char *data, size_t size,
88 struct data *config = (struct data *)userp;
90 (void)handle; /* prevent compiler warning */
94 fprintf(stderr, "== Info: %s", (char *)data);
95 default: /* in case a new one is introduced to shock us */
98 case CURLINFO_HEADER_OUT:
99 text = "=> Send header";
101 case CURLINFO_DATA_OUT:
102 text = "=> Send data";
104 case CURLINFO_SSL_DATA_OUT:
105 text = "=> Send SSL data";
107 case CURLINFO_HEADER_IN:
108 text = "<= Recv header";
110 case CURLINFO_DATA_IN:
111 text = "<= Recv data";
113 case CURLINFO_SSL_DATA_IN:
114 text = "<= Recv SSL data";
118 dump(text, stderr, (unsigned char *)data, size, config->trace_ascii);
123 static size_t current_offset = 0;
124 static char databuf[70000]; /* MUST be more than 64k OR
125 MAX_INITIAL_POST_SIZE */
127 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
129 size_t amount = nmemb * size; /* Total bytes curl wants */
130 size_t available = sizeof(databuf) - current_offset; /* What we have to
132 size_t given = amount < available ? amount : available; /* What is given */
134 memcpy(ptr, databuf + current_offset, given);
135 current_offset += given;
140 static size_t write_callback(void *ptr, size_t size, size_t nmemb,
143 int amount = curlx_uztosi(size * nmemb);
144 printf("%.*s", amount, (char *)ptr);
150 static curlioerr ioctl_callback(CURL * handle, int cmd, void *clientp)
153 if(cmd == CURLIOCMD_RESTARTREAD) {
154 printf("APPLICATION: recieved a CURLIOCMD_RESTARTREAD request\n");
155 printf("APPLICATION: ** REWINDING! **\n");
160 return CURLIOE_UNKNOWNCMD;
168 CURLcode res = CURLE_OUT_OF_MEMORY;
171 static const char fill[] = "test data";
173 config.trace_ascii = 1; /* enable ascii tracing */
175 if((curl = curl_easy_init()) == NULL) {
176 fprintf(stderr, "curl_easy_init() failed\n");
177 curl_global_cleanup();
178 return TEST_ERR_MAJOR_BAD;
181 test_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
182 test_setopt(curl, CURLOPT_DEBUGDATA, &config);
183 /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
184 test_setopt(curl, CURLOPT_VERBOSE, 1L);
186 /* setup repeated data string */
187 for(i=0; i < sizeof(databuf); ++i)
188 databuf[i] = fill[i % sizeof fill];
191 test_setopt(curl, CURLOPT_POST, 1L);
193 #ifdef CURL_DOES_CONVERSIONS
194 /* Convert the POST data to ASCII */
195 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
198 /* Setup read callback */
199 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
200 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
203 test_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
206 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
208 test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
210 test_setopt(curl, CURLOPT_URL, URL);
212 /* Accept any auth. But for this bug configure proxy with DIGEST, basic
213 might work too, not NTLM */
214 test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
216 res = curl_easy_perform(curl);
217 fprintf(stderr, "curl_easy_perform = %d\n", (int)res);
221 curl_easy_cleanup(curl);
222 curl_global_cleanup();