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;
if (avahi_server_add_service_strlst(avahi_server, i->entry_group, (AvahiIfIndex) interface, (AvahiProtocol) protocol, (AvahiPublishFlags) flags, name, type, domain, host, port, strlst) < 0) {
avahi_string_list_free(strlst);
return respond_error(c, m, avahi_server_errno(avahi_server), NULL);
- } else
- i->n_entries ++;
-
+ }
+
+ i->n_entries ++;
avahi_string_list_free(strlst);
return respond_ok(c, m);
+ } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddServiceSubtype")) {
+
+ int32_t interface, protocol;
+ uint32_t flags;
+ char *type, *name, *domain, *subtype;
+
+ 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_STRING, &subtype,
+ DBUS_TYPE_INVALID) || !type || !name || !subtype) {
+ avahi_log_warn("Error parsing EntryGroup::AddServiceSubtype 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_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 ++;
+
+ return respond_ok(c, m);
+
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) {
int32_t interface, protocol;
uint32_t flags;
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);
- else
- i->n_entries ++;
+
+ i->n_entries ++;
return respond_ok(c, m);
- }
+ }
avahi_log_warn("Missed message %s::%s()", dbus_message_get_interface(m), dbus_message_get_member(m));
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);
}
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);
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;
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);
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);
/* 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);