1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
11 #include <curl/curl.h>
14 char trace_ascii; /* 1 or 0 */
18 void dump(const char *text,
19 FILE *stream, unsigned char *ptr, size_t size,
25 unsigned int width=0x10;
28 /* without the hex output, we can fit more on screen */
31 fprintf(stream, "%s, %010.10ld bytes (0x%08.8lx)\n",
32 text, (long)size, (long)size);
34 for(i=0; i<size; i+= width) {
36 fprintf(stream, "%04.4lx: ", (long)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 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_SSL_DATA_OUT:
88 text = "=> Send SSL data";
90 case CURLINFO_HEADER_IN:
91 text = "<= Recv header";
93 case CURLINFO_DATA_IN:
94 text = "<= Recv data";
96 case CURLINFO_SSL_DATA_IN:
97 text = "<= Recv SSL data";
101 dump(text, stderr, (unsigned char *)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, 1L);
121 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
122 res = curl_easy_perform(curl);
125 curl_easy_cleanup(curl);