From 3632da5dea3a2e961729664d17808d98bfc2b325 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Nov 2005 00:07:12 +0000 Subject: [PATCH] Map DBUS specific errors to Avahi counterparts git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1026 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-client/client.c | 9 +++++++-- avahi-common/dbus.c | 31 ++++++++++++++++++++++++++++++- avahi-common/dbus.h | 3 +++ avahi-common/error.c | 3 ++- avahi-common/error.h | 3 ++- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/avahi-client/client.c b/avahi-client/client.c index 54d19e5..3c86bd6 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -544,8 +544,13 @@ fail: if (dbus_error_is_set(&error)) { - if (ret_error) - *ret_error = avahi_error_dbus_to_number(error.name); + if (ret_error) { + if (strcmp(error.name, DBUS_ERROR_FILE_NOT_FOUND) == 0) + /* DBUS returns this error when the DBUS daemon is not running */ + *ret_error = AVAHI_ERR_NO_DAEMON; + else + *ret_error = avahi_error_dbus_to_number(error.name); + } dbus_error_free(&error); } diff --git a/avahi-common/dbus.c b/avahi-common/dbus.c index fc4b34b..8140164 100644 --- a/avahi-common/dbus.c +++ b/avahi-common/dbus.c @@ -86,11 +86,36 @@ static const char * const table[- AVAHI_ERR_MAX] = { AVAHI_DBUS_ERR_INVALID_DNS_TYPE, AVAHI_DBUS_ERR_NOT_SUPPORTED, - AVAHI_DBUS_ERR_NOT_PERMITTED + AVAHI_DBUS_ERR_NOT_PERMITTED, + AVAHI_DBUS_ERR_INVALID_ARGUMENT +}; + +struct error_map { + const char *dbus_error; + int avahi_error; +}; + +static struct error_map error_map[] = { + { DBUS_ERROR_FAILED, AVAHI_ERR_FAILURE }, + { DBUS_ERROR_NO_MEMORY, AVAHI_ERR_NO_MEMORY }, + { DBUS_ERROR_SERVICE_UNKNOWN, AVAHI_ERR_NO_DAEMON }, + { DBUS_ERROR_BAD_ADDRESS, AVAHI_ERR_NO_DAEMON }, + { DBUS_ERROR_NOT_SUPPORTED, AVAHI_ERR_NOT_SUPPORTED }, + { DBUS_ERROR_LIMITS_EXCEEDED, AVAHI_ERR_TOO_MANY_OBJECTS }, + { DBUS_ERROR_ACCESS_DENIED, AVAHI_ERR_ACCESS_DENIED }, + { DBUS_ERROR_AUTH_FAILED, AVAHI_ERR_ACCESS_DENIED }, + { DBUS_ERROR_NO_SERVER, AVAHI_ERR_NO_DAEMON }, + { DBUS_ERROR_TIMEOUT, AVAHI_ERR_TIMEOUT }, + { DBUS_ERROR_NO_NETWORK, AVAHI_ERR_NO_NETWORK }, + { DBUS_ERROR_DISCONNECTED, AVAHI_ERR_DISCONNECTED }, + { DBUS_ERROR_INVALID_ARGS, AVAHI_ERR_INVALID_ARGUMENT }, + { DBUS_ERROR_TIMED_OUT, AVAHI_ERR_TIMEOUT }, + { NULL, 0 } }; int avahi_error_dbus_to_number(const char *s) { int e; + const struct error_map *m; assert(s); @@ -98,6 +123,10 @@ int avahi_error_dbus_to_number(const char *s) { if (strcmp(s, table[-e]) == 0) return e; + for (m = error_map; m->dbus_error; m++) + if (strcmp(m->dbus_error, s) == 0) + return m->avahi_error; + return AVAHI_ERR_DBUS_ERROR; } diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h index 790fc3c..eb29581 100644 --- a/avahi-common/dbus.h +++ b/avahi-common/dbus.h @@ -95,7 +95,10 @@ AVAHI_C_DECL_BEGIN #define AVAHI_DBUS_ERR_INVALID_DNS_CLASS "org.freedesktop.Avahi.InvalidDNSClassError" #define AVAHI_DBUS_ERR_INVALID_DNS_TYPE "org.freedesktop.Avahi.InvalidDNSTypeError" #define AVAHI_DBUS_ERR_NOT_SUPPORTED "org.freedesktop.Avahi.NotSupportedError" + #define AVAHI_DBUS_ERR_NOT_PERMITTED "org.freedesktop.Avahi.NotPermittedError" +#define AVAHI_DBUS_ERR_INVALID_ARGUMENT "org.freedesktop.Avahi.InvalidArgument" + /** Convert a DBus error string into an Avahi error number */ int avahi_error_dbus_to_number(const char *s); diff --git a/avahi-common/error.c b/avahi-common/error.c index 6c0a900..6fe981c 100644 --- a/avahi-common/error.c +++ b/avahi-common/error.c @@ -83,7 +83,8 @@ const char *avahi_strerror(int error) { "Invalid DNS class", "Not supported", - "Not permitted" + "Not permitted", + "Invalid argument" }; if (-error < 0 || -error >= -AVAHI_ERR_MAX) diff --git a/avahi-common/error.h b/avahi-common/error.h index d6c4620..8060ebc 100644 --- a/avahi-common/error.h +++ b/avahi-common/error.h @@ -86,6 +86,7 @@ enum { AVAHI_ERR_NOT_SUPPORTED = -49, /**< Not supported */ AVAHI_ERR_NOT_PERMITTED = -50, /**< Operation not permitted */ + AVAHI_ERR_INVALID_ARGUMENT = -51, /**< Invalid argument */ /**** **** IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD @@ -95,7 +96,7 @@ enum { **** Also remember to update the MAX value below. ****/ - AVAHI_ERR_MAX = -51 + AVAHI_ERR_MAX = -52 }; /** Return a human readable error string for the specified error code */ -- 2.39.5