zeroconf.c 1.75 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2011 The Music Player Daemon Project
3
 * http://www.musicpd.org
4 5 6 7 8 9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 19
 */

20
#include "config.h"
21
#include "zeroconf.h"
22
#include "zeroconf-internal.h"
23
#include "conf.h"
Max Kellermann's avatar
Max Kellermann committed
24
#include "Listen.hxx"
25

26 27
#include <glib.h>

28
/* The default service name to publish
29 30 31 32
 * (overridden by 'zeroconf_name' config parameter)
 */
#define SERVICE_NAME		"Music Player"

33 34
#define DEFAULT_ZEROCONF_ENABLED 1

35
static int zeroconfEnabled;
36

37 38
void initZeroconf(void)
{
39
	const char *serviceName;
40

41 42
	zeroconfEnabled = config_get_bool(CONF_ZEROCONF_ENABLED,
					  DEFAULT_ZEROCONF_ENABLED);
43
	if (!zeroconfEnabled)
44
		return;
45

46 47 48 49 50 51
	if (listen_port <= 0) {
		g_warning("No global port, disabling zeroconf");
		zeroconfEnabled = false;
		return;
	}

52
	serviceName = config_get_string(CONF_ZEROCONF_NAME, SERVICE_NAME);
53 54

#ifdef HAVE_AVAHI
55
	init_avahi(serviceName);
56 57 58 59 60
#endif

#ifdef HAVE_BONJOUR
	init_zeroconf_osx(serviceName);
#endif
61 62 63 64
}

void finishZeroconf(void)
{
65
	if (!zeroconfEnabled)
66 67
		return;

68
#ifdef HAVE_AVAHI
69
	avahi_finish();
70
#endif /* HAVE_AVAHI */
71 72

#ifdef HAVE_BONJOUR
73
	bonjour_finish();
74
#endif
75
}