24 #define ENABLE_CURLX_PRINTF 36 static void dump(
const char *timebuf,
const char *text,
37 FILE *stream,
const unsigned char *
ptr,
size_t size,
64 epoch_offset = time(NULL) - tv.
tv_sec;
67 secs = epoch_offset + tv.
tv_sec;
68 now = localtime(&secs);
69 snprintf(timebuf,
sizeof(timebuf),
"%02d:%02d:%02d.%06ld ",
70 now->tm_hour, now->tm_min, now->tm_sec, (
long)tv.
tv_usec);
92 warnf(config,
"Failed to create/open output");
101 static const char *
const s_infotype[] = {
102 "*",
"<",
">",
"{",
"}",
"{",
"}" 106 static bool newl =
FALSE;
107 static bool traced_data =
FALSE;
112 for(i = 0; i < size - 1; i++) {
113 if(data[i] ==
'\n') {
115 fprintf(output,
"%s%s ", timebuf, s_infotype[type]);
117 (void)
fwrite(data + st, i - st + 1, 1, output);
123 fprintf(output,
"%s%s ", timebuf, s_infotype[type]);
124 (void)
fwrite(data + st, i - st + 1, 1, output);
126 newl = (size && (data[size - 1] !=
'\n')) ?
TRUE :
FALSE;
132 fprintf(output,
"%s%s ", timebuf, s_infotype[type]);
133 (void)
fwrite(data, size, 1, output);
134 newl = (size && (data[size - 1] !=
'\n')) ?
TRUE :
FALSE;
146 if(!config->
isatty || ((output != stderr) && (output != stdout))) {
148 fprintf(output,
"%s%s ", timebuf, s_infotype[type]);
149 fprintf(output,
"[%zd bytes data]\n", size);
164 #ifdef CURL_DOES_CONVERSIONS 171 for(i = 0; i < size - 4; i++) {
172 if(memcmp(&data[i],
"\r\n\r\n", 4) == 0) {
174 text =
"=> Send header";
175 dump(timebuf, text, output, (
unsigned char *)data, i + 4,
189 fprintf(output,
"%s== Info: %s", timebuf, data);
195 text =
"=> Send header";
198 text =
"=> Send data";
201 text =
"<= Recv header";
204 text =
"<= Recv data";
207 text =
"<= Recv SSL data";
210 text =
"=> Send SSL data";
214 dump(timebuf, text, output, (
unsigned char *) data, size, config->
tracetype,
219 static void dump(
const char *timebuf,
const char *text,
220 FILE *stream,
const unsigned char *
ptr,
size_t size,
226 unsigned int width = 0x10;
232 fprintf(stream,
"%s%s, %zd bytes (0x%zx)\n", timebuf, text, size, size);
240 for(c = 0; c <
width; c++)
242 fprintf(stream,
"%02x ", ptr[i + c]);
247 for(c = 0; (c <
width) && (i + c < size); c++) {
250 (i + c + 1 <
size) && (ptr[i + c] == 0x0D) &&
251 (ptr[i + c + 1] == 0x0A)) {
252 i += (c + 2 -
width);
255 #ifdef CURL_DOES_CONVERSIONS 258 (i + c + 1 <
size) && (ptr[i + c] ==
'\r') &&
259 (ptr[i + c + 1] ==
'\n')) {
260 i += (c + 2 -
width);
264 fprintf(stream,
"%c", convert_char(infotype, ptr[i + c]));
267 fprintf(stream,
"%c", ((ptr[i + c] >= 0x20) && (ptr[i + c] < 0x80)) ?
272 (i + c + 2 < size) && (ptr[i + c + 1] == 0x0D) &&
273 (ptr[i + c + 2] == 0x0A)) {
274 i += (c + 3 -
width);
static struct timeval tvnow(void)
UNITTEST_START char * ptr
struct GlobalConfig * global
static time_t epoch_offset
UNITTEST_START char * output