#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) {
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;
}
}
/* 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;
#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"
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;
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);