• 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 AvahiSServiceBrowser {
36 AvahiServer *server;
37 char *domain_name;
38 char *service_type;
40 AvahiSRecordBrowser *record_browser;
42 AvahiSServiceBrowserCallback callback;
43 void* userdata;
45 AVAHI_LLIST_FIELDS(AvahiSServiceBrowser, browser);
48 static void record_browser_callback(
49 AvahiSRecordBrowser*rr,
50 AvahiIfIndex interface,
51 AvahiProtocol protocol,
52 AvahiBrowserEvent event,
53 AvahiRecord *record,
54 AvahiLookupResultFlags flags,
55 void* userdata) {
57 AvahiSServiceBrowser *b = userdata;
59 assert(rr);
60 assert(b);
62 /* Filter flags */
63 flags &= AVAHI_LOOKUP_RESULT_CACHED | AVAHI_LOOKUP_RESULT_MULTICAST | AVAHI_LOOKUP_RESULT_WIDE_AREA;
65 if (record) {
66 char service[AVAHI_LABEL_MAX], type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
68 assert(record->key->type == AVAHI_DNS_TYPE_PTR);
70 if (event == AVAHI_BROWSER_NEW && avahi_server_is_service_local(b->server, interface, protocol, record->data.ptr.name))
71 flags |= AVAHI_LOOKUP_RESULT_LOCAL;
73 if (avahi_service_name_split(record->data.ptr.name, service, sizeof(service), type, sizeof(type), domain, sizeof(domain)) < 0) {
74 avahi_log_warn("Failed to split '%s'", record->key->name);
75 return;
78 b->callback(b, interface, protocol, event, service, type, domain, flags, b->userdata);
80 } else
81 b->callback(b, interface, protocol, event, NULL, b->service_type, b->domain_name, flags, b->userdata);
85 AvahiSServiceBrowser *avahi_s_service_browser_new(
86 AvahiServer *server,
87 AvahiIfIndex interface,
88 AvahiProtocol protocol,
89 const char *service_type,
90 const char *domain,
91 AvahiLookupFlags flags,
92 AvahiSServiceBrowserCallback callback,
93 void* userdata) {
95 AvahiSServiceBrowser *b;
96 AvahiKey *k = NULL;
97 char n[AVAHI_DOMAIN_NAME_MAX];
98 int r;
100 assert(server);
101 assert(callback);
102 assert(service_type);
104 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_IF_VALID(interface), AVAHI_ERR_INVALID_INTERFACE);
105 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_PROTO_VALID(protocol), AVAHI_ERR_INVALID_PROTOCOL);
106 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, !domain || avahi_is_valid_domain_name(domain), AVAHI_ERR_INVALID_DOMAIN_NAME);
107 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, AVAHI_FLAGS_VALID(flags, AVAHI_LOOKUP_USE_WIDE_AREA|AVAHI_LOOKUP_USE_MULTICAST), AVAHI_ERR_INVALID_FLAGS);
108 AVAHI_CHECK_VALIDITY_RETURN_NULL(server, avahi_is_valid_service_type_generic(service_type), AVAHI_ERR_INVALID_SERVICE_TYPE);
110 if (!domain)
111 domain = server->domain_name;
113 if ((r = avahi_service_name_join(n, sizeof(n), NULL, service_type, domain)) < 0) {
114 avahi_server_set_errno(server, r);
115 return NULL;
118 if (!(b = avahi_new(AvahiSServiceBrowser, 1))) {
119 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
120 return NULL;
123 b->server = server;
124 b->domain_name = b->service_type = NULL;
125 b->callback = callback;
126 b->userdata = userdata;
127 b->record_browser = NULL;
129 AVAHI_LLIST_PREPEND(AvahiSServiceBrowser, browser, server->service_browsers, b);
131 if (!(b->domain_name = avahi_normalize_name_strdup(domain)) ||
132 !(b->service_type = avahi_normalize_name_strdup(service_type))) {
133 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
134 goto fail;
137 if (!(k = avahi_key_new(n, AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR))) {
138 avahi_server_set_errno(server, AVAHI_ERR_NO_MEMORY);
139 goto fail;
142 if (!(b->record_browser = avahi_s_record_browser_new(server, interface, protocol, k, flags, record_browser_callback, b)))
143 goto fail;
145 avahi_key_unref(k);
147 return b;
149 fail:
151 if (k)
152 avahi_key_unref(k);
154 avahi_s_service_browser_free(b);
155 return NULL;
158 void avahi_s_service_browser_free(AvahiSServiceBrowser *b) {
159 assert(b);
161 AVAHI_LLIST_REMOVE(AvahiSServiceBrowser, browser, b->server->service_browsers, b);
163 if (b->record_browser)
164 avahi_s_record_browser_free(b->record_browser);
166 avahi_free(b->domain_name);
167 avahi_free(b->service_type);
168 avahi_free(b);