Extended parameterization. Marked with @ all fields with special use

This commit is contained in:
Abramo Bagnara 2001-06-15 14:00:19 +00:00
parent cf325c68e3
commit 54daf2f16d
16 changed files with 315 additions and 349 deletions

View file

@ -975,7 +975,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
srvname = argv[optind]; srvname = argv[optind];
err = snd_config_search_alias(snd_config, "server", srvname, &conf); err = snd_config_search_definition(snd_config, "server", srvname, &conf);
if (err < 0) { if (err < 0) {
ERROR("Missing definition for server %s", srvname); ERROR("Missing definition for server %s", srvname);
return 1; return 1;

View file

@ -34,9 +34,9 @@ int snd_config_search(snd_config_t *config, const char *key,
snd_config_t **result); snd_config_t **result);
int snd_config_searchv(snd_config_t *config, int snd_config_searchv(snd_config_t *config,
snd_config_t **result, ...); snd_config_t **result, ...);
int snd_config_search_alias(snd_config_t *config, int snd_config_search_definition(snd_config_t *config,
const char *base, const char *key, const char *base, const char *key,
snd_config_t **result); snd_config_t **result);
int snd_config_expand(snd_config_t *config, const char *args, int snd_config_expand(snd_config_t *config, const char *args,
void *private_data, snd_config_t **result); void *private_data, snd_config_t **result);

View file

@ -7,14 +7,14 @@
# #
pcm.hw { pcm.hw {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -25,14 +25,14 @@ pcm.hw {
} }
pcm.plughw { pcm.plughw {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -46,8 +46,8 @@ pcm.plughw {
} }
pcm.plug { pcm.plug {
args [ SLAVE ] @args [ SLAVE ]
args.SLAVE { @args.SLAVE {
type string type string
} }
type plug type plug
@ -55,11 +55,11 @@ pcm.plug {
} }
pcm.shm { pcm.shm {
args [ SOCKET PCM ] @args [ SOCKET PCM ]
args.SOCKET { @args.SOCKET {
type string type string
} }
args.PCM { @args.PCM {
type string type string
} }
type shm type shm
@ -68,14 +68,14 @@ pcm.shm {
} }
pcm.tee { pcm.tee {
args [ SLAVE FILE FORMAT ] @args [ SLAVE FILE FORMAT ]
args.SLAVE { @args.SLAVE {
type string type string
} }
args.FILE { @args.FILE {
type string type string
} }
args.FORMAT { @args.FORMAT {
type string type string
default raw default raw
} }
@ -86,11 +86,11 @@ pcm.tee {
} }
pcm.file { pcm.file {
args [ FILE FORMAT ] @args [ FILE FORMAT ]
args.FILE { @args.FILE {
type string type string
} }
args.FORMAT { @args.FORMAT {
type string type string
default raw default raw
} }
@ -130,8 +130,8 @@ pcm.default {
} }
pcm.front { pcm.front {
args [ CARD DEV ] @args [ CARD DEV ]
args.CARD { @args.CARD {
type integer type integer
default { default {
@func getenv @func getenv
@ -144,7 +144,7 @@ pcm.front {
default 0 default 0
} }
} }
args.DEV { @args.DEV {
type integer type integer
default { default {
@func getenv @func getenv
@ -155,7 +155,7 @@ pcm.front {
default 0 default 0
} }
} }
refer { @refer {
filename { filename {
@func concat @func concat
strings [ strings [
@ -180,8 +180,8 @@ pcm.front {
} }
pcm.rear { pcm.rear {
args [ CARD DEV ] @args [ CARD DEV ]
args.CARD { @args.CARD {
type integer type integer
default { default {
@func getenv @func getenv
@ -194,7 +194,7 @@ pcm.rear {
default 0 default 0
} }
} }
args.DEV { @args.DEV {
type integer type integer
default { default {
@func getenv @func getenv
@ -205,7 +205,7 @@ pcm.rear {
default 0 default 0
} }
} }
refer { @refer {
filename { filename {
@func concat @func concat
strings [ strings [
@ -230,8 +230,8 @@ pcm.rear {
} }
pcm.center_lfe { pcm.center_lfe {
args [ CARD DEV ] @args [ CARD DEV ]
args.CARD { @args.CARD {
type integer type integer
default { default {
@func getenv @func getenv
@ -244,7 +244,7 @@ pcm.center_lfe {
default 0 default 0
} }
} }
args.DEV { @args.DEV {
type integer type integer
default { default {
@func getenv @func getenv
@ -255,7 +255,7 @@ pcm.center_lfe {
default 0 default 0
} }
} }
refer { @refer {
filename { filename {
@func concat @func concat
strings [ strings [
@ -280,8 +280,8 @@ pcm.center_lfe {
} }
pcm.surround40 { pcm.surround40 {
args [ CARD DEV ] @args [ CARD DEV ]
args.CARD { @args.CARD {
type integer type integer
default { default {
@func getenv @func getenv
@ -294,7 +294,7 @@ pcm.surround40 {
default 0 default 0
} }
} }
args.DEV { @args.DEV {
type integer type integer
default { default {
@func getenv @func getenv
@ -305,7 +305,7 @@ pcm.surround40 {
default 0 default 0
} }
} }
refer { @refer {
filename { filename {
@func concat @func concat
strings [ strings [
@ -330,8 +330,8 @@ pcm.surround40 {
} }
pcm.surround51 { pcm.surround51 {
args [ CARD DEV ] @args [ CARD DEV ]
args.CARD { @args.CARD {
type integer type integer
default { default {
@func getenv @func getenv
@ -344,7 +344,7 @@ pcm.surround51 {
default 0 default 0
} }
} }
args.DEV { @args.DEV {
type integer type integer
default { default {
@func getenv @func getenv
@ -355,7 +355,7 @@ pcm.surround51 {
default 0 default 0
} }
} }
refer { @refer {
filename { filename {
@func concat @func concat
strings [ strings [
@ -380,8 +380,8 @@ pcm.surround51 {
} }
pcm.iec958 { pcm.iec958 {
args [ CARD DEV AES0 AES1 AES2 AES3 ] @args [ CARD DEV AES0 AES1 AES2 AES3 ]
args.CARD { @args.CARD {
type integer type integer
default { default {
@func getenv @func getenv
@ -394,7 +394,7 @@ pcm.iec958 {
default 0 default 0
} }
} }
args.DEV { @args.DEV {
type integer type integer
default { default {
@func getenv @func getenv
@ -405,27 +405,27 @@ pcm.iec958 {
default 0 default 0
} }
} }
args.AES0 { @args.AES0 {
type integer type integer
# consumer, not-copyright, emphasis-none, mode=0 # consumer, not-copyright, emphasis-none, mode=0
default 0x04 default 0x04
} }
args.AES1 { @args.AES1 {
type integer type integer
# original, PCM coder # original, PCM coder
default 0x82 default 0x82
} }
args.AES2 { @args.AES2 {
type integer type integer
# source and channel # source and channel
default 0x00 default 0x00
} }
args.AES3 { @args.AES3 {
type integer type integer
# fs=48000Hz, clock accuracy=1000ppm # fs=48000Hz, clock accuracy=1000ppm
default 0x02 default 0x02
} }
refer { @refer {
filename { filename {
@func concat @func concat
strings [ strings [
@ -461,8 +461,8 @@ pcm.spdif pcm.iec958
# #
ctl.hw { ctl.hw {
args[ CARD ] @args[ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
type hw type hw
@ -470,11 +470,11 @@ ctl.hw {
} }
ctl.shm { ctl.shm {
args [ SOCKET CTL ] @args [ SOCKET CTL ]
args.SOCKET { @args.SOCKET {
type string type string
} }
args.CTL { @args.CTL {
type string type string
} }
type shm type shm
@ -498,14 +498,14 @@ ctl.default {
# #
rawmidi.hw { rawmidi.hw {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }

View file

@ -3,14 +3,14 @@
# #
pcm.emu10k1_front { pcm.emu10k1_front {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -21,25 +21,25 @@ pcm.emu10k1_front {
} }
pcm.front_0 { pcm.front_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
refer { @refer {
@func concat @func concat
strings [ "pcm.emu10k1_front:" $(CARD) ",0,-1" ] strings [ "pcm.emu10k1_front:" $(CARD) ",0,-1" ]
} }
} }
pcm.emu10k1_rear { pcm.emu10k1_rear {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -70,25 +70,25 @@ pcm.emu10k1_rear {
} }
pcm.rear_0 { pcm.rear_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
refer { @refer {
@func concat @func concat
strings [ "pcm.emu10k1_rear:" $(CARD) ",0,-1" ] strings [ "pcm.emu10k1_rear:" $(CARD) ",0,-1" ]
} }
} }
pcm.emu10k1_center_lfe { pcm.emu10k1_center_lfe {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -131,19 +131,19 @@ pcm.emu10k1_center_lfe {
} }
pcm.center_lfe_0 { pcm.center_lfe_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
refer { @refer {
@func concat @func concat
strings [ "pcm.emu10k1_center_lfe:" $(CARD) ",0,-1" ] strings [ "pcm.emu10k1_center_lfe:" $(CARD) ",0,-1" ]
} }
} }
pcm.surround40_0 { pcm.surround40_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
type multi type multi
@ -176,8 +176,8 @@ pcm.surround40_0 {
} }
pcm.surround51_0 { pcm.surround51_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
type multi type multi
@ -221,23 +221,23 @@ pcm.surround51_0 {
} }
pcm.iec958_0 { pcm.iec958_0 {
args [ CARD DEV AES0 AES1 AES2 AES3 ] @args [ CARD DEV AES0 AES1 AES2 AES3 ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.AES0 { @args.AES0 {
type integer type integer
} }
args.AES1 { @args.AES1 {
type integer type integer
} }
args.AES2 { @args.AES2 {
type integer type integer
} }
args.AES3 { @args.AES3 {
type integer type integer
} }
type hooks type hooks

View file

@ -3,14 +3,14 @@
# #
pcm.si7018_front { pcm.si7018_front {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -21,8 +21,8 @@ pcm.si7018_front {
} }
pcm.front_0 { pcm.front_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
redir { redir {
@ -32,14 +32,14 @@ pcm.front_0 {
} }
pcm.si7010_rear { pcm.si7010_rear {
args [ CARD DEV SUBDEV ] @args [ CARD DEV SUBDEV ]
args.CARD { @args.CARD {
type integer type integer
} }
args.DEV { @args.DEV {
type integer type integer
} }
args.SUBDEV { @args.SUBDEV {
type integer type integer
default -1 default -1
} }
@ -50,8 +50,8 @@ pcm.si7010_rear {
} }
pcm.rear_0 { pcm.rear_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
redir { redir {
@ -61,8 +61,8 @@ pcm.rear_0 {
} }
pcm.surround40_0 { pcm.surround40_0 {
args [ CARD ] @args [ CARD ]
args.CARD { @args.CARD {
type integer type integer
} }
type multi type multi

View file

@ -1788,7 +1788,7 @@ static int _snd_config_expand(snd_config_t *src,
switch (pass) { switch (pass) {
case SND_CONFIG_WALK_PASS_PRE: case SND_CONFIG_WALK_PASS_PRE:
{ {
if (strcmp(id, "args") == 0) if (strcmp(id, "@args") == 0)
return 0; return 0;
err = snd_config_make_compound(dst, id, src->u.compound.join); err = snd_config_make_compound(dst, id, src->u.compound.join);
if (err < 0) if (err < 0)
@ -2439,7 +2439,7 @@ int snd_config_expand(snd_config_t *config, const char *args,
{ {
int err; int err;
snd_config_t *defs, *subs = NULL, *res; snd_config_t *defs, *subs = NULL, *res;
err = snd_config_search(config, "args", &defs); err = snd_config_search(config, "@args", &defs);
if (err < 0) { if (err < 0) {
err = snd_config_copy(&res, config); err = snd_config_copy(&res, config);
if (err < 0) if (err < 0)
@ -2478,6 +2478,43 @@ int snd_config_expand(snd_config_t *config, const char *args,
return err; return err;
} }
/**
* \brief Search a node inside a config tree using alias
* \param config Config node handle
* \param base Key base (or NULL)
* \param key Key suffix
* \param result Pointer to expanded found node
* \return 0 on success otherwise a negative error code
*
* First key is tried and if nothing is found is tried base.key.
* If the value found is a string this is recursively tried in the
* same way.
*/
int snd_config_search_definition(snd_config_t *config,
const char *base, const char *name,
snd_config_t **result)
{
snd_config_t *conf;
char *key;
const char *args = strchr(name, ':');
int err;
if (args) {
args++;
key = alloca(args - name);
memcpy(key, name, args - name - 1);
key[args - name - 1] = '\0';
} else {
key = (char *) base;
}
err = snd_config_search_alias(config, base, key, &conf);
if (err < 0)
return err;
err = snd_config_expand(conf, args, NULL, result);
if (err < 0)
return err;
}
#if 0 #if 0
/* Not strictly needed, but useful to check for memory leaks */ /* Not strictly needed, but useful to check for memory leaks */

View file

@ -303,14 +303,14 @@ int snd_config_refer_load(snd_config_t *root,
* Helper functions for the configuration file * Helper functions for the configuration file
*/ */
int snd_func_getenv(snd_config_t **dst, snd_config_t *src, void *private_data ATTRIBUTE_UNUSED) int snd_func_getenv(snd_config_t **dst, snd_config_t *src, void *private_data)
{ {
snd_config_t *n, *d, *e; snd_config_t *n, *d, *e;
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
char *res, *def = NULL; char *res, *def = NULL;
int idx = 0, err; int idx = 0, err;
err = snd_config_expand(src, NULL, NULL, &e); err = snd_config_expand(src, NULL, private_data, &e);
if (err < 0) if (err < 0)
return err; return err;
err = snd_config_search(e, "envname", &n); err = snd_config_search(e, "envname", &n);
@ -373,14 +373,14 @@ int snd_func_getenv(snd_config_t **dst, snd_config_t *src, void *private_data AT
return err; return err;
} }
int snd_func_concat(snd_config_t **dst, snd_config_t *src, void *private_data ATTRIBUTE_UNUSED) int snd_func_concat(snd_config_t **dst, snd_config_t *src, void *private_data)
{ {
snd_config_t *n, *e; snd_config_t *n, *e;
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
char *res = NULL, *tmp; char *res = NULL, *tmp;
int idx = 0, len = 0, len1, err; int idx = 0, len = 0, len1, err;
err = snd_config_expand(src, NULL, NULL, &e); err = snd_config_expand(src, NULL, private_data, &e);
if (err < 0) if (err < 0)
return err; return err;
err = snd_config_search(e, "strings", &n); err = snd_config_search(e, "strings", &n);
@ -464,7 +464,7 @@ static int string_from_integer(char **dst, long v)
} }
#endif #endif
int snd_func_card_strtype(snd_config_t **dst, snd_config_t *src, void *private_data ATTRIBUTE_UNUSED) int snd_func_card_strtype(snd_config_t **dst, snd_config_t *src, void *private_data)
{ {
snd_config_t *n, *e; snd_config_t *n, *e;
char *res = NULL; char *res = NULL;
@ -473,7 +473,7 @@ int snd_func_card_strtype(snd_config_t **dst, snd_config_t *src, void *private_d
long v; long v;
int err; int err;
err = snd_config_expand(src, NULL, NULL, &e); err = snd_config_expand(src, NULL, private_data, &e);
if (err < 0) if (err < 0)
return err; return err;
err = snd_config_search(e, "card", &n); err = snd_config_search(e, "card", &n);
@ -513,7 +513,7 @@ int snd_func_card_strtype(snd_config_t **dst, snd_config_t *src, void *private_d
return err; return err;
} }
int snd_func_card_id(snd_config_t **dst, snd_config_t *src, void *private_data ATTRIBUTE_UNUSED) int snd_func_card_id(snd_config_t **dst, snd_config_t *src, void *private_data)
{ {
snd_config_t *n, *e; snd_config_t *n, *e;
char *res = NULL; char *res = NULL;
@ -522,7 +522,7 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *src, void *private_data A
long v; long v;
int err; int err;
err = snd_config_expand(src, NULL, NULL, &e); err = snd_config_expand(src, NULL, private_data, &e);
if (err < 0) if (err < 0)
return err; return err;
err = snd_config_search(e, "card", &n); err = snd_config_search(e, "card", &n);
@ -562,7 +562,7 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *src, void *private_data A
return err; return err;
} }
int snd_func_pcm_id(snd_config_t **dst, snd_config_t *src, void *private_data ATTRIBUTE_UNUSED) int snd_func_pcm_id(snd_config_t **dst, snd_config_t *src, void *private_data)
{ {
snd_config_t *n, *e; snd_config_t *n, *e;
char *res = NULL; char *res = NULL;
@ -571,7 +571,7 @@ int snd_func_pcm_id(snd_config_t **dst, snd_config_t *src, void *private_data AT
long card, device, subdevice = 0; long card, device, subdevice = 0;
int err; int err;
err = snd_config_expand(src, NULL, NULL, &e); err = snd_config_expand(src, NULL, private_data, &e);
if (err < 0) if (err < 0)
return err; return err;
err = snd_config_search(e, "card", &n); err = snd_config_search(e, "card", &n);

View file

@ -408,11 +408,11 @@ int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
SNDERR("Invalid type for %s", snd_config_get_id(conf)); SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err; return err;
} }
err = snd_config_search_alias(snd_config, "ctl_type", str, &type_conf); err = snd_config_search_definition(snd_config, "ctl_type", str, &type_conf);
if (err >= 0) { if (err >= 0) {
if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for CTL type %s definition", str); SNDERR("Invalid type for CTL type %s definition", str);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, type_conf) { snd_config_for_each(i, next, type_conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -423,7 +423,7 @@ int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
err = snd_config_get_string(n, &lib); err = snd_config_get_string(n, &lib);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -431,11 +431,13 @@ int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
err = snd_config_get_string(n, &open_name); err = snd_config_get_string(n, &open_name);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(type_conf);
return -EINVAL; return -EINVAL;
} }
} }
@ -446,11 +448,14 @@ int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
if (!lib) if (!lib)
lib = ALSA_LIB; lib = ALSA_LIB;
h = dlopen(lib, RTLD_NOW); h = dlopen(lib, RTLD_NOW);
if (h)
open_func = dlsym(h, open_name);
if (type_conf)
snd_config_delete(type_conf);
if (!h) { if (!h) {
SNDERR("Cannot open shared library %s", lib); SNDERR("Cannot open shared library %s", lib);
return -ENOENT; return -ENOENT;
} }
open_func = dlsym(h, open_name);
if (!open_func) { if (!open_func) {
SNDERR("symbol %s is not defined inside %s", open_name, lib); SNDERR("symbol %s is not defined inside %s", open_name, lib);
dlclose(h); dlclose(h);
@ -463,42 +468,9 @@ int snd_ctl_open_noupdate(snd_ctl_t **ctlp, snd_config_t *root, const char *name
{ {
int err; int err;
snd_config_t *ctl_conf; snd_config_t *ctl_conf;
char *base, *key; err = snd_config_search_definition(root, "ctl", name, &ctl_conf);
const char *args = strchr(name, ':');
if (args) {
args++;
base = alloca(args - name);
memcpy(base, name, args - name - 1);
base[args - name - 1] = '\0';
key = strchr(base, '.');
if (key)
*key++ = '\0';
} else {
key = strchr(name, '.');
if (key) {
key++;
base = alloca(key - name);
memcpy(base, name, key - name - 1);
base[key - name - 1] = '\0';
} else
base = (char *) name;
}
if (key == NULL) {
key = base;
base = NULL;
}
err = snd_config_search_alias(root, base, key, &ctl_conf);
if (err < 0) { if (err < 0) {
(void)(base == NULL && (err = snd_config_search_alias(root, "ctl", key, &ctl_conf))); SNDERR("Invalid CTL %s", name);
if (err < 0) {
SNDERR("Unknown PCM %s", name);
return err;
}
}
err = snd_config_expand(ctl_conf, args, NULL, &ctl_conf);
if (err < 0) {
SNDERR("Could not expand configuration for %s: %s", name, snd_strerror(err));
return err; return err;
} }
err = snd_ctl_open_conf(ctlp, name, ctl_conf, mode); err = snd_ctl_open_conf(ctlp, name, ctl_conf, mode);

View file

@ -570,14 +570,14 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf, int m
SNDERR("server is not defined"); SNDERR("server is not defined");
return -EINVAL; return -EINVAL;
} }
err = snd_config_search_alias(snd_config, "server", server, &sconfig); err = snd_config_search_definition(snd_config, "server", server, &sconfig);
if (err < 0) { if (err < 0) {
SNDERR("Unknown server %s", server); SNDERR("Unknown server %s", server);
return -EINVAL; return -EINVAL;
} }
if (snd_config_get_type(sconfig) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(sconfig) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for server %s definition", server); SNDERR("Invalid type for server %s definition", server);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, conf) { snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -588,7 +588,7 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf, int m
err = snd_config_get_string(n, &host); err = snd_config_get_string(n, &host);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -596,7 +596,7 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf, int m
err = snd_config_get_string(n, &sockname); err = snd_config_get_string(n, &sockname);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -604,32 +604,36 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf, int m
err = snd_config_get_integer(n, &port); err = snd_config_get_integer(n, &port);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(sconfig);
return -EINVAL; return -EINVAL;
} }
if (!host) { if (!host) {
SNDERR("host is not defined"); SNDERR("host is not defined");
return -EINVAL; goto _err;
} }
if (!sockname) { if (!sockname) {
SNDERR("socket is not defined"); SNDERR("socket is not defined");
return -EINVAL; goto _err;
} }
h = gethostbyname(host); h = gethostbyname(host);
if (!h) { if (!h) {
SNDERR("Cannot resolve %s", host); SNDERR("Cannot resolve %s", host);
return -EINVAL; goto _err;
} }
local = is_local(h); local = is_local(h);
if (!local) { if (!local) {
SNDERR("%s is not the local host", host); SNDERR("%s is not the local host", host);
return -EINVAL; goto _err;
} }
return snd_ctl_shm_open(handlep, name, sockname, ctl_name, mode); err = snd_ctl_shm_open(handlep, name, sockname, ctl_name, mode);
snd_config_delete(sconfig);
return err;
} }

View file

@ -942,11 +942,11 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
SNDERR("Invalid type for %s", snd_config_get_id(conf)); SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err; return err;
} }
err = snd_config_search_alias(snd_config, "pcm_type", str, &type_conf); err = snd_config_search_definition(snd_config, "pcm_type", str, &type_conf);
if (err >= 0) { if (err >= 0) {
if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for PCM type %s definition", str); SNDERR("Invalid type for PCM type %s definition", str);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, type_conf) { snd_config_for_each(i, next, type_conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -957,7 +957,7 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
err = snd_config_get_string(n, &lib); err = snd_config_get_string(n, &lib);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -965,11 +965,13 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
err = snd_config_get_string(n, &open_name); err = snd_config_get_string(n, &open_name);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(type_conf);
return -EINVAL; return -EINVAL;
} }
} }
@ -980,11 +982,14 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
if (!lib) if (!lib)
lib = ALSA_LIB; lib = ALSA_LIB;
h = dlopen(lib, RTLD_NOW); h = dlopen(lib, RTLD_NOW);
if (h)
open_func = dlsym(h, open_name);
if (type_conf)
snd_config_delete(type_conf);
if (!h) { if (!h) {
SNDERR("Cannot open shared library %s", lib); SNDERR("Cannot open shared library %s", lib);
return -ENOENT; return -ENOENT;
} }
open_func = dlsym(h, open_name);
if (!open_func) { if (!open_func) {
SNDERR("symbol %s is not defined inside %s", open_name, lib); SNDERR("symbol %s is not defined inside %s", open_name, lib);
dlclose(h); dlclose(h);
@ -1000,43 +1005,10 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
const char *name, snd_pcm_stream_t stream, int mode) const char *name, snd_pcm_stream_t stream, int mode)
{ {
int err; int err;
snd_config_t *pcm_conf; snd_config_t *pcm_conf, *conf;
char *base, *key; err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
const char *args = strchr(name, ':');
snd_config_t *conf;
if (args) {
args++;
base = alloca(args - name);
memcpy(base, name, args - name - 1);
base[args - name - 1] = '\0';
key = strchr(base, '.');
if (key)
*key++ = '\0';
} else {
key = strchr(name, '.');
if (key) {
key++;
base = alloca(key - name);
memcpy(base, name, key - name - 1);
base[key - name - 1] = '\0';
} else
base = (char *) name;
}
if (key == NULL) {
key = base;
base = NULL;
}
err = snd_config_search_alias(root, base, key, &pcm_conf);
if (err < 0) { if (err < 0) {
(void)(base == NULL && (err = snd_config_search_alias(root, "pcm", key, &pcm_conf))); SNDERR("Unknown PCM %s", name);
if (err < 0) {
SNDERR("Unknown PCM %s", name);
return err;
}
}
err = snd_config_expand(pcm_conf, args, NULL, &pcm_conf);
if (err < 0) {
SNDERR("Could not expand configuration for %s: %s", name, snd_strerror(err));
return err; return err;
} }
if (snd_config_search(pcm_conf, "refer", &conf) >= 0) { if (snd_config_search(pcm_conf, "refer", &conf) >= 0) {
@ -1044,8 +1016,7 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
int conf_free_tmp; int conf_free_tmp;
char *refer_name = NULL; char *refer_name = NULL;
err = snd_config_refer_load(root, conf, &refer_name, &tmp_conf, &conf_free_tmp); err = snd_config_refer_load(root, conf, &refer_name, &tmp_conf, &conf_free_tmp);
if (args) snd_config_delete(pcm_conf);
snd_config_delete(pcm_conf);
if (err < 0) { if (err < 0) {
SNDERR("Refer load error for %s: %s", name, snd_strerror(err)); SNDERR("Refer load error for %s: %s", name, snd_strerror(err));
return err; return err;
@ -4318,16 +4289,18 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
unsigned int k; unsigned int k;
snd_config_t *pcm_conf = NULL; snd_config_t *pcm_conf = NULL;
int err; int err;
int to_free = 0;
va_list args; va_list args;
assert(root); assert(root);
assert(conf); assert(conf);
assert(_pcm_conf); assert(_pcm_conf);
if (snd_config_get_string(conf, &str) >= 0) { if (snd_config_get_string(conf, &str) >= 0) {
err = snd_config_search_alias(conf, "pcm_slave", str, &conf); err = snd_config_search_definition(root, "pcm_slave", str, &conf);
if (err < 0) { if (err < 0) {
SNDERR("Configuration pcm_slave.%s was not found\n", str); SNDERR("Invalid slave definition");
return -EINVAL; return -EINVAL;
} }
to_free = 1;
} }
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid slave definition"); SNDERR("Invalid slave definition");
@ -4365,12 +4338,13 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
if (err < 0) { if (err < 0) {
_invalid: _invalid:
SNDERR("invalid type for %s", id); SNDERR("invalid type for %s", id);
return err; goto _err;
} }
f = snd_pcm_format_value(str); f = snd_pcm_format_value(str);
if (f == SND_PCM_FORMAT_UNKNOWN) { if (f == SND_PCM_FORMAT_UNKNOWN) {
SNDERR("unknown format"); SNDERR("unknown format");
return -EINVAL; err = -EINVAL;
goto _err;
} }
*(snd_pcm_format_t*)fields[k].ptr = f; *(snd_pcm_format_t*)fields[k].ptr = f;
break; break;
@ -4388,20 +4362,27 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
if (k < count) if (k < count)
continue; continue;
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
// return -EINVAL; err = -EINVAL;
goto _err;
} }
if (!pcm_conf) { if (!pcm_conf) {
SNDERR("missing field pcm"); SNDERR("missing field pcm");
return -EINVAL; err = -EINVAL;
goto _err;
} }
for (k = 0; k < count; ++k) { for (k = 0; k < count; ++k) {
if (fields[k].mandatory && !fields[k].valid) { if (fields[k].mandatory && !fields[k].valid) {
SNDERR("missing field %s", names[fields[k].index]); SNDERR("missing field %s", names[fields[k].index]);
return -EINVAL; err = -EINVAL;
goto _err;
} }
} }
*_pcm_conf = pcm_conf; *_pcm_conf = pcm_conf;
return 0; return 0;
_err:
if (to_free)
snd_config_delete(conf);
return err;
} }

View file

@ -335,13 +335,6 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
snd_config_iterator_t i, next; snd_config_iterator_t i, next;
int (*install_func)(snd_pcm_t *pcm, snd_config_t *args); int (*install_func)(snd_pcm_t *pcm, snd_config_t *args);
void *h; void *h;
if (snd_config_get_string(conf, &str) >= 0) {
err = snd_config_search_alias(snd_config, "pcm_hook", str, &conf);
if (err < 0) {
SNDERR("unknown pcm_hook %s", str);
return err;
}
}
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid hook definition"); SNDERR("Invalid hook definition");
return -EINVAL; return -EINVAL;
@ -371,11 +364,11 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
SNDERR("Invalid type for %s", snd_config_get_id(type)); SNDERR("Invalid type for %s", snd_config_get_id(type));
return err; return err;
} }
err = snd_config_search_alias(snd_config, "pcm_hook_type", str, &type); err = snd_config_search_definition(snd_config, "pcm_hook_type", str, &type);
if (err >= 0) { if (err >= 0) {
if (snd_config_get_type(type) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(type) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for PCM type %s definition", str); SNDERR("Invalid type for PCM type %s definition", str);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, type) { snd_config_for_each(i, next, type) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -386,7 +379,7 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
err = snd_config_get_string(n, &lib); err = snd_config_get_string(n, &lib);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -394,11 +387,13 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
err = snd_config_get_string(n, &install); err = snd_config_get_string(n, &install);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(type);
return -EINVAL; return -EINVAL;
} }
} }
@ -408,25 +403,30 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
} }
if (!lib) if (!lib)
lib = ALSA_LIB; lib = ALSA_LIB;
if (args && snd_config_get_string(args, &str) >= 0) {
err = snd_config_search_alias(snd_config, "hook_args", str, &args);
if (err < 0) {
SNDERR("unknown hook_args %s", str);
return err;
}
}
h = dlopen(lib, RTLD_NOW); h = dlopen(lib, RTLD_NOW);
if (h)
install_func = dlsym(h, install);
if (type)
snd_config_delete(type);
if (!h) { if (!h) {
SNDERR("Cannot open shared library %s", lib); SNDERR("Cannot open shared library %s", lib);
return -ENOENT; return -ENOENT;
} }
install_func = dlsym(h, install);
if (!install_func) { if (!install_func) {
SNDERR("symbol %s is not defined inside %s", install, lib); SNDERR("symbol %s is not defined inside %s", install, lib);
dlclose(h); dlclose(h);
return -ENXIO; return -ENXIO;
} }
err = install_func(pcm, args); if (args && snd_config_get_string(args, &str) >= 0) {
err = snd_config_search_definition(snd_config, "hook_args", str, &args);
if (err < 0) {
SNDERR("unknown hook_args %s", str);
return err;
}
err = install_func(pcm, args);
snd_config_delete(args);
} else
err = install_func(pcm, args);
if (err < 0) if (err < 0)
return err; return err;
return 0; return 0;
@ -480,7 +480,17 @@ int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
return 0; return 0;
snd_config_for_each(i, next, hooks) { snd_config_for_each(i, next, hooks) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
err = snd_pcm_hook_add_conf(*pcmp, n); const char *str;
if (snd_config_get_string(n, &str) >= 0) {
err = snd_config_search_definition(snd_config, "pcm_hook", str, &n);
if (err < 0) {
SNDERR("unknown pcm_hook %s", str);
return err;
}
err = snd_pcm_hook_add_conf(*pcmp, n);
snd_config_delete(n);
} else
err = snd_pcm_hook_add_conf(*pcmp, n);
if (err < 0) { if (err < 0) {
snd_pcm_close(*pcmp); snd_pcm_close(*pcmp);
return err; return err;

View file

@ -663,29 +663,23 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
snd_config_t *); snd_config_t *);
void *h; void *h;
int err; int err;
err = snd_config_get_string(conf, &str); int to_free = 0;
if (err >= 0) {
err = snd_config_search_alias(snd_config, "pcm_scope", str, &conf);
if (err < 0) {
SNDERR("unknown pcm_scope %s", str);
return err;
}
}
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for scope %s", str); SNDERR("Invalid type for scope %s", str);
return -EINVAL; err = -EINVAL;
goto _err;
} }
err = snd_config_search(conf, "type", &c); err = snd_config_search(conf, "type", &c);
if (err < 0) { if (err < 0) {
SNDERR("type is not defined"); SNDERR("type is not defined");
return err; goto _err;
} }
err = snd_config_get_string(c, &str); err = snd_config_get_string(c, &str);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", snd_config_get_id(c)); SNDERR("Invalid type for %s", snd_config_get_id(c));
return err; goto _err;
} }
err = snd_config_search_alias(snd_config, "pcm_scope_type", str, &type_conf); err = snd_config_search_definition(snd_config, "pcm_scope_type", str, &type_conf);
if (err >= 0) { if (err >= 0) {
snd_config_for_each(i, next, type_conf) { snd_config_for_each(i, next, type_conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -696,7 +690,7 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
err = snd_config_get_string(n, &lib); err = snd_config_get_string(n, &lib);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err1;
} }
continue; continue;
} }
@ -704,12 +698,13 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
err = snd_config_get_string(n, &open_name); err = snd_config_get_string(n, &open_name);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err1;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
return -EINVAL; err = -EINVAL;
goto _err1;
} }
} }
if (!open_name) { if (!open_name) {
@ -721,15 +716,24 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
h = dlopen(lib, RTLD_NOW); h = dlopen(lib, RTLD_NOW);
if (!h) { if (!h) {
SNDERR("Cannot open shared library %s", lib); SNDERR("Cannot open shared library %s", lib);
return -ENOENT; err = -ENOENT;
goto _err1;
} }
open_func = dlsym(h, open_name); open_func = dlsym(h, open_name);
if (type_conf)
snd_config_delete(type_conf);
if (!open_func) { if (!open_func) {
SNDERR("symbol %s is not defined inside %s", open_name, lib); SNDERR("symbol %s is not defined inside %s", open_name, lib);
dlclose(h); dlclose(h);
return -ENXIO; goto _err;
} }
return open_func(pcm, name, conf); return open_func(pcm, name, conf);
_err1:
snd_config_delete(type_conf);
_err:
if (to_free)
snd_config_delete(conf);
return err;
} }
@ -791,7 +795,17 @@ int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
snd_config_for_each(i, next, scopes) { snd_config_for_each(i, next, scopes) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
const char *id = snd_config_get_id(n); const char *id = snd_config_get_id(n);
err = snd_pcm_meter_add_scope_conf(*pcmp, id, n); const char *str;
if (snd_config_get_string(n, &str) >= 0) {
err = snd_config_search_definition(snd_config, "pcm_scope", str, &n);
if (err < 0) {
SNDERR("unknown pcm_scope %s", str);
return err;
}
err = snd_pcm_meter_add_scope_conf(*pcmp, id, n);
snd_config_delete(n);
} else
err = snd_pcm_meter_add_scope_conf(*pcmp, id, n);
if (err < 0) { if (err < 0) {
snd_pcm_close(*pcmp); snd_pcm_close(*pcmp);
return err; return err;

View file

@ -1414,7 +1414,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name,
SNDERR("slave is not defined"); SNDERR("slave is not defined");
return -EINVAL; return -EINVAL;
} }
err = snd_pcm_slave_conf(root, slave, &sconf, NULL, 5, err = snd_pcm_slave_conf(root, slave, &sconf, 5,
SND_PCM_HW_PARAM_CHANNELS, 0, &schannels, SND_PCM_HW_PARAM_CHANNELS, 0, &schannels,
SND_PCM_HW_PARAM_FORMAT, 0, &sformat, SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
SND_PCM_HW_PARAM_RATE, 0, &srate, SND_PCM_HW_PARAM_RATE, 0, &srate,

View file

@ -765,14 +765,14 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
SNDERR("server is not defined"); SNDERR("server is not defined");
return -EINVAL; return -EINVAL;
} }
err = snd_config_search_alias(snd_config, "server", server, &sconfig); err = snd_config_search_definition(snd_config, "server", server, &sconfig);
if (err < 0) { if (err < 0) {
SNDERR("Unknown server %s", server); SNDERR("Unknown server %s", server);
return -EINVAL; return -EINVAL;
} }
if (snd_config_get_type(sconfig) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(sconfig) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for server %s definition", server); SNDERR("Invalid type for server %s definition", server);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, sconfig) { snd_config_for_each(i, next, sconfig) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -783,7 +783,7 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
err = snd_config_get_string(n, &host); err = snd_config_get_string(n, &host);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -791,7 +791,7 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
err = snd_config_get_string(n, &sockname); err = snd_config_get_string(n, &sockname);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -799,32 +799,36 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
err = snd_config_get_integer(n, &port); err = snd_config_get_integer(n, &port);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(sconfig);
return -EINVAL; return -EINVAL;
} }
if (!host) { if (!host) {
SNDERR("host is not defined"); SNDERR("host is not defined");
return -EINVAL; goto _err;
} }
if (!sockname) { if (!sockname) {
SNDERR("socket is not defined"); SNDERR("socket is not defined");
return -EINVAL; goto _err;
} }
h = gethostbyname(host); h = gethostbyname(host);
if (!h) { if (!h) {
SNDERR("Cannot resolve %s", host); SNDERR("Cannot resolve %s", host);
return -EINVAL; goto _err;
} }
local = is_local(h); local = is_local(h);
if (!local) { if (!local) {
SNDERR("%s is not the local host", host); SNDERR("%s is not the local host", host);
return -EINVAL; return -EINVAL;
} }
return snd_pcm_shm_open(pcmp, name, sockname, pcm_name, stream, mode); err = snd_pcm_shm_open(pcmp, name, sockname, pcm_name, stream, mode);
snd_config_delete(sconfig);
return err;
} }

View file

@ -91,11 +91,11 @@ int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
SNDERR("Invalid type for %s", snd_config_get_id(conf)); SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err; return err;
} }
err = snd_config_search_alias(snd_config, "rawmidi_type", str, &type_conf); err = snd_config_search_definition(snd_config, "rawmidi_type", str, &type_conf);
if (err >= 0) { if (err >= 0) {
if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for RAWMIDI type %s definition", str); SNDERR("Invalid type for RAWMIDI type %s definition", str);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, type_conf) { snd_config_for_each(i, next, type_conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -106,7 +106,7 @@ int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
err = snd_config_get_string(n, &lib); err = snd_config_get_string(n, &lib);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -114,11 +114,13 @@ int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
err = snd_config_get_string(n, &open_name); err = snd_config_get_string(n, &open_name);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(type_conf);
return -EINVAL; return -EINVAL;
} }
} }
@ -129,11 +131,14 @@ int snd_rawmidi_open_conf(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
if (!lib) if (!lib)
lib = ALSA_LIB; lib = ALSA_LIB;
h = dlopen(lib, RTLD_NOW); h = dlopen(lib, RTLD_NOW);
if (h)
open_func = dlsym(h, open_name);
if (type_conf)
snd_config_delete(type_conf);
if (!h) { if (!h) {
SNDERR("Cannot open shared library %s", lib); SNDERR("Cannot open shared library %s", lib);
return -ENOENT; return -ENOENT;
} }
open_func = dlsym(h, open_name);
if (!open_func) { if (!open_func) {
SNDERR("symbol %s is not defined inside %s", open_name, lib); SNDERR("symbol %s is not defined inside %s", open_name, lib);
dlclose(h); dlclose(h);
@ -160,44 +165,11 @@ int snd_rawmidi_open_noupdate(snd_rawmidi_t **inputp, snd_rawmidi_t **outputp,
{ {
int err; int err;
snd_config_t *rawmidi_conf; snd_config_t *rawmidi_conf;
char *base, *key; err = snd_config_search_definition(root, "rawmidi", name, &rawmidi_conf);
const char *args = strchr(name, ':');
if (args) {
args++;
base = alloca(args - name);
memcpy(base, name, args - name - 1);
base[args - name - 1] = '\0';
key = strchr(base, '.');
if (key)
*key++ = '\0';
} else {
key = strchr(name, '.');
if (key) {
key++;
base = alloca(key - name);
memcpy(base, name, key - name - 1);
base[key - name - 1] = '\0';
} else
base = (char *) name;
}
if (key == NULL) {
key = base;
base = NULL;
}
err = snd_config_search_alias(root, base, key, &rawmidi_conf);
if (err < 0) { if (err < 0) {
(void)(base == NULL && (err = snd_config_search_alias(root, "rawmidi", key, &rawmidi_conf))); SNDERR("Unknown RawMidi %s", name);
if (err < 0) {
SNDERR("Unknown RawMidi %s", name);
return err;
}
}
err = snd_config_expand(rawmidi_conf, args, NULL, &rawmidi_conf);
if (err < 0) {
SNDERR("Could not expand configuration for %s: %s", name, snd_strerror(err));
return err; return err;
} }
err = snd_rawmidi_open_conf(inputp, outputp, name, rawmidi_conf, mode); err = snd_rawmidi_open_conf(inputp, outputp, name, rawmidi_conf, mode);
snd_config_delete(rawmidi_conf); snd_config_delete(rawmidi_conf);
return err; return err;

View file

@ -90,11 +90,11 @@ static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
SNDERR("Invalid type for %s", snd_config_get_id(conf)); SNDERR("Invalid type for %s", snd_config_get_id(conf));
return err; return err;
} }
err = snd_config_search_alias(snd_config, "seq_type", str, &type_conf); err = snd_config_search_definition(snd_config, "seq_type", str, &type_conf);
if (err >= 0) { if (err >= 0) {
if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
SNDERR("Invalid type for SEQ type %s definition", str); SNDERR("Invalid type for SEQ type %s definition", str);
return -EINVAL; goto _err;
} }
snd_config_for_each(i, next, type_conf) { snd_config_for_each(i, next, type_conf) {
snd_config_t *n = snd_config_iterator_entry(i); snd_config_t *n = snd_config_iterator_entry(i);
@ -105,7 +105,7 @@ static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
err = snd_config_get_string(n, &lib); err = snd_config_get_string(n, &lib);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
@ -113,11 +113,13 @@ static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
err = snd_config_get_string(n, &open_name); err = snd_config_get_string(n, &open_name);
if (err < 0) { if (err < 0) {
SNDERR("Invalid type for %s", id); SNDERR("Invalid type for %s", id);
return -EINVAL; goto _err;
} }
continue; continue;
} }
SNDERR("Unknown field %s", id); SNDERR("Unknown field %s", id);
_err:
snd_config_delete(type_conf);
return -EINVAL; return -EINVAL;
} }
} }
@ -128,11 +130,14 @@ static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
if (!lib) if (!lib)
lib = ALSA_LIB; lib = ALSA_LIB;
h = dlopen(lib, RTLD_NOW); h = dlopen(lib, RTLD_NOW);
if (h)
open_func = dlsym(h, open_name);
if (type_conf)
snd_config_delete(type_conf);
if (!h) { if (!h) {
SNDERR("Cannot open shared library %s", lib); SNDERR("Cannot open shared library %s", lib);
return -ENOENT; return -ENOENT;
} }
open_func = dlsym(h, open_name);
if (!open_func) { if (!open_func) {
SNDERR("symbol %s is not defined inside %s", open_name, lib); SNDERR("symbol %s is not defined inside %s", open_name, lib);
dlclose(h); dlclose(h);
@ -146,42 +151,9 @@ static int snd_seq_open_noupdate(snd_seq_t **seqp, snd_config_t *root,
{ {
int err; int err;
snd_config_t *seq_conf; snd_config_t *seq_conf;
char *base, *key; err = snd_config_search_definition(root, "seq", name, &seq_conf);
const char *args = strchr(name, ':');
if (args) {
args++;
base = alloca(args - name);
memcpy(base, name, args - name - 1);
base[args - name - 1] = '\0';
key = strchr(base, '.');
if (key)
*key++ = '\0';
} else {
key = strchr(name, '.');
if (key) {
key++;
base = alloca(key - name);
memcpy(base, name, key - name - 1);
base[key - name - 1] = '\0';
} else
base = (char *) name;
}
if (key == NULL) {
key = base;
base = NULL;
}
err = snd_config_search_alias(root, base, key, &seq_conf);
if (err < 0) { if (err < 0) {
(void)(base == NULL && (err = snd_config_search_alias(root, "seq", key, &seq_conf))); SNDERR("Unknown SEQ %s", name);
if (err < 0) {
SNDERR("Unknown PCM %s", name);
return err;
}
}
err = snd_config_expand(seq_conf, args, NULL, &seq_conf);
if (err < 0) {
SNDERR("Could not expand configuration for %s: %s", name, snd_strerror(err));
return err; return err;
} }
err = snd_seq_open_conf(seqp, name, seq_conf, streams, mode); err = snd_seq_open_conf(seqp, name, seq_conf, streams, mode);