]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/static-hosts.c
* avahi-core/dns.c: Use a '#define AVAHI_DNS_LABELS_MAX 127' instead of the hard...
[catta] / avahi-daemon / static-hosts.c
index aba96f720e82e548a4680e54511fce29dc88f7bf..9941a51dcc56bc566dd5eb812679b8335b0c2b93 100644 (file)
@@ -66,11 +66,11 @@ static void entry_group_callback(AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGro
             break;
 
         case AVAHI_ENTRY_GROUP_ESTABLISHED:
-            avahi_log_notice ("Static Host \"%s\" successfully established.", h->host);
+            avahi_log_notice ("Static host name \"%s\" successfully established.", h->host);
             break;
 
         case AVAHI_ENTRY_GROUP_FAILURE:
-            avahi_log_notice ("Failed to establish Static Host \"%s\": %s.", h->host, avahi_strerror (avahi_server_errno (s)));
+            avahi_log_notice ("Failed to establish static host name \"%s\": %s.", h->host, avahi_strerror (avahi_server_errno (s)));
             break;
         
         case AVAHI_ENTRY_GROUP_UNCOMMITED:
@@ -98,7 +98,8 @@ static void static_host_free(StaticHost *s) {
 
     AVAHI_LLIST_REMOVE(StaticHost, hosts, hosts, s);
 
-    avahi_s_entry_group_free (s->group);
+    if (s->group)
+        avahi_s_entry_group_free (s->group);
 
     avahi_free(s->host);
     avahi_free(s->ip);
@@ -112,15 +113,18 @@ static void add_static_host_to_server(StaticHost *h)
     int err;
 
     if (!h->group)
-        h->group = avahi_s_entry_group_new (avahi_server, entry_group_callback, h);
+        if (!(h->group = avahi_s_entry_group_new (avahi_server, entry_group_callback, h))) {
+            avahi_log_error("avahi_s_entry_group_new() failed: %s", avahi_strerror(err));
+            return;
+        }
 
     if (!avahi_address_parse (h->ip, AVAHI_PROTO_UNSPEC, &a)) {
-        avahi_log_error("Static host %s: avahi_address_parse failed", h->host);
+        avahi_log_error("Static host name %s: avahi_address_parse failed", h->host);
         return;
     }
 
     if ((err = avahi_server_add_address(avahi_server, h->group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, h->host, &a))) {
-        avahi_log_error ("Static host %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err));
+        avahi_log_error ("Static host name %s: avahi_server_add_address failure: %s", h->host, avahi_strerror(err));
         return;
     }
 
@@ -129,7 +133,8 @@ static void add_static_host_to_server(StaticHost *h)
 
 static void remove_static_host_from_server(StaticHost *h)
 {
-    avahi_s_entry_group_reset (h->group);
+    if (h->group)
+        avahi_s_entry_group_reset (h->group);
 }
  
 void static_hosts_add_to_server(void) {
@@ -171,54 +176,59 @@ void static_hosts_load(int in_chroot) {
 
         line++;
 
-               /* Find the start of the line, ignore whitespace */
-               s = ln + strspn(ln, " \t");
-               /* Set the end of the string to NULL */
-               s[strcspn(s, "#\r\n")] = 0;
+        /* Find the start of the line, ignore whitespace */
+        s = ln + strspn(ln, " \t");
+        /* Set the end of the string to NULL */
+        s[strcspn(s, "#\r\n")] = 0;
 
-               /* Ignore comment (#) and blank lines (*/
-               if (*s == '#' || *s == 0)
-                       continue;
+        /* Ignore blank lines */
+        if (*s == 0)
+            continue;
 
-               /* Read the first string (ip) up to the next whitespace */
-               len = strcspn(s, " \t");
-               ip = avahi_strndup(s, len);
+        /* Read the first string (ip) up to the next whitespace */
+        len = strcspn(s, " \t");
+        ip = avahi_strndup(s, len);
 
-               /* Skip past it */
-               s += len;
+        /* Skip past it */
+        s += len;
 
-               /* Find the next token */
-               s += strspn(s, " \t");
-               len = strcspn(s, " \t");
-               host = avahi_strndup(s, len);
+        /* Find the next token */
+        s += strspn(s, " \t");
+        len = strcspn(s, " \t");
+        host = avahi_strndup(s, len);
 
-               if (*host == 0)
-               {
-                       avahi_log_error ("%s:%d: Error, unexpected end of line!", filename, line);
-            break;
-               }
+        if (*host == 0)
+        {
+            avahi_log_error("%s:%d: Error, unexpected end of line!", filename, line);
+            avahi_free(host);
+            avahi_free(ip);
+           break;
+        }
+
+        /* Skip over the host */
+        s += len;
 
         /* Skip past any more spaces */
-               s += strspn(s+len, " \t");
+        s += strspn(s, " \t");
         
         /* Anything left? */
-               if (*(s+len) != 0) {
-                       avahi_log_error ("%s:%d: Junk on the end of the line!", filename, line);
+        if (*s != 0) {
+            avahi_log_error ("%s:%d: Junk on the end of the line!", filename, line);
+            avahi_free(host);
+            avahi_free(ip);
             break;
-               }
+        }
 
         h = static_host_new();
         h->host = host;
         h->ip = ip;
     }
+
+    fclose(f);
 }
 
 void static_hosts_free_all (void)
 {
-    StaticHost *h;
-
-    for (h = hosts; h; h = hosts->hosts_next)
-    {
-        static_host_free (h);
-    }
+    while(hosts)
+        static_host_free(hosts);
 }