if (!text)
text = avahi_strerror(error);
- reply = dbus_message_new_error(m, avahi_error_number_to_dbus (error), text);
+ reply = dbus_message_new_error(m, avahi_error_number_to_dbus(error), text);
dbus_connection_send(c, reply, NULL);
dbus_message_unref(reply);
return DBUS_HANDLER_RESULT_HANDLED;
}
+static void append_server_error(DBusMessage *reply) {
+ const char *t;
+
+ t = avahi_error_number_to_dbus(avahi_server_errno(avahi_server));
+
+ dbus_message_append_args(
+ reply,
+ DBUS_TYPE_STRING, &t,
+ DBUS_TYPE_INVALID);
+}
+
static char *file_get_contents(char *fname) {
int fd = -1;
struct stat st;
case AVAHI_BROWSER_NEW : return "ItemNew";
case AVAHI_BROWSER_REMOVE : return "ItemRemove";
case AVAHI_BROWSER_FAILURE : return "Failure";
- case AVAHI_BROWSER_NOT_FOUND : return "NotFound";
case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CacheExhausted";
case AVAHI_BROWSER_ALL_FOR_NOW : return "AllForNow";
}
static const char *map_resolve_signal_name(AvahiResolverEvent e) {
switch (e) {
case AVAHI_RESOLVER_FOUND : return "Found";
- case AVAHI_RESOLVER_TIMEOUT : return "Timeout";
case AVAHI_RESOLVER_FAILURE : return "Failure";
- case AVAHI_RESOLVER_NOT_FOUND : return "NotFound";
}
abort();
}
-static int map_resolve_error(AvahiResolverEvent e) {
-
- switch(e) {
- case AVAHI_RESOLVER_FOUND : abort();
- case AVAHI_RESOLVER_TIMEOUT : return AVAHI_ERR_TIMEOUT;
- case AVAHI_RESOLVER_FAILURE : return AVAHI_ERR_FAILURE;
- case AVAHI_RESOLVER_NOT_FOUND : return AVAHI_ERR_NOT_FOUND;
- }
-
- abort();
-}
static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
char *path, *contents;
dbus_message_unref(m);
}
+static int read_strlst(DBusMessage *m, int idx, AvahiStringList **l) {
+ DBusMessageIter iter, sub;
+ int j;
+ AvahiStringList *strlst = NULL;
+
+ assert(m);
+ assert(l);
+
+ dbus_message_iter_init(m, &iter);
+
+ for (j = 0; j < idx; 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)
+ goto fail;
+
+ dbus_message_iter_recurse(&iter, &sub);
+
+ for (;;) {
+ DBusMessageIter sub2;
+ int at, n;
+ uint8_t *k;
+
+ if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
+ break;
+
+ assert(at == DBUS_TYPE_ARRAY);
+
+ if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE)
+ 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);
+ }
+
+ *l = strlst;
+
+ return 0;
+
+fail:
+ avahi_log_warn("Error parsing TXT data");
+
+ avahi_string_list_free(strlst);
+ *l = NULL;
+ return -1;
+}
+
+
static DBusHandlerResult msg_entry_group_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
DBusError error;
EntryGroupInfo *i = userdata;
uint32_t flags;
char *type, *name, *domain, *host;
uint16_t port;
- AvahiStringList *strlst;
- DBusMessageIter iter, sub;
- int j;
+ AvahiStringList *strlst = NULL;
if (!dbus_message_get_args(
m, &error,
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_STRING, &host,
DBUS_TYPE_UINT16, &port,
- DBUS_TYPE_INVALID) || !type || !name) {
+ DBUS_TYPE_INVALID) ||
+ !type || !name ||
+ read_strlst(m, 8, &strlst) < 0) {
avahi_log_warn("Error parsing EntryGroup::AddService message");
goto fail;
}
- dbus_message_iter_init(m, &iter);
-
- for (j = 0; j < 8; 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;
- uint8_t *k;
-
- if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
- break;
-
- 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) {
+ if (!(flags & AVAHI_PUBLISH_UPDATE) && 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.");
return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
}
return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
}
- i->n_entries ++;
+ if (!(flags & AVAHI_PUBLISH_UPDATE))
+ i->n_entries ++;
+
avahi_string_list_free(strlst);
return respond_ok(c, m);
goto fail;
}
- if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
- avahi_log_warn("Too many entries per entry group, client request failed.");
+ if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP)
return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
- }
if (domain && !*domain)
domain = NULL;
if (avahi_server_add_service_subtype(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, subtype) < 0)
return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
- i->n_entries ++;
+ if (!(flags & AVAHI_PUBLISH_UPDATE))
+ i->n_entries ++;
+
+ return respond_ok(c, m);
+
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "UpdateServiceTxt")) {
+ int32_t interface, protocol;
+ uint32_t flags;
+ char *type, *name, *domain;
+ AvahiStringList *strlst;
+
+ if (!dbus_message_get_args(
+ m, &error,
+ DBUS_TYPE_INT32, &interface,
+ DBUS_TYPE_INT32, &protocol,
+ DBUS_TYPE_UINT32, &flags,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_STRING, &domain,
+ DBUS_TYPE_INVALID) ||
+ !type || !name ||
+ read_strlst(m, 6, &strlst)) {
+ avahi_log_warn("Error parsing EntryGroup::UpdateServiceTxt message");
+ goto fail;
+ }
+
+ if (domain && !*domain)
+ domain = NULL;
+
+ if (avahi_server_update_service_txt_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, strlst) < 0) {
+ avahi_string_list_free(strlst);
+ return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
+ }
+
+ avahi_string_list_free(strlst);
return respond_ok(c, m);
goto fail;
}
- if (i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP) {
- avahi_log_warn("Too many entries per entry group, client request failed.");
+ if (!(flags & AVAHI_PUBLISH_UPDATE) && i->n_entries >= MAX_ENTRIES_PER_ENTRY_GROUP)
return respond_error(c, m, AVAHI_ERR_TOO_MANY_ENTRIES, NULL);
- }
- if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a))) {
+ if (!(avahi_address_parse(address, AVAHI_PROTO_UNSPEC, &a)))
return respond_error(c, m, AVAHI_ERR_INVALID_ADDRESS, NULL);
- }
if (avahi_server_add_address(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, &a) < 0)
return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
- i->n_entries ++;
+ if (!(flags & AVAHI_PUBLISH_UPDATE))
+ i->n_entries ++;
return respond_ok(c, m);
}
assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
- char t[256], *pt = t;
+ char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
DBusMessage *reply;
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
- } else
- respond_error(server->bus, i->message, map_resolve_error(event), NULL);
+ } else {
+ assert(event == AVAHI_RESOLVER_FAILURE);
+ respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL);
+ }
sync_host_name_resolver_free(i);
}
assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
- char t[256], *pt = t;
+ char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
DBusMessage *reply;
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
- } else
- respond_error(server->bus, i->message, map_resolve_error(event), NULL);
+ } else {
+ assert(event == AVAHI_RESOLVER_FAILURE);
+ respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL);
+ }
sync_address_resolver_free(i);
}
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
- }
+ } else if (event == AVAHI_BROWSER_FAILURE)
+ append_server_error(m);
dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
- }
+ } else if (event == AVAHI_BROWSER_FAILURE)
+ append_server_error(m);
dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
DBUS_TYPE_STRING, &domain,
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
- }
+ } else if (event == AVAHI_BROWSER_FAILURE)
+ append_server_error(m);
dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
- char t[256], *pt = t;
+ char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
DBusMessage *reply;
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
- } else
- respond_error(server->bus, i->message, map_resolve_error(event), NULL);
+
+ } else {
+ assert(event == AVAHI_RESOLVER_FAILURE);
+
+ respond_error(server->bus, i->message, avahi_server_errno(avahi_server), NULL);
+ }
sync_service_resolver_free(i);
}
assert(r);
assert(i);
- reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, map_browse_signal_name(event));
+ reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ADDRESS_RESOLVER, map_resolve_signal_name(event));
if (event == AVAHI_RESOLVER_FOUND) {
- char t[256], *pt = t;
+ char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
+ } else {
+ assert(event == AVAHI_RESOLVER_FAILURE);
+ append_server_error(reply);
}
dbus_message_set_destination(reply, i->client->name);
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_HOST_NAME_RESOLVER, map_resolve_signal_name(event));
if (event == AVAHI_RESOLVER_FOUND) {
- char t[256], *pt = t;
+ char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
DBUS_TYPE_STRING, &pt,
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
+ } else {
+ assert(event == AVAHI_RESOLVER_FAILURE);
+ append_server_error(reply);
}
dbus_message_set_destination(reply, i->client->name);
reply = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_RESOLVER, map_resolve_signal_name(event));
if (event == AVAHI_RESOLVER_FOUND) {
- char t[256], *pt = t;
+ char t[AVAHI_ADDRESS_STR_MAX], *pt = t;
int32_t i_interface, i_protocol, i_aprotocol;
uint32_t u_flags;
/* avahi_log_debug(__FILE__": [%s] Successfully resolved service <%s.%s.%s>", i->path, name, type, domain); */
- assert(a);
- avahi_address_snprint(t, sizeof(t), a);
+ if (a)
+ avahi_address_snprint(t, sizeof(t), a);
+ else
+ t[0] = 0;
if (!name)
name = "";
i_interface = (int32_t) interface;
i_protocol = (int32_t) protocol;
- i_aprotocol = (int32_t) a->proto;
+ if (a)
+ i_aprotocol = (int32_t) a->proto;
+ else
+ i_aprotocol = AVAHI_PROTO_UNSPEC;
u_flags = (uint32_t) flags;
dbus_message_append_args(
reply,
DBUS_TYPE_UINT32, &u_flags,
DBUS_TYPE_INVALID);
+ } else {
+ assert(event == AVAHI_RESOLVER_FAILURE);
+ append_server_error(reply);
}
dbus_message_set_destination(reply, i->client->name);