summaryrefslogtreecommitdiff
path: root/src/journal-remote/microhttpd-util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-13 21:07:45 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2015-03-13 23:42:16 -0400
commitd357562c48ac71e2197ea63bc57671a29ba12cf6 (patch)
tree8e140514518ee711a591f83c13cb7d09bfe10684 /src/journal-remote/microhttpd-util.c
parent1b14c3cfbe25f9bf1183bd26875f3c68847559c0 (diff)
µhttp-util: setup gnutls logs in one function
Diffstat (limited to 'src/journal-remote/microhttpd-util.c')
-rw-r--r--src/journal-remote/microhttpd-util.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c
index b45c38d682..8a11fba044 100644
--- a/src/journal-remote/microhttpd-util.c
+++ b/src/journal-remote/microhttpd-util.c
@@ -121,7 +121,7 @@ static struct {
{ {"9", "enc", "int"}, LOG_DEBUG },
};
-void log_func_gnutls(int level, const char *message) {
+static void log_func_gnutls(int level, const char *message) {
assert_se(message);
if (0 <= level && level < (int) ELEMENTSOF(gnutls_log_map)) {
@@ -133,7 +133,18 @@ void log_func_gnutls(int level, const char *message) {
}
}
-int log_enable_gnutls_category(const char *cat) {
+static void log_reset_gnutls_level(void) {
+ int i;
+
+ for (i = ELEMENTSOF(gnutls_log_map) - 1; i >= 0; i--)
+ if (gnutls_log_map[i].enabled) {
+ log_debug("Setting gnutls log level to %d", i);
+ gnutls_global_set_log_level(i);
+ break;
+ }
+}
+
+static int log_enable_gnutls_category(const char *cat) {
unsigned i;
if (streq(cat, "all")) {
@@ -152,15 +163,22 @@ int log_enable_gnutls_category(const char *cat) {
return -EINVAL;
}
-void log_reset_gnutls_level(void) {
- int i;
+int setup_gnutls_logger(char **categories) {
+ char **cat;
+ int r;
- for (i = ELEMENTSOF(gnutls_log_map) - 1; i >= 0; i--)
- if (gnutls_log_map[i].enabled) {
- log_debug("Setting gnutls log level to %d", i);
- gnutls_global_set_log_level(i);
- break;
+ gnutls_global_set_log_function(log_func_gnutls);
+
+ if (categories) {
+ STRV_FOREACH(cat, categories) {
+ r = log_enable_gnutls_category(*cat);
+ if (r < 0)
+ return r;
}
+ } else
+ log_reset_gnutls_level();
+
+ return 0;
}
static int verify_cert_authorized(gnutls_session_t session) {
@@ -300,4 +318,10 @@ int check_permissions(struct MHD_Connection *connection, int *code, char **hostn
int check_permissions(struct MHD_Connection *connection, int *code, char **hostname) {
return -EPERM;
}
+
+int setup_gnutls_logger(char **categories) {
+ if (categories)
+ log_notice("Ignoring specified gnutls logging categories — gnutls not available.");
+ return 0;
+}
#endif