Begin to support a settings file -- not working yet.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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=<pathname> Specify a pathname to a directory in which to write the PID file.], [
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Sample Configuration File for Shairport Sync
|
||||
|
||||
// General Settings
|
||||
general =
|
||||
{
|
||||
// name = "Music Player"; // default is "Shairport Sync on <hostname>"
|
||||
// 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"
|
||||
};
|
||||
|
||||
|
||||
|
||||
+29
@@ -36,6 +36,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <popt.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user