5d7617fb30f47dd7e6edc9c977916fd7988f496f
[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;     char x = (ptr[i+c] &gt;= 0x20 && ptr[i+c] &lt; 0x80) ? ptr[i+c] : '.';
125 &nbsp;     fputc(x, stream);
126 &nbsp;   }
127 &nbsp;
128 &nbsp;   fputc('\n', stream); /* newline */
129 &nbsp; }
130 }
131 &nbsp;
132 static
133 int my_trace(CURL *handle, curl_infotype type,
134 &nbsp;            char *data, size_t size,
135 &nbsp;            void *userp)
136 {
137 &nbsp; const char *text;
138 &nbsp; (void)handle; /* prevent compiler warning */
139 &nbsp;
140 &nbsp; switch (type) {
141 &nbsp; case CURLINFO_TEXT:
142 &nbsp;   fprintf(stderr, "== Info: %s", data);
143 &nbsp; default: /* in case a new one is introduced to shock us */
144 &nbsp;   return 0;
145 &nbsp;
146 &nbsp; case CURLINFO_HEADER_OUT:
147 &nbsp;   text = "=&gt; Send header";
148 &nbsp;   break;
149 &nbsp; case CURLINFO_DATA_OUT:
150 &nbsp;   text = "=&gt; Send data";
151 &nbsp;   break;
152 &nbsp; case CURLINFO_SSL_DATA_OUT:
153 &nbsp;   text = "=&gt; Send SSL data";
154 &nbsp;   break;
155 &nbsp; case CURLINFO_HEADER_IN:
156 &nbsp;   text = "&lt;= Recv header";
157 &nbsp;   break;
158 &nbsp; case CURLINFO_DATA_IN:
159 &nbsp;   text = "&lt;= Recv data";
160 &nbsp;   break;
161 &nbsp; case CURLINFO_SSL_DATA_IN:
162 &nbsp;   text = "&lt;= Recv SSL data";
163 &nbsp;   break;
164 &nbsp; }
165 &nbsp;
166 &nbsp; dump(text, stderr, (unsigned char *)data, size);
167 &nbsp; return 0;
168 }
169 &nbsp;
170 int main(void)
171 {
172 &nbsp; CURL *curl;
173 &nbsp; CURLcode res;
174 &nbsp;
175 &nbsp; curl = curl_easy_init();
176 &nbsp; if(curl) {
177 &nbsp;   curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
178 &nbsp;
179 &nbsp;   /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
180 &nbsp;   curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
181 &nbsp;
182 &nbsp;   /* example.com is redirected, so we tell libcurl to follow redirection */
183 &nbsp;   curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
184 &nbsp;
185 &nbsp;   curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
186 &nbsp;   res = curl_easy_perform(curl);
187 &nbsp;   /* Check for errors */
188 &nbsp;   if(res != CURLE_OK)
189 &nbsp;     fprintf(stderr, "curl_easy_perform() failed: %s\n",
190 &nbsp;             curl_easy_strerror(res));
191 &nbsp;
192 &nbsp;   /* always cleanup */
193 &nbsp;   curl_easy_cleanup(curl);
194 &nbsp; }
195 &nbsp; return 0;
196 }
197 </pre>
198
199 <p class="level0"><a name="AVAILABILITY"></a><h2 class="nroffsh">AVAILABILITY</h2>
200 <p class="level0">Always <a name="RETURN"></a><h2 class="nroffsh">RETURN VALUE</h2>
201 <p class="level0">Returns CURLE_OK <a name="SEE"></a><h2 class="nroffsh">SEE ALSO</h2>
202 <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">
203  This HTML page was made with <a href="http://daniel.haxx.se/projects/roffit/">roffit</a>.
204 </body></html>