From 4ec9fd5b9be1862a02a6a56c620c403a6188c03e Mon Sep 17 00:00:00 2001 From: Mike Brady Date: Mon, 6 Apr 2015 13:52:13 +0100 Subject: [PATCH] Begin to support a settings file -- not working yet. --- common.h | 1 + configure.ac | 4 +++ scripts/shairport-sync.conf | 52 +++++++++++++++++++++++++++++++++++++ shairport.c | 29 +++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 scripts/shairport-sync.conf diff --git a/common.h b/common.h index 9a35d187..5707da31 100644 --- a/common.h +++ b/common.h @@ -39,6 +39,7 @@ enum stuffing_type { typedef struct { + char *configuration_file; // if used, all other command-line arguments are ignored char *password; char *apname; #ifdef CONFIG_METADATA diff --git a/configure.ac b/configure.ac index 04722753..1b1ffd21 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,10 @@ PKG_CHECK_MODULES( [POPT], [popt], [LIBS="${POPT_LIBS} ${LIBS}" AC_DEFINE([HAVE_LIBPOPT],[1],[Define to 1 if you have popt])]) +PKG_CHECK_MODULES( + [LIBCONFIG], [libconfig], + [LIBS="${LIBCONFIG_LIBS} ${LIBS}" + AC_DEFINE([HAVE_LIBCONFIG],[1],[Define to 1 if you have libconfig])]) # Look for piddir flag AC_ARG_WITH(piddir, [ --with-piddir= Specify a pathname to a directory in which to write the PID file.], [ diff --git a/scripts/shairport-sync.conf b/scripts/shairport-sync.conf new file mode 100644 index 00000000..101d44ef --- /dev/null +++ b/scripts/shairport-sync.conf @@ -0,0 +1,52 @@ +// Sample Configuration File for Shairport Sync + +// General Settings +general = +{ +// name = "Music Player"; // default is "Shairport Sync on " +// daemonize = no; +// mdns_backend = avahi; // not used, not tested +// output_backend = alsa; // setting is not used, alsa is default +// port = 5000; +// password = "secret"; // default is no password needed +// interpolation = basic; // aka "stuffing". Default is basic, alternative is soxr +// statistics = no; // print statistics in the log +// tolerance = 88; // allow this number of frames of drift before correcting it +// resync_threshold = 2205; a synchronisation error greater than this will cause resynchronisation +// log_verbosity = 0; // "0" means no verbosity, "3" is highest. +}; + +latency = +{ +// default = 88200; +// itunes = 99400; +// airplay = 88200; +// forkedDaapd = 99400; +}; + +metadata = +{ +// metadata_feed_enabled = no; +// include_cover_art = no; +// metadata_pipe = "/tmp/shairport-sync-coverart"; +}; + +sessioncontrol = +{ +// run_before_play_begins = "/path/to/application"; +// run_after_play_ends = "/path/to/application"; +// wait_for_completion = no; +// allow_session_interruption = no; +// session_timeout = 120; +}; + +alsa = +{ +// device_type = software; +// device = "default"; +// mixer = "default"; // default is that the device is also the mixer +// mixer_control_name = "PCM" +}; + + + diff --git a/shairport.c b/shairport.c index 565ced69..ff8f690c 100644 --- a/shairport.c +++ b/shairport.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "config.h" @@ -199,6 +200,7 @@ int parse_options(int argc, char **argv) { char *stuffing = NULL; /* used for picking up the stuffing option */ poptContext optCon; /* context for parsing command-line options */ struct poptOption optionsTable[] = { + { "config-file", 0, POPT_ARG_STRING, &config.configuration_file, 0, NULL } , { "statistics", 0, POPT_ARG_NONE, &config.statistics_requested, 0, NULL}, { "version", 'V', POPT_ARG_NONE, NULL, 0, NULL}, { "verbose", 'v', POPT_ARG_NONE, NULL, 'v', NULL }, @@ -268,6 +270,32 @@ int parse_options(int argc, char **argv) { if (c < -1) { die("%s: %s",poptBadOption(optCon, POPT_BADOPTION_NOALIAS),poptStrerror(c)); } + + // now, die if the -c option was chosen and there were more than two arguments, which should be the app name and the single -c option. + + if (config.configuration_file!=NULL) { + if ((argc!=2) && !((argc==3) && (debuglev!=0))) + die("If you choose the -c or --config-file option, no other command-line arguments are permitted -- %d arguments seen",argc); + // parse the arguments + config_t cfg; + config_setting_t *setting; + const char *str; + + config_init(&cfg); + + /* Read the file. If there is an error, report it and exit. */ + if(config_read_file(&cfg, config.configuration_file)) { + /* Get the store name. */ + if(config_lookup_string(&cfg, "name", &str)) + debug(1,"Store name: %s", str); + else + debug(1, "No 'name' setting in configuration file."); + } else { + debug(1,"Couldn't open configuration file."); + } + + config_destroy(&cfg); + } /* Print out options */ debug(2,"statistics_requester status is %d.",config.statistics_requested); @@ -292,6 +320,7 @@ int parse_options(int argc, char **argv) { debug(2,"metadata directory is \"%s\".",config.meta_dir); debug(2,"get-coverart is %d.",config.get_coverart); #endif + return optind+1; }