1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
10 * argv2 = proxy with embedded user+password
18 char trace_ascii; /* 1 or 0 */
22 void dump(const char *text,
23 FILE *stream, unsigned char *ptr, size_t size,
29 unsigned int width=0x10;
32 /* without the hex output, we can fit more on screen */
35 fprintf(stream, "%s, %d bytes (0x%x)\n", text, (int)size, (int)size);
37 for(i=0; i<size; i+= width) {
39 fprintf(stream, "%04x: ", (int)i);
42 /* hex not disabled, show it */
43 for(c = 0; c < width; c++)
45 fprintf(stream, "%02x ", ptr[i+c]);
50 for(c = 0; (c < width) && (i+c < size); c++) {
51 /* check for 0D0A; if found, skip past and start a new line of output */
52 if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
57 (ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.');
58 /* check again for 0D0A, to avoid an extra \n if it's at width */
59 if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
64 fputc('\n', stream); /* newline */
70 int my_trace(CURL *handle, curl_infotype type,
71 char *data, size_t size,
74 struct data *config = (struct data *)userp;
76 (void)handle; /* prevent compiler warning */
80 fprintf(stderr, "== Info: %s", (char *)data);
81 default: /* in case a new one is introduced to shock us */
84 case CURLINFO_HEADER_OUT:
85 text = "=> Send header";
87 case CURLINFO_DATA_OUT:
88 text = "=> Send data";
90 case CURLINFO_SSL_DATA_OUT:
91 text = "=> Send SSL data";
93 case CURLINFO_HEADER_IN:
94 text = "<= Recv header";
96 case CURLINFO_DATA_IN:
97 text = "<= Recv data";
99 case CURLINFO_SSL_DATA_IN:
100 text = "<= Recv SSL data";
104 dump(text, stderr, (unsigned char *)data, size, config->trace_ascii);
109 static size_t current_offset = 0;
110 static char databuf[70000]; /* MUST be more than 64k OR MAX_INITIAL_POST_SIZE */
112 static size_t read_callback(void *ptr, size_t size, size_t nmemb, void *stream)
114 size_t amount = nmemb * size; /* Total bytes curl wants */
115 size_t available = sizeof(databuf) - current_offset; /* What we have to give */
116 size_t given = amount < available ? amount : available; /* What is given */
118 memcpy(ptr, databuf + current_offset, given);
119 current_offset += given;
124 static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *stream)
126 printf("%.*s", (int)(size * nmemb), (char *)ptr);
132 static curlioerr ioctl_callback(CURL * handle, int cmd, void *clientp)
135 if (cmd == CURLIOCMD_RESTARTREAD ) {
136 printf("APPLICATION: recieved a CURLIOCMD_RESTARTREAD request\n");
137 printf("APPLICATION: ** REWINDING! **\n");
142 return CURLIOE_UNKNOWNCMD;
150 CURLcode res = CURLE_OUT_OF_MEMORY;
153 static const char fill[] = "test data";
155 config.trace_ascii = 1; /* enable ascii tracing */
157 if((curl = curl_easy_init()) == NULL) {
158 fprintf(stderr, "curl_easy_init() failed\n");
159 curl_global_cleanup();
160 return TEST_ERR_MAJOR_BAD;
163 test_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
164 test_setopt(curl, CURLOPT_DEBUGDATA, &config);
165 /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
166 test_setopt(curl, CURLOPT_VERBOSE, 1L);
168 /* setup repeated data string */
169 for (i=0; i < sizeof(databuf); ++i)
170 databuf[i] = fill[i % sizeof fill];
173 test_setopt(curl, CURLOPT_POST, 1L);
175 #ifdef CURL_DOES_CONVERSIONS
176 /* Convert the POST data to ASCII */
177 test_setopt(curl, CURLOPT_TRANSFERTEXT, 1L);
180 /* Setup read callback */
181 test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
182 test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
185 test_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
188 test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
190 test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
192 test_setopt(curl, CURLOPT_URL, URL);
194 /* Accept any auth. But for this bug configure proxy with DIGEST, basic might work too, not NTLM */
195 test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
197 res = curl_easy_perform(curl);
198 fprintf(stderr, "curl_easy_perform = %d\n", (int)res);
202 curl_easy_cleanup(curl);
203 curl_global_cleanup();