summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2022-03-18 11:16:17 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2022-03-18 11:18:26 +0100
commit1916c55d3ae3d16b2137a2224fdb480f51da55df (patch)
tree59d540f31f1e1bd2dede4442cd5e55cd92227f6f
parent18d0ab14bc7e31dec830c08e2eb6d4de01c57f82 (diff)
parent4e6b18e595cc24c411cbcd8d77795c7bb5a03ed9 (diff)
merge: branch 'hadess/NetworkManager-wip/hadess/curl-logging'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1151
-rw-r--r--src/core/nm-connectivity.c48
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);
}