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 AvahiServiceTypeBrowser {
36 AvahiRecordBrowser *record_browser;
38 AvahiServiceTypeBrowserCallback callback;
41 AVAHI_LLIST_FIELDS(AvahiServiceTypeBrowser, browser);
44 static void record_browser_callback(AvahiRecordBrowser*rr, gint interface, guchar protocol, AvahiBrowserEvent event, AvahiRecord *record, gpointer userdata) {
45 AvahiServiceTypeBrowser *b = userdata;
52 g_assert(record->key->type == AVAHI_DNS_TYPE_PTR);
54 n = avahi_normalize_name(record->data.ptr.name);
59 for (c = e = n; *c == '_';) {
72 if (!avahi_domain_equal(c, b->domain_name))
75 b->callback(b, interface, protocol, event, n, c, b->userdata);
81 avahi_log_warn("Invalid service type '%s'", n);
85 AvahiServiceTypeBrowser *avahi_service_type_browser_new(AvahiServer *server, gint interface, guchar protocol, const gchar *domain, AvahiServiceTypeBrowserCallback callback, gpointer userdata) {
86 AvahiServiceTypeBrowser *b;
93 b = g_new(AvahiServiceTypeBrowser, 1);
95 b->domain_name = avahi_normalize_name(domain ? domain : "local.");
96 b->callback = callback;
97 b->userdata = userdata;
100 n = g_strdup_printf("_services._dns-sd._udp.%s", b->domain_name);
101 k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
104 b->record_browser = avahi_record_browser_new(server, interface, protocol, k, record_browser_callback, b);
107 AVAHI_LLIST_PREPEND(AvahiServiceTypeBrowser, browser, server->service_type_browsers, b);
112 void avahi_service_type_browser_free(AvahiServiceTypeBrowser *b) {
115 AVAHI_LLIST_REMOVE(AvahiServiceTypeBrowser, browser, b->server->service_type_browsers, b);
117 avahi_record_browser_free(b->record_browser);
118 g_free(b->domain_name);