resolve-host-name.c \
resolve-address.c \
browse-domain.c \
- browse-service-type.c
+ browse-service-type.c \
+ browse-service.c
prioq_test_SOURCES = \
prioq-test.c \
if (a)
avahi_address_snprint(t, sizeof(t), a);
- g_message("HNR: (%i.%i) %s -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", event == AVAHI_BROWSER_NEW ? "found" : "timeout");
+ g_message("HNR: (%i.%i) <%s> -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", event == AVAHI_BROWSER_NEW ? "found" : "timeout");
}
static void ar_callback(AvahiAddressResolver *r, gint iface, guchar protocol, AvahiBrowserEvent event, const AvahiAddress *a, const gchar *hostname, gpointer userdata) {
avahi_address_snprint(t, sizeof(t), a);
- g_message("AR: (%i.%i) %s -> %s [%s]", iface, protocol, t, hostname ? hostname : "n/a", event == AVAHI_BROWSER_NEW ? "found" : "timeout");
+ g_message("AR: (%i.%i) %s -> <%s> [%s]", iface, protocol, t, hostname ? hostname : "n/a", event == AVAHI_BROWSER_NEW ? "found" : "timeout");
}
static void db_callback(AvahiDomainBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
- g_message("DB: (%i.%i) %s [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+ g_message("DB: (%i.%i) <%s> [%s]", iface, protocol, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
static void stb_callback(AvahiServiceTypeBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *service_type, const gchar *domain, gpointer userdata) {
- g_message("STB: (%i.%i) %s in %s [%s]", iface, protocol, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+ g_message("STB: (%i.%i) %s in <%s> [%s]", iface, protocol, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
+}
+
+static void sb_callback(AvahiServiceBrowser *b, gint iface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *service_type, const gchar *domain, gpointer userdata) {
+ g_message("SB: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain, event == AVAHI_BROWSER_NEW ? "new" : "remove");
}
int main(int argc, char *argv[]) {
AvahiAddress a;
AvahiDomainBrowser *db;
AvahiServiceTypeBrowser *stb;
+ AvahiServiceBrowser *sb;
avahi_server_config_init(&config);
/* config.host_name = g_strdup("test"); */
db = avahi_domain_browser_new(server, -1, AF_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, db_callback, NULL);
stb = avahi_service_type_browser_new(server, -1, AF_UNSPEC, NULL, stb_callback, NULL);
+
+ sb = avahi_service_browser_new(server, -1, AF_UNSPEC, "_http._tcp", NULL, sb_callback, NULL);
loop = g_main_loop_new(NULL, FALSE);
avahi_host_name_resolver_free(hnr);
avahi_address_resolver_free(ar);
avahi_service_type_browser_free(stb);
+ avahi_service_browser_free(sb);
if (group)
avahi_entry_group_free(group);
if (!avahi_domain_equal(c, b->domain_name))
goto fail;
- b->callback(b, interface, protocol, event, n, b->domain_name, b->userdata);
+ b->callback(b, interface, protocol, event, n, c, b->userdata);
g_free(n);
return;
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+
+#include "browse.h"
+#include "util.h"
+
+struct AvahiServiceBrowser {
+ AvahiServer *server;
+ gchar *domain_name;
+ gchar *service_type;
+
+ AvahiRecordBrowser *record_browser;
+
+ AvahiServiceBrowserCallback callback;
+ gpointer userdata;
+
+ AVAHI_LLIST_FIELDS(AvahiServiceBrowser, browser);
+};
+
+static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
+ AvahiServiceBrowser *b = userdata;
+ gchar *n, *e, *c, *s;
+ gchar service[128];
+
+ g_assert(rr);
+ g_assert(record);
+ g_assert(b);
+
+ g_assert(record->key->type == AVAHI_DNS_TYPE_PTR);
+
+ c = n = avahi_normalize_name(record->data.ptr.name);
+
+ if (!(avahi_unescape_label((const gchar**) &c, service, sizeof(service))))
+ goto fail;
+
+ for (s = e = c; *c == '_';) {
+ c += strcspn(c, ".");
+
+ if (*c == 0)
+ goto fail;
+
+ g_assert(*c == '.');
+ e = c;
+ c++;
+ }
+
+ *e = 0;
+
+ if (!avahi_domain_equal(c, b->domain_name))
+ goto fail;
+
+ b->callback(b, interface, protocol, event, service, s, c, b->userdata);
+ g_free(n);
+
+ return;
+
+fail:
+ g_warning("Invalid service '%s'", n);
+ g_free(n);
+}
+
+AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata) {
+ AvahiServiceBrowser *b;
+ AvahiKey *k;
+ gchar *n = NULL;
+
+ g_assert(server);
+ g_assert(callback);
+ g_assert(service_type);
+
+ b = g_new(AvahiServiceBrowser, 1);
+ b->server = server;
+ b->domain_name = avahi_normalize_name(domain ? domain : "local.");
+ b->service_type = avahi_normalize_name(service_type);
+ b->callback = callback;
+ b->userdata = userdata;
+
+ n = g_strdup_printf("%s%s", b->service_type, b->domain_name);
+ k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
+ g_free(n);
+
+ b->record_browser = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, b);
+ avahi_key_unref(k);
+
+ AVAHI_LLIST_PREPEND(AvahiServiceBrowser, browser, server->service_browsers, b);
+
+ return b;
+}
+
+void avahi_service_browser_free(AvahiServiceBrowser *b) {
+ g_assert(b);
+
+ AVAHI_LLIST_REMOVE(AvahiServiceBrowser, browser, b->server->service_browsers, b);
+
+ avahi_record_browser_free(b->record_browser);
+ g_free(b->domain_name);
+ g_free(b->service_type);
+ g_free(b);
+}
AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata);
void avahi_service_type_browser_free(AvahiServiceTypeBrowser *b);
+typedef struct AvahiServiceBrowser AvahiServiceBrowser;
+typedef void (*AvahiServiceBrowserCallback)(AvahiServiceBrowser *b, gint interface, guchar protocol, AvahiBrowserEvent event, const gchar *name, const gchar *type, const gchar *domain, gpointer userdata);
+AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata);
+void avahi_service_browser_free(AvahiServiceBrowser *b);
/* Not yet implemented */
-typedef struct AvahiServiceBrowser AvahiServiceBrowser;
typedef struct AvahiServiceResolver AvahiServiceResolver;
#endif
AVAHI_LLIST_HEAD_INIT(AvahiAddressResolver, s->address_resolvers);
AVAHI_LLIST_HEAD_INIT(AvahiDomainBrowser, s->domain_browsers);
AVAHI_LLIST_HEAD_INIT(AvahiServiceTypeBrowser, s->service_type_browsers);
+ AVAHI_LLIST_HEAD_INIT(AvahiServiceBrowser, s->service_browsers);
/* Get host name */
s->host_name = s->config.host_name ? avahi_normalize_name(s->config.host_name) : avahi_get_host_name();
avahi_domain_browser_free(s->domain_browsers);
while (s->service_type_browsers)
avahi_service_type_browser_free(s->service_type_browsers);
+ while (s->service_browsers)
+ avahi_service_browser_free(s->service_browsers);
while (s->record_browsers)
avahi_record_browser_destroy(s->record_browsers);
g_hash_table_destroy(s->record_browser_hashtable);
AVAHI_LLIST_HEAD(AvahiAddressResolver, address_resolvers);
AVAHI_LLIST_HEAD(AvahiDomainBrowser, domain_browsers);
AVAHI_LLIST_HEAD(AvahiServiceTypeBrowser, service_type_browsers);
+ AVAHI_LLIST_HEAD(AvahiServiceBrowser, service_browsers);
gboolean need_entry_cleanup, need_group_cleanup, need_browser_cleanup;