Commit 5d79aced authored by Jim Ramsay's avatar Jim Ramsay

Added zeroconf service publishing using avahi

git-svn-id: https://svn.musicpd.org/mpd/trunk@5238 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 2d985b01
......@@ -101,6 +101,7 @@ AC_ARG_WITH(mad-includes,[ --with-mad-includes=DIR Directory where mad head
AC_ARG_WITH(faad,[ --with-faad=PFX Prefix where faad2 is installed], faad_prefix="$withval", faad_prefix="")
AC_ARG_WITH(faad-libraries,[ --with-faad-libraries=DIR Directory where faad2 library is installed (optional)], faad_libraries="$withval", faad_libraries="")
AC_ARG_WITH(faad-includes,[ --with-faad-includes=DIR Directory where faad2 header files are installed (optional)], faad_includes="$withval", faad_includes="")
AC_ARG_WITH(zeroconf,[[ --with-zeroconf=[auto|avahi|bonjour|no] Enable zeroconf backend (default=auto)]], with_zeroconf="$withval", with_zeroconf="auto")
AC_C_BIGENDIAN
......@@ -587,6 +588,36 @@ if test x$enable_mod = xyes; then
fi
fi
if test x$with_zeroconf != xno -a \
x$with_zeroconf != xavahi -a \
x$with_zeroconf != xbonjour; then
with_zeroconf=auto
fi
if test x$with_zeroconf != xno; then
if test x$with_zeroconf = xauto; then
PKG_CHECK_MODULES([AVAHI], [avahi-client],
[with_zeroconf=avahi;AC_DEFINE([HAVE_AVAHI], 1, [Define to enable Avahi Zeroconf support])] MPD_LIBS="$MPD_LIBS $AVAHI_LIBS" MPD_CFLAGS="$MPD_CFLAGS $AVAHI_CFLAGS",
[with_zeroconf=auto])
elif test x$with_zeroconf = xavahi; then
PKG_CHECK_MODULES([AVAHI], [avahi-client],
[with_zeroconf=avahi;AC_DEFINE([HAVE_AVAHI], 1, [Define to enable Avahi Zeroconf support])] MPD_LIBS="$MPD_LIBS $AVAHI_LIBS" MPD_CFLAGS="$MPD_CFLAGS $AVAHI_CFLAGS")
fi
# In the future, should add bonjour support (for OSX) and check at autodetect
# time
#if test x$with_zeroconf = xbonjour -o x$with_zeroconf = xauto; then
if test x$with_zeroconf = xbonjour; then
AC_MSG_WARN([Bonjour support has not been implemented yet, disabling Zeroconf])
with_zeroconf=no
fi
if test x$with_zeroconf = xauto; then
AC_MSG_WARN([No supported Zeroconf backend found, disabling Zeroconf])
with_zeroconf=no
fi
fi
AC_OUTPUT(src/mp4ff/Makefile doc/Makefile src/Makefile Makefile )
echo ""
......@@ -736,6 +767,15 @@ if
fi
echo ""
echo " Other features:"
if test x$with_zeroconf != xno; then
echo " Zeroconf support ..............$with_zeroconf"
else
echo " Zeroconf support ..............disabled"
fi
echo ""
echo "##########################################"
echo ""
echo "You are now ready to compile MPD"
......
......@@ -45,6 +45,12 @@ error_file "~/.mpd/mpd.error"
#
#log_level "default"
#
# If Zeroconf is configured, the service name to publish. This
# should be unique on your local network, but name collisions
# will be taken care of for you.
#
#zeroconf_name "Music Player"
#
################################################################
......
......@@ -73,7 +73,8 @@ mpd_headers = \
utf8.h \
utils.h \
volume.h \
localization.h
localization.h \
zeroconf.h
mpd_SOURCES = \
......@@ -123,7 +124,8 @@ mpd_SOURCES = \
utils.c \
volume.c \
utf8.c \
localization.c
localization.c \
zeroconf.c
mpd_CFLAGS = $(MPD_CFLAGS)
......
......@@ -146,6 +146,7 @@ void initConf(void)
registerConfigParam(CONF_BIND_TO_ADDRESS, 1, 0);
registerConfigParam(CONF_PORT, 0, 0);
registerConfigParam(CONF_LOG_LEVEL, 0, 0);
registerConfigParam(CONF_ZEROCONF_NAME, 0, 0);
registerConfigParam(CONF_PASSWORD, 1, 0);
registerConfigParam(CONF_DEFAULT_PERMS, 0, 0);
registerConfigParam(CONF_AUDIO_OUTPUT, 1, 1);
......
......@@ -32,6 +32,7 @@
#define CONF_BIND_TO_ADDRESS "bind_to_address"
#define CONF_PORT "port"
#define CONF_LOG_LEVEL "log_level"
#define CONF_ZEROCONF_NAME "zeroconf_name"
#define CONF_PASSWORD "password"
#define CONF_DEFAULT_PERMS "default_permissions"
#define CONF_AUDIO_OUTPUT "audio_output"
......
......@@ -26,6 +26,7 @@
#include "permission.h"
#include "sllist.h"
#include "utils.h"
#include "ioops.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -62,6 +63,9 @@ static size_t interface_max_command_list_size =
static size_t interface_max_output_buffer_size =
INTERFACE_MAX_OUTPUT_BUFFER_SIZE_DEFAULT;
/* List of registered external IO handlers */
static struct ioOps *ioList;
/* maybe make conf option for this, or... 32 might be good enough */
static long int interface_list_cache_size = 32;
......@@ -488,6 +492,7 @@ int doIOForInterfaces(void)
{
fd_set rfds;
fd_set wfds;
fd_set efds;
struct timeval tv;
int i;
int selret;
......@@ -499,12 +504,43 @@ int doIOForInterfaces(void)
while (1) {
fdmax = 0;
FD_ZERO( &rfds );
FD_ZERO( &wfds );
FD_ZERO( &efds );
addInterfacesReadyToReadAndListenSocketToFdSet(&rfds, &fdmax);
addInterfacesForBufferFlushToFdSet(&wfds, &fdmax);
selret = select(fdmax + 1, &rfds, &wfds, NULL, &tv);
// Add fds for all registered IO handlers
if( ioList ) {
struct ioOps *i = ioList;
while( i ) {
struct ioOps *current = i;
int fdnum;
assert( current->fdset );
fdnum = current->fdset( &rfds, &wfds, &efds );
if( fdmax < fdnum )
fdmax = fdnum;
i = i->next;
}
}
selret = select(fdmax + 1, &rfds, &wfds, &efds, &tv);
if (selret < 0 && errno == EINTR)
break;
// Consume fds for all registered IO handlers
if( ioList ) {
struct ioOps *i = ioList;
while( i ) {
struct ioOps *current = i;
assert( current->consume );
selret = current->consume( selret, &rfds, &wfds, &efds );
i = i->next;
}
}
if (selret == 0 || (selret < 0 && errno == EINTR))
if (selret == 0)
break;
if (selret < 0) {
......@@ -794,3 +830,25 @@ static void printInterfaceOutBuffer(Interface * interface)
interface->send_buf_used = 0;
}
// From ioops.h:
void registerIO( struct ioOps *ops )
{
assert( ops != NULL );
ops->next = ioList;
ioList = ops;
ops->prev = NULL;
if( ops->next )
ops->next->prev = ops;
}
void deregisterIO( struct ioOps *ops )
{
assert( ops != NULL );
if( ioList == ops )
ioList = ops->next;
else if( ops->prev != NULL )
ops->prev->next = ops->next;
}
/* the Music Player Daemon (MPD)
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* 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.
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef IOOPS_H
#define IOOPS_H
#include <sys/select.h>
struct ioOps {
struct ioOps *prev, *next;
// Called before each 'select' statement.
// To register for IO, call FD_SET for each required queue
// Return the highest fd number you registered
int (*fdset) ( fd_set *rfds, fd_set *wfds, fd_set *efds );
// Called after each 'select' statement.
// fdCount is the number of fds total in all sets. It may be 0.
// For each fd you registered for in (fdset), you should FD_CLR it from the
// appropriate queue(s).
// Return the total number of fds left in all sets (Ie, return fdCount
// minus the number of times you called FD_CLR).
int (*consume) ( int fdCount, fd_set *rfds, fd_set *wfds, fd_set *efds );
};
// Call this to register your io operation handler struct
void registerIO( struct ioOps *ops );
// Call this to deregister your io operation handler struct
void deregisterIO( struct ioOps *ops );
#endif
......@@ -47,6 +47,7 @@
int *listenSockets = NULL;
int numberOfListenSockets = 0;
static int boundPort = 0;
static int establishListen(unsigned int port,
struct sockaddr *addrp, socklen_t addrlen)
......@@ -211,6 +212,8 @@ void listenOnPort(void)
}
}
boundPort = port;
do {
parseListenConfigParam(port, param);
} while ((param = getNextConfigParam(CONF_BIND_TO_ADDRESS, param)));
......@@ -266,3 +269,8 @@ void getConnections(fd_set * fds)
}
}
}
int getBoundPort()
{
return boundPort;
}
......@@ -36,4 +36,6 @@ void freeAllListenSockets(void);
/* fdmax should be initialized to something */
void addListenSocketsToFdSet(fd_set * fds, int *fdmax);
int getBoundPort(void);
#endif
......@@ -42,6 +42,7 @@
#include "../config.h"
#include "utils.h"
#include "normalize.h"
#include "zeroconf.h"
#include "localization.h"
#include <stdio.h>
......@@ -452,6 +453,7 @@ int main(int argc, char *argv[])
initAudioDriver();
initVolume();
initInterfaces();
initZeroconf();
initReplayGainState();
initNormalization();
initInputStream();
......@@ -477,6 +479,7 @@ int main(int argc, char *argv[])
write_state_file();
playerKill();
finishZeroconf();
freeAllInterfaces();
closeAllListenSockets();
finishPlaylist();
......
This diff is collapsed. Click to expand it.
/* the Music Player Daemon (MPD)
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* 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.
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ZEROCONF_H
#define ZEROCONF_H
#include "../config.h"
void initZeroconf(void);
void finishZeroconf(void);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment