4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 struct AvahiServiceBrowser {
36 AvahiRecordBrowser *record_browser;
38 AvahiServiceBrowserCallback callback;
41 AVAHI_LLIST_FIELDS(AvahiServiceBrowser, browser);
44 static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
45 AvahiServiceBrowser *b = userdata;
53 g_assert(record->key->type == AVAHI_DNS_TYPE_PTR);
55 c = n = avahi_normalize_name(record->data.ptr.name);
57 if (!(avahi_unescape_label((const gchar**) &c, service, sizeof(service))))
60 for (s = e = c; *c == '_';) {
73 if (!avahi_domain_equal(c, b->domain_name))
76 b->callback(b, interface, protocol, event, service, s, c, b->userdata);
82 g_warning("Invalid service '%s'", n);
86 AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata) {
87 AvahiServiceBrowser *b;
93 g_assert(service_type);
95 b = g_new(AvahiServiceBrowser, 1);
97 b->domain_name = avahi_normalize_name(domain ? domain : "local.");
98 b->service_type = avahi_normalize_name(service_type);
99 b->callback = callback;
100 b->userdata = userdata;
102 n = g_strdup_printf("%s%s", b->service_type, b->domain_name);
103 k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
106 b->record_browser = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, b);
109 AVAHI_LLIST_PREPEND(AvahiServiceBrowser, browser, server->service_browsers, b);
114 void avahi_service_browser_free(AvahiServiceBrowser *b) {
117 AVAHI_LLIST_REMOVE(AvahiServiceBrowser, browser, b->server->service_browsers, b);
119 avahi_record_browser_free(b->record_browser);
120 g_free(b->domain_name);
121 g_free(b->service_type);