2014-06-19 05:35:48 +08:00
|
|
|
.\" **************************************************************************
|
|
|
|
.\" * _ _ ____ _
|
|
|
|
.\" * Project ___| | | | _ \| |
|
|
|
|
.\" * / __| | | | |_) | |
|
|
|
|
.\" * | (__| |_| | _ <| |___
|
|
|
|
.\" * \___|\___/|_| \_\_____|
|
|
|
|
.\" *
|
2023-01-02 20:51:48 +08:00
|
|
|
.\" * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2014-06-19 05:35:48 +08:00
|
|
|
.\" *
|
|
|
|
.\" * This software is licensed as described in the file COPYING, which
|
|
|
|
.\" * you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
.\" * are also available at https://curl.se/docs/copyright.html.
|
2014-06-19 05:35:48 +08:00
|
|
|
.\" *
|
|
|
|
.\" * You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
.\" * copies of the Software, and permit persons to whom the Software is
|
|
|
|
.\" * furnished to do so, under the terms of the COPYING file.
|
|
|
|
.\" *
|
|
|
|
.\" * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
.\" * KIND, either express or implied.
|
|
|
|
.\" *
|
|
|
|
.\" * SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
.\" *
|
2014-06-19 05:35:48 +08:00
|
|
|
.\" **************************************************************************
|
|
|
|
.\"
|
2023-04-26 14:58:35 +08:00
|
|
|
.TH CURLOPT_DEBUGFUNCTION 3 "17 Jun 2014" libcurl libcurl
|
2014-06-19 05:35:48 +08:00
|
|
|
.SH NAME
|
|
|
|
CURLOPT_DEBUGFUNCTION \- debug callback
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
CURLINFO_TEXT = 0,
|
|
|
|
CURLINFO_HEADER_IN, /* 1 */
|
|
|
|
CURLINFO_HEADER_OUT, /* 2 */
|
|
|
|
CURLINFO_DATA_IN, /* 3 */
|
|
|
|
CURLINFO_DATA_OUT, /* 4 */
|
|
|
|
CURLINFO_SSL_DATA_IN, /* 5 */
|
|
|
|
CURLINFO_SSL_DATA_OUT, /* 6 */
|
|
|
|
CURLINFO_END
|
|
|
|
} curl_infotype;
|
|
|
|
|
|
|
|
int debug_callback(CURL *handle,
|
|
|
|
curl_infotype type,
|
|
|
|
char *data,
|
|
|
|
size_t size,
|
2023-02-07 22:58:17 +08:00
|
|
|
void *clientp);
|
2014-06-19 05:35:48 +08:00
|
|
|
|
|
|
|
CURLcode curl_easy_setopt(CURL *handle, CURLOPT_DEBUGFUNCTION,
|
|
|
|
debug_callback);
|
|
|
|
.SH DESCRIPTION
|
|
|
|
Pass a pointer to your callback function, which should match the prototype
|
|
|
|
shown above.
|
|
|
|
|
|
|
|
\fICURLOPT_DEBUGFUNCTION(3)\fP replaces the standard debug function used when
|
|
|
|
\fICURLOPT_VERBOSE(3)\fP is in effect. This callback receives debug
|
|
|
|
information, as specified in the \fItype\fP argument. This function must
|
|
|
|
return 0. The \fIdata\fP pointed to by the char * passed to this function WILL
|
2020-06-25 17:38:25 +08:00
|
|
|
NOT be null-terminated, but will be exactly of the \fIsize\fP as told by the
|
2014-06-19 05:35:48 +08:00
|
|
|
\fIsize\fP argument.
|
|
|
|
|
2023-02-07 22:58:17 +08:00
|
|
|
The \fIclientp\fP argument is the pointer set with \fICURLOPT_DEBUGDATA(3)\fP.
|
2014-06-19 05:35:48 +08:00
|
|
|
|
2022-09-21 05:30:19 +08:00
|
|
|
Available \fBcurl_infotype\fP values:
|
2014-06-19 05:35:48 +08:00
|
|
|
.IP CURLINFO_TEXT
|
|
|
|
The data is informational text.
|
|
|
|
.IP CURLINFO_HEADER_IN
|
|
|
|
The data is header (or header-like) data received from the peer.
|
|
|
|
.IP CURLINFO_HEADER_OUT
|
|
|
|
The data is header (or header-like) data sent to the peer.
|
|
|
|
.IP CURLINFO_DATA_IN
|
2022-12-16 19:45:20 +08:00
|
|
|
The data is the unprocessed protocol data received from the peer. Even if the
|
|
|
|
data is encoded or compressed, it will not be provided decoded nor
|
|
|
|
decompressed to this callback. If you need the data in decoded and
|
|
|
|
decompressed form, use \fICURLOPT_WRITEFUNCTION(3)\fP.
|
2014-06-19 05:35:48 +08:00
|
|
|
.IP CURLINFO_DATA_OUT
|
|
|
|
The data is protocol data sent to the peer.
|
|
|
|
.IP CURLINFO_SSL_DATA_OUT
|
|
|
|
The data is SSL/TLS (binary) data sent to the peer.
|
|
|
|
.IP CURLINFO_SSL_DATA_IN
|
|
|
|
The data is SSL/TLS (binary) data received from the peer.
|
|
|
|
.SH DEFAULT
|
|
|
|
NULL
|
|
|
|
.SH PROTOCOLS
|
|
|
|
All
|
|
|
|
.SH EXAMPLE
|
2014-10-21 16:26:40 +08:00
|
|
|
.nf
|
|
|
|
static
|
|
|
|
void dump(const char *text,
|
|
|
|
FILE *stream, unsigned char *ptr, size_t size)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
size_t c;
|
|
|
|
unsigned int width=0x10;
|
|
|
|
|
2015-09-28 11:44:31 +08:00
|
|
|
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\\n",
|
2014-10-21 16:26:40 +08:00
|
|
|
text, (long)size, (long)size);
|
|
|
|
|
|
|
|
for(i=0; i<size; i+= width) {
|
|
|
|
fprintf(stream, "%4.4lx: ", (long)i);
|
|
|
|
|
|
|
|
/* show hex to the left */
|
|
|
|
for(c = 0; c < width; c++) {
|
|
|
|
if(i+c < size)
|
|
|
|
fprintf(stream, "%02x ", ptr[i+c]);
|
|
|
|
else
|
|
|
|
fputs(" ", stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* show data on the right */
|
2016-02-21 05:23:05 +08:00
|
|
|
for(c = 0; (c < width) && (i+c < size); c++) {
|
|
|
|
char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
|
|
|
|
fputc(x, stream);
|
|
|
|
}
|
2014-10-21 16:26:40 +08:00
|
|
|
|
2015-09-28 11:44:31 +08:00
|
|
|
fputc('\\n', stream); /* newline */
|
2014-10-21 16:26:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int my_trace(CURL *handle, curl_infotype type,
|
|
|
|
char *data, size_t size,
|
2023-02-07 22:58:17 +08:00
|
|
|
void *clientp)
|
2014-10-21 16:26:40 +08:00
|
|
|
{
|
|
|
|
const char *text;
|
|
|
|
(void)handle; /* prevent compiler warning */
|
2023-02-07 22:58:17 +08:00
|
|
|
(void)clientp;
|
2014-10-21 16:26:40 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case CURLINFO_TEXT:
|
2022-11-07 19:15:24 +08:00
|
|
|
fputs("== Info: ", stderr);
|
|
|
|
fwrite(data, size, 1, stderr);
|
2014-10-21 16:26:40 +08:00
|
|
|
default: /* in case a new one is introduced to shock us */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case CURLINFO_HEADER_OUT:
|
|
|
|
text = "=> Send header";
|
|
|
|
break;
|
|
|
|
case CURLINFO_DATA_OUT:
|
|
|
|
text = "=> Send data";
|
|
|
|
break;
|
|
|
|
case CURLINFO_SSL_DATA_OUT:
|
|
|
|
text = "=> Send SSL data";
|
|
|
|
break;
|
|
|
|
case CURLINFO_HEADER_IN:
|
|
|
|
text = "<= Recv header";
|
|
|
|
break;
|
|
|
|
case CURLINFO_DATA_IN:
|
|
|
|
text = "<= Recv data";
|
|
|
|
break;
|
|
|
|
case CURLINFO_SSL_DATA_IN:
|
|
|
|
text = "<= Recv SSL data";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump(text, stderr, (unsigned char *)data, size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
CURL *curl;
|
|
|
|
CURLcode res;
|
|
|
|
|
|
|
|
curl = curl_easy_init();
|
|
|
|
if(curl) {
|
|
|
|
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_trace);
|
|
|
|
|
|
|
|
/* the DEBUGFUNCTION has no effect until we enable VERBOSE */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
|
|
|
|
|
|
|
/* example.com is redirected, so we tell libcurl to follow redirection */
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
|
|
|
|
|
2020-09-17 05:04:07 +08:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/");
|
2014-10-21 16:26:40 +08:00
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
/* Check for errors */
|
|
|
|
if(res != CURLE_OK)
|
2015-09-28 11:44:31 +08:00
|
|
|
fprintf(stderr, "curl_easy_perform() failed: %s\\n",
|
2014-10-21 16:26:40 +08:00
|
|
|
curl_easy_strerror(res));
|
|
|
|
|
|
|
|
/* always cleanup */
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
.fi
|
2014-06-19 05:35:48 +08:00
|
|
|
.SH AVAILABILITY
|
|
|
|
Always
|
|
|
|
.SH RETURN VALUE
|
|
|
|
Returns CURLE_OK
|
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR CURLOPT_VERBOSE "(3), " CURLOPT_DEBUGDATA "(3), "
|