]> git.meshlink.io Git - catta/commitdiff
Add DBUS API versioning
authorLennart Poettering <lennart@poettering.net>
Thu, 24 Nov 2005 01:30:44 +0000 (01:30 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 24 Nov 2005 01:30:44 +0000 (01:30 +0000)
git-svn-id: file:///home/lennart/svn/public/avahi/trunk@1027 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe

avahi-client/client.c
avahi-common/dbus.h
avahi-daemon/Server.introspect
avahi-daemon/dbus-protocol.c

index 3c86bd689403646d78739281d3cd2e6268828f6a..754fdaf0d998118745f72005f80d662f0f8ef120 100644 (file)
@@ -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;
index eb2958146a581b31f0edc4b3fca0eb9f0053d335..84d5d2d4a3919a866d0aced3eba12a773a1a16a7 100644 (file)
@@ -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"
index ec2f0420d835b4004b780a55b0a1849d65b3ec60..5a3f88bbfa88b7a32f0d70aa2bf6288c70c5b9c5 100644 (file)
   </interface>
 
   <interface name="org.freedesktop.Avahi.Server">
+
     <method name="GetVersionString">
       <arg name="version" type="s" direction="out"/>
     </method>
 
+    <method name="GetAPIVersion">
+      <arg name="version" type="u" direction="out"/>
+    </method>
+
     <method name="GetHostName">
       <arg name="name" type="s" direction="out"/>
     </method>
index f01837a478898560e61362d8ad41e46f54d75dff..bd26c8c046beaabe8fa10e4844c91333be223afa 100644 (file)
@@ -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);