diff --git a/src/Makefile.am b/src/Makefile.am
index cfbef9b5..a226504d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,7 @@ mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
webserver.h configfile.c configfile.h err.c err.h \
mp3-scanner.h mp3-scanner.c \
filescanner_ffmpeg.c \
+ mdns_avahi.c mdns_avahi.h \
db-generic.c db-generic.h ff-plugins.c ff-plugins.h \
rxml.c rxml.h redblack.c redblack.h \
scan-xml.c scan-wma.c scan-url.c \
diff --git a/src/configfile.c b/src/configfile.c
index 34d8eeb6..84fba08f 100644
--- a/src/configfile.c
+++ b/src/configfile.c
@@ -57,7 +57,6 @@
#include "os.h"
#include "xml-rpc.h"
#include "upnp.h"
-#include "rend.h"
/*
@@ -667,8 +666,6 @@ void config_emit_literal(WS_CONNINFO *pwsc, void *value, char *arg) {
* \param arg any args passwd with the meta command. Also unused
*/
void config_emit_service_status(WS_CONNINFO *pwsc, void *value, char *arg) {
- int mdns_running;
- char *html;
char buf[256];
int r_days, r_hours, r_mins, r_secs;
int scanning;
@@ -677,23 +674,6 @@ void config_emit_service_status(WS_CONNINFO *pwsc, void *value, char *arg) {
ws_writefd(pwsc,"
Service | ");
ws_writefd(pwsc,"Status | Control |
\n");
- ws_writefd(pwsc,"Rendezvous | ");
-
- if(config.use_mdns) {
- mdns_running=!rend_running();
-
- if(mdns_running) {
- html="Stop MDNS Server";
- } else {
- html="Start MDNS Server";
- }
-
- ws_writefd(pwsc,"%s | %s |
\n",mdns_running ? "Running":"Stopped",
- html);
- } else {
- ws_writefd(pwsc,"Not configured | | \n");
- }
-
ws_writefd(pwsc,"DAAP Server | %s | ",config.stop ? "Stopping":"Running");
if(config.stop) {
ws_writefd(pwsc,"Wait... |
\n");
diff --git a/src/main.c b/src/main.c
index a074e2e4..d24b253a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -87,9 +87,10 @@
#include "plugin.h"
#include "util.h"
#include "upnp.h"
-#include "rend.h"
#include "io.h"
+#include "mdns_avahi.h"
+
#ifdef HAVE_GETOPT_H
# include "getopt.h"
#endif
@@ -185,7 +186,6 @@ void usage(char *program) {
printf(" -a Set cwd to app dir before starting\n");
printf(" -d Debug level (0-9)\n");
printf(" -D Debug modules\n");
- printf(" -m Disable mDNS\n");
printf(" -c Use configfile specified\n");
printf(" -P Write the PID to specified file\n");
printf(" -f Run in foreground\n");
@@ -363,7 +363,7 @@ int main(int argc, char *argv[]) {
int convert_conf=0;
char *db_type,*db_parms,*web_root,*runas, *tmp;
char **mp3_dir_array;
- char *servername, *iface;
+ char *servername;
char *ffid = NULL;
int appdir = 0;
char *perr=NULL;
@@ -372,6 +372,7 @@ int main(int argc, char *argv[]) {
char *plugindir;
struct event *main_timer;
struct timeval tv;
+ int ret;
int err;
char *apppath;
@@ -379,7 +380,6 @@ int main(int argc, char *argv[]) {
int debuglevel=0;
int plugins_loaded = 0;
- config.use_mdns=1;
err_setlevel(2);
config.foreground=0;
@@ -414,10 +414,6 @@ int main(int argc, char *argv[]) {
configfile=optarg;
break;
- case 'm':
- config.use_mdns=0;
- break;
-
case 'P':
os_set_pidfile(optarg);
break;
@@ -560,17 +556,18 @@ int main(int argc, char *argv[]) {
os_deinit();
exit(EXIT_FAILURE);
}
-
- if(config.use_mdns) {
- DPRINTF(E_LOG,L_MAIN,"Starting rendezvous daemon\n");
- if(rend_init(runas)) {
- DPRINTF(E_FATAL,L_MAIN|L_REND,"Error in rend_init: %s\n",
- strerror(errno));
- }
- }
-
free(runas);
+ DPRINTF(E_LOG, L_MAIN, "mDNS init\n");
+ ret = mdns_init();
+ if (ret != 0)
+ {
+ DPRINTF(E_FATAL, L_MAIN | L_REND, "mDNS init failed\n");
+
+ os_deinit();
+ exit(EXIT_FAILURE);
+ }
+
#ifdef UPNP
upnp_init();
#endif
@@ -582,9 +579,8 @@ int main(int argc, char *argv[]) {
if(err) {
DPRINTF(E_LOG,L_MAIN|L_DB,"Error opening db: %s\n",perr);
- if(config.use_mdns) {
- rend_stop();
- }
+
+ mdns_deinit();
os_deinit();
exit(EXIT_FAILURE);
}
@@ -648,42 +644,39 @@ int main(int argc, char *argv[]) {
ws_registerhandler(config.server, "/",main_handler,main_auth,
0,1);
- if(config.use_mdns) { /* register services */
- servername = conf_get_servername();
+ /* Register mDNS services */
+ servername = conf_get_servername();
- memset(txtrecord,0,sizeof(txtrecord));
- txt_add(txtrecord,"txtvers=1");
- txt_add(txtrecord,"Database ID=%0X",util_djb_hash_str(servername));
- txt_add(txtrecord,"Machine ID=%0X",util_djb_hash_str(servername));
- txt_add(txtrecord,"Machine Name=%s",servername);
- txt_add(txtrecord,"mtd-version=" VERSION);
- txt_add(txtrecord,"iTSh Version=131073"); /* iTunes 6.0.4 */
- txt_add(txtrecord,"Version=196610"); /* iTunes 6.0.4 */
- tmp = conf_alloc_string("general","password",NULL);
- if(tmp && (strlen(tmp)==0)) tmp=NULL;
+ memset(txtrecord,0,sizeof(txtrecord));
+ txt_add(txtrecord,"txtvers=1");
+ txt_add(txtrecord,"Database ID=%0X",util_djb_hash_str(servername));
+ txt_add(txtrecord,"Machine ID=%0X",util_djb_hash_str(servername));
+ txt_add(txtrecord,"Machine Name=%s",servername);
+ txt_add(txtrecord,"mtd-version=" VERSION);
+ txt_add(txtrecord,"iTSh Version=131073"); /* iTunes 6.0.4 */
+ txt_add(txtrecord,"Version=196610"); /* iTunes 6.0.4 */
+ tmp = conf_alloc_string("general","password",NULL);
+ if(tmp && (strlen(tmp)==0)) tmp=NULL;
- txt_add(txtrecord,"Password=%s",tmp ? "true" : "false");
- if(tmp) free(tmp);
+ txt_add(txtrecord,"Password=%s",tmp ? "true" : "false");
+ if(tmp) free(tmp);
- srand((unsigned int)time(NULL));
+ srand((unsigned int)time(NULL));
- if(ffid) {
- txt_add(txtrecord,"ffid=%s",ffid);
- } else {
- txt_add(txtrecord,"ffid=%08x",rand());
- }
-
- DPRINTF(E_LOG,L_MAIN|L_REND,"Registering rendezvous names\n");
- iface = conf_alloc_string("general","interface","");
-
- rend_register(servername,"_http._tcp",ws_config.port,iface,txtrecord);
-
- plugin_rend_register(servername,ws_config.port,iface,txtrecord);
-
- free(servername);
- free(iface);
+ if(ffid) {
+ txt_add(txtrecord,"ffid=%s",ffid);
+ } else {
+ txt_add(txtrecord,"ffid=%08x",rand());
}
+ DPRINTF(E_LOG,L_MAIN|L_REND,"Registering rendezvous names\n");
+ /* Register main service */
+ mdns_register(servername, "_http._tcp", ws_config.port, txtrecord);
+ /* Register plugin services */
+ plugin_rend_register(servername, ws_config.port, txtrecord);
+
+ free(servername);
+
end_time=(int) time(NULL);
err=db_get_song_count(&perr,&song_count);
@@ -710,10 +703,8 @@ int main(int argc, char *argv[]) {
DPRINTF(E_LOG,L_MAIN,"Stopping gracefully\n");
- if(config.use_mdns) {
- DPRINTF(E_LOG,L_MAIN|L_REND,"Stopping rendezvous daemon\n");
- rend_stop();
- }
+ DPRINTF(E_LOG, L_MAIN | L_REND, "mDNS deinit\n");
+ mdns_deinit();
#ifdef UPNP
upnp_deinit();
diff --git a/src/plugin.c b/src/plugin.c
index 09f65482..0c477898 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -57,13 +57,14 @@
#include "io.h"
#include "os.h"
#include "plugin.h"
-#include "rend.h"
#include "smart-parser.h"
#include "xml-rpc.h"
#include "webserver.h"
#include "ff-plugins.h"
#include "io.h"
+#include "mdns_avahi.h"
+
typedef struct tag_pluginentry {
void *phandle;
PLUGIN_INFO *pinfo;
@@ -338,7 +339,7 @@ void plugin_url_handle(WS_CONNINFO *pwsc) {
* walk through the plugins and register whatever rendezvous
* names the clients want
*/
-int plugin_rend_register(char *name, int port, char *iface, char *txt) {
+int plugin_rend_register(char *name, int port, char *txt) {
PLUGIN_ENTRY *ppi;
PLUGIN_REND_INFO *pri;
char *supplied_txt;
@@ -355,7 +356,7 @@ int plugin_rend_register(char *name, int port, char *iface, char *txt) {
supplied_txt = txt;
DPRINTF(E_DBG,L_PLUG,"Registering %s\n",pri->type);
- rend_register(name,pri->type,port,iface,supplied_txt);
+ mdns_register(name, pri->type, port, supplied_txt);
pri++;
}
}
diff --git a/src/plugin.h b/src/plugin.h
index d4ac55c1..e49eb0c2 100644
--- a/src/plugin.h
+++ b/src/plugin.h
@@ -34,7 +34,7 @@ extern int plugin_deinit(void);
extern int plugin_url_candispatch(WS_CONNINFO *pwsc);
extern void plugin_url_handle(WS_CONNINFO *pwsc);
extern int plugin_auth_handle(WS_CONNINFO *pwsc, char *username, char *pw);
-extern int plugin_rend_register(char *name, int port, char *iface, char *txt);
+extern int plugin_rend_register(char *name, int port, char *txt);
extern void plugin_event_dispatch(int event_id, int intval, void *vp, int len);
extern void *plugin_enum(void *);
diff --git a/src/xml-rpc.c b/src/xml-rpc.c
index 4ade89c4..a93d3f0c 100644
--- a/src/xml-rpc.c
+++ b/src/xml-rpc.c
@@ -36,7 +36,6 @@
#include "mp3-scanner.h"
#include "os.h"
#include "plugin.h"
-#include "rend.h"
#include "webserver.h"
#include "xml-rpc.h"
@@ -520,18 +519,6 @@ void xml_get_stats(WS_CONNINFO *pwsc) {
xml_push(pxml,"service_status");
- xml_push(pxml,"service");
-
- xml_output(pxml,"name","Rendezvous");
-
- if(config.use_mdns) {
- xml_output(pxml,"status",rend_running() ? "Running" : "Stopped"); /* ??? */
- } else {
- xml_output(pxml,"status","Disabled");
- }
-
- xml_pop(pxml); /* service */
-
xml_push(pxml,"service");
xml_output(pxml,"name","DAAP Server");
xml_output(pxml,"status",config.stop ? "Stopping" : "Running");