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
30 #include <avahi-common/strlst.h>
31 #include <avahi-common/malloc.h>
32 #include <avahi-common/domain.h>
33 #include <avahi-common/simple-watch.h>
34 #include <avahi-common/error.h>
35 #include <avahi-common/llist.h>
37 #include <avahi-client/client.h>
38 #include <avahi-client/publish.h>
39 #include <avahi-client/lookup.h>
49 COMMAND_POLL_DONE = 'P',
50 COMMAND_POLL_FAILED = 'F'
61 typedef struct service_data service_data;
63 typedef struct oid_data {
66 sw_discovery discovery;
68 sw_result (*reply)(void);
69 service_data *service_data;
74 char *name, *regtype, *domain, *host;
76 AvahiIfIndex interface;
78 AVAHI_LLIST_FIELDS(service_data, services);
81 struct _sw_discovery {
83 AvahiSimplePoll *simple_poll;
86 oid_data oid_table[OID_MAX];
87 sw_discovery_oid oid_index;
89 int thread_fd, main_fd;
94 pthread_mutex_t mutex, salt_mutex;
96 AVAHI_LLIST_HEAD(service_data, services);
99 #define ASSERT_SUCCESS(r) { int __ret = (r); assert(__ret == 0); }
101 #define OID_GET_INDEX(data) ((sw_discovery_oid) (((data) - ((data)->discovery->oid_table))))
103 static sw_discovery discovery_ref(sw_discovery self);
104 static void discovery_unref(sw_discovery self);
106 static const char *add_trailing_dot(const char *s, char *buf, size_t buf_len) {
113 if (s[strlen(s)-1] == '.')
116 snprintf(buf, buf_len, "%s.", s);
120 static sw_result map_error(int error) {
125 case AVAHI_ERR_NO_MEMORY:
132 static int read_command(int fd) {
138 if ((r = read(fd, &command, 1)) != 1) {
139 fprintf(stderr, __FILE__": read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
146 static int write_command(int fd, char reply) {
149 if (write(fd, &reply, 1) != 1) {
150 fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
157 static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata) {
158 sw_discovery self = userdata;
163 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
164 ret = poll(ufds, nfds, timeout);
165 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
170 static void * thread_func(void *data) {
171 sw_discovery self = data;
175 pthread_sigmask(SIG_BLOCK, &mask, NULL);
177 self->thread = pthread_self();
178 self->thread_running = 1;
183 if ((command = read_command(self->thread_fd)) < 0)
186 /* fprintf(stderr, "Command: %c\n", command); */
193 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
198 if ((ret = avahi_simple_poll_run(self->simple_poll)) < 0) {
203 fprintf(stderr, __FILE__": avahi_simple_poll_run() failed: %s\n", strerror(errno));
209 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
211 if (write_command(self->thread_fd, ret < 0 ? COMMAND_POLL_FAILED : COMMAND_POLL_DONE) < 0)
226 static int oid_alloc(sw_discovery self, oid_type type) {
230 for (i = 0; i < OID_MAX; i++) {
232 while (self->oid_index >= OID_MAX)
233 self->oid_index -= OID_MAX;
235 if (self->oid_table[self->oid_index].type == OID_UNUSED) {
236 self->oid_table[self->oid_index].type = type;
237 self->oid_table[self->oid_index].discovery = self;
239 assert(OID_GET_INDEX(&self->oid_table[self->oid_index]) == self->oid_index);
241 return self->oid_index ++;
247 /* No free entry found */
249 return (sw_discovery_oid) -1;
252 static void oid_release(sw_discovery self, sw_discovery_oid oid) {
254 assert(oid < OID_MAX);
256 assert(self->oid_table[oid].type != OID_UNUSED);
258 self->oid_table[oid].type = OID_UNUSED;
259 self->oid_table[oid].discovery = NULL;
260 self->oid_table[oid].reply = NULL;
261 self->oid_table[oid].object = NULL;
262 self->oid_table[oid].extra = NULL;
263 self->oid_table[oid].service_data = NULL;
266 static oid_data* oid_get(sw_discovery self, sw_discovery_oid oid) {
272 if (self->oid_table[oid].type == OID_UNUSED)
275 return &self->oid_table[oid];
278 static service_data* service_data_new(sw_discovery self) {
283 if (!(sdata = avahi_new0(service_data, 1)))
286 AVAHI_LLIST_PREPEND(service_data, services, self->services, sdata);
292 static void service_data_free(sw_discovery self, service_data* sdata) {
296 AVAHI_LLIST_REMOVE(service_data, services, self->services, sdata);
298 avahi_free(sdata->name);
299 avahi_free(sdata->regtype);
300 avahi_free(sdata->domain);
301 avahi_free(sdata->host);
302 avahi_string_list_free(sdata->txt);
306 static void reg_client_callback(oid_data *data, AvahiClientState state);
308 static void client_callback(AvahiClient *s, AvahiClientState state, void* userdata) {
309 sw_discovery self = userdata;
310 sw_discovery_oid oid;
317 for (oid = 0; oid < OID_MAX; oid++) {
319 switch (self->oid_table[oid].type) {
321 case OID_ENTRY_GROUP:
322 reg_client_callback(&self->oid_table[oid], state);
325 case OID_DOMAIN_BROWSER:
326 case OID_SERVICE_BROWSER:
327 ((sw_discovery_browse_reply) self->oid_table[oid].reply)(self, oid, SW_DISCOVERY_BROWSE_INVALID, 0, NULL, NULL, NULL, self->oid_table[oid].extra);
330 case OID_SERVICE_RESOLVER:
336 discovery_unref(self);
339 sw_result sw_discovery_init(sw_discovery * self) {
340 int fd[2] = { -1, -1};
341 sw_result result = SW_E_UNKNOWN;
342 pthread_mutexattr_t mutex_attr;
351 if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0)
354 if (!(*self = avahi_new(struct _sw_discovery, 1))) {
360 (*self)->thread_fd = fd[0];
361 (*self)->main_fd = fd[1];
363 (*self)->client = NULL;
364 (*self)->simple_poll = NULL;
366 memset((*self)->oid_table, 0, sizeof((*self)->oid_table));
367 (*self)->oid_index = 0;
369 (*self)->thread_running = 0;
371 AVAHI_LLIST_HEAD_INIT(service_info, (*self)->services);
373 ASSERT_SUCCESS(pthread_mutexattr_init(&mutex_attr));
374 pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
375 ASSERT_SUCCESS(pthread_mutex_init(&(*self)->mutex, &mutex_attr));
376 ASSERT_SUCCESS(pthread_mutex_init(&(*self)->salt_mutex, &mutex_attr));
378 if (!((*self)->simple_poll = avahi_simple_poll_new()))
381 avahi_simple_poll_set_func((*self)->simple_poll, poll_func, *self);
383 if (!((*self)->client = avahi_client_new(avahi_simple_poll_get((*self)->simple_poll), 0, client_callback, *self, &error))) {
384 result = map_error(error);
388 /* Start simple poll */
389 if (avahi_simple_poll_prepare((*self)->simple_poll, -1) < 0)
392 /* Queue an initial POLL command for the thread */
393 if (write_command((*self)->main_fd, COMMAND_POLL) < 0)
396 if (pthread_create(&(*self)->thread, NULL, thread_func, *self) != 0)
399 (*self)->thread_running = 1;
406 sw_discovery_fina(*self);
411 static int stop_thread(sw_discovery self) {
414 if (!self->thread_running)
417 if (write_command(self->main_fd, COMMAND_QUIT) < 0)
420 avahi_simple_poll_wakeup(self->simple_poll);
422 ASSERT_SUCCESS(pthread_join(self->thread, NULL));
423 self->thread_running = 0;
427 static sw_discovery discovery_ref(sw_discovery self) {
429 assert(self->n_ref >= 1);
436 static void discovery_unref(sw_discovery self) {
438 assert(self->n_ref >= 1);
440 if (--self->n_ref > 0)
446 avahi_client_free(self->client);
448 if (self->simple_poll)
449 avahi_simple_poll_free(self->simple_poll);
451 if (self->thread_fd >= 0)
452 close(self->thread_fd);
454 if (self->main_fd >= 0)
455 close(self->main_fd);
457 ASSERT_SUCCESS(pthread_mutex_destroy(&self->mutex));
458 ASSERT_SUCCESS(pthread_mutex_destroy(&self->salt_mutex));
460 while (self->services)
461 service_data_free(self, self->services);
466 sw_result sw_discovery_fina(sw_discovery self) {
472 discovery_unref(self);
477 sw_result sw_discovery_run(sw_discovery self) {
482 return sw_salt_run((sw_salt) self);
485 sw_result sw_discovery_stop_run(sw_discovery self) {
490 return sw_salt_stop_run((sw_salt) self);
493 int sw_discovery_socket(sw_discovery self) {
498 return self->main_fd;
501 sw_result sw_discovery_read_socket(sw_discovery self) {
502 sw_result result = SW_E_UNKNOWN;
508 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
510 /* Cleanup notification socket */
511 if (read_command(self->main_fd) != COMMAND_POLL_DONE)
514 if (avahi_simple_poll_dispatch(self->simple_poll) < 0)
517 if (self->n_ref > 1) /* Perhaps we should die */
519 /* Dispatch events */
520 if (avahi_simple_poll_prepare(self->simple_poll, -1) < 0)
525 /* Request the poll */
526 if (write_command(self->main_fd, COMMAND_POLL) < 0)
533 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
535 discovery_unref(self);
540 sw_result sw_discovery_salt(sw_discovery self, sw_salt *salt) {
546 *salt = (sw_salt) self;
551 sw_result sw_salt_step(sw_salt self, sw_uint32 * msec) {
558 if (!((sw_discovery) self)->thread_running)
561 memset(&p, 0, sizeof(p));
562 p.fd = ((sw_discovery) self)->main_fd;
565 if ((r = poll(&p, 1, msec ? (int) *msec : -1)) < 0) {
567 /* Don't treat EINTR as error */
581 if (p.revents != POLLIN)
584 if ((result = sw_discovery_read_socket((sw_discovery) self)) != SW_OKAY)
591 sw_result sw_salt_run(sw_salt self) {
599 if ((ret = sw_salt_step(self, NULL)) != SW_OKAY)
603 sw_result sw_salt_stop_run(sw_salt self) {
608 if (stop_thread((sw_discovery) self) < 0)
614 sw_result sw_salt_lock(sw_salt self) {
618 ASSERT_SUCCESS(pthread_mutex_lock(&((sw_discovery) self)->salt_mutex));
623 sw_result sw_salt_unlock(sw_salt self) {
628 ASSERT_SUCCESS(pthread_mutex_unlock(&((sw_discovery) self)->salt_mutex));
633 static void reg_report_status(oid_data *data, sw_discovery_publish_status status) {
634 sw_discovery_publish_reply reply;
638 reply = (sw_discovery_publish_reply) data->reply;
640 reply(data->discovery,
646 static int reg_create_service(oid_data *data) {
648 const char *real_type;
652 real_type = avahi_get_type_from_subtype(data->service_data->regtype);
654 if ((ret = avahi_entry_group_add_service_strlst(
656 data->service_data->interface,
659 data->service_data->name,
660 real_type ? real_type : data->service_data->regtype,
661 data->service_data->domain,
662 data->service_data->host,
663 data->service_data->port,
664 data->service_data->txt)) < 0)
668 /* Create a subtype entry */
670 if (avahi_entry_group_add_service_subtype(
672 data->service_data->interface,
675 data->service_data->name,
677 data->service_data->domain,
678 data->service_data->regtype) < 0)
683 if ((ret = avahi_entry_group_commit(data->object)) < 0)
689 static void reg_client_callback(oid_data *data, AvahiClientState state) {
692 /* We've not been setup completely */
697 case AVAHI_CLIENT_FAILURE:
698 reg_report_status(data, SW_DISCOVERY_PUBLISH_INVALID);
701 case AVAHI_CLIENT_S_RUNNING: {
704 /* Register the service */
705 if ((ret = reg_create_service(data)) < 0) {
706 reg_report_status(data, SW_DISCOVERY_PUBLISH_INVALID);
713 case AVAHI_CLIENT_S_COLLISION:
714 case AVAHI_CLIENT_S_REGISTERING:
716 /* Remove our entry */
717 avahi_entry_group_reset(data->object);
720 case AVAHI_CLIENT_CONNECTING:
727 static void reg_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
728 oid_data *data = userdata;
734 case AVAHI_ENTRY_GROUP_ESTABLISHED:
736 reg_report_status(data, SW_DISCOVERY_PUBLISH_STARTED);
739 case AVAHI_ENTRY_GROUP_COLLISION:
741 reg_report_status(data, SW_DISCOVERY_PUBLISH_NAME_COLLISION);
744 case AVAHI_ENTRY_GROUP_REGISTERING:
745 case AVAHI_ENTRY_GROUP_UNCOMMITED:
749 case AVAHI_ENTRY_GROUP_FAILURE:
750 reg_report_status(data, SW_DISCOVERY_PUBLISH_INVALID);
756 sw_result sw_discovery_publish(
758 sw_uint32 interface_index,
759 sw_const_string name,
760 sw_const_string type,
761 sw_const_string domain,
762 sw_const_string host,
764 sw_octets text_record,
765 sw_uint32 text_record_len,
766 sw_discovery_publish_reply reply,
768 sw_discovery_oid * oid) {
771 sw_result result = SW_E_UNKNOWN;
773 AvahiStringList *txt = NULL;
783 if (text_record && text_record_len > 0)
784 if (avahi_string_list_parse(text_record, text_record_len, &txt) < 0)
787 if ((*oid = oid_alloc(self, OID_ENTRY_GROUP)) == (sw_discovery_oid) -1) {
788 avahi_string_list_free(txt);
792 if (!(sdata = service_data_new(self))) {
793 avahi_string_list_free(txt);
794 oid_release(self, *oid);
798 data = oid_get(self, *oid);
800 data->reply = (sw_result (*)(void)) reply;
802 data->service_data = sdata;
804 sdata->interface = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
805 sdata->name = avahi_strdup(name);
806 sdata->regtype = type ? avahi_normalize_name_strdup(type) : NULL;
807 sdata->domain = domain ? avahi_normalize_name_strdup(domain) : NULL;
808 sdata->host = host ? avahi_normalize_name_strdup(host) : NULL;
812 /* Some OOM checking would be cool here */
814 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
816 if (!(data->object = avahi_entry_group_new(self->client, reg_entry_group_callback, data))) {
817 result = map_error(avahi_client_errno(self->client));
821 if (avahi_client_get_state(self->client) == AVAHI_CLIENT_S_RUNNING) {
824 if ((error = reg_create_service(data)) < 0) {
825 result = map_error(error);
834 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
836 if (result != SW_OKAY)
837 if (*oid != (sw_discovery_oid) -1)
838 sw_discovery_cancel(self, *oid);
843 static void domain_browser_callback(
844 AvahiDomainBrowser *b,
845 AvahiIfIndex interface,
846 AVAHI_GCC_UNUSED AvahiProtocol protocol,
847 AvahiBrowserEvent event,
849 AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
852 oid_data* data = userdata;
853 sw_discovery_browse_reply reply;
854 static char domain_fixed[AVAHI_DOMAIN_NAME_MAX];
859 reply = (sw_discovery_browse_reply) data->reply;
861 domain = add_trailing_dot(domain, domain_fixed, sizeof(domain_fixed));
864 case AVAHI_BROWSER_NEW:
865 reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_ADD_DOMAIN, interface, NULL, NULL, domain, data->extra);
868 case AVAHI_BROWSER_REMOVE:
869 reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_REMOVE_DOMAIN, interface, NULL, NULL, domain, data->extra);
872 case AVAHI_BROWSER_FAILURE:
873 reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_INVALID, interface, NULL, NULL, domain, data->extra);
876 case AVAHI_BROWSER_CACHE_EXHAUSTED:
877 case AVAHI_BROWSER_ALL_FOR_NOW:
882 sw_result sw_discovery_browse_domains(
884 sw_uint32 interface_index,
885 sw_discovery_browse_reply reply,
887 sw_discovery_oid * oid) {
890 AvahiIfIndex ifindex;
891 sw_result result = SW_E_UNKNOWN;
899 if ((*oid = oid_alloc(self, OID_DOMAIN_BROWSER)) == (sw_discovery_oid) -1)
902 data = oid_get(self, *oid);
904 data->reply = (sw_result (*)(void)) reply;
907 ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
909 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
911 if (!(data->object = avahi_domain_browser_new(self->client, ifindex, AVAHI_PROTO_INET, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, domain_browser_callback, data))) {
912 result = map_error(avahi_client_errno(self->client));
920 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
922 if (result != SW_OKAY)
923 if (*oid != (sw_discovery_oid) -1)
924 sw_discovery_cancel(self, *oid);
929 static void service_resolver_callback(
930 AvahiServiceResolver *r,
931 AvahiIfIndex interface,
932 AVAHI_GCC_UNUSED AvahiProtocol protocol,
933 AvahiResolverEvent event,
937 const char *host_name,
938 const AvahiAddress *a,
940 AvahiStringList *txt,
941 AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
944 oid_data* data = userdata;
945 sw_discovery_resolve_reply reply;
950 reply = (sw_discovery_resolve_reply) data->reply;
953 case AVAHI_RESOLVER_FOUND: {
955 char host_name_fixed[AVAHI_DOMAIN_NAME_MAX];
958 sw_ipv4_address addr;
960 sw_ipv4_address_init_from_saddr(&addr, a->data.ipv4.address);
962 host_name = add_trailing_dot(host_name, host_name_fixed, sizeof(host_name_fixed));
964 if ((p = avahi_new0(uint8_t, (l = avahi_string_list_serialize(txt, NULL, 0))+1)))
965 avahi_string_list_serialize(txt, p, l);
967 reply(data->discovery, OID_GET_INDEX(data), interface, name, type, domain, addr, port, p, l, data->extra);
973 case AVAHI_RESOLVER_FAILURE:
975 /* Apparently there is no way in HOWL to inform about failed resolvings ... */
977 avahi_warn("A service failed to resolve in the HOWL compatiblity layer of Avahi which is used by '%s'. "
978 "Since the HOWL API doesn't offer any means to inform the application about this, we have to ignore the failure. "
979 "Please fix your application to use the native API of Avahi!",
986 sw_result sw_discovery_resolve(
988 sw_uint32 interface_index,
989 sw_const_string name,
990 sw_const_string type,
991 sw_const_string domain,
992 sw_discovery_resolve_reply reply,
994 sw_discovery_oid * oid) {
997 AvahiIfIndex ifindex;
998 sw_result result = SW_E_UNKNOWN;
1008 if ((*oid = oid_alloc(self, OID_SERVICE_RESOLVER)) == (sw_discovery_oid) -1)
1009 return SW_E_UNKNOWN;
1011 data = oid_get(self, *oid);
1013 data->reply = (sw_result (*)(void)) reply;
1014 data->extra = extra;
1016 ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
1018 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
1020 if (!(data->object = avahi_service_resolver_new(self->client, ifindex, AVAHI_PROTO_INET, name, type, domain, AVAHI_PROTO_INET, 0, service_resolver_callback, data))) {
1021 result = map_error(avahi_client_errno(self->client));
1029 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
1031 if (result != SW_OKAY)
1032 if (*oid != (sw_discovery_oid) -1)
1033 sw_discovery_cancel(self, *oid);
1038 static void service_browser_callback(
1039 AvahiServiceBrowser *b,
1040 AvahiIfIndex interface,
1041 AVAHI_GCC_UNUSED AvahiProtocol protocol,
1042 AvahiBrowserEvent event,
1046 AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
1049 oid_data* data = userdata;
1050 char type_fixed[AVAHI_DOMAIN_NAME_MAX], domain_fixed[AVAHI_DOMAIN_NAME_MAX];
1051 sw_discovery_browse_reply reply;
1056 reply = (sw_discovery_browse_reply) data->reply;
1058 type = add_trailing_dot(type, type_fixed, sizeof(type_fixed));
1059 domain = add_trailing_dot(domain, domain_fixed, sizeof(domain_fixed));
1062 case AVAHI_BROWSER_NEW:
1063 reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_ADD_SERVICE, interface, name, type, domain, data->extra);
1066 case AVAHI_BROWSER_REMOVE:
1067 reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_REMOVE_SERVICE, interface, name, type, domain, data->extra);
1070 case AVAHI_BROWSER_FAILURE:
1071 reply(data->discovery, OID_GET_INDEX(data), SW_DISCOVERY_BROWSE_INVALID, interface, name, type, domain, data->extra);
1074 case AVAHI_BROWSER_CACHE_EXHAUSTED:
1075 case AVAHI_BROWSER_ALL_FOR_NOW:
1080 sw_result sw_discovery_browse(
1082 sw_uint32 interface_index,
1083 sw_const_string type,
1084 sw_const_string domain,
1085 sw_discovery_browse_reply reply,
1087 sw_discovery_oid * oid) {
1090 AvahiIfIndex ifindex;
1091 sw_result result = SW_E_UNKNOWN;
1100 if ((*oid = oid_alloc(self, OID_SERVICE_BROWSER)) == (sw_discovery_oid) -1)
1101 return SW_E_UNKNOWN;
1103 data = oid_get(self, *oid);
1105 data->reply = (sw_result (*)(void)) reply;
1106 data->extra = extra;
1108 ifindex = interface_index == 0 ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface_index;
1110 ASSERT_SUCCESS(pthread_mutex_lock(&self->mutex));
1112 if (!(data->object = avahi_service_browser_new(self->client, ifindex, AVAHI_PROTO_INET, type, domain, 0, service_browser_callback, data))) {
1113 result = map_error(avahi_client_errno(self->client));
1121 ASSERT_SUCCESS(pthread_mutex_unlock(&self->mutex));
1123 if (result != SW_OKAY)
1124 if (*oid != (sw_discovery_oid) -1)
1125 sw_discovery_cancel(self, *oid);
1130 sw_result sw_discovery_cancel(sw_discovery self, sw_discovery_oid oid) {
1136 if (!(data = oid_get(self, oid)))
1137 return SW_E_UNKNOWN;
1140 switch (data->type) {
1141 case OID_SERVICE_BROWSER:
1142 avahi_service_browser_free(data->object);
1145 case OID_SERVICE_RESOLVER:
1146 avahi_service_resolver_free(data->object);
1149 case OID_DOMAIN_BROWSER:
1150 avahi_domain_browser_free(data->object);
1153 case OID_ENTRY_GROUP:
1154 avahi_entry_group_free(data->object);
1162 if (data->service_data) {
1163 assert(data->type == OID_ENTRY_GROUP);
1164 service_data_free(self, data->service_data);
1167 oid_release(self, oid);
1172 sw_result sw_discovery_init_with_flags(
1173 sw_discovery * self,
1174 sw_discovery_init_flags flags) {
1180 if (flags != SW_DISCOVERY_USE_SHARED_SERVICE)
1181 return SW_E_NO_IMPL;
1183 return sw_discovery_init(self);