1
/*****************************************************************************
3
* Project ___| | | | _ \| |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
8
* $Id: debug.c,v 1.1 2004/08/23 14:22:26 bagder Exp $
12
#include <curl/curl.h>
15
char trace_ascii; /* 1 or 0 */
19
void dump(const char *text,
20
FILE *stream, unsigned char *ptr, size_t size,
26
unsigned int width=0x10;
29
/* without the hex output, we can fit more on screen */
32
fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size);
34
for(i=0; i<size; i+= width) {
36
fprintf(stream, "%04zx: ", i);
39
/* hex not disabled, show it */
40
for(c = 0; c < width; c++)
42
fprintf(stream, "%02x ", ptr[i+c]);
47
for(c = 0; (c < width) && (i+c < size); c++) {
48
/* check for 0D0A; if found, skip past and start a new line of output */
49
if (nohex && (i+c+1 < size) && ptr[i+c]==0x0D && ptr[i+c+1]==0x0A) {
54
(ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.');
55
/* check again for 0D0A, to avoid an extra \n if it's at width */
56
if (nohex && (i+c+2 < size) && ptr[i+c+1]==0x0D && ptr[i+c+2]==0x0A) {
61
fputc('\n', stream); /* newline */
67
int my_trace(CURL *handle, curl_infotype type,
68
unsigned char *data, size_t size,
71
struct data *config = (struct data *)userp;
73
(void)handle; /* prevent compiler warning */
77
fprintf(stderr, "== Info: %s", data);
78
default: /* in case a new one is introduced to shock us */
81
case CURLINFO_HEADER_OUT:
82
text = "=> Send header";
84
case CURLINFO_DATA_OUT:
85
text = "=> Send data";
87
case CURLINFO_HEADER_IN:
88
text = "<= Recv header";
90
case CURLINFO_DATA_IN:
91
text = "<= Recv data";
93
case CURLINFO_SSL_DATA_IN:
94
text = "<= Recv SSL data";
96
case CURLINFO_SSL_DATA_OUT:
97
text = "<= Send SSL data";
101
dump(text, stderr, data, size, config->trace_ascii);
111
config.trace_ascii = 1; /* enable ascii tracing */
113
curl = curl_easy_init();
115
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
116
curl_easy_setopt(curl, CURLOPT_DEBUGDATA, &config);
118
/* the DEBUGFUNCTION has no effect until we enable VERBOSE */
119
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
121
curl_easy_setopt(curl, CURLOPT_URL, "curl.haxx.se");
122
res = curl_easy_perform(curl);
125
curl_easy_cleanup(curl);