mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-01 22:58:50 -04:00
tree-wide: replace strstr(a, b) == a with spa_strstartswith()
spa_strstartswith() is more immediately understandable. Coccinelle spatch file: @@ expression E1, E2; @@ - strstr(E1, E2) != E1 + !spa_strstartswith(E1, E2) @@ expression E1, E2; @@ - strstr(E1, E2) == E1 + spa_strstartswith(E1, E2) Applied to the tree except for alsa/acp/compat.h because it looks like that header is still mostly as-is from PA.
This commit is contained in:
parent
60c510d766
commit
51a177eb6d
20 changed files with 48 additions and 48 deletions
|
|
@ -2534,7 +2534,7 @@ static void registry_event_global(void *data, uint32_t id,
|
|||
node_id = atoi(str);
|
||||
|
||||
if ((str = spa_dict_lookup(props, PW_KEY_PORT_EXTRA)) != NULL &&
|
||||
strstr(str, "jack:flags:") == str)
|
||||
spa_strstartswith(str, "jack:flags:"))
|
||||
flags = atoi(str+11);
|
||||
|
||||
if ((str = spa_dict_lookup(props, PW_KEY_PORT_NAME)) == NULL)
|
||||
|
|
|
|||
|
|
@ -412,9 +412,9 @@ static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint)
|
|||
const char *codec_name;
|
||||
int i;
|
||||
|
||||
if (strstr(endpoint, A2DP_SINK_ENDPOINT "/") == endpoint)
|
||||
if (spa_strstartswith(endpoint, A2DP_SINK_ENDPOINT "/"))
|
||||
codec_name = endpoint + strlen(A2DP_SINK_ENDPOINT "/");
|
||||
else if (strstr(endpoint, A2DP_SOURCE_ENDPOINT "/") == endpoint)
|
||||
else if (spa_strstartswith(endpoint, A2DP_SOURCE_ENDPOINT "/"))
|
||||
codec_name = endpoint + strlen(A2DP_SOURCE_ENDPOINT "/");
|
||||
else
|
||||
return NULL;
|
||||
|
|
@ -430,9 +430,9 @@ static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint)
|
|||
static int a2dp_endpoint_to_profile(const char *endpoint)
|
||||
{
|
||||
|
||||
if (strstr(endpoint, A2DP_SINK_ENDPOINT "/") == endpoint)
|
||||
if (spa_strstartswith(endpoint, A2DP_SINK_ENDPOINT "/"))
|
||||
return SPA_BT_PROFILE_A2DP_SOURCE;
|
||||
else if (strstr(endpoint, A2DP_SOURCE_ENDPOINT "/") == endpoint)
|
||||
else if (spa_strstartswith(endpoint, A2DP_SOURCE_ENDPOINT "/"))
|
||||
return SPA_BT_PROFILE_A2DP_SINK;
|
||||
else
|
||||
return SPA_BT_PROFILE_NULL;
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ impl_cpu_get_vm_type(void *object)
|
|||
continue;
|
||||
|
||||
for (j = 0; j < SPA_N_ELEMENTS(dmi_vendor_table); j++) {
|
||||
if (strstr(s, dmi_vendor_table[j].vendor) == s) {
|
||||
if (spa_strstartswith(s, dmi_vendor_table[j].vendor)) {
|
||||
spa_log_debug(impl->log, "Virtualization %s found in DMI (%s)",
|
||||
s, dmi_vendors[i]);
|
||||
impl->vm_type = dmi_vendor_table[j].id;
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
|
|||
|
||||
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
|
||||
|
||||
if (strstr(media_class, "Audio/") != media_class)
|
||||
if (!spa_strstartswith(media_class, "Audio/"))
|
||||
return 0;
|
||||
if (!spa_streq(str, "alsa"))
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -321,9 +321,9 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
|||
priority -= atol(dev) * 16;
|
||||
priority -= atol(subdev);
|
||||
|
||||
if (strstr(profile, "analog-") == profile)
|
||||
if (spa_strstartswith(profile, "analog-"))
|
||||
priority += 9;
|
||||
else if (strstr(profile, "iec958-") == profile)
|
||||
else if (spa_strstartswith(profile, "iec958-"))
|
||||
priority += 8;
|
||||
|
||||
if (pw_properties_get(node->props, PW_KEY_PRIORITY_DRIVER) == NULL) {
|
||||
|
|
@ -356,7 +356,7 @@ static struct node *alsa_create_node(struct device *device, uint32_t id,
|
|||
|
||||
if ((devname = pw_properties_get(device->props, SPA_KEY_DEVICE_NAME)) == NULL)
|
||||
devname = "unnamed-device";
|
||||
if (strstr(devname, "alsa_card.") == devname)
|
||||
if (spa_strstartswith(devname, "alsa_card."))
|
||||
devname += 10;
|
||||
|
||||
pw_properties_set(node->props, SPA_KEY_NODE_NAME,
|
||||
|
|
|
|||
|
|
@ -616,7 +616,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
|
|||
|
||||
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
|
||||
|
||||
if (strstr(media_class, "Audio/") != media_class)
|
||||
if (!spa_strstartswith(media_class, "Audio/"))
|
||||
return 0;
|
||||
if (!spa_streq(str, "bluez5"))
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -405,7 +405,7 @@ static int update_device_props(struct device *device)
|
|||
snprintf(temp, sizeof(temp), "%d", device->id);
|
||||
s = temp;
|
||||
}
|
||||
if (strstr(s, "bluez_card.") == s)
|
||||
if (spa_strstartswith(s, "bluez_card."))
|
||||
s += strlen("bluez_card.");
|
||||
|
||||
pw_properties_set(p, PW_KEY_DEVICE_NAME,
|
||||
|
|
|
|||
|
|
@ -130,14 +130,14 @@ handle_endpoint(struct impl *impl, struct sm_object *object)
|
|||
ep->enabled = true;
|
||||
spa_list_append(&impl->endpoint_list, &ep->link);
|
||||
|
||||
if (strstr(media_class, "Stream/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Stream/")) {
|
||||
media_class += strlen("Stream/");
|
||||
|
||||
if (strstr(media_class, "Output/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Output/")) {
|
||||
direction = PW_DIRECTION_OUTPUT;
|
||||
media_class += strlen("Output/");
|
||||
}
|
||||
else if (strstr(media_class, "Input/") == media_class) {
|
||||
else if (spa_strstartswith(media_class, "Input/")) {
|
||||
direction = PW_DIRECTION_INPUT;
|
||||
media_class += strlen("Input/");
|
||||
}
|
||||
|
|
@ -151,11 +151,11 @@ handle_endpoint(struct impl *impl, struct sm_object *object)
|
|||
}
|
||||
else {
|
||||
const char *media;
|
||||
if (strstr(media_class, "Audio/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Audio/")) {
|
||||
media_class += strlen("Audio/");
|
||||
media = "Audio";
|
||||
}
|
||||
else if (strstr(media_class, "Video/") == media_class) {
|
||||
else if (spa_strstartswith(media_class, "Video/")) {
|
||||
media_class += strlen("Video/");
|
||||
media = "Video";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,21 +294,21 @@ handle_node(struct impl *impl, struct sm_object *object)
|
|||
if (role && spa_streq(role, "DSP"))
|
||||
node->active = node->configured = true;
|
||||
|
||||
if (strstr(media_class, "Stream/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Stream/")) {
|
||||
media_class += strlen("Stream/");
|
||||
|
||||
if (strstr(media_class, "Output/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Output/")) {
|
||||
direction = PW_DIRECTION_OUTPUT;
|
||||
media_class += strlen("Output/");
|
||||
}
|
||||
else if (strstr(media_class, "Input/") == media_class) {
|
||||
else if (spa_strstartswith(media_class, "Input/")) {
|
||||
direction = PW_DIRECTION_INPUT;
|
||||
media_class += strlen("Input/");
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
||||
if (strstr(media_class, "Video") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Video")) {
|
||||
if (direction == PW_DIRECTION_OUTPUT) {
|
||||
if ((str = pw_properties_get(object->props, PW_KEY_NODE_PLUGGED)) != NULL)
|
||||
node->plugged = pw_properties_parse_uint64(str);
|
||||
|
|
@ -317,7 +317,7 @@ handle_node(struct impl *impl, struct sm_object *object)
|
|||
}
|
||||
node->active = node->configured = true;
|
||||
}
|
||||
else if (strstr(media_class, "Unknown") == media_class) {
|
||||
else if (spa_strstartswith(media_class, "Unknown")) {
|
||||
node->active = node->configured = true;
|
||||
}
|
||||
|
||||
|
|
@ -330,11 +330,11 @@ handle_node(struct impl *impl, struct sm_object *object)
|
|||
const char *media;
|
||||
bool virtual = false;
|
||||
|
||||
if (strstr(media_class, "Audio/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Audio/")) {
|
||||
media_class += strlen("Audio/");
|
||||
media = "Audio";
|
||||
}
|
||||
else if (strstr(media_class, "Video/") == media_class) {
|
||||
else if (spa_strstartswith(media_class, "Video/")) {
|
||||
media_class += strlen("Video/");
|
||||
media = "Video";
|
||||
node->active = node->configured = true;
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ static int metadata_property(void *object, uint32_t subject,
|
|||
pw_properties_clear(impl->props);
|
||||
changed = 1;
|
||||
}
|
||||
else if (strstr(key, PREFIX) == key) {
|
||||
else if (spa_strstartswith(key, PREFIX)) {
|
||||
changed += pw_properties_set(impl->props, key, value);
|
||||
}
|
||||
}
|
||||
|
|
@ -472,10 +472,10 @@ static void session_create(void *data, struct sm_object *object)
|
|||
(media_class = pw_properties_get(object->props, PW_KEY_MEDIA_CLASS)) == NULL)
|
||||
return;
|
||||
|
||||
if (strstr(media_class, "Stream/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Stream/")) {
|
||||
media_class += strlen("Stream/");
|
||||
pw_log_debug(NAME " %p: add stream '%d' %s", impl, object->id, media_class);
|
||||
} else if (strstr(media_class, "Audio/") == media_class &&
|
||||
} else if (spa_strstartswith(media_class, "Audio/") &&
|
||||
((routes = pw_properties_get(object->props, "device.routes")) == NULL ||
|
||||
atoi(routes) == 0)) {
|
||||
pw_log_debug(NAME " %p: add node '%d' %s", impl, object->id, media_class);
|
||||
|
|
|
|||
|
|
@ -516,16 +516,16 @@ handle_node(struct impl *impl, struct sm_object *obj)
|
|||
if (media_class == NULL)
|
||||
return 0;
|
||||
|
||||
if (strstr(media_class, "Stream/") != media_class)
|
||||
if (!spa_strstartswith(media_class, "Stream/"))
|
||||
return 0;
|
||||
|
||||
media_class += strlen("Stream/");
|
||||
|
||||
if (strstr(media_class, "Output/") == media_class) {
|
||||
if (spa_strstartswith(media_class, "Output/")) {
|
||||
direction = PW_DIRECTION_OUTPUT;
|
||||
media_class += strlen("Output/");
|
||||
}
|
||||
else if (strstr(media_class, "Input/") == media_class) {
|
||||
else if (spa_strstartswith(media_class, "Input/")) {
|
||||
direction = PW_DIRECTION_INPUT;
|
||||
media_class += strlen("Input/");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,8 +178,8 @@ handle_node(struct impl *impl, struct sm_object *object)
|
|||
if (media_class == NULL)
|
||||
return 0;
|
||||
|
||||
if (strstr(media_class, "Audio/") != media_class &&
|
||||
(strstr(media_class, "Video/") != media_class))
|
||||
if (!spa_strstartswith(media_class, "Audio/") &&
|
||||
(!spa_strstartswith(media_class, "Video/")))
|
||||
return 0;
|
||||
|
||||
node = sm_object_add_data(object, SESSION_KEY, sizeof(struct node));
|
||||
|
|
|
|||
|
|
@ -563,7 +563,7 @@ handle_device(struct impl *impl, struct sm_object *obj)
|
|||
|
||||
pw_log_debug(NAME" %p: device "PW_KEY_MEDIA_CLASS":%s api:%s", impl, media_class, str);
|
||||
|
||||
if (strstr(media_class, "Video/") != media_class)
|
||||
if (!spa_strstartswith(media_class, "Video/"))
|
||||
return 0;
|
||||
if (!spa_streq(str, "v4l2"))
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ static struct node *v4l2_create_node(struct device *dev, uint32_t id,
|
|||
str = pw_properties_get(dev->props, SPA_KEY_DEVICE_ALIAS);
|
||||
if (str == NULL)
|
||||
str = "v4l2-device";
|
||||
if (strstr(str, "v4l2_device.") == str)
|
||||
if (spa_strstartswith(str, "v4l2_device."))
|
||||
str += 12;
|
||||
|
||||
if (strstr(info->factory_name, "sink") != NULL)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_it
|
|||
const char *str;
|
||||
spa_pod_builder_string(b, item->key);
|
||||
str = item->value;
|
||||
if (strstr(str, "pointer:") == str)
|
||||
if (spa_strstartswith(str, "pointer:"))
|
||||
str = "";
|
||||
spa_pod_builder_string(b, str);
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *i
|
|||
SPA_POD_String(&item->value),
|
||||
NULL)) < 0)
|
||||
return res;
|
||||
if (strstr(item->value, "pointer:") == item->value)
|
||||
if (spa_strstartswith(item->value, "pointer:"))
|
||||
item->value = "";
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_it
|
|||
const char *str;
|
||||
spa_pod_builder_string(b, item->key);
|
||||
str = item->value;
|
||||
if (strstr(str, "pointer:") == str)
|
||||
if (spa_strstartswith(str, "pointer:"))
|
||||
str = "";
|
||||
spa_pod_builder_string(b, str);
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *i
|
|||
SPA_POD_String(&item->value),
|
||||
NULL)) < 0)
|
||||
return res;
|
||||
if (strstr(item->value, "pointer:") == item->value)
|
||||
if (spa_strstartswith(item->value, "pointer:"))
|
||||
item->value = "";
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ static inline void push_item(struct spa_pod_builder *b, const struct spa_dict_it
|
|||
const char *str;
|
||||
spa_pod_builder_string(b, item->key);
|
||||
str = item->value;
|
||||
if (strstr(str, "pointer:") == str)
|
||||
if (spa_strstartswith(str, "pointer:"))
|
||||
str = "";
|
||||
spa_pod_builder_string(b, str);
|
||||
}
|
||||
|
|
@ -159,7 +159,7 @@ static inline int parse_item(struct spa_pod_parser *prs, struct spa_dict_item *i
|
|||
SPA_POD_String(&item->value),
|
||||
NULL)) < 0)
|
||||
return res;
|
||||
if (strstr(item->value, "pointer:") == item->value)
|
||||
if (spa_strstartswith(item->value, "pointer:"))
|
||||
item->value = "";
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,9 +63,9 @@ static int key_from_name(const char *name, char *key, size_t maxlen)
|
|||
{
|
||||
const char *media_class, *select, *str;
|
||||
|
||||
if (strstr(name, "sink-input-") == name)
|
||||
if (spa_strstartswith(name, "sink-input-"))
|
||||
media_class = "Output/Audio";
|
||||
else if (strstr(name, "source-output-") == name)
|
||||
else if (spa_strstartswith(name, "source-output-"))
|
||||
media_class = "Input/Audio";
|
||||
else
|
||||
return -1;
|
||||
|
|
@ -100,9 +100,9 @@ static int key_to_name(const char *key, char *name, size_t maxlen)
|
|||
{
|
||||
const char *type, *select, *str;
|
||||
|
||||
if (strstr(key, "restore.stream.Output/Audio.") == key)
|
||||
if (spa_strstartswith(key, "restore.stream.Output/Audio."))
|
||||
type = "sink-input";
|
||||
else if (strstr(key, "restore.stream.Input/Audio.") == key)
|
||||
else if (spa_strstartswith(key, "restore.stream.Input/Audio."))
|
||||
type = "source-output";
|
||||
else
|
||||
type = "stream";
|
||||
|
|
|
|||
|
|
@ -634,7 +634,7 @@ static struct server *create_server(struct impl *impl, const char *address)
|
|||
spa_list_init(&server->client_list);
|
||||
spa_list_append(&impl->server_list, &server->link);
|
||||
|
||||
if (strstr(address, "tcp:") == address) {
|
||||
if (spa_strstartswith(address, "tcp:")) {
|
||||
fd = make_inet_socket(server, address+4);
|
||||
} else {
|
||||
fd = -EINVAL;
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ static int update_properties(struct pw_impl_client *client, const struct spa_dic
|
|||
|
||||
for (i = 0; i < dict->n_items; i++) {
|
||||
if (filter) {
|
||||
if (strstr(dict->items[i].key, "pipewire.") == dict->items[i].key &&
|
||||
if (spa_strstartswith(dict->items[i].key, "pipewire.") &&
|
||||
(old = pw_properties_get(client->properties, dict->items[i].key)) != NULL &&
|
||||
(dict->items[i].value == NULL || !spa_streq(old, dict->items[i].value))) {
|
||||
pw_log_warn(NAME" %p: refuse property update '%s' from '%s' to '%s'",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue