]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/dbus-entry-group.c
socket: minor beautification
[catta] / avahi-daemon / dbus-entry-group.c
index 1d8c957a79e1f490bf3b2ed465cab4c8e0b8707e..4e879a5ba215db16f3ba8b788a0b423c94048426 100644 (file)
@@ -1,18 +1,16 @@
-/* $Id$ */
-
 /***
   This file is part of avahi.
+
   avahi is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1 of the
   License, or (at your option) any later version.
+
   avahi is distributed in the hope that it will be useful, but WITHOUT
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
   Public License for more details.
+
   You should have received a copy of the GNU Lesser General Public
   License along with avahi; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
@@ -40,13 +38,16 @@ void avahi_dbus_entry_group_free(EntryGroupInfo *i) {
 
     if (i->entry_group)
         avahi_s_entry_group_free(i->entry_group);
-    dbus_connection_unregister_object_path(server->bus, i->path);
-    avahi_free(i->path);
+
+    if (i->path) {
+        dbus_connection_unregister_object_path(server->bus, i->path);
+        avahi_free(i->path);
+    }
     AVAHI_LLIST_REMOVE(EntryGroupInfo, entry_groups, i->client->entry_groups, i);
 
+    assert(i->client->n_objects >= 1);
     i->client->n_objects--;
-    assert(i->client->n_objects >= 0);
-    
+
     avahi_free(i);
 }
 
@@ -55,13 +56,18 @@ void avahi_dbus_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiE
     DBusMessage *m;
     int32_t t;
     const char *e;
-    
+
     assert(s);
     assert(g);
     assert(i);
 
     m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged");
-    
+
+    if (!m) {
+        avahi_log_error("Failed allocate message");
+        return;
+    }
+
     t = (int32_t) state;
     if (state == AVAHI_ENTRY_GROUP_FAILURE)
         e = avahi_error_number_to_dbus(avahi_server_errno(s));
@@ -69,13 +75,13 @@ void avahi_dbus_entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiE
         e = AVAHI_DBUS_ERR_COLLISION;
     else
         e = AVAHI_DBUS_ERR_OK;
-        
+
     dbus_message_append_args(
         m,
         DBUS_TYPE_INT32, &t,
         DBUS_TYPE_STRING, &e,
         DBUS_TYPE_INVALID);
-    dbus_message_set_destination(m, i->client->name);  
+    dbus_message_set_destination(m, i->client->name);
     dbus_connection_send(server->bus, m, NULL);
     dbus_message_unref(m);
 }
@@ -87,7 +93,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
     assert(c);
     assert(m);
     assert(i);
-    
+
     dbus_error_init(&error);
 
     avahi_log_debug(__FILE__": interface=%s, path=%s, member=%s",
@@ -97,12 +103,12 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
     /* Introspection */
     if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
-        return avahi_dbus_handle_introspect(c, m, "EntryGroup.introspect");
-    
+        return avahi_dbus_handle_introspect(c, m, "org.freedesktop.Avahi.EntryGroup.xml");
+
     /* Access control */
-    if (strcmp(dbus_message_get_sender(m), i->client->name)) 
+    if (strcmp(dbus_message_get_sender(m), i->client->name))
         return avahi_dbus_respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
-    
+
     if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Free")) {
 
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
@@ -112,7 +118,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
         avahi_dbus_entry_group_free(i);
         return avahi_dbus_respond_ok(c, m);
-        
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Commit")) {
 
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
@@ -122,21 +128,21 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
         if (avahi_s_entry_group_commit(i->entry_group) < 0)
             return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
-        
+
         return avahi_dbus_respond_ok(c, m);
-        
-        
+
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Reset")) {
-        
+
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
             avahi_log_warn("Error parsing EntryGroup::Reset message");
             goto fail;
         }
 
         avahi_s_entry_group_reset(i->entry_group);
-       i->n_entries = 0;
+        i->n_entries = 0;
         return avahi_dbus_respond_ok(c, m);
-        
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty")) {
 
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
@@ -145,10 +151,10 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
         }
 
         return avahi_dbus_respond_boolean(c, m, !!avahi_s_entry_group_is_empty(i->entry_group));
-        
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) {
         AvahiEntryGroupState state;
-        
+
         if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
             avahi_log_warn("Error parsing EntryGroup::GetState message");
             goto fail;
@@ -156,14 +162,14 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
         state = avahi_s_entry_group_get_state(i->entry_group);
         return avahi_dbus_respond_int32(c, m, (int32_t) state);
-        
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) {
         int32_t interface, protocol;
         uint32_t flags;
         char *type, *name, *domain, *host;
         uint16_t port;
         AvahiStringList *strlst = NULL;
-        
+
         if (!dbus_message_get_args(
                 m, &error,
                 DBUS_TYPE_INT32, &interface,
@@ -173,7 +179,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
                 DBUS_TYPE_STRING, &type,
                 DBUS_TYPE_STRING, &domain,
                 DBUS_TYPE_STRING, &host,
-                DBUS_TYPE_UINT16, &port, 
+                DBUS_TYPE_UINT16, &port,
                 DBUS_TYPE_INVALID) ||
             !type || !name ||
             avahi_dbus_read_strlst(m, 8, &strlst) < 0) {
@@ -181,7 +187,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
             goto fail;
         }
 
-        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX) {
+        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max) {
             avahi_string_list_free(strlst);
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
         }
@@ -199,17 +205,17 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
         if (!(flags & AVAHI_PUBLISH_UPDATE))
             i->n_entries ++;
-            
+
         avahi_string_list_free(strlst);
-        
+
         return avahi_dbus_respond_ok(c, m);
-        
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddServiceSubtype")) {
 
         int32_t interface, protocol;
         uint32_t flags;
         char *type, *name, *domain, *subtype;
-        
+
         if (!dbus_message_get_args(
                 m, &error,
                 DBUS_TYPE_INT32, &interface,
@@ -224,18 +230,18 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
             goto fail;
         }
 
-        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX)
+        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max)
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
 
         if (domain && !*domain)
             domain = NULL;
 
-        if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0) 
+        if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0)
             return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
 
         if (!(flags & AVAHI_PUBLISH_UPDATE))
             i->n_entries ++;
-        
+
         return avahi_dbus_respond_ok(c, m);
 
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "UpdateServiceTxt")) {
@@ -243,7 +249,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
         uint32_t flags;
         char *type, *name, *domain;
         AvahiStringList *strlst;
-        
+
         if (!dbus_message_get_args(
                 m, &error,
                 DBUS_TYPE_INT32, &interface,
@@ -268,15 +274,15 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
         }
 
         avahi_string_list_free(strlst);
-        
+
         return avahi_dbus_respond_ok(c, m);
-        
+
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) {
         int32_t interface, protocol;
         uint32_t flags;
         char *name, *address;
         AvahiAddress a;
-        
+
         if (!dbus_message_get_args(
                 m, &error,
                 DBUS_TYPE_INT32, &interface,
@@ -289,9 +295,9 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
             goto fail;
         }
 
-        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX)
+        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max)
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
-        
+
         if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a)))
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
 
@@ -300,7 +306,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
         if (!(flags & AVAHI_PUBLISH_UPDATE))
             i->n_entries ++;
-        
+
         return avahi_dbus_respond_ok(c, m);
     } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddRecord")) {
         int32_t interface, protocol;
@@ -309,7 +315,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
         char *name;
         void *rdata;
         AvahiRecord *r;
-        
+
         if (!dbus_message_get_args(
                 m, &error,
                 DBUS_TYPE_INT32, &interface,
@@ -325,7 +331,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
             goto fail;
         }
 
-        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= ENTRIES_PER_ENTRY_GROUP_MAX)
+        if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= server->n_entries_per_entry_group_max)
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
 
         if (!avahi_is_valid_domain_name (name))
@@ -338,7 +344,7 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
             avahi_record_unref (r);
             return avahi_dbus_respond_error(c, m, AVAHI_ERR_INVALID_RDATA, NULL);
         }
-        
+
         if (avahi_server_add(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, r) < 0) {
             avahi_record_unref (r);
             return avahi_dbus_respond_error(c, m, avahi_server_errno(avahi_server), NULL);
@@ -346,18 +352,18 @@ DBusHandlerResult avahi_dbus_msg_entry_group_impl(DBusConnection *c, DBusMessage
 
         if (!(flags & AVAHI_PUBLISH_UPDATE))
             i->n_entries ++;
-       
-        avahi_record_unref (r); 
+
+        avahi_record_unref (r);
 
         return avahi_dbus_respond_ok(c, m);
-    } 
-    
+    }
+
+
     avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
 
 fail:
     if (dbus_error_is_set(&error))
         dbus_error_free(&error);
-    
+
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }