mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-24 06:05:56 -05:00
Remove non-Avahi mDNS backends
This commit is contained in:
parent
3a8c7b3c41
commit
a278c5998c
31
configure.in
31
configure.in
@ -22,8 +22,6 @@ AC_CHECK_FUNCS(timegm)
|
||||
AC_CHECK_FUNCS(va_copy)
|
||||
AC_CHECK_FUNCS(__va_copy)
|
||||
|
||||
AM_CONDITIONAL(COND_REND_OSX,false)
|
||||
|
||||
AC_FUNC_SETPGRP
|
||||
|
||||
if test "x$prefix" != xNONE -a "x$prefix" != "x/usr"; then
|
||||
@ -79,7 +77,7 @@ AC_ARG_ENABLE(sqlite3,[ --enable-sqlite3 Enable sqlite3 db backend],
|
||||
AC_ARG_ENABLE(mdns,[ --enable-mdns Enable mDNS support],
|
||||
[ case "${enableval}" in
|
||||
yes) ;;
|
||||
no) rend_howl=false; rend_avahi=false; CPPFLAGS="${CPPFLAGS} -DWITHOUT_MDNS";;
|
||||
no) rend_avahi=false; CPPFLAGS="${CPPFLAGS} -DWITHOUT_MDNS";;
|
||||
*) AC_MSG_ERROR(bad value ${enableval} for --disable-mdns);;
|
||||
esac ])
|
||||
|
||||
@ -89,20 +87,12 @@ AC_ARG_ENABLE(nslu2,[ --enable-nslu2 Build for NSLU2/uNSLUng],
|
||||
AC_ARG_ENABLE(avahi,[ --enable-avahi Use avahi 0.6 or later],
|
||||
[ case "${enableval}" in
|
||||
yes) PKG_CHECK_MODULES(AVAHI, [ avahi-client >= 0.6 ]);
|
||||
rend_avahi=true; rend_howl=false; LDFLAGS="${LDFLAGS} $AVAHI_LIBS";
|
||||
rend_avahi=true; LDFLAGS="${LDFLAGS} $AVAHI_LIBS";
|
||||
CPPFLAGS="${CPPFLAGS} $AVAHI_CFLAGS -DWITH_AVAHI";;
|
||||
no) rend_avahi=false;;
|
||||
*) AC_MSG_ERROR(bad value ${enableval} for --enable-avahi);;
|
||||
esac ])
|
||||
|
||||
AC_ARG_ENABLE(howl,[ --enable-howl Use howl 0.9.2 or later],
|
||||
[ case "${enableval}" in
|
||||
yes) rend_howl=true; rend_avahi=false; LIBS="${LIBS} -lhowl";
|
||||
CPPFLAGS="${CPPFLAGS} -DWITH_HOWL";;
|
||||
no) rend_howl=false;;
|
||||
*) AC_MSG_ERROR(bad value ${enableval} for --enable-howl);;
|
||||
esac ])
|
||||
|
||||
AC_ARG_ENABLE(oggvorbis,[ --enable-oggvorbis Enable Ogg/Vorbis support],
|
||||
[ case "${enableval}" in
|
||||
yes) use_oggvorbis=true;
|
||||
@ -135,7 +125,6 @@ AC_ARG_ENABLE(mem-debug,[ --enable-mem-debug Enable memory debugging],
|
||||
AC_ARG_ENABLE(ssl,[ --enable-ssl Enable SSL support in web server],
|
||||
CPPFLAGS="${CPPFLAGS} -DUSE_SSL"; use_ssl=true; )
|
||||
|
||||
AM_CONDITIONAL(COND_REND_HOWL, test x$rend_howl = xtrue)
|
||||
AM_CONDITIONAL(COND_REND_AVAHI, test x$rend_avahi = xtrue)
|
||||
AM_CONDITIONAL(COND_OGGVORBIS, test x$use_oggvorbis = xtrue)
|
||||
AM_CONDITIONAL(COND_FLAC, test x$use_flac = xtrue)
|
||||
@ -178,22 +167,6 @@ AC_ARG_WITH(static-libs,
|
||||
fi
|
||||
])
|
||||
|
||||
AC_ARG_WITH(howl-includes,
|
||||
[--with-howl-includes[[=DIR]] use howl include files in DIR],[
|
||||
if test "$withval" != "no" -a "$withval" != "yes"; then
|
||||
Z_DIR=$withval
|
||||
CPPFLAGS="${CPPFLAGS} -I$withval"
|
||||
fi
|
||||
])
|
||||
|
||||
AC_ARG_WITH(howl-libs,
|
||||
[--with-howl-libs[[=DIR]] use howl lib files in DIR],[
|
||||
if test "$withval" != "no" -a "$withval" != "yes"; then
|
||||
Z_DIR=$withval
|
||||
LDFLAGS="${LDFLAGS} -L$withval -R$withval"
|
||||
fi
|
||||
])
|
||||
|
||||
AC_ARG_WITH(ssl-includes,
|
||||
[--with-ssl-includes[[=DIR]] use ssl include files in DIR],[
|
||||
if test "$withval" != "no" -a "$withval" != "yes"; then
|
||||
|
@ -7,14 +7,6 @@ bin_PROGRAMS = wavstreamer
|
||||
|
||||
LDADD=
|
||||
|
||||
if COND_REND_HOWL
|
||||
HRENDSRC=rend-howl.c rend-unix.c
|
||||
endif
|
||||
|
||||
if COND_REND_OSX
|
||||
ORENDSRC=rend-osx.c rend-unix.c
|
||||
endif
|
||||
|
||||
if COND_REND_AVAHI
|
||||
ARENDSRC=rend-avahi.c
|
||||
endif
|
||||
@ -56,7 +48,7 @@ wavstreamer_SOURCES = wavstreamer.c
|
||||
|
||||
mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
|
||||
webserver.h configfile.c configfile.h err.c err.h restart.c restart.h \
|
||||
mp3-scanner.h mp3-scanner.c rend-unix.h \
|
||||
mp3-scanner.h mp3-scanner.c \
|
||||
db-generic.c db-generic.h ff-plugins.c ff-plugins.h \
|
||||
rxml.c rxml.h redblack.c redblack.h scan-mp3.c scan-aif.c \
|
||||
scan-xml.c scan-wma.c scan-aac.c scan-aac.h scan-wav.c scan-url.c \
|
||||
@ -65,11 +57,11 @@ mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
|
||||
os-unix.h os-unix.c os.h plugin.c plugin.h db-sql-updates.c \
|
||||
memdebug.c memdebug.h ssl.h io.h io.c io-errors.h io-plugin.h \
|
||||
bsd-snprintf.c bsd-snprintf.h \
|
||||
$(ORENDSRC) $(HRENDSRC) $(ARENDSRC) $(OGGVORBISSRC) \
|
||||
$(ARENDSRC) $(OGGVORBISSRC) \
|
||||
$(FLACSRC) $(MUSEPACKSRC) $(SQLITEDB) $(SQLITE3DB) $(SQLDB) $(GDBM) \
|
||||
$(UPNP)
|
||||
|
||||
EXTRA_DIST = rend-howl.c rend-osx.c scan-mpc.c \
|
||||
EXTRA_DIST = scan-mpc.c \
|
||||
scan-ogg.c scan-flac.c db-sql.c db-sql.h \
|
||||
db-sql-sqlite2.h db-sql-sqlite2.c \
|
||||
db-sql-sqlite3.h db-sql-sqlite3.c \
|
||||
|
@ -1136,10 +1136,6 @@ void config_emit_flags(WS_CONNINFO *pwsc, void *value, char *arg) {
|
||||
ws_writefd(pwsc,"%s ","--with-gdbm");
|
||||
#endif
|
||||
|
||||
#ifdef WITH_HOWL
|
||||
ws_writefd(pwsc,"%s ","--enable-howl");
|
||||
#endif
|
||||
|
||||
#ifdef NSLU2
|
||||
ws_writefd(pwsc,"%s ","--enable-nslu2");
|
||||
#endif
|
||||
|
186
src/rend-howl.c
186
src/rend-howl.c
@ -1,186 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* Rendezvous for SwampWolf's Howl (http://www.swampwolf.com)
|
||||
*
|
||||
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <howl.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "daapd.h"
|
||||
#include "err.h"
|
||||
#include "os-unix.h"
|
||||
#include "rend-unix.h"
|
||||
|
||||
pthread_t rend_tid;
|
||||
sw_discovery rend_handle;
|
||||
|
||||
/* Forwards */
|
||||
void *rend_pipe_monitor(void* arg);
|
||||
void rend_callback(void);
|
||||
|
||||
/*
|
||||
* rend_howl_reply
|
||||
*
|
||||
* Callback function for mDNS stuff
|
||||
*/
|
||||
static sw_result rend_howl_reply(sw_discovery discovery,
|
||||
sw_discovery_publish_status status,
|
||||
sw_discovery_oid oid,
|
||||
sw_opaque extra) {
|
||||
static sw_string status_text[] = {
|
||||
"started",
|
||||
"stopped",
|
||||
"name collision",
|
||||
"invalid"
|
||||
};
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Publish reply: %s\n",status_text[status]);
|
||||
return SW_OKAY;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rend_private_init
|
||||
*
|
||||
* Initialize howl and start runloop
|
||||
*/
|
||||
int rend_private_init(char *user) {
|
||||
DPRINTF(E_DBG,L_REND,"Starting rendezvous services\n");
|
||||
signal(SIGHUP, SIG_IGN); // SIGHUP might happen from a request to reload the daap server
|
||||
|
||||
if(sw_discovery_init(&rend_handle) != SW_OKAY) {
|
||||
DPRINTF(E_WARN,L_REND,"Error initializing howl\n");
|
||||
errno=EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(os_drop_privs(user))
|
||||
return -1;
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Starting polling thread\n");
|
||||
|
||||
if(pthread_create(&rend_tid,NULL,rend_pipe_monitor,NULL)) {
|
||||
DPRINTF(E_FATAL,L_REND,"Could not start thread. Terminating\n");
|
||||
/* should kill parent, too */
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Entering runloop\n");
|
||||
|
||||
sw_discovery_run(rend_handle);
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Exiting runloop\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_pipe_monitor
|
||||
*/
|
||||
void *rend_pipe_monitor(void* arg) {
|
||||
fd_set rset;
|
||||
int result;
|
||||
|
||||
while(1) {
|
||||
DPRINTF(E_DBG,L_REND,"Waiting for data\n");
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(rend_pipe_to[RD_SIDE],&rset);
|
||||
|
||||
/* sit in a select spin until there is data on the to fd */
|
||||
while(((result=select(rend_pipe_to[RD_SIDE] + 1,&rset,NULL,NULL,NULL)) != -1) &&
|
||||
errno != EINTR) {
|
||||
if(FD_ISSET(rend_pipe_to[RD_SIDE],&rset)) {
|
||||
DPRINTF(E_DBG,L_REND,"Received a message from daap server\n");
|
||||
rend_callback();
|
||||
}
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Select error!\n");
|
||||
/* should really bail here */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* rend_callback
|
||||
*
|
||||
* This gets called from the main thread when there is a
|
||||
* message waiting to be processed.
|
||||
*/
|
||||
void rend_callback(void) {
|
||||
REND_MESSAGE msg;
|
||||
sw_discovery_oid rend_oid;
|
||||
sw_result result;
|
||||
|
||||
/* here, we've seen the message, now we have to process it */
|
||||
|
||||
if(rend_read_message(&msg) != sizeof(msg)) {
|
||||
DPRINTF(E_FATAL,L_REND,"Rendezvous socket closed (daap server crashed?) Aborting.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
switch(msg.cmd) {
|
||||
case REND_MSG_TYPE_REGISTER:
|
||||
DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port);
|
||||
if((result=sw_discovery_publish(rend_handle,
|
||||
0, /* interface handle */
|
||||
msg.name,
|
||||
msg.type,
|
||||
NULL, /* domain */
|
||||
NULL, /* host */
|
||||
msg.port,
|
||||
(sw_octets) msg.txt,
|
||||
strlen(msg.txt),
|
||||
rend_howl_reply,
|
||||
NULL,
|
||||
&rend_oid)) != SW_OKAY) {
|
||||
DPRINTF(E_WARN,L_REND,"Error registering name\n");
|
||||
rend_send_response(-1);
|
||||
} else {
|
||||
rend_send_response(0); /* success */
|
||||
}
|
||||
break;
|
||||
case REND_MSG_TYPE_UNREGISTER:
|
||||
DPRINTF(E_WARN,L_REND,"Unsupported function: UNREGISTER\n");
|
||||
rend_send_response(-1); /* error */
|
||||
break;
|
||||
case REND_MSG_TYPE_STOP:
|
||||
DPRINTF(E_DBG,L_REND,"Stopping mDNS\n");
|
||||
rend_send_response(0);
|
||||
//sw_rendezvous_stop_publish(rend_handle);
|
||||
sw_discovery_fina(rend_handle);
|
||||
break;
|
||||
case REND_MSG_TYPE_STATUS:
|
||||
DPRINTF(E_DBG,L_REND,"Status inquiry -- returning 0\n");
|
||||
rend_send_response(0); /* success */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
259
src/rend-osx.c
259
src/rend-osx.c
@ -1,259 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* Rendezvous - OSX style
|
||||
*
|
||||
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <libc.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <DNSServiceDiscovery/DNSServiceDiscovery.h>
|
||||
|
||||
#include "daapd.h"
|
||||
#include "err.h"
|
||||
#include "os-unix.h"
|
||||
#include "rend-unix.h"
|
||||
|
||||
CFRunLoopRef rend_runloop;
|
||||
CFRunLoopSourceRef rend_rls;
|
||||
pthread_t rend_tid;
|
||||
|
||||
/* Forwards */
|
||||
void *rend_pipe_monitor(void* arg);
|
||||
|
||||
/*
|
||||
* rend_stoprunloop
|
||||
*/
|
||||
static void rend_stoprunloop(void) {
|
||||
CFRunLoopStop(rend_runloop);
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_sigint
|
||||
*/
|
||||
/*
|
||||
static void rend_sigint(int sigraised) {
|
||||
DPRINTF(E_INF,L_REND,"SIGINT\n");
|
||||
rend_stoprunloop();
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* rend_handler
|
||||
*/
|
||||
static void rend_handler(CFMachPortRef port, void *msg, CFIndex size, void *info) {
|
||||
DNSServiceDiscovery_handleReply(msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_addtorunloop
|
||||
*/
|
||||
static int rend_addtorunloop(dns_service_discovery_ref client) {
|
||||
mach_port_t port=DNSServiceDiscoveryMachPort(client);
|
||||
|
||||
if(!port)
|
||||
return -1;
|
||||
else {
|
||||
CFMachPortContext context = { 0, 0, NULL, NULL, NULL };
|
||||
Boolean shouldFreeInfo;
|
||||
CFMachPortRef cfMachPort=CFMachPortCreateWithPort(kCFAllocatorDefault,
|
||||
port, rend_handler,
|
||||
&context, &shouldFreeInfo);
|
||||
|
||||
CFRunLoopSourceRef rls=CFMachPortCreateRunLoopSource(NULL,cfMachPort,0);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(),
|
||||
rls,kCFRunLoopDefaultMode);
|
||||
CFRelease(rls);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_reply
|
||||
*/
|
||||
static void rend_reply(DNSServiceRegistrationReplyErrorType errorCode, void *context) {
|
||||
switch(errorCode) {
|
||||
case kDNSServiceDiscoveryNoError:
|
||||
DPRINTF(E_DBG,L_REND,"Registered successfully\n");
|
||||
break;
|
||||
case kDNSServiceDiscoveryNameConflict:
|
||||
DPRINTF(E_WARN,L_REND,"Error - name in use\n");
|
||||
break;
|
||||
default:
|
||||
DPRINTF(E_WARN,L_REND,"Error %d\n",errorCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_pipe_monitor
|
||||
*/
|
||||
void *rend_pipe_monitor(void* arg) {
|
||||
fd_set rset;
|
||||
int result;
|
||||
|
||||
|
||||
while(1) {
|
||||
DPRINTF(E_DBG,L_REND,"Waiting for data\n");
|
||||
FD_ZERO(&rset);
|
||||
FD_SET(rend_pipe_to[RD_SIDE],&rset);
|
||||
|
||||
/* sit in a select spin until there is data on the to fd */
|
||||
while(((result=select(rend_pipe_to[RD_SIDE] + 1,&rset,NULL,NULL,NULL)) != -1) &&
|
||||
errno != EINTR) {
|
||||
if(FD_ISSET(rend_pipe_to[RD_SIDE],&rset)) {
|
||||
DPRINTF(E_DBG,L_REND,"Received a message from daap server\n");
|
||||
CFRunLoopSourceSignal(rend_rls);
|
||||
CFRunLoopWakeUp(rend_runloop);
|
||||
sleep(1); /* force a reschedule, hopefully */
|
||||
}
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Select error!\n");
|
||||
/* should really bail here */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a text stanza to the buffer (pascal-style multistring)
|
||||
*
|
||||
* @param buffer where to put the text info
|
||||
* @param string what pascal string to append
|
||||
*/
|
||||
void rend_add_text(char *buffer, char *string) {
|
||||
char *ptr=&buffer[strlen(buffer)];
|
||||
*ptr=strlen(string);
|
||||
strcpy(ptr+1,string);
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_callback
|
||||
*
|
||||
* This gets called from the main thread when there is a
|
||||
* message waiting to be processed.
|
||||
*/
|
||||
void rend_callback(void *info) {
|
||||
REND_MESSAGE msg;
|
||||
unsigned short usPort;
|
||||
dns_service_discovery_ref dns_ref=NULL;
|
||||
char *src,*dst;
|
||||
int len;
|
||||
|
||||
/* here, we've seen the message, now we have to process it */
|
||||
if(rend_read_message(&msg) != sizeof(msg)) {
|
||||
DPRINTF(E_FATAL,L_REND,"Rendezvous socket closed (daap server crashed?) Aborting.\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
src=dst=msg.txt;
|
||||
while(src && (*src) && (src - msg.txt < MAX_TEXT_LEN)) {
|
||||
len = (*src);
|
||||
if((src + len + 1) - msg.txt < MAX_TEXT_LEN) {
|
||||
memmove(dst,src+1,len);
|
||||
dst += len;
|
||||
if(*src) {
|
||||
*dst++ = '\001';
|
||||
} else {
|
||||
*dst='\0';
|
||||
}
|
||||
}
|
||||
src += len + 1;
|
||||
}
|
||||
|
||||
switch(msg.cmd) {
|
||||
case REND_MSG_TYPE_REGISTER:
|
||||
DPRINTF(E_DBG,L_REND,"Registering %s.%s (%d)\n",msg.type,msg.name,msg.port);
|
||||
usPort=htons(msg.port);
|
||||
dns_ref=DNSServiceRegistrationCreate(msg.name,msg.type,"",usPort,msg.txt,rend_reply,nil);
|
||||
if(rend_addtorunloop(dns_ref)) {
|
||||
DPRINTF(E_WARN,L_REND,"Add to runloop failed\n");
|
||||
rend_send_response(-1);
|
||||
} else {
|
||||
rend_send_response(0); /* success */
|
||||
}
|
||||
break;
|
||||
case REND_MSG_TYPE_UNREGISTER:
|
||||
DPRINTF(E_WARN,L_REND,"Unsupported function: UNREGISTER\n");
|
||||
rend_send_response(-1); /* error */
|
||||
break;
|
||||
case REND_MSG_TYPE_STOP:
|
||||
DPRINTF(E_DBG,L_REND,"Stopping mDNS\n");
|
||||
rend_send_response(0);
|
||||
rend_stoprunloop();
|
||||
break;
|
||||
case REND_MSG_TYPE_STATUS:
|
||||
DPRINTF(E_DBG,L_REND,"Status inquiry -- returning 1\n");
|
||||
rend_send_response(1); /* success */
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_private_init
|
||||
*
|
||||
* start up the rendezvous services
|
||||
*/
|
||||
int rend_private_init(char *user) {
|
||||
CFRunLoopSourceContext context;
|
||||
|
||||
if(os_drop_privs(user)) /* shouldn't be running as root anyway */
|
||||
return -1;
|
||||
|
||||
/* need a sigint handler */
|
||||
DPRINTF(E_DBG,L_REND,"Starting rendezvous services\n");
|
||||
|
||||
memset((void*)&context,0,sizeof(context));
|
||||
context.perform = rend_callback;
|
||||
|
||||
rend_runloop = CFRunLoopGetCurrent();
|
||||
rend_rls = CFRunLoopSourceCreate(NULL,0,&context);
|
||||
CFRunLoopAddSource(CFRunLoopGetCurrent(),rend_rls,kCFRunLoopDefaultMode);
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Starting polling thread\n");
|
||||
|
||||
if(pthread_create(&rend_tid,NULL,rend_pipe_monitor,NULL)) {
|
||||
DPRINTF(E_FATAL,L_REND,"Could not start thread. Terminating\n");
|
||||
/* should kill parent, too */
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Starting runloop\n");
|
||||
|
||||
CFRunLoopRun();
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Exiting runloop\n");
|
||||
|
||||
CFRelease(rend_rls);
|
||||
pthread_cancel(rend_tid);
|
||||
close(rend_pipe_to[RD_SIDE]);
|
||||
close(rend_pipe_from[WR_SIDE]);
|
||||
return 0;
|
||||
}
|
||||
|
228
src/rend-unix.c
228
src/rend-unix.c
@ -1,228 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* General unix rendezvous routines
|
||||
*
|
||||
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <restart.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "daapd.h"
|
||||
#include "err.h"
|
||||
#include "rend-unix.h"
|
||||
|
||||
int rend_pipe_to[2];
|
||||
int rend_pipe_from[2];
|
||||
int rend_pid;
|
||||
|
||||
#define RD_SIDE 0
|
||||
#define WR_SIDE 1
|
||||
|
||||
/*
|
||||
* rend_init
|
||||
*
|
||||
* Fork and set up message passing system
|
||||
*/
|
||||
int rend_init(char *user) {
|
||||
int err;
|
||||
int fd;
|
||||
|
||||
if(pipe((int*)&rend_pipe_to) == -1)
|
||||
return -1;
|
||||
|
||||
if(pipe((int*)&rend_pipe_from) == -1) {
|
||||
err=errno;
|
||||
close(rend_pipe_to[RD_SIDE]);
|
||||
close(rend_pipe_to[WR_SIDE]);
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rend_pid=fork();
|
||||
if(rend_pid==-1) {
|
||||
err=errno;
|
||||
close(rend_pipe_to[RD_SIDE]);
|
||||
close(rend_pipe_to[WR_SIDE]);
|
||||
close(rend_pipe_from[RD_SIDE]);
|
||||
close(rend_pipe_from[WR_SIDE]);
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(rend_pid) { /* parent */
|
||||
close(rend_pipe_to[RD_SIDE]);
|
||||
close(rend_pipe_from[WR_SIDE]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* child */
|
||||
close(rend_pipe_to[WR_SIDE]);
|
||||
close(rend_pipe_from[RD_SIDE]);
|
||||
|
||||
/* Depending on the backend, this might not get done on the
|
||||
* rendezvous server-specific side
|
||||
*/
|
||||
signal(SIGTTOU, SIG_IGN);
|
||||
signal(SIGTTIN, SIG_IGN);
|
||||
signal(SIGTSTP, SIG_IGN);
|
||||
|
||||
#ifdef SETPGRP_VOID
|
||||
setpgrp();
|
||||
#else
|
||||
setpgrp(0,0);
|
||||
#endif
|
||||
|
||||
#ifdef TIOCNOTTY
|
||||
if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
|
||||
ioctl(fd, TIOCNOTTY, (char *) NULL);
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
|
||||
if((fd = open("/dev/null", O_RDWR, 0)) != -1) {
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
if(!config.foreground)
|
||||
dup2(fd, STDERR_FILENO);
|
||||
|
||||
if (fd > 2)
|
||||
close(fd);
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
|
||||
chdir("/");
|
||||
umask(0);
|
||||
|
||||
/* something bad here... should really signal the parent, rather
|
||||
* than just zombieizing
|
||||
*/
|
||||
rend_private_init(user); /* should only return when terminated */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_running
|
||||
*
|
||||
* See if the rendezvous daemon is runnig
|
||||
*/
|
||||
int rend_running(void) {
|
||||
REND_MESSAGE msg;
|
||||
int result;
|
||||
|
||||
DPRINTF(E_DBG,L_REND,"Status inquiry\n");
|
||||
memset((void*)&msg,0x00,sizeof(msg));
|
||||
msg.cmd=REND_MSG_TYPE_STATUS;
|
||||
result=rend_send_message(&msg);
|
||||
DPRINTF(E_DBG,L_REND,"Returning status %d\n",result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
*rend_stop
|
||||
*
|
||||
* Stop the rendezvous server
|
||||
*/
|
||||
int rend_stop(void) {
|
||||
REND_MESSAGE msg;
|
||||
|
||||
memset((void*)&msg,0x0,sizeof(msg));
|
||||
msg.cmd=REND_MSG_TYPE_STOP;
|
||||
return rend_send_message(&msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_register
|
||||
*
|
||||
* register a rendezvous name
|
||||
*/
|
||||
int rend_register(char *name, char *type, int port, char *iface, char *txt) {
|
||||
REND_MESSAGE msg;
|
||||
|
||||
if((strlen(name)+1 > MAX_NAME_LEN) || (strlen(type)+1 > MAX_NAME_LEN) ||
|
||||
(strlen(txt)+1 > MAX_TEXT_LEN)) {
|
||||
DPRINTF(E_FATAL,L_REND,"Registration failed: name or type too long\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset((void*)&msg,0x00,sizeof(msg)); /* shut valgrind up */
|
||||
msg.cmd=REND_MSG_TYPE_REGISTER;
|
||||
strncpy(msg.name,name,MAX_NAME_LEN-1);
|
||||
strncpy(msg.type,type,MAX_NAME_LEN-1);
|
||||
if(iface)
|
||||
strncpy(msg.iface,iface,MAX_IFACE_NAME_LEN-1);
|
||||
strncpy(msg.txt,txt,MAX_NAME_LEN-1);
|
||||
msg.port=port;
|
||||
|
||||
return rend_send_message(&msg);
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_unregister
|
||||
*
|
||||
* Stop advertising a rendezvous name
|
||||
*/
|
||||
int rend_unregister(char *name, char *type, int port) {
|
||||
return -1; /* not implemented */
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_send_message
|
||||
*
|
||||
* Send a rendezvous message
|
||||
*/
|
||||
int rend_send_message(REND_MESSAGE *pmsg) {
|
||||
int retval;
|
||||
|
||||
if(r_write(rend_pipe_to[WR_SIDE],pmsg,sizeof(REND_MESSAGE)) == -1)
|
||||
return -1;
|
||||
|
||||
if((retval=r_read(rend_pipe_from[RD_SIDE],&retval,sizeof(int)) == -1))
|
||||
return -1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_read_message
|
||||
*
|
||||
* read the message passed to the rend daemon
|
||||
*/
|
||||
int rend_read_message(REND_MESSAGE *pmsg) {
|
||||
return r_read(rend_pipe_to[RD_SIDE],pmsg,sizeof(REND_MESSAGE));
|
||||
}
|
||||
|
||||
/*
|
||||
* rend_send_response
|
||||
*
|
||||
* Let the rendezvous daemon return a result
|
||||
*/
|
||||
int rend_send_response(int value) {
|
||||
return r_write(rend_pipe_from[WR_SIDE],&value,sizeof(int));
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/*
|
||||
* $Id$
|
||||
* General unix rendezvous routines
|
||||
*
|
||||
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
|
||||
*
|
||||
* 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 _REND_UNIX_H_
|
||||
#define _REND_UNIX_H_
|
||||
|
||||
#define MAX_NAME_LEN 200
|
||||
/* Is there a posixly correct constant for this? */
|
||||
#define MAX_IFACE_NAME_LEN 20
|
||||
#define MAX_TEXT_LEN 255
|
||||
|
||||
typedef struct tag_rend_message {
|
||||
int cmd;
|
||||
int port;
|
||||
char name[MAX_NAME_LEN];
|
||||
char type[MAX_NAME_LEN];
|
||||
char iface[MAX_IFACE_NAME_LEN];
|
||||
char txt[MAX_TEXT_LEN];
|
||||
} REND_MESSAGE;
|
||||
|
||||
#define REND_MSG_TYPE_REGISTER 0
|
||||
#define REND_MSG_TYPE_UNREGISTER 1
|
||||
#define REND_MSG_TYPE_STOP 2
|
||||
#define REND_MSG_TYPE_STATUS 3
|
||||
|
||||
#define RD_SIDE 0
|
||||
#define WR_SIDE 1
|
||||
|
||||
extern int rend_pipe_to[2];
|
||||
extern int rend_pipe_from[2];
|
||||
|
||||
extern int rend_send_message(REND_MESSAGE *pmsg);
|
||||
extern int rend_send_response(int value);
|
||||
extern int rend_private_init(char *user);
|
||||
extern int rend_read_message(REND_MESSAGE *pmsg);
|
||||
|
||||
#endif /* _REND_UNIX_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user