#include <gdbus.h>
+#define TIMEOUT 30000
+
#define NEARD_SERVICE "org.neard"
#define NEARD_PATH "/"
#define NEARD_MANAGER_INTERFACE "org.neard.Manager"
struct data_elements {
unsigned int value;
unsigned int length;
- gboolean fixed_length;
+ bool fixed_length;
};
typedef enum {
static DBusConnection *connection = NULL;
DBusPendingCall *register_call = NULL;
-gboolean agent_registered = FALSE;
+bool agent_registered = false;
static guint watch_id = 0;
static int set_2b_into_tlv(uint8_t *tlv_msg, uint16_t val)
uint8_t *tlv_msg;
int pos = 0;
- if (ssid == NULL || length == NULL)
+ if (!ssid || !length)
return NULL;
ssid_len = strlen(ssid);
*length = 6 + 4 + ssid_len;
- if (psk != NULL) {
+ if (psk) {
psk_len = strlen(psk);
*length += 4 + psk_len;
} else
psk_len = 0;
tlv_msg = g_try_malloc0(sizeof(uint8_t) * (*length));
- if (tlv_msg == NULL)
+ if (!tlv_msg)
return NULL;
pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_SSID].value);
pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_AUTHENTICATION_TYPE].value);
pos += set_2b_into_tlv(tlv_msg+pos,
DEs[DE_AUTHENTICATION_TYPE].length);
- if (psk != NULL) {
+ if (psk) {
pos += set_2b_into_tlv(tlv_msg+pos, DE_VAL_PSK);
pos += set_2b_into_tlv(tlv_msg+pos, DEs[DE_NETWORK_KEY].value);
pos += set_2b_into_tlv(tlv_msg+pos, psk_len);
const char *key;
int arg_type;
+ if (!tlv_msg || !length)
+ return -EINVAL;
+
dbus_message_iter_init(message, &iter);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
if (arg_type != DBUS_TYPE_DICT_ENTRY)
return -EINVAL;
- if (tlv_msg == NULL && length == NULL)
- return 0;
-
while (arg_type != DBUS_TYPE_INVALID) {
dbus_message_iter_recurse(&array, &dict_entry);
if (dbus_message_iter_get_arg_type(&dict_entry) !=
uint8_t *tlv_msg;
int length;
- if (connman_technology_get_wifi_tethering(&ssid, &psk) == FALSE)
+ if (!connman_technology_get_wifi_tethering(&ssid, &psk))
return get_reply_on_error(message, ENOTSUP);
tlv_msg = encode_to_tlv(ssid, psk, &length);
- if (tlv_msg == NULL)
+ if (!tlv_msg)
return get_reply_on_error(message, ENOTSUP);
reply = dbus_message_new_method_return(message);
- if (reply == NULL)
+ if (!reply)
goto out;
dbus_message_iter_init_append(reply, &iter);
static DBusMessage *request_oob_method(DBusConnection *dbus_conn,
DBusMessage *message, void *user_data)
{
+ DBusMessageIter iter;
+
DBG("");
- if (parse_request_oob_params(message, NULL, NULL) != 0)
+ dbus_message_iter_init(message, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
return get_reply_on_error(message, EINVAL);
return create_request_oob_reply(message);
static void free_wifi_sc(struct wifi_sc *wsc)
{
- if (wsc == NULL)
+ if (!wsc)
return;
g_free(wsc->ssid);
uint8_t *array;
array = g_try_malloc0(sizeof(uint8_t) * length);
- if (array == NULL)
+ if (!array)
return NULL;
memcpy((void *)array, (void *)tlv_msg, length*sizeof(uint8_t));
char *str;
str = g_try_malloc0((sizeof(char) * length) + 1);
- if (str == NULL)
+ if (!str)
return NULL;
memcpy((void *)str, (void *)tlv_msg, length*sizeof(char));
return DE_MAX;
}
-static inline gboolean is_de_length_fine(DEid id, uint16_t length)
+static inline bool is_de_length_fine(DEid id, uint16_t length)
{
- if (DEs[id].fixed_length == TRUE)
+ if (DEs[id].fixed_length)
return (length == DEs[id].length);
return (length <= DEs[id].length);
int i, j;
hex_str = g_try_malloc0(((length*2)+1) * sizeof(char));
- if (hex_str == NULL)
+ if (!hex_str)
return NULL;
for (i = 0, j = 0; i < length; i++, j += 2)
int pos;
DEid id;
- if (tlv_msg == NULL || length == 0)
+ if (!tlv_msg || length == 0)
return NULL;
wsc = g_try_malloc0(sizeof(struct wifi_sc));
- if (wsc == NULL)
+ if (!wsc)
return NULL;
pos = 0;
continue;
}
- if (is_de_length_fine(id, len) == FALSE)
+ if (!is_de_length_fine(id, len))
goto error;
switch (id) {
int ret = -EINVAL;
wsc = decode_from_tlv(tlv_msg, length);
- if (wsc == NULL)
+ if (!wsc)
return -EINVAL;
- if (wsc->ssid == NULL)
+ if (!wsc->ssid)
goto out;
keyfile = g_key_file_new();
- if (keyfile == NULL) {
+ if (!keyfile) {
ret = -ENOMEM;
goto out;
}
g_key_file_set_boolean(keyfile, NEARD_SERVICE_GROUP,
SERVICE_KEY_HIDDEN, TRUE);
- if (wsc->passphrase != NULL)
+ if (wsc->passphrase)
g_key_file_set_string(keyfile, NEARD_SERVICE_GROUP,
SERVICE_KEY_PASSPHRASE, wsc->passphrase);
{
DBG("");
- agent_registered = FALSE;
+ agent_registered = false;
g_dbus_unregister_interface(connection,
AGENT_PATH, NEARD_AGENT_INTERFACE);
}
static const GDBusMethodTable neard_methods[] = {
-{ GDBUS_ASYNC_METHOD("RequestOOB",
+ { GDBUS_ASYNC_METHOD("RequestOOB",
GDBUS_ARGS({ "data", "a{sv}" }),
GDBUS_ARGS({ "data", "a{sv}" }), request_oob_method) },
{ GDBUS_ASYNC_METHOD("PushOOB",
static void cleanup_register_call(void)
{
- if (register_call != NULL) {
+ if (register_call) {
dbus_pending_call_cancel(register_call);
dbus_pending_call_unref(register_call);
register_call = NULL;
{
DBusMessage *reply;
- if (dbus_pending_call_get_completed(pending) == FALSE)
+ if (!dbus_pending_call_get_completed(pending))
return;
register_call = NULL;
reply = dbus_pending_call_steal_reply(pending);
- if (reply == NULL)
+ if (!reply)
goto out;
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
g_dbus_unregister_interface(connection,
AGENT_PATH, NEARD_AGENT_INTERFACE);
} else
- agent_registered = TRUE;
+ agent_registered = true;
dbus_message_unref(reply);
out:
message = dbus_message_new_method_call(NEARD_SERVICE, NEARD_PATH,
NEARD_MANAGER_INTERFACE,
"RegisterHandoverAgent");
- if (message == NULL)
+ if (!message)
return;
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
&path, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID);
- if (dbus_connection_send_with_reply(connection, message,
- ®ister_call, DBUS_TIMEOUT_USE_DEFAULT) == FALSE) {
- dbus_message_unref(message);
+ if (!dbus_connection_send_with_reply(connection, message,
+ ®ister_call, TIMEOUT))
goto out;
- }
- if (dbus_pending_call_set_notify(register_call, register_agent_cb,
- NULL, NULL) == FALSE)
+ if (!dbus_pending_call_set_notify(register_call,
+ register_agent_cb, NULL, NULL))
cleanup_register_call();
out:
const char *type = AGENT_TYPE;
DBusMessage *message;
- if (agent_registered == FALSE)
+ if (!agent_registered)
return cleanup_register_call();
- agent_registered = FALSE;
+ agent_registered = false;
message = dbus_message_new_method_call(NEARD_SERVICE, NEARD_PATH,
NEARD_MANAGER_INTERFACE,
"UnregisterHandoverAgent");
- if (message != NULL) {
+ if (message) {
dbus_message_append_args(message, DBUS_TYPE_OBJECT_PATH,
&path, DBUS_TYPE_STRING, &type, DBUS_TYPE_INVALID);
g_dbus_send_message(connection, message);
{
DBG("");
- if (agent_registered == TRUE)
+ if (agent_registered)
return;
if (g_dbus_register_interface(connection, AGENT_PATH,
NEARD_AGENT_INTERFACE, neard_methods,
- NULL, NULL, NULL, NULL) == TRUE)
+ NULL, NULL, NULL, NULL))
register_agent();
}
{
DBG("");
- if (agent_registered == TRUE) {
+ if (agent_registered) {
g_dbus_unregister_interface(connection,
AGENT_PATH, NEARD_AGENT_INTERFACE);
- agent_registered = FALSE;
+ agent_registered = false;
}
cleanup_register_call();
static int neard_init(void)
{
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -EIO;
watch_id = g_dbus_add_service_watch(connection, NEARD_SERVICE,
if (watch_id != 0)
g_dbus_remove_watch(connection, watch_id);
- if (connection != NULL)
+ if (connection)
dbus_connection_unref(connection);
}