+static void service_resolver_callback(
+ AvahiServiceResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const gchar *name,
+ const gchar *type,
+ const gchar *domain,
+ const gchar *host_name,
+ const AvahiAddress *a,
+ guint16 port,
+ AvahiStringList *txt,
+ gpointer userdata) {
+
+ ServiceResolverInfo *i = userdata;
+ DBusMessage *reply;
+
+ g_assert(r);
+ g_assert(host_name);
+ 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;
+
+ g_assert(a);
+ avahi_address_snprint(t, sizeof(t), a);
+
+ i_interface = (gint32) interface;
+ 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_interface,
+ DBUS_TYPE_INT32, &i_protocol,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &type,
+ DBUS_TYPE_STRING, &domain,
+ DBUS_TYPE_STRING, &host_name,
+ 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]);
+
+ } else {
+ g_assert(event == AVAHI_RESOLVER_TIMEOUT);
+ reply = dbus_message_new_error(i->message, "org.freedesktop.Avahi.TimeoutError", NULL);
+ }
+
+ dbus_connection_send(server->bus, reply, NULL);
+ dbus_message_unref(reply);
+
+ service_resolver_free(i);
+}
+