From 2195db08000139b0a5fa48d6bdcd061a09bc78c9 Mon Sep 17 00:00:00 2001 From: chme Date: Sat, 31 Oct 2015 09:01:38 +0100 Subject: [PATCH] [mpd] Announce mpd support with avahi/zeroconf --- src/main.c | 19 +++++++++++++++++-- src/mdns_avahi.c | 11 +++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index f1dce5c4..e64b5c79 100644 --- a/src/main.c +++ b/src/main.c @@ -221,14 +221,16 @@ daemonize(int background, char *pidfile) } static int -register_services(char *ffid, int no_rsp, int no_daap) +register_services(char *ffid, int no_rsp, int no_daap, int mdns_no_mpd) { cfg_t *lib; + cfg_t *mpd; char *libname; char *password; char *txtrecord[10]; char records[9][128]; int port; + int mpd_port; uint32_t hash; int i; int ret; @@ -318,6 +320,16 @@ register_services(char *ffid, int no_rsp, int no_daap) if (ret < 0) return ret; + /* Register MPD serivce */ + mpd = cfg_getsec(cfg, "mpd"); + mpd_port = cfg_getint(mpd, "port"); + if (!mdns_no_mpd && mpd_port > 0) + { + ret = mdns_register(libname, "_mpd._tcp", mpd_port, NULL); + if (ret < 0) + return ret; + } + return 0; } @@ -446,6 +458,7 @@ main(int argc, char **argv) int background; int mdns_no_rsp; int mdns_no_daap; + int mdns_no_mpd; int loglevel; char *logdomains; char *logfile; @@ -484,6 +497,7 @@ main(int argc, char **argv) ffid = NULL; mdns_no_rsp = 0; mdns_no_daap = 0; + mdns_no_mpd = 1; // only announce if mpd protocol support is activated while ((option = getopt_long(argc, argv, "D:d:c:P:fb:v", option_map, NULL)) != -1) { @@ -747,6 +761,7 @@ main(int argc, char **argv) ret = EXIT_FAILURE; goto mpd_fail; } + mdns_no_mpd = 0; #endif /* Start Remote pairing service */ @@ -760,7 +775,7 @@ main(int argc, char **argv) } /* Register mDNS services */ - ret = register_services(ffid, mdns_no_rsp, mdns_no_daap); + ret = register_services(ffid, mdns_no_rsp, mdns_no_daap, mdns_no_mpd); if (ret < 0) { ret = EXIT_FAILURE; diff --git a/src/mdns_avahi.c b/src/mdns_avahi.c index aa3643c2..9939c4c0 100644 --- a/src/mdns_avahi.c +++ b/src/mdns_avahi.c @@ -4,7 +4,7 @@ * Copyright (C) 2009-2011 Julien BLACHE * * Pieces coming from mt-daapd: - * Copyright (C) 2005 Sebastian Dröge + * Copyright (C) 2005 Sebastian Dröge * * 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 @@ -1032,11 +1032,14 @@ mdns_register(char *name, char *type, int port, char **txt) ge->port = port; txt_sl = NULL; - for (i = 0; txt[i]; i++) + if (txt) { - txt_sl = avahi_string_list_add(txt_sl, txt[i]); + for (i = 0; txt[i]; i++) + { + txt_sl = avahi_string_list_add(txt_sl, txt[i]); - DPRINTF(E_DBG, L_MDNS, "Added key %s\n", txt[i]); + DPRINTF(E_DBG, L_MDNS, "Added key %s\n", txt[i]); + } } ge->txt = txt_sl;