{
const char *rf_mode = rf_mode_to_string(adapter);
- if (rf_mode == NULL)
+ if (!rf_mode)
return;
near_dbus_property_changed_basic(adapter->path,
DBG("%s", adapter->path);
- if (adapter->path == NULL)
+ if (!adapter->path)
return;
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
const char *tag_path;
tag_path = __near_tag_get_path(tag);
- if (tag_path == NULL)
+ if (!tag_path)
return;
DBG("%s", tag_path);
const char *device_path;
device_path = __near_device_get_path(device);
- if (device_path == NULL)
+ if (!device_path)
return;
DBG("%s", device_path);
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
near_dbus_property_changed_array(adapter->path,
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
near_dbus_property_changed_array(adapter->path,
DBG("conn %p", conn);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
DBUS_TYPE_BOOLEAN, &val);
rf_mode = rf_mode_to_string(adapter);
- if (rf_mode != NULL)
+ if (rf_mode)
near_dbus_dict_append_basic(&dict, "Mode",
DBUS_TYPE_STRING, &rf_mode);
DBG("");
- if (adapter == NULL)
+ if (!adapter)
return FALSE;
tag = adapter->tag_link;
- if (tag == NULL)
+ if (!tag)
goto out_err;
err = __near_tag_check_presence(tag, tag_present_cb);
DBG("");
- if (adapter == NULL)
+ if (!adapter)
return FALSE;
adapter_start_poll(adapter);
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
if (status < 0) {
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
adapter->presence_timeout =
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
if (adapter->presence_timeout > 0)
bool powered_setting;
adapter = g_try_malloc0(sizeof(struct near_adapter));
- if (adapter == NULL)
+ if (!adapter)
return NULL;
adapter->name = g_strdup(name);
- if (adapter->name == NULL) {
+ if (!adapter->name) {
g_free(adapter);
return NULL;
}
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
adapter->dep_up = dep;
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return false;
return adapter->dep_up;
DBG("%s", adapter->path);
- if (g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)) != NULL)
+ if (g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx)))
return -EEXIST;
g_hash_table_insert(adapter_hash, GINT_TO_POINTER(idx), adapter);
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
if (status < 0) {
adapter = g_hash_table_lookup(adapter_hash,
GINT_TO_POINTER(adapter_idx));
- if (adapter == NULL)
+ if (!adapter)
return;
if (status < 0) {
- if (adapter->device_link != NULL) {
+ if (adapter->device_link) {
__near_netlink_dep_link_down(adapter->idx);
adapter->device_link = NULL;
}
tag = __near_tag_add(adapter->idx, target_idx, protocols,
sens_res, sel_res,
nfcid, nfcid_len);
- if (tag == NULL)
+ if (!tag)
return -ENODEV;
g_hash_table_insert(adapter->tags, GINT_TO_POINTER(target_idx), tag);
int err;
device = __near_device_add(adapter->idx, target_idx, nfcid, nfcid_len);
- if (device == NULL)
+ if (!device)
return -ENODEV;
g_hash_table_insert(adapter->devices, GINT_TO_POINTER(target_idx),
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
adapter->polling = false;
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
adapter->rf_mode = NEAR_ADAPTER_RF_MODE_IDLE;
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
adapter->polling = false;
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
if (!g_hash_table_remove(adapter->devices, GINT_TO_POINTER(device_idx)))
for (list = adapter->ioreq_list; list; list = list->next) {
struct near_adapter_ioreq *req = list->data;
- if (req == NULL)
+ if (!req)
continue;
req->cb(NULL, error, req->data);
sk = g_io_channel_unix_get_fd(channel);
first = g_list_first(adapter->ioreq_list);
- if (first == NULL)
+ if (!first)
return TRUE;
req = first->data;
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
if (adapter->tag_sock != -1)
tag = g_hash_table_lookup(adapter->tags,
GINT_TO_POINTER(target_idx));
- if (tag == NULL)
+ if (!tag)
return -ENOLINK;
sock = socket(AF_NFC, SOCK_SEQPACKET, NFC_SOCKPROTO_RAW);
adapter->tag_sock = sock;
adapter->tag_link = tag;
- if (adapter->channel == NULL)
+ if (!adapter->channel)
adapter->channel = g_io_channel_unix_new(adapter->tag_sock);
g_io_channel_set_flags(adapter->channel, G_IO_FLAG_NONBLOCK, NULL);
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL)
+ if (!adapter)
return -ENODEV;
DBG("link %p", adapter->tag_link);
- if (adapter->tag_link == NULL)
+ if (!adapter->tag_link)
return -ENOLINK;
tag_type = __near_tag_get_type(adapter->tag_link);
DBG("idx %d", idx);
adapter = g_hash_table_lookup(adapter_hash, GINT_TO_POINTER(idx));
- if (adapter == NULL) {
+ if (!adapter) {
err = -ENODEV;
goto out_err;
}
- if (adapter->tag_sock == -1 || adapter->tag_link == NULL) {
+ if (adapter->tag_sock == -1 || !adapter->tag_link) {
err = -ENOLINK;
goto out_err;
}
- if (cb != NULL && adapter->watch != 0) {
+ if (cb && adapter->watch != 0) {
req = g_try_malloc0(sizeof(*req));
- if (req == NULL) {
+ if (!req) {
err = -ENOMEM;
goto out_err;
}
return err;
out_err:
- if (req != NULL) {
+ if (req) {
GList *last = g_list_last(adapter->ioreq_list);
g_free(req);
g_list_delete_link(adapter->ioreq_list, last);
}
- if (data_rel != NULL)
+ if (data_rel)
return (*data_rel)(err, data);
return err;
DBG("%s", adapter->path);
- if (adapter->path == NULL)
+ if (!adapter->path)
return;
driver->listen(adapter->idx, device_read_cb);
DBG("");
- if (agent == NULL || agent->watch == 0)
+ if (!agent || agent->watch == 0)
return;
g_dbus_remove_watch(connection, agent->watch);
struct near_ndef_agent *agent = data;
DBusMessage *message;
- if (agent == NULL)
+ if (!agent)
return;
DBG("%s %s", agent->sender, agent->path);
message = dbus_message_new_method_call(agent->sender, agent->path,
NFC_NDEF_AGENT_INTERFACE, "Release");
- if (message == NULL)
+ if (!message)
return;
dbus_message_set_no_reply(message, TRUE);
record = list->data;
path = __near_ndef_record_get_path(record);
- if (path == NULL)
+ if (!path)
continue;
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &path);
DBG("");
- if (agent->sender == NULL || agent->path == NULL)
+ if (!agent->sender || !agent->path)
return;
DBG("Sending NDEF to %s %s", agent->path, agent->sender);
message = dbus_message_new_method_call(agent->sender, agent->path,
NFC_NDEF_AGENT_INTERFACE,
"GetNDEF");
- if (message == NULL)
+ if (!message)
return;
dbus_message_iter_init_append(message, &iter);
record = list->data;
type = __near_ndef_record_get_type(record);
- if (type == NULL)
+ if (!type)
continue;
DBG("Looking for type %s", type);
agent = g_hash_table_lookup(ndef_app_hash, type);
- if (agent != NULL)
+ if (agent)
break;
}
- if (agent == NULL)
+ if (!agent)
return;
ndef_agent_push_records(agent, records);
DBG("%s registers path %s for %s", sender, path, record_type);
- if (g_hash_table_lookup(ndef_app_hash, record_type) != NULL)
+ if (g_hash_table_lookup(ndef_app_hash, record_type))
return -EEXIST;
agent = g_try_malloc0(sizeof(struct near_ndef_agent));
- if (agent == NULL)
+ if (!agent)
return -ENOMEM;
agent->sender = g_strdup(sender);
agent->path = g_strdup(path);
agent->record_type = g_strdup(record_type);
- if (agent->sender == NULL || agent->path == NULL ||
- agent->record_type == NULL) {
+ if (!agent->sender || !agent->path ||
+ !agent->record_type) {
g_free(agent);
return -ENOMEM;
}
DBG("sender %s path %s type %s", sender, path, record_type);
agent = g_hash_table_lookup(ndef_app_hash, record_type);
- if (agent == NULL)
+ if (!agent)
return -EINVAL;
if (strcmp(agent->path, path) != 0 || strcmp(agent->sender, sender) != 0)
struct carrier_data *c_data;
c_data = g_try_new0(struct carrier_data, 1);
- if (c_data == NULL)
+ if (!c_data)
return NULL;
c_data->state = CPS_UNKNOWN;
near_dbus_dict_open(&iter, &dict);
- if (data != NULL) {
+ if (data) {
void *pdata = data->data;
switch (data->type) {
agent = g_hash_table_lookup(ho_agent_hash,
GINT_TO_POINTER(carrier));
- if (agent == NULL)
+ if (!agent)
return NULL;
message = dbus_message_new_method_call(agent->sender,
agent->path, NFC_HANDOVER_AGENT_INTERFACE,
"RequestOOB");
- if (message == NULL)
+ if (!message)
return NULL;
prepare_data(message, data);
dbus_message_unref(message);
- if (reply == NULL) {
+ if (!reply) {
if (dbus_error_is_set(&error)) {
near_error("RequestOOB failed: %s", error.message);
dbus_error_free(&error);
struct near_handover_agent *agent = NULL;
agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(carrier));
- if (agent == NULL)
+ if (!agent)
return -ESRCH;
message = dbus_message_new_method_call(agent->sender,
agent->path, NFC_HANDOVER_AGENT_INTERFACE,
"PushOOB");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
prepare_data(message, data);
dbus_message_unref(message);
- if (reply != NULL) {
+ if (reply) {
dbus_message_unref(reply);
return 0;
}
{
struct near_handover_agent *agent = data;
- if (agent == NULL)
+ if (!agent)
return;
g_free(agent->sender);
DBG("data %p", data);
- if (agent == NULL)
+ if (!agent)
return;
switch (agent->carrier) {
struct near_handover_agent *agent = data;
DBusMessage *message;
- if (agent == NULL || agent->watch == 0)
+ if (!agent || agent->watch == 0)
return;
message = dbus_message_new_method_call(agent->sender, agent->path,
"org.neard.HandoverAgent",
"Release");
- if (message != NULL)
+ if (message)
g_dbus_send_message(connection, message);
}
struct near_handover_agent *agent;
agent = g_try_malloc0(sizeof(struct near_handover_agent));
- if (agent == NULL)
+ if (!agent)
return -ENOMEM;
agent->sender = g_strdup(sender);
return -EINVAL;
agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(ho_carrier));
- if (agent != NULL)
+ if (agent)
return -EEXIST;
return create_handover_agent(sender, path, ho_carrier);
ho_carrier = string2carrier(carrier);
agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(ho_carrier));
- if (agent == NULL)
+ if (!agent)
return -ESRCH;
if (strcmp(agent->path, path) != 0 ||
agent = g_hash_table_lookup(ho_agent_hash, GINT_TO_POINTER(carrier));
- return agent != NULL ? TRUE : FALSE;
+ return agent ? TRUE : FALSE;
}
int __near_agent_init(void)
DBG("");
connection = near_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -1;
ndef_app_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
{
DBG("");
- if (oob->def_adapter != NULL) {
+ if (oob->def_adapter) {
g_free(oob->def_adapter);
oob->def_adapter = NULL;
}
- if (oob->bd_addr != NULL) {
+ if (oob->bd_addr) {
g_free(oob->bd_addr);
oob->bd_addr = NULL;
}
- if (oob->bt_name != NULL) {
+ if (oob->bt_name) {
g_free(oob->bt_name);
oob->bt_name = NULL;
}
- if (oob->spair_hash != NULL) {
+ if (oob->spair_hash) {
g_free(oob->spair_hash);
oob->spair_hash = NULL;
}
- if (oob->spair_randomizer != NULL) {
+ if (oob->spair_randomizer) {
g_free(oob->spair_randomizer);
oob->spair_randomizer = NULL;
}
msg = dbus_message_new_method_call(dest, path, interface, method);
- if (msg == NULL) {
+ if (!msg) {
near_error("Unable to allocate new D-Bus %s message", method);
return -ENOMEM;
}
goto error_done;
}
- if (pending == NULL) {
+ if (!pending) {
near_error("D-Bus connection not available");
err = -EIO;
goto error_done;
DBG("");
reply = dbus_pending_call_steal_reply(pending);
- if (reply == NULL)
+ if (!reply)
return;
dbus_error_init(&error);
DBG("");
reply = dbus_pending_call_steal_reply(pending);
- if (reply == NULL)
+ if (!reply)
return;
dbus_error_init(&error);
/* Now, fill the local struct */
oob->bd_addr = g_try_malloc0(BT_ADDRESS_SIZE);
- if (oob->bd_addr == NULL)
+ if (!oob->bd_addr)
return -ENOMEM;
/* Address is like: "ff:ee:dd:cc:bb:aa" */
} 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) {
+ if (oob->bt_name) {
oob->bt_name_len = strlen(oob->bt_name);
DBG("local name: %s", oob->bt_name);
}
} else if (g_str_equal(key, "UUIDs")) {
oob->uuids_len = sizeof(value);
oob->uuids = g_try_malloc0(oob->uuids_len);
- if (oob->uuids == NULL)
+ if (!oob->uuids)
return -ENOMEM;
memcpy(oob->uuids, &value, oob->uuids_len);
}
g_free(bt_def_oob_data.bt_name);
bt_def_oob_data.bt_name = g_strdup(name);
- if (bt_def_oob_data.bt_name != NULL)
+ if (bt_def_oob_data.bt_name)
bt_def_oob_data.bt_name_len = strlen(name);
else
bt_def_oob_data.bt_name_len = 0;
DBG("");
reply = dbus_pending_call_steal_reply(pending);
- if (reply == NULL)
+ if (!reply)
return;
dbus_error_init(&error);
DBG("");
reply = dbus_pending_call_steal_reply(pending);
- if (reply == NULL)
+ if (!reply)
return;
dbus_error_init(&error);
case EIR_CLASS_OF_DEVICE:
tmp = g_strdup_printf("%02X%02X%02X",
*data, *(data + 1), *(data + 2));
- if (tmp != NULL) {
+ if (tmp) {
oob->class_of_device = strtol(tmp, NULL, 16);
*props |= OOB_PROPS_COD;
}
/* Class of device */
tmp = g_strdup_printf("%02X%02X%02X",
*ptr, *(ptr + 1), *(ptr + 2));
- if (tmp != NULL)
+ if (tmp)
oob->class_of_device = strtol(tmp, NULL, 16);
g_free(tmp);
/* check and get the default adapter */
oob->def_adapter = g_strdup(bt_def_oob_data.def_adapter);
- if (oob->def_adapter == NULL) {
+ if (!oob->def_adapter) {
near_error("bt_get_default_adapter failed");
bt_eir_free(oob);
return -EIO;
/* check and get the default adapter */
oob->def_adapter = g_strdup(bt_def_oob_data.def_adapter);
- if (oob->bt_name == NULL) {
+ if (!oob->bt_name) {
near_error("bt_get_default_adapter failed: %d", -EIO);
bt_eir_free(oob);
return -EIO;
char random[OOB_SP_SIZE];
/* Check adapter datas */
- if (bt_def_oob_data.def_adapter == NULL) {
+ if (!bt_def_oob_data.def_adapter) {
near_error("No bt adapter info");
goto fail;
}
data = g_try_malloc0(sizeof(*data));
- if (data == NULL)
+ if (!data)
goto fail;
data->size = sizeof(uint16_t) /* stored oob size */
data->size += 2 * (OOB_SP_SIZE + EIR_HEADER_LEN);
/* OOB datas */
- if (hash != NULL) {
- data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
- data->data[offset++] = EIR_SP_HASH;
- memcpy(data->data + offset, hash, OOB_SP_SIZE);
- offset += OOB_SP_SIZE;
- }
-
- if (random != NULL) {
- data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
- data->data[offset++] = EIR_SP_RANDOMIZER;
- memcpy(data->data + offset, random, OOB_SP_SIZE);
- offset += OOB_SP_SIZE;
- }
+ data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
+ data->data[offset++] = EIR_SP_HASH;
+ memcpy(data->data + offset, hash, OOB_SP_SIZE);
+ offset += OOB_SP_SIZE;
+
+ data->data[offset++] = OOB_SP_SIZE + EIR_SIZE_LEN;
+ data->data[offset++] = EIR_SP_RANDOMIZER;
+ memcpy(data->data + offset, random, OOB_SP_SIZE);
+ offset += OOB_SP_SIZE;
}
/* bt name */
- if (bt_def_oob_data.bt_name != NULL) {
+ if (bt_def_oob_data.bt_name) {
int name_len;
data->size += EIR_HEADER_LEN;
DBG("");
- if (bt_props->def_adapter == NULL)
+ if (!bt_props->def_adapter)
return TRUE;
g_dbus_remove_watch(bt_conn, adapter_props_watch);
{
DBG("");
- if (bt_conn == NULL)
+ if (!bt_conn)
return;
__near_bluetooth_legacy_stop();
/* save the dbus connection */
bt_conn = near_dbus_get_connection();
- if (bt_conn == NULL) {
+ if (!bt_conn) {
if (dbus_error_is_set(&err)) {
near_error("%s", err.message);
dbus_error_free(&err);
{
unsigned int i;
- if (ident == NULL)
+ if (!ident)
return FALSE;
for (i = 0; i < strlen(ident); i++) {
GString *str;
unsigned int i, size;
- if (value == NULL)
+ if (!value)
return NULL;
size = strlen(value);
str = g_string_new(NULL);
- if (str == NULL)
+ if (!str)
return NULL;
for (i = 0; i < size; i++) {
DBusMessage *signal;
DBusMessageIter iter;
- if (path == NULL)
+ if (!path)
return FALSE;
signal = dbus_message_new_signal(path, interface, "PropertyChanged");
- if (signal == NULL)
+ if (!signal)
return FALSE;
dbus_message_iter_init_append(signal, &iter);
DBusMessage *signal;
DBusMessageIter iter;
- if (path == NULL)
+ if (!path)
return FALSE;
signal = dbus_message_new_signal(path, interface, "PropertyChanged");
- if (signal == NULL)
+ if (!signal)
return FALSE;
dbus_message_iter_init_append(signal, &iter);
DBusMessage *signal;
DBusMessageIter iter;
- if (path == NULL)
+ if (!path)
return FALSE;
signal = dbus_message_new_signal(path, interface, "PropertyChanged");
- if (signal == NULL)
+ if (!signal)
return FALSE;
dbus_message_iter_init_append(signal, &iter);
path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
adapter_idx, target_idx);
- if (path == NULL)
+ if (!path)
return NULL;
device = g_hash_table_lookup(device_hash, path);
char *path;
path = __near_ndef_record_get_path(record);
- if (path == NULL)
+ if (!path)
continue;
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
DBG("conn %p", conn);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
conn = near_dbus_get_connection();
device = near_device_get_device(adapter_idx, target_idx);
- if (conn == NULL || device == NULL)
+ if (!conn || !device)
return;
if (status != 0) {
reply = __near_error_failed(device->push_msg, -status);
- if (reply != NULL)
+ if (reply)
g_dbus_send_message(conn, reply);
} else {
g_dbus_send_reply(conn, device->push_msg, DBUS_TYPE_INVALID);
device->push_msg = dbus_message_ref(msg);
service_name = sn_from_message(msg);
- if (service_name == NULL) {
+ if (!service_name) {
err = -EINVAL;
goto error;
}
ndef = __ndef_build_from_message(msg);
- if (ndef == NULL) {
+ if (!ndef) {
err = -EINVAL;
goto error;
}
DBG("path %s", device->path);
- if (g_hash_table_lookup(device_hash, device->path) == NULL)
+ if (!g_hash_table_lookup(device_hash, device->path))
return;
- if (device->push_msg != NULL)
+ if (device->push_msg)
push_cb(device->adapter_idx, device->target_idx, EIO);
g_dbus_unregister_interface(connection, device->path,
struct near_device *device;
device = near_device_get_device(adapter_idx, target_idx);
- if (device == NULL)
+ if (!device)
return -ENODEV;
device->data_length = data_length;
device->data = g_try_malloc0(data_length);
- if (device->data == NULL)
+ if (!device->data)
return -ENOMEM;
- if (data != NULL)
+ if (data)
memcpy(device->data, data, data_length);
return 0;
NFC_PATH, device->adapter_idx,
device->target_idx, device->n_records);
- if (path == NULL)
+ if (!path)
continue;
__near_ndef_record_register(record, path);
DBUS_TYPE_OBJECT_PATH, append_records,
device);
- if (cb != NULL)
+ if (cb)
cb(device->adapter_idx, device->target_idx, status);
g_list_free(records);
char *path;
device = near_device_get_device(adapter_idx, target_idx);
- if (device != NULL)
+ if (device)
return NULL;
device = g_try_malloc0(sizeof(struct near_device));
- if (device == NULL)
+ if (!device)
return NULL;
device->path = g_strdup_printf("%s/nfc%d/device%d", NFC_PATH,
adapter_idx, target_idx);
- if (device->path == NULL) {
+ if (!device->path) {
g_free(device);
return NULL;
}
}
path = g_strdup(device->path);
- if (path == NULL) {
+ if (!path) {
g_free(device);
return NULL;
}
{
DBG("");
- if (driver->listen == NULL)
+ if (!driver->listen)
return -EINVAL;
driver_list = g_slist_insert_sorted(driver_list, driver, cmp_prio);
{
int i;
- if (enabled == NULL)
+ if (!enabled)
return false;
- for (i = 0; enabled[i] != NULL; i++) {
- if (desc->name != NULL && g_pattern_match_simple(enabled[i],
+ for (i = 0; enabled[i]; i++) {
+ if (desc->name && g_pattern_match_simple(enabled[i],
desc->name))
return true;
- if (desc->file != NULL && g_pattern_match_simple(enabled[i],
+ if (desc->file && g_pattern_match_simple(enabled[i],
desc->file))
return true;
}
struct near_debug_desc *desc;
const char *name = NULL, *file = NULL;
- if (debug != NULL)
+ if (debug)
enabled = g_strsplit_set(debug, ":, ", 0);
for (desc = __start___debug; desc < __stop___debug; desc++) {
- if (file != NULL || name != NULL) {
+ if (file || name) {
if (g_strcmp0(desc->file, file) == 0) {
- if (desc->name == NULL)
+ if (!desc->name)
desc->name = name;
} else
file = NULL;
GError *error = NULL;
bool boolean;
- if (config == NULL)
+ if (!config)
return;
DBG("parsing main.conf");
boolean = g_key_file_get_boolean(config, "General",
"ConstantPoll", &error);
- if (error == NULL)
+ if (!error)
near_settings.constant_poll = boolean;
boolean = g_key_file_get_boolean(config, "General",
"DefaultPowered", &error);
- if (error == NULL)
+ if (!error)
near_settings.default_powered = boolean;
g_clear_error(&error);
g_option_context_add_main_entries(context, options, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
- if (error != NULL) {
+ if (error) {
g_printerr("%s\n", error->message);
g_error_free(error);
} else
dbus_error_init(&err);
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, NFC_SERVICE, &err);
- if (conn == NULL) {
+ if (!conn) {
if (dbus_error_is_set(&err)) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
DBG("conn %p", conn);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
DBG("idx %d", idx);
adapter = __near_adapter_create(idx, name, protocols, powered);
- if (adapter == NULL)
+ if (!adapter)
return -ENOMEM;
path = __near_adapter_get_path(adapter);
- if (path == NULL) {
+ if (!path) {
__near_adapter_destroy(adapter);
return -EINVAL;
}
DBG("idx %d", idx);
adapter = __near_adapter_get(idx);
- if (adapter == NULL)
+ if (!adapter)
return;
path = __near_adapter_get_path(adapter);
- if (path == NULL)
+ if (!path)
return;
size_t data_len;
data = __near_ndef_record_get_data(record, &data_len);
- if (data == NULL)
+ if (!data)
continue;
dbus_message_iter_append_fixed_array(iter, DBUS_TYPE_BYTE,
{
DBG("");
- if (text == NULL || dict == NULL)
+ if (!text || !dict)
return;
- if (text->encoding != NULL)
+ if (text->encoding)
near_dbus_dict_append_basic(dict, "Encoding",
DBUS_TYPE_STRING,
&(text->encoding));
- if (text->language_code != NULL)
+ if (text->language_code)
near_dbus_dict_append_basic(dict, "Language",
DBUS_TYPE_STRING,
&(text->language_code));
- if (text->data != NULL)
+ if (text->data)
near_dbus_dict_append_basic(dict, "Representation",
DBUS_TYPE_STRING,
&(text->data));
{
DBG("");
- if (aar == NULL || dict == NULL)
+ if (!aar || !dict)
return;
- if (aar->package != NULL)
+ if (aar->package)
near_dbus_dict_append_basic(dict, "AndroidPackage",
DBUS_TYPE_STRING,
&(aar->package));
DBG("");
- if (uri == NULL || dict == NULL)
+ if (!uri || !dict)
return;
if (uri->identifier > NFC_MAX_URI_ID) {
DBG("");
- if (sp == NULL || dict == NULL)
+ if (!sp || !dict)
return;
- if (sp->action != NULL)
+ if (sp->action)
near_dbus_dict_append_basic(dict, "Action", DBUS_TYPE_STRING,
&(sp->action));
- if (sp->uri != NULL)
+ if (sp->uri)
append_uri_payload(sp->uri, dict);
- if (sp->title_records != NULL &&
+ if (sp->title_records &&
sp->number_of_title_records > 0) {
for (i = 0; i < sp->number_of_title_records; i++)
append_text_payload(sp->title_records[i], dict);
}
- if (sp->type != NULL)
+ if (sp->type)
near_dbus_dict_append_basic(dict, "MIMEType", DBUS_TYPE_STRING,
&(sp->type));
{
DBG("");
- if (mime == NULL || dict == NULL)
+ if (!mime || !dict)
return;
- if (mime->type != NULL)
+ if (mime->type)
near_dbus_dict_append_basic(dict, "MIME",
DBUS_TYPE_STRING,
&(mime->type));
DBG("");
- if (record == NULL || dict == NULL)
+ if (!record || !dict)
return;
switch (record->header->rec_type) {
DBG("conn %p", conn);
- if (conn == NULL || msg == NULL ||
- data == NULL)
+ if (!conn || !msg ||
+ !data)
return NULL;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
static void free_text_payload(struct near_ndef_text_payload *text)
{
- if (text == NULL)
+ if (!text)
return;
g_free(text->encoding);
static void free_uri_payload(struct near_ndef_uri_payload *uri)
{
- if (uri == NULL)
+ if (!uri)
return;
g_free(uri->field);
{
uint8_t i;
- if (sp == NULL)
+ if (!sp)
return;
free_uri_payload(sp->uri);
- if (sp->title_records != NULL) {
+ if (sp->title_records) {
for (i = 0; i < sp->number_of_title_records; i++)
free_text_payload(sp->title_records[i]);
}
static void free_mime_payload(struct near_ndef_mime_payload *mime)
{
- if (mime == NULL)
+ if (!mime)
return;
g_free(mime->type);
static void free_ac_payload(struct near_ndef_ac_payload *ac)
{
- if (ac == NULL)
+ if (!ac)
return;
g_free(ac->cdr);
{
int i;
- if (ho == NULL)
+ if (!ho)
return;
- if (ho->ac_payloads != NULL) {
+ if (ho->ac_payloads) {
for (i = 0; i < ho->number_of_ac_payloads; i++)
free_ac_payload(ho->ac_payloads[i]);
}
static void free_aar_payload(struct near_ndef_aar_payload *aar)
{
- if (aar == NULL)
+ if (!aar)
return;
g_free(aar->package);
static void free_ndef_record(struct near_ndef_record *record)
{
- if (record == NULL)
+ if (!record)
return;
g_free(record->path);
- if (record->header != NULL) {
+ if (record->header) {
switch (record->header->rec_type) {
case RECORD_TYPE_WKT_SIZE:
static void free_ndef_message(struct near_ndef_message *msg)
{
- if (msg == NULL)
+ if (!msg)
return;
g_free(msg->data);
DBG("");
- if (rec == NULL || rec->header == NULL)
+ if (!rec || !rec->header)
return -EINVAL;
tnf = rec->header->tnf;
{
DBG("");
- if (msg_mb == NULL || msg_me == NULL)
+ if (!msg_mb || !msg_me)
return 0;
/* Validating record header begin and end bits
DBG("length %d", length);
- if (rec == NULL || offset >= length)
+ if (!rec || offset >= length)
return NULL;
/* This check is for empty record. */
return NULL;
rec_header = g_try_malloc0(sizeof(struct near_ndef_record_header));
- if (rec_header == NULL)
+ if (!rec_header)
return NULL;
rec_header->mb = RECORD_MB_BIT(rec[offset]);
goto fail;
type = g_try_malloc0(rec_header->type_len);
- if (type == NULL)
+ if (!type)
goto fail;
memcpy(type, rec + offset, rec_header->type_len);
goto fail;
rec_header->il_field = g_try_malloc0(rec_header->il_length);
- if (rec_header->il_field == NULL)
+ if (!rec_header->il_field)
goto fail;
memcpy(rec_header->il_field, rec + offset,
DBG("");
- if (payload == NULL)
+ if (!payload)
return NULL;
offset = 0;
text_payload = g_try_malloc0(sizeof(struct near_ndef_text_payload));
- if (text_payload == NULL)
+ if (!text_payload)
return NULL;
/* 0x80 is used to get 7th bit value (0th bit is LSB) */
DBG("");
- if (payload == NULL)
+ if (!payload)
return NULL;
offset = 0;
uri_payload = g_try_malloc0(sizeof(struct near_ndef_uri_payload));
- if (uri_payload == NULL)
+ if (!uri_payload)
return NULL;
uri_payload->identifier = payload[offset];
if (uri_payload->field_length > 0) {
uri_payload->field = g_try_malloc0(uri_payload->field_length);
- if (uri_payload->field == NULL)
+ if (!uri_payload->field)
goto fail;
memcpy(uri_payload->field, payload + offset,
DBG("");
- if (titles == NULL)
+ if (!titles)
return -EINVAL;
length = g_slist_length(titles);
for (j = i + 1; j < length; j++) {
title2 = g_slist_nth_data(titles, j);
- if ((title1->language_code == NULL) &&
- (title2->language_code == NULL))
+ if ((!title1->language_code) &&
+ (!title2->language_code))
continue;
if (g_strcmp0(title1->language_code,
DBG("");
- if (payload == NULL)
+ if (!payload)
return NULL;
offset = 0;
sp_payload = g_try_malloc0(sizeof(struct near_ndef_sp_payload));
- if (sp_payload == NULL)
+ if (!sp_payload)
return NULL;
while (offset < length) {
DBG("Record header : 0x%x", payload[offset]);
rec_header = parse_record_header(payload, offset, length);
- if (rec_header == NULL)
+ if (!rec_header)
goto fail;
if (validate_record_begin_and_end_bits(&mb, &me,
case RECORD_TYPE_WKT_URI:
/* URI record should be only one. */
- if (sp_payload->uri != NULL)
+ if (sp_payload->uri)
goto fail;
sp_payload->uri = parse_uri_payload(payload + offset,
rec_header->payload_len);
- if (sp_payload->uri == NULL)
+ if (!sp_payload->uri)
goto fail;
break;
struct near_ndef_text_payload *title;
title = parse_text_payload(payload + offset,
rec_header->payload_len);
- if (title == NULL)
+ if (!title)
goto fail;
titles = g_slist_append(titles, title);
if (rec_header->payload_len > 0) {
sp_payload->type = g_try_malloc0(
rec_header->payload_len);
- if (sp_payload->type == NULL)
+ if (!sp_payload->type)
goto fail;
sp_payload->type = g_strndup(
* Code to fill smart poster record structure from
* 'titles' list.
*/
- if (titles == NULL)
+ if (!titles)
return sp_payload;
if (validate_language_code_in_sp_record(titles) != 0) {
sp_payload->title_records = g_try_malloc0(
sp_payload->number_of_title_records *
sizeof(struct near_ndef_text_payload *));
- if (sp_payload->title_records == NULL)
+ if (!sp_payload->title_records)
goto fail;
for (i = 0; i < sp_payload->number_of_title_records; i++) {
fail:
near_error("smart poster payload parsing failed");
- if (rec_header != NULL) {
+ if (rec_header) {
g_free(rec_header->type_name);
g_free(rec_header->il_field);
g_free(rec_header);
DBG("");
- if (mime == NULL || c_data == NULL)
+ if (!mime || !c_data)
return -EINVAL;
switch (mime->handover.carrier_type) {
DBG("");
- if (c_data == NULL || ndef_data == NULL ||
+ if (!c_data || !ndef_data ||
((offset + payload_length) > ndef_length))
return NULL;
mime = g_try_malloc0(sizeof(struct near_ndef_mime_payload));
- if (mime == NULL)
+ if (!mime)
return NULL;
c_temp = g_try_malloc0(sizeof(struct carrier_data));
- if (c_temp == NULL) {
+ if (!c_temp) {
g_free(mime);
return NULL;
}
uint8_t hdr = 0, type_len, sr_bit, il_bit, id_len;
msg = g_try_malloc0(sizeof(struct near_ndef_message));
- if (msg == NULL)
+ if (!msg)
return NULL;
msg->length = 0;
msg->length++; /* record header*/
msg->length++; /* type name length byte*/
- type_len = (type_name != NULL) ? strlen(type_name) : 0;
- id_len = (payload_id != NULL) ? payload_id_len : 0;
+ type_len = (type_name) ? strlen(type_name) : 0;
+ id_len = (payload_id) ? payload_id_len : 0;
sr_bit = (payload_len <= NDEF_MSG_SHORT_RECORD_MAX_LENGTH)
? TRUE : FALSE;
- il_bit = (payload_id != NULL) ? TRUE : FALSE;
+ il_bit = (payload_id) ? TRUE : FALSE;
msg->length += (sr_bit) ? 1 : 4;
msg->length += (il_bit) ? 1 : 0;
msg->length += id_len;
msg->data = g_try_malloc0(msg->length);
- if (msg->data == NULL)
+ if (!msg->data)
goto fail;
/* Set MB ME bits */
if (il_bit)
msg->data[msg->offset++] = payload_id_len;
- if (type_name != NULL) {
+ if (type_name) {
memcpy(msg->data + msg->offset, type_name, type_len);
msg->offset += type_len;
}
DBG("");
- if (payload == NULL)
+ if (!payload)
return NULL;
offset = 0;
ac_payload = g_try_malloc0(sizeof(struct near_ndef_ac_payload));
- if (ac_payload == NULL)
+ if (!ac_payload)
goto fail;
/* Carrier flag */
/* Carrier data reference */
ac_payload->cdr = g_try_malloc0(ac_payload->cdr_len + 1);
- if (ac_payload->cdr == NULL)
+ if (!ac_payload->cdr)
goto fail;
memcpy(ac_payload->cdr, payload + offset, ac_payload->cdr_len);
/* save the auxiliary data reference */
ac_payload->adata = g_try_malloc0(
ac_payload->adata_refcount * sizeof(uint16_t));
- if (ac_payload->adata == NULL)
+ if (!ac_payload->adata)
goto fail;
memcpy(ac_payload->adata, payload + offset,
NULL, 0,
RECORD_TNF_WELLKNOWN,
true, true);
- if (ac_msg == NULL)
+ if (!ac_msg)
return NULL;
/* Prepare ac message */
NULL, 0,
RECORD_TNF_WELLKNOWN,
true, true);
- if (cr_msg == NULL)
+ if (!cr_msg)
return NULL;
/* Prepare ac message */
DBG(" %s", mime_type);
- if (mime_type == NULL)
+ if (!mime_type)
return NULL;
msg = ndef_message_alloc_complete(mime_type, data_len, cdr, cdr_len,
RECORD_TNF_MIME, true, true);
- if (msg == NULL)
+ if (!msg)
return NULL;
/* store data */
DBG("");
- if (ac == NULL || cfg == NULL)
+ if (!ac || !cfg)
return -EINVAL;
switch (carrier) {
mime_type = BT_MIME_STRING_2_1;
local_carrier = __near_agent_handover_request_data(
HO_AGENT_BT, remote_carrier);
- if (local_carrier != NULL)
+ if (local_carrier)
break;
- prop = (mime != NULL) ? mime->handover.properties :
+ prop = (mime) ? mime->handover.properties :
OOB_PROPS_EMPTY;
local_carrier = __near_bluetooth_local_get_properties(prop);
* Handover Select.
* In those 2 cases we return an error.
*/
- if (carrier == NEAR_CARRIER_WIFI && remote_carrier == NULL) {
- if (local_carrier != NULL &&
+ if (carrier == NEAR_CARRIER_WIFI && !remote_carrier) {
+ if (local_carrier &&
type == RECORD_TYPE_WKT_HANDOVER_REQUEST) {
g_free(local_carrier);
return -EINVAL;
}
- if (local_carrier == NULL &&
+ if (!local_carrier &&
type == RECORD_TYPE_WKT_HANDOVER_SELECT)
return -EINVAL;
- if (local_carrier == NULL &&
+ if (!local_carrier &&
type == RECORD_TYPE_WKT_HANDOVER_REQUEST) {
*cfg = near_ndef_prepare_cfg_message(mime_type,
NULL, 0,
}
}
- if (local_carrier == NULL) {
+ if (!local_carrier) {
DBG("Unable to retrieve local carrier %s data", carrier_string);
return -ESRCH;
}
g_free(local_carrier);
- if (*cfg == NULL || *ac == NULL) {
+ if (!*cfg || !*ac) {
free_ndef_message(*ac);
free_ndef_message(*cfg);
struct near_ndef_message *ho_msg;
ho_msg = ndef_message_alloc(type, msg_len);
- if (ho_msg == NULL)
+ if (!ho_msg)
return NULL;
/*
struct near_ndef_message *msg;
uint32_t length = 0;
- if (list == NULL)
+ if (!list)
return 0;
while (list) {
GList *temp = acs;
struct near_ndef_message *ac;
- if (ho == NULL || temp == NULL)
+ if (!ho || !temp)
return;
while (temp) {
struct near_ndef_message *cfg;
uint32_t offset;
- if (ho == NULL || temp == NULL)
+ if (!ho || !temp)
return;
offset = ho->offset;
DBG("");
ac_msg = near_ndef_prepare_ac_message(CPS_UNKNOWN, &cdr, sizeof(cdr));
- if (ac_msg == NULL)
+ if (!ac_msg)
return NULL;
hs_length = 1;
hs_length += ac_msg->length;
hs_msg = prepare_handover_message_header("Hs", hs_length, hs_length);
- if (hs_msg == NULL)
+ if (!hs_msg)
goto fail;
near_ndef_set_mb_me(hs_msg->data, true, true);
* alternative carries or unknown mime types or unknown
* configuration data.
*/
- if ((remote_mimes == NULL || remote_cfgs == NULL))
+ if ((!remote_mimes || !remote_cfgs))
return near_ndef_prepare_empty_hs_message();
mime_iter = remote_mimes;
while (mime_iter) {
remote_mime = mime_iter->data;
remote_cfg = cfg_iter->data;
- if (remote_mime == NULL || remote_cfg == NULL)
+ if (!remote_mime || !remote_cfg)
goto fail;
ret = near_ndef_prepare_ac_and_cfg_records(
hs_length += ndef_message_list_length(cfg_msgs);
hs_msg = prepare_handover_message_header("Hs", hs_length, hs_pl_length);
- if (hs_msg == NULL)
+ if (!hs_msg)
goto fail;
num_of_carriers = g_list_length(ac_msgs);
if (type == RECORD_TYPE_WKT_HANDOVER_REQUEST) {
collision = GUINT16_TO_BE(g_random_int_range(0, G_MAXUINT16 + 1));
cr_msg = near_ndef_prepare_cr_message(collision);
- if (cr_msg == NULL)
+ if (!cr_msg)
goto fail;
near_ndef_set_mb_me(cr_msg->data, true, false);
ho_msg = prepare_handover_message_header(str_type,
ho_length, ho_pl_length);
- if (ho_msg == NULL)
+ if (!ho_msg)
goto fail;
g_list_foreach(ac_msgs, set_mb_me_to_false, NULL);
rec_count = g_slist_length(acs);
ho->ac_payloads = g_try_malloc0(rec_count *
sizeof(struct near_ndef_ac_payload *));
- if (ho->ac_payloads == NULL)
+ if (!ho->ac_payloads)
goto fail;
temp = acs;
for (i = 0; i < rec_count; i++) {
rec_count = g_slist_length(mimes);
ho->cfg_payloads = g_try_malloc0(rec_count *
sizeof(struct near_ndef_mime_payload *));
- if (ho->cfg_payloads == NULL)
+ if (!ho->cfg_payloads)
goto fail;
temp = mimes;
for (i = 0; i < rec_count; i++) {
DBG("");
- if (payload == NULL)
+ if (!payload)
return NULL;
offset = 0;
/* Create the handover record payload */
ho_payload = g_try_malloc0(sizeof(struct near_ndef_ho_payload));
- if (ho_payload == NULL)
+ if (!ho_payload)
return NULL;
/* Version is the first mandatory field of hr payload */
HANDOVER_MAJOR(HANDOVER_VERSION)) {
near_error("Unsupported version (%d)", ho_payload->version);
/* Skip parsing and return an empty record */
- if (reply != NULL)
+ if (reply)
*reply = near_ndef_prepare_empty_hs_message();
return ho_payload;
while (offset < ho_length) {
/* Create local record for mime parsing */
trec = g_try_malloc0(sizeof(struct near_ndef_record));
- if (trec == NULL)
+ if (!trec)
return NULL;
trec->header = parse_record_header(payload, offset, ho_length);
- if (trec->header == NULL)
+ if (!trec->header)
goto fail;
offset = trec->header->offset;
&c_data);
trec->ho = NULL;
- if (mime == NULL || c_data == NULL)
+ if (!mime || !c_data)
goto fail;
/* add the mime to the list */
ac = parse_ac_payload(payload + offset,
trec->header->payload_len);
- if (ac == NULL)
+ if (!ac)
goto fail;
acs = g_slist_append(acs, ac);
DBG("could not process alternative carriers");
goto fail;
}
- } else if (reply != NULL) {
+ } else if (reply) {
/* This is a Hs with no cfg and no Ac: No reply and fail */
if (rec_type == RECORD_TYPE_WKT_HANDOVER_SELECT &&
g_slist_length(acs) == 0) {
/* Prepare Hs, it depends upon Hr message carrier types */
*reply = near_ndef_prepare_hs_reply(mimes, c_datas);
- if (*reply == NULL) {
+ if (!*reply) {
DBG("error in preparing in HS record");
goto fail;
}
}
- if ((acs == NULL) || (mimes == NULL))
+ if ((!acs) || (!mimes))
return ho_payload;
/* Save the records */
fail:
near_error("handover payload parsing failed");
- if (trec != NULL) {
- if (trec->header != NULL) {
+ if (trec) {
+ if (trec->header) {
g_free(trec->header->type_name);
g_free(trec->header->il_field);
g_free(trec->header);
DBG("");
- if (payload == NULL)
+ if (!payload)
return NULL;
aar_payload = g_try_malloc0(sizeof(struct near_ndef_uri_payload));
- if (aar_payload == NULL)
+ if (!aar_payload)
return NULL;
aar_payload->package = g_strndup((char *)payload, length);
- if (aar_payload->package == NULL) {
+ if (!aar_payload->package) {
near_error("AAR payload parsing failed");
free_aar_payload(aar_payload);
return NULL;
{
DBG("");
- if ((rec1 == NULL) || (rec2 == NULL))
+ if ((!rec1) || (!rec2))
return false;
- if ((rec1->header == NULL) || (rec2->header == NULL))
+ if ((!rec1->header) || (!rec2->header))
return false;
/* usual checks */
- if ((rec1->header->il_field == NULL) ||
- (rec2->header->il_field == NULL))
+ if ((!rec1->header->il_field) ||
+ (!rec2->header->il_field))
return false;
if (memcmp(rec1->header->il_field, rec2->header->il_field,
DBG("");
- if ((rec1 == NULL) || (rec2 == NULL))
+ if ((!rec1) || (!rec2))
return false;
- if ((rec1->header == NULL) || (rec2->header == NULL))
+ if ((!rec1->header) || (!rec2->header))
return false;
/* usual checks */
- if ((rec1->mime == NULL) || (rec2->mime == NULL))
+ if ((!rec1->mime) || (!rec2->mime))
return false;
- if ((rec1->mime->type == NULL) || (rec2->mime->type == NULL))
+ if ((!rec1->mime->type) || (!rec2->mime->type))
return false;
if (strlen(rec1->mime->type) != strlen(rec2->mime->type))
/* helper to get the record data length */
size_t near_ndef_data_length(struct near_ndef_record *rec)
{
- if (rec == NULL)
+ if (!rec)
return 0;
else
return rec->data_len;
/* helper to get the record data pointer */
uint8_t *near_ndef_data_ptr(struct near_ndef_record *rec)
{
- if (rec == NULL)
+ if (!rec)
return NULL;
else
return rec->data;
records = NULL;
- if (ndef_data == NULL ||
+ if (!ndef_data ||
ndef_length < NDEF_MSG_MIN_LENGTH)
goto fail;
DBG("Record Header : 0x%X", ndef_data[offset]);
record = g_try_malloc0(sizeof(struct near_ndef_record));
- if (record == NULL)
+ if (!record)
goto fail;
record->header = parse_record_header(ndef_data, offset,
ndef_length);
- if (record->header == NULL)
+ if (!record->header)
goto fail;
if (validate_record_begin_and_end_bits(&p_mb, &p_me,
ndef_length - offset,
record->header->mb, record->header->me,
reply);
- if (record->ho == NULL)
+ if (!record->ho)
goto fail;
/* the complete frame is processed, break the loop */
record->text = parse_text_payload(ndef_data + offset,
record->header->payload_len);
- if (record->text == NULL)
+ if (!record->text)
goto fail;
break;
record->uri = parse_uri_payload(ndef_data + offset,
record->header->payload_len);
- if (record->uri == NULL)
+ if (!record->uri)
goto fail;
break;
ndef_data + offset,
record->header->payload_len);
- if (record->sp == NULL)
+ if (!record->sp)
goto fail;
break;
ndef_length, offset,
record->header->payload_len,
&c_data);
- if (record->mime == NULL)
+ if (!record->mime)
goto fail;
/* No carrier data, move on */
- if (c_data == NULL)
+ if (!c_data)
break;
if (process_mime_type(record->mime, c_data) < 0) {
record->aar = parse_aar_payload(ndef_data + offset,
record->header->payload_len);
- if (record->aar == NULL)
+ if (!record->aar)
goto fail;
break;
record->header->payload_len;
record->data = g_try_malloc0(record->data_len);
- if (record->data == NULL)
+ if (!record->data)
goto fail;
memcpy(record->data, record_start, record->data_len);
offset = 0;
- if (ndef_in == NULL || ndef_in_length < NDEF_MSG_MIN_LENGTH) {
+ if (!ndef_in || ndef_in_length < NDEF_MSG_MIN_LENGTH) {
err = -EINVAL;
goto fail;
}
while (offset < ndef_in_length) {
record = g_try_malloc0(sizeof(struct near_ndef_record));
- if (record == NULL) {
+ if (!record) {
err = -ENOMEM;
goto fail;
}
/* Create a record */
record->header = parse_record_header(ndef_in, offset,
ndef_in_length);
- if (record->header == NULL) {
+ if (!record->header) {
err = -EINVAL;
goto fail;
}
/* Validate input parameters*/
if (((g_strcmp0(encoding, "UTF-8") != 0) &&
(g_strcmp0(encoding, "UTF-16") != 0)) ||
- (language_code == NULL) ||
- (text == NULL)) {
+ (!language_code) ||
+ (!text)) {
return NULL;
}
payload_length = 1 + code_len + text_len;
msg = ndef_message_alloc("T", payload_length);
- if (msg == NULL)
+ if (!msg)
return NULL;
if (g_strcmp0(encoding, "UTF-16") == 0)
DBG("");
/* Validate input parameters*/
- if ((field_length == 0 && field != NULL) ||
- (field_length != 0 && field == NULL)) {
+ if ((field_length == 0 && field) ||
+ (field_length != 0 && !field)) {
return NULL;
}
payload_length = field_length + 1;
msg = ndef_message_alloc("U", payload_length);
- if (msg == NULL)
+ if (!msg)
return NULL;
msg->data[msg->offset++] = identifier;
/* URI is mandatory in Smartposter */
uri = near_ndef_prepare_uri_record(uri_identifier, uri_field_length,
uri_field);
- if (uri == NULL)
+ if (!uri)
goto fail;
/* URI record length is equal to payload length of Sp record */
msg = ndef_message_alloc("Sp", uri->length);
- if (msg == NULL)
+ if (!msg)
goto fail;
memcpy(msg->data + msg->offset, uri->data, uri->length);
DBG("");
- if (text == NULL)
+ if (!text)
return NULL;
dbus_message_iter_init(msg, &iter);
DBG("");
carrier = get_text_field(msg, "Carrier");
- if (carrier == NULL)
+ if (!carrier)
return NULL;
arr = g_strsplit(carrier, ",", NEAR_CARRIER_MAX);
DBG("");
uri = get_uri_field(msg);
- if (uri == NULL)
+ if (!uri)
return NULL;
id = 0;
for (i = 1; i <= NFC_MAX_URI_ID; i++) {
uri_prefix = __near_ndef_get_uri_prefix(i);
- if (uri_prefix != NULL &&
+ if (uri_prefix &&
g_str_has_prefix(uri, uri_prefix)) {
id = i;
id_len = strlen(uri_prefix);
* TODO: Other records support.
*/
uri = get_uri_field(msg);
- if (uri == NULL)
+ if (!uri)
return NULL;
for (i = 1; i <= NFC_MAX_URI_ID; i++) {
uri_prefix = __near_ndef_get_uri_prefix(i);
- if (uri_prefix != NULL &&
+ if (uri_prefix &&
g_str_has_prefix(uri, uri_prefix))
break;
}
- if (uri_prefix == NULL) {
+ if (!uri_prefix) {
i = 0;
id_len = 0;
} else
{
int offset = 0;
- if (tlv == NULL || data == NULL)
+ if (!tlv || !data)
return 0;
fillb16(tlv, id);
struct near_ndef_message *mime;
/* At least SSID is required in case of open network */
- if (ssid == NULL)
+ if (!ssid)
return NULL;
DBG("SSID %s Passphrase %s", ssid, passphrase);
/* Prepare TLV from ssid and passphrasse */
ssid_len = strlen(ssid);
- if (passphrase != NULL) {
+ if (passphrase) {
pass_len = strlen(passphrase);
key_type = WIFI_WSC_KEY_PSK;
} else {
/* add authentication type length */
tlv_len += WIFI_WSC_ID_LENGTH + WIFI_WSC_ID_DATA_LENGTH + 2;
/* add network key length */
- if (passphrase != NULL)
+ if (passphrase)
tlv_len += WIFI_WSC_ID_LENGTH +
WIFI_WSC_ID_DATA_LENGTH + pass_len;
tlv = g_try_malloc0(tlv_len);
- if (tlv == NULL)
+ if (!tlv)
return NULL;
offset = 0;
(uint8_t *) temp_key);
/* copy Network Key */
- if (passphrase != NULL)
+ if (passphrase)
offset += fill_wifi_wsc_data(tlv + offset, WIFI_WSC_ID_KEY,
pass_len,
(uint8_t *) passphrase);
mime = ndef_message_alloc_complete(WIFI_WSC_MIME_STRING, tlv_len, NULL,
0, RECORD_TNF_MIME, true,
true);
- if (mime == NULL) {
+ if (!mime) {
g_free(tlv);
return NULL;
}
{
DBG("");
- if (payload == NULL || payload_len == NULL) {
+ if (!payload || !payload_len) {
near_error("Payload %p payload_len %p", payload, payload_len);
return NULL;
}
DBG("Payload %*s", payload_len, payload);
mime = ndef_message_alloc_complete(type, payload_len, NULL, 0,
RECORD_TNF_MIME, true, true);
- if (mime == NULL) {
+ if (!mime) {
near_error("Failed to alloc NDEF message");
return NULL;
}
struct carrier_data *carrier;
get_wsc_data(arr_iter, &ssid, &passphrase);
- if (ssid != NULL)
+ if (ssid)
return near_ndef_prepare_wsc_record(
ssid, passphrase);
*/
carrier = __near_agent_handover_request_data(
HO_AGENT_WIFI, NULL);
- if (carrier == NULL)
+ if (!carrier)
return NULL;
mime = ndef_message_alloc_complete(
WIFI_WSC_MIME_STRING, carrier->size,
NULL, 0, RECORD_TNF_MIME, true, true);
- if (mime == NULL) {
+ if (!mime) {
g_free(carrier);
return NULL;
}
DBG("mime string %s", mime_str);
dbus_message_iter_recurse(&iter, &payload_iter);
- if (get_mime_payload_data(payload_iter,
- &payload, &payload_len) == NULL)
+ if (!get_mime_payload_data(payload_iter,
+ &payload, &payload_len))
return NULL;
return near_ndef_prepare_mime_payload_record(
DBG("");
cb = nl_cb_alloc(NL_CB_DEFAULT);
- if (cb == NULL)
+ if (!cb)
return -ENOMEM;
err = nl_send_auto_complete(sock, msg);
nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &done);
nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &done);
- if (rx_handler != NULL)
+ if (rx_handler)
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, rx_handler, data);
while (err == 0 && done == 0)
genlmsg_parse(nlh, 0, attrs, NFC_ATTR_MAX, NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL ||
- attrs[NFC_ATTR_DEVICE_NAME] == NULL ||
- attrs[NFC_ATTR_PROTOCOLS] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX] ||
+ !attrs[NFC_ATTR_DEVICE_NAME] ||
+ !attrs[NFC_ATTR_PROTOCOLS]) {
nl_perror(NLE_MISSING_ATTR, "NFC_CMD_GET_DEVICE");
return NL_STOP;
}
name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
- if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL)
+ if (!attrs[NFC_ATTR_DEVICE_POWERED])
powered = false;
else
powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
DBG("");
- if (nfc_state == NULL || nfc_state->nfc_id < 0)
+ if (!nfc_state || nfc_state->nfc_id < 0)
return -ENODEV;
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_DUMP, NFC_CMD_GET_DEVICE, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto out;
}
DBG("IM protos 0x%x TM protos 0x%x", im_protocols, tm_protocols);
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_START_POLL, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_STOP_POLL, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_DEP_LINK_UP, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, NFC_CMD_DEP_LINK_DOWN, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
if (enable)
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_REQUEST, cmd, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
near_error("Missing device index");
return -ENODEV;
}
idx = nla_get_u32(attrs[NFC_ATTR_DEVICE_INDEX]);
if (add &&
- (attrs[NFC_ATTR_DEVICE_NAME] == NULL ||
- attrs[NFC_ATTR_PROTOCOLS] == NULL)) {
+ (!attrs[NFC_ATTR_DEVICE_NAME] ||
+ !attrs[NFC_ATTR_PROTOCOLS])) {
near_error("Missing attributes");
return -EINVAL;
}
name = nla_get_string(attrs[NFC_ATTR_DEVICE_NAME]);
protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
- if (attrs[NFC_ATTR_DEVICE_POWERED] == NULL)
+ if (!attrs[NFC_ATTR_DEVICE_POWERED])
powered = false;
else
powered = nla_get_u8(attrs[NFC_ATTR_DEVICE_POWERED]);
target_idx = nla_get_u32(attrs[NFC_ATTR_TARGET_INDEX]);
protocols = nla_get_u32(attrs[NFC_ATTR_PROTOCOLS]);
- if (attrs[NFC_ATTR_TARGET_SENS_RES] != NULL)
+ if (attrs[NFC_ATTR_TARGET_SENS_RES])
sens_res =
nla_get_u16(attrs[NFC_ATTR_TARGET_SENS_RES]);
- if (attrs[NFC_ATTR_TARGET_SEL_RES] != NULL)
+ if (attrs[NFC_ATTR_TARGET_SEL_RES])
sel_res =
nla_get_u16(attrs[NFC_ATTR_TARGET_SEL_RES]);
- if (attrs[NFC_ATTR_TARGET_NFCID1] != NULL) {
+ if (attrs[NFC_ATTR_TARGET_NFCID1]) {
nfcid_len = nla_len(attrs[NFC_ATTR_TARGET_NFCID1]);
if (nfcid_len <= NFC_MAX_NFCID1_LEN)
memcpy(nfcid, nla_data(attrs[NFC_ATTR_TARGET_NFCID1]),
nla_parse(attr, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attr[NFC_ATTR_DEVICE_INDEX] == NULL)
+ if (!attr[NFC_ATTR_DEVICE_INDEX])
return -ENODEV;
adapter_idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
DBG("adapter %d", adapter_idx);
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, nfc_state->nfc_id, 0,
NLM_F_DUMP, NFC_CMD_GET_TARGET, NFC_GENL_VERSION);
- if (hdr == NULL) {
+ if (!hdr) {
err = -EINVAL;
goto nla_put_failure;
}
nla_parse(attr, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attr[NFC_ATTR_DEVICE_INDEX] == NULL)
+ if (!attr[NFC_ATTR_DEVICE_INDEX])
return -ENODEV;
- if (attr[NFC_ATTR_TARGET_INDEX] == NULL)
+ if (!attr[NFC_ATTR_TARGET_INDEX])
return -ENODEV;
adapter_idx = nla_get_u32(attr[NFC_ATTR_DEVICE_INDEX]);
nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
near_error("Missing device index");
return -ENODEV;
}
- if (attrs[NFC_ATTR_COMM_MODE] == NULL ||
- attrs[NFC_ATTR_RF_MODE] == NULL) {
+ if (!attrs[NFC_ATTR_COMM_MODE] ||
+ !attrs[NFC_ATTR_RF_MODE]) {
near_error("Missing rf or comm modes");
return -ENODEV;
}
rf_mode = nla_get_u8(attrs[NFC_ATTR_RF_MODE]);
if (rf_mode == NFC_RF_INITIATOR) {
- if (attrs[NFC_ATTR_TARGET_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_TARGET_INDEX]) {
near_error("Missing target index");
return -ENODEV;
};
nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
near_error("Missing device index");
return -ENODEV;
}
nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
near_error("Missing device index");
return -ENODEV;
}
nla_parse(attrs, NFC_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
genlmsg_attrlen(gnlh, 0), NULL);
- if (attrs[NFC_ATTR_DEVICE_INDEX] == NULL) {
+ if (!attrs[NFC_ATTR_DEVICE_INDEX]) {
near_error("Missing device index");
return -ENODEV;
}
return FALSE;
cb = nl_cb_alloc(NL_CB_VERBOSE);
- if (cb == NULL)
+ if (!cb)
return TRUE;
nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
DBG("");
msg = nlmsg_alloc();
- if (msg == NULL)
+ if (!msg)
return -ENOMEM;
ctrlid = genl_ctrl_resolve(sock, "nlctrl");
DBG("");
nfc_state = g_try_malloc0(sizeof(struct nlnfc_state));
- if (nfc_state == NULL)
+ if (!nfc_state)
return -ENOMEM;
nfc_state->cmd_sock = nl_socket_alloc();
- if (nfc_state->cmd_sock == NULL) {
+ if (!nfc_state->cmd_sock) {
near_error("Failed to allocate NFC command netlink socket");
err = -ENOMEM;
goto state_free;
}
nfc_state->event_sock = nl_socket_alloc();
- if (nfc_state->event_sock == NULL) {
+ if (!nfc_state->event_sock) {
near_error("Failed to allocate NFC event netlink socket");
err = -ENOMEM;
goto handle_cmd_destroy;
void __near_netlink_cleanup(void)
{
- if (netlink_channel != NULL) {
+ if (netlink_channel) {
g_io_channel_shutdown(netlink_channel, TRUE, NULL);
g_io_channel_unref(netlink_channel);
netlink_channel = NULL;
}
- if (nfc_state == NULL)
+ if (!nfc_state)
return;
nl_socket_free(nfc_state->cmd_sock);
{
struct near_plugin *plugin;
- if (desc->init == NULL)
+ if (!desc->init)
return false;
if (!g_str_equal(desc->version, NEAR_VERSION)) {
}
plugin = g_try_new0(struct near_plugin, 1);
- if (plugin == NULL)
+ if (!plugin)
return false;
plugin->handle = handle;
}
dir = g_dir_open(PLUGINDIR, 0, NULL);
- if (dir != NULL) {
- while ((file = g_dir_read_name(dir)) != NULL) {
+ if (dir) {
+ while ((file = g_dir_read_name(dir))) {
void *handle;
struct near_plugin_desc *desc;
filename = g_build_filename(PLUGINDIR, file, NULL);
handle = dlopen(filename, RTLD_NOW);
- if (handle == NULL) {
+ if (!handle) {
near_error("Can't load %s: %s",
filename, dlerror());
g_free(filename);
g_free(filename);
desc = dlsym(handle, "near_plugin_desc");
- if (desc == NULL) {
+ if (!desc) {
near_error("Can't load symbol: %s",
dlerror());
dlclose(handle);
if (plugin->active && plugin->desc->exit)
plugin->desc->exit();
- if (plugin->handle != NULL)
+ if (plugin->handle)
dlclose(plugin->handle);
g_free(plugin);
GList *records;
struct near_ndef_message *msg = NULL;
- if (ndef == NULL)
+ if (!ndef)
return;
/*
/* Parse the incoming frame */
records = near_ndef_parse_msg(ndef, nfc_data_length, &msg);
- if (records == NULL)
+ if (!records)
return;
near_ndef_records_free(records);
{
struct snep_fragment *fragment = data;
- if (fragment != NULL)
+ if (fragment)
g_free(fragment->data);
g_free(fragment);
DBG("");
- if (userdata == NULL)
+ if (!userdata)
return;
data = (struct p2p_snep_put_req_data *) userdata;
DBG("");
- if (req == NULL || req->fragments == NULL ||
+ if (!req || !req->fragments ||
g_slist_length(req->fragments) == 0)
return -EINVAL;
/* Get the incoming data */
ndef_len = frame.length;
ndef = g_try_malloc0(ndef_len);
- if (ndef == NULL)
+ if (!ndef)
return -ENOMEM;
bytes_recv = recv(req->fd, ndef, ndef_len, 0);
while (ndef->offset < ndef->length) {
fragment = g_try_malloc0(sizeof(struct snep_fragment));
- if (fragment == NULL)
+ if (!fragment)
return -ENOMEM;
if (max_fragment_len <= (ndef->length - ndef->offset))
fragment->len = ndef->length - ndef->offset;
fragment->data = g_try_malloc0(fragment->len);
- if (fragment->data == NULL) {
+ if (!fragment->data) {
g_free(fragment);
return -ENOMEM;
}
switch (snep_data->request) {
case NEAR_SNEP_REQ_PUT:
DBG("NEAR_SNEP_REQ_PUT");
- if (req_put != NULL)
+ if (req_put)
ret = (*req_put)(client_fd, snep_data);
else {
near_snep_core_response_noinfo(client_fd,
case NEAR_SNEP_REQ_GET:
DBG("NEAR_SNEP_REQ_GET");
- if (req_get != NULL)
+ if (req_get)
ret = (*req_get)(client_fd, snep_data);
else {
near_snep_core_response_noinfo(client_fd,
}
/* If there's some fragments, don't delete before the CONT */
- if (snep_data->req == NULL) {
+ if (!snep_data->req) {
/* free and leave */
DBG("Clean Table");
g_hash_table_remove(snep_client_hash,
case NEAR_SNEP_REQ_REJECT:
DBG("NEAR_SNEP_REQ_REJECT");
- if (snep_data->req->fragments == NULL) {
+ if (!snep_data->req->fragments) {
near_error("error: NEAR_SNEP_REQ_REJECT but no fragment");
ret = false;
}
* remaining fragments...
*/
- if (snep_data->req == NULL) {
+ if (!snep_data->req) {
ret = true;
break;
}
DBG("NEAR_SNEP_REQ_CONTINUE");
- if (snep_data->req->fragments == NULL) {
+ if (!snep_data->req->fragments) {
near_error("error: NEAR_SNEP_REQ_CONTINUE but no fragment");
ret = false;
goto leave_cont;
* If snep data is already there, and there are more bytes to read
* we just go ahead and read more fragments from the client.
*/
- if (snep_data != NULL &&
+ if (snep_data &&
snep_data->nfc_data_length !=
snep_data->nfc_data_current_length) {
ret = snep_core_read_ndef(client_fd, snep_data);
* we should just process a CONTINUE frame and send the fragments
* back to the client. This will be done from snep_core_process_request().
*/
- if (snep_data != NULL) {
+ if (snep_data) {
snep_data->request = frame.request;
goto process_request;
}
/* This is a new request from the client */
snep_data = g_try_malloc0(sizeof(struct p2p_snep_data));
- if (snep_data == NULL)
+ if (!snep_data)
return false;
/* the whole frame length */
ndef_length = GINT_FROM_BE(frame.length);
snep_data->nfc_data = g_try_malloc0(ndef_length + TLV_SIZE);
- if (snep_data->nfc_data == NULL) {
+ if (!snep_data->nfc_data) {
g_free(snep_data);
return false;
}
fragment = g_try_malloc0(sizeof(struct snep_fragment));
- if (fragment == NULL) {
+ if (!fragment) {
err = -ENOMEM;
goto error;
}
}
fragment->data = g_try_malloc0(fragment->len);
- if (fragment->data == NULL) {
+ if (!fragment->data) {
g_free(fragment);
err = ENOMEM;
goto error;
return 0;
error:
- if (req != NULL)
+ if (req)
free_snep_core_push_data(req, err);
return err;
/* get the snep data */
snep_data = g_hash_table_lookup(snep_client_hash,
GINT_TO_POINTER(client_fd));
- if (snep_data == NULL) {
+ if (!snep_data) {
DBG("snep_data not found");
goto done;
}
/* Prepare the ndef struct */
ndef = g_try_malloc0(sizeof(struct near_ndef_message));
- if (ndef == NULL)
+ if (!ndef)
goto done;
ndef->data = g_try_malloc0(length);
- if (ndef->data == NULL) {
+ if (!ndef->data) {
g_free(ndef);
ndef = NULL;
goto done;
/* Now prepare req struct */
req = g_try_malloc0(sizeof(struct p2p_snep_put_req_data));
- if (req == NULL)
+ if (!req)
goto done;
/* Prepare the callback */
done:
/* If no fragment, free mem */
- if (req != NULL) {
+ if (req) {
if (req->fragments == 0) {
g_free(req);
snep_data->req = NULL;
}
}
- if (ndef != NULL)
+ if (ndef)
g_free(ndef->data);
g_free(ndef);
}
DBG("");
req = g_try_malloc0(sizeof(struct p2p_snep_put_req_data));
- if (req == NULL) {
+ if (!req) {
err = -ENOMEM;
goto error;
}
snep_data = g_hash_table_lookup(snep_client_hash,
GINT_TO_POINTER(client_fd));
- if (snep_data == NULL)
+ if (!snep_data)
return;
snep_data->cb(snep_data->adapter_idx, snep_data->target_idx, err);
path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
adapter_idx, target_idx);
- if (path == NULL)
+ if (!path)
return NULL;
tag = g_hash_table_lookup(tag_hash, path);
char *path;
path = __near_ndef_record_get_path(record);
- if (path == NULL)
+ if (!path)
continue;
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
DBG("conn %p", conn);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
near_dbus_dict_open(&array, &dict);
type = type_string(tag);
- if (type != NULL)
+ if (type)
near_dbus_dict_append_basic(&dict, "Type",
DBUS_TYPE_STRING, &type);
protocol = protocol_string(tag);
- if (protocol != NULL)
+ if (protocol)
near_dbus_dict_append_basic(&dict, "Protocol",
DBUS_TYPE_STRING, &protocol);
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
return;
dbus_message_unref(tag->write_msg);
DBG("Write status %d", status);
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
return;
conn = near_dbus_get_connection();
- if (conn == NULL)
+ if (!conn)
goto out;
if (status != 0) {
reply = __near_error_failed(tag->write_msg, EINVAL);
- if (reply != NULL)
+ if (reply)
g_dbus_send_message(conn, reply);
} else {
g_dbus_send_reply(conn, tag->write_msg, DBUS_TYPE_INVALID);
DBG("format status %d", status);
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
return;
- if (tag->write_msg == NULL)
+ if (!tag->write_msg)
return;
if (status == 0) {
return __near_error_in_progress(msg);
ndef = __ndef_build_from_message(msg);
- if (ndef == NULL)
+ if (!ndef)
return __near_error_failed(msg, EINVAL);
tag->write_msg = dbus_message_ref(msg);
ndef_with_header = g_try_malloc0(sizeof(
struct near_ndef_message));
- if (ndef_with_header == NULL)
+ if (!ndef_with_header)
goto fail;
ndef_with_header->offset = 0;
ndef_with_header->length = ndef->length + tlv_len_size;
ndef_with_header->data =
g_try_malloc0(ndef->length + tlv_len_size);
- if (ndef_with_header->data == NULL)
+ if (!ndef_with_header->data)
goto fail;
ndef_with_header->data[0] = TLV_NDEF;
case NFC_PROTO_FELICA:
ndef_with_header = g_try_malloc0(sizeof(
struct near_ndef_message));
- if (ndef_with_header == NULL)
+ if (!ndef_with_header)
goto fail;
ndef_with_header->offset = 0;
ndef_with_header->length = ndef->length;
ndef_with_header->data = g_try_malloc0(
ndef_with_header->length);
- if (ndef_with_header->data == NULL)
+ if (!ndef_with_header->data)
goto fail;
memcpy(ndef_with_header->data, ndef->data, ndef->length);
case NFC_PROTO_ISO14443:
ndef_with_header = g_try_malloc0(sizeof(
struct near_ndef_message));
- if (ndef_with_header == NULL)
+ if (!ndef_with_header)
goto fail;
ndef_with_header->offset = 0;
ndef_with_header->length = ndef->length + 2;
ndef_with_header->data = g_try_malloc0(ndef->length + 2);
- if (ndef_with_header->data == NULL)
+ if (!ndef_with_header->data)
goto fail;
ndef_with_header->data[0] = (uint8_t)(ndef->length >> 8);
char *path;
path = __near_ndef_record_get_path(record);
- if (path == NULL)
+ if (!path)
continue;
dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
tag->path = g_strdup_printf("%s/nfc%d/tag%d", NFC_PATH,
adapter_idx, target_idx);
- if (tag->path == NULL)
+ if (!tag->path)
return -ENOMEM;
tag->adapter_idx = adapter_idx;
tag->target_idx = target_idx;
char *path;
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag != NULL)
+ if (tag)
return NULL;
tag = g_try_malloc0(sizeof(struct near_tag));
- if (tag == NULL)
+ if (!tag)
return NULL;
if (tag_initialize(tag, adapter_idx, target_idx,
}
path = g_strdup(tag->path);
- if (path == NULL) {
+ if (!path) {
g_free(tag);
return NULL;
}
DBG("path %s", tag->path);
- if (g_hash_table_lookup(tag_hash, tag->path) == NULL)
+ if (!g_hash_table_lookup(tag_hash, tag->path))
return;
g_dbus_unregister_interface(connection, tag->path,
struct near_tag *tag;
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
return NEAR_TAG_NFC_SUBTYPE_UNKNOWN;
return tag->sub_type;
uint8_t *nfcid;
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
goto fail;
nfcid = g_try_malloc0(tag->nfcid_len);
- if (nfcid == NULL)
+ if (!nfcid)
goto fail;
memcpy(nfcid, tag->nfcid, tag->nfcid_len);
DBG("NFCID len %zd", nfcid_len);
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
return -ENODEV;
if (tag->nfcid_len > 0)
struct near_tag *tag;
tag = near_tag_get_tag(adapter_idx, target_idx);
- if (tag == NULL)
+ if (!tag)
return -ENODEV;
tag->data_length = data_length;
tag->data = g_try_malloc0(data_length);
- if (tag->data == NULL)
+ if (!tag->data)
return -ENOMEM;
- if (data != NULL)
+ if (data)
memcpy(tag->data, data, data_length);
return 0;
NFC_PATH, tag->adapter_idx,
tag->target_idx, tag->n_records);
- if (path == NULL)
+ if (!path)
continue;
__near_ndef_record_register(record, path);
DBUS_TYPE_OBJECT_PATH, append_records,
tag);
- if (cb != NULL)
+ if (cb)
cb(tag->adapter_idx, tag->target_idx, status);
g_list_free(records);
uint8_t *near_tag_get_data(struct near_tag *tag, size_t *data_length)
{
- if (data_length == NULL)
+ if (!data_length)
return NULL;
*data_length = tag->data_length;
enum near_tag_memory_layout near_tag_get_memory_layout(struct near_tag *tag)
{
- if (tag == NULL)
+ if (!tag)
return NEAR_TAG_MEMORY_UNKNOWN;
return tag->layout;
void near_tag_set_memory_layout(struct near_tag *tag,
enum near_tag_memory_layout layout)
{
- if (tag == NULL)
+ if (!tag)
return;
tag->layout = layout;
void near_tag_set_max_ndef_size(struct near_tag *tag, uint16_t size)
{
- if (tag == NULL)
+ if (!tag)
return;
tag->t4.max_ndef_size = size;
uint16_t near_tag_get_max_ndef_size(struct near_tag *tag)
{
- if (tag == NULL)
+ if (!tag)
return 0;
return tag->t4.max_ndef_size;
void near_tag_set_c_apdu_max_size(struct near_tag *tag, uint16_t size)
{
- if (tag == NULL)
+ if (!tag)
return;
tag->t4.c_apdu_max_size = size;
uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag)
{
- if (tag == NULL)
+ if (!tag)
return 0;
return tag->t4.c_apdu_max_size;
void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len)
{
- if (tag == NULL || len > TYPE3_IDM_LEN)
+ if (!tag || len > TYPE3_IDM_LEN)
return;
memset(tag->t3.IDm, 0, TYPE3_IDM_LEN);
uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len)
{
- if (tag == NULL || len == NULL)
+ if (!tag || !len)
return NULL;
*len = TYPE3_IDM_LEN;
void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len)
{
- if (tag == NULL || len > TYPE3_ATTR_BLOCK_SIZE)
+ if (!tag || len > TYPE3_ATTR_BLOCK_SIZE)
return;
memset(tag->t3.attr, 0, TYPE3_ATTR_BLOCK_SIZE);
uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len)
{
- if (tag == NULL || len == NULL)
+ if (!tag || !len)
return NULL;
*len = TYPE3_ATTR_BLOCK_SIZE;
void near_tag_set_ic_type(struct near_tag *tag, uint8_t ic_type)
{
- if (tag == NULL)
+ if (!tag)
return;
tag->t3.ic_type = ic_type;
uint8_t near_tag_get_ic_type(struct near_tag *tag)
{
- if (tag == NULL)
+ if (!tag)
return 0;
return tag->t3.ic_type;
{
DBG("");
- if (driver->read == NULL)
+ if (!driver->read)
return -EINVAL;
driver_list = g_slist_insert_sorted(driver_list, driver, cmp_prio);
__near_adapter_stop_check_presence(tag->adapter_idx,
tag->target_idx);
- if (tag->blank && driver->format != NULL) {
+ if (tag->blank && driver->format) {
DBG("Blank tag detected, formatting");
err = driver->format(tag->adapter_idx,
tag->target_idx, format_cb);
}
}
- if (list == NULL)
+ if (!list)
err = -EOPNOTSUPP;
if (err < 0)
DBG("driver type 0x%x", driver->type);
if (driver->type == tag->type) {
- if (driver->check_presence == NULL)
+ if (!driver->check_presence)
continue;
return driver->check_presence(tag->adapter_idx, tag->target_idx, cb);