]> git.meshlink.io Git - catta/commitdiff
* Beef up simple protocol with error codes
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Aug 2005 19:26:12 +0000 (19:26 +0000)
committerLennart Poettering <lennart@poettering.net>
Fri, 5 Aug 2005 19:26:12 +0000 (19:26 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@239 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-common/dbus.h
avahi-core/core.h
avahi-core/server.c
avahi-daemon/dbus-protocol.c
avahi-daemon/simple-protocol.c

index 64696d2760e0fa9f9a9b2dd7f315d5cf542ea0b0..b21d1fd83bdd20639cb0c6fbd1453480fe70990d 100644 (file)
@@ -51,6 +51,8 @@ AVAHI_C_DECL_BEGIN
 #define AVAHI_DBUS_ERR_TOO_MANY_OBJECTS "org.freedesktop.Avahi.TooManyObjectsError"
 #define AVAHI_DBUS_ERR_TOO_MANY_ENTRIES "org.freedesktop.Avahi.TooManyEntriesError"
 #define AVAHI_DBUS_ERR_OS "org.freedesktop.Avahi.OSError"
+#define AVAHI_DBUS_ERR_ACCESS_DENIED DBUS_ERROR_ACCESS_DENIED
+#define AVAHI_DBUS_ERR_INVALID_OPERATION "org.freedesktop.Avahi.InvalidOperationError"
 
 AVAHI_C_DECL_END
 
index 1adf244e8a98a4e47349766db736969a2317e0a8..2951f6d34efc41f381a096e8f28bc4ce950ffb68 100644 (file)
@@ -83,7 +83,8 @@ enum {
     AVAHI_ERR_TOO_MANY_ENTRIES = -18,      /**< Too many entries */
     AVAHI_ERR_OS = -19,                    /**< OS error */
     AVAHI_ERR_ACCESS_DENIED = -20,         /**< Access denied */
-    AVAHI_ERR_MAX = -21
+    AVAHI_ERR_INVALID_OPERATION = -21,     /**< Invalid operation */
+    AVAHI_ERR_MAX = -22
 };
 
 /** States of a server object */
index c4acf35db1e1544417e6df52d1510bbaac7844d9..541c7b729b298441bd037b3545d076d75f135735 100644 (file)
@@ -2318,7 +2318,8 @@ const gchar *avahi_strerror(gint error) {
         "Too many objects",
         "Too many entries",
         "OS Error",
-        "Access denied"
+        "Access denied",
+        "Invalid operation"
     };
 
     return msg[-error];
index a87712d88132c72103f5232b16afcb5661eae320..eb7b913732ee016588c578bac7aaf2ea49e15460 100644 (file)
@@ -343,7 +343,8 @@ static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, gint e
         AVAHI_DBUS_ERR_TOO_MANY_OBJECTS,
         AVAHI_DBUS_ERR_TOO_MANY_ENTRIES,
         AVAHI_DBUS_ERR_OS,
-        DBUS_ERROR_ACCESS_DENIED
+        AVAHI_DBUS_ERR_ACCESS_DENIED,
+        AVAHI_DBUS_ERR_INVALID_OPERATION
     };
 
     g_assert(-error > -AVAHI_OK);
index f7c3f1eb2cff56e0f9050499421bc0632a89a4ef..d41cda523fd5cd44855d37278eb52d2a0485a3e2 100644 (file)
@@ -171,7 +171,7 @@ static void host_name_resolver_callback(AvahiHostNameResolver *r, AvahiIfIndex i
 
 
     if (event == AVAHI_RESOLVER_TIMEOUT)
-        client_output_printf(c, "- Query timed out\n");
+        client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_TIMEOUT);
     else {
         gchar t[64];
         avahi_address_snprint(t, sizeof(t), a);
@@ -188,7 +188,7 @@ static void address_resolver_callback(AvahiAddressResolver *r, AvahiIfIndex ifac
     g_assert(c);
 
     if (event == AVAHI_RESOLVER_TIMEOUT)
-        client_output_printf(c, "- Query timed out\n");
+        client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_TIMEOUT);
     else 
         client_output_printf(c, "+ %i %u %s\n", iface, protocol, hostname);
 
@@ -219,7 +219,7 @@ static void handle_line(Client *c, const gchar *s) {
         return;
 
     if ((n_args = sscanf(s, "%63s %63s", cmd, arg)) < 1 ) {
-        client_output_printf(c, "- Failed to parse command, try \"HELP\".\n");
+        client_output_printf(c, "%+i Failed to parse command, try \"HELP\".\n", AVAHI_ERR_INVALID_OPERATION);
         c->state = CLIENT_DEAD;
         return;
     }
@@ -236,43 +236,56 @@ static void handle_line(Client *c, const gchar *s) {
                              "+      BROWSE-DNS-SERVERS-IPV6\n");
         c->state = CLIENT_DEAD; }
     else if (strcmp(cmd, "FUCK") == 0 && n_args == 1) {
-        client_output_printf(c, "FUCK: Go fuck yourself!\n");
+        client_output_printf(c, "FUCK: Go fuck yourself!\n");
         c->state = CLIENT_DEAD;
     } else if (strcmp(cmd, "RESOLVE-HOSTNAME-IPV4") == 0 && n_args == 2) {
         c->state = CLIENT_RESOLVE_HOSTNAME;
-        c->host_name_resolver = avahi_host_name_resolver_new(avahi_server, -1, AF_UNSPEC, arg, c->afquery = AF_INET, host_name_resolver_callback, c);
+        if (!(c->host_name_resolver = avahi_host_name_resolver_new(avahi_server, -1, AF_UNSPEC, arg, c->afquery = AF_INET, host_name_resolver_callback, c)))
+            goto fail;
     } else if (strcmp(cmd, "RESOLVE-HOSTNAME-IPV6") == 0 && n_args == 2) {
         c->state = CLIENT_RESOLVE_HOSTNAME;
-        c->host_name_resolver = avahi_host_name_resolver_new(avahi_server, -1, AF_UNSPEC, arg, c->afquery = AF_INET6, host_name_resolver_callback, c);
+        if (!(c->host_name_resolver = avahi_host_name_resolver_new(avahi_server, -1, AF_UNSPEC, arg, c->afquery = AF_INET6, host_name_resolver_callback, c)))
+            goto fail;
     } else if (strcmp(cmd, "RESOLVE-HOSTNAME") == 0 && n_args == 2) {
         c->state = CLIENT_RESOLVE_HOSTNAME;
-        c->host_name_resolver = avahi_host_name_resolver_new(avahi_server, -1, AF_UNSPEC, arg, c->afquery = AF_UNSPEC, host_name_resolver_callback, c);
+        if (!(c->host_name_resolver = avahi_host_name_resolver_new(avahi_server, -1, AF_UNSPEC, arg, c->afquery = AF_UNSPEC, host_name_resolver_callback, c)))
+            goto fail;
     } else if (strcmp(cmd, "RESOLVE-ADDRESS") == 0 && n_args == 2) {
         AvahiAddress addr;
         
         if (!(avahi_address_parse(arg, AF_UNSPEC, &addr))) {
-            client_output_printf(c, "- Failed to parse address \"%s\".\n", arg);
+            client_output_printf(c, "%+i Failed to parse address \"%s\".\n", AVAHI_ERR_INVALID_ADDRESS, arg);
             c->state = CLIENT_DEAD;
         } else {
             c->state = CLIENT_RESOLVE_ADDRESS;
-            c->address_resolver = avahi_address_resolver_new(avahi_server, -1, AF_UNSPEC, &addr, address_resolver_callback, c);
+            if (!(c->address_resolver = avahi_address_resolver_new(avahi_server, -1, AF_UNSPEC, &addr, address_resolver_callback, c)))
+                goto fail;
         }
     } else if (strcmp(cmd, "BROWSE-DNS-SERVERS-IPV4") == 0 && n_args == 1) {
         c->state = CLIENT_BROWSE_DNS_SERVERS;
-        c->dns_server_browser = avahi_dns_server_browser_new(avahi_server, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery = AF_INET, dns_server_browser_callback, c);
+        if (!(c->dns_server_browser = avahi_dns_server_browser_new(avahi_server, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery = AF_INET, dns_server_browser_callback, c)))
+            goto fail;
         client_output_printf(c, "+ Browsing ...\n");
     } else if (strcmp(cmd, "BROWSE-DNS-SERVERS-IPV6") == 0 && n_args == 1) {
         c->state = CLIENT_BROWSE_DNS_SERVERS;
-        c->dns_server_browser = avahi_dns_server_browser_new(avahi_server, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery = AF_INET6, dns_server_browser_callback, c);
+        if (!(c->dns_server_browser = avahi_dns_server_browser_new(avahi_server, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery = AF_INET6, dns_server_browser_callback, c)))
+            goto fail;
         client_output_printf(c, "+ Browsing ...\n");
     } else if (strcmp(cmd, "BROWSE-DNS-SERVERS") == 0 && n_args == 1) {
         c->state = CLIENT_BROWSE_DNS_SERVERS;
-        c->dns_server_browser = avahi_dns_server_browser_new(avahi_server, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery = AF_UNSPEC, dns_server_browser_callback, c);
+        if (!(c->dns_server_browser = avahi_dns_server_browser_new(avahi_server, -1, AF_UNSPEC, NULL, AVAHI_DNS_SERVER_RESOLVE, c->afquery = AF_UNSPEC, dns_server_browser_callback, c)))
+            goto fail;
         client_output_printf(c, "+ Browsing ...\n");
     } else {
-        client_output_printf(c, "- Invalid command \"%s\", try \"HELP\".\n", cmd);
+        client_output_printf(c, "%+i Invalid command \"%s\", try \"HELP\".\n", AVAHI_ERR_INVALID_OPERATION, cmd);
         c->state = CLIENT_DEAD;
     }
+
+    return;
+
+fail:
+    client_output_printf(c, "%+i %s\n", avahi_server_errno(avahi_server), avahi_strerror(avahi_server_errno(avahi_server)));
+    c->state = CLIENT_DEAD;
 }
 
 static void handle_input(Client *c) {