/** @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;
-static int set_stringlist(const struct config_state *cs,
- const struct conf *whoami,
- int nvec, char **vec) {
- int n;
- struct stringlist *sl;
-
- sl = ADDRESS(cs->config, struct stringlist);
- sl->n = 0;
- for(n = 0; n < nvec; ++n) {
- sl->n++;
- sl->s = xrealloc(sl->s, (sl->n * sizeof (char *)));
- sl->s[sl->n - 1] = xstrdup(vec[n]);
- }
- return 0;
-}
-
static int set_integer(const struct config_state *cs,
const struct conf *whoami,
int nvec, char **vec) {
static int set_integer(const struct config_state *cs,
const struct conf *whoami,
int nvec, char **vec) {
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) {
struct namepartlist *npl = ADDRESS(cs->config, struct namepartlist);
unsigned reflags;
static int set_namepart(const struct config_state *cs,
const struct conf *whoami,
int nvec, char **vec) {
struct namepartlist *npl = ADDRESS(cs->config, struct namepartlist);
unsigned reflags;
- if(!(re = pcre_compile(vec[1],
- PCRE_UTF8
- |regsub_compile_options(reflags),
- &errstr, &erroffset, 0))) {
- disorder_error(0, "%s:%d: compiling regexp /%s/: %s (offset %d)",
+ if(!(re = regexp_compile(vec[1], regsub_compile_options(reflags),
+ errstr, sizeof(errstr), &erroffset)))
+ {
+ disorder_error(0, "%s:%d: compiling regexp /%s/: %s (offset %zu)",
cs->path, cs->line, vec[1], errstr, erroffset);
return -1;
}
cs->path, cs->line, vec[1], errstr, erroffset);
return -1;
}
const struct conf *whoami,
int nvec, char **vec) {
struct transformlist *tl = ADDRESS(cs->config, struct transformlist);
const struct conf *whoami,
int nvec, char **vec) {
struct transformlist *tl = ADDRESS(cs->config, struct transformlist);
- if(!(re = pcre_compile(vec[1],
- PCRE_UTF8
- |regsub_compile_options(reflags),
- &errstr, &erroffset, 0))) {
- disorder_error(0, "%s:%d: compiling regexp /%s/: %s (offset %d)",
+ if(!(re = regexp_compile(vec[1], regsub_compile_options(reflags),
+ errstr, sizeof(errstr), &erroffset)))
+ {
+ disorder_error(0, "%s:%d: compiling regexp /%s/: %s (offset %zu)",
cs->path, cs->line, vec[1], errstr, erroffset);
return -1;
}
cs->path, cs->line, vec[1], errstr, erroffset);
return -1;
}
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_collections = { set_collections, free_collectionlist },
type_boolean = { set_boolean, free_none },
type_string = { set_string, free_string },
type_collections = { set_collections, free_collectionlist },
type_boolean = { set_boolean, free_none },
type_string = { set_string, free_string },
type_integer = { set_integer, free_none },
type_stringlist_accum = { set_stringlist_accum, free_stringlistlist },
type_string_accum = { set_string_accum, free_stringlist },
type_integer = { set_integer, free_none },
type_stringlist_accum = { set_stringlist_accum, free_stringlistlist },
type_string_accum = { set_string_accum, free_stringlist },
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(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