spa: add spa_strendswith (copy from protocol-pulse)

Useful function, let's make it generally available.
This commit is contained in:
Peter Hutterer 2021-06-21 15:04:15 +10:00 committed by Wim Taymans
parent 71d39e90ed
commit 0880ff9a84
7 changed files with 50 additions and 15 deletions

View file

@ -197,14 +197,6 @@ static inline int node_state(enum pw_node_state state)
return STATE_INVALID;
}
static inline bool pw_endswith(const char *s, const char *sfx)
{
size_t l1, l2;
l1 = strlen(s);
l2 = strlen(sfx);
return l1 >= l2 && strcmp(s + l1 - l2, sfx) == 0;
}
enum {
SINK_HW_VOLUME_CTRL = 0x0001U,
SINK_LATENCY = 0x0002U,

View file

@ -190,7 +190,7 @@ struct module *create_module_echo_cancel(struct impl *impl, const char *argument
}
if ((str = pw_properties_get(props, "source_master")) != NULL) {
if (pw_endswith(str, ".monitor")) {
if (spa_strendswith(str, ".monitor")) {
pw_properties_setf(source_props, PW_KEY_NODE_TARGET,
"%.*s", (int)strlen(str)-8, str);
} else {

View file

@ -157,7 +157,7 @@ struct module *create_module_loopback(struct impl *impl, const char *argument)
*/
if ((str = pw_properties_get(props, "source")) != NULL) {
if (pw_endswith(str, ".monitor")) {
if (spa_strendswith(str, ".monitor")) {
pw_properties_setf(capture_props, PW_KEY_NODE_TARGET,
"%.*s", (int)strlen(str)-8, str);
} else {

View file

@ -171,7 +171,7 @@ struct module *create_module_simple_protocol_tcp(struct impl *impl, const char *
}
if ((str = pw_properties_get(props, "source")) != NULL) {
if (pw_endswith(str, ".monitor")) {
if (spa_strendswith(str, ".monitor")) {
pw_properties_setf(module_props, "capture.node",
"%.*s", (int)strlen(str)-8, str);
} else {

View file

@ -1726,7 +1726,7 @@ static int do_create_record_stream(struct client *client, uint32_t command, uint
pw_properties_setf(props,
PW_KEY_NODE_TARGET, "%u", source_index);
} else if (source_name != NULL) {
if (pw_endswith(source_name, ".monitor")) {
if (spa_strendswith(source_name, ".monitor")) {
pw_properties_setf(props,
PW_KEY_NODE_TARGET,
"%.*s", (int)strlen(source_name)-8, source_name);
@ -2125,7 +2125,7 @@ static struct pw_manager_object *find_device(struct client *client,
id = SPA_ID_INVALID;
if (name != NULL && !sink) {
if (pw_endswith(name, ".monitor")) {
if (spa_strendswith(name, ".monitor")) {
name = strndupa(name, strlen(name)-8);
monitor = true;
} else if (spa_streq(name, DEFAULT_MONITOR)) {
@ -3903,7 +3903,7 @@ static int do_get_info(struct client *client, uint32_t command, uint32_t tag, st
}
if (command == COMMAND_GET_SOURCE_INFO &&
sel.value != NULL && pw_endswith(sel.value, ".monitor")) {
sel.value != NULL && spa_strendswith(sel.value, ".monitor")) {
sel.value = strndupa(sel.value, strlen(sel.value)-8);
}
@ -4314,7 +4314,7 @@ static int do_set_default(struct client *client, uint32_t command, uint32_t tag,
if (name != NULL) {
if (o->props && (str = pw_properties_get(o->props, PW_KEY_NODE_NAME)) != NULL)
name = str;
else if (pw_endswith(name, ".monitor"))
else if (spa_strendswith(name, ".monitor"))
name = strndupa(name, strlen(name)-8);
res = pw_manager_set_metadata(manager, client->metadata_default,