]> git.meshlink.io Git - meshlink/commitdiff
route avahi log to meshlink log
authorNiklas Hofmann <niklas.hofmann@everbase.net>
Sat, 9 Aug 2014 12:49:53 +0000 (14:49 +0200)
committerNiklas Hofmann <niklas.hofmann@everbase.net>
Sat, 9 Aug 2014 12:49:53 +0000 (14:49 +0200)
src/discovery.c

index cf1dd5e214fb19c34271fa9af540b4edb9331ebf..b50aea8d80f689991355db5dac9269eb292fa06e 100644 (file)
@@ -9,6 +9,7 @@
 #include <avahi-core/core.h>
 #include <avahi-core/lookup.h>
 #include <avahi-core/publish.h>
+#include <avahi-core/log.h>
 #include <avahi-common/simple-watch.h>
 #include <avahi-common/malloc.h>
 #include <avahi-common/alternative.h>
@@ -400,6 +401,33 @@ static void *discovery_loop(void *userdata)
     return NULL;
 }
 
+static void discovery_log_cb(AvahiLogLevel level, const char *txt)
+{
+    meshlink_log_level_t mlevel = MESHLINK_CRITICAL;
+
+    switch(level)
+    {
+    case AVAHI_LOG_ERROR:
+        mlevel = MESHLINK_ERROR;
+        break;
+
+    case AVAHI_LOG_WARN:
+        mlevel = MESHLINK_WARNING;
+        break;
+
+    case AVAHI_LOG_NOTICE:
+    case AVAHI_LOG_INFO:
+        mlevel = MESHLINK_INFO;
+        break;
+
+    case AVAHI_LOG_DEBUG:
+        mlevel = MESHLINK_DEBUG;
+        break;
+    }
+
+    logger(NULL, mlevel, "%s\n", txt);
+}
+
 bool discovery_start(meshlink_handle_t *mesh)
 {
     logger(mesh, MESHLINK_DEBUG, "discovery_start called\n");
@@ -412,6 +440,9 @@ bool discovery_start(meshlink_handle_t *mesh)
     assert(mesh->discovery_threadstarted == false);
     assert(mesh->avahi_servicetype == NULL);
 
+    // handle avahi logs
+    avahi_set_log_function(discovery_log_cb);
+    
     // create service type string
     size_t servicetype_strlen = sizeof(MESHLINK_MDNS_SERVICE_TYPE) + strlen(mesh->appname) + 1;
     mesh->avahi_servicetype = malloc(servicetype_strlen);