Curl debug output improvements and minor fixes.
This commit is contained in:
@@ -421,7 +421,8 @@ void cwdebug_backtrace(int n)
|
|||||||
namespace debug
|
namespace debug
|
||||||
{
|
{
|
||||||
|
|
||||||
libcwd_do_type const libcw_do;
|
namespace libcwd { libcwd_do_type const libcw_do; }
|
||||||
|
|
||||||
ll_thread_local int Indent::S_indentation;
|
ll_thread_local int Indent::S_indentation;
|
||||||
|
|
||||||
Indent::Indent(int indent) : M_indent(indent)
|
Indent::Indent(int indent) : M_indent(indent)
|
||||||
|
|||||||
@@ -46,14 +46,15 @@ struct buf2str {
|
|||||||
int mSize;
|
int mSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace libcwd
|
|
||||||
|
|
||||||
enum print_thread_id_t { print_thread_id };
|
|
||||||
inline void init() { }
|
|
||||||
struct libcwd_do_type {
|
struct libcwd_do_type {
|
||||||
void on() const { }
|
void on() const { }
|
||||||
};
|
};
|
||||||
extern LL_COMMON_API libcwd_do_type const libcw_do;
|
extern LL_COMMON_API libcwd_do_type const libcw_do;
|
||||||
|
|
||||||
|
} // namespace libcwd
|
||||||
|
|
||||||
|
enum print_thread_id_t { print_thread_id };
|
||||||
|
inline void init() { }
|
||||||
struct Indent {
|
struct Indent {
|
||||||
int M_indent;
|
int M_indent;
|
||||||
static ll_thread_local int S_indentation;
|
static ll_thread_local int S_indentation;
|
||||||
@@ -87,8 +88,13 @@ extern LL_COMMON_API fake_channel const notice;
|
|||||||
} // namespace dc
|
} // namespace dc
|
||||||
} // namespace debug
|
} // namespace debug
|
||||||
|
|
||||||
|
#define LIBCWD_DEBUG_CHANNELS debug
|
||||||
|
#define LibcwDoutScopeBegin(a, b, c) do { using namespace debug; llinfos_nf << print_thread_id << (c).mLabel << ": " << Indent::print;
|
||||||
|
#define LibcwDoutStream llcont
|
||||||
|
#define LibcwDoutScopeEnd llcont << llendl; } while(0)
|
||||||
|
|
||||||
#define Debug(x) do { using namespace debug; x; } while(0)
|
#define Debug(x) do { using namespace debug; x; } while(0)
|
||||||
#define Dout(a, b) do { using namespace debug; if ((a).mOn) { llinfos_nf << print_thread_id << (a).mLabel << ": " << Indent::print << b << llendl; } } while(0)
|
#define Dout(a, b) do { using namespace debug; if ((a).mOn) { llinfos_nf << print_thread_id << (a).mLabel << ": " << Indent::print << b << llendl; } } while(0)
|
||||||
#define DoutEntering(a, b) \
|
#define DoutEntering(a, b) \
|
||||||
int __slviewer_debug_indentation = 2; \
|
int __slviewer_debug_indentation = 2; \
|
||||||
{ \
|
{ \
|
||||||
|
|||||||
@@ -958,13 +958,6 @@ void CurlEasyRequest::addHeader(char const* header)
|
|||||||
|
|
||||||
#if defined(CWDEBUG) || defined(DEBUG_CURLIO)
|
#if defined(CWDEBUG) || defined(DEBUG_CURLIO)
|
||||||
|
|
||||||
#ifndef CWDEBUG
|
|
||||||
#define LIBCWD_DEBUGCHANNELS 0
|
|
||||||
#define LibcwDoutScopeBegin(a, b, c) do { using namespace debug; llinfos_nf << dc::curlio.mLabel << ": ";
|
|
||||||
#define LibcwDoutStream llcont
|
|
||||||
#define LibcwDoutScopeEnd llcont << llendl; } while(0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int curl_debug_cb(CURL*, curl_infotype infotype, char* buf, size_t size, void* user_ptr)
|
static int curl_debug_cb(CURL*, curl_infotype infotype, char* buf, size_t size, void* user_ptr)
|
||||||
{
|
{
|
||||||
#ifdef CWDEBUG
|
#ifdef CWDEBUG
|
||||||
@@ -977,14 +970,15 @@ static int curl_debug_cb(CURL*, curl_infotype infotype, char* buf, size_t size,
|
|||||||
libcw_do.marker().assign(marker.str().data(), marker.str().size());
|
libcw_do.marker().assign(marker.str().data(), marker.str().size());
|
||||||
if (!debug::channels::dc::curlio.is_on())
|
if (!debug::channels::dc::curlio.is_on())
|
||||||
debug::channels::dc::curlio.on();
|
debug::channels::dc::curlio.on();
|
||||||
|
LibcwDoutScopeBegin(LIBCWD_DEBUGCHANNELS, libcwd::libcw_do, dc::curlio|cond_nonewline_cf(infotype == CURLINFO_TEXT))
|
||||||
#else
|
#else
|
||||||
if (infotype == CURLINFO_TEXT)
|
if (infotype == CURLINFO_TEXT)
|
||||||
{
|
{
|
||||||
while (size > 0 && (buf[size - 1] == '\r' || buf[size - 1] == '\n'))
|
while (size > 0 && (buf[size - 1] == '\r' || buf[size - 1] == '\n'))
|
||||||
--size;
|
--size;
|
||||||
}
|
}
|
||||||
|
LibcwDoutScopeBegin(LIBCWD_DEBUGCHANNELS, libcwd::libcw_do, dc::curlio)
|
||||||
#endif
|
#endif
|
||||||
LibcwDoutScopeBegin(LIBCWD_DEBUGCHANNELS, libcw_do, dc::curlio|cond_nonewline_cf(infotype == CURLINFO_TEXT))
|
|
||||||
switch (infotype)
|
switch (infotype)
|
||||||
{
|
{
|
||||||
case CURLINFO_TEXT:
|
case CURLINFO_TEXT:
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
#include "debug_libcurl.h"
|
#include "debug_libcurl.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "llerror.h"
|
#include "llerror.h"
|
||||||
|
#ifdef CWDEBUG
|
||||||
|
#include <libcwd/buf2str.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CURL_VERSION(major, minor, patch) \
|
#define CURL_VERSION(major, minor, patch) \
|
||||||
(LIBCURL_VERSION_MAJOR > major || \
|
(LIBCURL_VERSION_MAJOR > major || \
|
||||||
@@ -277,6 +280,7 @@ std::ostream& operator<<(std::ostream& os, CURLoption option)
|
|||||||
CASEPRINT(CURLOPT_PROGRESSDATA);
|
CASEPRINT(CURLOPT_PROGRESSDATA);
|
||||||
CASEPRINT(CURLOPT_AUTOREFERER);
|
CASEPRINT(CURLOPT_AUTOREFERER);
|
||||||
CASEPRINT(CURLOPT_PROXYPORT);
|
CASEPRINT(CURLOPT_PROXYPORT);
|
||||||
|
CASEPRINT(CURLOPT_POSTFIELDSIZE);
|
||||||
CASEPRINT(CURLOPT_HTTPPROXYTUNNEL);
|
CASEPRINT(CURLOPT_HTTPPROXYTUNNEL);
|
||||||
CASEPRINT(CURLOPT_INTERFACE);
|
CASEPRINT(CURLOPT_INTERFACE);
|
||||||
CASEPRINT(CURLOPT_KRBLEVEL);
|
CASEPRINT(CURLOPT_KRBLEVEL);
|
||||||
@@ -552,25 +556,26 @@ CURLcode debug_curl_easy_getinfo(CURL* curl, CURLINFO info, ...)
|
|||||||
CURLcode ret;
|
CURLcode ret;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
union param_type {
|
union param_type {
|
||||||
|
void* some_ptr;
|
||||||
long* long_ptr;
|
long* long_ptr;
|
||||||
char* char_ptr;
|
char** char_ptr;
|
||||||
curl_slist* curl_slist_ptr;
|
curl_slist** curl_slist_ptr;
|
||||||
double* double_ptr;
|
double* double_ptr;
|
||||||
} param;
|
} param;
|
||||||
va_start(ap, info);
|
va_start(ap, info);
|
||||||
param.long_ptr = va_arg(ap, long*);
|
param.some_ptr = va_arg(ap, void*);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
ret = curl_easy_getinfo(curl, info, param.long_ptr);
|
ret = curl_easy_getinfo(curl, info, param.some_ptr);
|
||||||
if (info == CURLINFO_PRIVATE)
|
if (info == CURLINFO_PRIVATE)
|
||||||
{
|
{
|
||||||
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", 0x" << std::hex << (size_t)param.char_ptr << std::dec << ") = " << ret);
|
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", 0x" << std::hex << (size_t)param.some_ptr << std::dec << ") = " << ret);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch((info & CURLINFO_TYPEMASK))
|
switch((info & CURLINFO_TYPEMASK))
|
||||||
{
|
{
|
||||||
case CURLINFO_STRING:
|
case CURLINFO_STRING:
|
||||||
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (char*){ \"" << (ret == CURLE_OK ? param.char_ptr : " <unchanged> ") << "\" }) = " << ret);
|
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (char**){ \"" << (ret == CURLE_OK ? *param.char_ptr : " <unchanged> ") << "\" }) = " << ret);
|
||||||
break;
|
break;
|
||||||
case CURLINFO_LONG:
|
case CURLINFO_LONG:
|
||||||
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (long*){ " << (ret == CURLE_OK ? *param.long_ptr : 0L) << "L }) = " << ret);
|
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (long*){ " << (ret == CURLE_OK ? *param.long_ptr : 0L) << "L }) = " << ret);
|
||||||
@@ -579,7 +584,7 @@ CURLcode debug_curl_easy_getinfo(CURL* curl, CURLINFO info, ...)
|
|||||||
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (double*){" << (ret == CURLE_OK ? *param.double_ptr : 0.) << "}) = " << ret);
|
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (double*){" << (ret == CURLE_OK ? *param.double_ptr : 0.) << "}) = " << ret);
|
||||||
break;
|
break;
|
||||||
case CURLINFO_SLIST:
|
case CURLINFO_SLIST:
|
||||||
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (curl_slist*){ " << (ret == CURLE_OK ? *param.curl_slist_ptr : unchanged_slist) << " }) = " << ret);
|
Dout(dc::curl, "curl_easy_getinfo(" << curl << ", " << info << ", (curl_slist**){ " << (ret == CURLE_OK ? **param.curl_slist_ptr : unchanged_slist) << " }) = " << ret);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -644,24 +649,93 @@ CURLcode debug_curl_easy_setopt(CURL* handle, CURLoption option, ...)
|
|||||||
std::exit(EXIT_FAILURE);
|
std::exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
static long postfieldsize; // Cache. Assumes only one thread sets CURLOPT_POSTFIELDSIZE.
|
||||||
switch (param_type)
|
switch (param_type)
|
||||||
{
|
{
|
||||||
case CURLOPTTYPE_LONG:
|
case CURLOPTTYPE_LONG:
|
||||||
|
{
|
||||||
ret = curl_easy_setopt(handle, option, param.along);
|
ret = curl_easy_setopt(handle, option, param.along);
|
||||||
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", " << param.along << "L) = " << ret);
|
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", " << param.along << "L) = " << ret);
|
||||||
|
if (option == CURLOPT_POSTFIELDSIZE)
|
||||||
|
{
|
||||||
|
postfieldsize = param.along;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case CURLOPTTYPE_OBJECTPOINT:
|
case CURLOPTTYPE_OBJECTPOINT:
|
||||||
|
{
|
||||||
ret = curl_easy_setopt(handle, option, param.ptr);
|
ret = curl_easy_setopt(handle, option, param.ptr);
|
||||||
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", (object*)0x" << std::hex << (size_t)param.ptr << std::dec << ") = " << ret);
|
LibcwDoutScopeBegin(LIBCWD_DEBUGCHANNELS, libcwd::libcw_do, dc::curl)
|
||||||
|
LibcwDoutStream << "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", ";
|
||||||
|
// For a subset of all options that take a char*, print the string passed.
|
||||||
|
if (option == CURLOPT_PROXY || // Set HTTP proxy to use. The parameter should be a char* to a zero terminated string holding the host name or dotted IP address.
|
||||||
|
option == CURLOPT_PROXYUSERPWD || // Pass a char* as parameter, which should be [user name]:[password] to use for the connection to the HTTP proxy.
|
||||||
|
option == CURLOPT_CAINFO || // Pass a char * to a zero terminated string naming a file holding one or more certificates to verify the peer with.
|
||||||
|
option == CURLOPT_URL || // Pass in a pointer to the actual URL to deal with. The parameter should be a char * to a zero terminated string [...]
|
||||||
|
option == CURLOPT_COOKIEFILE || // Pass a pointer to a zero terminated string as parameter. It should contain the name of your file holding cookie data to read.
|
||||||
|
option == CURLOPT_CUSTOMREQUEST || // Pass a pointer to a zero terminated string as parameter. It can be used to specify the request instead of GET or HEAD when performing HTTP based requests
|
||||||
|
option == CURLOPT_ENCODING || // Sets the contents of the Accept-Encoding: header sent in a HTTP request, and enables decoding of a response when a Content-Encoding: header is received.
|
||||||
|
option == CURLOPT_POSTFIELDS ||
|
||||||
|
option == CURLOPT_COPYPOSTFIELDS) // Full data to post in a HTTP POST operation.
|
||||||
|
{
|
||||||
|
bool const is_postfield = option == CURLOPT_POSTFIELDS || option == CURLOPT_COPYPOSTFIELDS;
|
||||||
|
char* str = (char*)param.ptr;
|
||||||
|
long size;
|
||||||
|
LibcwDoutStream << "(char*)0x" << std::hex << (size_t)param.ptr << std::dec << ")";
|
||||||
|
if (is_postfield)
|
||||||
|
{
|
||||||
|
size = postfieldsize < 32 ? postfieldsize : 32; // Only print first 32 characters (this was already written to debug output before).
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size = strlen(str);
|
||||||
|
}
|
||||||
|
LibcwDoutStream << "[";
|
||||||
|
if (str)
|
||||||
|
{
|
||||||
|
LibcwDoutStream << libcwd::buf2str(str, size);
|
||||||
|
if (is_postfield && postfieldsize > 32)
|
||||||
|
LibcwDoutStream << "...";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LibcwDoutStream << "NULL";
|
||||||
|
}
|
||||||
|
LibcwDoutStream << "](" << (is_postfield ? postfieldsize : size) << " bytes))";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LibcwDoutStream << "(object*)0x" << std::hex << (size_t)param.ptr << std::dec << ")";
|
||||||
|
}
|
||||||
|
LibcwDoutStream << " = " << ret;
|
||||||
|
LibcwDoutScopeEnd;
|
||||||
|
if (option == CURLOPT_HTTPHEADER && param.ptr)
|
||||||
|
{
|
||||||
|
debug::Indent indent(2);
|
||||||
|
Dout(dc::curl, "HTTP Headers:");
|
||||||
|
struct curl_slist* list = (struct curl_slist*)param.ptr;
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
Dout(dc::curl, '"' << list->data << '"');
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case CURLOPTTYPE_FUNCTIONPOINT:
|
case CURLOPTTYPE_FUNCTIONPOINT:
|
||||||
ret = curl_easy_setopt(handle, option, param.ptr);
|
ret = curl_easy_setopt(handle, option, param.ptr);
|
||||||
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", (function*)0x" << std::hex << (size_t)param.ptr << std::dec << ") = " << ret);
|
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", (function*)0x" << std::hex << (size_t)param.ptr << std::dec << ") = " << ret);
|
||||||
break;
|
break;
|
||||||
case CURLOPTTYPE_OFF_T:
|
case CURLOPTTYPE_OFF_T:
|
||||||
|
{
|
||||||
ret = curl_easy_setopt(handle, option, param.offset);
|
ret = curl_easy_setopt(handle, option, param.offset);
|
||||||
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", (curl_off_t)" << param.offset << ") = " << ret);
|
Dout(dc::curl, "curl_easy_setopt(" << (AICURL*)handle << ", " << option << ", (curl_off_t)" << param.offset << ") = " << ret);
|
||||||
|
if (option == CURLOPT_POSTFIELDSIZE_LARGE)
|
||||||
|
{
|
||||||
|
postfieldsize = (long)param.offset;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user