1 .\" **************************************************************************
3 .\" * Project ___| | | | _ \| |
4 .\" * / __| | | | |_) | |
5 .\" * | (__| |_| | _ <| |___
6 .\" * \___|\___/|_| \_\_____|
8 .\" * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
10 .\" * This software is licensed as described in the file COPYING, which
11 .\" * you should have received as part of this distribution. The terms
12 .\" * are also available at https://curl.haxx.se/docs/copyright.html.
14 .\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 .\" * copies of the Software, and permit persons to whom the Software is
16 .\" * furnished to do so, under the terms of the COPYING file.
18 .\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 .\" * KIND, either express or implied.
21 .\" **************************************************************************
23 .TH CURLOPT_DEBUGFUNCTION 3 "October 06, 2016" "libcurl 7.59.0" "curl_easy_setopt options"
26 CURLOPT_DEBUGFUNCTION \- debug callback
29 #include <curl/curl.h>
33 CURLINFO_HEADER_IN, /* 1 */
34 CURLINFO_HEADER_OUT, /* 2 */
35 CURLINFO_DATA_IN, /* 3 */
36 CURLINFO_DATA_OUT, /* 4 */
37 CURLINFO_SSL_DATA_IN, /* 5 */
38 CURLINFO_SSL_DATA_OUT, /* 6 */
42 int debug_callback(CURL *handle,
48 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
51 Pass a pointer to your callback function, which should match the prototype
54 \fICURLOPT_DEBUGFUNCTION(3)\fP replaces the standard debug function used when
55 \fICURLOPT_VERBOSE(3)\fP is in effect. This callback receives debug
56 information, as specified in the \fItype\fP argument. This function must
57 return 0. The \fIdata\fP pointed to by the char * passed to this function WILL
58 NOT be zero terminated, but will be exactly of the \fIsize\fP as told by the
61 The \fIuserptr\fP argument is the pointer set with \fICURLOPT_DEBUGDATA(3)\fP.
63 Available curl_infotype values:
65 The data is informational text.
66 .IP CURLINFO_HEADER_IN
67 The data is header (or header-like) data received from the peer.
68 .IP CURLINFO_HEADER_OUT
69 The data is header (or header-like) data sent to the peer.
71 The data is protocol data received from the peer.
73 The data is protocol data sent to the peer.
74 .IP CURLINFO_SSL_DATA_OUT
75 The data is SSL/TLS (binary) data sent to the peer.
76 .IP CURLINFO_SSL_DATA_IN
77 The data is SSL/TLS (binary) data received from the peer.
85 void dump(const char *text,
86 FILE *stream, unsigned char *ptr, size_t size)
90 unsigned int width=0x10;
92 fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\\n",
93 text, (long)size, (long)size);
95 for(i=0; i<size; i+= width) {
96 fprintf(stream, "%4.4lx: ", (long)i);
98 /* show hex to the left */
99 for(c = 0; c < width; c++) {
101 fprintf(stream, "%02x ", ptr[i+c]);
106 /* show data on the right */
107 for(c = 0; (c < width) && (i+c < size); c++) {
108 char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
112 fputc('\\n', stream); /* newline */
117 int my_trace(CURL *handle, curl_infotype type,
118 char *data, size_t size,
122 (void)handle; /* prevent compiler warning */
127 fprintf(stderr, "== Info: %s", data);
128 default: /* in case a new one is introduced to shock us */
131 case CURLINFO_HEADER_OUT:
132 text = "=> Send header";
134 case CURLINFO_DATA_OUT:
135 text = "=> Send data";
137 case CURLINFO_SSL_DATA_OUT:
138 text = "=> Send SSL data";
140 case CURLINFO_HEADER_IN:
141 text = "<= Recv header";
143 case CURLINFO_DATA_IN:
144 text = "<= Recv data";
146 case CURLINFO_SSL_DATA_IN:
147 text = "<= Recv SSL data";
151 dump(text, stderr, (unsigned char *)data, size);
160 curl = curl_easy_init();
162 curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
164 /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
165 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
167 /* example.com is redirected, so we tell libcurl to follow redirection */
168 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
170 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
171 res = curl_easy_perform(curl);
172 /* Check for errors */
174 fprintf(stderr, "curl_easy_perform() failed: %s\\n",
175 curl_easy_strerror(res));
178 curl_easy_cleanup(curl);
188 .BR CURLOPT_VERBOSE "(3), " CURLOPT_DEBUGDATA "(3), "