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