2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2007-12-27 05:48:52 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2007-12-27 05:48:52 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
2016-11-23 14:53:24 +08:00
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2011-03-10 18:48:02 +08:00
|
|
|
***************************************************************************/
|
|
|
|
/* argv1 = URL
|
2007-12-27 05:48:52 +08:00
|
|
|
* argv2 = proxy with embedded user+password
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "warnless.h"
|
|
|
|
#include "memdebug.h"
|
2008-09-20 12:26:55 +08:00
|
|
|
|
2007-12-27 05:48:52 +08:00
|
|
|
struct data {
|
|
|
|
char trace_ascii; /* 1 or 0 */
|
|
|
|
};
|
|
|
|
|
|
|
|
static
|
|
|
|
void dump(const char *text,
|
|
|
|
FILE *stream, unsigned char *ptr, size_t size,
|
|
|
|
char nohex)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t c;
|
|
|
|
|
2017-09-10 05:09:06 +08:00
|
|
|
unsigned int width = 0x10;
|
2007-12-27 05:48:52 +08:00
|
|
|
|
|
|
|
if(nohex)
|
|
|
|
/* without the hex output, we can fit more on screen */
|
|
|
|
width = 0x40;
|
|
|
|
|
2018-05-07 03:20:32 +08:00
|
|
|
fprintf(stream, "%s, %zu bytes (0x%zx)\n", text, size, size);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2017-09-10 05:55:08 +08:00
|
|
|
for(i = 0; i<size; i += width) {
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2018-05-07 03:20:32 +08:00
|
|
|
fprintf(stream, "%04zx: ", i);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
|
|
|
if(!nohex) {
|
|
|
|
/* hex not disabled, show it */
|
|
|
|
for(c = 0; c < width; c++)
|
2017-09-10 05:55:08 +08:00
|
|
|
if(i + c < size)
|
|
|
|
fprintf(stream, "%02x ", ptr[i + c]);
|
2007-12-27 05:48:52 +08:00
|
|
|
else
|
|
|
|
fputs(" ", stream);
|
|
|
|
}
|
|
|
|
|
2017-09-10 05:55:08 +08:00
|
|
|
for(c = 0; (c < width) && (i + c < size); c++) {
|
2007-12-27 05:48:52 +08:00
|
|
|
/* check for 0D0A; if found, skip past and start a new line of output */
|
2017-09-10 05:55:08 +08:00
|
|
|
if(nohex && (i + c + 1 < size) && ptr[i + c] == 0x0D &&
|
|
|
|
ptr[i + c + 1] == 0x0A) {
|
|
|
|
i += (c + 2 - width);
|
2007-12-27 05:48:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fprintf(stream, "%c",
|
2017-09-10 05:55:08 +08:00
|
|
|
(ptr[i + c] >= 0x20) && (ptr[i + c]<0x80)? ptr[i + c] : '.');
|
2007-12-27 05:48:52 +08:00
|
|
|
/* check again for 0D0A, to avoid an extra \n if it's at width */
|
2017-09-10 05:55:08 +08:00
|
|
|
if(nohex && (i + c + 2 < size) && ptr[i + c + 1] == 0x0D &&
|
|
|
|
ptr[i + c + 2] == 0x0A) {
|
|
|
|
i += (c + 3 - width);
|
2007-12-27 05:48:52 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fputc('\n', stream); /* newline */
|
|
|
|
}
|
|
|
|
fflush(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int my_trace(CURL *handle, curl_infotype type,
|
2008-02-27 17:06:15 +08:00
|
|
|
char *data, size_t size,
|
2007-12-27 05:48:52 +08:00
|
|
|
void *userp)
|
|
|
|
{
|
|
|
|
struct data *config = (struct data *)userp;
|
|
|
|
const char *text;
|
|
|
|
(void)handle; /* prevent compiler warning */
|
|
|
|
|
2016-12-14 06:34:59 +08:00
|
|
|
switch(type) {
|
2007-12-27 05:48:52 +08:00
|
|
|
case CURLINFO_TEXT:
|
2008-01-04 23:39:06 +08:00
|
|
|
fprintf(stderr, "== Info: %s", (char *)data);
|
2007-12-27 05:48:52 +08:00
|
|
|
return 0;
|
|
|
|
case CURLINFO_HEADER_OUT:
|
|
|
|
text = "=> Send header";
|
|
|
|
break;
|
|
|
|
case CURLINFO_DATA_OUT:
|
|
|
|
text = "=> Send data";
|
|
|
|
break;
|
|
|
|
case CURLINFO_SSL_DATA_OUT:
|
|
|
|
text = "=> Send SSL data";
|
|
|
|
break;
|
|
|
|
case CURLINFO_HEADER_IN:
|
|
|
|
text = "<= Recv header";
|
|
|
|
break;
|
|
|
|
case CURLINFO_DATA_IN:
|
|
|
|
text = "<= Recv data";
|
|
|
|
break;
|
|
|
|
case CURLINFO_SSL_DATA_IN:
|
|
|
|
text = "<= Recv SSL data";
|
|
|
|
break;
|
2023-12-08 21:05:09 +08:00
|
|
|
default: /* in case a new one is introduced to shock us */
|
|
|
|
return 0;
|
2007-12-27 05:48:52 +08:00
|
|
|
}
|
|
|
|
|
2008-02-27 17:06:15 +08:00
|
|
|
dump(text, stderr, (unsigned char *)data, size, config->trace_ascii);
|
2007-12-27 05:48:52 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static size_t current_offset = 0;
|
2016-04-03 17:57:34 +08:00
|
|
|
static char databuf[70000]; /* MUST be more than 64k OR
|
|
|
|
MAX_INITIAL_POST_SIZE */
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2020-12-31 00:01:47 +08:00
|
|
|
static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
|
2007-12-27 05:48:52 +08:00
|
|
|
{
|
|
|
|
size_t amount = nmemb * size; /* Total bytes curl wants */
|
2016-04-03 17:57:34 +08:00
|
|
|
size_t available = sizeof(databuf) - current_offset; /* What we have to
|
|
|
|
give */
|
2007-12-27 05:48:52 +08:00
|
|
|
size_t given = amount < available ? amount : available; /* What is given */
|
|
|
|
(void)stream;
|
2008-09-19 03:02:40 +08:00
|
|
|
memcpy(ptr, databuf + current_offset, given);
|
2007-12-27 05:48:52 +08:00
|
|
|
current_offset += given;
|
|
|
|
return given;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-03 17:57:34 +08:00
|
|
|
static size_t write_callback(void *ptr, size_t size, size_t nmemb,
|
|
|
|
void *stream)
|
2007-12-27 05:48:52 +08:00
|
|
|
{
|
2012-03-22 09:40:19 +08:00
|
|
|
int amount = curlx_uztosi(size * nmemb);
|
|
|
|
printf("%.*s", amount, (char *)ptr);
|
2007-12-27 05:48:52 +08:00
|
|
|
(void)stream;
|
|
|
|
return size * nmemb;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-23 14:53:24 +08:00
|
|
|
static curlioerr ioctl_callback(CURL *handle, int cmd, void *clientp)
|
2007-12-27 05:48:52 +08:00
|
|
|
{
|
|
|
|
(void)clientp;
|
2016-04-04 02:28:34 +08:00
|
|
|
if(cmd == CURLIOCMD_RESTARTREAD) {
|
2021-10-27 15:35:28 +08:00
|
|
|
printf("APPLICATION received a CURLIOCMD_RESTARTREAD request\n");
|
|
|
|
printf("APPLICATION ** REWINDING! **\n");
|
2007-12-27 05:48:52 +08:00
|
|
|
current_offset = 0;
|
|
|
|
return CURLIOE_OK;
|
|
|
|
}
|
|
|
|
(void)handle;
|
|
|
|
return CURLIOE_UNKNOWNCMD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-05-12 03:36:05 +08:00
|
|
|
CURLcode test(char *URL)
|
2007-12-27 05:48:52 +08:00
|
|
|
{
|
|
|
|
CURL *curl;
|
2017-08-20 03:27:38 +08:00
|
|
|
CURLcode res = CURLE_OK;
|
2007-12-27 05:48:52 +08:00
|
|
|
struct data config;
|
|
|
|
size_t i;
|
2008-07-12 02:23:06 +08:00
|
|
|
static const char fill[] = "test data";
|
2007-12-27 05:48:52 +08:00
|
|
|
|
|
|
|
config.trace_ascii = 1; /* enable ascii tracing */
|
|
|
|
|
2017-08-20 03:27:38 +08:00
|
|
|
global_init(CURL_GLOBAL_ALL);
|
|
|
|
easy_init(curl);
|
2010-02-06 02:07:19 +08:00
|
|
|
|
|
|
|
test_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
|
|
|
|
test_setopt(curl, CURLOPT_DEBUGDATA, &config);
|
|
|
|
/* the DEBUGFUNCTION has no effect until we enable VERBOSE */
|
|
|
|
test_setopt(curl, CURLOPT_VERBOSE, 1L);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
/* setup repeated data string */
|
2017-09-10 05:09:06 +08:00
|
|
|
for(i = 0; i < sizeof(databuf); ++i)
|
2018-05-12 05:40:58 +08:00
|
|
|
databuf[i] = fill[i % sizeof(fill)];
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
/* Post */
|
|
|
|
test_setopt(curl, CURLOPT_POST, 1L);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
/* Setup read callback */
|
|
|
|
test_setopt(curl, CURLOPT_POSTFIELDSIZE, (long) sizeof(databuf));
|
|
|
|
test_setopt(curl, CURLOPT_READFUNCTION, read_callback);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
/* Write callback */
|
|
|
|
test_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
/* Ioctl function */
|
2022-11-14 22:21:34 +08:00
|
|
|
CURL_IGNORE_DEPRECATION(
|
|
|
|
test_setopt(curl, CURLOPT_IOCTLFUNCTION, ioctl_callback);
|
|
|
|
)
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
test_setopt(curl, CURLOPT_PROXY, libtest_arg2);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
test_setopt(curl, CURLOPT_URL, URL);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2016-04-03 17:57:34 +08:00
|
|
|
/* Accept any auth. But for this bug configure proxy with DIGEST, basic
|
|
|
|
might work too, not NTLM */
|
2010-02-06 02:07:19 +08:00
|
|
|
test_setopt(curl, CURLOPT_PROXYAUTH, (long)CURLAUTH_ANY);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
res = curl_easy_perform(curl);
|
2007-12-27 05:48:52 +08:00
|
|
|
|
2010-02-06 02:07:19 +08:00
|
|
|
test_cleanup:
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
2008-07-12 02:23:06 +08:00
|
|
|
curl_global_cleanup();
|
2024-05-12 03:36:05 +08:00
|
|
|
return res;
|
2007-12-27 05:48:52 +08:00
|
|
|
}
|