1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
4 <title>CURLOPT_DEBUGFUNCTION man page</title>
5 <meta name="generator" content="roffit">
6 <STYLE type="text/css">
32 background-color: #e0e0e0;
38 font-family: monospace;
48 <p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
49 <p class="level0">CURLOPT_DEBUGFUNCTION - debug callback <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
50 <p class="level0"><pre>
51 <p class="level0">#include <curl/curl.h>
52 <p class="level0">typedef enum {
53 CURLINFO_TEXT = 0,
54 CURLINFO_HEADER_IN, /* 1 */
55 CURLINFO_HEADER_OUT, /* 2 */
56 CURLINFO_DATA_IN, /* 3 */
57 CURLINFO_DATA_OUT, /* 4 */
58 CURLINFO_SSL_DATA_IN, /* 5 */
59 CURLINFO_SSL_DATA_OUT, /* 6 */
62 <p class="level0">int debug_callback(CURL *handle,
63 curl_infotype type,
66 void *userptr);
67 <p class="level0">CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
68 debug_callback);
70 <a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
71 <p class="level0">Pass a pointer to your callback function, which should match the prototype shown above.
72 <p class="level0"><a Class="emphasis" href="./CURLOPT_DEBUGFUNCTION.html">CURLOPT_DEBUGFUNCTION</a> replaces the standard debug function used when <a Class="emphasis" href="./CURLOPT_VERBOSE.html">CURLOPT_VERBOSE</a> is in effect. This callback receives debug information, as specified in the <span Class="emphasis">type</span> argument. This function must return 0. The <span Class="emphasis">data</span> pointed to by the char * passed to this function WILL NOT be zero terminated, but will be exactly of the <span Class="emphasis">size</span> as told by the <span Class="emphasis">size</span> argument.
73 <p class="level0">The <span Class="emphasis">userptr</span> argument is the pointer set with <a Class="emphasis" href="./CURLOPT_DEBUGDATA.html">CURLOPT_DEBUGDATA</a>.
74 <p class="level0">Available curl_infotype values:
75 <p class="level0"><a name="CURLINFOTEXT"></a><span class="nroffip">CURLINFO_TEXT</span>
76 <p class="level1">The data is informational text.
77 <p class="level0"><a name="CURLINFOHEADERIN"></a><span class="nroffip">CURLINFO_HEADER_IN</span>
78 <p class="level1">The data is header (or header-like) data received from the peer.
79 <p class="level0"><a name="CURLINFOHEADEROUT"></a><span class="nroffip">CURLINFO_HEADER_OUT</span>
80 <p class="level1">The data is header (or header-like) data sent to the peer.
81 <p class="level0"><a name="CURLINFODATAIN"></a><span class="nroffip">CURLINFO_DATA_IN</span>
82 <p class="level1">The data is protocol data received from the peer.
83 <p class="level0"><a name="CURLINFODATAOUT"></a><span class="nroffip">CURLINFO_DATA_OUT</span>
84 <p class="level1">The data is protocol data sent to the peer.
85 <p class="level0"><a name="CURLINFOSSLDATAOUT"></a><span class="nroffip">CURLINFO_SSL_DATA_OUT</span>
86 <p class="level1">The data is SSL/TLS (binary) data sent to the peer.
87 <p class="level0"><a name="CURLINFOSSLDATAIN"></a><span class="nroffip">CURLINFO_SSL_DATA_IN</span>
88 <p class="level1">The data is SSL/TLS (binary) data received from the peer. <a name="DEFAULT"></a><h2 class="nroffsh">DEFAULT</h2>
89 <p class="level0">NULL <a name="PROTOCOLS"></a><h2 class="nroffsh">PROTOCOLS</h2>
90 <p class="level0">All <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
91 <p class="level0"><pre>
92 <p class="level0">static
93 void dump(const char *text,
94 FILE *stream, unsigned char *ptr, size_t size)
98 unsigned int width=0x10;
99 <p class="level0"> fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)n",
100 text, (long)size, (long)size);
101 <p class="level0"> for(i=0; i<size; i+= width) {
102 fprintf(stream, "%4.4lx: ", (long)i);
103 <p class="level0"> /* show hex to the left */
104 for(c = 0; c < width; c++) {
105 if(i+c < size)
106 fprintf(stream, "%02x ", ptr[i+c]);
108 fputs(" ", stream);
110 <p class="level0"> /* show data on the right */
111 for(c = 0; (c < width) && (i+c < size); c++)
112 fputc(ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.', stream);
113 <p class="level0"> fputc('n', stream); /* newline */
116 <p class="level0">static
117 int my_trace(CURL *handle, curl_infotype type,
118 char *data, size_t size,
121 const char *text;
122 (void)handle; /* prevent compiler warning */
123 <p class="level0"> switch (type) {
124 case CURLINFO_TEXT:
125 fprintf(stderr, "== Info: %s", data);
126 default: /* in case a new one is introduced to shock us */
128 <p class="level0"> case CURLINFO_HEADER_OUT:
129 text = "=> Send header";
131 case CURLINFO_DATA_OUT:
132 text = "=> Send data";
134 case CURLINFO_SSL_DATA_OUT:
135 text = "=> Send SSL data";
137 case CURLINFO_HEADER_IN:
138 text = "<= Recv header";
140 case CURLINFO_DATA_IN:
141 text = "<= Recv data";
143 case CURLINFO_SSL_DATA_IN:
144 text = "<= Recv SSL data";
147 <p class="level0"> dump(text, stderr, (unsigned char *)data, size);
150 <p class="level0">int main(void)
154 <p class="level0"> curl = curl_easy_init();
156 curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
157 <p class="level0"> /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
158 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
159 <p class="level0"> /* example.com is redirected, so we tell libcurl to follow redirection */
160 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
161 <p class="level0"> curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
162 res = curl_easy_perform(curl);
163 /* Check for errors */
164 if(res != CURLE_OK)
165 fprintf(stderr, "curl_easy_perform() failed: %sn",
166 curl_easy_strerror(res));
167 <p class="level0"> /* always cleanup */
168 curl_easy_cleanup(curl);
174 <p class="level0"><a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
175 <p class="level0">Always <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
176 <p class="level0">Returns CURLE_OK <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
177 <p class="level0"><a Class="manpage" href="./CURLOPT_VERBOSE.html">CURLOPT_VERBOSE</a>, <a Class="manpage" href="./CURLOPT_DEBUGDATA.html">CURLOPT_DEBUGDATA</a>, <span Class="manpage"> </span> <p class="roffit">
178 This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.