1CURLOPT_DEBUGFUNCTION(3)            libcurl           CURLOPT_DEBUGFUNCTION(3)
2
3
4

NAME

6       CURLOPT_DEBUGFUNCTION - debug callback
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       typedef enum {
12         CURLINFO_TEXT = 0,
13         CURLINFO_HEADER_IN,    /* 1 */
14         CURLINFO_HEADER_OUT,   /* 2 */
15         CURLINFO_DATA_IN,      /* 3 */
16         CURLINFO_DATA_OUT,     /* 4 */
17         CURLINFO_SSL_DATA_IN,  /* 5 */
18         CURLINFO_SSL_DATA_OUT, /* 6 */
19         CURLINFO_END
20       } curl_infotype;
21
22       int debug_callback(CURL *handle,
23                          curl_infotype type,
24                          char *data,
25                          size_t size,
26                          void *clientp);
27
28       CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
29                                 debug_callback);
30

DESCRIPTION

32       Pass a pointer to your callback function, which should match the proto‐
33       type shown above.
34
35       CURLOPT_DEBUGFUNCTION(3) replaces the standard debug function used when
36       CURLOPT_VERBOSE(3)  is in effect. This callback receives debug informa‐
37       tion, as specified in the type argument. This function must  return  0.
38       The  data  pointed to by the char * passed to this function WILL NOT be
39       null-terminated, but will be exactly of the size as told  by  the  size
40       argument.
41
42       The clientp argument is the pointer set with CURLOPT_DEBUGDATA(3).
43
44       Available curl_infotype values:
45
46       CURLINFO_TEXT
47              The data is informational text.
48
49       CURLINFO_HEADER_IN
50              The data is header (or header-like) data received from the peer.
51
52       CURLINFO_HEADER_OUT
53              The data is header (or header-like) data sent to the peer.
54
55       CURLINFO_DATA_IN
56              The  data  is  the  unprocessed  protocol data received from the
57              peer. Even if the data is encoded or compressed, it will not  be
58              provided  decoded nor decompressed to this callback. If you need
59              the data in decoded and decompressed  form,  use  CURLOPT_WRITE‐
60              FUNCTION(3).
61
62       CURLINFO_DATA_OUT
63              The data is protocol data sent to the peer.
64
65       CURLINFO_SSL_DATA_OUT
66              The data is SSL/TLS (binary) data sent to the peer.
67
68       CURLINFO_SSL_DATA_IN
69              The data is SSL/TLS (binary) data received from the peer.
70

DEFAULT

72       NULL
73

PROTOCOLS

75       All
76

EXAMPLE

78       static
79       void dump(const char *text,
80                 FILE *stream, unsigned char *ptr, size_t size)
81       {
82         size_t i;
83         size_t c;
84         unsigned int width=0x10;
85
86         fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n",
87                 text, (long)size, (long)size);
88
89         for(i=0; i<size; i+= width) {
90           fprintf(stream, "%4.4lx: ", (long)i);
91
92           /* show hex to the left */
93           for(c = 0; c < width; c++) {
94             if(i+c < size)
95               fprintf(stream, "%02x ", ptr[i+c]);
96             else
97               fputs("   ", stream);
98           }
99
100           /* show data on the right */
101           for(c = 0; (c < width) && (i+c < size); c++) {
102             char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
103             fputc(x, stream);
104           }
105
106           fputc('\n', stream); /* newline */
107         }
108       }
109
110       static
111       int my_trace(CURL *handle, curl_infotype type,
112                    char *data, size_t size,
113                    void *clientp)
114       {
115         const char *text;
116         (void)handle; /* prevent compiler warning */
117         (void)clientp;
118
119         switch (type) {
120         case CURLINFO_TEXT:
121           fputs("== Info: ", stderr);
122           fwrite(data, size, 1, stderr);
123         default: /* in case a new one is introduced to shock us */
124           return 0;
125
126         case CURLINFO_HEADER_OUT:
127           text = "=> Send header";
128           break;
129         case CURLINFO_DATA_OUT:
130           text = "=> Send data";
131           break;
132         case CURLINFO_SSL_DATA_OUT:
133           text = "=> Send SSL data";
134           break;
135         case CURLINFO_HEADER_IN:
136           text = "<= Recv header";
137           break;
138         case CURLINFO_DATA_IN:
139           text = "<= Recv data";
140           break;
141         case CURLINFO_SSL_DATA_IN:
142           text = "<= Recv SSL data";
143           break;
144         }
145
146         dump(text, stderr, (unsigned char *)data, size);
147         return 0;
148       }
149
150       int main(void)
151       {
152         CURL *curl;
153         CURLcode res;
154
155         curl = curl_easy_init();
156         if(curl) {
157           curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
158
159           /* the DEBUGFUNCTION has no effect until we enable VERBOSE */
160           curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
161
162           /* example.com is redirected, so we tell libcurl to follow redirection */
163           curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
164
165           curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
166           res = curl_easy_perform(curl);
167           /* Check for errors */
168           if(res != CURLE_OK)
169             fprintf(stderr, "curl_easy_perform() failed: %s\n",
170                     curl_easy_strerror(res));
171
172           /* always cleanup */
173           curl_easy_cleanup(curl);
174         }
175         return 0;
176       }
177

AVAILABILITY

179       Always
180

RETURN VALUE

182       Returns CURLE_OK
183

SEE ALSO

185       CURLOPT_VERBOSE(3), CURLOPT_DEBUGDATA(3),
186
187
188
189ibcurl 8.2.1                    April 26, 2023        CURLOPT_DEBUGFUNCTION(3)
Impressum