]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/static-services.c
* add C examples
[catta] / avahi-daemon / static-services.c
index 898edf3a2144a8f39d2cdaa8f97ff07dd98849b9..8c54eab6d11494bcef273736917ddd3f7dd509f3 100644 (file)
@@ -38,6 +38,7 @@
 #include <avahi-core/log.h>
 
 #include "main.h"
+#include "static-services.h"
 
 typedef struct StaticService StaticService;
 typedef struct StaticServiceGroup StaticServiceGroup;
@@ -151,7 +152,8 @@ static void static_service_free(StaticService *s) {
 static void static_service_group_free(StaticServiceGroup *g) {
     g_assert(g);
 
-    remove_static_service_group_from_server(g);
+    if (g->entry_group)
+        avahi_entry_group_free(g->entry_group);
 
     while (g->services)
         static_service_free(g->services);
@@ -201,8 +203,11 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
         g->chosen_name = replacestr(g->name, "%h", avahi_server_get_host_name(avahi_server));
     else
         g->chosen_name = g_strdup(g->name);
-    
-    g->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, g);
+
+    if (!g->entry_group)
+        g->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, g);
+
+    g_assert(avahi_entry_group_is_empty(g->entry_group));
     
     for (s = g->services; s; s = s->services_next) {
 
@@ -210,9 +215,9 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
                 avahi_server,
                 g->entry_group,
                 -1, AF_UNSPEC,
-                s->type, g->chosen_name,
+                g->chosen_name, s->type, 
                 s->domain_name, s->host_name, s->port,
-                avahi_string_list_copy(s->txt_records)) < 0) {
+                s->txt_records) < 0) {
             avahi_log_error("Failed to add service '%s' of type '%s', ignoring service group (%s)", g->chosen_name, s->type, g->filename);
             remove_static_service_group_from_server(g);
             return;
@@ -225,10 +230,8 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
 static void remove_static_service_group_from_server(StaticServiceGroup *g) {
     g_assert(g);
 
-    if (g->entry_group) {
-        avahi_entry_group_free(g->entry_group);
-        g->entry_group = NULL;
-    }
+    if (g->entry_group)
+        avahi_entry_group_reset(g->entry_group);
 }
 
 typedef enum {
@@ -590,8 +593,8 @@ void static_service_load(void) {
     }
 
     memset(&globbuf, 0, sizeof(globbuf));
-    if (glob(AVAHI_SERVICE_DIRECTORY "/*.service", GLOB_ERR, NULL, &globbuf) != 0)
-        avahi_log_error("glob() failed.\n");
+    if (glob(AVAHI_SERVICE_DIR "/*.service", GLOB_ERR, NULL, &globbuf) != 0)
+        avahi_log_error("Failed to read service directory.");
     else {
         for (p = globbuf.gl_pathv; *p; p++)
             load_file(*p);