diff options
author | Daniel Wagner <daniel.wagner@bmw-carit.de> | 2013-08-14 09:27:52 +0200 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-08-20 11:05:30 +0200 |
commit | 49885b7d8574c9a55016114387bcb54db1b1b13a (patch) | |
tree | 7c4a417734a06891854e41ba0f4ab23cfc7bd0fb /src | |
parent | a3594b1032554feee39844f01c7c709d1bca9545 (diff) | |
download | neard-49885b7d8574c9a55016114387bcb54db1b1b13a.tar.gz neard-49885b7d8574c9a55016114387bcb54db1b1b13a.tar.bz2 neard-49885b7d8574c9a55016114387bcb54db1b1b13a.zip |
core: Use stdbool instead gboolean or near_bool_t
This patch has been created via coccinelle:
// Rule set 1
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
@r2@
type T;
identifier f;
parameter list[n] ps;
identifier i;
@@
T f(ps, near_bool_t i, ...);
@@
identifier r2.f;
expression list [r.n] es;
@@
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
@@
typedef bool;
@@
- near_bool_t
+ bool
// Rule set 2
// This is not a beautiful script but it does the job.
// Improvemtents are welcome.
// Fix all assigments but do not convert yet the type
@@
gboolean x;
@@
x =
(
- TRUE
+ true
|
- FALSE
+ false
)
// Figure out which function signature will to be fixed...
// when we have the defitition
@r@
identifier f;
parameter list[n] ps;
identifier i;
@@
f(ps, gboolean i, ...) { ... }
// ... and now convert all call sites
@@
identifier r.f;
expression list [r.n] es;
@@
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
// Figure out which function signature will to be fixed...
// when we have the declaration only
@r2@
type T;
identifier f;
parameter list[n] ps;
identifier i;
@@
T f(ps, gboolean i, ...);
// ... and now convert all call sites
@@
identifier r2.f;
expression list [r.n] es;
@@
f(es,
(
- FALSE
+ false
|
- TRUE
+ true
)
,...)
// A handfull of the GLib hooks we can't change. Let's remember
// all ther positions.
// 1. timeouts
@k1@
identifier f;
position p;
typedef gpointer;
identifier ptr;
@@
static gboolean@p f(gpointer ptr);
@k2@
identifier f;
position p;
identifier ptr;
@@
static gboolean@p f(gpointer ptr) { ... }
// hash map iterator functions
@k3@
identifier f;
position p;
identifier p1, p2, p3;
@@
static gboolean@p f(gpointer p1, gpointer p2, gpointer p3) { ... }
// 2. GIOChannel
@k4@
identifier f;
position p;
typedef GIOChannel, GIOCondition;
identifier ptr;
identifier ch, cn;
@@
static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr);
@k5@
identifier f;
position p;
identifier ptr;
identifier ch, cn;
@@
static gboolean@p f(GIOChannel *ch, GIOCondition cn, gpointer ptr) { ... }
// 3. GSourceFuncs
@k6@
identifier f;
position p;
typedef GSource;
identifier src;
@@
static gboolean@p f(GSource *src, ...) { ... }
// gdbus functions
@k7@
identifier f;
position p;
typedef DBusConnection;
identifier con;
@@
static gboolean@p f(DBusConnection *con, ...) { ... }
// Now convert all gboolean which are are not used for interactin
// with GLib
// Note here happens the magic!
@@
typedef bool;
position p != {k1.p,k2.p,k3.p,k4.p,k5.p,k6.p,k7.p};
@@
- gboolean@p
+ bool
// Update all return types
@@
identifier f;
@@
bool f(...) {
<...
- return TRUE;
+ return true;
...>
}
@@
identifier f;
@@
bool f(...) {
<...
- return FALSE;
+ return false;
...>
}
// Rule set 3
@@
expression E;
symbol TRUE;
symbol FALSE;
@@
(
E
- == TRUE
|
- TRUE == E
+ E
|
- E != TRUE
+ !E
|
- TRUE != E
+ !E
|
- E == FALSE
+ !E
|
- FALSE == E
+ !E
|
E
- != FALSE
|
- FALSE != E
+ E
)
Diffstat (limited to 'src')
-rw-r--r-- | src/adapter.c | 69 | ||||
-rw-r--r-- | src/agent.c | 6 | ||||
-rw-r--r-- | src/bluetooth.c | 62 | ||||
-rw-r--r-- | src/device.c | 2 | ||||
-rw-r--r-- | src/log.c | 20 | ||||
-rw-r--r-- | src/main.c | 30 | ||||
-rw-r--r-- | src/manager.c | 10 | ||||
-rw-r--r-- | src/ndef.c | 115 | ||||
-rw-r--r-- | src/near.h | 16 | ||||
-rw-r--r-- | src/netlink.c | 26 | ||||
-rw-r--r-- | src/plugin.c | 39 | ||||
-rw-r--r-- | src/snep.c | 44 | ||||
-rw-r--r-- | src/tag.c | 16 |
13 files changed, 227 insertions, 228 deletions
diff --git a/src/adapter.c b/src/adapter.c index 59d023f..53d76cf 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -61,10 +61,10 @@ struct near_adapter { uint32_t poll_mode; enum near_adapter_rf_mode rf_mode; - near_bool_t powered; - near_bool_t polling; - near_bool_t constant_poll; - near_bool_t dep_up; + bool powered; + bool polling; + bool constant_poll; + bool dep_up; GHashTable *tags; struct near_tag *tag_link; @@ -195,7 +195,7 @@ static int adapter_start_poll(struct near_adapter *adapter) if (err < 0) return err; - adapter->polling = TRUE; + adapter->polling = true; polling_changed(adapter); @@ -398,7 +398,7 @@ static DBusMessage *set_property(DBusConnection *conn, DBG("conn %p", conn); - if (dbus_message_iter_init(msg, &iter) == FALSE) + if (!dbus_message_iter_init(msg, &iter)) return __near_error_invalid_arguments(msg); dbus_message_iter_get_basic(&iter, &name); @@ -407,7 +407,7 @@ static DBusMessage *set_property(DBusConnection *conn, type = dbus_message_iter_get_arg_type(&value); - if (g_str_equal(name, "Powered") == TRUE) { + if (g_str_equal(name, "Powered")) { dbus_bool_t powered; if (type != DBUS_TYPE_BOOLEAN) @@ -418,7 +418,7 @@ static DBusMessage *set_property(DBusConnection *conn, err = __near_netlink_adapter_enable(adapter->idx, powered); if (err < 0) { if (err == -EALREADY) { - if (powered == TRUE) + if (powered) return __near_error_already_enabled(msg); else return __near_error_already_disabled(msg); @@ -473,14 +473,14 @@ static DBusMessage *stop_poll_loop(DBusConnection *conn, DBG("conn %p", conn); - if (adapter->polling == FALSE) + if (!adapter->polling) return __near_error_not_polling(msg); err = __near_netlink_stop_poll(adapter->idx); if (err < 0) return __near_error_failed(msg, -err); - adapter->polling = FALSE; + adapter->polling = false; polling_changed(adapter); @@ -515,7 +515,7 @@ static gboolean check_presence(gpointer user_data) out_err: near_adapter_disconnect(adapter->idx); - if (adapter->constant_poll == TRUE) + if (adapter->constant_poll) adapter_start_poll(adapter); return FALSE; @@ -551,7 +551,7 @@ static void tag_present_cb(uint32_t adapter_idx, uint32_t target_idx, DBG("Tag is gone"); near_adapter_disconnect(adapter->idx); - if (adapter->constant_poll == TRUE) + if (adapter->constant_poll) adapter_start_poll(adapter); return; @@ -617,10 +617,10 @@ static const GDBusSignalTable adapter_signals[] = { }; struct near_adapter *__near_adapter_create(uint32_t idx, - const char *name, uint32_t protocols, near_bool_t powered) + const char *name, uint32_t protocols, bool powered) { struct near_adapter *adapter; - near_bool_t powered_setting; + bool powered_setting; adapter = g_try_malloc0(sizeof(struct near_adapter)); if (adapter == NULL) @@ -633,9 +633,9 @@ struct near_adapter *__near_adapter_create(uint32_t idx, } powered_setting = near_setting_get_bool("DefaultPowered"); - if (powered_setting == TRUE && powered == FALSE && + if (powered_setting && !powered && !__near_netlink_adapter_enable(idx, powered_setting)) - powered = TRUE; + powered = true; DBG("Powered %d", powered); @@ -643,7 +643,7 @@ struct near_adapter *__near_adapter_create(uint32_t idx, adapter->protocols = protocols; adapter->powered = powered; adapter->constant_poll = near_setting_get_bool("ConstantPoll"); - adapter->dep_up = FALSE; + adapter->dep_up = false; adapter->tags = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tag); adapter->tag_sock = -1; @@ -674,7 +674,7 @@ struct near_adapter *__near_adapter_get(uint32_t idx) return g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)); } -int __near_adapter_set_dep_state(uint32_t idx, near_bool_t dep) +int __near_adapter_set_dep_state(uint32_t idx, bool dep) { struct near_adapter *adapter; @@ -686,10 +686,10 @@ int __near_adapter_set_dep_state(uint32_t idx, near_bool_t dep) adapter->dep_up = dep; - if (dep == FALSE && adapter->constant_poll == TRUE) + if (!dep && adapter->constant_poll) adapter_start_poll(adapter); - if (dep == FALSE) { + if (!dep) { uint32_t target_idx; target_idx = __neard_device_get_idx(adapter->device_link); @@ -704,7 +704,7 @@ int __near_adapter_set_dep_state(uint32_t idx, near_bool_t dep) return 0; } -near_bool_t __near_adapter_get_dep_state(uint32_t idx) +bool __near_adapter_get_dep_state(uint32_t idx) { struct near_adapter *adapter; @@ -712,7 +712,7 @@ near_bool_t __near_adapter_get_dep_state(uint32_t idx) adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)); if (adapter == NULL) - return FALSE; + return false; return adapter->dep_up; } @@ -761,7 +761,7 @@ static void tag_read_cb(uint32_t adapter_idx, uint32_t target_idx, int status) if (status < 0) { near_adapter_disconnect(adapter->idx); - if (adapter->constant_poll == TRUE) + if (adapter->constant_poll) adapter_start_poll(adapter); return; @@ -792,7 +792,7 @@ static void device_read_cb(uint32_t adapter_idx, uint32_t target_idx, adapter->device_link = NULL; } - if (adapter->constant_poll == TRUE) + if (adapter->constant_poll) adapter_start_poll(adapter); return; @@ -858,7 +858,7 @@ static int adapter_add_device(struct near_adapter *adapter, adapter->device_link = device; - if (adapter->dep_up == TRUE) + if (adapter->dep_up) return 0; err = __near_netlink_dep_link_up(adapter->idx, target_idx, @@ -887,7 +887,7 @@ int __near_adapter_add_target(uint32_t idx, uint32_t target_idx, if (adapter == NULL) return -ENODEV; - adapter->polling = FALSE; + adapter->polling = false; polling_changed(adapter); adapter->rf_mode = NEAR_ADAPTER_RF_MODE_INITIATOR; @@ -900,7 +900,7 @@ int __near_adapter_add_target(uint32_t idx, uint32_t target_idx, ret = adapter_add_tag(adapter, target_idx, protocols, sens_res, sel_res, nfcid, nfcid_len); - if (ret < 0 && adapter->constant_poll == TRUE) + if (ret < 0 && adapter->constant_poll) adapter_start_poll(adapter); return ret; @@ -920,14 +920,14 @@ int __near_adapter_remove_target(uint32_t idx, uint32_t target_idx) rf_mode_changed(adapter); if (g_hash_table_remove(adapter->tags, - GINT_TO_POINTER(target_idx)) == TRUE) { + GINT_TO_POINTER(target_idx))) { __near_adapter_tags_changed(idx); return 0; } if (g_hash_table_remove(adapter->devices, - GINT_TO_POINTER(target_idx)) == TRUE) { + GINT_TO_POINTER(target_idx))) { __near_adapter_devices_changed(idx); return 0; @@ -947,8 +947,8 @@ int __near_adapter_add_device(uint32_t idx, uint8_t *nfcid, uint8_t nfcid_len) if (adapter == NULL) return -ENODEV; - adapter->polling = FALSE; - adapter->dep_up = TRUE; + adapter->polling = false; + adapter->dep_up = true; adapter->rf_mode = NEAR_ADAPTER_RF_MODE_TARGET; polling_changed(adapter); rf_mode_changed(adapter); @@ -973,17 +973,16 @@ int __near_adapter_remove_device(uint32_t idx) if (adapter == NULL) return -ENODEV; - if (g_hash_table_remove(adapter->devices, - GINT_TO_POINTER(device_idx)) == FALSE) + if (!g_hash_table_remove(adapter->devices, GINT_TO_POINTER(device_idx))) return 0; adapter->rf_mode = NEAR_ADAPTER_RF_MODE_IDLE; rf_mode_changed(adapter); __near_adapter_devices_changed(idx); - adapter->dep_up = FALSE; + adapter->dep_up = false; - if (adapter->constant_poll == TRUE) + if (adapter->constant_poll) adapter_start_poll(adapter); return 0; diff --git a/src/agent.c b/src/agent.c index 74ec0ed..cbbf45e 100644 --- a/src/agent.c +++ b/src/agent.c @@ -449,7 +449,7 @@ struct carrier_data *__near_agent_handover_request_data( dbus_message_unref(message); if (reply == NULL) { - if (dbus_error_is_set(&error) == TRUE) { + if (dbus_error_is_set(&error)) { near_error("RequestOOB failed: %s", error.message); dbus_error_free(&error); } else { @@ -499,7 +499,7 @@ int __near_agent_handover_push_data(enum ho_agent_carrier carrier, return 0; } - if (dbus_error_is_set(&error) == TRUE) { + if (dbus_error_is_set(&error)) { near_error("PushOOB failed: %s", error.message); dbus_error_free(&error); } else { @@ -643,7 +643,7 @@ int __near_agent_handover_unregister(const char *sender, const char *path, return 0; } -near_bool_t __near_agent_handover_registered(enum ho_agent_carrier carrier) +bool __near_agent_handover_registered(enum ho_agent_carrier carrier) { struct near_handove_agent *agent = NULL; diff --git a/src/bluetooth.c b/src/bluetooth.c index b446fd7..30a2008 100644 --- a/src/bluetooth.c +++ b/src/bluetooth.c @@ -77,9 +77,9 @@ struct near_oob_data { char *bt_name; /* short or long name */ uint8_t bt_name_len; int class_of_device; /* Class of device */ - near_bool_t powered; - near_bool_t pairable; - near_bool_t discoverable; + bool powered; + bool pairable; + bool discoverable; uint8_t *uuids; int uuids_len; @@ -322,7 +322,7 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob) DBusMessageIter array, dict; - if (dbus_message_iter_init(reply, &array) == FALSE) + if (!dbus_message_iter_init(reply, &array)) return -1; if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) @@ -340,7 +340,7 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob) dbus_message_iter_next(&entry); dbus_message_iter_recurse(&entry, &value); - if (g_str_equal(key, "Address") == TRUE) { + if (g_str_equal(key, "Address")) { dbus_message_iter_get_basic(&value, &data); /* Now, fill the local struct */ @@ -353,7 +353,7 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob) oob->bd_addr[i] = strtol(data + j, NULL, 16); DBG("local address: %s", data); - } else if (g_str_equal(key, "Name") == TRUE) { + } else if (g_str_equal(key, "Name")) { dbus_message_iter_get_basic(&value, &data); oob->bt_name = g_strdup(data); if (oob->bt_name != NULL) { @@ -361,23 +361,23 @@ static int extract_properties(DBusMessage *reply, struct near_oob_data *oob) DBG("local name: %s", oob->bt_name); } - } else if (g_str_equal(key, "Class") == TRUE) { + } else if (g_str_equal(key, "Class")) { dbus_message_iter_get_basic(&value, &idata); oob->class_of_device = idata; - } else if (g_str_equal(key, "Powered") == TRUE) { + } else if (g_str_equal(key, "Powered")) { dbus_message_iter_get_basic(&value, &idata); oob->powered = idata; - } else if (g_str_equal(key, "Discoverable") == TRUE) { + } else if (g_str_equal(key, "Discoverable")) { dbus_message_iter_get_basic(&value, &idata); oob->discoverable = idata; - } else if (g_str_equal(key, "Pairable") == TRUE) { + } else if (g_str_equal(key, "Pairable")) { dbus_message_iter_get_basic(&value, &idata); oob->pairable = idata; - } else if (g_str_equal(key, "UUIDs") == TRUE) { + } else if (g_str_equal(key, "UUIDs")) { oob->uuids_len = sizeof(value); oob->uuids = g_try_malloc0(oob->uuids_len); if (oob->uuids == NULL) @@ -425,7 +425,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn, DBusMessageIter var; const char *property; - if (dbus_message_iter_init(message, &iter) == FALSE) + if (!dbus_message_iter_init(message, &iter)) return TRUE; dbus_message_iter_get_basic(&iter, &property); @@ -436,7 +436,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn, dbus_message_iter_recurse(&iter, &var); - if (g_str_equal(property, "Name") == TRUE) { + if (g_str_equal(property, "Name")) { const char *name; if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING) @@ -453,7 +453,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn, bt_def_oob_data.bt_name_len = 0; DBG("%s: %s", property, name); - } else if (g_str_equal(property, "Class") == TRUE) { + } else if (g_str_equal(property, "Class")) { int class; if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_UINT32) @@ -463,7 +463,7 @@ static gboolean bt_adapter_property_changed(DBusConnection *conn, bt_def_oob_data.class_of_device = class; DBG("%s: %x", property, bt_def_oob_data.class_of_device); - } else if (g_str_equal(property, "Powered") == TRUE) { + } else if (g_str_equal(property, "Powered")) { dbus_bool_t powered; if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN) @@ -540,8 +540,8 @@ static void bt_get_default_adapter_cb(DBusPendingCall *pending, void *user_data) if (dbus_set_error_from_message(&error, reply)) goto cb_fail; - if (dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, - &path, DBUS_TYPE_INVALID) == FALSE) + if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, + &path, DBUS_TYPE_INVALID)) goto cb_fail; /* Save the default adapter */ @@ -680,7 +680,7 @@ static void bt_parse_eir(uint8_t *eir_data, uint16_t eir_data_len, */ int __near_bluetooth_parse_oob_record(struct carrier_data *data, uint16_t *mime_properties, - near_bool_t pair) + bool pair) { struct near_oob_data *oob; uint16_t bt_oob_data_size; @@ -760,7 +760,7 @@ int __near_bluetooth_parse_oob_record(struct carrier_data *data, return -EINVAL; } - if (pair == FALSE) { + if (!pair) { bt_eir_free(oob); return 0; } @@ -813,7 +813,7 @@ static int bt_sync_oob_readlocaldata(DBusConnection *conn, char *adapter_path, dbus_message_unref(message); if (!reply) { - if (dbus_error_is_set(&error) == TRUE) { + if (dbus_error_is_set(&error)) { near_error("%s", error.message); dbus_error_free(&error); } else { @@ -822,11 +822,11 @@ static int bt_sync_oob_readlocaldata(DBusConnection *conn, char *adapter_path, return 0; } - if (dbus_message_get_args(reply, NULL, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, spair_hash, &hash_len, - DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, - spair_randomizer, &rndm_len, - DBUS_TYPE_INVALID) == FALSE) + if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_ARRAY, + DBUS_TYPE_BYTE, spair_hash, + &hash_len, DBUS_TYPE_ARRAY, + DBUS_TYPE_BYTE, spair_randomizer, + &rndm_len, DBUS_TYPE_INVALID)) goto done; if ((hash_len != OOB_SP_SIZE) || (rndm_len != OOB_SP_SIZE)) { @@ -938,7 +938,7 @@ struct carrier_data *__near_bluetooth_local_get_properties(uint16_t mime_props) data->data[0] = data->size ; - if (bt_def_oob_data.powered == TRUE) + if (bt_def_oob_data.powered) data->state = CPS_ACTIVE; else data->state = CPS_INACTIVE; @@ -966,7 +966,7 @@ static gboolean bt_adapter_removed(DBusConnection *conn, DBusMessage *message, g_dbus_remove_watch(bt_conn, adapter_props_watch); adapter_props_watch = 0; - if (dbus_message_iter_init(message, &iter) == FALSE) + if (!dbus_message_iter_init(message, &iter)) return TRUE; dbus_message_iter_get_basic(&iter, &adapter_path); @@ -992,7 +992,7 @@ static gboolean bt_default_adapter_changed(DBusConnection *conn, DBG(""); - if (dbus_message_iter_init(message, &iter) == FALSE) + if (!dbus_message_iter_init(message, &iter)) return TRUE; g_dbus_remove_watch(bt_conn, adapter_props_watch); @@ -1054,7 +1054,7 @@ static void bt_connect(DBusConnection *conn, void *data) { DBG("connection %p with %p", conn, data); - if (__near_agent_handover_registered(HO_AGENT_BT) == TRUE) { + if (__near_agent_handover_registered(HO_AGENT_BT)) { DBG("Agent already registered"); return; } @@ -1092,7 +1092,7 @@ static void bt_disconnect(DBusConnection *conn, void *user_data) static int bt_prepare_handlers(DBusConnection *conn) { - if (__near_agent_handover_registered(HO_AGENT_BT) == TRUE) + if (__near_agent_handover_registered(HO_AGENT_BT)) return 0; watch = g_dbus_add_service_watch(bt_conn, BLUEZ_SERVICE, @@ -1154,7 +1154,7 @@ int __near_bluetooth_init(void) /* save the dbus connection */ bt_conn = near_dbus_get_connection(); if (bt_conn == NULL) { - if (dbus_error_is_set(&err) == TRUE) { + if (dbus_error_is_set(&err)) { near_error("%s", err.message); dbus_error_free(&err); } else diff --git a/src/device.c b/src/device.c index 18b6d1f..e992fa0 100644 --- a/src/device.c +++ b/src/device.c @@ -444,7 +444,7 @@ int __near_device_push(struct near_device *device, DBG(""); - if (__near_adapter_get_dep_state(device->adapter_idx) == FALSE) { + if (!__near_adapter_get_dep_state(device->adapter_idx)) { near_error("DEP link is not established"); return -ENOLINK; } @@ -77,26 +77,26 @@ extern struct near_debug_desc __stop___debug[]; static gchar **enabled = NULL; -static gboolean is_enabled(struct near_debug_desc *desc) +static bool is_enabled(struct near_debug_desc *desc) { int i; if (enabled == NULL) - return FALSE; + return false; for (i = 0; enabled[i] != NULL; i++) { if (desc->name != NULL && g_pattern_match_simple(enabled[i], - desc->name) == TRUE) - return TRUE; + desc->name)) + return true; if (desc->file != NULL && g_pattern_match_simple(enabled[i], - desc->file) == TRUE) - return TRUE; + desc->file)) + return true; } - return FALSE; + return false; } -int __near_log_init(const char *debug, gboolean detach) +int __near_log_init(const char *debug, bool detach) { int option = LOG_NDELAY | LOG_PID; struct near_debug_desc *desc; @@ -114,11 +114,11 @@ int __near_log_init(const char *debug, gboolean detach) file = NULL; } - if (is_enabled(desc) == TRUE) + if (is_enabled(desc)) desc->flags |= NEAR_DEBUG_FLAG_PRINT; } - if (detach == FALSE) + if (!detach) option |= LOG_PERROR; openlog("neard", option, LOG_DAEMON); @@ -35,8 +35,8 @@ #include "near.h" static struct { - near_bool_t constant_poll; - near_bool_t default_powered; + bool constant_poll; + bool default_powered; } near_settings = { .constant_poll = FALSE, .default_powered = FALSE, @@ -68,7 +68,7 @@ static GKeyFile *load_config(const char *file) static void parse_config(GKeyFile *config) { GError *error = NULL; - gboolean boolean; + bool boolean; if (config == NULL) return; @@ -170,10 +170,10 @@ static void disconnect_callback(DBusConnection *conn, void *user_data) static gchar *option_debug = NULL; static gchar *option_plugin = NULL; static gchar *option_noplugin = NULL; -static gboolean option_detach = TRUE; -static gboolean option_version = FALSE; +static bool option_detach = true; +static bool option_version = false; -static gboolean parse_debug(const char *key, const char *value, +static bool parse_debug(const char *key, const char *value, gpointer user_data, GError **error) { if (value) @@ -181,7 +181,7 @@ static gboolean parse_debug(const char *key, const char *value, else option_debug = g_strdup("*"); - return TRUE; + return true; } static GOptionEntry options[] = { @@ -200,15 +200,15 @@ static GOptionEntry options[] = { { NULL }, }; -near_bool_t near_setting_get_bool(const char *key) +bool near_setting_get_bool(const char *key) { - if (g_str_equal(key, "ConstantPoll") == TRUE) + if (g_str_equal(key, "ConstantPoll")) return near_settings.constant_poll; - if (g_str_equal(key, "DefaultPowered") == TRUE) + if (g_str_equal(key, "DefaultPowered")) return near_settings.default_powered; - return FALSE; + return false; } int main(int argc, char *argv[]) @@ -223,7 +223,7 @@ int main(int argc, char *argv[]) context = g_option_context_new(NULL); g_option_context_add_main_entries(context, options, NULL); - if (g_option_context_parse(context, &argc, &argv, &error) == FALSE) { + if (!g_option_context_parse(context, &argc, &argv, &error)) { if (error != NULL) { g_printerr("%s\n", error->message); g_error_free(error); @@ -234,7 +234,7 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (option_version == TRUE) { + if (option_version) { printf("%s\n", VERSION); exit(0); } @@ -247,7 +247,7 @@ int main(int argc, char *argv[]) conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NFC_SERVICE, &err); if (conn == NULL) { - if (dbus_error_is_set(&err) == TRUE) { + if (dbus_error_is_set(&err)) { fprintf(stderr, "%s\n", err.message); dbus_error_free(&err); } else @@ -280,7 +280,7 @@ int main(int argc, char *argv[]) __near_plugin_init(option_plugin, option_noplugin); - if (option_detach == TRUE) { + if (option_detach) { if (daemon(0, 0)) { perror("Can't start daemon"); exit(1); diff --git a/src/manager.c b/src/manager.c index 0950661..0f6c4ae 100644 --- a/src/manager.c +++ b/src/manager.c @@ -60,7 +60,7 @@ static DBusMessage *get_properties(DBusConnection *conn, } int __near_manager_adapter_add(uint32_t idx, const char *name, - uint32_t protocols, near_bool_t powered) + uint32_t protocols, bool powered) { struct near_adapter *adapter; const char *path; @@ -136,7 +136,7 @@ static DBusMessage *register_handover_agent(DBusConnection *conn, sender = dbus_message_get_sender(msg); - if (dbus_message_iter_init(msg, &iter) == FALSE) + if (!dbus_message_iter_init(msg, &iter)) return __near_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) @@ -168,7 +168,7 @@ static DBusMessage *unregister_handover_agent(DBusConnection *conn, sender = dbus_message_get_sender(msg); - if (dbus_message_iter_init(msg, &iter) == FALSE) + if (!dbus_message_iter_init(msg, &iter)) return __near_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) @@ -200,7 +200,7 @@ static DBusMessage *register_ndef_agent(DBusConnection *conn, sender = dbus_message_get_sender(msg); - if (dbus_message_iter_init(msg, &iter) == FALSE) + if (!dbus_message_iter_init(msg, &iter)) return __near_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) @@ -232,7 +232,7 @@ static DBusMessage *unregister_ndef_agent(DBusConnection *conn, sender = dbus_message_get_sender(msg); - if (dbus_message_iter_init(msg, &iter) == FALSE) + if (!dbus_message_iter_init(msg, &iter)) return __near_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) @@ -1343,7 +1343,7 @@ static int process_mime_type(struct near_ndef_mime_payload *mime, err = __near_agent_handover_push_data(HO_AGENT_BT, c_data); if (err == -ESRCH) err = __near_bluetooth_parse_oob_record(c_data, - &mime->handover.properties, TRUE); + &mime->handover.properties, true); break; case NEAR_CARRIER_WIFI: @@ -1414,34 +1414,34 @@ static struct near_ndef_mime_payload *parse_mime_type( } /* Set the MB bit in message header */ -static uint8_t near_ndef_set_mb(uint8_t *hdr, near_bool_t first_rec) +static uint8_t near_ndef_set_mb(uint8_t *hdr, bool first_rec) { /* Reset bits 0x40 */ *hdr &= (0xFF & (~RECORD_MB)); /* Set if needed */ - if (first_rec == TRUE) + if (first_rec) *hdr |= RECORD_MB; return *hdr; } /* Set the MB/ME bit in message header */ -static uint8_t near_ndef_set_me(uint8_t *hdr, near_bool_t last_rec) +static uint8_t near_ndef_set_me(uint8_t *hdr, bool last_rec) { /* Reset bits 0x80 */ *hdr &= (0xFF & (~RECORD_ME)); /* Set if needed */ - if (last_rec == TRUE) + if (last_rec) *hdr |= RECORD_ME; return *hdr; } /* Set the MB/ME bit in message header */ -static uint8_t near_ndef_set_mb_me(uint8_t *hdr, near_bool_t first_rec, - near_bool_t last_rec) +static uint8_t near_ndef_set_mb_me(uint8_t *hdr, bool first_rec, + bool last_rec) { near_ndef_set_mb(hdr, first_rec); return near_ndef_set_me(hdr, last_rec); @@ -1453,8 +1453,8 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name, char *payload_id, uint8_t payload_id_len, enum record_tnf tnf, - near_bool_t first_rec, - near_bool_t last_rec) + bool first_rec, + bool last_rec) { struct near_ndef_message *msg; uint8_t hdr = 0, type_len, sr_bit, il_bit, id_len; @@ -1475,8 +1475,8 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name, il_bit = (payload_id != NULL) ? TRUE : FALSE; - msg->length += (sr_bit == TRUE) ? 1 : 4; - msg->length += (il_bit == TRUE) ? 1 : 0; + msg->length += (sr_bit) ? 1 : 4; + msg->length += (il_bit) ? 1 : 0; msg->length += type_len; msg->length += payload_len; msg->length += id_len; @@ -1488,11 +1488,11 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name, /* Set MB ME bits */ hdr = near_ndef_set_mb_me(&hdr, first_rec, last_rec); - if (sr_bit == TRUE) + if (sr_bit) hdr |= RECORD_SR; hdr = RECORD_TNF_WKT_SET(hdr); - if (il_bit == TRUE) + if (il_bit) hdr |= RECORD_IL; switch (tnf) { @@ -1527,14 +1527,14 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name, msg->data[msg->offset++] = hdr; msg->data[msg->offset++] = type_len; - if (sr_bit == TRUE) { + if (sr_bit) { msg->data[msg->offset++] = payload_len; } else { fillb32((msg->data + msg->offset), payload_len); msg->offset += 4; } - if (il_bit == TRUE) + if (il_bit) msg->data[msg->offset++] = payload_id_len; if (type_name != NULL) { @@ -1542,7 +1542,7 @@ static struct near_ndef_message *ndef_message_alloc_complete(char *type_name, msg->offset += type_len; } - if (il_bit == TRUE) { + if (il_bit) { memcpy(msg->data + msg->offset, payload_id, payload_id_len); msg->offset += payload_id_len; } @@ -1568,7 +1568,7 @@ static struct near_ndef_message *ndef_message_alloc(char *type_name, return ndef_message_alloc_complete(type_name, payload_len, NULL, 0, RECORD_TNF_WELLKNOWN, - TRUE, TRUE); + true, true); } static enum carrier_power_state get_cps(uint8_t data) @@ -1650,7 +1650,7 @@ static struct near_ndef_message *near_ndef_prepare_ac_message(uint8_t cps, AC_RECORD_PAYLOAD_LEN(cdr_len), NULL, 0, RECORD_TNF_WELLKNOWN, - TRUE, TRUE); + true, true); if (ac_msg == NULL) return NULL; @@ -1678,7 +1678,7 @@ static struct near_ndef_message *near_ndef_prepare_cr_message(uint16_t cr_id) cr_msg = ndef_message_alloc_complete("cr", sizeof(uint16_t), NULL, 0, RECORD_TNF_WELLKNOWN, - TRUE, TRUE); + true, true); if (cr_msg == NULL) return NULL; @@ -1700,7 +1700,7 @@ static struct near_ndef_message *near_ndef_prepare_cfg_message(char *mime_type, return NULL; msg = ndef_message_alloc_complete(mime_type, data_len, cdr, cdr_len, - RECORD_TNF_MIME, TRUE, TRUE); + RECORD_TNF_MIME, true, true); if (msg == NULL) return NULL; @@ -1845,7 +1845,7 @@ static struct near_ndef_message *prepare_handover_message_header(char *type, * So, we have to fix the payload length in the header. */ ho_msg->data[NDEF_PAYLOAD_LENGTH_OFFSET] = payload_len; - near_ndef_set_mb_me(ho_msg->data, TRUE, FALSE); + near_ndef_set_mb_me(ho_msg->data, true, false); /* Add version */ ho_msg->data[ho_msg->offset++] = HANDOVER_VERSION; @@ -1918,7 +1918,7 @@ static void set_mb_me_to_false(gpointer data, gpointer user_data) { struct near_ndef_message *msg = data; - near_ndef_set_mb_me(msg->data, FALSE, FALSE); + near_ndef_set_mb_me(msg->data, false, false); } static struct near_ndef_message *near_ndef_prepare_empty_hs_message(void) @@ -1941,7 +1941,7 @@ static struct near_ndef_message *near_ndef_prepare_empty_hs_message(void) if (hs_msg == NULL) goto fail; - near_ndef_set_mb_me(hs_msg->data, TRUE, TRUE); + near_ndef_set_mb_me(hs_msg->data, true, true); memcpy(hs_msg->data + hs_msg->offset, ac_msg->data, ac_msg->length); hs_msg->offset += ac_msg->length; @@ -2029,23 +2029,23 @@ static struct near_ndef_message *near_ndef_prepare_hs_reply( if (num_of_carriers == 1) { /* only one message */ ac_msg = ac_msgs->data; - near_ndef_set_mb_me(ac_msg->data, TRUE, TRUE); + near_ndef_set_mb_me(ac_msg->data, true, true); } else if (num_of_carriers > 1) { g_list_foreach(ac_msgs, set_mb_me_to_false, NULL); /* first message */ temp = g_list_first(ac_msgs); ac_msg = temp->data; - near_ndef_set_mb_me(ac_msg->data, TRUE, FALSE); + near_ndef_set_mb_me(ac_msg->data, true, false); /* last message */ temp = g_list_last(ac_msgs); ac_msg = temp->data; - near_ndef_set_mb_me(ac_msg->data, FALSE, TRUE); + near_ndef_set_mb_me(ac_msg->data, false, true); } g_list_foreach(cfg_msgs, set_mb_me_to_false, NULL); temp = g_list_last(cfg_msgs); cfg_msg = temp->data; - near_ndef_set_mb_me(cfg_msg->data, FALSE, TRUE); + near_ndef_set_mb_me(cfg_msg->data, false, true); /* copy acs */ copy_ac_records(hs_msg, ac_msgs); @@ -2144,7 +2144,7 @@ near_ndef_prepare_ho_message(enum record_type type, GSList *carriers) if (cr_msg == NULL) goto fail; - near_ndef_set_mb_me(cr_msg->data, TRUE, FALSE); + near_ndef_set_mb_me(cr_msg->data, true, false); ho_pl_length += cr_msg->length; } @@ -2165,7 +2165,7 @@ near_ndef_prepare_ho_message(enum record_type type, GSList *carriers) /* last message */ temp = g_list_last(ac_msgs); ac_msg = temp->data; - near_ndef_set_mb_me(ac_msg->data, FALSE, TRUE); + near_ndef_set_mb_me(ac_msg->data, false, true); /* * Hs record payloads do not have collision recore, the first record @@ -2174,13 +2174,13 @@ near_ndef_prepare_ho_message(enum record_type type, GSList *carriers) if (type == RECORD_TYPE_WKT_HANDOVER_SELECT) { temp = g_list_first(ac_msgs); ac_msg = temp->data; - near_ndef_set_mb_me(ac_msg->data, TRUE, FALSE); + near_ndef_set_mb_me(ac_msg->data, true, false); } g_list_foreach(cfg_msgs, set_mb_me_to_false, NULL); temp = g_list_last(cfg_msgs); cfg_msg = temp->data; - near_ndef_set_mb_me(cfg_msg->data, FALSE, TRUE); + near_ndef_set_mb_me(cfg_msg->data, false, true); if (type == RECORD_TYPE_WKT_HANDOVER_REQUEST) { /* copy cr */ @@ -2290,7 +2290,7 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type, uint8_t mb = 0, me = 0, i; uint32_t offset; int16_t count_ac = 0; - near_bool_t action = FALSE, status; + bool action = false, status; DBG(""); @@ -2375,9 +2375,9 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type, * is the signal to launch the pairing. */ if (rec_type == RECORD_TYPE_WKT_HANDOVER_SELECT) - action = TRUE; + action = true; else - action = FALSE; + action = false; /* HO payload for reply creation */ trec->ho = ho_payload; @@ -2451,19 +2451,19 @@ static struct near_ndef_ho_payload *parse_ho_payload(enum record_type rec_type, * In case of multiple carriers, handover with any carrier * gets done then leave the loop. */ - if (action == TRUE) { - status = FALSE; + if (action) { + status = false; count_ac = g_slist_length(mimes); for (i = 0; i < count_ac; i++) { if (process_mime_type(g_slist_nth_data(mimes, i), g_slist_nth_data(c_datas, i)) == 0) { - status = TRUE; + status = true; break; } } - if (status == FALSE) { + if (!status) { DBG("could not process alternative carriers"); goto fail; } @@ -2557,56 +2557,56 @@ int __near_ndef_record_register(struct near_ndef_record *record, char *path) * These functions parse a specific type record (id or mime) to find the * associated string. */ -near_bool_t near_ndef_record_cmp_id(struct near_ndef_record *rec1, +bool near_ndef_record_cmp_id(struct near_ndef_record *rec1, struct near_ndef_record *rec2) { DBG(""); if ((rec1 == NULL) || (rec2 == NULL)) - return FALSE; + return false; if ((rec1->header == NULL) || (rec2->header == NULL)) - return FALSE; + return false; /* usual checks */ if ((rec1->header->il_field == NULL) || (rec2->header->il_field == NULL)) - return FALSE; + return false; if (memcmp(rec1->header->il_field, rec2->header->il_field, (rec1->header->il_length) > (rec2->header->il_length) ? (rec1->header->il_length) : (rec2->header->il_length)) != 0) - return FALSE; + return false; - return TRUE; + return true; } -near_bool_t near_ndef_record_cmp_mime(struct near_ndef_record *rec1, +bool near_ndef_record_cmp_mime(struct near_ndef_record *rec1, struct near_ndef_record *rec2) { DBG(""); if ((rec1 == NULL) || (rec2 == NULL)) - return FALSE; + return false; if ((rec1->header == NULL) || (rec2->header == NULL)) - return FALSE; + return false; /* usual checks */ if ((rec1->mime == NULL) || (rec2->mime == NULL)) - return FALSE; + return false; if ((rec1->mime->type == NULL) || (rec2->mime->type == NULL)) - return FALSE; + return false; if (strlen(rec1->mime->type) != strlen(rec2->mime->type)) - return FALSE; + return false; if ((g_strcmp0(rec1->mime->type, rec2->mime->type) != 0)) - return FALSE; + return false; - return TRUE; + return true; } /* helper to get the record data length */ @@ -3172,7 +3172,7 @@ static struct near_ndef_message *build_uri_record(DBusMessage *msg) uri_prefix = __near_ndef_get_uri_prefix(i); if (uri_prefix != NULL && - g_str_has_prefix(uri, uri_prefix) == TRUE) { + g_str_has_prefix(uri, uri_prefix)) { id = i; id_len = strlen(uri_prefix); break; @@ -3207,7 +3207,7 @@ static struct near_ndef_message *build_sp_record(DBusMessage *msg) uri_prefix = __near_ndef_get_uri_prefix(i); if (uri_prefix != NULL && - g_str_has_prefix(uri, uri_prefix) == TRUE) + g_str_has_prefix(uri, uri_prefix)) break; } @@ -3350,7 +3350,8 @@ struct near_ndef_message *near_ndef_prepare_wsc_record(char *ssid, (uint8_t *) passphrase); mime = ndef_message_alloc_complete(WIFI_WSC_MIME_STRING, tlv_len, NULL, - 0, RECORD_TNF_MIME, TRUE, TRUE); + 0, RECORD_TNF_MIME, true, + true); if (mime == NULL) { g_free(tlv); return NULL; @@ -3411,7 +3412,7 @@ static struct near_ndef_message *near_ndef_prepare_mime_payload_record( DBG("Payload %*s", payload_len, payload); mime = ndef_message_alloc_complete(type, payload_len, NULL, 0, - RECORD_TNF_MIME, TRUE, TRUE); + RECORD_TNF_MIME, true, true); if (mime == NULL) { near_error("Failed to alloc NDEF message"); return NULL; @@ -3466,7 +3467,7 @@ static struct near_ndef_message *build_mime_record(DBusMessage *msg) mime = ndef_message_alloc_complete( WIFI_WSC_MIME_STRING, carrier->size, - NULL, 0, RECORD_TNF_MIME, TRUE, TRUE); + NULL, 0, RECORD_TNF_MIME, true, true); if (mime == NULL) { g_free(carrier); return NULL; @@ -35,7 +35,7 @@ struct near_device_driver; #include <near/log.h> -int __near_log_init(const char *debug, gboolean detach); +int __near_log_init(const char *debug, bool detach); void __near_log_cleanup(void); #include <near/dbus.h> @@ -67,7 +67,7 @@ DBusMessage *__near_error_invalid_property(DBusMessage *msg); DBusMessage *__near_error_io_error(DBusMessage *msg); int __near_manager_adapter_add(uint32_t idx, const char *name, - uint32_t protocols, near_bool_t powered); + uint32_t protocols, bool powered); void __near_manager_adapter_remove(uint32_t idx); int __near_manager_init(DBusConnection *conn); void __near_manager_cleanup(void); @@ -75,7 +75,7 @@ void __near_manager_cleanup(void); #include <near/adapter.h> struct near_adapter *__near_adapter_create(uint32_t idx, - const char *name, uint32_t protocols, near_bool_t powered); + const char *name, uint32_t protocols, bool powered); void __near_adapter_destroy(struct near_adapter *adapter); const char *__near_adapter_get_path(struct near_adapter *adapter); struct near_adapter *__near_adapter_get(uint32_t idx); @@ -87,8 +87,8 @@ int __near_adapter_add_target(uint32_t idx, uint32_t target_idx, int __near_adapter_remove_target(uint32_t idx, uint32_t target_idx); int __near_adapter_add_device(uint32_t idx, uint8_t *nfcid, uint8_t nfcid_len); int __near_adapter_remove_device(uint32_t idx); -int __near_adapter_set_dep_state(uint32_t idx, near_bool_t dep); -near_bool_t __near_adapter_get_dep_state(uint32_t idx); +int __near_adapter_set_dep_state(uint32_t idx, bool dep); +bool __near_adapter_get_dep_state(uint32_t idx); void __near_adapter_tags_changed(uint32_t adapter_idx); void __near_adapter_devices_changed(uint32_t adapter_idx); void __near_adapter_listen(struct near_device_driver *driver); @@ -159,7 +159,7 @@ int __near_netlink_stop_poll(int idx); int __near_netlink_dep_link_up(uint32_t idx, uint32_t target_idx, uint8_t comm_mode, uint8_t rf_mode); int __near_netlink_dep_link_down(uint32_t idx); -int __near_netlink_adapter_enable(int idx, near_bool_t enable); +int __near_netlink_adapter_enable(int idx, bool enable); int __near_netlink_init(void); void __near_netlink_cleanup(void); @@ -233,7 +233,7 @@ void __near_bluetooth_cleanup(void); void __near_bluetooth_legacy_start(void); void __near_bluetooth_legacy_stop(void); int __near_bluetooth_parse_oob_record(struct carrier_data *data, - uint16_t *properties, near_bool_t pair); + uint16_t *properties, bool pair); int __near_bluetooth_pair(void *data); struct carrier_data *__near_bluetooth_local_get_properties(uint16_t mime_props); @@ -246,7 +246,7 @@ int __near_agent_handover_register(const char *sender, const char *path, const char *carrier); int __near_agent_handover_unregister(const char *sender, const char *path, const char *carrier); -near_bool_t __near_agent_handover_registered(enum ho_agent_carrier carrier); +bool __near_agent_handover_registered(enum ho_agent_carrier carrier); struct carrier_data *__near_agent_handover_request_data( enum ho_agent_carrier carrier, diff --git a/src/netlink.c b/src/netlink.c index cf8cae8..c6028c0 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -146,7 +146,7 @@ static int get_devices_handler(struct nl_msg *n, void *arg) struct nlattr *attrs[NFC_ATTR_MAX + 1]; char *name; uint32_t idx, protocols; - near_bool_t powered; + bool powered; DBG(""); @@ -164,7 +164,7 @@ static int get_devices_handler(struct nl_msg *n, void *arg) protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]); if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL) - powered = FALSE; + powered = false; else powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]); @@ -338,7 +338,7 @@ nla_put_failure: return err; } -int __near_netlink_adapter_enable(int idx, near_bool_t enable) +int __near_netlink_adapter_enable(int idx, bool enable) { struct nl_msg *msg; void *hdr; @@ -351,7 +351,7 @@ int __near_netlink_adapter_enable(int idx, near_bool_t enable) if (msg == NULL) return -ENOMEM; - if (enable == TRUE) + if (enable) cmd = NFC_CMD_DEV_UP; else cmd = NFC_CMD_DEV_DOWN; @@ -383,7 +383,7 @@ static int no_seq_check(struct nl_msg *n, void *arg) return NL_OK; } -static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, near_bool_t add) +static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, bool add) { struct nlattr *attrs[NFC_ATTR_MAX + 1]; uint32_t idx; @@ -399,22 +399,22 @@ static int nfc_netlink_event_adapter(struct genlmsghdr *gnlh, near_bool_t add) idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]); - if (add == TRUE && + if (add && (attrs[NFC_ATTR_DEVICE_NAME] == NULL || attrs[NFC_ATTR_PROTOCOLS] == NULL)) { near_error("Missing attributes"); return -EINVAL; } - if (add == TRUE) { + if (add) { char *name; uint32_t protocols; - near_bool_t powered; + bool powered; name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]); protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]); if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL) - powered = FALSE; + powered = false; else powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]); @@ -571,7 +571,7 @@ static int nfc_netlink_event_dep_up(struct genlmsghdr *gnlh) DBG("%d %d", idx, target_idx); - return __near_adapter_set_dep_state(idx, TRUE); + return __near_adapter_set_dep_state(idx, true); } else { return -EOPNOTSUPP; } @@ -593,7 +593,7 @@ static int nfc_netlink_event_dep_down(struct genlmsghdr *gnlh) idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]); - __near_adapter_set_dep_state(idx, FALSE); + __near_adapter_set_dep_state(idx, false); return 0; } @@ -657,12 +657,12 @@ static int nfc_netlink_event(struct nl_msg *n, void *arg) break; case NFC_EVENT_DEVICE_ADDED: DBG("Adapter added"); - nfc_netlink_event_adapter(gnlh, TRUE); + nfc_netlink_event_adapter(gnlh, true); break; case NFC_EVENT_DEVICE_REMOVED: DBG("Adapter removed"); - nfc_netlink_event_adapter(gnlh, FALSE); + nfc_netlink_event_adapter(gnlh, false); break; case NFC_CMD_DEP_LINK_UP: diff --git a/src/plugin.c b/src/plugin.c index 30c8227..fbfc34d 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -37,7 +37,7 @@ static GSList *plugins = NULL; struct near_plugin { void *handle; - gboolean active; + bool active; struct near_plugin_desc *desc; }; @@ -49,32 +49,32 @@ static gint compare_priority(gconstpointer a, gconstpointer b) return plugin2->desc->priority - plugin1->desc->priority; } -static gboolean add_plugin(void *handle, struct near_plugin_desc *desc) +static bool add_plugin(void *handle, struct near_plugin_desc *desc) { struct near_plugin *plugin; if (desc->init == NULL) - return FALSE; + return false; - if (g_str_equal(desc->version, NEAR_VERSION) == FALSE) { + if (!g_str_equal(desc->version, NEAR_VERSION)) { near_error("Version mismatch for %s", desc->description); - return FALSE; + return false; } plugin = g_try_new0(struct near_plugin, 1); if (plugin == NULL) - return FALSE; + return false; plugin->handle = handle; - plugin->active = FALSE; + plugin->active = false; plugin->desc = desc; plugins = g_slist_insert_sorted(plugins, plugin, compare_priority); - return TRUE; + return true; } -static gboolean check_plugin(struct near_plugin_desc *desc, +static bool check_plugin(struct near_plugin_desc *desc, char **patterns, char **excludes) { if (excludes) { @@ -83,7 +83,7 @@ static gboolean check_plugin(struct near_plugin_desc *desc, break; if (*excludes) { near_info("Excluding %s", desc->description); - return FALSE; + return false; } } @@ -93,11 +93,11 @@ static gboolean check_plugin(struct near_plugin_desc *desc, break; if (!*patterns) { near_info("Ignoring %s", desc->description); - return FALSE; + return false; } } - return TRUE; + return true; } #include "builtin.h" @@ -121,8 +121,7 @@ int __near_plugin_init(const char *pattern, const char *exclude) excludes = g_strsplit_set(exclude, ":, ", -1); for (i = 0; __near_builtin[i]; i++) { - if (check_plugin(__near_builtin[i], - patterns, excludes) == FALSE) + if (!check_plugin(__near_builtin[i], patterns, excludes)) continue; add_plugin(NULL, __near_builtin[i]); @@ -134,8 +133,8 @@ int __near_plugin_init(const char *pattern, const char *exclude) void *handle; struct near_plugin_desc *desc; - if (g_str_has_prefix(file, "lib") == TRUE || - g_str_has_suffix(file, ".so") == FALSE) + if (g_str_has_prefix(file, "lib") || + !g_str_has_suffix(file, ".so")) continue; filename = g_build_filename(PLUGINDIR, file, NULL); @@ -158,12 +157,12 @@ int __near_plugin_init(const char *pattern, const char *exclude) continue; } - if (check_plugin(desc, patterns, excludes) == FALSE) { + if (!check_plugin(desc, patterns, excludes)) { dlclose(handle); continue; } - if (add_plugin(handle, desc) == FALSE) + if (!add_plugin(handle, desc)) dlclose(handle); } @@ -176,7 +175,7 @@ int __near_plugin_init(const char *pattern, const char *exclude) if (plugin->desc->init() < 0) continue; - plugin->active = TRUE; + plugin->active = true; } g_strfreev(patterns); @@ -194,7 +193,7 @@ void __near_plugin_cleanup(void) for (list = plugins; list; list = list->next) { struct near_plugin *plugin = list->data; - if (plugin->active == TRUE && plugin->desc->exit) + if (plugin->active && plugin->desc->exit) plugin->desc->exit(); if (plugin->handle != NULL) @@ -186,7 +186,7 @@ static int snep_core_read_ndef(int client_fd, if (snep_data->nfc_data_length == snep_data->nfc_data_current_length) return 0; - if (snep_data->respond_continue == FALSE) { + if (!snep_data->respond_continue) { snep_data->respond_continue = TRUE; near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_CONTINUE); } @@ -380,12 +380,12 @@ static int snep_core_push_prepare_fragments(struct p2p_snep_put_req_data *req, return 0; } -static near_bool_t snep_core_process_request(int client_fd, +static bool snep_core_process_request(int client_fd, struct p2p_snep_data *snep_data, near_server_io req_get, near_server_io req_put) { - near_bool_t ret; + bool ret; int err; DBG("request %d", snep_data->request); @@ -399,7 +399,7 @@ static near_bool_t snep_core_process_request(int client_fd, else { near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_NOT_IMPL); - ret = TRUE; + ret = true; } /* free and leave */ @@ -414,7 +414,7 @@ static near_bool_t snep_core_process_request(int client_fd, else { near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_NOT_IMPL); - ret = TRUE; + ret = true; } /* If there's some fragments, don't delete before the CONT */ @@ -430,10 +430,10 @@ static near_bool_t snep_core_process_request(int client_fd, DBG("NEAR_SNEP_REQ_REJECT"); if (snep_data->req->fragments == NULL) { near_error("error: NEAR_SNEP_REQ_REJECT but no fragment"); - ret = FALSE; + ret = false; } else { - ret = TRUE; + ret = true; } g_slist_free_full(snep_data->req->fragments, @@ -452,14 +452,14 @@ static near_bool_t snep_core_process_request(int client_fd, */ if (snep_data->req == NULL) { - ret = TRUE; + ret = true; break; } DBG("NEAR_SNEP_REQ_CONTINUE"); if (snep_data->req->fragments == NULL) { near_error("error: NEAR_SNEP_REQ_CONTINUE but no fragment"); - ret = FALSE; + ret = false; goto leave_cont; } @@ -467,12 +467,12 @@ static near_bool_t snep_core_process_request(int client_fd, while (g_slist_length(snep_data->req->fragments) != 0) { err = snep_core_send_fragment(snep_data->req); if (err < 0) { - ret = FALSE; + ret = false; goto leave_cont; } } - ret = TRUE; + ret = true; leave_cont: /* No more fragment to send, clean memory */ @@ -487,7 +487,7 @@ leave_cont: default: near_error("Unsupported SNEP request code"); - ret = FALSE; + ret = false; break; } @@ -510,7 +510,7 @@ leave_cont: * missing bytes (llcp removes fragmentation issues) * */ -near_bool_t near_snep_core_read(int client_fd, +bool near_snep_core_read(int client_fd, uint32_t adapter_idx, uint32_t target_idx, near_tag_io_cb cb, near_server_io req_get, @@ -550,20 +550,20 @@ near_bool_t near_snep_core_read(int client_fd, if (bytes_recv < 0) { near_error("Read error SNEP %d %s", bytes_recv, strerror(errno)); - return FALSE; + return false; } /* Check frame size */ if (bytes_recv != sizeof(frame)) { near_error("Bad frame size: %d", bytes_recv); - return FALSE; + return false; } /* If major is different, send UNSUPPORTED VERSION */ if (NEAR_SNEP_MAJOR(frame.version) != NEAR_SNEP_MAJOR(NEAR_SNEP_VERSION)) { near_error("Unsupported version (%d)", frame.version); near_snep_core_response_noinfo(client_fd, NEAR_SNEP_RESP_VERSION); - return TRUE; + return true; } /* @@ -581,7 +581,7 @@ near_bool_t near_snep_core_read(int client_fd, /* This is a new request from the client */ snep_data = g_try_malloc0(sizeof(struct p2p_snep_data)); if (snep_data == NULL) - return FALSE; + return false; /* the whole frame length */ ndef_length = GINT_FROM_BE(frame.length); @@ -589,7 +589,7 @@ near_bool_t near_snep_core_read(int client_fd, snep_data->nfc_data = g_try_malloc0(ndef_length + TLV_SIZE); if (snep_data->nfc_data == NULL) { g_free(snep_data); - return FALSE; + return false; } /* fill the struct */ @@ -636,7 +636,7 @@ static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req, struct p2p_snep_req_frame header; struct snep_fragment *fragment; uint32_t max_fragment_len; - gboolean fragmenting; + bool fragmenting; int err; int snep_req_header_length, snep_additional_length; @@ -665,10 +665,10 @@ static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req, if (max_fragment_len >= (ndef->length + snep_req_header_length)) { fragment->len = ndef->length + snep_req_header_length; - fragmenting = FALSE; + fragmenting = false; } else { fragment->len = max_fragment_len; - fragmenting = TRUE; + fragmenting = true; } fragment->data = g_try_malloc0(fragment->len); @@ -686,7 +686,7 @@ static int near_snep_core_response(int fd, struct p2p_snep_put_req_data *req, near_put_be32(snep_req_header_length, fragment->data + NEAR_SNEP_REQ_PUT_HEADER_LENGTH); - if (fragmenting == TRUE) { + if (fragmenting) { memcpy(fragment->data + snep_req_header_length, ndef->data, max_fragment_len - snep_req_header_length); ndef->offset = max_fragment_len - snep_req_header_length; @@ -47,7 +47,7 @@ struct near_tag { uint32_t type; enum near_tag_sub_type sub_type; enum near_tag_memory_layout layout; - near_bool_t readonly; + bool readonly; uint8_t nfcid[NFC_MAX_NFCID1_LEN]; uint8_t nfcid_len; @@ -57,7 +57,7 @@ struct near_tag { uint32_t n_records; GList *records; - near_bool_t blank; + bool blank; /* Tag specific structures */ struct { @@ -332,7 +332,7 @@ static DBusMessage *write_ndef(DBusConnection *conn, DBG("conn %p", conn); - if (tag->readonly == TRUE) { + if (tag->readonly) { DBG("Read only tag"); return __near_error_permission_denied(msg); } @@ -596,7 +596,7 @@ static int tag_initialize(struct near_tag *tag, tag->target_idx = target_idx; tag->protocol = protocols; tag->n_records = 0; - tag->readonly = FALSE; + tag->readonly = false; if (nfcid_len <= NFC_MAX_NFCID1_LEN) { tag->nfcid_len = nfcid_len; @@ -795,17 +795,17 @@ int near_tag_add_records(struct near_tag *tag, GList *records, return 0; } -void near_tag_set_ro(struct near_tag *tag, near_bool_t readonly) +void near_tag_set_ro(struct near_tag *tag, bool readonly) { tag->readonly = readonly; } -void near_tag_set_blank(struct near_tag *tag, near_bool_t blank) +void near_tag_set_blank(struct near_tag *tag, bool blank) { tag->blank = blank; } -near_bool_t near_tag_get_blank(struct near_tag *tag) +bool near_tag_get_blank(struct near_tag *tag) { return tag->blank; } @@ -1004,7 +1004,7 @@ int __near_tag_write(struct near_tag *tag, __near_adapter_stop_check_presence(tag->adapter_idx, tag->target_idx); - if (tag->blank == TRUE && driver->format != NULL) { + if (tag->blank && driver->format != NULL) { DBG("Blank tag detected, formatting"); err = driver->format(tag->adapter_idx, tag->target_idx, format_cb); |