]> git.meshlink.io Git - catta/commitdiff
* rename some DBUS errrors
authorLennart Poettering <lennart@poettering.net>
Mon, 26 Sep 2005 00:07:05 +0000 (00:07 +0000)
committerLennart Poettering <lennart@poettering.net>
Mon, 26 Sep 2005 00:07:05 +0000 (00:07 +0000)
* add new VERSION_MISMATCH error

git-svn-id: file:///home/lennart/svn/public/avahi/trunk@630 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-client/client.c
avahi-common/dbus.c
avahi-common/dbus.h
avahi-common/error.c
avahi-common/error.h

index 6df3e03446c68c4854532bb1550ddf52f8919646..ae3d7388502a5c8a155ef3b96c4061897621d568 100644 (file)
@@ -245,10 +245,10 @@ fail:
 }
 
 static int get_server_state(AvahiClient *client, int *ret_error) {
-    DBusMessage *message, *reply;
+    DBusMessage *message = NULL, *reply = NULL;
     DBusError error;
     int32_t state;
-    int e;
+    int e = AVAHI_ERR_NO_MEMORY;
     
     assert(client);
 
@@ -258,31 +258,88 @@ static int get_server_state(AvahiClient *client, int *ret_error) {
         goto fail;
 
     reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
-    dbus_message_unref(message);
 
-    if (!reply)
+    if (!reply || dbus_error_is_set (&error))
         goto fail;
 
-    if (!(dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID)))
+    if (!(dbus_message_get_args(reply, &error, DBUS_TYPE_INT32, &state, DBUS_TYPE_INVALID)) ||
+        dbus_error_is_set (&error))
         goto fail;
 
     client_set_state(client, (AvahiServerState) state);
 
+    dbus_message_unref(message);
+    dbus_message_unref(reply);
+    
+    return AVAHI_OK;
+
+fail:
+    if (dbus_error_is_set(&error)) {
+        e = avahi_error_dbus_to_number (error.name);
+        dbus_error_free(&error);
+    } 
+    
+    if (ret_error)
+        *ret_error = e;
+
+    if (message)
+        dbus_message_unref(message);
+    if (reply)
+        dbus_message_unref(reply);
+    
+    return e;
+}
+
+static int check_version(AvahiClient *client, int *ret_error) {
+    DBusMessage *message = NULL, *reply  = NULL;
+    DBusError error;
+    char *version;
+    int e = AVAHI_ERR_NO_MEMORY;
+    
+    assert(client);
+
+    dbus_error_init(&error);
+
+    if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString")))
+        goto fail;
+
+    reply = dbus_connection_send_with_reply_and_block (client->bus, message, -1, &error);
+
+    if (!reply || dbus_error_is_set (&error))
+        goto fail;
+
+    if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &version, DBUS_TYPE_INVALID) ||
+        dbus_error_is_set (&error))
+        goto fail;
+
+    if (strcmp(version, PACKAGE_STRING) != 0) {
+        e = AVAHI_ERR_VERSION_MISMATCH;
+        goto fail;
+    }
+
+    dbus_message_unref(message);
+    dbus_message_unref(reply);
+               
     return AVAHI_OK;
 
 fail:
     if (dbus_error_is_set(&error)) {
         e = avahi_error_dbus_to_number (error.name);
         dbus_error_free(&error);
-    } else
-        e = AVAHI_ERR_NO_MEMORY;
+    } 
 
     if (ret_error)
         *ret_error = e;
-        
+
+    if (message)
+        dbus_message_unref(message);
+    if (reply)
+        dbus_message_unref(reply);
+    
     return e;
 }
 
+
 /* This function acts like dbus_bus_get but creates a private
  * connection instead */
 static DBusConnection*
@@ -411,6 +468,9 @@ AvahiClient *avahi_client_new(const AvahiPoll *poll_api, AvahiClientCallback cal
     if (get_server_state(client, ret_error) < 0)
         goto fail;
 
+    if (check_version(client, ret_error) < 0)
+        goto fail;
+
     return client;
 
 fail:
index 28428ed1f4a0d0ae2932dcaa2c221e845802922f..14d1b2b9cd910562035275960a65b8957d70ad0d 100644 (file)
@@ -62,7 +62,8 @@ static const char * const table[- AVAHI_ERR_MAX] = {
     AVAHI_DBUS_ERR_INVALID_PROTOCOL,
     AVAHI_DBUS_ERR_INVALID_FLAGS,
     AVAHI_DBUS_ERR_NOT_FOUND,
-    AVAHI_DBUS_ERR_INVALID_CONFIG
+    AVAHI_DBUS_ERR_INVALID_CONFIG,
+    AVAHI_DBUS_ERR_VERSION_MISMATCH
 };
 
 int avahi_error_dbus_to_number(const char *s) {
index cd90af1ab82269fe63f70812267958bfbeab1458..5f2acffae075ebd60b48ac71da10ba322f15493f 100644 (file)
@@ -69,10 +69,11 @@ AVAHI_C_DECL_BEGIN
 #define AVAHI_DBUS_ERR_INVALID_OBJECT "org.freedesktop.Avahi.InvalidObjectError"
 #define AVAHI_DBUS_ERR_NO_DAEMON "org.freedesktop.Avahi.NoDaemonError"
 #define AVAHI_DBUS_ERR_INVALID_INTERFACE "org.freedesktop.Avahi.InvalidInterfaceError"
-#define AVAHI_DBUS_ERR_INVALID_PROTOCOL "org.freedesktop.Avahi.InvalidInterfaceProtocol"
-#define AVAHI_DBUS_ERR_INVALID_FLAGS "org.freedesktop.Avahi.InvalidFlags"
-#define AVAHI_DBUS_ERR_NOT_FOUND "org.freedesktop.Avahi.NotFound"
-#define AVAHI_DBUS_ERR_INVALID_CONFIG "org.freedesktop.Avahi.InvalidConfiguration"
+#define AVAHI_DBUS_ERR_INVALID_PROTOCOL "org.freedesktop.Avahi.InvalidInterfaceProtocolError"
+#define AVAHI_DBUS_ERR_INVALID_FLAGS "org.freedesktop.Avahi.InvalidFlagsError"
+#define AVAHI_DBUS_ERR_NOT_FOUND "org.freedesktop.Avahi.NotFoundError"
+#define AVAHI_DBUS_ERR_INVALID_CONFIG "org.freedesktop.Avahi.InvalidConfigurationError"
+#define AVAHI_DBUS_ERR_VERSION_MISMATCH "org.freedesktop.Avahi.VersionMismatchError"
 
 /** Convert a DBus error string into an Avahi error number */
 int avahi_error_dbus_to_number(const char *s);
index 73f13d2df85297d440f1f458d4adb852ab62cf36..42423616213313083bf0bc004d03a51883c7efb8 100644 (file)
@@ -59,7 +59,8 @@ const char *avahi_strerror(int error) {
         "Invalid protocol specification",
         "Invalid flags",
         "Not found",
-        "Invalid configuration"
+        "Invalid configuration",
+        "Version mismatch"
     };
 
     if (-error < 0 || -error >= -AVAHI_ERR_MAX)
index 2b06c5a83e4a841217b498dc48c5ce9910ea41b0..851c600ca376e7f99d5e7b50be556a55d9b9edf0 100644 (file)
@@ -64,6 +64,7 @@ enum {
     AVAHI_ERR_INVALID_FLAGS = -29,         /**< Invalid flags */
     AVAHI_ERR_NOT_FOUND = -30,             /**< Not found */
     AVAHI_ERR_INVALID_CONFIG = -31,        /**< Configuration error */
+    AVAHI_ERR_VERSION_MISMATCH = -32,      /**< Verson mismatch */
 
     /****
      ****    IF YOU ADD A NEW ERROR CODE HERE, PLEASE DON'T FORGET TO ADD
@@ -73,7 +74,7 @@ enum {
      ****    Also remember to update the MAX value below.
      ****/
     
-    AVAHI_ERR_MAX = -32
+    AVAHI_ERR_MAX = -33
 };
 
 /** Return a human readable error string for the specified error code */