}
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);
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*
if (get_server_state(client, ret_error) < 0)
goto fail;
+ if (check_version(client, ret_error) < 0)
+ goto fail;
+
return client;
fail:
#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);
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
**** 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 */