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:
Peter Hutterer 2021-08-02 14:05:45 +10:00 committed by Wim Taymans
parent 60c510d766
commit 51a177eb6d
20 changed files with 48 additions and 48 deletions

View file

@ -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;

View file

@ -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,

View file

@ -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;

View file

@ -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,

View file

@ -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";
}

View file

@ -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;

View file

@ -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,12 +472,12 @@ 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 &&
((routes = pw_properties_get(object->props, "device.routes")) == NULL ||
atoi(routes) == 0)) {
} 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);
} else {
return;

View file

@ -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/");
}

View file

@ -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));

View file

@ -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;

View file

@ -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)

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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";

View file

@ -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;

View file

@ -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'",