#include <config.h>
#endif
-#include <glib.h>
#include <string.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include <errno.h>
+#include <unistd.h>
+#include <glib.h>
#define DBUS_API_SUBJECT_TO_CHANGE
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
-#include <avahi-core/llist.h>
+#include <avahi-common/llist.h>
#include <avahi-core/log.h>
#include <avahi-core/core.h>
#include <avahi-common/dbus.h>
#define MAX_OBJECTS_PER_CLIENT 50
#define MAX_ENTRIES_PER_ENTRY_GROUP 20
+/* #define VALGRIND_WORKAROUND */
+
struct EntryGroupInfo {
guint id;
Client *client;
return client;
}
-static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, const gchar *error, const gchar *text) {
+static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, gint error, const gchar *text) {
DBusMessage *reply;
- reply = dbus_message_new_error(m, error, text);
+ const gchar * const table[- AVAHI_ERR_MAX] = {
+ NULL, /* OK */
+ AVAHI_DBUS_ERR_FAILURE,
+ AVAHI_DBUS_ERR_BAD_STATE,
+ AVAHI_DBUS_ERR_INVALID_HOST_NAME,
+ AVAHI_DBUS_ERR_INVALID_DOMAIN_NAME,
+ AVAHI_DBUS_ERR_NO_NETWORK,
+ AVAHI_DBUS_ERR_INVALID_TTL,
+ AVAHI_DBUS_ERR_IS_PATTERN,
+ AVAHI_DBUS_ERR_LOCAL_COLLISION,
+ AVAHI_DBUS_ERR_INVALID_RECORD,
+ AVAHI_DBUS_ERR_INVALID_SERVICE_NAME,
+ AVAHI_DBUS_ERR_INVALID_SERVICE_TYPE,
+ AVAHI_DBUS_ERR_INVALID_PORT,
+ AVAHI_DBUS_ERR_INVALID_KEY,
+ AVAHI_DBUS_ERR_INVALID_ADDRESS,
+ AVAHI_DBUS_ERR_TIMEOUT,
+ AVAHI_DBUS_ERR_TOO_MANY_CLIENTS,
+ AVAHI_DBUS_ERR_TOO_MANY_OBJECTS,
+ AVAHI_DBUS_ERR_TOO_MANY_ENTRIES,
+ AVAHI_DBUS_ERR_OS,
+ AVAHI_DBUS_ERR_ACCESS_DENIED,
+ AVAHI_DBUS_ERR_INVALID_OPERATION
+ };
+
+ g_assert(-error > -AVAHI_OK);
+ g_assert(-error < -AVAHI_ERR_MAX);
+
+ reply = dbus_message_new_error(m, table[-error], text ? text : avahi_strerror(error));
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
+static DBusHandlerResult respond_int32(DBusConnection *c, DBusMessage *m, gint32 i) {
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return(m);
+ dbus_message_append_args(reply, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID);
+ dbus_connection_send(c, reply, NULL);
+ dbus_message_unref(reply);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
static DBusHandlerResult respond_ok(DBusConnection *c, DBusMessage *m) {
DBusMessage *reply;
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-
static void entry_group_callback(AvahiServer *s, AvahiEntryGroup *g, AvahiEntryGroupState state, gpointer userdata) {
EntryGroupInfo *i = userdata;
DBusMessage *m;
/* Access control */
if (strcmp(dbus_message_get_sender(m), i->client->name))
- return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
+ return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "Free")) {
goto fail;
}
- b = avahi_entry_group_is_empty(i->entry_group);
-
+ b = !!avahi_entry_group_is_empty(i->entry_group);
+
reply = dbus_message_new_method_return(m);
- dbus_message_append_args(m, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID);
+ dbus_message_append_args(reply, DBUS_TYPE_BOOLEAN, &b, DBUS_TYPE_INVALID);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "GetState")) {
- DBusMessage *reply;
- gint32 t;
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing EntryGroup::GetState message");
goto fail;
}
- t = (gint32) avahi_entry_group_get_state(i->entry_group);
- reply = dbus_message_new_method_return(m);
- dbus_message_append_args(reply, DBUS_TYPE_INT32, &t, DBUS_TYPE_INVALID);
- dbus_connection_send(c, reply, NULL);
- dbus_message_unref(reply);
-
- return DBUS_HANDLER_RESULT_HANDLED;
+ return respond_int32(c, m, (gint32) avahi_entry_group_get_state(i->entry_group));
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) {
gint32 interface, protocol;
gchar *type, *name, *domain, *host;
guint16 port;
- gchar **txt = NULL;
- gint txt_len;
AvahiStringList *strlst;
+ DBusMessageIter iter, sub;
+ int j;
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_STRING, &host,
DBUS_TYPE_UINT16, &port,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &txt, &txt_len,
- DBUS_TYPE_INVALID) || !type || !*type || !name || !*name || !port) {
+ DBUS_TYPE_INVALID) || !type || !name) {
avahi_log_warn("Error parsing EntryGroup::AddService message");
goto fail;
}
+ dbus_message_iter_init(m, &iter);
+
+ for (j = 0; j < 7; j++)
+ dbus_message_iter_next(&iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
+ dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_ARRAY) {
+ avahi_log_warn("Error parsing EntryGroup::AddService message 2");
+ goto fail;
+ }
+
+ strlst = NULL;
+ dbus_message_iter_recurse(&iter, &sub);
+
+ for (;;) {
+ DBusMessageIter sub2;
+ int at, n;
+ guint8 *k;
+
+ if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
+ break;
+
+ g_assert(at == DBUS_TYPE_ARRAY);
+
+ if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) {
+ avahi_log_warn("Error parsing EntryGroup::AddService message");
+ goto fail;
+ }
+
+ dbus_message_iter_recurse(&sub, &sub2);
+ dbus_message_iter_get_fixed_array(&sub2, &k, &n);
+ strlst = avahi_string_list_add_arbitrary(strlst, k, n);
+
+ dbus_message_iter_next(&sub);
+ }
+
if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
+ avahi_string_list_free(strlst);
avahi_log_warn("Too many entries per entry group, client request failed.");
- dbus_free_string_array(txt);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_ENTRIES, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
}
- strlst = avahi_string_list_new_from_array((const gchar**) txt, txt_len);
- dbus_free_string_array(txt);
-
if (domain && !*domain)
domain = NULL;
host = NULL;
if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, host, port, strlst) < 0) {
- avahi_log_warn("Failed to add service: %s", name);
avahi_string_list_free(strlst);
- return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_SERVICE, NULL);
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
} else
i->n_entries ++;
DBUS_TYPE_INT32, &protocol,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID) || !name || !*name || !address || !*address) {
+ DBUS_TYPE_INVALID) || !name || !address) {
avahi_log_warn("Error parsing EntryGroup::AddAddress message");
goto fail;
}
if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
avahi_log_warn("Too many entries per entry group, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_ENTRIES, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
}
if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))) {
- avahi_log_warn("Error parsing address data");
- return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
+ return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
}
- if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0) {
- avahi_log_warn("Failed to add service: %s", name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
- } else
+ if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, 0, name, &a) < 0)
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
+ else
i->n_entries ++;
return respond_ok(c, m);
static void host_name_resolver_callback(AvahiHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata) {
HostNameResolverInfo *i = userdata;
- DBusMessage *reply;
g_assert(r);
g_assert(host_name);
if (event == AVAHI_RESOLVER_FOUND) {
char t[256], *pt = t;
gint32 i_interface, i_protocol, i_aprotocol;
+ DBusMessage *reply;
g_assert(a);
avahi_address_snprint(t, sizeof(t), a);
DBUS_TYPE_STRING, &pt,
DBUS_TYPE_INVALID);
+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
} else {
g_assert(event == AVAHI_RESOLVER_TIMEOUT);
- reply = dbus_message_new_error(i->message, AVAHI_DBUS_ERROR_TIMEOUT, NULL);
- }
- dbus_connection_send(server->bus, reply, NULL);
- dbus_message_unref(reply);
+ respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
+ }
host_name_resolver_free(i);
}
static void address_resolver_callback(AvahiAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const gchar *host_name, gpointer userdata) {
AddressResolverInfo *i = userdata;
- DBusMessage *reply;
g_assert(r);
g_assert(address);
if (event == AVAHI_RESOLVER_FOUND) {
char t[256], *pt = t;
gint32 i_interface, i_protocol, i_aprotocol;
+ DBusMessage *reply;
g_assert(host_name);
avahi_address_snprint(t, sizeof(t), address);
DBUS_TYPE_STRING, &host_name,
DBUS_TYPE_INVALID);
+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
} else {
g_assert(event == AVAHI_RESOLVER_TIMEOUT);
- reply = dbus_message_new_error(i->message, AVAHI_DBUS_ERROR_TIMEOUT, NULL);
+ respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
}
- dbus_connection_send(server->bus, reply, NULL);
- dbus_message_unref(reply);
-
address_resolver_free(i);
}
/* Access control */
if (strcmp(dbus_message_get_sender(m), i->client->name))
- return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
+ return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, "Free")) {
/* Access control */
if (strcmp(dbus_message_get_sender(m), i->client->name))
- return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
+ return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, "Free")) {
/* Introspection */
if (dbus_message_is_method_call(m, DBUS_INTERFACE_INTROSPECTABLE, "Introspect"))
- return handle_introspect(c, m, "ServiceBrowser.introspect");
+ return handle_introspect(c, m, "ServiceBrowser.Introspect");
/* Access control */
if (strcmp(dbus_message_get_sender(m), i->client->name))
- return respond_error(c, m, DBUS_ERROR_ACCESS_DENIED, NULL);
+ return respond_error(c, m, AVAHI_ERR_ACCESS_DENIED, NULL);
if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, "Free")) {
gpointer userdata) {
ServiceResolverInfo *i = userdata;
- DBusMessage *reply;
g_assert(r);
g_assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
char t[256], *pt = t;
gint32 i_interface, i_protocol, i_aprotocol;
- gchar **array;
guint n, j;
AvahiStringList *p;
+ DBusMessage *reply;
+ DBusMessageIter iter, sub;
g_assert(host_name);
i_protocol = (gint32) protocol;
i_aprotocol = (gint32) a->family;
- array = g_new(gchar*, (n = avahi_string_list_length(txt)));
-
- /** FIXME: DBUS doesn't support strings that include NUL bytes (?) */
- for (p = txt, j = n-1; p; p = p->next, j--)
- array[j] = g_strndup((gchar*) p->text, p->size);
-
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
reply,
DBUS_TYPE_INT32, &i_aprotocol,
DBUS_TYPE_STRING, &pt,
DBUS_TYPE_UINT16, &port,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &array, n,
DBUS_TYPE_INVALID);
- for (j = 0; j < n; j++)
- g_free(array[j]);
+ dbus_message_iter_init_append(reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "ay", &sub);
+
+ for (p = txt, j = n-1; p; p = p->next, j--) {
+ DBusMessageIter sub2;
+ const guint8 *data = p->text;
+
+ dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2);
+ dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size);
+ dbus_message_iter_close_container(&sub, &sub2);
+ }
+ dbus_message_iter_close_container(&iter, &sub);
+
+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
} else {
g_assert(event == AVAHI_RESOLVER_TIMEOUT);
- reply = dbus_message_new_error(i->message, AVAHI_DBUS_ERROR_TIMEOUT, NULL);
- }
- dbus_connection_send(server->bus, reply, NULL);
- dbus_message_unref(reply);
+ respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
+ }
service_resolver_free(i);
}
-
static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
DBusError error;
return respond_string(c, m, PACKAGE_STRING);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetState")) {
- DBusMessage *reply;
- gint32 s;
-
+
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INVALID))) {
avahi_log_warn("Error parsing Server::GetState message");
goto fail;
}
- s = (gint32) avahi_server_get_state(avahi_server);
+ return respond_int32(c, m, (gint32) avahi_server_get_state(avahi_server));
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
+ gint32 idx;
+ int fd;
+ struct ifreq ifr;
- reply = dbus_message_new_method_return(m);
- dbus_message_append_args(reply, DBUS_TYPE_INT32, &s, DBUS_TYPE_INVALID);
- dbus_connection_send(c, reply, NULL);
- dbus_message_unref(reply);
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &idx, DBUS_TYPE_INVALID))) {
+ avahi_log_warn("Error parsing Server::GetNetworkInterfaceNameByIndex message");
+ goto fail;
+ }
+
+#ifdef VALGRIND_WORKAROUND
+ return respond_string(c, m, "blah");
+#else
- return DBUS_HANDLER_RESULT_HANDLED;
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ ifr.ifr_ifindex = idx;
+
+ if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ close(fd);
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ close(fd);
+
+ return respond_string(c, m, ifr.ifr_name);
+#endif
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
+ gchar *n;
+ int fd;
+ struct ifreq ifr;
+
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
+ avahi_log_warn("Error parsing Server::GetNetworkInterfaceIndexByName message");
+ goto fail;
+ }
+
+#ifdef VALGRIND_WORKAROUND
+ return respond_int32(c, m, 1);
+#else
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ memset(&ifr, 0, sizeof(ifr));
+ g_snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", n);
+
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
+ gchar txt[256];
+ g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ close(fd);
+ return respond_error(c, m, AVAHI_ERR_OS, txt);
+ }
+
+ close(fd);
+
+ return respond_int32(c, m, ifr.ifr_ifindex);
+#endif
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) {
gchar *n, * t;
- if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n || !*n) {
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetAlternativeHostName message");
goto fail;
}
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
gchar *n, *t;
- if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n || !*n) {
+ if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetAlternativeServiceName message");
goto fail;
}
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
i = g_new(EntryGroupInfo, 1);
client->n_objects++;
if (!(i->entry_group = avahi_entry_group_new(avahi_server, entry_group_callback, i))) {
- avahi_log_warn("Failed to create entry group");
entry_group_free(i);
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
dbus_connection_register_object_path(c, i->path, &vtable, i);
DBUS_TYPE_INT32, &protocol,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INT32, &aprotocol,
- DBUS_TYPE_INVALID) || !name || !*name) {
+ DBUS_TYPE_INVALID) || !name) {
avahi_log_warn("Error parsing Server::ResolveHostName message");
goto fail;
}
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
i = g_new(HostNameResolverInfo, 1);
if (!(i->host_name_resolver = avahi_host_name_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, (AvahiProtocol) aprotocol, host_name_resolver_callback, i))) {
host_name_resolver_free(i);
- avahi_log_warn("Failed to create host name resolver");
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
return DBUS_HANDLER_RESULT_HANDLED;
DBUS_TYPE_INT32, &interface,
DBUS_TYPE_INT32, &protocol,
DBUS_TYPE_STRING, &address,
- DBUS_TYPE_INVALID) || !address || !*address) {
+ DBUS_TYPE_INVALID) || !address) {
avahi_log_warn("Error parsing Server::ResolveAddress message");
goto fail;
}
- if (!avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a)) {
- avahi_log_warn("Error parsing address data");
- return respond_error(c, m, AVAHI_DBUS_ERROR_INVALID_ADDRESS, NULL);
- }
+ if (!avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))
+ return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
i = g_new(AddressResolverInfo, 1);
if (!(i->address_resolver = avahi_address_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, &a, address_resolver_callback, i))) {
address_resolver_free(i);
- avahi_log_warn("Failed to create address resolver");
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
return DBUS_HANDLER_RESULT_HANDLED;
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
if (!*domain)
client->n_objects++;
if (!(i->domain_browser = avahi_domain_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, (AvahiDomainBrowserType) type, domain_browser_callback, i))) {
- avahi_log_warn("Failed to create domain browser");
domain_browser_free(i);
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
dbus_connection_register_object_path(c, i->path, &vtable, i);
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
if (!*domain)
client->n_objects++;
if (!(i->service_type_browser = avahi_service_type_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, domain, service_type_browser_callback, i))) {
- avahi_log_warn("Failed to create service type browser");
service_type_browser_free(i);
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
dbus_connection_register_object_path(c, i->path, &vtable, i);
DBUS_TYPE_INT32, &protocol,
DBUS_TYPE_STRING, &type,
DBUS_TYPE_STRING, &domain,
- DBUS_TYPE_INVALID) || !type || !*type) {
+ DBUS_TYPE_INVALID) || !type) {
avahi_log_warn("Error parsing Server::ServiceBrowserNew message");
goto fail;
}
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
if (!*domain)
client->n_objects++;
if (!(i->service_browser = avahi_service_browser_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, type, domain, service_browser_callback, i))) {
- avahi_log_warn("Failed to create service browser");
service_browser_free(i);
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
dbus_connection_register_object_path(c, i->path, &vtable, i);
DBUS_TYPE_STRING, &type,
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_INT32, &aprotocol,
- DBUS_TYPE_INVALID) || !name || !*name || !type || !*type) {
+ DBUS_TYPE_INVALID) || !name || !type) {
avahi_log_warn("Error parsing Server::ResolveService message");
goto fail;
}
if (!(client = client_get(dbus_message_get_sender(m), TRUE))) {
avahi_log_warn("Too many clients, client request failed.");
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_CLIENTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_CLIENTS, NULL);
}
if (client->n_objects >= MAX_OBJECTS_PER_CLIENT) {
avahi_log_warn("Too many objects for client '%s', client request failed.", client->name);
- return respond_error(c, m, AVAHI_DBUS_ERROR_TOO_MANY_OBJECTS, NULL);
+ return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
if (!*domain)
if (!(i->service_resolver = avahi_service_resolver_new(avahi_server, (AvahiIfIndex) interface, (AvahiProtocol) protocol, name, type, domain, (AvahiProtocol) aprotocol, service_resolver_callback, i))) {
service_resolver_free(i);
- avahi_log_warn("Failed to create service resolver");
- goto fail;
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
return DBUS_HANDLER_RESULT_HANDLED;