2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2007-01-11 21:41:17 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2007-01-11 21:41:17 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-27 22:18:45 +01:00
|
|
|
#include "ZeroconfGlue.hxx"
|
|
|
|
#include "ZeroconfAvahi.hxx"
|
|
|
|
#include "ZeroconfBonjour.hxx"
|
2013-09-05 08:47:10 +02:00
|
|
|
#include "ConfigGlobal.hxx"
|
|
|
|
#include "ConfigOption.hxx"
|
2013-01-03 11:05:44 +01:00
|
|
|
#include "Listen.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "util/Domain.hxx"
|
|
|
|
#include "Log.hxx"
|
2013-10-15 09:21:13 +02:00
|
|
|
#include "Compiler.h"
|
2007-01-11 21:41:17 +01:00
|
|
|
|
2013-09-27 22:31:24 +02:00
|
|
|
static constexpr Domain zeroconf_domain("zeroconf");
|
2008-11-24 14:40:40 +01:00
|
|
|
|
2008-01-03 11:03:28 +01:00
|
|
|
/* The default service name to publish
|
2007-01-11 21:41:17 +01:00
|
|
|
* (overridden by 'zeroconf_name' config parameter)
|
|
|
|
*/
|
|
|
|
#define SERVICE_NAME "Music Player"
|
|
|
|
|
2007-06-03 21:25:25 +02:00
|
|
|
#define DEFAULT_ZEROCONF_ENABLED 1
|
|
|
|
|
2007-06-03 21:30:37 +02:00
|
|
|
static int zeroconfEnabled;
|
2007-06-02 19:06:08 +02:00
|
|
|
|
2013-01-27 22:18:45 +01:00
|
|
|
void
|
2013-01-27 22:32:10 +01:00
|
|
|
ZeroconfInit(gcc_unused EventLoop &loop)
|
2007-01-14 03:08:09 +01:00
|
|
|
{
|
2009-01-27 20:17:44 +01:00
|
|
|
const char *serviceName;
|
2007-06-03 20:08:51 +02:00
|
|
|
|
2009-01-17 20:23:33 +01:00
|
|
|
zeroconfEnabled = config_get_bool(CONF_ZEROCONF_ENABLED,
|
|
|
|
DEFAULT_ZEROCONF_ENABLED);
|
2007-06-03 21:25:25 +02:00
|
|
|
if (!zeroconfEnabled)
|
2007-06-03 20:08:51 +02:00
|
|
|
return;
|
2007-01-14 03:08:09 +01:00
|
|
|
|
2012-02-13 21:04:50 +01:00
|
|
|
if (listen_port <= 0) {
|
2013-09-27 22:31:24 +02:00
|
|
|
LogInfo(zeroconf_domain,
|
|
|
|
"No global port, disabling zeroconf");
|
2012-02-13 21:04:50 +01:00
|
|
|
zeroconfEnabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-27 20:17:44 +01:00
|
|
|
serviceName = config_get_string(CONF_ZEROCONF_NAME, SERVICE_NAME);
|
2007-06-02 19:06:08 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_AVAHI
|
2013-01-27 22:53:21 +01:00
|
|
|
AvahiInit(loop, serviceName);
|
2007-06-02 19:06:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_BONJOUR
|
2013-01-27 22:32:10 +01:00
|
|
|
BonjourInit(loop, serviceName);
|
2007-06-02 19:06:08 +02:00
|
|
|
#endif
|
2007-01-11 21:41:17 +01:00
|
|
|
}
|
|
|
|
|
2013-01-27 22:18:45 +01:00
|
|
|
void
|
|
|
|
ZeroconfDeinit()
|
2007-01-11 21:41:17 +01:00
|
|
|
{
|
2007-06-03 21:25:25 +02:00
|
|
|
if (!zeroconfEnabled)
|
2007-06-03 20:08:51 +02:00
|
|
|
return;
|
|
|
|
|
2007-01-14 05:25:27 +01:00
|
|
|
#ifdef HAVE_AVAHI
|
2013-01-27 22:18:45 +01:00
|
|
|
AvahiDeinit();
|
2007-05-16 01:23:09 +02:00
|
|
|
#endif /* HAVE_AVAHI */
|
2007-06-02 19:06:08 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_BONJOUR
|
2013-01-27 22:18:45 +01:00
|
|
|
BonjourDeinit();
|
2007-06-02 19:06:08 +02:00
|
|
|
#endif
|
2007-01-11 21:41:17 +01:00
|
|
|
}
|