<title>CURLOPT_DEBUGFUNCTION man page</title>
<meta name="generator" content="roffit">
<STYLE type="text/css">
-pre {
- overflow: auto;
- margin: 0;
-}
-
-P.level0, pre.level0 {
+P.level0 {
padding-left: 2em;
}
-P.level1, pre.level1 {
+P.level1 {
padding-left: 4em;
}
-P.level2, pre.level2 {
+P.level2 {
padding-left: 6em;
}
<p class="level0"><a name="NAME"></a><h2 class="nroffsh">NAME</h2>
<p class="level0">CURLOPT_DEBUGFUNCTION - debug callback <a name="SYNOPSIS"></a><h2 class="nroffsh">SYNOPSIS</h2>
-<p class="level0"><pre class="level0">
-#include <curl/curl.h>
-
-typedef enum {
- CURLINFO_TEXT = 0,
- CURLINFO_HEADER_IN, /* 1 */
- CURLINFO_HEADER_OUT, /* 2 */
- CURLINFO_DATA_IN, /* 3 */
- CURLINFO_DATA_OUT, /* 4 */
- CURLINFO_SSL_DATA_IN, /* 5 */
- CURLINFO_SSL_DATA_OUT, /* 6 */
- CURLINFO_END
-} curl_infotype;
-
-int debug_callback(CURL *handle,
- curl_infotype type,
- char *data,
- size_t size,
- void *userptr);
-
-CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
- debug_callback);
-</pre>
+<p class="level0"><pre>
+<p class="level0">#include <curl/curl.h>
+ <p class="level0">typedef enum {
+ CURLINFO_TEXT = 0,
+ CURLINFO_HEADER_IN, /* 1 */
+ CURLINFO_HEADER_OUT, /* 2 */
+ CURLINFO_DATA_IN, /* 3 */
+ CURLINFO_DATA_OUT, /* 4 */
+ CURLINFO_SSL_DATA_IN, /* 5 */
+ CURLINFO_SSL_DATA_OUT, /* 6 */
+ CURLINFO_END
+ } curl_infotype;
+ <p class="level0">int debug_callback(CURL *handle,
+ curl_infotype type,
+ char *data,
+ size_t size,
+ void *userptr);
+ <p class="level0">CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
+ debug_callback);
+ </pre>
<a name="DESCRIPTION"></a><h2 class="nroffsh">DESCRIPTION</h2>
<p class="level0">Pass a pointer to your callback function, which should match the prototype shown above.
<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.
<p class="level1">The data is SSL/TLS (binary) data received from the peer. <a name="DEFAULT"></a><h2 class="nroffsh">DEFAULT</h2>
<p class="level0">NULL <a name="PROTOCOLS"></a><h2 class="nroffsh">PROTOCOLS</h2>
<p class="level0">All <a name="EXAMPLE"></a><h2 class="nroffsh">EXAMPLE</h2>
-<p class="level0"><pre class="level0">
-static
-void dump(const char *text,
- FILE *stream, unsigned char *ptr, size_t size)
-{
- size_t i;
- size_t c;
- unsigned int width=0x10;
-
- fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)n",
- text, (long)size, (long)size);
-
- for(i=0; i<size; i+= width) {
- fprintf(stream, "%4.4lx: ", (long)i);
-
- /* show hex to the left */
- for(c = 0; c < width; c++) {
- if(i+c < size)
- fprintf(stream, "%02x ", ptr[i+c]);
- else
- fputs(" ", stream);
- }
-
- /* show data on the right */
- for(c = 0; (c < width) && (i+c < size); c++)
- fputc(ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.', stream);
-
- fputc('n', stream); /* newline */
- }
-}
-
-static
-int my_trace(CURL *handle, curl_infotype type,
- char *data, size_t size,
- void *userp)
-{
- const char *text;
- (void)handle; /* prevent compiler warning */
-
- switch (type) {
- case CURLINFO_TEXT:
- fprintf(stderr, "== Info: %s", data);
- default: /* in case a new one is introduced to shock us */
- return 0;
-
- case CURLINFO_HEADER_OUT:
- text = "=> Send header";
- break;
- case CURLINFO_DATA_OUT:
- text = "=> Send data";
- break;
- case CURLINFO_SSL_DATA_OUT:
- text = "=> Send SSL data";
- break;
- case CURLINFO_HEADER_IN:
- text = "<= Recv header";
- break;
- case CURLINFO_DATA_IN:
- text = "<= Recv data";
- break;
- case CURLINFO_SSL_DATA_IN:
- text = "<= Recv SSL data";
- break;
- }
-
- dump(text, stderr, (unsigned char *)data, size);
- return 0;
-}
-
-int main(void)
-{
- CURL *curl;
- CURLcode res;
-
- curl = curl_easy_init();
- if(curl) {
- curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
-
- /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
- curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
-
- /* example.com is redirected, so we tell libcurl to follow redirection */
- curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
-
- curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
- res = curl_easy_perform(curl);
- /* Check for errors */
- if(res != CURLE_OK)
- fprintf(stderr, "curl_easy_perform() failed: %sn",
- curl_easy_strerror(res));
-
- /* always cleanup */
- curl_easy_cleanup(curl);
- }
- return 0;
-}
-</pre>
+<p class="level0"><pre>
+<p class="level0">static
+ void dump(const char *text,
+ FILE *stream, unsigned char *ptr, size_t size)
+ {
+ size_t i;
+ size_t c;
+ unsigned int width=0x10;
+ <p class="level0"> fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)n",
+ text, (long)size, (long)size);
+ <p class="level0"> for(i=0; i<size; i+= width) {
+ fprintf(stream, "%4.4lx: ", (long)i);
+ <p class="level0"> /* show hex to the left */
+ for(c = 0; c < width; c++) {
+ if(i+c < size)
+ fprintf(stream, "%02x ", ptr[i+c]);
+ else
+ fputs(" ", stream);
+ }
+ <p class="level0"> /* show data on the right */
+ for(c = 0; (c < width) && (i+c < size); c++)
+ fputc(ptr[i+c]>=0x20) && (ptr[i+c]<0x80)?ptr[i+c]:'.', stream);
+ <p class="level0"> fputc('n', stream); /* newline */
+ }
+ }
+ <p class="level0">static
+ int my_trace(CURL *handle, curl_infotype type,
+ char *data, size_t size,
+ void *userp)
+ {
+ const char *text;
+ (void)handle; /* prevent compiler warning */
+ <p class="level0"> switch (type) {
+ case CURLINFO_TEXT:
+ fprintf(stderr, "== Info: %s", data);
+ default: /* in case a new one is introduced to shock us */
+ return 0;
+ <p class="level0"> case CURLINFO_HEADER_OUT:
+ text = "=> Send header";
+ break;
+ case CURLINFO_DATA_OUT:
+ text = "=> Send data";
+ break;
+ case CURLINFO_SSL_DATA_OUT:
+ text = "=> Send SSL data";
+ break;
+ case CURLINFO_HEADER_IN:
+ text = "<= Recv header";
+ break;
+ case CURLINFO_DATA_IN:
+ text = "<= Recv data";
+ break;
+ case CURLINFO_SSL_DATA_IN:
+ text = "<= Recv SSL data";
+ break;
+ }
+ <p class="level0"> dump(text, stderr, (unsigned char *)data, size);
+ return 0;
+ }
+ <p class="level0">int main(void)
+ {
+ CURL *curl;
+ CURLcode res;
+ <p class="level0"> curl = curl_easy_init();
+ if(curl) {
+ curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
+ <p class="level0"> /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
+ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
+ <p class="level0"> /* example.com is redirected, so we tell libcurl to follow redirection */
+ curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
+ <p class="level0"> curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
+ res = curl_easy_perform(curl);
+ /* Check for errors */
+ if(res != CURLE_OK)
+ fprintf(stderr, "curl_easy_perform() failed: %sn",
+ curl_easy_strerror(res));
+ <p class="level0"> /* always cleanup */
+ curl_easy_cleanup(curl);
+ }
+ return 0;
+ }
+ </pre>
<p class="level0"><a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
<p class="level0">Always <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>