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
28 #include <avahi-common/domain.h>
29 #include <avahi-common/malloc.h>
30 #include <avahi-common/error.h>
35 struct AvahiSServiceTypeBrowser {
39 AvahiSRecordBrowser *record_browser;
41 AvahiSServiceTypeBrowserCallback callback;
44 AVAHI_LLIST_FIELDS(AvahiSServiceTypeBrowser, browser);
47 static void record_browser_callback(AvahiSRecordBrowser*rr, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, AvahiRecord *record, void* userdata) {
48 AvahiSServiceTypeBrowser *b = userdata;
55 assert(record->key->type == AVAHI_DNS_TYPE_PTR);
57 n = avahi_normalize_name(record->data.ptr.name);
62 for (c = e = n; *c == '_';) {
75 if (!avahi_domain_equal(c, b->domain_name))
78 b->callback(b, interface, protocol, event, n, c, b->userdata);
84 avahi_log_warn("Invalid service type '%s'", n);
88 AvahiSServiceTypeBrowser *avahi_s_service_type_browser_new(AvahiServer *server, AvahiIfIndex interface, AvahiProtocol protocol, const char *domain, AvahiSServiceTypeBrowserCallback callback, void* userdata) {
89 AvahiSServiceTypeBrowser *b;
96 if (domain && !avahi_is_valid_domain_name(domain)) {
97 avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME);
101 if (!(b = avahi_new(AvahiSServiceTypeBrowser, 1))) {
102 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
107 b->domain_name = avahi_normalize_name(domain ? domain : "local");
108 b->callback = callback;
109 b->userdata = userdata;
111 AVAHI_LLIST_PREPEND(AvahiSServiceTypeBrowser, browser, server->service_type_browsers, b);
113 n = avahi_strdup_printf("_services._dns-sd._udp.%s", b->domain_name);
114 k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
117 b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, record_browser_callback, b);
120 if (!b->record_browser)
126 void avahi_s_service_type_browser_free(AvahiSServiceTypeBrowser *b) {
129 AVAHI_LLIST_REMOVE(AvahiSServiceTypeBrowser, browser, b->server->service_type_browsers, b);
131 if (b->record_browser)
132 avahi_s_record_browser_free(b->record_browser);
134 avahi_free(b->domain_name);