Current File : //usr/share/doc/libcurl/html/opts/CURLOPT_DEBUGFUNCTION.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>CURLOPT_DEBUGFUNCTION man page</title>
<meta name="generator" content="roffit">
<STYLE type="text/css">
pre {
  overflow: auto;
  margin: 0;
}

P.level0, pre.level0 {
 padding-left: 2em;
}

P.level1, pre.level1 {
 padding-left: 4em;
}

P.level2, pre.level2 {
 padding-left: 6em;
}

span.emphasis {
 font-style: italic;
}

span.bold {
 font-weight: bold;
}

span.manpage {
 font-weight: bold;
}

h2.nroffsh {
 background-color: #e0e0e0;
}

span.nroffip {
 font-weight: bold;
 font-size: 120%;
 font-family: monospace;
}

p.roffit {
 text-align: center;
 font-size: 80%;
}
</STYLE>
</head><body>

<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">
&#35;include &lt;curl/curl.h&gt;
&nbsp;
typedef enum {
&nbsp; CURLINFO_TEXT = 0,
&nbsp; CURLINFO_HEADER_IN,    /* 1 */
&nbsp; CURLINFO_HEADER_OUT,   /* 2 */
&nbsp; CURLINFO_DATA_IN,      /* 3 */
&nbsp; CURLINFO_DATA_OUT,     /* 4 */
&nbsp; CURLINFO_SSL_DATA_IN,  /* 5 */
&nbsp; CURLINFO_SSL_DATA_OUT, /* 6 */
&nbsp; CURLINFO_END
} curl_infotype;
&nbsp;
int debug_callback(CURL *handle,
&nbsp;                  curl_infotype type,
&nbsp;                  char *data,
&nbsp;                  size_t size,
&nbsp;                  void *userptr);
&nbsp;
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
&nbsp;                         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="level0">The <span Class="emphasis">userptr</span> argument is the pointer set with <a Class="emphasis" href="./CURLOPT_DEBUGDATA.html">CURLOPT_DEBUGDATA</a>. 
<p class="level0">Available curl_infotype values: 
<p class="level0"><a name="CURLINFOTEXT"></a><span class="nroffip">CURLINFO_TEXT</span> 
<p class="level1">The data is informational text. 
<p class="level0"><a name="CURLINFOHEADERIN"></a><span class="nroffip">CURLINFO_HEADER_IN</span> 
<p class="level1">The data is header (or header-like) data received from the peer. 
<p class="level0"><a name="CURLINFOHEADEROUT"></a><span class="nroffip">CURLINFO_HEADER_OUT</span> 
<p class="level1">The data is header (or header-like) data sent to the peer. 
<p class="level0"><a name="CURLINFODATAIN"></a><span class="nroffip">CURLINFO_DATA_IN</span> 
<p class="level1">The data is protocol data received from the peer. 
<p class="level0"><a name="CURLINFODATAOUT"></a><span class="nroffip">CURLINFO_DATA_OUT</span> 
<p class="level1">The data is protocol data sent to the peer. 
<p class="level0"><a name="CURLINFOSSLDATAOUT"></a><span class="nroffip">CURLINFO_SSL_DATA_OUT</span> 
<p class="level1">The data is SSL/TLS (binary) data sent to the peer. 
<p class="level0"><a name="CURLINFOSSLDATAIN"></a><span class="nroffip">CURLINFO_SSL_DATA_IN</span> 
<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,
&nbsp;         FILE *stream, unsigned char *ptr, size_t size)
{
&nbsp; size_t i;
&nbsp; size_t c;
&nbsp; unsigned int width=0x10;
&nbsp;
&nbsp; fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n",
&nbsp;         text, (long)size, (long)size);
&nbsp;
&nbsp; for(i=0; i&lt;size; i+= width) {
&nbsp;   fprintf(stream, "%4.4lx: ", (long)i);
&nbsp;
&nbsp;   /* show hex to the left */
&nbsp;   for(c = 0; c &lt; width; c++) {
&nbsp;     if(i+c &lt; size)
&nbsp;       fprintf(stream, "%02x ", ptr[i+c]);
&nbsp;     else
&nbsp;       fputs("   ", stream);
&nbsp;   }
&nbsp;
&nbsp;   /* show data on the right */
&nbsp;   for(c = 0; (c &lt; width) && (i+c &lt; size); c++)
&nbsp;     fputc(ptr[i+c]&gt;=0x20) && (ptr[i+c]&lt;0x80)?ptr[i+c]:'.', stream);
&nbsp;
&nbsp;   fputc('\n', stream); /* newline */
&nbsp; }
}
&nbsp;
static
int my_trace(CURL *handle, curl_infotype type,
&nbsp;            char *data, size_t size,
&nbsp;            void *userp)
{
&nbsp; const char *text;
&nbsp; (void)handle; /* prevent compiler warning */
&nbsp;
&nbsp; switch (type) {
&nbsp; case CURLINFO_TEXT:
&nbsp;   fprintf(stderr, "== Info: %s", data);
&nbsp; default: /* in case a new one is introduced to shock us */
&nbsp;   return 0;
&nbsp;
&nbsp; case CURLINFO_HEADER_OUT:
&nbsp;   text = "=&gt; Send header";
&nbsp;   break;
&nbsp; case CURLINFO_DATA_OUT:
&nbsp;   text = "=&gt; Send data";
&nbsp;   break;
&nbsp; case CURLINFO_SSL_DATA_OUT:
&nbsp;   text = "=&gt; Send SSL data";
&nbsp;   break;
&nbsp; case CURLINFO_HEADER_IN:
&nbsp;   text = "&lt;= Recv header";
&nbsp;   break;
&nbsp; case CURLINFO_DATA_IN:
&nbsp;   text = "&lt;= Recv data";
&nbsp;   break;
&nbsp; case CURLINFO_SSL_DATA_IN:
&nbsp;   text = "&lt;= Recv SSL data";
&nbsp;   break;
&nbsp; }
&nbsp;
&nbsp; dump(text, stderr, (unsigned char *)data, size);
&nbsp; return 0;
}
&nbsp;
int main(void)
{
&nbsp; CURL *curl;
&nbsp; CURLcode res;
&nbsp;
&nbsp; curl = curl_easy_init();
&nbsp; if(curl) {
&nbsp;   curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
&nbsp;
&nbsp;   /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
&nbsp;   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
&nbsp;
&nbsp;   /* example.com is redirected, so we tell libcurl to follow redirection */
&nbsp;   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
&nbsp;
&nbsp;   curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
&nbsp;   res = curl_easy_perform(curl);
&nbsp;   /* Check for errors */
&nbsp;   if(res != CURLE_OK)
&nbsp;     fprintf(stderr, "curl_easy_perform() failed: %s\n",
&nbsp;             curl_easy_strerror(res));
&nbsp;
&nbsp;   /* always cleanup */
&nbsp;   curl_easy_cleanup(curl);
&nbsp; }
&nbsp; 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>
<p class="level0">Returns CURLE_OK <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
<p class="level0"><a Class="manpage" href="./CURLOPT_VERBOSE.html">CURLOPT_VERBOSE</a>, <a Class="manpage" href="./CURLOPT_DEBUGDATA.html">CURLOPT_DEBUGDATA</a><p class="roffit">
 This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
</body></html>