/*
* This file is part of DisOrder.
- * Copyright (C) 2004, 2005, 2006, 2007 Richard Kettlewell
+ * Copyright (C) 2004-2008 Richard Kettlewell
* Portions copyright (C) 2007 Mark Wooding
*
* This program is free software; you can redistribute it and/or modify
* @brief Configuration file support
*/
-#include <config.h>
-#include "types.h"
+#include "common.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "regsub.h"
#include "signame.h"
#include "authhash.h"
+#include "vector.h"
/** @brief Path to config file
*
};
for(n = 0; n < nvec; ++n) {
- if((i = TABLE_FIND(restrictions, struct restriction, name, vec[n])) < 0) {
+ if((i = TABLE_FIND(restrictions, name, vec[n])) < 0) {
error(0, "%s:%d: invalid restriction '%s'",
cs->path, cs->line, vec[n]);
return -1;
{ C(multicast_loop), &type_boolean, validate_any },
{ C(multicast_ttl), &type_integer, validate_non_negative },
{ C(namepart), &type_namepart, validate_any },
+ { C(new_bias), &type_integer, validate_positive },
+ { C(new_bias_age), &type_integer, validate_positive },
+ { C(new_max), &type_integer, validate_positive },
{ C2(nice, nice_rescan), &type_integer, validate_non_negative },
{ C(nice_rescan), &type_integer, validate_non_negative },
{ C(nice_server), &type_integer, validate_any },
{ C(plugins), &type_string_accum, validate_isdir },
{ C(prefsync), &type_integer, validate_positive },
{ C(queue_pad), &type_integer, validate_positive },
+ { C(replay_min), &type_integer, validate_non_negative },
{ C(refresh), &type_integer, validate_positive },
+ { C(reminder_interval), &type_integer, validate_positive },
+ { C(remote_userman), &type_boolean, validate_any },
{ C2(restrict, restrictions), &type_restrict, validate_any },
{ C(sample_format), &type_sample_format, validate_sample_format },
{ C(scratch), &type_string_accum, validate_isreg },
+ { C(sendmail), &type_string, validate_isabspath },
{ C(short_display), &type_integer, validate_positive },
{ C(signal), &type_signal, validate_any },
{ C(smtp_server), &type_string, validate_any },
static const struct conf *find(const char *key) {
int n;
- if((n = TABLE_FIND(conf, struct conf, name, key)) < 0)
+ if((n = TABLE_FIND(conf, name, key)) < 0)
return 0;
return &conf[n];
}
|| which->type->set(cs, which, nvec - 1, vec + 1));
}
+static int config_set_args(const struct config_state *cs,
+ const char *which, ...) {
+ va_list ap;
+ struct vector v[1];
+ char *s;
+
+ vector_init(v);
+ vector_append(v, (char *)which);
+ va_start(ap, which);
+ while((s = va_arg(ap, char *)))
+ vector_append(v, s);
+ va_end(ap);
+ vector_terminate(v);
+ return config_set(cs, v->nvec, v->vec);
+}
+
/** @brief Error callback used by config_include() */
static void config_error(const char *msg, void *u) {
const struct config_state *cs = u;
};
#define NDEFAULT_STOPWORDS (sizeof default_stopwords / sizeof *default_stopwords)
+static const char *const default_players[] = {
+ "*.ogg",
+ "*.flac",
+ "*.mp3",
+ "*.wav",
+};
+#define NDEFAULT_PLAYERS (sizeof default_players / sizeof *default_players)
+
/** @brief Make a new default configuration */
static struct config *config_default(void) {
struct config *c = xmalloc(sizeof *c);
const char *logname;
struct passwd *pw;
struct config_state cs;
+ size_t n;
cs.path = "<internal>";
cs.line = 0;
c->sample_format.channels = 2;
c->sample_format.endian = ENDIAN_NATIVE;
c->queue_pad = 10;
+ c->replay_min = 8 * 3600;
c->api = -1;
c->multicast_ttl = 1;
c->multicast_loop = 1;
c->dbversion = 2;
c->cookie_login_lifetime = 86400;
c->cookie_key_lifetime = 86400 * 7;
+ if(sendmail_binary[0] && strcmp(sendmail_binary, "none"))
+ c->sendmail = xstrdup(sendmail_binary);
c->smtp_server = xstrdup("127.0.0.1");
+ c->new_max = 100;
+ c->reminder_interval = 600; /* 10m */
+ c->new_bias_age = 7 * 86400; /* 1 week */
+ c->new_bias = 9000000; /* 100 times the base weight */
+ /* Default stopwords */
if(config_set(&cs, (int)NDEFAULT_STOPWORDS, (char **)default_stopwords))
exit(1);
+ /* Default player configuration */
+ for(n = 0; n < NDEFAULT_PLAYERS; ++n) {
+ if(config_set_args(&cs, "player",
+ default_players[n], "execraw", "disorder-decode", (char *)0))
+ exit(1);
+ if(config_set_args(&cs, "tracklength",
+ default_players[n], "disorder-tracklength", (char *)0))
+ exit(1);
+ }
return c;
}
-static char *get_file(struct config *c, const char *name) {
+char *config_get_file2(struct config *c, const char *name) {
char *s;
byte_xasprintf(&s, "%s/%s", c->home, name);
int n;
static const char *namepart[][4] = {
- { "title", "/([0-9]+ *[-:] *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display" },
+ { "title", "/([0-9]+ *[-:]? *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display" },
{ "title", "/([^/]+)\\.[a-zA-Z0-9]+$", "$1", "sort" },
{ "album", "/([^/]+)/[^/]+$", "$1", "*" },
{ "artist", "/([^/]+)/[^/]+/[^/]+$", "$1", "*" },
#define NNAMEPART (int)(sizeof namepart / sizeof *namepart)
static const char *transform[][5] = {
- { "track", "^.*/([0-9]+ *[-:] *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display", "" },
+ { "track", "^.*/([0-9]+ *[-:]? *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display", "" },
{ "track", "^.*/([^/]+)\\.[a-zA-Z0-9]+$", "$1", "sort", "" },
{ "dir", "^.*/([^/]+)$", "$1", "*", "" },
{ "dir", "^(the) ([^/]*)", "$2, $1", "sort", "i", },
c->api = BACKEND_COMMAND;
else if(c->broadcast.n)
c->api = BACKEND_NETWORK;
- else {
-#if HAVE_ALSA_ASOUNDLIB_H
- c->api = BACKEND_ALSA;
-#elif HAVE_SYS_SOUNDCARD_H
- c->api = BACKEND_OSS;
-#elif HAVE_COREAUDIO_AUDIOHARDWARE_H
- c->api = BACKEND_COREAUDIO;
-#else
- c->api = BACKEND_COMMAND;
-#endif
- }
+ else
+ c->api = DEFAULT_BACKEND;
}
if(server) {
if(c->api == BACKEND_COMMAND && !c->speaker_command)
r |= RIGHT_REMOVE_ANY;
c->default_rights = rights_string(r);
}
- if(!c->mixer)
- c->mixer = xstrdup(mixer_default_device(c->api));
- if(!c->channel)
- c->channel = xstrdup(mixer_default_channel(c->api));
}
/** @brief (Re-)read the config file
return -1;
xfree(privconf);
/* if we have a password file, read it */
- if((privconf = config_userconf(getenv("HOME"), pw))
+ if((privconf = config_userconf(0, pw))
&& access(privconf, F_OK) == 0
&& config_include(c, privconf))
return -1;
config_postdefaults(c, server);
/* everything is good so we shall use the new config */
config_free(config);
- /* final error checking */
- if(c->mixer && !mixer_valid_device(c->api, c->mixer)) {
- error(0, "invalid mixer device: %s", c->mixer);
- return -1;
- }
- if(c->channel && !mixer_valid_channel(c->api, c->channel)) {
- error(0, "invalid mixer channel: %s", c->channel);
- return -1;
- }
/* warn about obsolete directives */
if(c->restrictions)
error(0, "'restrict' will be removed in a future version");
}
char *config_get_file(const char *name) {
- return get_file(config, name);
+ return config_get_file2(config, name);
}
/*