Revert "Imported Upstream version 7.44.0"
[platform/upstream/curl.git] / docs / libcurl / opts / CURLOPT_DEBUGFUNCTION.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2  "http://www.w3.org/TR/html4/loose.dtd">
3 <html><head>
4 <title>CURLOPT_DEBUGFUNCTION man page</title>
5 <meta name="generator" content="roffit">
6 <STYLE type="text/css">
7 P.level0 {
8  padding-left: 2em;
9 }
10
11 P.level1 {
12  padding-left: 4em;
13 }
14
15 P.level2 {
16  padding-left: 6em;
17 }
18
19 span.emphasis {
20  font-style: italic;
21 }
22
23 span.bold {
24  font-weight: bold;
25 }
26
27 span.manpage {
28  font-weight: bold;
29 }
30
31 h2.nroffsh {
32  background-color: #e0e0e0;
33 }
34
35 span.nroffip {
36  font-weight: bold;
37  font-size: 120%;
38  font-family: monospace;
39 }
40
41 p.roffit {
42  text-align: center;
43  font-size: 80%;
44 }
45 </STYLE>
46 </head><body>
47
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 &lt;curl/curl.h&gt;
52  <p class="level0">typedef enum {
53  &nbsp; CURLINFO_TEXT = 0,
54  &nbsp; CURLINFO_HEADER_IN,    /* 1 */
55  &nbsp; CURLINFO_HEADER_OUT,   /* 2 */
56  &nbsp; CURLINFO_DATA_IN,      /* 3 */
57  &nbsp; CURLINFO_DATA_OUT,     /* 4 */
58  &nbsp; CURLINFO_SSL_DATA_IN,  /* 5 */
59  &nbsp; CURLINFO_SSL_DATA_OUT, /* 6 */
60  &nbsp; CURLINFO_END
61  } curl_infotype;
62  <p class="level0">int debug_callback(CURL *handle,
63  &nbsp;                  curl_infotype type,
64  &nbsp;                  char *data,
65  &nbsp;                  size_t size,
66  &nbsp;                  void *userptr);
67  <p class="level0">CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
68  &nbsp;                         debug_callback);
69  </pre>
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  &nbsp;         FILE *stream, unsigned char *ptr, size_t size)
95  {
96  &nbsp; size_t i;
97  &nbsp; size_t c;
98  &nbsp; unsigned int width=0x10;
99  <p class="level0">&nbsp; fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)n",
100  &nbsp;         text, (long)size, (long)size);
101  <p class="level0">&nbsp; for(i=0; i&lt;size; i+= width) {
102  &nbsp;   fprintf(stream, "%4.4lx: ", (long)i);
103  <p class="level0">&nbsp;   /* show hex to the left */
104  &nbsp;   for(c = 0; c &lt; width; c++) {
105  &nbsp;     if(i+c &lt; size)
106  &nbsp;       fprintf(stream, "%02x ", ptr[i+c]);
107  &nbsp;     else
108  &nbsp;       fputs("   ", stream);
109  &nbsp;   }
110  <p class="level0">&nbsp;   /* show data on the right */
111  &nbsp;   for(c = 0; (c &lt; width) && (i+c &lt; size); c++)
112  &nbsp;     fputc(ptr[i+c]&gt;=0x20) && (ptr[i+c]&lt;0x80)?ptr[i+c]:'.', stream);
113  <p class="level0">&nbsp;   fputc('n', stream); /* newline */
114  &nbsp; }
115  }
116  <p class="level0">static
117  int my_trace(CURL *handle, curl_infotype type,
118  &nbsp;            char *data, size_t size,
119  &nbsp;            void *userp)
120  {
121  &nbsp; const char *text;
122  &nbsp; (void)handle; /* prevent compiler warning */
123  <p class="level0">&nbsp; switch (type) {
124  &nbsp; case CURLINFO_TEXT:
125  &nbsp;   fprintf(stderr, "== Info: %s", data);
126  &nbsp; default: /* in case a new one is introduced to shock us */
127  &nbsp;   return 0;
128  <p class="level0">&nbsp; case CURLINFO_HEADER_OUT:
129  &nbsp;   text = "=&gt; Send header";
130  &nbsp;   break;
131  &nbsp; case CURLINFO_DATA_OUT:
132  &nbsp;   text = "=&gt; Send data";
133  &nbsp;   break;
134  &nbsp; case CURLINFO_SSL_DATA_OUT:
135  &nbsp;   text = "=&gt; Send SSL data";
136  &nbsp;   break;
137  &nbsp; case CURLINFO_HEADER_IN:
138  &nbsp;   text = "&lt;= Recv header";
139  &nbsp;   break;
140  &nbsp; case CURLINFO_DATA_IN:
141  &nbsp;   text = "&lt;= Recv data";
142  &nbsp;   break;
143  &nbsp; case CURLINFO_SSL_DATA_IN:
144  &nbsp;   text = "&lt;= Recv SSL data";
145  &nbsp;   break;
146  &nbsp; }
147  <p class="level0">&nbsp; dump(text, stderr, (unsigned char *)data, size);
148  &nbsp; return 0;
149  }
150  <p class="level0">int main(void)
151  {
152  &nbsp; CURL *curl;
153  &nbsp; CURLcode res;
154  <p class="level0">&nbsp; curl = curl_easy_init();
155  &nbsp; if(curl) {
156  &nbsp;   curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
157  <p class="level0">&nbsp;   /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
158  &nbsp;   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
159  <p class="level0">&nbsp;   /* example.com is redirected, so we tell libcurl to follow redirection */
160  &nbsp;   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
161  <p class="level0">&nbsp;   curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
162  &nbsp;   res = curl_easy_perform(curl);
163  &nbsp;   /* Check for errors */
164  &nbsp;   if(res != CURLE_OK)
165  &nbsp;     fprintf(stderr, "curl_easy_perform() failed: %sn",
166  &nbsp;             curl_easy_strerror(res));
167  <p class="level0">&nbsp;   /* always cleanup */
168  &nbsp;   curl_easy_cleanup(curl);
169  &nbsp; }
170  &nbsp; return 0;
171  }
172  </pre>
173
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>.
179 </body></html>