Commit graph

187 commits

Author SHA1 Message Date
Jaroslav Kysela
ef38bff00e conf: fix snd_config_substitute (for src->parent)
If source configuration node has a parent set, it must be always
detached to avoid memory corruptions.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2024-06-21 16:32:10 +02:00
borine
9cb4414e3b doxygen: conf: silence 'not documented' warnings
From: borine@github
Link: https://github.com/alsa-project/alsa-lib/pull/340
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-09-01 16:11:43 +02:00
borine
9505cfdb46 doxygen: fix broken parameter name tags
From: borine@github
Link: https://github.com/alsa-project/alsa-lib/pull/340
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-09-01 16:10:55 +02:00
Maxython
b40fcda7fb compilation: fix ANDROID -> __ANDROID__ define detection
Fixes: https://github.com/alsa-project/alsa-lib/pull/301/
Signed-off-by: Maxython <mixython@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2023-05-02 14:52:27 +02:00
Jaroslav Kysela
13e31fb1ec alsa-lib: conf - fix possible use-after-free in get_char_skip_comments
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-12-07 14:54:30 +01:00
SASANO Takayoshi
60c1430b43 add DragonFlyBSD build support (except test/)
due to undefined reference to 'environ' error, ucm_exec.c uses workaround.

Fixes: https://github.com/alsa-project/alsa-lib/pull/250
Signed-off-by: SASANO Takayoshi <uaa@uaa.org.uk>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-10-17 13:11:47 +02:00
SASANO Takayoshi
b33ef3f73d add NetBSD/OpenBSD build support (except test/)
Fixes: https://github.com/alsa-project/alsa-lib/pull/250
Signed-off-by: SASANO Takayoshi <uaa@uaa.org.uk>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-10-17 13:11:29 +02:00
Simon McVittie
87ff5318e3 conf: Use ino64_t to save and compare inode numbers
On 32-bit platforms when not using the large-file-support ABI,
struct stat64 contains ino64_t which is 64-bit, while ino_t is only
32-bit.

snd_config_update_r() checks whether a file has been replaced by saving
the ino member of a struct stat64 and comparing it with a previously-saved
inode number. On 32-bit platforms, assigning the 64-bit member of struct
stat64 to a 32-bit member of struct finfo will truncate it modulo 1<<32,
which could conceivably result in libasound not reloading configuration
when it should (although the inode number space is large enough to make
this failure mode highly unlikely).

Fixes: https://github.com/alsa-project/alsa-lib/pull/231
Signed-off-by: Simon McVittie <smcv@collabora.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-06-05 10:24:26 +02:00
Sebastian Krzyszkowiak
45b65fa4c1 conf: Use LFS calls when reading config files
Although at first glance it doesn't seem useful to support config
files larger than 2GB, LFS also influences inode size. Without this,
32-bit libasound may be unable to read config files on filesystems
with 64-bit inodes, such as Btrfs or NFS.

Fixes: https://github.com/alsa-project/alsa-lib/pull/223
Signed-off-by: Sebastian Krzyszkowiak <dos@dosowisko.net>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-20 09:54:32 +02:00
Jaroslav Kysela
3e5a894378 conf: fix memory leak in snd_config_substitute() for strings
When destination type is SND_CONFIG_TYPE_STRING, the old string
must be freed.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-05-13 16:19:50 +02:00
Jaroslav Kysela
3dbe072d8d conf: snd_config_merge - fix comment (overwrite / override)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-27 18:25:00 +01:00
Jaroslav Kysela
c687c48210 conf: fix the export of safe_strto* functions from libasound
Only one library should define the safe_strto function. Export it
correctly and add _snd_ prefix to avoid possible clashes with the other
application code.

Fixes: 47252054 ("src/topology/parser.c: drop duplicate safe_strtol_base")
Fixes: https://github.com/alsa-project/alsa-lib/pull/208
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2022-01-01 19:26:48 +01:00
Jaroslav Kysela
4b22871ee5 conf: fix the device parsing when arguments has no defaults
The commit bf528b90 sets the value to an empty string which causes
these errors:

   pcm_hw.c: Invalid type for device
   pcm_hw.c: Invalid type for subdevice

When device arguments (@args) have no default values set,
the field must be skipped to keep the compatibility.

BugLink: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/1246
Fixes: https://github.com/alsa-project/alsa-lib/issues/199
Fixes: bf528b90 ("conf: add possibility to evaluate simple integer math expressions")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-09 10:15:47 +01:00
Jaroslav Kysela
ebb8a6c7a1 conf: introduce snd_config_load_string()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-12-01 10:18:58 +01:00
Jaroslav Kysela
bf528b9066 conf: add possibility to evaluate simple integer math expressions
It is useful to use the math expressions for the values in configuration.
This patch adds a simple expression evaluation routines (integer only).
The syntax is simplified unix shell (bash) style.

Examples:

	$[1 + 1]
	$[$[2 + 2] / $var1]
	$[0xa0 | 0x05]

As a bonus, the variable substitutions were more abstracted.
The function snd_config_expand_custom() was introduced to be used
for example in the topology pre-precessor.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-30 11:33:35 +01:00
Jaroslav Kysela
32d332b786 conf: add safe_strtoll_base() like safe_strtol_base()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-29 15:01:32 +01:00
Jaroslav Kysela
f547b2e35f conf: introduce safe_strtol_base()
It is useful to parse hexadecimal strings, too.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-11-02 10:41:11 +01:00
Jaroslav Kysela
ddfc32abf5 conf: fix load_for_all_cards()
The 63f7745b commit is loading the driver specific configuration
multiple times which ends with the array merges (see the bug).

Introduce the loaded compound which traces the already loaded
driver configurations and skip the multiple load requests.

Fixes: https://github.com/alsa-project/alsa-lib/issues/143
Fixes: 63f7745b ("conf: extend load_for_all_cards hook (id/value table)")
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-06-02 08:49:32 +02:00
Jaroslav Kysela
b623b5dfed conf: snd_config_merge() - substitute non-compound config handles
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-24 12:14:47 +02:00
Jaroslav Kysela
6a944d1b2a conf: snd_config_merge() - merge (concat) correctly arrays
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-24 12:14:45 +02:00
Jaroslav Kysela
e3edbf6e3b conf: return count of items in snd_config_is_array()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-24 09:27:17 +02:00
Jaroslav Kysela
8eaa03b7c9 conf: print quoted string more wisely
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 13:17:13 +02:00
Jaroslav Kysela
0ee4642a69 ucm: cfg-save - allow to save the sub-tree including root keys
The leading '+' in the keys specification add the key prefix
(sub-tree root identification) to the saved configuration.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 12:33:43 +02:00
Jaroslav Kysela
4522e2008f conf: fix snd_config_merge() - merge schema
All child compounds must be traversed and merged.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-18 11:30:15 +02:00
Jaroslav Kysela
ffb401ba22 conf: load the card specific configurations to the config sub-tree
The /var/lib/alsa/card<CARDNO>.conf.d configurations are loaded
to the cards.<CARDNO> tree only (overwrite mode).

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-13 11:04:33 +02:00
Jaroslav Kysela
1aef5a8f8a conf: add snd_config_make_path() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-13 11:02:41 +02:00
Jaroslav Kysela
3050af4b90 conf: add snd_config_is_empty() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-13 10:59:47 +02:00
Jaroslav Kysela
15b59a5647 conf: _snd_config_evaluate - remove 'delete compound members' call
With the recent snd_config_substitute() fix, remove the duplicate
code.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 12:13:31 +02:00
Jaroslav Kysela
8f236983b6 conf: fix snd_config_substitute() - memory leak
There's an issue with the current code: It says append for compounds,
but it does overwrite without the proper members delete from
the overwritten (destination) compound node.

Don't change the behaviour, just fix the comment and memory leak.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 12:09:37 +02:00
Jaroslav Kysela
1a52373fbc conf: fix snd_config_merge() - double free in overwrite mode
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-12 12:08:49 +02:00
Jaroslav Kysela
63f7745be5 conf: extend load_for_all_cards hook (id/value table)
For the per-card configuration, add possibility to define
card number -> card driver link table.

Example:

  cards.0 'cards.USB-Audio'
  cards.1 'cards.USB-Audio'
  cards.2 'cards.HDA-Intel'
  cards.3 'cards.USB-Audio'

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-05-04 20:27:52 +02:00
Jaroslav Kysela
4870358b2f conf: add snd_config_merge() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-13 09:23:06 +02:00
Jaroslav Kysela
619cf45cb9 conf: extend hook load_for_all_cards
Pass also card integer number.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-04-07 16:25:23 +02:00
Takashi Iwai
7bf1dd543b conf: Fix invalid free at parse_args()
The previous fix for memory leaks introduced a few regression.
The major one is the assert hit in the error path reaching with NULL
or uninitialized sub object.  Also, in other code paths, it's possible
that an already released sub object gets freed again.

Fix those bugs by initializing the sub object properly and add a NULL
check before calling snd_config_delete().

Fixes: ad5f255b47 ("conf: fix memory leak on the error path in parse_args()")
Reported-and-tested-by: Mark Hills <mark@xwax.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2021-03-18 17:43:58 +01:00
Jaroslav Kysela
ad5f255b47 conf: fix memory leak on the error path in parse_args()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-11 09:26:07 +01:00
Jaroslav Kysela
8bd9e7897d conf: snd_config_save() - print arrays as [] not the internal representation
The internal represention of an array is:

{
	0 value1
	1 value2
	2 value2
	...
}

which is identicatal to shorter:

[
	value1
	value2
	value3
]

Always print the short format. It's more optimized and readable.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-07 21:02:20 +01:00
Jaroslav Kysela
5766e54fbe conf: improve the tabulator level prints
Do not use per char loop, but compose a string.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2021-03-07 20:57:28 +01:00
Jaroslav Kysela
6c24cd2e60 conf: fix return code in _snd_config_load_with_include
Fixes: 5275d170e0 ("conf: fix use after free in _snd_config_load_with_include")
BugLink: https://github.com/alsa-project/alsa-lib/issues/108
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-12-29 11:17:58 +01:00
Jaroslav Kysela
9ebd29d2d3 conf: fix get_hexachar() return value
Reported-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-12-27 13:17:48 +01:00
Alex Henrie
5275d170e0 conf: fix use after free in _snd_config_load_with_include
Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-12-27 09:20:38 +01:00
Jaroslav Kysela
ed75249852 conf: quote also strings with '*' and '#' characters in string_print()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-08-18 16:53:35 +02:00
Jaroslav Kysela
409cea0759 conf: remove debug printf() in snd_config_hook_load()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-05 13:12:15 +02:00
Jaroslav Kysela
1fa7d670f8 conf: load function (hook) - add OR support
While I was trying to work on XDG_CONFIG_HOME support, I though
that it may be nice to support OR for the file specification.

But then I found that we can already do this via the refer hook.

I commit this change anyway, because the snd_config_hook_load()
function is more clean now.

The OR is implemented with three | characters like:

  "~/.asoundrc|||~/.asoundrc2|||/opt/some/other/path"

(first file found wins)

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-06-04 17:32:47 +02:00
Jaroslav Kysela
0c99c073d3 conf: add snd_config_is_array() function
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-08 12:00:42 +02:00
Jaroslav Kysela
05a6effd8d conf: use bool type for the join member in the config structure
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-05-08 11:23:38 +02:00
Bertware
a78dd1bd1e Quote strings containing [ or ] when saving an alsa config
Signed-off-by: Bert Marcelis <bert.marcelis@outlook.com>
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-13 14:24:28 +01:00
Jaroslav Kysela
aa1bac2d04 topology: add snd_tplg_save()
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2020-01-03 23:38:08 +01:00
Jaroslav Kysela
9980e18c3c alsa-lib: fix the array parser (unique compound keys)
The code from the old import may merge arrays wrongly and
the result is a compound with same keys like:

Input:

        lines [
                "SSP0.OUT, , BUF1.3"
        ]
        lines [
                "BUF2.0, , SSP0.IN"
        ]

Parsed contents:

        lines {
                0 'SSP0.OUT, , BUF1.3'
                0 'BUF2.0, , SSP0.IN'
        }

Proper parsed contents (create+merge mode):

        lines {
                0 'SSP0.OUT, , BUF1.3'
                1 'BUF2.0, , SSP0.IN'
        }

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-12-12 18:44:35 +01:00
Jaroslav Kysela
c28618353b conf: check for include path duplicates
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-19 10:55:29 +01:00
Jaroslav Kysela
39fda8a69a conf: fix the include paths support
I omitted to use parent paths and the proper error code
when no paths are defined.

Fixes: f600310954 ("conf: improve the include paths code")

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
2019-11-18 19:03:06 +01:00