diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-03-17 11:50:34 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-03-17 20:41:31 +0000 |
commit | 4e6b18e595cc24c411cbcd8d77795c7bb5a03ed9 (patch) | |
tree | 59d540f31f1e1bd2dede4442cd5e55cd92227f6f | |
parent | 18d0ab14bc7e31dec830c08e2eb6d4de01c57f82 (diff) |
connectivity: Add debug to curl queries
Add debug output when we use curl to make queries.
References: https://curl.se/libcurl/c/debug.html
-rw-r--r-- | src/core/nm-connectivity.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c index 04c1248a9b..ad20d1ee28 100644 --- a/src/core/nm-connectivity.c +++ b/src/core/nm-connectivity.c @@ -621,6 +621,49 @@ _timeout_cb(gpointer user_data) cb_data_complete(cb_data, NM_CONNECTIVITY_LIMITED, "timeout"); return G_SOURCE_REMOVE; } + +static int +easy_debug_cb(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr) +{ + NMConnectivityCheckHandle *cb_data = userptr; + const char *escaped = NULL; + gs_free char *to_free = NULL; + + switch (type) { + case CURLINFO_TEXT: + escaped = nm_utils_buf_utf8safe_escape((char *) data, + size, + NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, + &to_free); + _LOG2T("libcurl: == Info: %s", escaped ?: ""); + /* fall-through */ + default: /* in case a new one is introduced to shock us */ + return 0; + + case CURLINFO_DATA_OUT: + _LOG2T("libcurl => Send data"); + return 0; + case CURLINFO_SSL_DATA_OUT: + _LOG2T("libcurl => Send SSL data"); + return 0; + case CURLINFO_HEADER_IN: + _LOG2T("libcurl <= Recv header"); + return 0; + case CURLINFO_DATA_IN: + _LOG2T("libcurl <= Recv data"); + return 0; + case CURLINFO_SSL_DATA_IN: + _LOG2T("libcurl <= Recv SSL data"); + return 0; + case CURLINFO_HEADER_OUT: + escaped = nm_utils_buf_utf8safe_escape((char *) data, + size, + NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL, + &to_free); + _LOG2T("libcurl => Send header: %s", escaped ?: ""); + return 0; + } +} #endif static gboolean @@ -695,6 +738,11 @@ do_curl_request(NMConnectivityCheckHandle *cb_data) curl_easy_setopt(ehandle, CURLOPT_RESOLVE, cb_data->concheck.hosts); curl_easy_setopt(ehandle, CURLOPT_IPRESOLVE, resolve); curl_easy_setopt(ehandle, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); + if (_LOGT_ENABLED()) { + curl_easy_setopt(ehandle, CURLOPT_DEBUGFUNCTION, easy_debug_cb); + curl_easy_setopt(ehandle, CURLOPT_DEBUGDATA, cb_data); + curl_easy_setopt(ehandle, CURLOPT_VERBOSE, 1L); + } curl_multi_add_handle(mhandle, ehandle); } |