* Portions copyright (C) 2007 Mark Wooding
*
* This program is free software: you can redistribute it and/or modify
* Portions copyright (C) 2007 Mark Wooding
*
* This program is free software: you can redistribute it and/or modify
/** @brief Table of audio APIs
*
* Only set in server processes.
*/
const struct uaudio *const *config_uaudio_apis;
/** @brief Table of audio APIs
*
* Only set in server processes.
*/
const struct uaudio *const *config_uaudio_apis;
cl = ADDRESS(cs->config, struct collectionlist);
++cl->n;
cl->s = xrealloc(cl->s, cl->n * sizeof (struct collection));
cl = ADDRESS(cs->config, struct collectionlist);
++cl->n;
cl->s = xrealloc(cl->s, cl->n * sizeof (struct collection));
switch (*p) {
case 'l': case 'L': t = ENDIAN_LITTLE; p++; break;
case 'b': case 'B': t = ENDIAN_BIG; p++; break;
default: t = ENDIAN_NATIVE; break;
}
switch (*p) {
case 'l': case 'L': t = ENDIAN_LITTLE; p++; break;
case 'b': case 'B': t = ENDIAN_BIG; p++; break;
default: t = ENDIAN_NATIVE; break;
}
if(*p) {
disorder_error(0, "%s:%d: junk after channels", cs->path, cs->line);
return -1;
if(*p) {
disorder_error(0, "%s:%d: junk after channels", cs->path, cs->line);
return -1;
static int set_namepart(const struct config_state *cs,
const struct conf *whoami,
int nvec, char **vec) {
static int set_namepart(const struct config_state *cs,
const struct conf *whoami,
int nvec, char **vec) {
static int set_rights(const struct config_state *cs,
const struct conf *whoami,
static int set_rights(const struct config_state *cs,
const struct conf *whoami,
static void free_namepartlist(struct config *c,
const struct conf *whoami) {
struct namepartlist *npl = ADDRESS(c, struct namepartlist);
static void free_namepartlist(struct config *c,
const struct conf *whoami) {
struct namepartlist *npl = ADDRESS(c, struct namepartlist);
static void free_netaddress(struct config *c,
const struct conf *whoami) {
static void free_netaddress(struct config *c,
const struct conf *whoami) {
type_stringlist_accum = { set_stringlist_accum, free_stringlistlist },
type_string_accum = { set_string_accum, free_stringlist },
type_sample_format = { set_sample_format, free_none },
type_stringlist_accum = { set_stringlist_accum, free_stringlistlist },
type_string_accum = { set_string_accum, free_stringlist },
type_sample_format = { set_sample_format, free_none },
type_namepart = { set_namepart, free_namepartlist },
type_transform = { set_transform, free_transformlist },
type_namepart = { set_namepart, free_namepartlist },
type_transform = { set_transform, free_transformlist },
type_netaddress = { set_netaddress, free_netaddress },
type_rights = { set_rights, free_string };
type_netaddress = { set_netaddress, free_netaddress },
type_rights = { set_rights, free_string };
if(nvec < 1) {
disorder_error(0, "%s:%d: missing argument", cs->path, cs->line);
if(nvec < 1) {
disorder_error(0, "%s:%d: missing argument", cs->path, cs->line);
return -1;
}
if(xstrtol(&n, vec[0], 0, 0)) {
return -1;
}
if(xstrtol(&n, vec[0], 0, 0)) {
- disorder_error(0, "%s:%d: %s", cs->path, cs->line, strerror(errno));
+ disorder_error(0, "%s:%d: %s", cs->path, cs->line,
+ format_error(ec_errno, errno, errbuf, sizeof errbuf));
if(nvec < 1) {
disorder_error(0, "%s:%d: missing argument", cs->path, cs->line);
if(nvec < 1) {
disorder_error(0, "%s:%d: missing argument", cs->path, cs->line);
return -1;
}
if(xstrtol(&n, vec[0], 0, 0)) {
return -1;
}
if(xstrtol(&n, vec[0], 0, 0)) {
- disorder_error(0, "%s:%d: %s", cs->path, cs->line, strerror(errno));
+ disorder_error(0, "%s:%d: %s", cs->path, cs->line,
+ format_error(ec_errno, errno, errbuf, sizeof errbuf));
/** @brief Validate a system username
* @param cs Configuration state
* @param nvec Length of (proposed) new value
/** @brief Validate a system username
* @param cs Configuration state
* @param nvec Length of (proposed) new value
/** @brief Validate a playback backend name
* @param cs Configuration state
* @param nvec Length of (proposed) new value
/** @brief Validate a playback backend name
* @param cs Configuration state
* @param nvec Length of (proposed) new value
/** @brief All configuration items */
static const struct conf conf[] = {
{ C(alias), &type_string, validate_alias },
/** @brief All configuration items */
static const struct conf conf[] = {
{ C(alias), &type_string, validate_alias },
{ C(api), &type_string, validate_backend },
{ C(api), &type_string, validate_backend },
{ C(authorization_algorithm), &type_string, validate_algo },
{ C(broadcast), &type_netaddress, validate_destaddr },
{ C(broadcast_from), &type_netaddress, validate_any },
{ C(authorization_algorithm), &type_string, validate_algo },
{ C(broadcast), &type_netaddress, validate_destaddr },
{ C(broadcast_from), &type_netaddress, validate_any },
{ C(default_rights), &type_rights, validate_any },
{ C(device), &type_string, validate_any },
{ C(history), &type_integer, validate_positive },
{ C(default_rights), &type_rights, validate_any },
{ C(device), &type_string, validate_any },
{ C(history), &type_integer, validate_positive },
{ C(home), &type_string, validate_isabspath },
{ C(home), &type_string, validate_isabspath },
{ C(listen), &type_netaddress, validate_any },
{ C(mail_sender), &type_string, validate_any },
{ C(mixer), &type_string, validate_any },
{ C(mount_rescan), &type_boolean, validate_any },
{ C(multicast_loop), &type_boolean, validate_any },
{ C(multicast_ttl), &type_integer, validate_non_negative },
{ C(listen), &type_netaddress, validate_any },
{ C(mail_sender), &type_string, validate_any },
{ C(mixer), &type_string, validate_any },
{ C(mount_rescan), &type_boolean, validate_any },
{ C(multicast_loop), &type_boolean, validate_any },
{ C(multicast_ttl), &type_integer, validate_non_negative },
{ C(namepart), &type_namepart, validate_any },
{ 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 },
{ C(new_bias), &type_integer, validate_positive },
{ C(new_bias_age), &type_integer, validate_positive },
{ C(new_max), &type_integer, validate_positive },
{ C(remote_userman), &type_boolean, validate_any },
{ C(replay_min), &type_integer, validate_non_negative },
{ C(rtp_delay_threshold), &type_integer, validate_positive },
{ C(remote_userman), &type_boolean, validate_any },
{ C(replay_min), &type_integer, validate_non_negative },
{ C(rtp_delay_threshold), &type_integer, validate_positive },
{ C(rtp_verbose), &type_boolean, validate_any },
{ C(sample_format), &type_sample_format, validate_sample_format },
{ C(scratch), &type_string_accum, validate_isreg },
{ C(rtp_verbose), &type_boolean, 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(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 },
{ C(sox_generation), &type_integer, validate_non_negative },
{ C(short_display), &type_integer, validate_positive },
{ C(signal), &type_signal, validate_any },
{ C(smtp_server), &type_string, validate_any },
{ C(sox_generation), &type_integer, validate_non_negative },
{ C2(speaker_backend, api), &type_string, validate_backend },
{ C2(speaker_backend, api), &type_string, validate_backend },
{ C(speaker_command), &type_string, validate_any },
{ C(stopword), &type_string_accum, validate_any },
{ C(templates), &type_string_accum, validate_isdir },
{ C(tracklength), &type_stringlist_accum, validate_tracklength },
{ C(speaker_command), &type_string, validate_any },
{ C(stopword), &type_string_accum, validate_any },
{ C(templates), &type_string_accum, validate_isdir },
{ C(tracklength), &type_stringlist_accum, validate_tracklength },
{ C(transform), &type_transform, validate_any },
{ C(transform), &type_transform, validate_any },
{ C(url), &type_string, validate_url },
{ C(url), &type_string, validate_url },
{ C(user), &type_string, validate_isauser },
{ C(user), &type_string, validate_isauser },
{ C(username), &type_string, validate_any },
};
{ C(username), &type_string, validate_any },
};
+#endif
+#if _WIN32
+ {
+ char buffer[128];
+ DWORD bufsize = sizeof buffer;
+ if(!GetUserNameA(buffer, &bufsize))
+ disorder_fatal(0, "cannot determine our username");
+ c->username = xstrdup(buffer);
+ }
+#else
if(!(pw = getpwuid(getuid())))
disorder_fatal(0, "cannot determine our username");
logname = pw->pw_name;
c->username = xstrdup(logname);
if(!(pw = getpwuid(getuid())))
disorder_fatal(0, "cannot determine our username");
logname = pw->pw_name;
c->username = xstrdup(logname);
if(sendmail_binary[0] && strcmp(sendmail_binary, "none"))
c->sendmail = xstrdup(sendmail_binary);
if(sendmail_binary[0] && strcmp(sendmail_binary, "none"))
c->sendmail = xstrdup(sendmail_binary);
byte_xasprintf(&s, "%s/%s", c->home, name);
return s;
}
byte_xasprintf(&s, "%s/%s", c->home, name);
return s;
}
static const char *namepart[][4] = {
{ "title", "/([0-9]+ *[-:]? *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display" },
{ "title", "/([^/]+)\\.[a-zA-Z0-9]+$", "$1", "sort" },
static const char *namepart[][4] = {
{ "title", "/([0-9]+ *[-:]? *)?([^/]+)\\.[a-zA-Z0-9]+$", "$2", "display" },
{ "title", "/([^/]+)\\.[a-zA-Z0-9]+$", "$1", "sort" },
{ "dir", "[[:punct:]]", "", "sort", "g", }
};
#define NTRANSFORM (int)(sizeof transform / sizeof *transform)
{ "dir", "[[:punct:]]", "", "sort", "g", }
};
#define NTRANSFORM (int)(sizeof transform / sizeof *transform)
for(n = 0; n < NTRANSFORM; ++n)
set_transform(&cs, whoami, 5, (char **)transform[n]);
}
for(n = 0; n < NTRANSFORM; ++n)
set_transform(&cs, whoami, 5, (char **)transform[n]);
}
else if(config_uaudio_apis)
c->api = xstrdup(uaudio_default(config_uaudio_apis,
UAUDIO_API_SERVER)->name);
else if(config_uaudio_apis)
c->api = xstrdup(uaudio_default(config_uaudio_apis,
UAUDIO_API_SERVER)->name);
- /* standalone Disobedience installs might not have a global config file */
- if(access(configfile, F_OK) == 0)
- if(config_include(c, configfile))
- return -1;
+ /* standalone client installs might not have a global config file */
+ if(configfile)
+ if(access(configfile, F_OK) == 0)
+ if(config_include(c, configfile))
+ return -1;
/* if we can read the private config file, do */
if((privconf = config_private())
&& access(privconf, R_OK) == 0
/* if we can read the private config file, do */
if((privconf = config_private())
&& access(privconf, R_OK) == 0
if(!(pw = getpwuid(getuid())))
disorder_fatal(0, "cannot determine our username");
if((privconf = config_usersysconf(pw))
if(!(pw = getpwuid(getuid())))
disorder_fatal(0, "cannot determine our username");
if((privconf = config_usersysconf(pw))
/* if we have a password file, read it */
if((privconf = config_userconf(0, pw))
&& access(privconf, F_OK) == 0
/* if we have a password file, read it */
if((privconf = config_userconf(0, pw))
&& access(privconf, F_OK) == 0
if(strcmp(c->home, oldconfig->home)) {
disorder_error(0, "'home' cannot be changed without a restart");
failed = 1;
}
if(strcmp(c->home, oldconfig->home)) {
disorder_error(0, "'home' cannot be changed without a restart");
failed = 1;
}
if(strcmp(c->alias, oldconfig->alias)) {
disorder_error(0, "'alias' cannot be changed without a restart");
failed = 1;
if(strcmp(c->alias, oldconfig->alias)) {
disorder_error(0, "'alias' cannot be changed without a restart");
failed = 1;
disorder_error(0, "'nice_server' cannot be changed without a restart");
/* ...but we accept the new config anyway */
}
disorder_error(0, "'nice_server' cannot be changed without a restart");
/* ...but we accept the new config anyway */
}
if(namepartlist_compare(&c->namepart, &oldconfig->namepart)) {
disorder_error(0, "'namepart' settings cannot be changed without a restart");
failed = 1;
}
if(namepartlist_compare(&c->namepart, &oldconfig->namepart)) {
disorder_error(0, "'namepart' settings cannot be changed without a restart");
failed = 1;
}
if(stringlist_compare(&c->stopword, &oldconfig->stopword)) {
disorder_error(0, "'stopword' settings cannot be changed without a restart");
failed = 1;
if(stringlist_compare(&c->stopword, &oldconfig->stopword)) {
disorder_error(0, "'stopword' settings cannot be changed without a restart");
failed = 1;
}
/** @brief Return the path to user's personal configuration file */
char *config_userconf(const char *home, const struct passwd *pw) {
char *s;
}
/** @brief Return the path to user's personal configuration file */
char *config_userconf(const char *home, const struct passwd *pw) {
char *s;
+#if _WIN32
+ wchar_t *wpath = 0;
+ char *appdata;
+ if(SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wpath) != S_OK)
+ disorder_fatal(0, "error calling SHGetKnownFolderPath");
+ appdata = win_wtomb(wpath);
+ CoTaskMemFree(wpath);
+ byte_xasprintf(&s, "%s\\DisOrder\\passwd", appdata);
+#else
if(!home && !pw && !(pw = getpwuid(getuid())))
disorder_fatal(0, "cannot determine our username");
byte_xasprintf(&s, "%s/.disorder/passwd", home ? home : pw->pw_dir);
if(!home && !pw && !(pw = getpwuid(getuid())))
disorder_fatal(0, "cannot determine our username");
byte_xasprintf(&s, "%s/.disorder/passwd", home ? home : pw->pw_dir);
/** @brief Return the path to user-specific system configuration */
char *config_usersysconf(const struct passwd *pw) {
char *s;
/** @brief Return the path to user-specific system configuration */
char *config_usersysconf(const struct passwd *pw) {
char *s;
char *config_get_file(const char *name) {
return config_get_file2(config, name);
}
char *config_get_file(const char *name) {
return config_get_file2(config, name);
}
/** @brief Order two namepart definitions
* @param a First namepart definition
* @param b Second namepart definition
/** @brief Order two namepart definitions
* @param a First namepart definition
* @param b Second namepart definition
/** @brief Verify configuration table.
* @return The number of problems found
*/
int config_verify(void) {
int fails = 0;
/** @brief Verify configuration table.
* @return The number of problems found
*/
int config_verify(void) {
int fails = 0;
if(strcmp(conf[n-1].name, conf[n].name) >= 0) {
fprintf(stderr, "%s >= %s\n", conf[n-1].name, conf[n].name);
++fails;
if(strcmp(conf[n-1].name, conf[n].name) >= 0) {
fprintf(stderr, "%s >= %s\n", conf[n-1].name, conf[n].name);
++fails;