• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/iserver/avahi-0.6.25/avahi-core/

Lines Matching defs:*

0 /* $Id$ */
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
19 USA.
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 #include <string.h>
28 #include <avahi-common/domain.h>
29 #include <avahi-common/malloc.h>
30 #include <avahi-common/error.h>
32 #include "browse.h"
33 #include "log.h"
35 struct AvahiSServiceTypeBrowser {
36 AvahiServer *server;
37 char *domain_name;
39 AvahiSRecordBrowser *record_browser;
41 AvahiSServiceTypeBrowserCallback callback;
42 void* userdata;
44 AVAHI_LLIST_FIELDS(AvahiSServiceTypeBrowser, browser);
47 static void record_browser_callback(
48 AvahiSRecordBrowser*rr,
49 AvahiIfIndex interface,
50 AvahiProtocol protocol,
51 AvahiBrowserEvent event,
52 AvahiRecord *record,
53 AvahiLookupResultFlags flags,
54 void* userdata) {
56 AvahiSServiceTypeBrowser *b = userdata;
58 assert(rr);
59 assert(b);
61 /* Filter flags */
62 flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
64 if (record) {
65 char type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
67 assert(record->key->type == AVAHI_DNS_TYPE_PTR);
69 if (avahi_service_name_split(record->data.ptr.name, NULL, 0, type, sizeof(type), domain, sizeof(domain)) < 0) {
70 avahi_log_warn("Invalid service type '%s'", record->key->name);
71 return;
74 b->callback(b, interface, protocol, event, type, domain, flags, b->userdata);
75 } else
76 b->callback(b, interface, protocol, event, NULL, b->domain_name, flags, b->userdata);
79 AvahiSServiceTypeBrowser *avahi_s_service_type_browser_new(
80 AvahiServer *server,
81 AvahiIfIndex interface,
82 AvahiProtocol protocol,
83 const char *domain,
84 AvahiLookupFlags flags,
85 AvahiSServiceTypeBrowserCallback callback,
86 void* userdata) {
88 AvahiSServiceTypeBrowser *b;
89 AvahiKey *k = NULL;
90 char n[AVAHI_DOMAIN_NAME_MAX];
91 int r;
93 assert(server);
94 assert(callback);
96 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
97 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
98 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
99 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
101 if (!domain)
102 domain = server->domain_name;
104 if ((r = avahi_service_name_join(n, sizeof(n), NULL, "_services._dns-sd._udp", domain)) < 0) {
105 avahi_server_set_errno(server, r);
106 return NULL;
109 if (!(b = avahi_new(AvahiSServiceTypeBrowser, 1))) {
110 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
111 return NULL;
114 b->server = server;
115 b->callback = callback;
116 b->userdata = userdata;
117 b->record_browser = NULL;
119 AVAHI_LLIST_PREPEND(AvahiSServiceTypeBrowser, browser, server->service_type_browsers, b);
121 if (!(b->domain_name = avahi_normalize_name_strdup(domain))) {
122 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
123 goto fail;
126 if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
127 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
128 goto fail;
131 if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
132 goto fail;
134 avahi_key_unref(k);
136 return b;
138 fail:
139 if (k)
140 avahi_key_unref(k);
142 avahi_s_service_type_browser_free(b);
144 return NULL;
147 void avahi_s_service_type_browser_free(AvahiSServiceTypeBrowser *b) {
148 assert(b);
150 AVAHI_LLIST_REMOVE(AvahiSServiceTypeBrowser, browser, b->server->service_type_browsers, b);
152 if (b->record_browser)
153 avahi_s_record_browser_free(b->record_browser);
155 avahi_free(b->domain_name);
156 avahi_free(b);