summaryrefslogtreecommitdiff
path: root/src/agent-connman.c
diff options
context:
space:
mode:
authorZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 02:37:39 (GMT)
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 02:37:39 (GMT)
commit1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch)
tree6e991827d28537f7f40f20786c2354fd04a9fdad /src/agent-connman.c
parentfbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff)
downloadconnman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.zip
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.gz
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.bz2
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'src/agent-connman.c')
-rw-r--r--src/agent-connman.c113
1 files changed, 66 insertions, 47 deletions
diff --git a/src/agent-connman.c b/src/agent-connman.c
index 9ccba72..ab538f3 100644
--- a/src/agent-connman.c
+++ b/src/agent-connman.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -34,7 +34,7 @@
#include "connman.h"
-static connman_bool_t check_reply_has_dict(DBusMessage *reply)
+static bool check_reply_has_dict(DBusMessage *reply)
{
const char *signature = DBUS_TYPE_ARRAY_AS_STRING
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
@@ -42,8 +42,8 @@ static connman_bool_t check_reply_has_dict(DBusMessage *reply)
DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
- if (dbus_message_has_signature(reply, signature) == TRUE)
- return TRUE;
+ if (dbus_message_has_signature(reply, signature))
+ return true;
connman_warn("Reply %s to %s from %s has wrong signature %s",
signature,
@@ -51,7 +51,7 @@ static connman_bool_t check_reply_has_dict(DBusMessage *reply)
dbus_message_get_sender(reply),
dbus_message_get_signature(reply));
- return FALSE;
+ return false;
}
struct request_input_reply {
@@ -63,8 +63,8 @@ struct request_input_reply {
static void request_input_passphrase_reply(DBusMessage *reply, void *user_data)
{
struct request_input_reply *passphrase_reply = user_data;
- connman_bool_t values_received = FALSE;
- connman_bool_t wps = FALSE;
+ bool values_received = false;
+ bool wps = false;
const char *error = NULL;
char *identity = NULL;
char *passphrase = NULL;
@@ -74,15 +74,18 @@ static void request_input_passphrase_reply(DBusMessage *reply, void *user_data)
int name_len = 0;
DBusMessageIter iter, dict;
+ if (!reply)
+ goto out;
+
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
error = dbus_message_get_error_name(reply);
goto done;
}
- if (check_reply_has_dict(reply) == FALSE)
+ if (!check_reply_has_dict(reply))
goto done;
- values_received = TRUE;
+ values_received = true;
dbus_message_iter_init(reply, &iter);
dbus_message_iter_recurse(&iter, &dict);
@@ -105,13 +108,14 @@ static void request_input_passphrase_reply(DBusMessage *reply, void *user_data)
} else if (g_str_equal(key, "Passphrase")) {
dbus_message_iter_next(&entry);
- if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT)
+ if (dbus_message_iter_get_arg_type(&entry)
+ != DBUS_TYPE_VARIANT)
break;
dbus_message_iter_recurse(&entry, &value);
dbus_message_iter_get_basic(&value, &passphrase);
} else if (g_str_equal(key, "WPS")) {
- wps = TRUE;
+ wps = true;
dbus_message_iter_next(&entry);
if (dbus_message_iter_get_arg_type(&entry)
@@ -152,6 +156,8 @@ done:
identity, passphrase,
wps, wpspin, error,
passphrase_reply->user_data);
+
+out:
g_free(passphrase_reply);
}
@@ -161,14 +167,14 @@ static void request_input_append_alternates(DBusMessageIter *iter,
const char *str = user_data;
char **alternates, **alternative;
- if (str == NULL)
+ if (!str)
return;
alternates = g_strsplit(str, ",", 0);
- if (alternates == NULL)
+ if (!alternates)
return;
- for (alternative = alternates; *alternative != NULL; alternative++)
+ for (alternative = alternates; *alternative; alternative++)
dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
alternative);
@@ -204,9 +210,9 @@ static void request_input_append_passphrase(DBusMessageIter *iter,
case CONNMAN_SERVICE_SECURITY_8021X:
phase2 = __connman_service_get_phase2(service);
- if (phase2 != NULL && (
- g_str_has_suffix(phase2, "GTC") == TRUE ||
- g_str_has_suffix(phase2, "OTP") == TRUE))
+ if (phase2 && (
+ g_str_has_suffix(phase2, "GTC") ||
+ g_str_has_suffix(phase2, "OTP")))
value = "response";
else
value = "passphrase";
@@ -222,7 +228,7 @@ static void request_input_append_passphrase(DBusMessageIter *iter,
connman_dbus_dict_append_basic(iter, "Requirement",
DBUS_TYPE_STRING, &value);
- if (__connman_service_wps_enabled(service) == TRUE) {
+ if (__connman_service_wps_enabled(service)) {
connman_dbus_dict_append_array(iter, "Alternates",
DBUS_TYPE_STRING,
request_input_append_alternates,
@@ -310,12 +316,12 @@ static void previous_passphrase_handler(DBusMessageIter *iter,
network = __connman_service_get_network(service);
data.passphrase = connman_network_get_string(network, "WiFi.PinWPS");
- if (connman_network_get_bool(network, "WiFi.UseWPS") == TRUE &&
- data.passphrase != NULL) {
+ if (connman_network_get_bool(network, "WiFi.UseWPS") &&
+ data.passphrase) {
data.type = "wpspin";
} else {
data.passphrase = __connman_service_get_passphrase(service);
- if (data.passphrase == NULL)
+ if (!data.passphrase)
return;
security = __connman_service_get_security(service);
@@ -342,21 +348,24 @@ static void request_input_login_reply(DBusMessage *reply, void *user_data)
{
struct request_input_reply *username_password_reply = user_data;
const char *error = NULL;
- connman_bool_t values_received = FALSE;
+ bool values_received = false;
char *username = NULL;
char *password = NULL;
char *key;
DBusMessageIter iter, dict;
+ if (!reply)
+ goto out;
+
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
error = dbus_message_get_error_name(reply);
goto done;
}
- if (check_reply_has_dict(reply) == FALSE)
+ if (!check_reply_has_dict(reply))
goto done;
- values_received = TRUE;
+ values_received = true;
dbus_message_iter_init(reply, &iter);
dbus_message_iter_recurse(&iter, &dict);
@@ -395,11 +404,14 @@ done:
username, password,
FALSE, NULL, error,
username_password_reply->user_data);
+
+out:
g_free(username_password_reply);
}
int __connman_agent_request_passphrase_input(struct connman_service *service,
- authentication_cb_t callback, void *user_data)
+ authentication_cb_t callback,
+ const char *dbus_sender, void *user_data)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
@@ -407,16 +419,20 @@ int __connman_agent_request_passphrase_input(struct connman_service *service,
DBusMessageIter dict;
struct request_input_reply *passphrase_reply;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
- if (service == NULL || agent_path == NULL || callback == NULL)
+ DBG("agent %p service %p path %s", agent, service, agent_path);
+
+ if (!service || !agent || !agent_path || !callback)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
CONNMAN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -443,20 +459,19 @@ int __connman_agent_request_passphrase_input(struct connman_service *service,
if (__connman_service_get_security(service) !=
CONNMAN_SERVICE_SECURITY_NONE) {
connman_dbus_dict_append_dict(&dict, "Passphrase",
- request_input_append_passphrase, service);
+ request_input_append_passphrase, service);
previous_passphrase_handler(&dict, service);
}
- if (__connman_service_wps_enabled(service) == TRUE) {
- connman_dbus_dict_append_dict(&dict, "WPS",
+ if (__connman_service_wps_enabled(service))
+ connman_dbus_dict_append_dict(&dict, "WPS",
request_input_append_wps, NULL);
- }
connman_dbus_dict_close(&iter, &dict);
passphrase_reply = g_try_new0(struct request_input_reply, 1);
- if (passphrase_reply == NULL) {
+ if (!passphrase_reply) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -468,7 +483,7 @@ int __connman_agent_request_passphrase_input(struct connman_service *service,
err = connman_agent_queue_message(service, message,
connman_timeout_input_request(),
request_input_passphrase_reply,
- passphrase_reply);
+ passphrase_reply, agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent message", err);
@@ -491,16 +506,17 @@ int __connman_agent_request_login_input(struct connman_service *service,
DBusMessageIter dict;
struct request_input_reply *username_password_reply;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
+ agent = connman_agent_get_info(NULL, &agent_sender, &agent_path);
- if (service == NULL || agent_path == NULL || callback == NULL)
+ if (!service || !agent || !agent_path || !callback)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
CONNMAN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -520,7 +536,7 @@ int __connman_agent_request_login_input(struct connman_service *service,
connman_dbus_dict_close(&iter, &dict);
username_password_reply = g_try_new0(struct request_input_reply, 1);
- if (username_password_reply == NULL) {
+ if (!username_password_reply) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -531,7 +547,8 @@ int __connman_agent_request_login_input(struct connman_service *service,
err = connman_agent_queue_message(service, message,
connman_timeout_input_request(),
- request_input_login_reply, username_password_reply);
+ request_input_login_reply, username_password_reply,
+ agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
@@ -553,7 +570,7 @@ struct request_browser_reply_data {
static void request_browser_reply(DBusMessage *reply, void *user_data)
{
struct request_browser_reply_data *browser_reply_data = user_data;
- connman_bool_t result = FALSE;
+ bool result = false;
const char *error = NULL;
if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
@@ -561,7 +578,7 @@ static void request_browser_reply(DBusMessage *reply, void *user_data)
goto done;
}
- result = TRUE;
+ result = true;
done:
browser_reply_data->callback(browser_reply_data->service, result,
@@ -578,19 +595,20 @@ int __connman_agent_request_browser(struct connman_service *service,
DBusMessageIter iter;
const char *path, *agent_sender, *agent_path;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
+ agent = connman_agent_get_info(NULL, &agent_sender, &agent_path);
- if (service == NULL || agent_path == NULL || callback == NULL)
+ if (!service || !agent || !agent_path || !callback)
return -ESRCH;
- if (url == NULL)
+ if (!url)
url = "";
message = dbus_message_new_method_call(agent_sender, agent_path,
CONNMAN_AGENT_INTERFACE,
"RequestBrowser");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -601,7 +619,7 @@ int __connman_agent_request_browser(struct connman_service *service,
dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &url);
browser_reply_data = g_try_new0(struct request_browser_reply_data, 1);
- if (browser_reply_data == NULL) {
+ if (!browser_reply_data) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -612,7 +630,8 @@ int __connman_agent_request_browser(struct connman_service *service,
err = connman_agent_queue_message(service, message,
connman_timeout_browser_launch(),
- request_browser_reply, browser_reply_data);
+ request_browser_reply, browser_reply_data,
+ agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending browser request", err);