2b5b6336277a45d162a5d18a890391be02126d9c
[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 pre {
8   overflow: auto;
9   margin: 0;
10 }
11
12 P.level0, pre.level0 {
13  padding-left: 2em;
14 }
15
16 P.level1, pre.level1 {
17  padding-left: 4em;
18 }
19
20 P.level2, pre.level2 {
21  padding-left: 6em;
22 }
23
24 span.emphasis {
25  font-style: italic;
26 }
27
28 span.bold {
29  font-weight: bold;
30 }
31
32 span.manpage {
33  font-weight: bold;
34 }
35
36 h2.nroffsh {
37  background-color: #e0e0e0;
38 }
39
40 span.nroffip {
41  font-weight: bold;
42  font-size: 120%;
43  font-family: monospace;
44 }
45
46 p.roffit {
47  text-align: center;
48  font-size: 80%;
49 }
50 </STYLE>
51 </head><body>
52
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 &#35;include &lt;curl/curl.h&gt;
57 &nbsp;
58 typedef enum {
59 &nbsp; CURLINFO_TEXT = 0,
60 &nbsp; CURLINFO_HEADER_IN,    /* 1 */
61 &nbsp; CURLINFO_HEADER_OUT,   /* 2 */
62 &nbsp; CURLINFO_DATA_IN,      /* 3 */
63 &nbsp; CURLINFO_DATA_OUT,     /* 4 */
64 &nbsp; CURLINFO_SSL_DATA_IN,  /* 5 */
65 &nbsp; CURLINFO_SSL_DATA_OUT, /* 6 */
66 &nbsp; CURLINFO_END
67 } curl_infotype;
68 &nbsp;
69 int debug_callback(CURL *handle,
70 &nbsp;                  curl_infotype type,
71 &nbsp;                  char *data,
72 &nbsp;                  size_t size,
73 &nbsp;                  void *userptr);
74 &nbsp;
75 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
76 &nbsp;                         debug_callback);
77 </pre>
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">
100 static
101 void dump(const char *text,
102 &nbsp;         FILE *stream, unsigned char *ptr, size_t size)
103 {
104 &nbsp; size_t i;
105 &nbsp; size_t c;
106 &nbsp; unsigned int width=0x10;
107 &nbsp;
108 &nbsp; fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)n",
109 &nbsp;         text, (long)size, (long)size);
110 &nbsp;
111 &nbsp; for(i=0; i&lt;size; i+= width) {
112 &nbsp;   fprintf(stream, "%4.4lx: ", (long)i);
113 &nbsp;
114 &nbsp;   /* show hex to the left */
115 &nbsp;   for(c = 0; c &lt; width; c++) {
116 &nbsp;     if(i+c &lt; size)
117 &nbsp;       fprintf(stream, "%02x ", ptr[i+c]);
118 &nbsp;     else
119 &nbsp;       fputs("   ", stream);
120 &nbsp;   }
121 &nbsp;
122 &nbsp;   /* show data on the right */
123 &nbsp;   for(c = 0; (c &lt; width) && (i+c &lt; size); c++)
124 &nbsp;     fputc(ptr[i+c]&gt;=0x20) && (ptr[i+c]&lt;0x80)?ptr[i+c]:'.', stream);
125 &nbsp;
126 &nbsp;   fputc('n', stream); /* newline */
127 &nbsp; }
128 }
129 &nbsp;
130 static
131 int my_trace(CURL *handle, curl_infotype type,
132 &nbsp;            char *data, size_t size,
133 &nbsp;            void *userp)
134 {
135 &nbsp; const char *text;
136 &nbsp; (void)handle; /* prevent compiler warning */
137 &nbsp;
138 &nbsp; switch (type) {
139 &nbsp; case CURLINFO_TEXT:
140 &nbsp;   fprintf(stderr, "== Info: %s", data);
141 &nbsp; default: /* in case a new one is introduced to shock us */
142 &nbsp;   return 0;
143 &nbsp;
144 &nbsp; case CURLINFO_HEADER_OUT:
145 &nbsp;   text = "=&gt; Send header";
146 &nbsp;   break;
147 &nbsp; case CURLINFO_DATA_OUT:
148 &nbsp;   text = "=&gt; Send data";
149 &nbsp;   break;
150 &nbsp; case CURLINFO_SSL_DATA_OUT:
151 &nbsp;   text = "=&gt; Send SSL data";
152 &nbsp;   break;
153 &nbsp; case CURLINFO_HEADER_IN:
154 &nbsp;   text = "&lt;= Recv header";
155 &nbsp;   break;
156 &nbsp; case CURLINFO_DATA_IN:
157 &nbsp;   text = "&lt;= Recv data";
158 &nbsp;   break;
159 &nbsp; case CURLINFO_SSL_DATA_IN:
160 &nbsp;   text = "&lt;= Recv SSL data";
161 &nbsp;   break;
162 &nbsp; }
163 &nbsp;
164 &nbsp; dump(text, stderr, (unsigned char *)data, size);
165 &nbsp; return 0;
166 }
167 &nbsp;
168 int main(void)
169 {
170 &nbsp; CURL *curl;
171 &nbsp; CURLcode res;
172 &nbsp;
173 &nbsp; curl = curl_easy_init();
174 &nbsp; if(curl) {
175 &nbsp;   curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
176 &nbsp;
177 &nbsp;   /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
178 &nbsp;   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
179 &nbsp;
180 &nbsp;   /* example.com is redirected, so we tell libcurl to follow redirection */
181 &nbsp;   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
182 &nbsp;
183 &nbsp;   curl_easy_setopt(curl, CURLOPT_URL, "<a href="http://example.com/">http://example.com/</a>");
184 &nbsp;   res = curl_easy_perform(curl);
185 &nbsp;   /* Check for errors */
186 &nbsp;   if(res != CURLE_OK)
187 &nbsp;     fprintf(stderr, "curl_easy_perform() failed: %sn",
188 &nbsp;             curl_easy_strerror(res));
189 &nbsp;
190 &nbsp;   /* always cleanup */
191 &nbsp;   curl_easy_cleanup(curl);
192 &nbsp; }
193 &nbsp; return 0;
194 }
195 </pre>
196
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>.
202 </body></html>