From bf0db10cd964b708a77d2e1768500f57a1392023 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 5 Aug 2005 19:26:12 +0000 Subject: [PATCH] * Beef up simple protocol with error codes git-svn-id: file:///home/lennart/svn/public/avahi/trunk@239 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-common/dbus.h | 2 ++ avahi-core/core.h | 3 ++- avahi-core/server.c | 3 ++- avahi-daemon/dbus-protocol.c | 3 ++- avahi-daemon/simple-protocol.c | 39 ++++++++++++++++++++++------------ 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h index 64696d2..b21d1fd 100644 --- a/avahi-common/dbus.h +++ b/avahi-common/dbus.h @@ -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 diff --git a/avahi-core/core.h b/avahi-core/core.h index 1adf244..2951f6d 100644 --- a/avahi-core/core.h +++ b/avahi-core/core.h @@ -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 */ diff --git a/avahi-core/server.c b/avahi-core/server.c index c4acf35..541c7b7 100644 --- a/avahi-core/server.c +++ b/avahi-core/server.c @@ -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]; diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index a87712d..eb7b913 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -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); diff --git a/avahi-daemon/simple-protocol.c b/avahi-daemon/simple-protocol.c index f7c3f1e..d41cda5 100644 --- a/avahi-daemon/simple-protocol.c +++ b/avahi-daemon/simple-protocol.c @@ -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) { -- 2.39.5