summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-04-01 18:17:31 +0200
committerThomas Haller <thaller@redhat.com>2022-04-04 16:09:36 +0200
commit1dc16931be22151658505c48401c8c447880675c (patch)
tree9d59f7e1fc61ce896811c18494c8ffc0efdd384d
parent57d226d3f08d8a904a554367e799c9c367032b0d (diff)
connectivity: refactor easy_debug_cb()
It seems nicer to me to choose a message in the switch and only print at one place.
-rw-r--r--src/core/nm-connectivity.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/src/core/nm-connectivity.c b/src/core/nm-connectivity.c
index e436458e94..4ef8f48b4f 100644
--- a/src/core/nm-connectivity.c
+++ b/src/core/nm-connectivity.c
@@ -626,44 +626,51 @@ _timeout_cb(gpointer user_data)
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;
+ NMConnectivityCheckHandle *cb_data = userptr;
+ gs_free char *data_escaped = NULL;
+ const char *msg;
+ gboolean print_data = FALSE;
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;
-
+ print_data = TRUE;
+ msg = "== Info: ";
+ break;
case CURLINFO_DATA_OUT:
- _LOG2T("libcurl => Send data");
- return 0;
+ msg = "=> Send data";
+ break;
case CURLINFO_SSL_DATA_OUT:
- _LOG2T("libcurl => Send SSL data");
- return 0;
+ msg = "=> Send SSL data";
+ break;
case CURLINFO_HEADER_IN:
- _LOG2T("libcurl <= Recv header");
- return 0;
+ msg = "<= Recv header";
+ break;
case CURLINFO_DATA_IN:
- _LOG2T("libcurl <= Recv data");
- return 0;
+ msg = "<= Recv data";
+ break;
case CURLINFO_SSL_DATA_IN:
- _LOG2T("libcurl <= Recv SSL data");
- return 0;
+ msg = "<= Recv SSL data";
+ break;
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 ?: "");
+ print_data = TRUE;
+ msg = "=> Send header: ";
+ return 0;
+ default:
return 0;
}
+
+ _LOG2T("libcurl %s%s%s%s",
+ msg,
+ NM_PRINT_FMT_QUOTED(print_data,
+ "[",
+ (data_escaped = nm_utils_buf_utf8safe_escape_cp(
+ data,
+ size,
+ NM_UTILS_STR_UTF8_SAFE_FLAG_ESCAPE_CTRL))
+ ?: "",
+ "]",
+ ""));
+ return 0;
}
#endif