From: Felix Fietkau Date: Thu, 18 Apr 2024 12:28:09 +0000 (+0200) Subject: lib: add log_msg callback to get more detailed log messages X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=c2bf660d88ece757ebc4889ef30ec2fa11fb1e9e;p=project%2Fuclient.git lib: add log_msg callback to get more detailed log messages Signed-off-by: Felix Fietkau --- diff --git a/uclient-http.c b/uclient-http.c index d6e9dcf..0b70ede 100644 --- a/uclient-http.c +++ b/uclient-http.c @@ -861,17 +861,23 @@ static void uclient_ssl_notify_state(struct ustream *us) static void uclient_ssl_notify_error(struct ustream_ssl *ssl, int error, const char *str) { struct uclient_http *uh = container_of(ssl, struct uclient_http, ussl); + struct uclient *uc = &uh->uc; + if (uc->cb->log_msg) + uc->cb->log_msg(uc, UCLIENT_LOG_SSL_ERROR, str); uclient_http_error(uh, UCLIENT_ERROR_CONNECT); } static void uclient_ssl_notify_verify_error(struct ustream_ssl *ssl, int error, const char *str) { struct uclient_http *uh = container_of(ssl, struct uclient_http, ussl); + struct uclient *uc = &uh->uc; if (!uh->ssl_require_validation) return; + if (uc->cb->log_msg) + uc->cb->log_msg(uc, UCLIENT_LOG_SSL_VERIFY_ERROR, str); uclient_http_error(uh, UCLIENT_ERROR_SSL_INVALID_CERT); } diff --git a/uclient.h b/uclient.h index 5ccda74..772a5bd 100644 --- a/uclient.h +++ b/uclient.h @@ -39,6 +39,12 @@ enum uclient_error_code { __UCLIENT_ERROR_MAX }; +enum uclient_log_type { + UCLIENT_LOG_SSL_ERROR, + UCLIENT_LOG_SSL_VERIFY_ERROR, + __UCLIENT_LOG_MAX +}; + union uclient_addr { struct sockaddr sa; struct sockaddr_in sin; @@ -85,6 +91,7 @@ struct uclient_cb { void (*data_eof)(struct uclient *cl); void (*header_done)(struct uclient *cl); void (*error)(struct uclient *cl, int code); + void (*log_msg)(struct uclient *cl, enum uclient_log_type type, const char *msg); }; struct uclient *uclient_new(const char *url, const char *auth_str, const struct uclient_cb *cb);