From be4aaeb485d31dee095b0c9c90e6b79333bc0e21 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 24 Nov 2005 01:30:44 +0000 Subject: [PATCH] Add DBUS API versioning git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1027 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-client/client.c | 52 ++++++++++++++++++++++++++++------ avahi-common/dbus.h | 9 ++++++ avahi-daemon/Server.introspect | 5 ++++ avahi-daemon/dbus-protocol.c | 10 ++++++- 4 files changed, 66 insertions(+), 10 deletions(-) diff --git a/avahi-client/client.c b/avahi-client/client.c index 3c86bd6..754fdaf 100644 --- a/avahi-client/client.c +++ b/avahi-client/client.c @@ -39,6 +39,8 @@ #include "client.h" #include "internal.h" +#define AVAHI_CLIENT_DBUS_API_SUPPORTED ((uint32_t) 0x0201) + static int init_server(AvahiClient *client, int *ret_error); int avahi_client_set_errno (AvahiClient *client, int error) { @@ -345,26 +347,57 @@ fail: static int check_version(AvahiClient *client, int *ret_error) { DBusMessage *message = NULL, *reply = NULL; DBusError error; - char *version; + uint32_t 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"))) + if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "GetAPIVersion"))) 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 (!reply || dbus_error_is_set (&error)) { + char *version_str; - if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &version, DBUS_TYPE_INVALID) || - dbus_error_is_set (&error)) - goto fail; + if (!dbus_error_is_set(&error) || strcmp(error.name, DBUS_ERROR_UNKNOWN_METHOD)) + goto fail; + + /* If the method GetAPIVersion is not known, we look if + * GetVersionString matches "avahi 0.6" which is the only + * version we support which doesn't have GetAPIVersion() .*/ + + dbus_message_unref(message); + if (reply) dbus_message_unref(reply); + dbus_error_free(&error); + + if (!(message = dbus_message_new_method_call(AVAHI_DBUS_NAME, AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "GetVersionString"))) + goto fail; - if (strcmp(version, PACKAGE_STRING) != 0) { + 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_str, DBUS_TYPE_INVALID) || + dbus_error_is_set (&error)) + goto fail; + + version = strcmp(version_str, "avahi 0.6") == 0 ? 0x0201 : 0x0000; + + } else { + + if (!dbus_message_get_args (reply, &error, DBUS_TYPE_UINT32, &version, DBUS_TYPE_INVALID) || + dbus_error_is_set(&error)) + goto fail; + } + + fprintf(stderr, "API Version 0x%04x\n", version); + + if ((version & 0xFF00) != (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0xFF00) || + (version & 0x00FF) < (AVAHI_CLIENT_DBUS_API_SUPPORTED & 0x00FF)) { e = AVAHI_ERR_VERSION_MISMATCH; goto fail; } @@ -404,7 +437,8 @@ static int init_server(AvahiClient *client, int *ret_error) { } /* This function acts like dbus_bus_get but creates a private - * connection instead */ + * connection instead. Eventually this should be replaced by a DBUS + * provided version. */ static DBusConnection* avahi_dbus_bus_get(DBusError *error) { DBusConnection *c; const char *a; diff --git a/avahi-common/dbus.h b/avahi-common/dbus.h index eb29581..84d5d2d 100644 --- a/avahi-common/dbus.h +++ b/avahi-common/dbus.h @@ -41,6 +41,15 @@ AVAHI_C_DECL_BEGIN #define AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER AVAHI_DBUS_NAME".ServiceResolver" #define AVAHI_DBUS_INTERFACE_RECORD_BROWSER AVAHI_DBUS_NAME".RecordBrowser" +/** The DBUS API version identifier. The first byte specifies the API +release, the second byte specifies the revision. If the revision +number is increased the API has been extended but is downwards +compatible. If the release changes compatibility is lost. + +Avahi 0.6 implements API version 0x0201; +Avahi 0.6.1 implements API version 0x0202 */ +#define AVAHI_DBUS_API_VERSION ((uint32_t) 0x0202) + #define AVAHI_DBUS_ERR_OK "org.freedesktop.Avahi.Success" #define AVAHI_DBUS_ERR_FAILURE "org.freedesktop.Avahi.Failure" #define AVAHI_DBUS_ERR_BAD_STATE "org.freedesktop.Avahi.BadStateError" diff --git a/avahi-daemon/Server.introspect b/avahi-daemon/Server.introspect index ec2f042..5a3f88b 100644 --- a/avahi-daemon/Server.introspect +++ b/avahi-daemon/Server.introspect @@ -32,10 +32,15 @@ + + + + + diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index f01837a..bd26c8c 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -261,6 +261,15 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_string(c, m, PACKAGE_STRING); + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAPIVersion")) { + + if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) { + avahi_log_warn("Error parsing Server::GetAPIVersion message"); + goto fail; + } + + return avahi_dbus_respond_uint32(c, m, AVAHI_DBUS_API_VERSION); + } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) { AvahiServerState state; @@ -594,7 +603,6 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL); } - if (client->n_objects >= OBJECTS_PER_CLIENT_MAX) { avahi_log_warn("Too many objects for client '%s', client request failed.", client->name); return avahi_dbus_respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL); -- 2.39.5