summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-09-26 00:07:05 +0000
committerLennart Poettering <lennart@poettering.net>2005-09-26 00:07:05 +0000
commit8782ae678cf60713b5513016f16b039251c40870 (patch)
treece1057e89d56ac38acd3350af8041e9940599133
parentb2839754a3d1e15a3009561e69b41608014af0cb (diff)
* rename some DBUS errrors
* add new VERSION_MISMATCH error git-svn-id: file:///home/lennart/svn/public/avahi/trunk@630 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--avahi-client/client.c76
-rw-r--r--avahi-common/dbus.c3
-rw-r--r--avahi-common/dbus.h9
-rw-r--r--avahi-common/error.c3
-rw-r--r--avahi-common/error.h3
5 files changed, 79 insertions, 15 deletions
diff --git a/avahi-client/client.c b/avahi-client/client.c
index 6df3e03..ae3d738 100644
--- a/avahi-client/client.c
+++ b/avahi-client/client.c
@@ -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:
diff --git a/avahi-common/dbus.c b/avahi-common/dbus.c
index 28428ed..14d1b2b 100644
--- a/avahi-common/dbus.c
+++ b/avahi-common/dbus.c
@@ -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) {
diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h
index cd90af1..5f2acff 100644
--- a/avahi-common/dbus.h
+++ b/avahi-common/dbus.h
@@ -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);
diff --git a/avahi-common/error.c b/avahi-common/error.c
index 73f13d2..4242361 100644
--- a/avahi-common/error.c
+++ b/avahi-common/error.c
@@ -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)
diff --git a/avahi-common/error.h b/avahi-common/error.h
index 2b06c5a..851c600 100644
--- a/avahi-common/error.h
+++ b/avahi-common/error.h
@@ -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 */