#include "memdebug.h" /* keep this as LAST include */
-static void dump(const char *timebuf, const char *text,
+static void dump(const char *timebuf, const char *idsbuf, const char *text,
FILE *stream, const unsigned char *ptr, size_t size,
trace tracetype, curl_infotype infotype);
return hms_buf;
}
-static void log_line_start(FILE *log, const char *intro, curl_infotype type)
+static void log_line_start(FILE *log, const char *timebuf,
+ const char *idsbuf, curl_infotype type)
{
/*
* This is the trace look that is similar to what libcurl makes on its
static const char * const s_infotype[] = {
"* ", "< ", "> ", "{ ", "} ", "{ ", "} "
};
- if(intro && *intro)
- fprintf(log, "%s%s", intro, s_infotype[type]);
+ if((timebuf && *timebuf) || (idsbuf && *idsbuf))
+ fprintf(log, "%s%s%s", timebuf, idsbuf, s_infotype[type]);
else
fputs(s_infotype[type], log);
}
+#define TRC_IDS_FORMAT_IDS_1 "[%" CURL_FORMAT_CURL_OFF_T "-x] "
+#define TRC_IDS_FORMAT_IDS_2 "[%" CURL_FORMAT_CURL_OFF_T "-%" \
+ CURL_FORMAT_CURL_OFF_T "] "
/*
** callback for CURLOPT_DEBUGFUNCTION
*/
const char *text;
struct timeval tv;
char timebuf[20];
+ /* largest signed 64bit is: 9,223,372,036,854,775,807
+ * max length in decimal: 1 + (6*3) = 19
+ * formatted via TRC_IDS_FORMAT_IDS_2 this becomes 2 + 19 + 1 + 19 + 2 = 43
+ * negative xfer-id are not printed, negative conn-ids use TRC_IDS_FORMAT_1
+ */
+ char idsbuf[60];
+ curl_off_t xfer_id, conn_id;
(void)handle; /* not used */
else
timebuf[0] = 0;
+ if(handle && config->traceids &&
+ !curl_easy_getinfo(handle, CURLINFO_XFER_ID, &xfer_id) && xfer_id >= 0) {
+ if(!curl_easy_getinfo(handle, CURLINFO_CONN_ID, &conn_id) &&
+ conn_id >= 0) {
+ msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_2,
+ xfer_id, conn_id);
+ }
+ else {
+ msnprintf(idsbuf, sizeof(idsbuf), TRC_IDS_FORMAT_IDS_1, xfer_id);
+ }
+ }
+ else
+ idsbuf[0] = 0;
+
if(!config->trace_stream) {
/* open for append */
if(!strcmp("-", config->trace_dump))
for(i = 0; i < size - 1; i++) {
if(data[i] == '\n') { /* LF */
if(!newl) {
- log_line_start(output, timebuf, type);
+ log_line_start(output, timebuf, idsbuf, type);
}
(void)fwrite(data + st, i - st + 1, 1, output);
st = i + 1;
}
}
if(!newl)
- log_line_start(output, timebuf, type);
+ log_line_start(output, timebuf, idsbuf, type);
(void)fwrite(data + st, i - st + 1, 1, output);
}
newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
case CURLINFO_TEXT:
case CURLINFO_HEADER_IN:
if(!newl)
- log_line_start(output, timebuf, type);
+ log_line_start(output, timebuf, idsbuf, type);
(void)fwrite(data, size, 1, output);
newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
traced_data = FALSE;
function */
if(!config->isatty || ((output != stderr) && (output != stdout))) {
if(!newl)
- log_line_start(output, timebuf, type);
+ log_line_start(output, timebuf, idsbuf, type);
fprintf(output, "[%zu bytes data]\n", size);
newl = FALSE;
traced_data = TRUE;
switch(type) {
case CURLINFO_TEXT:
- fprintf(output, "%s== Info: %.*s", timebuf, (int)size, data);
+ fprintf(output, "%s%s== Info: %.*s", timebuf, idsbuf, (int)size, data);
/* FALLTHROUGH */
default: /* in case a new one is introduced to shock us */
return 0;
break;
}
- dump(timebuf, text, output, (unsigned char *) data, size, config->tracetype,
- type);
+ dump(timebuf, idsbuf, text, output, (unsigned char *) data, size,
+ config->tracetype, type);
return 0;
}
-static void dump(const char *timebuf, const char *text,
+static void dump(const char *timebuf, const char *idsbuf, const char *text,
FILE *stream, const unsigned char *ptr, size_t size,
trace tracetype, curl_infotype infotype)
{
/* without the hex output, we can fit more on screen */
width = 0x40;
- fprintf(stream, "%s%s, %zu bytes (0x%zx)\n", timebuf, text, size, size);
+ fprintf(stream, "%s%s%s, %zu bytes (0x%zx)\n", timebuf, idsbuf,
+ text, size, size);
for(i = 0; i < size; i += width) {