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
32 struct AvahiServiceBrowser {
37 AvahiRecordBrowser *record_browser;
39 AvahiServiceBrowserCallback callback;
42 AVAHI_LLIST_FIELDS(AvahiServiceBrowser, browser);
45 static void record_browser_callback(AvahiRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
46 AvahiServiceBrowser *b = userdata;
54 g_assert(record->key->type == AVAHI_DNS_TYPE_PTR);
56 c = n = avahi_normalize_name(record->data.ptr.name);
58 if (!(avahi_unescape_label((const gchar**) &c, service, sizeof(service))))
61 for (s = e = c; *c == '_';) {
74 if (!avahi_domain_equal(c, b->domain_name))
77 b->callback(b, interface, protocol, event, service, s, c, b->userdata);
83 avahi_log_warn("Invalid service '%s'", n);
87 AvahiServiceBrowser *avahi_service_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const gchar *service_type, const gchar *domain, AvahiServiceBrowserCallback callback, gpointer userdata) {
88 AvahiServiceBrowser *b;
94 g_assert(service_type);
96 b = g_new(AvahiServiceBrowser, 1);
98 b->domain_name = avahi_normalize_name(domain ? domain : "local");
99 b->service_type = avahi_normalize_name(service_type);
100 b->callback = callback;
101 b->userdata = userdata;
103 n = g_strdup_printf("%s.%s", b->service_type, b->domain_name);
104 k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
107 b->record_browser = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, b);
110 AVAHI_LLIST_PREPEND(AvahiServiceBrowser, browser, server->service_browsers, b);
115 void avahi_service_browser_free(AvahiServiceBrowser *b) {
118 AVAHI_LLIST_REMOVE(AvahiServiceBrowser, browser, b->server->service_browsers, b);
120 avahi_record_browser_free(b->record_browser);
121 g_free(b->domain_name);
122 g_free(b->service_type);