]> code.delx.au - pulseaudio/blob - src/modules/module-zeroconf-publish.c
Merge branch 'master' of git://git.0pointer.de/pulseaudio
[pulseaudio] / src / modules / module-zeroconf-publish.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2004-2006 Lennart Poettering
5
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <unistd.h>
30
31 #include <avahi-client/client.h>
32 #include <avahi-client/publish.h>
33 #include <avahi-common/alternative.h>
34 #include <avahi-common/error.h>
35 #include <avahi-common/domain.h>
36
37 #include <pulse/xmalloc.h>
38 #include <pulse/util.h>
39
40 #include <pulsecore/sink.h>
41 #include <pulsecore/source.h>
42 #include <pulsecore/native-common.h>
43 #include <pulsecore/core-util.h>
44 #include <pulsecore/log.h>
45 #include <pulsecore/core-subscribe.h>
46 #include <pulsecore/dynarray.h>
47 #include <pulsecore/modargs.h>
48 #include <pulsecore/avahi-wrap.h>
49 #include <pulsecore/endianmacros.h>
50
51 #include "module-zeroconf-publish-symdef.h"
52
53 PA_MODULE_AUTHOR("Lennart Poettering");
54 PA_MODULE_DESCRIPTION("mDNS/DNS-SD Service Publisher");
55 PA_MODULE_VERSION(PACKAGE_VERSION);
56 PA_MODULE_LOAD_ONCE(TRUE);
57 PA_MODULE_USAGE("port=<IP port number>");
58
59 #define SERVICE_TYPE_SINK "_pulse-sink._tcp"
60 #define SERVICE_TYPE_SOURCE "_pulse-source._tcp"
61 #define SERVICE_TYPE_SERVER "_pulse-server._tcp"
62 #define SERVICE_SUBTYPE_SINK_HARDWARE "_hardware._sub."SERVICE_TYPE_SINK
63 #define SERVICE_SUBTYPE_SINK_VIRTUAL "_virtual._sub."SERVICE_TYPE_SINK
64 #define SERVICE_SUBTYPE_SOURCE_HARDWARE "_hardware._sub."SERVICE_TYPE_SOURCE
65 #define SERVICE_SUBTYPE_SOURCE_VIRTUAL "_virtual._sub."SERVICE_TYPE_SOURCE
66 #define SERVICE_SUBTYPE_SOURCE_MONITOR "_monitor._sub."SERVICE_TYPE_SOURCE
67 #define SERVICE_SUBTYPE_SOURCE_NON_MONITOR "_non-monitor._sub."SERVICE_TYPE_SOURCE
68
69 static const char* const valid_modargs[] = {
70 "port",
71 NULL
72 };
73
74 enum service_subtype {
75 SUBTYPE_HARDWARE,
76 SUBTYPE_VIRTUAL,
77 SUBTYPE_MONITOR
78 };
79
80 struct service {
81 struct userdata *userdata;
82 AvahiEntryGroup *entry_group;
83 char *service_name;
84 pa_object *device;
85 enum service_subtype subtype;
86 };
87
88 struct userdata {
89 pa_core *core;
90 pa_module *module;
91 AvahiPoll *avahi_poll;
92 AvahiClient *client;
93
94 pa_hashmap *services;
95 char *service_name;
96
97 AvahiEntryGroup *main_entry_group;
98
99 uint16_t port;
100
101 pa_hook_slot *sink_new_slot, *source_new_slot, *sink_unlink_slot, *source_unlink_slot, *sink_changed_slot, *source_changed_slot;
102 };
103
104 static void get_service_data(struct service *s, pa_sample_spec *ret_ss, pa_channel_map *ret_map, const char **ret_name, const char **ret_description, enum service_subtype *ret_subtype) {
105 pa_assert(s);
106 pa_assert(ret_ss);
107 pa_assert(ret_description);
108 pa_assert(ret_subtype);
109
110 if (pa_sink_isinstance(s->device)) {
111 pa_sink *sink = PA_SINK(s->device);
112
113 *ret_ss = sink->sample_spec;
114 *ret_map = sink->channel_map;
115 *ret_name = sink->name;
116 *ret_description = pa_strnull(pa_proplist_gets(sink->proplist, PA_PROP_DEVICE_DESCRIPTION));
117 *ret_subtype = sink->flags & PA_SINK_HARDWARE ? SUBTYPE_HARDWARE : SUBTYPE_VIRTUAL;
118
119 } else if (pa_source_isinstance(s->device)) {
120 pa_source *source = PA_SOURCE(s->device);
121
122 *ret_ss = source->sample_spec;
123 *ret_map = source->channel_map;
124 *ret_name = source->name;
125 *ret_description = pa_strnull(pa_proplist_gets(source->proplist, PA_PROP_DEVICE_DESCRIPTION));
126 *ret_subtype = source->monitor_of ? SUBTYPE_MONITOR : (source->flags & PA_SOURCE_HARDWARE ? SUBTYPE_HARDWARE : SUBTYPE_VIRTUAL);
127
128 } else
129 pa_assert_not_reached();
130 }
131
132 static AvahiStringList* txt_record_server_data(pa_core *c, AvahiStringList *l) {
133 char s[128];
134
135 pa_assert(c);
136
137 l = avahi_string_list_add_pair(l, "server-version", PACKAGE_NAME" "PACKAGE_VERSION);
138 l = avahi_string_list_add_pair(l, "user-name", pa_get_user_name(s, sizeof(s)));
139 l = avahi_string_list_add_pair(l, "fqdn", pa_get_fqdn(s, sizeof(s)));
140 l = avahi_string_list_add_printf(l, "cookie=0x%08x", c->cookie);
141
142 return l;
143 }
144
145 static int publish_service(struct service *s);
146
147 static void service_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
148 struct service *s = userdata;
149
150 pa_assert(s);
151
152 switch (state) {
153
154 case AVAHI_ENTRY_GROUP_ESTABLISHED:
155 pa_log_info("Successfully established service %s.", s->service_name);
156 break;
157
158 case AVAHI_ENTRY_GROUP_COLLISION: {
159 char *t;
160
161 t = avahi_alternative_service_name(s->service_name);
162 pa_log_info("Name collision, renaming %s to %s.", s->service_name, t);
163 pa_xfree(s->service_name);
164 s->service_name = t;
165
166 publish_service(s);
167 break;
168 }
169
170 case AVAHI_ENTRY_GROUP_FAILURE: {
171 pa_log("Failed to register service: %s", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
172
173 avahi_entry_group_free(g);
174 s->entry_group = NULL;
175
176 break;
177 }
178
179 case AVAHI_ENTRY_GROUP_UNCOMMITED:
180 case AVAHI_ENTRY_GROUP_REGISTERING:
181 ;
182 }
183 }
184
185 static void service_free(struct service *s);
186
187 static int publish_service(struct service *s) {
188 int r = -1;
189 AvahiStringList *txt = NULL;
190 const char *description = NULL, *name = NULL;
191 pa_sample_spec ss;
192 pa_channel_map map;
193 char cm[PA_CHANNEL_MAP_SNPRINT_MAX];
194 enum service_subtype subtype;
195
196 const char * const subtype_text[] = {
197 [SUBTYPE_HARDWARE] = "hardware",
198 [SUBTYPE_VIRTUAL] = "virtual",
199 [SUBTYPE_MONITOR] = "monitor"
200 };
201
202 pa_assert(s);
203
204 if (!s->userdata->client || avahi_client_get_state(s->userdata->client) != AVAHI_CLIENT_S_RUNNING)
205 return 0;
206
207 if (!s->entry_group) {
208 if (!(s->entry_group = avahi_entry_group_new(s->userdata->client, service_entry_group_callback, s))) {
209 pa_log("avahi_entry_group_new(): %s", avahi_strerror(avahi_client_errno(s->userdata->client)));
210 goto finish;
211 }
212 } else
213 avahi_entry_group_reset(s->entry_group);
214
215 txt = txt_record_server_data(s->userdata->core, txt);
216
217 get_service_data(s, &ss, &map, &name, &description, &subtype);
218 txt = avahi_string_list_add_pair(txt, "device", name);
219 txt = avahi_string_list_add_printf(txt, "rate=%u", ss.rate);
220 txt = avahi_string_list_add_printf(txt, "channels=%u", ss.channels);
221 txt = avahi_string_list_add_pair(txt, "format", pa_sample_format_to_string(ss.format));
222 txt = avahi_string_list_add_pair(txt, "channel_map", pa_channel_map_snprint(cm, sizeof(cm), &map));
223 txt = avahi_string_list_add_pair(txt, "subtype", subtype_text[subtype]);
224
225 if (avahi_entry_group_add_service_strlst(
226 s->entry_group,
227 AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
228 0,
229 s->service_name,
230 pa_sink_isinstance(s->device) ? SERVICE_TYPE_SINK : SERVICE_TYPE_SOURCE,
231 NULL,
232 NULL,
233 s->userdata->port,
234 txt) < 0) {
235
236 pa_log("avahi_entry_group_add_service_strlst(): %s", avahi_strerror(avahi_client_errno(s->userdata->client)));
237 goto finish;
238 }
239
240 if (avahi_entry_group_add_service_subtype(
241 s->entry_group,
242 AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
243 0,
244 s->service_name,
245 pa_sink_isinstance(s->device) ? SERVICE_TYPE_SINK : SERVICE_TYPE_SOURCE,
246 NULL,
247 pa_sink_isinstance(s->device) ? (subtype == SUBTYPE_HARDWARE ? SERVICE_SUBTYPE_SINK_HARDWARE : SERVICE_SUBTYPE_SINK_VIRTUAL) :
248 (subtype == SUBTYPE_HARDWARE ? SERVICE_SUBTYPE_SOURCE_HARDWARE : (subtype == SUBTYPE_VIRTUAL ? SERVICE_SUBTYPE_SOURCE_VIRTUAL : SERVICE_SUBTYPE_SOURCE_MONITOR))) < 0) {
249
250 pa_log("avahi_entry_group_add_service_subtype(): %s", avahi_strerror(avahi_client_errno(s->userdata->client)));
251 goto finish;
252 }
253
254 if (pa_source_isinstance(s->device) && subtype != SUBTYPE_MONITOR) {
255 if (avahi_entry_group_add_service_subtype(
256 s->entry_group,
257 AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
258 0,
259 s->service_name,
260 SERVICE_TYPE_SOURCE,
261 NULL,
262 SERVICE_SUBTYPE_SOURCE_NON_MONITOR) < 0) {
263
264 pa_log("avahi_entry_group_add_service_subtype(): %s", avahi_strerror(avahi_client_errno(s->userdata->client)));
265 goto finish;
266 }
267 }
268
269 if (avahi_entry_group_commit(s->entry_group) < 0) {
270 pa_log("avahi_entry_group_commit(): %s", avahi_strerror(avahi_client_errno(s->userdata->client)));
271 goto finish;
272 }
273
274 r = 0;
275 pa_log_debug("Successfully created entry group for %s.", s->service_name);
276
277 finish:
278
279 /* Remove this service */
280 if (r < 0)
281 service_free(s);
282
283 avahi_string_list_free(txt);
284
285 return r;
286 }
287
288 static struct service *get_service(struct userdata *u, pa_object *device) {
289 struct service *s;
290 char hn[64], un[64];
291 const char *n;
292
293 pa_assert(u);
294 pa_object_assert_ref(device);
295
296 if ((s = pa_hashmap_get(u->services, device)))
297 return s;
298
299 s = pa_xnew(struct service, 1);
300 s->userdata = u;
301 s->entry_group = NULL;
302 s->device = device;
303
304 if (pa_sink_isinstance(device)) {
305 if (!(n = pa_proplist_gets(PA_SINK(device)->proplist, PA_PROP_DEVICE_DESCRIPTION)))
306 n = PA_SINK(device)->name;
307 } else {
308 if (!(n = pa_proplist_gets(PA_SOURCE(device)->proplist, PA_PROP_DEVICE_DESCRIPTION)))
309 n = PA_SOURCE(device)->name;
310 }
311
312 s->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s: %s",
313 pa_get_user_name(un, sizeof(un)),
314 pa_get_host_name(hn, sizeof(hn)),
315 n),
316 AVAHI_LABEL_MAX-1);
317
318 pa_hashmap_put(u->services, s->device, s);
319
320 return s;
321 }
322
323 static void service_free(struct service *s) {
324 pa_assert(s);
325
326 pa_hashmap_remove(s->userdata->services, s->device);
327
328 if (s->entry_group) {
329 pa_log_debug("Removing entry group for %s.", s->service_name);
330 avahi_entry_group_free(s->entry_group);
331 }
332
333 pa_xfree(s->service_name);
334 pa_xfree(s);
335 }
336
337 static pa_bool_t shall_ignore(pa_object *o) {
338 pa_object_assert_ref(o);
339
340 if (pa_sink_isinstance(o))
341 return !!(PA_SINK(o)->flags & PA_SINK_NETWORK);
342
343 if (pa_source_isinstance(o))
344 return PA_SOURCE(o)->monitor_of || (PA_SOURCE(o)->flags & PA_SOURCE_NETWORK);
345
346 pa_assert_not_reached();
347 }
348
349 static pa_hook_result_t device_new_or_changed_cb(pa_core *c, pa_object *o, struct userdata *u) {
350 pa_assert(c);
351 pa_object_assert_ref(o);
352
353 if (!shall_ignore(o))
354 publish_service(get_service(u, o));
355
356 return PA_HOOK_OK;
357 }
358
359 static pa_hook_result_t device_unlink_cb(pa_core *c, pa_object *o, struct userdata *u) {
360 struct service *s;
361
362 pa_assert(c);
363 pa_object_assert_ref(o);
364
365 if ((s = pa_hashmap_get(u->services, o)))
366 service_free(s);
367
368 return PA_HOOK_OK;
369 }
370
371 static int publish_main_service(struct userdata *u);
372
373 static void main_entry_group_callback(AvahiEntryGroup *g, AvahiEntryGroupState state, void *userdata) {
374 struct userdata *u = userdata;
375 pa_assert(u);
376
377 switch (state) {
378
379 case AVAHI_ENTRY_GROUP_ESTABLISHED:
380 pa_log_info("Successfully established main service.");
381 break;
382
383 case AVAHI_ENTRY_GROUP_COLLISION: {
384 char *t;
385
386 t = avahi_alternative_service_name(u->service_name);
387 pa_log_info("Name collision: renaming main service %s to %s.", u->service_name, t);
388 pa_xfree(u->service_name);
389 u->service_name = t;
390
391 publish_main_service(u);
392 break;
393 }
394
395 case AVAHI_ENTRY_GROUP_FAILURE: {
396 pa_log("Failed to register main service: %s", avahi_strerror(avahi_client_errno(avahi_entry_group_get_client(g))));
397
398 avahi_entry_group_free(g);
399 u->main_entry_group = NULL;
400 break;
401 }
402
403 case AVAHI_ENTRY_GROUP_UNCOMMITED:
404 case AVAHI_ENTRY_GROUP_REGISTERING:
405 break;
406 }
407 }
408
409 static int publish_main_service(struct userdata *u) {
410 AvahiStringList *txt = NULL;
411 int r = -1;
412
413 pa_assert(u);
414
415 if (!u->main_entry_group) {
416 if (!(u->main_entry_group = avahi_entry_group_new(u->client, main_entry_group_callback, u))) {
417 pa_log("avahi_entry_group_new() failed: %s", avahi_strerror(avahi_client_errno(u->client)));
418 goto fail;
419 }
420 } else
421 avahi_entry_group_reset(u->main_entry_group);
422
423 txt = txt_record_server_data(u->core, txt);
424
425 if (avahi_entry_group_add_service_strlst(
426 u->main_entry_group,
427 AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
428 0,
429 u->service_name,
430 SERVICE_TYPE_SERVER,
431 NULL,
432 NULL,
433 u->port,
434 txt) < 0) {
435
436 pa_log("avahi_entry_group_add_service_strlst() failed: %s", avahi_strerror(avahi_client_errno(u->client)));
437 goto fail;
438 }
439
440 if (avahi_entry_group_commit(u->main_entry_group) < 0) {
441 pa_log("avahi_entry_group_commit() failed: %s", avahi_strerror(avahi_client_errno(u->client)));
442 goto fail;
443 }
444
445 r = 0;
446
447 fail:
448 avahi_string_list_free(txt);
449
450 return r;
451 }
452
453 static int publish_all_services(struct userdata *u) {
454 pa_sink *sink;
455 pa_source *source;
456 int r = -1;
457 uint32_t idx;
458
459 pa_assert(u);
460
461 pa_log_debug("Publishing services in Zeroconf");
462
463 for (sink = PA_SINK(pa_idxset_first(u->core->sinks, &idx)); sink; sink = PA_SINK(pa_idxset_next(u->core->sinks, &idx)))
464 if (!shall_ignore(PA_OBJECT(sink)))
465 publish_service(get_service(u, PA_OBJECT(sink)));
466
467 for (source = PA_SOURCE(pa_idxset_first(u->core->sources, &idx)); source; source = PA_SOURCE(pa_idxset_next(u->core->sources, &idx)))
468 if (!shall_ignore(PA_OBJECT(source)))
469 publish_service(get_service(u, PA_OBJECT(source)));
470
471 if (publish_main_service(u) < 0)
472 goto fail;
473
474 r = 0;
475
476 fail:
477 return r;
478 }
479
480 static void unpublish_all_services(struct userdata *u, pa_bool_t rem) {
481 void *state = NULL;
482 struct service *s;
483
484 pa_assert(u);
485
486 pa_log_debug("Unpublishing services in Zeroconf");
487
488 while ((s = pa_hashmap_iterate(u->services, &state, NULL))) {
489 if (s->entry_group) {
490 if (rem) {
491 pa_log_debug("Removing entry group for %s.", s->service_name);
492 avahi_entry_group_free(s->entry_group);
493 s->entry_group = NULL;
494 } else {
495 avahi_entry_group_reset(s->entry_group);
496 pa_log_debug("Resetting entry group for %s.", s->service_name);
497 }
498 }
499 }
500
501 if (u->main_entry_group) {
502 if (rem) {
503 pa_log_debug("Removing main entry group.");
504 avahi_entry_group_free(u->main_entry_group);
505 u->main_entry_group = NULL;
506 } else {
507 avahi_entry_group_reset(u->main_entry_group);
508 pa_log_debug("Resetting main entry group.");
509 }
510 }
511 }
512
513 static void client_callback(AvahiClient *c, AvahiClientState state, void *userdata) {
514 struct userdata *u = userdata;
515
516 pa_assert(c);
517 pa_assert(u);
518
519 u->client = c;
520
521 switch (state) {
522 case AVAHI_CLIENT_S_RUNNING:
523 publish_all_services(u);
524 break;
525
526 case AVAHI_CLIENT_S_COLLISION:
527 pa_log_debug("Host name collision");
528 unpublish_all_services(u, FALSE);
529 break;
530
531 case AVAHI_CLIENT_FAILURE:
532 if (avahi_client_errno(c) == AVAHI_ERR_DISCONNECTED) {
533 int error;
534
535 pa_log_debug("Avahi daemon disconnected.");
536
537 unpublish_all_services(u, TRUE);
538 avahi_client_free(u->client);
539
540 if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) {
541 pa_log("avahi_client_new() failed: %s", avahi_strerror(error));
542 pa_module_unload_request(u->module, TRUE);
543 }
544 }
545
546 break;
547
548 default: ;
549 }
550 }
551
552 int pa__init(pa_module*m) {
553
554 struct userdata *u;
555 uint32_t port = PA_NATIVE_DEFAULT_PORT;
556 pa_modargs *ma = NULL;
557 char hn[256], un[256];
558 int error;
559
560 if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
561 pa_log("Failed to parse module arguments.");
562 goto fail;
563 }
564
565 if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port <= 0 || port > 0xFFFF) {
566 pa_log("Invalid port specified.");
567 goto fail;
568 }
569
570 m->userdata = u = pa_xnew(struct userdata, 1);
571 u->core = m->core;
572 u->module = m;
573 u->port = (uint16_t) port;
574
575 u->avahi_poll = pa_avahi_poll_new(m->core->mainloop);
576
577 u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
578
579 u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
580 u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
581 u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u);
582 u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
583 u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u);
584 u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u);
585
586 u->main_entry_group = NULL;
587
588 u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", pa_get_user_name(un, sizeof(un)), pa_get_host_name(hn, sizeof(hn))), AVAHI_LABEL_MAX);
589
590 if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) {
591 pa_log("avahi_client_new() failed: %s", avahi_strerror(error));
592 goto fail;
593 }
594
595 pa_modargs_free(ma);
596
597 return 0;
598
599 fail:
600 pa__done(m);
601
602 if (ma)
603 pa_modargs_free(ma);
604
605 return -1;
606 }
607
608 void pa__done(pa_module*m) {
609 struct userdata*u;
610 pa_assert(m);
611
612 if (!(u = m->userdata))
613 return;
614
615 if (u->services) {
616 struct service *s;
617
618 while ((s = pa_hashmap_first(u->services)))
619 service_free(s);
620
621 pa_hashmap_free(u->services, NULL, NULL);
622 }
623
624 if (u->sink_new_slot)
625 pa_hook_slot_free(u->sink_new_slot);
626 if (u->source_new_slot)
627 pa_hook_slot_free(u->source_new_slot);
628 if (u->sink_changed_slot)
629 pa_hook_slot_free(u->sink_changed_slot);
630 if (u->source_changed_slot)
631 pa_hook_slot_free(u->source_changed_slot);
632 if (u->sink_unlink_slot)
633 pa_hook_slot_free(u->sink_unlink_slot);
634 if (u->source_unlink_slot)
635 pa_hook_slot_free(u->source_unlink_slot);
636
637 if (u->main_entry_group)
638 avahi_entry_group_free(u->main_entry_group);
639
640 if (u->client)
641 avahi_client_free(u->client);
642
643 if (u->avahi_poll)
644 pa_avahi_poll_free(u->avahi_poll);
645
646 pa_xfree(u->service_name);
647 pa_xfree(u);
648 }