treewide: replace strcmp() == 0 with spa_streq()

This change is only done in source files for now, header files will be done
separately.
This commit is contained in:
Peter Hutterer 2021-05-18 11:36:13 +10:00
parent d8a9534a9a
commit 7697ed0757
130 changed files with 817 additions and 675 deletions

View file

@ -46,6 +46,7 @@
#include <spa/utils/keys.h>
#include <spa/utils/names.h>
#include <spa/utils/result.h>
#include <spa/utils/string.h>
#include <spa/utils/json.h>
#include "a2dp-codecs.h"
@ -413,7 +414,7 @@ static const struct a2dp_codec *a2dp_endpoint_to_codec(const char *endpoint)
for (i = 0; a2dp_codecs[i]; i++) {
const struct a2dp_codec *codec = a2dp_codecs[i];
if (strcmp(codec->name, codec_name) == 0)
if (spa_streq(codec->name, codec_name))
return codec;
}
return NULL;
@ -433,7 +434,7 @@ static int a2dp_endpoint_to_profile(const char *endpoint)
static bool is_a2dp_codec_enabled(struct spa_bt_monitor *monitor, const struct a2dp_codec *codec)
{
if (!monitor->enable_sbc_xq && codec->feature_flag != NULL &&
strcmp(codec->feature_flag, "sbc-xq") == 0)
spa_streq(codec->feature_flag, "sbc-xq"))
return false;
return spa_dict_lookup(&monitor->enabled_codecs, codec->name) != NULL;
@ -505,7 +506,7 @@ static struct spa_bt_adapter *adapter_find(struct spa_bt_monitor *monitor, const
{
struct spa_bt_adapter *d;
spa_list_for_each(d, &monitor->adapter_list, link)
if (strcmp(d->path, path) == 0)
if (spa_streq(d->path, path))
return d;
return NULL;
}
@ -545,15 +546,15 @@ static int adapter_update_props(struct spa_bt_adapter *adapter,
spa_log_debug(monitor->log, "adapter %p: %s=%s", adapter, key, value);
if (strcmp(key, "Alias") == 0) {
if (spa_streq(key, "Alias")) {
free(adapter->alias);
adapter->alias = strdup(value);
}
else if (strcmp(key, "Name") == 0) {
else if (spa_streq(key, "Name")) {
free(adapter->name);
adapter->name = strdup(value);
}
else if (strcmp(key, "Address") == 0) {
else if (spa_streq(key, "Address")) {
free(adapter->address);
adapter->address = strdup(value);
}
@ -565,7 +566,7 @@ static int adapter_update_props(struct spa_bt_adapter *adapter,
spa_log_debug(monitor->log, "adapter %p: %s=%d", adapter, key, value);
if (strcmp(key, "Class") == 0)
if (spa_streq(key, "Class"))
adapter->bluetooth_class = value;
}
@ -576,11 +577,11 @@ static int adapter_update_props(struct spa_bt_adapter *adapter,
spa_log_debug(monitor->log, "adapter %p: %s=%d", adapter, key, value);
if (strcmp(key, "Powered") == 0) {
if (spa_streq(key, "Powered")) {
adapter->powered = value;
}
}
else if (strcmp(key, "UUIDs") == 0) {
else if (spa_streq(key, "UUIDs")) {
DBusMessageIter iter;
if (!check_iter_signature(&it[1], "as"))
@ -645,7 +646,7 @@ struct spa_bt_device *spa_bt_device_find(struct spa_bt_monitor *monitor, const c
{
struct spa_bt_device *d;
spa_list_for_each(d, &monitor->device_list, link)
if (strcmp(d->path, path) == 0)
if (spa_streq(d->path, path))
return d;
return NULL;
}
@ -654,7 +655,7 @@ struct spa_bt_device *spa_bt_device_find_by_address(struct spa_bt_monitor *monit
{
struct spa_bt_device *d;
spa_list_for_each(d, &monitor->device_list, link)
if (strcmp(d->address, remote_address) == 0 && strcmp(d->adapter->address, local_address) == 0)
if (spa_streq(d->address, remote_address) && spa_streq(d->adapter->address, local_address))
return d;
return NULL;
}
@ -1107,19 +1108,19 @@ static int device_update_props(struct spa_bt_device *device,
spa_log_debug(monitor->log, "device %p: %s=%s", device, key, value);
if (strcmp(key, "Alias") == 0) {
if (spa_streq(key, "Alias")) {
free(device->alias);
device->alias = strdup(value);
}
else if (strcmp(key, "Name") == 0) {
else if (spa_streq(key, "Name")) {
free(device->name);
device->name = strdup(value);
}
else if (strcmp(key, "Address") == 0) {
else if (spa_streq(key, "Address")) {
free(device->address);
device->address = strdup(value);
}
else if (strcmp(key, "Adapter") == 0) {
else if (spa_streq(key, "Adapter")) {
free(device->adapter_path);
device->adapter_path = strdup(value);
@ -1128,7 +1129,7 @@ static int device_update_props(struct spa_bt_device *device,
spa_log_warn(monitor->log, "unknown adapter %s", value);
}
}
else if (strcmp(key, "Icon") == 0) {
else if (spa_streq(key, "Icon")) {
free(device->icon);
device->icon = strdup(value);
}
@ -1140,7 +1141,7 @@ static int device_update_props(struct spa_bt_device *device,
spa_log_debug(monitor->log, "device %p: %s=%08x", device, key, value);
if (strcmp(key, "Class") == 0)
if (spa_streq(key, "Class"))
device->bluetooth_class = value;
}
else if (type == DBUS_TYPE_UINT16) {
@ -1150,7 +1151,7 @@ static int device_update_props(struct spa_bt_device *device,
spa_log_debug(monitor->log, "device %p: %s=%d", device, key, value);
if (strcmp(key, "Appearance") == 0)
if (spa_streq(key, "Appearance"))
device->appearance = value;
}
else if (type == DBUS_TYPE_INT16) {
@ -1160,7 +1161,7 @@ static int device_update_props(struct spa_bt_device *device,
spa_log_debug(monitor->log, "device %p: %s=%d", device, key, value);
if (strcmp(key, "RSSI") == 0)
if (spa_streq(key, "RSSI"))
device->RSSI = value;
}
else if (type == DBUS_TYPE_BOOLEAN) {
@ -1170,24 +1171,24 @@ static int device_update_props(struct spa_bt_device *device,
spa_log_debug(monitor->log, "device %p: %s=%d", device, key, value);
if (strcmp(key, "Paired") == 0) {
if (spa_streq(key, "Paired")) {
device->paired = value;
}
else if (strcmp(key, "Trusted") == 0) {
else if (spa_streq(key, "Trusted")) {
device->trusted = value;
}
else if (strcmp(key, "Connected") == 0) {
else if (spa_streq(key, "Connected")) {
device_set_connected(device, value);
}
else if (strcmp(key, "Blocked") == 0) {
else if (spa_streq(key, "Blocked")) {
device->blocked = value;
}
else if (strcmp(key, "ServicesResolved") == 0) {
else if (spa_streq(key, "ServicesResolved")) {
if (value)
spa_bt_device_check_profiles(device, false);
}
}
else if (strcmp(key, "UUIDs") == 0) {
else if (spa_streq(key, "UUIDs")) {
DBusMessageIter iter;
uint32_t prev_profiles = device->profiles;
@ -1232,7 +1233,7 @@ bool spa_bt_device_supports_a2dp_codec(struct spa_bt_device *device, const struc
if (!device->adapter->application_registered) {
/* Codec switching not supported: only plain SBC allowed */
return (codec->codec_id == A2DP_CODEC_SBC && strcmp(codec->name, "sbc") == 0);
return (codec->codec_id == A2DP_CODEC_SBC && spa_streq(codec->name, "sbc"));
}
spa_list_for_each(ep, &device->remote_endpoint_list, device_link) {
@ -1285,7 +1286,7 @@ static struct spa_bt_remote_endpoint *device_remote_endpoint_find(struct spa_bt_
{
struct spa_bt_remote_endpoint *ep;
spa_list_for_each(ep, &device->remote_endpoint_list, device_link)
if (strcmp(ep->path, path) == 0)
if (spa_streq(ep->path, path))
return ep;
return NULL;
}
@ -1294,7 +1295,7 @@ static struct spa_bt_remote_endpoint *remote_endpoint_find(struct spa_bt_monitor
{
struct spa_bt_remote_endpoint *ep;
spa_list_for_each(ep, &monitor->remote_endpoint_list, link)
if (strcmp(ep->path, path) == 0)
if (spa_streq(ep->path, path))
return ep;
return NULL;
}
@ -1324,11 +1325,11 @@ static int remote_endpoint_update_props(struct spa_bt_remote_endpoint *remote_en
spa_log_debug(monitor->log, "remote_endpoint %p: %s=%s", remote_endpoint, key, value);
if (strcmp(key, "UUID") == 0) {
if (spa_streq(key, "UUID")) {
free(remote_endpoint->uuid);
remote_endpoint->uuid = strdup(value);
}
else if (strcmp(key, "Device") == 0) {
else if (spa_streq(key, "Device")) {
struct spa_bt_device *device;
device = spa_bt_device_find(monitor, value);
if (device == NULL)
@ -1351,7 +1352,7 @@ static int remote_endpoint_update_props(struct spa_bt_remote_endpoint *remote_en
spa_log_debug(monitor->log, "remote_endpoint %p: %s=%d", remote_endpoint, key, value);
if (strcmp(key, "DelayReporting") == 0) {
if (spa_streq(key, "DelayReporting")) {
remote_endpoint->delay_reporting = value;
}
}
@ -1362,11 +1363,11 @@ static int remote_endpoint_update_props(struct spa_bt_remote_endpoint *remote_en
spa_log_debug(monitor->log, "remote_endpoint %p: %s=%02x", remote_endpoint, key, value);
if (strcmp(key, "Codec") == 0) {
if (spa_streq(key, "Codec")) {
remote_endpoint->codec = value;
}
}
else if (strcmp(key, "Capabilities") == 0) {
else if (spa_streq(key, "Capabilities")) {
DBusMessageIter iter;
uint8_t *value;
int i, len;
@ -1436,7 +1437,7 @@ struct spa_bt_transport *spa_bt_transport_find(struct spa_bt_monitor *monitor, c
{
struct spa_bt_transport *t;
spa_list_for_each(t, &monitor->transport_list, link)
if (strcmp(t->path, path) == 0)
if (spa_streq(t->path, path))
return t;
return NULL;
}
@ -1816,7 +1817,7 @@ static int transport_update_props(struct spa_bt_transport *transport,
spa_log_debug(monitor->log, "transport %p: %s=%s", transport, key, value);
if (strcmp(key, "UUID") == 0) {
if (spa_streq(key, "UUID")) {
switch (spa_bt_profile_from_uuid(value)) {
case SPA_BT_PROFILE_A2DP_SOURCE:
transport->profile = SPA_BT_PROFILE_A2DP_SINK;
@ -1829,16 +1830,16 @@ static int transport_update_props(struct spa_bt_transport *transport,
break;
}
}
else if (strcmp(key, "State") == 0) {
else if (spa_streq(key, "State")) {
spa_bt_transport_set_state(transport, spa_bt_transport_state_from_string(value));
}
else if (strcmp(key, "Device") == 0) {
else if (spa_streq(key, "Device")) {
transport->device = spa_bt_device_find(monitor, value);
if (transport->device == NULL)
spa_log_warn(monitor->log, "could not find device %s", value);
}
}
else if (strcmp(key, "Codec") == 0) {
else if (spa_streq(key, "Codec")) {
uint8_t value;
if (type != DBUS_TYPE_BYTE)
@ -1849,7 +1850,7 @@ static int transport_update_props(struct spa_bt_transport *transport,
transport->codec = value;
}
else if (strcmp(key, "Configuration") == 0) {
else if (spa_streq(key, "Configuration")) {
DBusMessageIter iter;
uint8_t *value;
int i, len;
@ -1873,7 +1874,7 @@ static int transport_update_props(struct spa_bt_transport *transport,
transport->configuration_len = len;
}
}
else if (strcmp(key, "Volume") == 0) {
else if (spa_streq(key, "Volume")) {
uint16_t value;
struct spa_bt_transport_volume * t_volume;
@ -1898,7 +1899,7 @@ static int transport_update_props(struct spa_bt_transport *transport,
else
spa_bt_transport_volume_changed(transport);
}
else if (strcmp(key, "Delay") == 0) {
else if (spa_streq(key, "Delay")) {
uint16_t value;
if (type != DBUS_TYPE_UINT16)
@ -2011,7 +2012,7 @@ static int transport_acquire(void *data, bool optional)
m = NULL;
if (r == NULL) {
if (optional && strcmp(err.name, "org.bluez.Error.NotAvailable") == 0) {
if (optional && spa_streq(err.name, "org.bluez.Error.NotAvailable")) {
spa_log_info(monitor->log, "Failed optional acquire of unavailable transport %s",
transport->path);
}
@ -2851,7 +2852,7 @@ static int adapter_register_endpoints(struct spa_bt_adapter *a)
if (!is_a2dp_codec_enabled(monitor, codec))
continue;
if (!(codec->codec_id == A2DP_CODEC_SBC && strcmp(codec->name, "sbc") == 0))
if (!(codec->codec_id == A2DP_CODEC_SBC && spa_streq(codec->name, "sbc")))
continue;
if ((err = bluez_register_endpoint(monitor, a->path,
@ -3125,7 +3126,7 @@ static void interface_added(struct spa_bt_monitor *monitor,
{
spa_log_debug(monitor->log, "Found object %s, interface %s", object_path, interface_name);
if (strcmp(interface_name, BLUEZ_ADAPTER_INTERFACE) == 0) {
if (spa_streq(interface_name, BLUEZ_ADAPTER_INTERFACE)) {
struct spa_bt_adapter *a;
a = adapter_find(monitor, object_path);
@ -3139,13 +3140,13 @@ static void interface_added(struct spa_bt_monitor *monitor,
adapter_update_props(a, props_iter, NULL);
adapter_register_application(a);
}
else if (strcmp(interface_name, BLUEZ_PROFILE_MANAGER_INTERFACE) == 0) {
else if (spa_streq(interface_name, BLUEZ_PROFILE_MANAGER_INTERFACE)) {
if (!monitor->backend_ofono_registered && !monitor->backend_hsphfpd_registered) {
spa_bt_backend_register_profiles(monitor->backend_native);
monitor->backend_native_registered = true;
}
}
else if (strcmp(interface_name, BLUEZ_DEVICE_INTERFACE) == 0) {
else if (spa_streq(interface_name, BLUEZ_DEVICE_INTERFACE)) {
struct spa_bt_device *d;
d = spa_bt_device_find(monitor, object_path);
@ -3171,7 +3172,7 @@ static void interface_added(struct spa_bt_monitor *monitor,
d->reconnect_state = BT_DEVICE_RECONNECT_INIT;
device_start_timer(d);
}
else if (strcmp(interface_name, BLUEZ_MEDIA_ENDPOINT_INTERFACE) == 0) {
else if (spa_streq(interface_name, BLUEZ_MEDIA_ENDPOINT_INTERFACE)) {
struct spa_bt_remote_endpoint *ep;
struct spa_bt_device *d;
@ -3233,17 +3234,17 @@ static void interfaces_removed(struct spa_bt_monitor *monitor, DBusMessageIter *
spa_log_debug(monitor->log, "Found object %s, interface %s", object_path, interface_name);
if (strcmp(interface_name, BLUEZ_DEVICE_INTERFACE) == 0) {
if (spa_streq(interface_name, BLUEZ_DEVICE_INTERFACE)) {
struct spa_bt_device *d;
d = spa_bt_device_find(monitor, object_path);
if (d != NULL)
device_free(d);
} else if (strcmp(interface_name, BLUEZ_ADAPTER_INTERFACE) == 0) {
} else if (spa_streq(interface_name, BLUEZ_ADAPTER_INTERFACE)) {
struct spa_bt_adapter *a;
a = adapter_find(monitor, object_path);
if (a != NULL)
adapter_free(a);
} else if (strcmp(interface_name, BLUEZ_MEDIA_ENDPOINT_INTERFACE) == 0) {
} else if (spa_streq(interface_name, BLUEZ_MEDIA_ENDPOINT_INTERFACE)) {
struct spa_bt_remote_endpoint *ep;
ep = remote_endpoint_find(monitor, object_path);
if (ep != NULL) {
@ -3339,7 +3340,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
goto fail;
}
if (strcmp(name, BLUEZ_SERVICE) == 0) {
if (spa_streq(name, BLUEZ_SERVICE)) {
bool has_old_owner = old_owner && *old_owner;
bool has_new_owner = new_owner && *new_owner;
@ -3374,7 +3375,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
spa_log_debug(monitor->log, "Bluetooth daemon appeared");
get_managed_objects(monitor);
}
} else if (strcmp(name, OFONO_SERVICE) == 0 && monitor->backend_ofono) {
} else if (spa_streq(name, OFONO_SERVICE) && monitor->backend_ofono) {
if (old_owner && *old_owner) {
spa_log_debug(monitor->log, "oFono daemon disappeared");
monitor->backend_ofono_registered = false;
@ -3395,7 +3396,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
monitor->backend_native_registered = true;
}
}
} else if (strcmp(name, HSPHFPD_SERVICE) == 0 && monitor->backend_hsphfpd) {
} else if (spa_streq(name, HSPHFPD_SERVICE) && monitor->backend_hsphfpd) {
if (old_owner && *old_owner) {
spa_log_debug(monitor->log, "hsphfpd daemon disappeared");
spa_bt_backend_unregistered(monitor->backend_hsphfpd);
@ -3464,7 +3465,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
dbus_message_iter_next(&it[0]);
dbus_message_iter_recurse(&it[0], &it[1]);
if (strcmp(iface, BLUEZ_ADAPTER_INTERFACE) == 0) {
if (spa_streq(iface, BLUEZ_ADAPTER_INTERFACE)) {
struct spa_bt_adapter *a;
a = adapter_find(monitor, path);
@ -3477,7 +3478,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
adapter_update_props(a, &it[1], NULL);
}
else if (strcmp(iface, BLUEZ_DEVICE_INTERFACE) == 0) {
else if (spa_streq(iface, BLUEZ_DEVICE_INTERFACE)) {
struct spa_bt_device *d;
d = spa_bt_device_find(monitor, path);
@ -3490,7 +3491,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
device_update_props(d, &it[1], NULL);
}
else if (strcmp(iface, BLUEZ_MEDIA_ENDPOINT_INTERFACE) == 0) {
else if (spa_streq(iface, BLUEZ_MEDIA_ENDPOINT_INTERFACE)) {
struct spa_bt_remote_endpoint *ep;
struct spa_bt_device *d;
@ -3508,7 +3509,7 @@ static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *m, void *us
if (d)
spa_bt_device_emit_profiles_changed(d, d->profiles, d->connected_profiles);
}
else if (strcmp(iface, BLUEZ_MEDIA_TRANSPORT_INTERFACE) == 0) {
else if (spa_streq(iface, BLUEZ_MEDIA_TRANSPORT_INTERFACE)) {
struct spa_bt_transport *transport;
transport = spa_bt_transport_find(monitor, path);
@ -3631,7 +3632,7 @@ static int impl_get_interface(struct spa_handle *handle, const char *type, void
this = (struct spa_bt_monitor *) handle;
if (strcmp(type, SPA_TYPE_INTERFACE_Device) == 0)
if (spa_streq(type, SPA_TYPE_INTERFACE_Device))
*interface = &this->device;
else
return -ENOENT;
@ -3723,17 +3724,17 @@ int spa_bt_profiles_from_json_array(const char *str)
return -EINVAL;
while (spa_json_get_string(&it_array, role_name, sizeof(role_name)) > 0) {
if (strcmp(role_name, "hsp_hs") == 0) {
if (spa_streq(role_name, "hsp_hs")) {
profiles |= SPA_BT_PROFILE_HSP_HS;
} else if (strcmp(role_name, "hsp_ag") == 0) {
} else if (spa_streq(role_name, "hsp_ag")) {
profiles |= SPA_BT_PROFILE_HSP_AG;
} else if (strcmp(role_name, "hfp_hf") == 0) {
} else if (spa_streq(role_name, "hfp_hf")) {
profiles |= SPA_BT_PROFILE_HFP_HF;
} else if (strcmp(role_name, "hfp_ag") == 0) {
} else if (spa_streq(role_name, "hfp_ag")) {
profiles |= SPA_BT_PROFILE_HFP_AG;
} else if (strcmp(role_name, "a2dp_sink") == 0) {
} else if (spa_streq(role_name, "a2dp_sink")) {
profiles |= SPA_BT_PROFILE_A2DP_SINK;
} else if (strcmp(role_name, "a2dp_source") == 0) {
} else if (spa_streq(role_name, "a2dp_source")) {
profiles |= SPA_BT_PROFILE_A2DP_SOURCE;
}
}
@ -3875,7 +3876,7 @@ impl_init(const struct spa_handle_factory *factory,
uint32_t tmp;
if ((str = spa_dict_lookup(info, "api.bluez5.connection-info")) != NULL &&
(strcmp(str, "true") == 0 || atoi(str)))
(spa_streq(str, "true") || atoi(str)))
this->connection_info_supported = true;
if ((str = spa_dict_lookup(info, "bluez5.default.rate")) != NULL &&
@ -3887,7 +3888,7 @@ impl_init(const struct spa_handle_factory *factory,
this->default_audio_info.channels = tmp;
if ((str = spa_dict_lookup(info, "bluez5.sbc-xq-support")) != NULL &&
(strcmp(str, "true") == 0 || atoi(str)))
(spa_streq(str, "true") || atoi(str)))
this->enable_sbc_xq = true;
}