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">
12 P.level0, pre.level0 {
16 P.level1, pre.level1 {
20 P.level2, pre.level2 {
37 background-color: #e0e0e0;
43 font-family: monospace;
53 <p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
54 <p class="level0">CURLOPT_DEBUGFUNCTION - debug callback <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
55 <p class="level0"><pre class="level0">
56 #include <curl/curl.h>
59 CURLINFO_TEXT = 0,
60 CURLINFO_HEADER_IN, /* 1 */
61 CURLINFO_HEADER_OUT, /* 2 */
62 CURLINFO_DATA_IN, /* 3 */
63 CURLINFO_DATA_OUT, /* 4 */
64 CURLINFO_SSL_DATA_IN, /* 5 */
65 CURLINFO_SSL_DATA_OUT, /* 6 */
69 int debug_callback(CURL *handle,
70 curl_infotype type,
73 void *userptr);
75 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
76 debug_callback);
78 <a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
79 <p class="level0">Pass a pointer to your callback function, which should match the prototype shown above.
80 <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.
81 <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>.
82 <p class="level0">Available curl_infotype values:
83 <p class="level0"><a name="CURLINFOTEXT"></a><span class="nroffip">CURLINFO_TEXT</span>
84 <p class="level1">The data is informational text.
85 <p class="level0"><a name="CURLINFOHEADERIN"></a><span class="nroffip">CURLINFO_HEADER_IN</span>
86 <p class="level1">The data is header (or header-like) data received from the peer.
87 <p class="level0"><a name="CURLINFOHEADEROUT"></a><span class="nroffip">CURLINFO_HEADER_OUT</span>
88 <p class="level1">The data is header (or header-like) data sent to the peer.
89 <p class="level0"><a name="CURLINFODATAIN"></a><span class="nroffip">CURLINFO_DATA_IN</span>
90 <p class="level1">The data is protocol data received from the peer.
91 <p class="level0"><a name="CURLINFODATAOUT"></a><span class="nroffip">CURLINFO_DATA_OUT</span>
92 <p class="level1">The data is protocol data sent to the peer.
93 <p class="level0"><a name="CURLINFOSSLDATAOUT"></a><span class="nroffip">CURLINFO_SSL_DATA_OUT</span>
94 <p class="level1">The data is SSL/TLS (binary) data sent to the peer.
95 <p class="level0"><a name="CURLINFOSSLDATAIN"></a><span class="nroffip">CURLINFO_SSL_DATA_IN</span>
96 <p class="level1">The data is SSL/TLS (binary) data received from the peer. <a name="DEFAULT"></a><h2 class="nroffsh">DEFAULT</h2>
97 <p class="level0">NULL <a name="PROTOCOLS"></a><h2 class="nroffsh">PROTOCOLS</h2>
98 <p class="level0">All <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
99 <p class="level0"><pre class="level0">
101 void dump(const char *text,
102 FILE *stream, unsigned char *ptr, size_t size)
106 unsigned int width=0x10;
108 fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)n",
109 text, (long)size, (long)size);
111 for(i=0; i<size; i+= width) {
112 fprintf(stream, "%4.4lx: ", (long)i);
114 /* show hex to the left */
115 for(c = 0; c < width; c++) {
116 if(i+c < size)
117 fprintf(stream, "%02x ", ptr[i+c]);
119 fputs(" ", stream);
122 /* show data on the right */
123 for(c = 0; (c < width) && (i+c < size); c++)
124 fputc(ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.', stream);
126 fputc('n', stream); /* newline */
131 int my_trace(CURL *handle, curl_infotype type,
132 char *data, size_t size,
135 const char *text;
136 (void)handle; /* prevent compiler warning */
138 switch (type) {
139 case CURLINFO_TEXT:
140 fprintf(stderr, "== Info: %s", data);
141 default: /* in case a new one is introduced to shock us */
144 case CURLINFO_HEADER_OUT:
145 text = "=> Send header";
147 case CURLINFO_DATA_OUT:
148 text = "=> Send data";
150 case CURLINFO_SSL_DATA_OUT:
151 text = "=> Send SSL data";
153 case CURLINFO_HEADER_IN:
154 text = "<= Recv header";
156 case CURLINFO_DATA_IN:
157 text = "<= Recv data";
159 case CURLINFO_SSL_DATA_IN:
160 text = "<= Recv SSL data";
164 dump(text, stderr, (unsigned char *)data, size);
173 curl = curl_easy_init();
175 curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
177 /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
178 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
180 /* example.com is redirected, so we tell libcurl to follow redirection */
181 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
183 curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
184 res = curl_easy_perform(curl);
185 /* Check for errors */
186 if(res != CURLE_OK)
187 fprintf(stderr, "curl_easy_perform() failed: %sn",
188 curl_easy_strerror(res));
190 /* always cleanup */
191 curl_easy_cleanup(curl);
197 <p class="level0"><a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
198 <p class="level0">Always <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
199 <p class="level0">Returns CURLE_OK <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
200 <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">
201 This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.