summaryrefslogtreecommitdiff
path: root/vpn
diff options
context:
space:
mode:
Diffstat (limited to 'vpn')
-rw-r--r--vpn/connman-vpn.conf8
-rw-r--r--vpn/connman-vpn.service.in3
-rw-r--r--vpn/main.c38
-rw-r--r--vpn/plugins/l2tp.c106
-rw-r--r--vpn/plugins/openconnect.c357
-rw-r--r--vpn/plugins/openvpn.c63
-rw-r--r--vpn/plugins/pptp.c100
-rw-r--r--vpn/plugins/vpn.c67
-rw-r--r--vpn/plugins/vpn.h5
-rw-r--r--vpn/plugins/vpnc.c71
-rw-r--r--vpn/vpn-agent.c12
-rw-r--r--vpn/vpn-agent.h2
-rw-r--r--vpn/vpn-config.c142
-rw-r--r--vpn/vpn-ipconfig.c54
-rw-r--r--vpn/vpn-manager.c10
-rw-r--r--vpn/vpn-provider.c477
-rw-r--r--vpn/vpn-provider.h8
-rw-r--r--vpn/vpn-rtnl.c56
-rw-r--r--vpn/vpn.h13
19 files changed, 828 insertions, 764 deletions
diff --git a/vpn/connman-vpn.conf b/vpn/connman-vpn.conf
deleted file mode 100644
index 99a96ce8..00000000
--- a/vpn/connman-vpn.conf
+++ /dev/null
@@ -1,8 +0,0 @@
-[General]
-
-# Set input request timeout. Default is 300 seconds
-# The request for inputs like passphrase will timeout
-# after certain amount of time. Use this setting to
-# increase the value in case of different user
-# interface designs.
-# InputRequestTimeout = 300
diff --git a/vpn/connman-vpn.service.in b/vpn/connman-vpn.service.in
index ec02a867..3778d51c 100644
--- a/vpn/connman-vpn.service.in
+++ b/vpn/connman-vpn.service.in
@@ -1,6 +1,7 @@
[Unit]
Description=ConnMan VPN service
-After=syslog.target
+Requires=dbus.socket
+After=dbus.socket
[Service]
Type=dbus
diff --git a/vpn/main.c b/vpn/main.c
index d72fa74c..ee88aacd 100644
--- a/vpn/main.c
+++ b/vpn/main.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * 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
@@ -84,14 +84,14 @@ static void parse_config(GKeyFile *config, const char *file)
GError *error = NULL;
int timeout;
- if (config == NULL)
+ if (!config)
return;
DBG("parsing %s", file);
timeout = g_key_file_get_integer(config, "General",
"InputRequestTimeout", &error);
- if (error == NULL && timeout >= 0)
+ if (!error && timeout >= 0)
connman_vpn_settings.timeout_inputreq = timeout * 1000;
g_clear_error(&error);
@@ -103,7 +103,7 @@ static int config_init(const char *file)
config = load_config(file);
parse_config(config, file);
- if (config != NULL)
+ if (config)
g_key_file_free(config);
return 0;
@@ -188,11 +188,11 @@ static gchar *option_config = NULL;
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 gboolean option_routes = FALSE;
+static bool option_detach = true;
+static bool option_version = false;
+static bool option_routes = 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)
@@ -200,7 +200,7 @@ static gboolean parse_debug(const char *key, const char *value,
else
option_debug = g_strdup("*");
- return TRUE;
+ return true;
}
static GOptionEntry options[] = {
@@ -244,8 +244,8 @@ 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 (error != NULL) {
+ if (!g_option_context_parse(context, &argc, &argv, &error)) {
+ if (error) {
g_printerr("%s\n", error->message);
g_error_free(error);
} else
@@ -255,19 +255,19 @@ int main(int argc, char *argv[])
g_option_context_free(context);
- if (option_version == TRUE) {
+ if (option_version) {
printf("%s\n", VERSION);
exit(0);
}
- if (option_detach == TRUE) {
+ if (option_detach) {
if (daemon(0, 0)) {
perror("Can't start daemon");
exit(1);
}
}
- if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+ if (mkdir(VPN_STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
if (errno != EEXIST)
perror("Failed to create state directory");
@@ -298,8 +298,8 @@ int main(int argc, char *argv[])
dbus_error_init(&err);
conn = g_dbus_setup_bus(DBUS_BUS_SYSTEM, VPN_SERVICE, &err);
- if (conn == NULL) {
- if (dbus_error_is_set(&err) == TRUE) {
+ if (!conn) {
+ if (dbus_error_is_set(&err)) {
fprintf(stderr, "%s\n", err.message);
dbus_error_free(&err);
} else
@@ -309,11 +309,11 @@ int main(int argc, char *argv[])
g_dbus_set_disconnect_function(conn, disconnect_callback, NULL, NULL);
- __connman_log_init(argv[0], option_debug, option_detach, FALSE,
+ __connman_log_init(argv[0], option_debug, option_detach, false,
"Connection Manager VPN daemon", VERSION);
__connman_dbus_init(conn);
- if (option_config == NULL)
+ if (!option_config)
config_init(CONFIGMAINFILE);
else
config_init(option_config);
@@ -347,7 +347,7 @@ int main(int argc, char *argv[])
__connman_agent_cleanup();
__connman_inotify_cleanup();
__connman_dbus_cleanup();
- __connman_log_cleanup(FALSE);
+ __connman_log_cleanup(false);
dbus_connection_unref(conn);
diff --git a/vpn/plugins/l2tp.c b/vpn/plugins/l2tp.c
index a3221789..91acc85f 100644
--- a/vpn/plugins/l2tp.c
+++ b/vpn/plugins/l2tp.c
@@ -2,8 +2,8 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2010,2013 BMW Car IT GmbH. 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
@@ -132,18 +132,18 @@ static DBusMessage *l2tp_get_sec(struct connman_task *task,
const char *user, *passwd;
struct vpn_provider *provider = user_data;
- if (dbus_message_get_no_reply(msg) == FALSE) {
+ if (!dbus_message_get_no_reply(msg)) {
DBusMessage *reply;
user = vpn_provider_get_string(provider, "L2TP.User");
passwd = vpn_provider_get_string(provider, "L2TP.Password");
- if (user == NULL || strlen(user) == 0 ||
- passwd == NULL || strlen(passwd) == 0)
+ if (!user || strlen(user) == 0 ||
+ !passwd || strlen(passwd) == 0)
return NULL;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
@@ -198,20 +198,14 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%s = %s", key, value);
- if (!strcmp(key, "INTERNAL_IP4_ADDRESS")) {
- vpn_provider_set_string(provider, "Address", value);
+ if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
addressv4 = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_NETMASK")) {
- vpn_provider_set_string(provider, "Netmask", value);
+ if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
netmask = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_DNS")) {
- vpn_provider_set_string(provider, "DNS", value);
+ if (!strcmp(key, "INTERNAL_IP4_DNS"))
nameservers = g_strdup(value);
- }
if (!strcmp(key, "INTERNAL_IFNAME"))
ifname = g_strdup(value);
@@ -227,12 +221,12 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_FAILURE;
}
- if (addressv4 != NULL)
+ if (addressv4)
ipaddress = connman_ipaddress_alloc(AF_INET);
g_free(ifname);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
connman_error("No IP address for provider");
g_free(addressv4);
g_free(netmask);
@@ -241,12 +235,12 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
}
value = vpn_provider_get_string(provider, "HostIP");
- if (value != NULL) {
+ if (value) {
vpn_provider_set_string(provider, "Gateway", value);
gateway = g_strdup(value);
}
- if (addressv4 != NULL)
+ if (addressv4)
connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
gateway);
@@ -265,29 +259,29 @@ static int l2tp_notify(DBusMessage *msg, struct vpn_provider *provider)
static int l2tp_save(struct vpn_provider *provider, GKeyFile *keyfile)
{
const char *option;
- connman_bool_t l2tp_option, pppd_option;
+ bool l2tp_option, pppd_option;
int i;
for (i = 0; i < (int)ARRAY_SIZE(pppd_options); i++) {
- l2tp_option = pppd_option = FALSE;
+ l2tp_option = pppd_option = false;
if (strncmp(pppd_options[i].cm_opt, "L2TP.", 5) == 0)
- l2tp_option = TRUE;
+ l2tp_option = true;
if (strncmp(pppd_options[i].cm_opt, "PPPD.", 5) == 0)
- pppd_option = TRUE;
+ pppd_option = true;
- if (l2tp_option == TRUE || pppd_option == TRUE) {
+ if (l2tp_option || pppd_option) {
option = vpn_provider_get_string(provider,
pppd_options[i].cm_opt);
- if (option == NULL) {
+ if (!option) {
/*
* Check if the option prefix is L2TP as the
* PPPD options were using L2TP prefix earlier.
*/
char *l2tp_str;
- if (pppd_option == FALSE)
+ if (!pppd_option)
continue;
l2tp_str = g_strdup_printf("L2TP.%s",
@@ -296,7 +290,7 @@ static int l2tp_save(struct vpn_provider *provider, GKeyFile *keyfile)
l2tp_str);
g_free(l2tp_str);
- if (option == NULL)
+ if (!option)
continue;
}
@@ -333,7 +327,7 @@ static ssize_t l2tp_write_bool_option(int fd,
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "true") == 0 ||
strcmp(value, "1") == 0) {
@@ -352,8 +346,8 @@ static int l2tp_write_option(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL) {
- if (value != NULL)
+ if (key) {
+ if (value)
buf = g_strdup_printf("%s %s\n", key, value);
else
buf = g_strdup_printf("%s\n", key);
@@ -371,7 +365,7 @@ static int l2tp_write_section(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
buf = g_strdup_printf("%s = %s\n", key, value);
ret = full_write(fd, buf, strlen(buf));
@@ -478,11 +472,11 @@ static void l2tp_died(struct connman_task *task, int exit_code, void *user_data)
vpn_died(task, exit_code, user_data);
- conf_file = g_strdup_printf("/var/run/connman/connman-xl2tpd.conf");
+ conf_file = g_strdup_printf(VPN_STATEDIR "/connman-xl2tpd.conf");
unlink(conf_file);
g_free(conf_file);
- conf_file = g_strdup_printf("/var/run/connman/connman-ppp-option.conf");
+ conf_file = g_strdup_printf(VPN_STATEDIR "/connman-ppp-option.conf");
unlink(conf_file);
g_free(conf_file);
}
@@ -508,7 +502,7 @@ static void request_input_reply(DBusMessage *reply, void *user_data)
goto done;
}
- if (vpn_agent_check_reply_has_dict(reply) == FALSE)
+ if (!vpn_agent_check_reply_has_dict(reply))
goto done;
dbus_message_iter_init(reply, &iter);
@@ -567,7 +561,8 @@ typedef void (* request_cb_t)(struct vpn_provider *provider,
const char *error, void *user_data);
static int request_input(struct vpn_provider *provider,
- request_cb_t callback, void *user_data)
+ request_cb_t callback, const char *dbus_sender,
+ void *user_data)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
@@ -575,16 +570,17 @@ static int request_input(struct vpn_provider *provider,
DBusMessageIter dict;
struct request_input_reply *l2tp_reply;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
-
- if (provider == NULL || agent_path == NULL || callback == NULL)
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
+ if (!provider || !agent || !agent_path || !callback)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
VPN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -602,7 +598,7 @@ static int request_input(struct vpn_provider *provider,
connman_dbus_dict_close(&iter, &dict);
l2tp_reply = g_try_new0(struct request_input_reply, 1);
- if (l2tp_reply == NULL) {
+ if (!l2tp_reply) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -613,7 +609,7 @@ static int request_input(struct vpn_provider *provider,
err = connman_agent_queue_message(provider, message,
connman_timeout_input_request(),
- request_input_reply, l2tp_reply);
+ request_input_reply, l2tp_reply, agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
@@ -635,7 +631,7 @@ static int run_connect(struct vpn_provider *provider,
int l2tp_fd, pppd_fd;
int err;
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
DBG("Cannot connect username %s password %p",
username, password);
err = -EINVAL;
@@ -644,7 +640,7 @@ static int run_connect(struct vpn_provider *provider,
DBG("username %s password %p", username, password);
- l2tp_name = g_strdup_printf("/var/run/connman/connman-xl2tpd.conf");
+ l2tp_name = g_strdup_printf(VPN_STATEDIR "/connman-xl2tpd.conf");
l2tp_fd = open(l2tp_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (l2tp_fd < 0) {
@@ -654,7 +650,7 @@ static int run_connect(struct vpn_provider *provider,
goto done;
}
- pppd_name = g_strdup_printf("/var/run/connman/connman-ppp-option.conf");
+ pppd_name = g_strdup_printf(VPN_STATEDIR "/connman-ppp-option.conf");
pppd_fd = open(pppd_name, O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (pppd_fd < 0) {
@@ -675,6 +671,8 @@ static int run_connect(struct vpn_provider *provider,
g_free(l2tp_name);
g_free(pppd_name);
+ close(l2tp_fd);
+ close(pppd_fd);
err = connman_task_run(task, l2tp_died, provider,
NULL, NULL, NULL);
@@ -685,7 +683,7 @@ static int run_connect(struct vpn_provider *provider,
}
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
@@ -704,10 +702,10 @@ static void request_input_cb(struct vpn_provider *provider,
{
struct l2tp_private_data *data = user_data;
- if (username == NULL || password == NULL)
+ if (!username || !password)
DBG("Requesting username %s or password failed, error %s",
username, error);
- else if (error != NULL)
+ else if (error)
DBG("error %s", error);
vpn_provider_set_string(provider, "L2TP.User", username);
@@ -722,7 +720,8 @@ static void request_input_cb(struct vpn_provider *provider,
static int l2tp_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *username, *password;
int err;
@@ -738,11 +737,11 @@ static int l2tp_connect(struct vpn_provider *provider,
DBG("user %s password %p", username, password);
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
struct l2tp_private_data *data;
data = g_try_new0(struct l2tp_private_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->task = task;
@@ -750,7 +749,8 @@ static int l2tp_connect(struct vpn_provider *provider,
data->cb = cb;
data->user_data = user_data;
- err = request_input(provider, request_input_cb, data);
+ err = request_input(provider, request_input_cb, dbus_sender,
+ data);
if (err != -EINPROGRESS) {
free_private_data(data);
goto done;
@@ -763,13 +763,13 @@ done:
username, password);
error:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
}
-static int l2tp_error_code(int exit_code)
+static int l2tp_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
case 1:
diff --git a/vpn/plugins/openconnect.c b/vpn/plugins/openconnect.c
index 83584da8..c6b9cd65 100644
--- a/vpn/plugins/openconnect.c
+++ b/vpn/plugins/openconnect.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-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
@@ -57,12 +57,19 @@ struct {
};
struct oc_private_data {
+ struct vpn_provider *provider;
struct connman_task *task;
char *if_name;
vpn_provider_connect_cb_t cb;
void *user_data;
};
+static void free_private_data(struct oc_private_data *data)
+{
+ g_free(data->if_name);
+ g_free(data);
+}
+
static int task_append_config_data(struct vpn_provider *provider,
struct connman_task *task)
{
@@ -70,12 +77,12 @@ static int task_append_config_data(struct vpn_provider *provider,
int i;
for (i = 0; i < (int)ARRAY_SIZE(oc_options); i++) {
- if (oc_options[i].oc_opt == NULL)
+ if (!oc_options[i].oc_opt)
continue;
option = vpn_provider_get_string(provider,
oc_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
if (connman_task_add_argument(task,
@@ -144,7 +151,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
/* The netmask contains the address and the prefix */
sep = strchr(value, '/');
- if (sep != NULL) {
+ if (sep) {
unsigned char ip_len = sep - value;
addressv6 = g_strndup(value, ip_len);
@@ -160,13 +167,13 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
if (!strcmp(key, "CISCO_PROXY_PAC"))
vpn_provider_set_pac(provider, value);
- if (domain == NULL && !strcmp(key, "CISCO_DEF_DOMAIN")) {
+ if (!domain && !strcmp(key, "CISCO_DEF_DOMAIN")) {
g_free(domain);
domain = g_strdup(value);
}
- if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
- g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
+ if (g_str_has_prefix(key, "CISCO_SPLIT_INC") ||
+ g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC"))
vpn_provider_append_route(provider, key, value);
dbus_message_iter_next(&dict);
@@ -174,14 +181,14 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%p %p", addressv4, addressv6);
- if (addressv4 != NULL)
+ if (addressv4)
ipaddress = connman_ipaddress_alloc(AF_INET);
- else if (addressv6 != NULL)
+ else if (addressv6)
ipaddress = connman_ipaddress_alloc(AF_INET6);
else
ipaddress = NULL;
- if (ipaddress == NULL) {
+ if (!ipaddress) {
g_free(addressv4);
g_free(addressv6);
g_free(netmask);
@@ -191,7 +198,7 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_FAILURE;
}
- if (addressv4 != NULL)
+ if (addressv4)
connman_ipaddress_set_ipv4(ipaddress, addressv4,
netmask, gateway);
else
@@ -210,8 +217,85 @@ static int oc_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_CONNECT;
}
-static void request_input_append_cookie(DBusMessageIter *iter,
- void *user_data)
+static int run_connect(struct vpn_provider *provider,
+ struct connman_task *task, const char *if_name,
+ vpn_provider_connect_cb_t cb, void *user_data)
+{
+ const char *vpnhost, *vpncookie, *servercert, *mtu;
+ int fd, err = 0, len;
+
+ vpnhost = vpn_provider_get_string(provider, "OpenConnect.VPNHost");
+ if (!vpnhost)
+ vpnhost = vpn_provider_get_string(provider, "Host");
+ vpncookie = vpn_provider_get_string(provider, "OpenConnect.Cookie");
+ servercert = vpn_provider_get_string(provider,
+ "OpenConnect.ServerCert");
+
+ if (!vpncookie || !servercert) {
+ err = -EINVAL;
+ goto done;
+ }
+
+ task_append_config_data(provider, task);
+
+ connman_task_add_argument(task, "--servercert", servercert);
+
+ mtu = vpn_provider_get_string(provider, "VPN.MTU");
+
+ if (mtu)
+ connman_task_add_argument(task, "--mtu", (char *)mtu);
+
+ connman_task_add_argument(task, "--syslog", NULL);
+ connman_task_add_argument(task, "--cookie-on-stdin", NULL);
+
+ connman_task_add_argument(task, "--script",
+ SCRIPTDIR "/openconnect-script");
+
+ connman_task_add_argument(task, "--interface", if_name);
+
+ connman_task_add_argument(task, (char *)vpnhost, NULL);
+
+ err = connman_task_run(task, vpn_died, provider,
+ &fd, NULL, NULL);
+ if (err < 0) {
+ connman_error("openconnect failed to start");
+ err = -EIO;
+ goto done;
+ }
+
+ len = strlen(vpncookie);
+ if (write(fd, vpncookie, len) != (ssize_t)len ||
+ write(fd, "\n", 1) != 1) {
+ connman_error("openconnect failed to take cookie on stdin");
+ err = -EIO;
+ goto done;
+ }
+
+done:
+ if (cb)
+ cb(provider, user_data, err);
+
+ return err;
+}
+
+static void request_input_append_informational(DBusMessageIter *iter,
+ void *user_data)
+{
+ const char *str;
+
+ str = "string";
+ connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING, &str);
+
+ str = "informational";
+ connman_dbus_dict_append_basic(iter, "Requirement", DBUS_TYPE_STRING,
+ &str);
+
+ str = user_data;
+ connman_dbus_dict_append_basic(iter, "Value", DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_mandatory(DBusMessageIter *iter,
+ void *user_data)
{
char *str = "string";
@@ -222,29 +306,20 @@ static void request_input_append_cookie(DBusMessageIter *iter,
DBUS_TYPE_STRING, &str);
}
-struct request_input_reply {
- struct vpn_provider *provider;
- vpn_provider_auth_cb_t callback;
- void *user_data;
-};
-
static void request_input_cookie_reply(DBusMessage *reply, void *user_data)
{
- struct request_input_reply *cookie_reply = user_data;
- const char *error = NULL;
- char *cookie = NULL;
+ struct oc_private_data *data = user_data;
+ char *cookie = NULL, *servercert = NULL, *vpnhost = NULL;
char *key;
DBusMessageIter iter, dict;
- DBG("provider %p", cookie_reply->provider);
+ DBG("provider %p", data->provider);
- if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) {
- error = dbus_message_get_error_name(reply);
- goto done;
- }
+ if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+ goto err;
- if (vpn_agent_check_reply_has_dict(reply) == FALSE)
- goto done;
+ if (!vpn_agent_check_reply_has_dict(reply))
+ goto err;
dbus_message_iter_init(reply, &iter);
dbus_message_iter_recurse(&iter, &dict);
@@ -267,40 +342,76 @@ static void request_input_cookie_reply(DBusMessage *reply, void *user_data)
!= DBUS_TYPE_STRING)
break;
dbus_message_iter_get_basic(&value, &cookie);
+ vpn_provider_set_string_hide_value(data->provider,
+ key, cookie);
+
+ } else if (g_str_equal(key, "OpenConnect.ServerCert")) {
+ dbus_message_iter_next(&entry);
+ if (dbus_message_iter_get_arg_type(&entry)
+ != DBUS_TYPE_VARIANT)
+ break;
+ dbus_message_iter_recurse(&entry, &value);
+ if (dbus_message_iter_get_arg_type(&value)
+ != DBUS_TYPE_STRING)
+ break;
+ dbus_message_iter_get_basic(&value, &servercert);
+ vpn_provider_set_string(data->provider, key,
+ servercert);
+
+ } else if (g_str_equal(key, "OpenConnect.VPNHost")) {
+ dbus_message_iter_next(&entry);
+ if (dbus_message_iter_get_arg_type(&entry)
+ != DBUS_TYPE_VARIANT)
+ break;
+ dbus_message_iter_recurse(&entry, &value);
+ if (dbus_message_iter_get_arg_type(&value)
+ != DBUS_TYPE_STRING)
+ break;
+ dbus_message_iter_get_basic(&value, &vpnhost);
+ vpn_provider_set_string(data->provider, key, vpnhost);
}
dbus_message_iter_next(&dict);
}
-done:
- cookie_reply->callback(cookie_reply->provider, cookie, error,
- cookie_reply->user_data);
- g_free(cookie_reply);
-}
+ if (!cookie || !servercert || !vpnhost)
+ goto err;
+
+ run_connect(data->provider, data->task, data->if_name, data->cb,
+ data->user_data);
+
+ free_private_data(data);
-typedef void (* request_cb_t)(struct vpn_provider *provider,
- const char *vpncookie,
- const char *error, void *user_data);
+ return;
+
+err:
+ vpn_provider_indicate_error(data->provider,
+ VPN_PROVIDER_ERROR_AUTH_FAILED);
+
+ free_private_data(data);
+}
static int request_cookie_input(struct vpn_provider *provider,
- request_cb_t callback, void *user_data)
+ struct oc_private_data *data,
+ const char *dbus_sender)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
DBusMessageIter iter;
DBusMessageIter dict;
- struct request_input_reply *cookie_reply;
+ const char *str;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
-
- if (provider == NULL || agent_path == NULL || callback == NULL)
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
+ if (!provider || !agent || !agent_path)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
VPN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -311,30 +422,39 @@ static int request_cookie_input(struct vpn_provider *provider,
connman_dbus_dict_open(&iter, &dict);
+ str = vpn_provider_get_string(provider, "OpenConnect.CACert");
+ if (str)
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.CACert",
+ request_input_append_informational,
+ (void *)str);
+
+ str = vpn_provider_get_string(provider, "OpenConnect.ClientCert");
+ if (str)
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.ClientCert",
+ request_input_append_informational,
+ (void *)str);
+
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.ServerCert",
+ request_input_append_mandatory, NULL);
+
+ connman_dbus_dict_append_dict(&dict, "OpenConnect.VPNHost",
+ request_input_append_mandatory, NULL);
+
connman_dbus_dict_append_dict(&dict, "OpenConnect.Cookie",
- request_input_append_cookie, provider);
+ request_input_append_mandatory, NULL);
vpn_agent_append_host_and_name(&dict, provider);
connman_dbus_dict_close(&iter, &dict);
- cookie_reply = g_try_new0(struct request_input_reply, 1);
- if (cookie_reply == NULL) {
- dbus_message_unref(message);
- return -ENOMEM;
- }
-
- cookie_reply->provider = provider;
- cookie_reply->callback = callback;
- cookie_reply->user_data = user_data;
-
err = connman_agent_queue_message(provider, message,
connman_timeout_input_request(),
- request_input_cookie_reply, cookie_reply);
+ request_input_cookie_reply, data, agent);
+
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
- g_free(cookie_reply);
+
return err;
}
@@ -343,133 +463,46 @@ static int request_cookie_input(struct vpn_provider *provider,
return -EINPROGRESS;
}
-static int run_connect(struct vpn_provider *provider,
- struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data,
- const char *vpncookie)
-{
- const char *vpnhost, *cafile, *certsha1, *mtu;
- int fd, err = 0, len;
-
- vpnhost = vpn_provider_get_string(provider, "Host");
-
- if (vpncookie == NULL) {
- DBG("Cookie missing, cannot connect!");
- err = -EINVAL;
- goto done;
- }
-
- task_append_config_data(provider, task);
-
- vpn_provider_set_string(provider, "OpenConnect.Cookie", vpncookie);
-
- certsha1 = vpn_provider_get_string(provider,
- "OpenConnect.ServerCert");
- if (certsha1)
- connman_task_add_argument(task, "--servercert",
- (char *)certsha1);
-
- cafile = vpn_provider_get_string(provider, "OpenConnect.CACert");
- mtu = vpn_provider_get_string(provider, "VPN.MTU");
-
- if (cafile)
- connman_task_add_argument(task, "--cafile",
- (char *)cafile);
- if (mtu)
- connman_task_add_argument(task, "--mtu", (char *)mtu);
-
- connman_task_add_argument(task, "--syslog", NULL);
- connman_task_add_argument(task, "--cookie-on-stdin", NULL);
-
- connman_task_add_argument(task, "--script",
- SCRIPTDIR "/openconnect-script");
-
- connman_task_add_argument(task, "--interface", if_name);
-
- connman_task_add_argument(task, (char *)vpnhost, NULL);
-
- err = connman_task_run(task, vpn_died, provider,
- &fd, NULL, NULL);
- if (err < 0) {
- connman_error("openconnect failed to start");
- err = -EIO;
- goto done;
- }
-
- len = strlen(vpncookie);
- if (write(fd, vpncookie, len) != (ssize_t)len ||
- write(fd, "\n", 1) != 1) {
- connman_error("openconnect failed to take cookie on stdin");
- err = -EIO;
- goto done;
- }
-
-done:
- if (cb != NULL)
- cb(provider, user_data, err);
-
- return err;
-}
-
-static void free_private_data(struct oc_private_data *data)
-{
- g_free(data->if_name);
- g_free(data);
-}
-
-static void request_input_cb(struct vpn_provider *provider,
- const char *vpncookie,
- const char *error, void *user_data)
-{
- struct oc_private_data *data = user_data;
-
- if (vpncookie == NULL)
- DBG("Requesting cookie failed, error %s", error);
- else if (error != NULL)
- DBG("error %s", error);
-
- run_connect(provider, data->task, data->if_name, data->cb,
- data->user_data, vpncookie);
-
- free_private_data(data);
-}
-
static int oc_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb,
+ const char *dbus_sender, void *user_data)
{
- const char *vpnhost, *vpncookie;
+ const char *vpnhost, *vpncookie, *servercert;
int err;
vpnhost = vpn_provider_get_string(provider, "Host");
- if (vpnhost == NULL) {
+ if (!vpnhost) {
connman_error("Host not set; cannot enable VPN");
return -EINVAL;
}
vpncookie = vpn_provider_get_string(provider, "OpenConnect.Cookie");
- if (vpncookie == NULL) {
+ servercert = vpn_provider_get_string(provider,
+ "OpenConnect.ServerCert");
+ if (!vpncookie || !servercert) {
struct oc_private_data *data;
data = g_try_new0(struct oc_private_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
+ data->provider = provider;
data->task = task;
data->if_name = g_strdup(if_name);
data->cb = cb;
data->user_data = user_data;
- err = request_cookie_input(provider, request_input_cb, data);
+ err = request_cookie_input(provider, data, dbus_sender);
if (err != -EINPROGRESS) {
+ vpn_provider_indicate_error(data->provider,
+ VPN_PROVIDER_ERROR_LOGIN_FAILED);
free_private_data(data);
- goto done;
}
return err;
}
-done:
- return run_connect(provider, task, if_name, cb, user_data, vpncookie);
+ return run_connect(provider, task, if_name, cb, user_data);
}
static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
@@ -479,21 +512,21 @@ static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
setting = vpn_provider_get_string(provider,
"OpenConnect.ServerCert");
- if (setting != NULL)
+ if (setting)
g_key_file_set_string(keyfile,
vpn_provider_get_save_group(provider),
"OpenConnect.ServerCert", setting);
setting = vpn_provider_get_string(provider,
"OpenConnect.CACert");
- if (setting != NULL)
+ if (setting)
g_key_file_set_string(keyfile,
vpn_provider_get_save_group(provider),
"OpenConnect.CACert", setting);
setting = vpn_provider_get_string(provider,
"VPN.MTU");
- if (setting != NULL)
+ if (setting)
g_key_file_set_string(keyfile,
vpn_provider_get_save_group(provider),
"VPN.MTU", setting);
@@ -502,7 +535,7 @@ static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
if (strncmp(oc_options[i].cm_opt, "OpenConnect.", 12) == 0) {
option = vpn_provider_get_string(provider,
oc_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
g_key_file_set_string(keyfile,
@@ -514,13 +547,15 @@ static int oc_save(struct vpn_provider *provider, GKeyFile *keyfile)
return 0;
}
-static int oc_error_code(int exit_code)
+static int oc_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
case 1:
return VPN_PROVIDER_ERROR_CONNECT_FAILED;
case 2:
+ vpn_provider_set_string_hide_value(provider,
+ "OpenConnect.Cookie", NULL);
return VPN_PROVIDER_ERROR_LOGIN_FAILED;
default:
return VPN_PROVIDER_ERROR_UNKNOWN;
diff --git a/vpn/plugins/openvpn.c b/vpn/plugins/openvpn.c
index 486944d5..35013c40 100644
--- a/vpn/plugins/openvpn.c
+++ b/vpn/plugins/openvpn.c
@@ -84,18 +84,18 @@ static struct nameserver_entry *ov_append_dns_entries(const char *key,
struct nameserver_entry *entry = NULL;
gchar **options;
- if (g_str_has_prefix(key, "foreign_option_") == FALSE)
+ if (!g_str_has_prefix(key, "foreign_option_"))
return NULL;
options = g_strsplit(value, " ", 3);
- if (options[0] != NULL &&
+ if (options[0] &&
!strcmp(options[0], "dhcp-option") &&
- options[1] != NULL &&
+ options[1] &&
!strcmp(options[1], "DNS") &&
- options[2] != NULL) {
+ options[2]) {
entry = g_try_new(struct nameserver_entry, 1);
- if (entry == NULL)
+ if (!entry)
return NULL;
entry->nameserver = g_strdup(options[2]);
@@ -112,15 +112,15 @@ static char *ov_get_domain_name(const char *key, const char *value)
gchar **options;
char *domain = NULL;
- if (g_str_has_prefix(key, "foreign_option_") == FALSE)
+ if (!g_str_has_prefix(key, "foreign_option_"))
return NULL;
options = g_strsplit(value, " ", 3);
- if (options[0] != NULL &&
+ if (options[0] &&
!strcmp(options[0], "dhcp-option") &&
- options[1] != NULL &&
+ options[1] &&
!strcmp(options[1], "DOMAIN") &&
- options[2] != NULL) {
+ options[2]) {
domain = g_strdup(options[2]);
}
@@ -186,30 +186,24 @@ static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%s = %s", key, value);
- if (!strcmp(key, "trusted_ip")) {
- vpn_provider_set_string(provider, "Gateway", value);
+ if (!strcmp(key, "trusted_ip"))
gateway = g_strdup(value);
- }
- if (!strcmp(key, "ifconfig_local")) {
- vpn_provider_set_string(provider, "Address", value);
+ if (!strcmp(key, "ifconfig_local"))
address = g_strdup(value);
- }
- if (!strcmp(key, "ifconfig_remote")) {
- vpn_provider_set_string(provider, "Peer", value);
+ if (!strcmp(key, "ifconfig_remote"))
peer = g_strdup(value);
- }
- if (g_str_has_prefix(key, "route_") == TRUE)
+ if (g_str_has_prefix(key, "route_"))
vpn_provider_append_route(provider, key, value);
- if ((ns_entry = ov_append_dns_entries(key, value)) != NULL)
+ if ((ns_entry = ov_append_dns_entries(key, value)))
nameserver_list = g_slist_prepend(nameserver_list,
ns_entry);
else {
char *domain = ov_get_domain_name(key, value);
- if (domain != NULL) {
+ if (domain) {
vpn_provider_set_domain(provider, domain);
g_free(domain);
}
@@ -219,7 +213,7 @@ static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
}
ipaddress = connman_ipaddress_alloc(AF_INET);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
g_slist_free_full(nameserver_list, free_ns_entry);
g_free(address);
g_free(gateway);
@@ -232,16 +226,16 @@ static int ov_notify(DBusMessage *msg, struct vpn_provider *provider)
connman_ipaddress_set_peer(ipaddress, peer);
vpn_provider_set_ipaddress(provider, ipaddress);
- if (nameserver_list != NULL) {
+ if (nameserver_list) {
char *nameservers = NULL;
GSList *tmp;
nameserver_list = g_slist_sort(nameserver_list, cmp_ns);
- for (tmp = nameserver_list; tmp != NULL;
+ for (tmp = nameserver_list; tmp;
tmp = g_slist_next(tmp)) {
struct nameserver_entry *ns = tmp->data;
- if (nameservers == NULL) {
+ if (!nameservers) {
nameservers = g_strdup(ns->nameserver);
} else {
char *str;
@@ -276,7 +270,7 @@ static int ov_save(struct vpn_provider *provider, GKeyFile *keyfile)
if (strncmp(ov_options[i].cm_opt, "OpenVPN.", 8) == 0) {
option = vpn_provider_get_string(provider,
ov_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
g_key_file_set_string(keyfile,
@@ -294,12 +288,12 @@ static int task_append_config_data(struct vpn_provider *provider,
int i;
for (i = 0; i < (int)ARRAY_SIZE(ov_options); i++) {
- if (ov_options[i].ov_opt == NULL)
+ if (!ov_options[i].ov_opt)
continue;
option = vpn_provider_get_string(provider,
ov_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
if (connman_task_add_argument(task,
@@ -314,13 +308,14 @@ static int task_append_config_data(struct vpn_provider *provider,
static int ov_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *option;
int err = 0, fd;
option = vpn_provider_get_string(provider, "Host");
- if (option == NULL) {
+ if (!option) {
connman_error("Host not set; cannot enable VPN");
return -EINVAL;
}
@@ -328,16 +323,16 @@ static int ov_connect(struct vpn_provider *provider,
task_append_config_data(provider, task);
option = vpn_provider_get_string(provider, "OpenVPN.ConfigFile");
- if (option == NULL) {
+ if (!option) {
/*
* Set some default options if user has no config file.
*/
option = vpn_provider_get_string(provider, "OpenVPN.TLSAuth");
- if (option != NULL) {
+ if (option) {
connman_task_add_argument(task, "--tls-auth", option);
option = vpn_provider_get_string(provider,
"OpenVPN.TLSAuthDir");
- if (option != NULL)
+ if (option)
connman_task_add_argument(task, option, NULL);
}
@@ -394,7 +389,7 @@ static int ov_connect(struct vpn_provider *provider,
}
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
diff --git a/vpn/plugins/pptp.c b/vpn/plugins/pptp.c
index 01b5e2ba..a6e51e79 100644
--- a/vpn/plugins/pptp.c
+++ b/vpn/plugins/pptp.c
@@ -2,8 +2,8 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
- * Copyright (C) 2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2010,2013 BMW Car IT GmbH. 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
@@ -96,17 +96,17 @@ static DBusMessage *pptp_get_sec(struct connman_task *task,
struct vpn_provider *provider = user_data;
DBusMessage *reply;
- if (dbus_message_get_no_reply(msg) == TRUE)
+ if (dbus_message_get_no_reply(msg))
return NULL;
user = vpn_provider_get_string(provider, "PPTP.User");
passwd = vpn_provider_get_string(provider, "PPTP.Password");
- if (user == NULL || strlen(user) == 0 ||
- passwd == NULL || strlen(passwd) == 0)
+ if (!user || strlen(user) == 0 ||
+ !passwd || strlen(passwd) == 0)
return NULL;
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_append_args(reply, DBUS_TYPE_STRING, &user,
@@ -128,7 +128,7 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
dbus_message_iter_get_basic(&iter, &reason);
dbus_message_iter_next(&iter);
- if (provider == NULL) {
+ if (!provider) {
connman_error("No provider found");
return VPN_STATE_FAILURE;
}
@@ -157,20 +157,14 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
DBG("%s = %s", key, value);
- if (!strcmp(key, "INTERNAL_IP4_ADDRESS")) {
- vpn_provider_set_string(provider, "Address", value);
+ if (!strcmp(key, "INTERNAL_IP4_ADDRESS"))
addressv4 = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_NETMASK")) {
- vpn_provider_set_string(provider, "Netmask", value);
+ if (!strcmp(key, "INTERNAL_IP4_NETMASK"))
netmask = g_strdup(value);
- }
- if (!strcmp(key, "INTERNAL_IP4_DNS")) {
- vpn_provider_set_string(provider, "DNS", value);
+ if (!strcmp(key, "INTERNAL_IP4_DNS"))
nameservers = g_strdup(value);
- }
if (!strcmp(key, "INTERNAL_IFNAME"))
ifname = g_strdup(value);
@@ -186,12 +180,12 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
return VPN_STATE_FAILURE;
}
- if (addressv4 != NULL)
+ if (addressv4)
ipaddress = connman_ipaddress_alloc(AF_INET);
g_free(ifname);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
connman_error("No IP address for provider");
g_free(addressv4);
g_free(netmask);
@@ -200,12 +194,12 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
}
value = vpn_provider_get_string(provider, "HostIP");
- if (value != NULL) {
+ if (value) {
vpn_provider_set_string(provider, "Gateway", value);
gateway = g_strdup(value);
}
- if (addressv4 != NULL)
+ if (addressv4)
connman_ipaddress_set_ipv4(ipaddress, addressv4, netmask,
gateway);
@@ -224,29 +218,29 @@ static int pptp_notify(DBusMessage *msg, struct vpn_provider *provider)
static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
{
const char *option;
- connman_bool_t pptp_option, pppd_option;
+ bool pptp_option, pppd_option;
int i;
for (i = 0; i < (int)ARRAY_SIZE(pptp_options); i++) {
- pptp_option = pppd_option = FALSE;
+ pptp_option = pppd_option = false;
if (strncmp(pptp_options[i].cm_opt, "PPTP.", 5) == 0)
- pptp_option = TRUE;
+ pptp_option = true;
if (strncmp(pptp_options[i].cm_opt, "PPPD.", 5) == 0)
- pppd_option = TRUE;
+ pppd_option = true;
- if (pptp_option == TRUE || pppd_option == TRUE) {
+ if (pptp_option || pppd_option) {
option = vpn_provider_get_string(provider,
pptp_options[i].cm_opt);
- if (option == NULL) {
+ if (!option) {
/*
* Check if the option prefix is PPTP as the
* PPPD options were using PPTP prefix earlier.
*/
char *pptp_str;
- if (pppd_option == FALSE)
+ if (!pppd_option)
continue;
pptp_str = g_strdup_printf("PPTP.%s",
@@ -255,7 +249,7 @@ static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
pptp_str);
g_free(pptp_str);
- if (option == NULL)
+ if (!option)
continue;
}
@@ -271,7 +265,7 @@ static int pptp_save(struct vpn_provider *provider, GKeyFile *keyfile)
static void pptp_write_bool_option(struct connman_task *task,
const char *key, const char *value)
{
- if (key != NULL && value != NULL) {
+ if (key && value) {
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "true") == 0 ||
strcmp(value, "1") == 0)
@@ -300,7 +294,7 @@ static void request_input_reply(DBusMessage *reply, void *user_data)
goto done;
}
- if (vpn_agent_check_reply_has_dict(reply) == FALSE)
+ if (!vpn_agent_check_reply_has_dict(reply))
goto done;
dbus_message_iter_init(reply, &iter);
@@ -359,7 +353,8 @@ typedef void (* request_cb_t)(struct vpn_provider *provider,
const char *error, void *user_data);
static int request_input(struct vpn_provider *provider,
- request_cb_t callback, void *user_data)
+ request_cb_t callback, const char *dbus_sender,
+ void *user_data)
{
DBusMessage *message;
const char *path, *agent_sender, *agent_path;
@@ -367,16 +362,17 @@ static int request_input(struct vpn_provider *provider,
DBusMessageIter dict;
struct request_input_reply *pptp_reply;
int err;
+ void *agent;
- connman_agent_get_info(&agent_sender, &agent_path);
-
- if (provider == NULL || agent_path == NULL || callback == NULL)
+ agent = connman_agent_get_info(dbus_sender, &agent_sender,
+ &agent_path);
+ if (!provider || !agent || !agent_path || !callback)
return -ESRCH;
message = dbus_message_new_method_call(agent_sender, agent_path,
VPN_AGENT_INTERFACE,
"RequestInput");
- if (message == NULL)
+ if (!message)
return -ENOMEM;
dbus_message_iter_init_append(message, &iter);
@@ -394,7 +390,7 @@ static int request_input(struct vpn_provider *provider,
connman_dbus_dict_close(&iter, &dict);
pptp_reply = g_try_new0(struct request_input_reply, 1);
- if (pptp_reply == NULL) {
+ if (!pptp_reply) {
dbus_message_unref(message);
return -ENOMEM;
}
@@ -405,7 +401,7 @@ static int request_input(struct vpn_provider *provider,
err = connman_agent_queue_message(provider, message,
connman_timeout_input_request(),
- request_input_reply, pptp_reply);
+ request_input_reply, pptp_reply, agent);
if (err < 0 && err != -EBUSY) {
DBG("error %d sending agent request", err);
dbus_message_unref(message);
@@ -428,13 +424,13 @@ static int run_connect(struct vpn_provider *provider,
int err, i;
host = vpn_provider_get_string(provider, "Host");
- if (host == NULL) {
+ if (!host) {
connman_error("Host not set; cannot enable VPN");
err = -EINVAL;
goto done;
}
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
DBG("Cannot connect username %s password %p",
username, password);
err = -EINVAL;
@@ -445,7 +441,7 @@ static int run_connect(struct vpn_provider *provider,
str = g_strdup_printf("%s %s --nolaunchpppd --loglevel 2",
PPTP, host);
- if (str == NULL) {
+ if (!str) {
connman_error("can not allocate memory");
err = -ENOMEM;
goto done;
@@ -465,10 +461,10 @@ static int run_connect(struct vpn_provider *provider,
for (i = 0; i < (int)ARRAY_SIZE(pptp_options); i++) {
opt_s = vpn_provider_get_string(provider,
pptp_options[i].cm_opt);
- if (opt_s == NULL)
+ if (!opt_s)
opt_s = pptp_options[i].vpnc_default;
- if (opt_s == NULL)
+ if (!opt_s)
continue;
if (pptp_options[i].type == OPT_STRING)
@@ -491,7 +487,7 @@ static int run_connect(struct vpn_provider *provider,
}
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
@@ -510,10 +506,10 @@ static void request_input_cb(struct vpn_provider *provider,
{
struct pptp_private_data *data = user_data;
- if (username == NULL || password == NULL)
+ if (!username || !password)
DBG("Requesting username %s or password failed, error %s",
username, error);
- else if (error != NULL)
+ else if (error)
DBG("error %s", error);
vpn_provider_set_string(provider, "PPTP.User", username);
@@ -528,7 +524,8 @@ static void request_input_cb(struct vpn_provider *provider,
static int pptp_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *username, *password;
int err;
@@ -546,11 +543,11 @@ static int pptp_connect(struct vpn_provider *provider,
DBG("user %s password %p", username, password);
- if (username == NULL || password == NULL) {
+ if (!username || !password) {
struct pptp_private_data *data;
data = g_try_new0(struct pptp_private_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->task = task;
@@ -558,7 +555,8 @@ static int pptp_connect(struct vpn_provider *provider,
data->cb = cb;
data->user_data = user_data;
- err = request_input(provider, request_input_cb, data);
+ err = request_input(provider, request_input_cb, dbus_sender,
+ data);
if (err != -EINPROGRESS) {
free_private_data(data);
goto done;
@@ -571,13 +569,13 @@ done:
username, password);
error:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
}
-static int pptp_error_code(int exit_code)
+static int pptp_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
diff --git a/vpn/plugins/vpn.c b/vpn/plugins/vpn.c
index 99f829cd..b407573e 100644
--- a/vpn/plugins/vpn.c
+++ b/vpn/plugins/vpn.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-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
@@ -75,16 +75,16 @@ static int stop_vpn(struct vpn_provider *provider)
struct ifreq ifr;
int fd, err;
- if (data == NULL)
+ if (!data)
return -EINVAL;
name = vpn_provider_get_driver_name(provider);
- if (name == NULL)
+ if (!name)
return -EINVAL;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data != NULL && vpn_driver_data->vpn_driver != NULL &&
+ if (vpn_driver_data && vpn_driver_data->vpn_driver &&
vpn_driver_data->vpn_driver->flags == VPN_FLAG_NO_TUN)
return 0;
@@ -129,7 +129,7 @@ void vpn_died(struct connman_task *task, int exit_code, void *user_data)
DBG("provider %p data %p", provider, data);
- if (data == NULL)
+ if (!data)
goto vpn_exit;
state = data->state;
@@ -149,12 +149,13 @@ vpn_exit:
struct vpn_driver_data *vpn_data = NULL;
name = vpn_provider_get_driver_name(provider);
- if (name != NULL)
+ if (name)
vpn_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_data != NULL &&
- vpn_data->vpn_driver->error_code != NULL)
- ret = vpn_data->vpn_driver->error_code(exit_code);
+ if (vpn_data &&
+ vpn_data->vpn_driver->error_code)
+ ret = vpn_data->vpn_driver->error_code(provider,
+ exit_code);
else
ret = VPN_PROVIDER_ERROR_UNKNOWN;
@@ -166,7 +167,7 @@ vpn_exit:
vpn_provider_set_index(provider, -1);
- if (data != NULL) {
+ if (data) {
vpn_provider_unref(data->provider);
g_free(data->if_name);
g_free(data);
@@ -180,14 +181,14 @@ int vpn_set_ifname(struct vpn_provider *provider, const char *ifname)
struct vpn_data *data = vpn_provider_get_data(provider);
int index;
- if (ifname == NULL || data == NULL)
+ if (!ifname || !data)
return -EIO;
index = connman_inet_ifindex(ifname);
if (index < 0)
return -EIO;
- if (data->if_name != NULL)
+ if (data->if_name)
g_free(data->if_name);
data->if_name = (char *)g_strdup(ifname);
@@ -224,14 +225,14 @@ static DBusMessage *vpn_notify(struct connman_task *task,
name = vpn_provider_get_driver_name(provider);
- if (name == NULL) {
+ if (!name) {
DBG("Cannot find VPN driver for provider %p", provider);
vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
return NULL;
}
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data == NULL) {
+ if (!vpn_driver_data) {
DBG("Cannot find VPN driver data for name %s", name);
vpn_provider_set_state(provider, VPN_PROVIDER_STATE_FAILURE);
return NULL;
@@ -290,7 +291,7 @@ static int vpn_create_tun(struct vpn_provider *provider)
int i, fd, index;
int ret = 0;
- if (data == NULL)
+ if (!data)
return -EISCONN;
fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC);
@@ -320,7 +321,7 @@ static int vpn_create_tun(struct vpn_provider *provider)
}
data->if_name = (char *)g_strdup(ifr.ifr_name);
- if (data->if_name == NULL) {
+ if (!data->if_name) {
connman_error("Failed to allocate memory");
close(fd);
ret = -ENOMEM;
@@ -354,7 +355,8 @@ exist_err:
}
static int vpn_connect(struct vpn_provider *provider,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb,
+ const char *dbus_sender, void *user_data)
{
struct vpn_data *data = vpn_provider_get_data(provider);
struct vpn_driver_data *vpn_driver_data;
@@ -362,7 +364,7 @@ static int vpn_connect(struct vpn_provider *provider,
int ret = 0;
enum vpn_state state = VPN_STATE_UNKNOWN;
- if (data != NULL)
+ if (data)
state = data->state;
DBG("data %p state %d", data, state);
@@ -370,7 +372,7 @@ static int vpn_connect(struct vpn_provider *provider,
switch (state) {
case VPN_STATE_UNKNOWN:
data = g_try_new0(struct vpn_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->provider = vpn_provider_ref(provider);
@@ -396,12 +398,12 @@ static int vpn_connect(struct vpn_provider *provider,
}
name = vpn_provider_get_driver_name(provider);
- if (name == NULL)
+ if (!name)
return -EINVAL;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data == NULL || vpn_driver_data->vpn_driver == NULL) {
+ if (!vpn_driver_data || !vpn_driver_data->vpn_driver) {
ret = -EINVAL;
goto exist_err;
}
@@ -414,7 +416,7 @@ static int vpn_connect(struct vpn_provider *provider,
data->task = connman_task_create(vpn_driver_data->program);
- if (data->task == NULL) {
+ if (!data->task) {
ret = -ENOMEM;
stop_vpn(provider);
goto exist_err;
@@ -430,7 +432,8 @@ static int vpn_connect(struct vpn_provider *provider,
}
ret = vpn_driver_data->vpn_driver->connect(provider, data->task,
- data->if_name, cb, user_data);
+ data->if_name, cb, dbus_sender,
+ user_data);
if (ret < 0 && ret != -EINPROGRESS) {
stop_vpn(provider);
connman_task_destroy(data->task);
@@ -468,11 +471,11 @@ static int vpn_disconnect(struct vpn_provider *provider)
DBG("disconnect provider %p:", provider);
- if (data == NULL)
+ if (!data)
return 0;
name = vpn_provider_get_driver_name(provider);
- if (name == NULL)
+ if (!name)
return 0;
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
@@ -496,7 +499,7 @@ static int vpn_remove(struct vpn_provider *provider)
struct vpn_data *data;
data = vpn_provider_get_data(provider);
- if (data == NULL)
+ if (!data)
return 0;
if (data->watch != 0) {
@@ -519,8 +522,8 @@ static int vpn_save(struct vpn_provider *provider, GKeyFile *keyfile)
name = vpn_provider_get_driver_name(provider);
vpn_driver_data = g_hash_table_lookup(driver_hash, name);
- if (vpn_driver_data != NULL &&
- vpn_driver_data->vpn_driver->save != NULL)
+ if (vpn_driver_data &&
+ vpn_driver_data->vpn_driver->save)
return vpn_driver_data->vpn_driver->save(provider, keyfile);
return 0;
@@ -532,7 +535,7 @@ int vpn_register(const char *name, struct vpn_driver *vpn_driver,
struct vpn_driver_data *data;
data = g_try_new0(struct vpn_driver_data, 1);
- if (data == NULL)
+ if (!data)
return -ENOMEM;
data->name = name;
@@ -547,12 +550,12 @@ int vpn_register(const char *name, struct vpn_driver *vpn_driver,
data->provider_driver.remove = vpn_remove;
data->provider_driver.save = vpn_save;
- if (driver_hash == NULL)
+ if (!driver_hash)
driver_hash = g_hash_table_new_full(g_str_hash,
g_str_equal,
NULL, g_free);
- if (driver_hash == NULL) {
+ if (!driver_hash) {
connman_error("driver_hash not initialized for %s", name);
g_free(data);
return -ENOMEM;
@@ -570,7 +573,7 @@ void vpn_unregister(const char *name)
struct vpn_driver_data *data;
data = g_hash_table_lookup(driver_hash, name);
- if (data == NULL)
+ if (!data)
return;
vpn_provider_driver_unregister(&data->provider_driver);
diff --git a/vpn/plugins/vpn.h b/vpn/plugins/vpn.h
index 6f86aac5..3d2b66c5 100644
--- a/vpn/plugins/vpn.h
+++ b/vpn/plugins/vpn.h
@@ -45,9 +45,10 @@ struct vpn_driver {
int (*notify) (DBusMessage *msg, struct vpn_provider *provider);
int (*connect) (struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data);
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data);
void (*disconnect) (struct vpn_provider *provider);
- int (*error_code) (int exit_code);
+ int (*error_code) (struct vpn_provider *provider, int exit_code);
int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
};
diff --git a/vpn/plugins/vpnc.c b/vpn/plugins/vpnc.c
index 9f69850f..04235c86 100644
--- a/vpn/plugins/vpnc.c
+++ b/vpn/plugins/vpnc.c
@@ -2,8 +2,8 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
- * Copyright (C) 2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2010,2013 BMW Car IT GmbH. All rights reserved.
+ * Copyright (C) 2010,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
@@ -57,29 +57,29 @@ struct {
const char *vpnc_opt;
const char *vpnc_default;
int type;
- connman_bool_t cm_save;
+ bool cm_save;
} vpnc_options[] = {
- { "Host", "IPSec gateway", NULL, OPT_STRING, TRUE },
- { "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING, TRUE },
- { "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING, FALSE },
- { "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING, FALSE },
- { "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING, FALSE },
- { "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING, TRUE },
- { "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING, TRUE },
- { "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING, TRUE },
- { "VPNC.Domain", "Domain", NULL, OPT_STRING, TRUE },
- { "VPNC.Vendor", "Vendor", NULL, OPT_STRING, TRUE },
- { "VPNC.LocalPort", "Local Port", "0", OPT_STRING, TRUE, },
+ { "Host", "IPSec gateway", NULL, OPT_STRING, true },
+ { "VPNC.IPSec.ID", "IPSec ID", NULL, OPT_STRING, true },
+ { "VPNC.IPSec.Secret", "IPSec secret", NULL, OPT_STRING, false },
+ { "VPNC.Xauth.Username", "Xauth username", NULL, OPT_STRING, false },
+ { "VPNC.Xauth.Password", "Xauth password", NULL, OPT_STRING, false },
+ { "VPNC.IKE.Authmode", "IKE Authmode", NULL, OPT_STRING, true },
+ { "VPNC.IKE.DHGroup", "IKE DH Group", NULL, OPT_STRING, true },
+ { "VPNC.PFS", "Perfect Forward Secrecy", NULL, OPT_STRING, true },
+ { "VPNC.Domain", "Domain", NULL, OPT_STRING, true },
+ { "VPNC.Vendor", "Vendor", NULL, OPT_STRING, true },
+ { "VPNC.LocalPort", "Local Port", "0", OPT_STRING, true, },
{ "VPNC.CiscoPort", "Cisco UDP Encapsulation Port", "0", OPT_STRING,
- TRUE },
- { "VPNC.AppVersion", "Application Version", NULL, OPT_STRING, TRUE },
+ true },
+ { "VPNC.AppVersion", "Application Version", NULL, OPT_STRING, true },
{ "VPNC.NATTMode", "NAT Traversal Mode", "cisco-udp", OPT_STRING,
- TRUE },
+ true },
{ "VPNC.DPDTimeout", "DPD idle timeout (our side)", NULL, OPT_STRING,
- TRUE },
- { "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN, TRUE },
+ true },
+ { "VPNC.SingleDES", "Enable Single DES", NULL, OPT_BOOLEAN, true },
{ "VPNC.NoEncryption", "Enable no encryption", NULL, OPT_BOOLEAN,
- TRUE },
+ true },
};
static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
@@ -129,8 +129,8 @@ static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
if (!strcmp(key, "CISCO_DEF_DOMAIN"))
vpn_provider_set_domain(provider, value);
- if (g_str_has_prefix(key, "CISCO_SPLIT_INC") == TRUE ||
- g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC") == TRUE)
+ if (g_str_has_prefix(key, "CISCO_SPLIT_INC") ||
+ g_str_has_prefix(key, "CISCO_IPV6_SPLIT_INC"))
vpn_provider_append_route(provider, key, value);
dbus_message_iter_next(&dict);
@@ -138,7 +138,7 @@ static int vc_notify(DBusMessage *msg, struct vpn_provider *provider)
ipaddress = connman_ipaddress_alloc(AF_INET);
- if (ipaddress == NULL) {
+ if (!ipaddress) {
g_free(address);
g_free(netmask);
g_free(gateway);
@@ -180,7 +180,7 @@ static ssize_t write_option(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
buf = g_strdup_printf("%s %s\n", key, value);
ret = full_write(fd, buf, strlen(buf));
@@ -195,7 +195,7 @@ static ssize_t write_bool_option(int fd, const char *key, const char *value)
gchar *buf;
ssize_t ret = 0;
- if (key != NULL && value != NULL) {
+ if (key && value) {
if (strcasecmp(value, "yes") == 0 ||
strcasecmp(value, "true") == 0 ||
strcmp(value, "1") == 0) {
@@ -217,10 +217,10 @@ static int vc_write_config_data(struct vpn_provider *provider, int fd)
for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
opt_s = vpn_provider_get_string(provider,
vpnc_options[i].cm_opt);
- if (opt_s == FALSE)
+ if (!opt_s)
opt_s = vpnc_options[i].vpnc_default;
- if (opt_s == FALSE)
+ if (!opt_s)
continue;
if (vpnc_options[i].type == OPT_STRING) {
@@ -246,12 +246,12 @@ static int vc_save(struct vpn_provider *provider, GKeyFile *keyfile)
for (i = 0; i < (int)ARRAY_SIZE(vpnc_options); i++) {
if (strncmp(vpnc_options[i].cm_opt, "VPNC.", 5) == 0) {
- if (vpnc_options[i].cm_save == FALSE)
+ if (!vpnc_options[i].cm_save)
continue;
option = vpn_provider_get_string(provider,
vpnc_options[i].cm_opt);
- if (option == NULL)
+ if (!option)
continue;
g_key_file_set_string(keyfile,
@@ -264,19 +264,20 @@ static int vc_save(struct vpn_provider *provider, GKeyFile *keyfile)
static int vc_connect(struct vpn_provider *provider,
struct connman_task *task, const char *if_name,
- vpn_provider_connect_cb_t cb, void *user_data)
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data)
{
const char *option;
int err = 0, fd;
option = vpn_provider_get_string(provider, "Host");
- if (option == NULL) {
+ if (!option) {
connman_error("Host not set; cannot enable VPN");
err = -EINVAL;
goto done;
}
option = vpn_provider_get_string(provider, "VPNC.IPSec.ID");
- if (option == NULL) {
+ if (!option) {
connman_error("Group not set; cannot enable VPN");
err = -EINVAL;
goto done;
@@ -292,7 +293,7 @@ static int vc_connect(struct vpn_provider *provider,
SCRIPTDIR "/openconnect-script");
option = vpn_provider_get_string(provider, "VPNC.Debug");
- if (option != NULL)
+ if (option)
connman_task_add_argument(task, "--debug", option);
connman_task_add_argument(task, "-", NULL);
@@ -310,13 +311,13 @@ static int vc_connect(struct vpn_provider *provider,
close(fd);
done:
- if (cb != NULL)
+ if (cb)
cb(provider, user_data, err);
return err;
}
-static int vc_error_code(int exit_code)
+static int vc_error_code(struct vpn_provider *provider, int exit_code)
{
switch (exit_code) {
case 1:
diff --git a/vpn/vpn-agent.c b/vpn/vpn-agent.c
index f1cfb1e0..b0b582b7 100644
--- a/vpn/vpn-agent.c
+++ b/vpn/vpn-agent.c
@@ -35,7 +35,7 @@
#include "vpn-agent.h"
#include "vpn.h"
-connman_bool_t vpn_agent_check_reply_has_dict(DBusMessage *reply)
+bool vpn_agent_check_reply_has_dict(DBusMessage *reply)
{
const char *signature = DBUS_TYPE_ARRAY_AS_STRING
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
@@ -43,8 +43,8 @@ connman_bool_t vpn_agent_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,
@@ -52,7 +52,7 @@ connman_bool_t vpn_agent_check_reply_has_dict(DBusMessage *reply)
dbus_message_get_sender(reply),
dbus_message_get_signature(reply));
- return FALSE;
+ return false;
}
static void request_input_append_name(DBusMessageIter *iter, void *user_data)
@@ -117,9 +117,9 @@ static void request_input_append_user_info(DBusMessageIter *iter,
connman_dbus_dict_append_basic(iter, "Requirement",
DBUS_TYPE_STRING, &str);
- if (data->username_str != NULL) {
+ if (data->username_str) {
str = vpn_provider_get_string(provider, data->username_str);
- if (str != NULL)
+ if (str)
connman_dbus_dict_append_basic(iter, "Value",
DBUS_TYPE_STRING, &str);
}
diff --git a/vpn/vpn-agent.h b/vpn/vpn-agent.h
index 821d7596..c7328d7f 100644
--- a/vpn/vpn-agent.h
+++ b/vpn/vpn-agent.h
@@ -34,7 +34,7 @@ extern "C" {
void vpn_agent_append_host_and_name(DBusMessageIter *iter,
struct vpn_provider *provider);
-connman_bool_t vpn_agent_check_reply_has_dict(DBusMessage *reply);
+bool vpn_agent_check_reply_has_dict(DBusMessage *reply);
void vpn_agent_append_user_info(DBusMessageIter *iter,
struct vpn_provider *provider,
const char *username_str);
diff --git a/vpn/vpn-config.c b/vpn/vpn-config.c
index 728b0763..293c64e0 100644
--- a/vpn/vpn-config.c
+++ b/vpn/vpn-config.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
@@ -64,7 +64,7 @@ struct vpn_config {
static GHashTable *config_table = NULL;
-static connman_bool_t cleanup = FALSE;
+static bool cleanup = false;
/* Definition of possible strings in the .config files */
#define CONFIG_KEY_NAME "Name"
@@ -96,7 +96,7 @@ static void unregister_provider(gpointer data)
struct vpn_provider *provider;
char *provider_id;
- if (cleanup == TRUE)
+ if (cleanup)
goto free_only;
provider_id = config_provider->provider_identifier;
@@ -105,10 +105,10 @@ static void unregister_provider(gpointer data)
config_provider->ident, provider_id);
provider = __vpn_provider_lookup(provider_id);
- if (provider != NULL)
+ if (provider)
__vpn_provider_delete(provider);
else {
- if (__connman_storage_remove_provider(provider_id) == FALSE)
+ if (!__connman_storage_remove_provider(provider_id))
DBG("Could not remove all files for provider %s",
provider_id);
}
@@ -132,19 +132,19 @@ static int set_string(struct vpn_config_provider *config_provider,
{
DBG("provider %p key %s value %s", config_provider, key, value);
- if (g_str_equal(key, "Type") == TRUE) {
+ if (g_str_equal(key, "Type")) {
g_free(config_provider->type);
config_provider->type = g_strdup(value);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
g_free(config_provider->name);
config_provider->name = g_strdup(value);
- } else if (g_str_equal(key, "Host") == TRUE) {
+ } else if (g_str_equal(key, "Host")) {
g_free(config_provider->host);
config_provider->host = g_strdup(value);
- } else if (g_str_equal(key, "Domain") == TRUE) {
+ } else if (g_str_equal(key, "Domain")) {
g_free(config_provider->domain);
config_provider->domain = g_strdup(value);
- } else if (g_str_equal(key, "Networks") == TRUE) {
+ } else if (g_str_equal(key, "Networks")) {
g_free(config_provider->networks);
config_provider->networks = g_strdup(value);
}
@@ -159,15 +159,15 @@ static const char *get_string(struct vpn_config_provider *config_provider,
{
DBG("provider %p key %s", config_provider, key);
- if (g_str_equal(key, "Type") == TRUE)
+ if (g_str_equal(key, "Type"))
return config_provider->type;
- else if (g_str_equal(key, "Name") == TRUE)
+ else if (g_str_equal(key, "Name"))
return config_provider->name;
- else if (g_str_equal(key, "Host") == TRUE)
+ else if (g_str_equal(key, "Host"))
return config_provider->host;
- else if (g_str_equal(key, "Domain") == TRUE)
+ else if (g_str_equal(key, "Domain"))
return config_provider->domain;
- else if (g_str_equal(key, "Networks") == TRUE)
+ else if (g_str_equal(key, "Networks"))
return config_provider->networks;
return g_hash_table_lookup(config_provider->setting_strings, key);
@@ -180,13 +180,13 @@ static void add_keys(struct vpn_config_provider *config_provider,
gsize nb_avail_keys, i;
avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
- if (avail_keys == NULL)
+ if (!avail_keys)
return;
for (i = 0 ; i < nb_avail_keys; i++) {
char *value = g_key_file_get_value(keyfile, group,
avail_keys[i], NULL);
- if (value == NULL) {
+ if (!value) {
connman_warn("Cannot find value for %s",
avail_keys[i]);
continue;
@@ -213,11 +213,11 @@ static int load_provider(GKeyFile *keyfile, const char *group,
return -EINVAL;
config_provider = g_hash_table_lookup(config->provider_table, ident);
- if (config_provider != NULL)
+ if (config_provider)
return -EALREADY;
config_provider = g_try_new0(struct vpn_config_provider, 1);
- if (config_provider == NULL)
+ if (!config_provider)
return -ENOMEM;
config_provider->ident = g_strdup(ident);
@@ -229,12 +229,12 @@ static int load_provider(GKeyFile *keyfile, const char *group,
host = get_string(config_provider, "Host");
domain = get_string(config_provider, "Domain");
- if (host != NULL && domain != NULL) {
+ if (host && domain) {
char *id = __vpn_provider_create_identifier(host, domain);
struct vpn_provider *provider;
provider = __vpn_provider_lookup(id);
- if (provider != NULL) {
+ if (provider) {
if (action == REMOVE) {
__vpn_provider_delete(provider);
err = 0;
@@ -298,7 +298,7 @@ static void check_keys(GKeyFile *keyfile, const char *group,
gsize nb_avail_keys, i, j;
avail_keys = g_key_file_get_keys(keyfile, group, &nb_avail_keys, NULL);
- if (avail_keys == NULL)
+ if (!avail_keys)
return;
for (i = 0 ; i < nb_avail_keys; i++) {
@@ -306,7 +306,7 @@ static void check_keys(GKeyFile *keyfile, const char *group,
if (g_strcmp0(avail_keys[i], possible_keys[j]) == 0)
break;
- if (possible_keys[j] == NULL)
+ if (!possible_keys[j])
connman_warn("Unknown configuration key %s in [%s]",
avail_keys[i], group);
}
@@ -320,42 +320,42 @@ static int load_config(struct vpn_config *config, char *path, enum what action)
gsize length;
char **groups;
char *str;
- gboolean found = FALSE;
+ bool found = false;
int i;
DBG("config %p", config);
keyfile = __connman_storage_load_provider_config(config->ident);
- if (keyfile == NULL)
+ if (!keyfile)
return -EIO;
/* Verify keys validity of the global section */
check_keys(keyfile, "global", config_possible_keys);
- str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
- if (str != NULL) {
+ str = __vpn_config_get_string(keyfile, "global", CONFIG_KEY_NAME, NULL);
+ if (str) {
g_free(config->name);
config->name = str;
}
- str = g_key_file_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
- if (str != NULL) {
+ str = __vpn_config_get_string(keyfile, "global", CONFIG_KEY_DESC, NULL);
+ if (str) {
g_free(config->description);
config->description = str;
}
groups = g_key_file_get_groups(keyfile, &length);
- for (i = 0; groups[i] != NULL; i++) {
- if (g_str_has_prefix(groups[i], "provider_") == TRUE) {
+ for (i = 0; groups[i]; i++) {
+ if (g_str_has_prefix(groups[i], "provider_")) {
int ret = load_provider(keyfile, groups[i], config,
action);
if (ret == 0 || ret == -EALREADY)
- found = TRUE;
+ found = true;
}
}
- if (found == FALSE)
+ if (!found)
connman_warn("Config file %s/%s.config does not contain any "
"configuration that can be provisioned!",
path, config->ident);
@@ -373,11 +373,11 @@ static struct vpn_config *create_config(const char *ident)
DBG("ident %s", ident);
- if (g_hash_table_lookup(config_table, ident) != NULL)
+ if (g_hash_table_lookup(config_table, ident))
return NULL;
config = g_try_new0(struct vpn_config, 1);
- if (config == NULL)
+ if (!config)
return NULL;
config->ident = g_strdup(ident);
@@ -392,21 +392,21 @@ static struct vpn_config *create_config(const char *ident)
return config;
}
-static connman_bool_t validate_ident(const char *ident)
+static bool validate_ident(const char *ident)
{
unsigned int i;
- if (ident == NULL)
- return FALSE;
+ if (!ident)
+ return false;
for (i = 0; i < strlen(ident); i++)
- if (g_ascii_isprint(ident[i]) == FALSE)
- return FALSE;
+ if (!g_ascii_isprint(ident[i]))
+ return false;
- return TRUE;
+ return true;
}
-static char *get_dir()
+static char *get_dir(void)
{
return g_strdup_printf("%s", VPN_STORAGEDIR);
}
@@ -419,31 +419,31 @@ static int read_configs(void)
DBG("path %s", path);
dir = g_dir_open(path, 0, NULL);
- if (dir != NULL) {
+ if (dir) {
const gchar *file;
- while ((file = g_dir_read_name(dir)) != NULL) {
+ while ((file = g_dir_read_name(dir))) {
GString *str;
gchar *ident;
- if (g_str_has_suffix(file, ".config") == FALSE)
+ if (!g_str_has_suffix(file, ".config"))
continue;
ident = g_strrstr(file, ".config");
- if (ident == NULL)
+ if (!ident)
continue;
str = g_string_new_len(file, ident - file);
- if (str == NULL)
+ if (!str)
continue;
ident = g_string_free(str, FALSE);
- if (validate_ident(ident) == TRUE) {
+ if (validate_ident(ident)) {
struct vpn_config *config;
config = create_config(ident);
- if (config != NULL)
+ if (config)
load_config(config, path, ADD);
} else {
connman_error("Invalid config ident %s", ident);
@@ -464,19 +464,19 @@ static void config_notify_handler(struct inotify_event *event,
{
char *ext;
- if (ident == NULL)
+ if (!ident)
return;
- if (g_str_has_suffix(ident, ".config") == FALSE)
+ if (!g_str_has_suffix(ident, ".config"))
return;
ext = g_strrstr(ident, ".config");
- if (ext == NULL)
+ if (!ext)
return;
*ext = '\0';
- if (validate_ident(ident) == FALSE) {
+ if (!validate_ident(ident)) {
connman_error("Invalid config ident %s", ident);
return;
}
@@ -494,7 +494,7 @@ static void config_notify_handler(struct inotify_event *event,
char *path = get_dir();
config = g_hash_table_lookup(config_table, ident);
- if (config != NULL) {
+ if (config) {
g_hash_table_remove_all(config->provider_table);
load_config(config, path, REMOVE);
@@ -510,7 +510,7 @@ static void config_notify_handler(struct inotify_event *event,
* one in order to avoid create/remove/create loop
*/
config = create_config(ident);
- if (config != NULL)
+ if (config)
load_config(config, path, ADD);
}
@@ -540,7 +540,7 @@ void __vpn_config_cleanup(void)
DBG("");
- cleanup = TRUE;
+ cleanup = true;
connman_inotify_unregister(dir, config_notify_handler);
@@ -549,5 +549,33 @@ void __vpn_config_cleanup(void)
g_hash_table_destroy(config_table);
config_table = NULL;
- cleanup = FALSE;
+ cleanup = false;
+}
+
+char *__vpn_config_get_string(GKeyFile *key_file,
+ const char *group_name, const char *key, GError **error)
+{
+ char *str = g_key_file_get_string(key_file, group_name, key, error);
+ if (!str)
+ return NULL;
+
+ return g_strchomp(str);
+}
+
+char **__vpn_config_get_string_list(GKeyFile *key_file,
+ const char *group_name, const char *key, gsize *length, GError **error)
+{
+ char **p;
+ char **strlist = g_key_file_get_string_list(key_file, group_name, key,
+ length, error);
+ if (!strlist)
+ return NULL;
+
+ p = strlist;
+ while (*p) {
+ *p = g_strstrip(*p);
+ p++;
+ }
+
+ return strlist;
}
diff --git a/vpn/vpn-ipconfig.c b/vpn/vpn-ipconfig.c
index 7e1d77e6..c3e61453 100644
--- a/vpn/vpn-ipconfig.c
+++ b/vpn/vpn-ipconfig.c
@@ -47,7 +47,7 @@ struct vpn_ipconfig {
int refcount;
int index;
int family;
- connman_bool_t enabled;
+ bool enabled;
struct connman_ipaddress *address;
struct connman_ipaddress *system;
};
@@ -75,7 +75,7 @@ unsigned char __vpn_ipconfig_netmask_prefix_len(const char *netmask)
in_addr_t mask;
in_addr_t host;
- if (netmask == NULL)
+ if (!netmask)
return 32;
mask = inet_network(netmask);
@@ -94,7 +94,7 @@ unsigned char __vpn_ipconfig_netmask_prefix_len(const char *netmask)
const char *__vpn_ipconfig_get_peer(struct vpn_ipconfig *ipconfig)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return NULL;
return ipconfig->address->peer;
@@ -105,7 +105,7 @@ unsigned short __vpn_ipconfig_get_type_from_index(int index)
struct vpn_ipdevice *ipdevice;
ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
- if (ipdevice == NULL)
+ if (!ipdevice)
return ARPHRD_VOID;
return ipdevice->type;
@@ -116,7 +116,7 @@ unsigned int __vpn_ipconfig_get_flags_from_index(int index)
struct vpn_ipdevice *ipdevice;
ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
- if (ipdevice == NULL)
+ if (!ipdevice)
return 0;
return ipdevice->flags;
@@ -128,7 +128,7 @@ void __vpn_ipconfig_foreach(void (*function) (int index,
GList *list, *keys;
keys = g_hash_table_get_keys(ipdevice_hash);
- if (keys == NULL)
+ if (!keys)
return;
for (list = g_list_first(keys); list; list = g_list_next(list)) {
@@ -143,7 +143,7 @@ void __vpn_ipconfig_foreach(void (*function) (int index,
void __vpn_ipconfig_set_local(struct vpn_ipconfig *ipconfig,
const char *address)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return;
g_free(ipconfig->address->local);
@@ -152,7 +152,7 @@ void __vpn_ipconfig_set_local(struct vpn_ipconfig *ipconfig,
const char *__vpn_ipconfig_get_local(struct vpn_ipconfig *ipconfig)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return NULL;
return ipconfig->address->local;
@@ -161,7 +161,7 @@ const char *__vpn_ipconfig_get_local(struct vpn_ipconfig *ipconfig)
void __vpn_ipconfig_set_peer(struct vpn_ipconfig *ipconfig,
const char *address)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return;
g_free(ipconfig->address->peer);
@@ -171,7 +171,7 @@ void __vpn_ipconfig_set_peer(struct vpn_ipconfig *ipconfig,
void __vpn_ipconfig_set_broadcast(struct vpn_ipconfig *ipconfig,
const char *broadcast)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return;
g_free(ipconfig->address->broadcast);
@@ -183,7 +183,7 @@ void __vpn_ipconfig_set_gateway(struct vpn_ipconfig *ipconfig,
{
DBG("");
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return;
g_free(ipconfig->address->gateway);
ipconfig->address->gateway = g_strdup(gateway);
@@ -192,7 +192,7 @@ void __vpn_ipconfig_set_gateway(struct vpn_ipconfig *ipconfig,
const char *
__vpn_ipconfig_get_gateway(struct vpn_ipconfig *ipconfig)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return NULL;
return ipconfig->address->gateway;
@@ -201,7 +201,7 @@ __vpn_ipconfig_get_gateway(struct vpn_ipconfig *ipconfig)
void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig,
unsigned char prefixlen)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return;
ipconfig->address->prefixlen = prefixlen;
@@ -210,7 +210,7 @@ void __vpn_ipconfig_set_prefixlen(struct vpn_ipconfig *ipconfig,
unsigned char
__vpn_ipconfig_get_prefixlen(struct vpn_ipconfig *ipconfig)
{
- if (ipconfig->address == NULL)
+ if (!ipconfig->address)
return 0;
return ipconfig->address->prefixlen;
@@ -220,7 +220,7 @@ int __vpn_ipconfig_address_add(struct vpn_ipconfig *ipconfig, int family)
{
DBG("ipconfig %p family %d", ipconfig, family);
- if (ipconfig == NULL)
+ if (!ipconfig)
return -EINVAL;
if (family == AF_INET)
@@ -237,7 +237,7 @@ int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family)
{
DBG("ipconfig %p family %d", ipconfig, family);
- if (ipconfig == NULL || ipconfig->address == NULL)
+ if (!ipconfig || !ipconfig->address)
return -EINVAL;
DBG("family %d gw %s peer %s", family,
@@ -260,7 +260,7 @@ int __vpn_ipconfig_gateway_add(struct vpn_ipconfig *ipconfig, int family)
void __vpn_ipconfig_unref_debug(struct vpn_ipconfig *ipconfig,
const char *file, int line, const char *caller)
{
- if (ipconfig == NULL)
+ if (!ipconfig)
return;
DBG("%p ref %d by %s:%d:%s()", ipconfig, ipconfig->refcount - 1,
@@ -281,17 +281,17 @@ static struct vpn_ipconfig *create_ipv6config(int index)
DBG("index %d", index);
ipv6config = g_try_new0(struct vpn_ipconfig, 1);
- if (ipv6config == NULL)
+ if (!ipv6config)
return NULL;
ipv6config->refcount = 1;
ipv6config->index = index;
- ipv6config->enabled = FALSE;
+ ipv6config->enabled = false;
ipv6config->family = AF_INET6;
ipv6config->address = connman_ipaddress_alloc(AF_INET6);
- if (ipv6config->address == NULL) {
+ if (!ipv6config->address) {
g_free(ipv6config);
return NULL;
}
@@ -313,17 +313,17 @@ struct vpn_ipconfig *__vpn_ipconfig_create(int index, int family)
DBG("index %d", index);
ipconfig = g_try_new0(struct vpn_ipconfig, 1);
- if (ipconfig == NULL)
+ if (!ipconfig)
return NULL;
ipconfig->refcount = 1;
ipconfig->index = index;
- ipconfig->enabled = FALSE;
+ ipconfig->enabled = false;
ipconfig->family = family;
ipconfig->address = connman_ipaddress_alloc(AF_INET);
- if (ipconfig->address == NULL) {
+ if (!ipconfig->address) {
g_free(ipconfig);
return NULL;
}
@@ -371,11 +371,11 @@ void __vpn_ipconfig_newlink(int index, unsigned short type,
return;
ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
- if (ipdevice != NULL)
+ if (ipdevice)
goto update;
ipdevice = g_try_new0(struct vpn_ipdevice, 1);
- if (ipdevice == NULL)
+ if (!ipdevice)
return;
ipdevice->index = index;
@@ -398,7 +398,7 @@ update:
ipdevice->flags = flags;
str = g_string_new(NULL);
- if (str == NULL)
+ if (!str)
return;
if (flags & IFF_UP)
@@ -425,7 +425,7 @@ void __vpn_ipconfig_dellink(int index, struct rtnl_link_stats *stats)
DBG("index %d", index);
ipdevice = g_hash_table_lookup(ipdevice_hash, GINT_TO_POINTER(index));
- if (ipdevice == NULL)
+ if (!ipdevice)
return;
g_hash_table_remove(ipdevice_hash, GINT_TO_POINTER(index));
diff --git a/vpn/vpn-manager.c b/vpn/vpn-manager.c
index 1ba745b4..021d625f 100644
--- a/vpn/vpn-manager.c
+++ b/vpn/vpn-manager.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * 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
@@ -82,8 +82,8 @@ static DBusMessage *get_connections(DBusConnection *conn, DBusMessage *msg,
DBG("conn %p", conn);
reply = __vpn_provider_get_connections(msg);
- if (reply == NULL)
- return __connman_error_failed(msg, -EINVAL);
+ if (!reply)
+ return __connman_error_failed(msg, EINVAL);
return reply;
}
@@ -162,7 +162,7 @@ int __vpn_manager_init(void)
DBG("");
connection = connman_dbus_get_connection();
- if (connection == NULL)
+ if (!connection)
return -1;
g_dbus_register_interface(connection, VPN_MANAGER_PATH,
@@ -179,7 +179,7 @@ void __vpn_manager_cleanup(void)
{
DBG("");
- if (connection == NULL)
+ if (!connection)
return;
g_dbus_unregister_interface(connection, VPN_MANAGER_PATH,
diff --git a/vpn/vpn-provider.c b/vpn/vpn-provider.c
index 513d9261..c39ebf9d 100644
--- a/vpn/vpn-provider.c
+++ b/vpn/vpn-provider.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * 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
@@ -42,7 +42,7 @@ static DBusConnection *connection;
static GHashTable *provider_hash;
static GSList *driver_list;
static int configuration_count;
-static gboolean handle_routes;
+static bool handle_routes;
struct vpn_route {
int family;
@@ -52,8 +52,8 @@ struct vpn_route {
};
struct vpn_setting {
- gboolean hide_value;
- gboolean immutable;
+ bool hide_value;
+ bool immutable;
char *value;
};
@@ -83,7 +83,7 @@ struct vpn_provider {
guint notify_id;
char *config_file;
char *config_entry;
- connman_bool_t immutable;
+ bool immutable;
};
static void append_properties(DBusMessageIter *iter,
@@ -116,7 +116,7 @@ static void append_route(DBusMessageIter *iter, void *user_data)
connman_dbus_dict_open(iter, &item);
- if (route == NULL)
+ if (!route)
goto empty_dict;
if (route->family == AF_INET)
@@ -128,15 +128,15 @@ static void append_route(DBusMessageIter *iter, void *user_data)
connman_dbus_dict_append_basic(&item, "ProtocolFamily",
DBUS_TYPE_INT32, &family);
- if (route->network != NULL)
+ if (route->network)
connman_dbus_dict_append_basic(&item, "Network",
DBUS_TYPE_STRING, &route->network);
- if (route->netmask != NULL)
+ if (route->netmask)
connman_dbus_dict_append_basic(&item, "Netmask",
DBUS_TYPE_STRING, &route->netmask);
- if (route->gateway != NULL)
+ if (route->gateway)
connman_dbus_dict_append_basic(&item, "Gateway",
DBUS_TYPE_STRING, &route->gateway);
@@ -150,14 +150,14 @@ static void append_routes(DBusMessageIter *iter, void *user_data)
GHashTableIter hash;
gpointer value, key;
- if (routes == NULL) {
+ if (!routes) {
append_route(iter, NULL);
return;
}
g_hash_table_iter_init(&hash, routes);
- while (g_hash_table_iter_next(&hash, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&hash, &key, &value)) {
DBusMessageIter dict;
dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL,
@@ -211,14 +211,17 @@ static GSList *read_route_dict(GSList *routes, DBusMessageIter *dicts)
type = dbus_message_iter_get_arg_type(&value);
switch (type) {
- case DBUS_TYPE_STRING:
- if (g_str_equal(key, "ProtocolFamily") == TRUE)
+ case DBUS_TYPE_INT32:
+ if (g_str_equal(key, "ProtocolFamily"))
dbus_message_iter_get_basic(&value, &family);
- else if (g_str_equal(key, "Network") == TRUE)
+ break;
+
+ case DBUS_TYPE_STRING:
+ if (g_str_equal(key, "Network"))
dbus_message_iter_get_basic(&value, &network);
- else if (g_str_equal(key, "Netmask") == TRUE)
+ else if (g_str_equal(key, "Netmask"))
dbus_message_iter_get_basic(&value, &netmask);
- else if (g_str_equal(key, "Gateway") == TRUE)
+ else if (g_str_equal(key, "Gateway"))
dbus_message_iter_get_basic(&value, &gateway);
break;
}
@@ -229,13 +232,13 @@ static GSList *read_route_dict(GSList *routes, DBusMessageIter *dicts)
DBG("family %d network %s netmask %s gateway %s", family,
network, netmask, gateway);
- if (network == NULL || netmask == NULL) {
+ if (!network || !netmask) {
DBG("Ignoring route as network/netmask is missing");
return routes;
}
route = g_try_new(struct vpn_route, 1);
- if (route == NULL) {
+ if (!route) {
g_slist_free_full(routes, free_route);
return NULL;
}
@@ -307,7 +310,7 @@ static void set_user_networks(struct vpn_provider *provider, GSList *networks)
{
GSList *list;
- for (list = networks; list != NULL; list = g_slist_next(list)) {
+ for (list = networks; list; list = g_slist_next(list)) {
struct vpn_route *route = list->data;
if (__vpn_provider_append_user_route(provider,
@@ -323,8 +326,8 @@ static void del_routes(struct vpn_provider *provider)
gpointer value, key;
g_hash_table_iter_init(&hash, provider->user_routes);
- while (handle_routes == TRUE && g_hash_table_iter_next(&hash,
- &key, &value) == TRUE) {
+ while (handle_routes && g_hash_table_iter_next(&hash,
+ &key, &value)) {
struct vpn_route *route = value;
if (route->family == AF_INET6) {
unsigned char prefixlen = atoi(route->netmask);
@@ -346,7 +349,7 @@ static void send_value(const char *path, const char *key, const char *value)
const char *empty = "";
const char *str;
- if (value != NULL)
+ if (value)
str = value;
else
str = empty;
@@ -388,7 +391,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
DBG("provider %p", provider);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
dbus_message_iter_init_append(reply, &array);
@@ -408,10 +411,10 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
DBG("conn %p", conn);
- if (provider->immutable == TRUE)
+ if (provider->immutable)
return __connman_error_not_supported(msg);
- if (dbus_message_iter_init(msg, &iter) == FALSE)
+ if (!dbus_message_iter_init(msg, &iter))
return __connman_error_invalid_arguments(msg);
if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
@@ -427,19 +430,19 @@ static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg,
type = dbus_message_iter_get_arg_type(&value);
- if (g_str_equal(name, "UserRoutes") == TRUE) {
+ if (g_str_equal(name, "UserRoutes")) {
GSList *networks;
if (type != DBUS_TYPE_ARRAY)
return __connman_error_invalid_arguments(msg);
networks = get_user_networks(&value);
- if (networks != NULL) {
+ if (networks) {
del_routes(provider);
provider->user_networks = networks;
set_user_networks(provider, provider->user_networks);
- if (handle_routes == FALSE)
+ if (!handle_routes)
send_routes(provider, provider->user_routes,
"UserRoutes");
}
@@ -461,18 +464,18 @@ static DBusMessage *clear_property(DBusConnection *conn, DBusMessage *msg,
DBG("conn %p", conn);
- if (provider->immutable == TRUE)
+ if (provider->immutable)
return __connman_error_not_supported(msg);
dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID);
- if (g_str_equal(name, "UserRoutes") == TRUE) {
+ if (g_str_equal(name, "UserRoutes")) {
del_routes(provider);
- if (handle_routes == FALSE)
+ if (!handle_routes)
send_routes(provider, provider->user_routes, name);
- } else if (vpn_provider_get_string(provider, name) != NULL) {
+ } else if (vpn_provider_get_string(provider, name)) {
vpn_provider_set_string(provider, name, NULL);
} else {
return __connman_error_invalid_property(msg);
@@ -539,7 +542,7 @@ static void resolv_result(GResolvResultStatus status,
DBG("status %d", status);
- if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results != NULL &&
+ if (status == G_RESOLV_RESULT_STATUS_SUCCESS && results &&
g_strv_length(results) > 0)
provider->host_ip = g_strdupv(results);
@@ -548,13 +551,13 @@ static void resolv_result(GResolvResultStatus status,
static void provider_resolv_host_addr(struct vpn_provider *provider)
{
- if (provider->host == NULL)
+ if (!provider->host)
return;
if (connman_inet_check_ipaddress(provider->host) > 0)
return;
- if (provider->host_ip != NULL)
+ if (provider->host_ip)
return;
/*
@@ -564,7 +567,7 @@ static void provider_resolv_host_addr(struct vpn_provider *provider)
* the IP address also before VPN connection can be established.
*/
provider->resolv = g_resolv_new(0);
- if (provider->resolv == NULL) {
+ if (!provider->resolv) {
DBG("Cannot resolv %s", provider->host);
return;
}
@@ -580,15 +583,15 @@ static void provider_resolv_host_addr(struct vpn_provider *provider)
void __vpn_provider_append_properties(struct vpn_provider *provider,
DBusMessageIter *iter)
{
- if (provider->host != NULL)
+ if (provider->host)
connman_dbus_dict_append_basic(iter, "Host",
DBUS_TYPE_STRING, &provider->host);
- if (provider->domain != NULL)
+ if (provider->domain)
connman_dbus_dict_append_basic(iter, "Domain",
DBUS_TYPE_STRING, &provider->domain);
- if (provider->type != NULL)
+ if (provider->type)
connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING,
&provider->type);
}
@@ -599,15 +602,15 @@ int __vpn_provider_append_user_route(struct vpn_provider *provider,
{
struct vpn_route *route;
char *key = g_strdup_printf("%d/%s/%s/%s", family, network,
- netmask, gateway != NULL ? gateway : "");
+ netmask, gateway ? gateway : "");
DBG("family %d network %s netmask %s gw %s", family, network,
netmask, gateway);
route = g_hash_table_lookup(provider->user_routes, key);
- if (route == NULL) {
+ if (!route) {
route = g_try_new0(struct vpn_route, 1);
- if (route == NULL) {
+ if (!route) {
connman_error("out of memory");
return -ENOMEM;
}
@@ -631,23 +634,23 @@ static struct vpn_route *get_route(char *route_str)
int family = PF_UNSPEC;
struct vpn_route *route = NULL;
- if (elems == NULL)
+ if (!elems)
return NULL;
family_str = elems[0];
network = elems[1];
- if (network == NULL || network[0] == '\0')
+ if (!network || network[0] == '\0')
goto out;
netmask = elems[2];
- if (netmask == NULL || netmask[0] == '\0')
+ if (!netmask || netmask[0] == '\0')
goto out;
gateway = elems[3];
route = g_try_new0(struct vpn_route, 1);
- if (route == NULL)
+ if (!route)
goto out;
if (family_str[0] == '\0' || atoi(family_str) == 0) {
@@ -663,20 +666,20 @@ static struct vpn_route *get_route(char *route_str)
}
}
- if (g_strrstr(network, ":") != NULL) {
+ if (g_strrstr(network, ":")) {
if (family != PF_UNSPEC && family != AF_INET6)
DBG("You have IPv6 address but you have non IPv6 route");
- } else if (g_strrstr(network, ".") != NULL) {
+ } else if (g_strrstr(network, ".")) {
if (family != PF_UNSPEC && family != AF_INET)
DBG("You have IPv4 address but you have non IPv4 route");
- if (g_strrstr(netmask, ".") == NULL) {
+ if (!g_strrstr(netmask, ".")) {
/* We have netmask length */
in_addr_t addr;
struct in_addr netmask_in;
unsigned char prefix_len = 32;
- if (netmask != NULL) {
+ if (netmask) {
char *ptr;
long int value = strtol(netmask, &ptr, 10);
if (ptr != netmask && *ptr == '\0' &&
@@ -714,9 +717,9 @@ static GSList *get_routes(gchar **networks)
GSList *routes = NULL;
int i;
- for (i = 0; networks[i] != NULL; i++) {
+ for (i = 0; networks[i]; i++) {
route = get_route(networks[i]);
- if (route != NULL)
+ if (route)
routes = g_slist_prepend(routes, route);
}
@@ -734,16 +737,16 @@ static int provider_load_from_keyfile(struct vpn_provider *provider,
settings = g_key_file_get_keys(keyfile, provider->identifier, &length,
NULL);
- if (settings == NULL) {
+ if (!settings) {
g_key_file_free(keyfile);
return -ENOENT;
}
while (idx < length) {
key = settings[idx];
- if (key != NULL) {
- if (g_str_equal(key, "Networks") == TRUE) {
- networks = g_key_file_get_string_list(keyfile,
+ if (key) {
+ if (g_str_equal(key, "Networks")) {
+ networks = __vpn_config_get_string_list(keyfile,
provider->identifier,
key,
&num_user_networks,
@@ -751,7 +754,7 @@ static int provider_load_from_keyfile(struct vpn_provider *provider,
provider->user_networks = get_routes(networks);
} else {
- value = g_key_file_get_string(keyfile,
+ value = __vpn_config_get_string(keyfile,
provider->identifier,
key, NULL);
vpn_provider_set_string(provider, key,
@@ -764,7 +767,7 @@ static int provider_load_from_keyfile(struct vpn_provider *provider,
g_strfreev(settings);
g_strfreev(networks);
- if (provider->user_networks != NULL)
+ if (provider->user_networks)
set_user_networks(provider, provider->user_networks);
return 0;
@@ -778,7 +781,7 @@ static int vpn_provider_load(struct vpn_provider *provider)
DBG("provider %p", provider);
keyfile = __connman_storage_load_provider(provider->identifier);
- if (keyfile == NULL)
+ if (!keyfile)
return -ENOENT;
provider_load_from_keyfile(provider, keyfile);
@@ -793,13 +796,13 @@ static gchar **create_network_list(GSList *networks, gsize *count)
gchar **result = NULL;
unsigned int num_elems = 0;
- for (list = networks; list != NULL; list = g_slist_next(list)) {
+ for (list = networks; list; list = g_slist_next(list)) {
struct vpn_route *route = list->data;
int family;
result = g_try_realloc(result,
(num_elems + 1) * sizeof(gchar *));
- if (result == NULL)
+ if (!result)
return NULL;
switch (route->family) {
@@ -816,13 +819,13 @@ static gchar **create_network_list(GSList *networks, gsize *count)
result[num_elems] = g_strdup_printf("%d/%s/%s/%s",
family, route->network, route->netmask,
- route->gateway == NULL ? "" : route->gateway);
+ !route->gateway ? "" : route->gateway);
num_elems++;
}
result = g_try_realloc(result, (num_elems + 1) * sizeof(gchar *));
- if (result == NULL)
+ if (!result)
return NULL;
result[num_elems] = NULL;
@@ -837,7 +840,7 @@ static int vpn_provider_save(struct vpn_provider *provider)
DBG("provider %p immutable %s", provider,
provider->immutable ? "yes" : "no");
- if (provider->immutable == TRUE) {
+ if (provider->immutable) {
/*
* Do not save providers that are provisioned via .config
* file.
@@ -846,7 +849,7 @@ static int vpn_provider_save(struct vpn_provider *provider)
}
keyfile = g_key_file_new();
- if (keyfile == NULL)
+ if (!keyfile)
return -ENOMEM;
g_key_file_set_string(keyfile, provider->identifier,
@@ -857,13 +860,13 @@ static int vpn_provider_save(struct vpn_provider *provider)
"Host", provider->host);
g_key_file_set_string(keyfile, provider->identifier,
"VPN.Domain", provider->domain);
- if (provider->user_networks != NULL) {
+ if (provider->user_networks) {
gchar **networks;
gsize network_count;
networks = create_network_list(provider->user_networks,
&network_count);
- if (networks != NULL) {
+ if (networks) {
g_key_file_set_string_list(keyfile,
provider->identifier,
"Networks",
@@ -873,20 +876,20 @@ static int vpn_provider_save(struct vpn_provider *provider)
}
}
- if (provider->config_file != NULL && strlen(provider->config_file) > 0)
+ if (provider->config_file && strlen(provider->config_file) > 0)
g_key_file_set_string(keyfile, provider->identifier,
"Config.file", provider->config_file);
- if (provider->config_entry != NULL &&
+ if (provider->config_entry &&
strlen(provider->config_entry) > 0)
g_key_file_set_string(keyfile, provider->identifier,
"Config.ident", provider->config_entry);
- if (provider->driver != NULL && provider->driver->save != NULL)
+ if (provider->driver && provider->driver->save)
provider->driver->save(provider, keyfile);
__connman_storage_save_provider(keyfile, provider->identifier);
- g_key_file_free(keyfile);
+ g_key_file_free(keyfile);
return 0;
}
@@ -900,13 +903,13 @@ struct vpn_provider *__vpn_provider_lookup(const char *identifier)
return provider;
}
-static gboolean match_driver(struct vpn_provider *provider,
+static bool match_driver(struct vpn_provider *provider,
struct vpn_provider_driver *driver)
{
if (g_strcmp0(driver->name, provider->type) == 0)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
static int provider_probe(struct vpn_provider *provider)
@@ -916,24 +919,24 @@ static int provider_probe(struct vpn_provider *provider)
DBG("provider %p driver %p name %s", provider, provider->driver,
provider->name);
- if (provider->driver != NULL)
+ if (provider->driver)
return -EALREADY;
for (list = driver_list; list; list = list->next) {
struct vpn_provider_driver *driver = list->data;
- if (match_driver(provider, driver) == FALSE)
+ if (!match_driver(provider, driver))
continue;
DBG("driver %p name %s", driver, driver->name);
- if (driver->probe != NULL && driver->probe(provider) == 0) {
+ if (driver->probe && driver->probe(provider) == 0) {
provider->driver = driver;
break;
}
}
- if (provider->driver == NULL)
+ if (!provider->driver)
return -ENODEV;
return 0;
@@ -941,7 +944,7 @@ static int provider_probe(struct vpn_provider *provider)
static void provider_remove(struct vpn_provider *provider)
{
- if (provider->driver != NULL) {
+ if (provider->driver) {
provider->driver->remove(provider);
provider->driver = NULL;
}
@@ -987,7 +990,7 @@ static void provider_destruct(struct vpn_provider *provider)
g_hash_table_destroy(provider->routes);
g_hash_table_destroy(provider->user_routes);
g_hash_table_destroy(provider->setting_strings);
- if (provider->resolv != NULL) {
+ if (provider->resolv) {
g_resolv_unref(provider->resolv);
provider->resolv = NULL;
}
@@ -1035,7 +1038,7 @@ int __vpn_provider_disconnect(struct vpn_provider *provider)
DBG("provider %p", provider);
- if (provider->driver != NULL && provider->driver->disconnect != NULL)
+ if (provider->driver && provider->driver->disconnect)
err = provider->driver->disconnect(provider);
else
return -EOPNOTSUPP;
@@ -1055,7 +1058,7 @@ static void connect_cb(struct vpn_provider *provider, void *user_data,
if (error != 0) {
DBusMessage *reply = __connman_error_failed(pending, error);
- if (reply != NULL)
+ if (reply)
g_dbus_send_message(connection, reply);
vpn_provider_indicate_error(provider,
@@ -1073,9 +1076,11 @@ int __vpn_provider_connect(struct vpn_provider *provider, DBusMessage *msg)
DBG("provider %p", provider);
- if (provider->driver != NULL && provider->driver->connect != NULL) {
+ if (provider->driver && provider->driver->connect) {
dbus_message_ref(msg);
- err = provider->driver->connect(provider, connect_cb, msg);
+ err = provider->driver->connect(provider, connect_cb,
+ dbus_message_get_sender(msg),
+ msg);
} else
return -EOPNOTSUPP;
@@ -1092,7 +1097,7 @@ static void connection_removed_signal(struct vpn_provider *provider)
signal = dbus_message_new_signal(VPN_MANAGER_PATH,
VPN_MANAGER_INTERFACE, "ConnectionRemoved");
- if (signal == NULL)
+ if (!signal)
return;
dbus_message_iter_init_append(signal, &iter);
@@ -1110,7 +1115,7 @@ static char *get_ident(const char *path)
return NULL;
pos = strrchr(path, '/');
- if (pos == NULL)
+ if (!pos)
return NULL;
return pos + 1;
@@ -1126,7 +1131,7 @@ int __vpn_provider_remove(const char *path)
ident = get_ident(path);
provider = __vpn_provider_lookup(ident);
- if (provider != NULL)
+ if (provider)
return __vpn_provider_delete(provider);
return -ENXIO;
@@ -1153,7 +1158,7 @@ static void append_ipv4(DBusMessageIter *iter, void *user_data)
const char *address, *gateway, *peer;
address = __vpn_ipconfig_get_local(provider->ipconfig_ipv4);
- if (address != NULL) {
+ if (address) {
in_addr_t addr;
struct in_addr netmask;
char *mask;
@@ -1174,12 +1179,12 @@ static void append_ipv4(DBusMessageIter *iter, void *user_data)
}
gateway = __vpn_ipconfig_get_gateway(provider->ipconfig_ipv4);
- if (gateway != NULL)
+ if (gateway)
connman_dbus_dict_append_basic(iter, "Gateway",
DBUS_TYPE_STRING, &gateway);
peer = __vpn_ipconfig_get_peer(provider->ipconfig_ipv4);
- if (peer != NULL)
+ if (peer)
connman_dbus_dict_append_basic(iter, "Peer",
DBUS_TYPE_STRING, &peer);
}
@@ -1190,7 +1195,7 @@ static void append_ipv6(DBusMessageIter *iter, void *user_data)
const char *address, *gateway, *peer;
address = __vpn_ipconfig_get_local(provider->ipconfig_ipv6);
- if (address != NULL) {
+ if (address) {
unsigned char prefixlen;
connman_dbus_dict_append_basic(iter, "Address",
@@ -1204,12 +1209,12 @@ static void append_ipv6(DBusMessageIter *iter, void *user_data)
}
gateway = __vpn_ipconfig_get_gateway(provider->ipconfig_ipv6);
- if (gateway != NULL)
+ if (gateway)
connman_dbus_dict_append_basic(iter, "Gateway",
DBUS_TYPE_STRING, &gateway);
peer = __vpn_ipconfig_get_peer(provider->ipconfig_ipv6);
- if (peer != NULL)
+ if (peer)
connman_dbus_dict_append_basic(iter, "Peer",
DBUS_TYPE_STRING, &peer);
}
@@ -1240,7 +1245,7 @@ static void append_nameservers(DBusMessageIter *iter, char **servers)
DBG("%p", servers);
- for (i = 0; servers[i] != NULL; i++) {
+ for (i = 0; servers[i]; i++) {
DBG("servers[%d] %s", i, servers[i]);
dbus_message_iter_append_basic(iter,
DBUS_TYPE_STRING, &servers[i]);
@@ -1251,7 +1256,7 @@ static void append_dns(DBusMessageIter *iter, void *user_data)
{
struct vpn_provider *provider = user_data;
- if (provider->nameservers != NULL)
+ if (provider->nameservers)
append_nameservers(iter, provider->nameservers);
}
@@ -1263,7 +1268,7 @@ static int provider_indicate_state(struct vpn_provider *provider,
str = state2string(state);
DBG("provider %p state %s/%d", provider, str, state);
- if (str == NULL)
+ if (!str)
return -EINVAL;
old_state = provider->state;
@@ -1289,7 +1294,7 @@ static int provider_indicate_state(struct vpn_provider *provider,
DBUS_TYPE_STRING,
append_dns, provider);
- if (provider->domain != NULL)
+ if (provider->domain)
connman_dbus_property_changed_basic(provider->path,
VPN_CONNECTION_INTERFACE,
"Domain",
@@ -1346,31 +1351,33 @@ static void append_properties(DBusMessageIter *iter,
DBusMessageIter dict;
GHashTableIter hash;
gpointer value, key;
+ dbus_bool_t immutable;
connman_dbus_dict_open(iter, &dict);
append_state(&dict, provider);
- if (provider->type != NULL)
+ if (provider->type)
connman_dbus_dict_append_basic(&dict, "Type",
DBUS_TYPE_STRING, &provider->type);
- if (provider->name != NULL)
+ if (provider->name)
connman_dbus_dict_append_basic(&dict, "Name",
DBUS_TYPE_STRING, &provider->name);
- if (provider->host != NULL)
+ if (provider->host)
connman_dbus_dict_append_basic(&dict, "Host",
DBUS_TYPE_STRING, &provider->host);
if (provider->index >= 0)
connman_dbus_dict_append_basic(&dict, "Index",
DBUS_TYPE_INT32, &provider->index);
- if (provider->domain != NULL)
+ if (provider->domain)
connman_dbus_dict_append_basic(&dict, "Domain",
DBUS_TYPE_STRING, &provider->domain);
+ immutable = provider->immutable;
connman_dbus_dict_append_basic(&dict, "Immutable", DBUS_TYPE_BOOLEAN,
- &provider->immutable);
+ &immutable);
if (provider->family == AF_INET)
connman_dbus_dict_append_dict(&dict, "IPv4", append_ipv4,
@@ -1390,14 +1397,14 @@ static void append_properties(DBusMessageIter *iter,
DBUS_TYPE_DICT_ENTRY, append_routes,
provider->routes);
- if (provider->setting_strings != NULL) {
+ if (provider->setting_strings) {
g_hash_table_iter_init(&hash, provider->setting_strings);
- while (g_hash_table_iter_next(&hash, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&hash, &key, &value)) {
struct vpn_setting *setting = value;
- if (setting->hide_value == FALSE &&
- setting->value != NULL)
+ if (!setting->hide_value &&
+ setting->value)
connman_dbus_dict_append_basic(&dict, key,
DBUS_TYPE_STRING,
&setting->value);
@@ -1414,7 +1421,7 @@ static void connection_added_signal(struct vpn_provider *provider)
signal = dbus_message_new_signal(VPN_MANAGER_PATH,
VPN_MANAGER_INTERFACE, "ConnectionAdded");
- if (signal == NULL)
+ if (!signal)
return;
dbus_message_iter_init_append(signal, &iter);
@@ -1426,19 +1433,19 @@ static void connection_added_signal(struct vpn_provider *provider)
dbus_message_unref(signal);
}
-static connman_bool_t check_host(char **hosts, char *host)
+static bool check_host(char **hosts, char *host)
{
int i;
- if (hosts == NULL)
- return FALSE;
+ if (!hosts)
+ return false;
- for (i = 0; hosts[i] != NULL; i++) {
+ for (i = 0; hosts[i]; i++) {
if (g_strcmp0(hosts[i], host) == 0)
- return TRUE;
+ return true;
}
- return FALSE;
+ return false;
}
static void provider_append_routes(gpointer key, gpointer value,
@@ -1448,7 +1455,7 @@ static void provider_append_routes(gpointer key, gpointer value,
struct vpn_provider *provider = user_data;
int index = provider->index;
- if (handle_routes == FALSE)
+ if (!handle_routes)
return;
/*
@@ -1456,7 +1463,7 @@ static void provider_append_routes(gpointer key, gpointer value,
* VPN server, then we must discard that because the
* server cannot be contacted via VPN tunnel.
*/
- if (check_host(provider->host_ip, route->network) == TRUE) {
+ if (check_host(provider->host_ip, route->network)) {
DBG("Discarding VPN route to %s via %s at index %d",
route->network, route->gateway, index);
return;
@@ -1476,14 +1483,14 @@ static void provider_append_routes(gpointer key, gpointer value,
}
static int set_connected(struct vpn_provider *provider,
- connman_bool_t connected)
+ bool connected)
{
struct vpn_ipconfig *ipconfig;
DBG("provider %p id %s connected %d", provider,
provider->identifier, connected);
- if (connected == TRUE) {
+ if (connected) {
if (provider->family == AF_INET6)
ipconfig = provider->ipconfig_ipv6;
else
@@ -1491,7 +1498,7 @@ static int set_connected(struct vpn_provider *provider,
__vpn_ipconfig_address_add(ipconfig, provider->family);
- if (handle_routes == TRUE)
+ if (handle_routes)
__vpn_ipconfig_gateway_add(ipconfig, provider->family);
provider_indicate_state(provider,
@@ -1517,18 +1524,18 @@ static int set_connected(struct vpn_provider *provider,
int vpn_provider_set_state(struct vpn_provider *provider,
enum vpn_provider_state state)
{
- if (provider == NULL)
+ if (!provider)
return -EINVAL;
switch (state) {
case VPN_PROVIDER_STATE_UNKNOWN:
return -EINVAL;
case VPN_PROVIDER_STATE_IDLE:
- return set_connected(provider, FALSE);
+ return set_connected(provider, false);
case VPN_PROVIDER_STATE_CONNECT:
return provider_indicate_state(provider, state);
case VPN_PROVIDER_STATE_READY:
- return set_connected(provider, TRUE);
+ return set_connected(provider, true);
case VPN_PROVIDER_STATE_DISCONNECT:
return provider_indicate_state(provider, state);
case VPN_PROVIDER_STATE_FAILURE:
@@ -1562,7 +1569,7 @@ static int connection_unregister(struct vpn_provider *provider)
{
DBG("provider %p path %s", provider, provider->path);
- if (provider->path == NULL)
+ if (!provider->path)
return -EALREADY;
g_dbus_unregister_interface(connection, provider->path,
@@ -1578,7 +1585,7 @@ static int connection_register(struct vpn_provider *provider)
{
DBG("provider %p path %s", provider, provider->path);
- if (provider->path != NULL)
+ if (provider->path)
return -EALREADY;
provider->path = g_strdup_printf("%s/connection/%s", VPN_PATH,
@@ -1613,7 +1620,7 @@ static void provider_initialize(struct vpn_provider *provider)
provider->type = NULL;
provider->domain = NULL;
provider->identifier = NULL;
- provider->immutable = FALSE;
+ provider->immutable = false;
provider->user_networks = NULL;
provider->routes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
NULL, free_route);
@@ -1628,7 +1635,7 @@ static struct vpn_provider *vpn_provider_new(void)
struct vpn_provider *provider;
provider = g_try_new0(struct vpn_provider, 1);
- if (provider == NULL)
+ if (!provider)
return NULL;
provider->refcount = 1;
@@ -1644,11 +1651,11 @@ static struct vpn_provider *vpn_provider_get(const char *identifier)
struct vpn_provider *provider;
provider = g_hash_table_lookup(provider_hash, identifier);
- if (provider != NULL)
+ if (provider)
return provider;
provider = vpn_provider_new();
- if (provider == NULL)
+ if (!provider)
return NULL;
DBG("provider %p", provider);
@@ -1682,21 +1689,21 @@ static struct vpn_provider *provider_create_from_keyfile(GKeyFile *keyfile,
{
struct vpn_provider *provider;
- if (keyfile == NULL || ident == NULL)
+ if (!keyfile || !ident)
return NULL;
provider = __vpn_provider_lookup(ident);
- if (provider == NULL) {
+ if (!provider) {
provider = vpn_provider_get(ident);
- if (provider == NULL) {
+ if (!provider) {
DBG("can not create provider");
return NULL;
}
provider_load_from_keyfile(provider, keyfile);
- if (provider->name == NULL || provider->host == NULL ||
- provider->domain == NULL) {
+ if (!provider->name || !provider->host ||
+ !provider->domain) {
DBG("cannot get name, host or domain");
vpn_provider_unref(provider);
return NULL;
@@ -1719,10 +1726,10 @@ static void provider_create_all_from_type(const char *provider_type)
providers = __connman_storage_get_providers();
- if (providers == NULL)
+ if (!providers)
return;
- for (i = 0; providers[i] != NULL; i+=1) {
+ for (i = 0; providers[i]; i += 1) {
if (strncmp(providers[i], "provider_", 9) != 0)
continue;
@@ -1730,10 +1737,10 @@ static void provider_create_all_from_type(const char *provider_type)
id = providers[i] + 9;
keyfile = __connman_storage_load_provider(id);
- if (keyfile == NULL)
+ if (!keyfile)
continue;
- type = g_key_file_get_string(keyfile, id, "Type", NULL);
+ type = __vpn_config_get_string(keyfile, id, "Type", NULL);
DBG("keyfile %p id %s type %s", keyfile, id, type);
@@ -1743,7 +1750,7 @@ static void provider_create_all_from_type(const char *provider_type)
continue;
}
- if (provider_create_from_keyfile(keyfile, id) == NULL)
+ if (!provider_create_from_keyfile(keyfile, id))
DBG("could not create provider");
g_free(type);
@@ -1757,7 +1764,7 @@ char *__vpn_provider_create_identifier(const char *host, const char *domain)
char *ident;
ident = g_strdup_printf("%s_%s", host, domain);
- if (ident == NULL)
+ if (!ident)
return NULL;
provider_dbus_ident(ident);
@@ -1790,18 +1797,18 @@ int __vpn_provider_create(DBusMessage *msg)
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_STRING:
- if (g_str_equal(key, "Type") == TRUE)
+ if (g_str_equal(key, "Type"))
dbus_message_iter_get_basic(&value, &type);
- else if (g_str_equal(key, "Name") == TRUE)
+ else if (g_str_equal(key, "Name"))
dbus_message_iter_get_basic(&value, &name);
- else if (g_str_equal(key, "Host") == TRUE)
+ else if (g_str_equal(key, "Host"))
dbus_message_iter_get_basic(&value, &host);
- else if (g_str_equal(key, "VPN.Domain") == TRUE ||
- g_str_equal(key, "Domain") == TRUE)
+ else if (g_str_equal(key, "VPN.Domain") ||
+ g_str_equal(key, "Domain"))
dbus_message_iter_get_basic(&value, &domain);
break;
case DBUS_TYPE_ARRAY:
- if (g_str_equal(key, "UserRoutes") == TRUE)
+ if (g_str_equal(key, "UserRoutes"))
networks = get_user_networks(&value);
break;
}
@@ -1809,21 +1816,21 @@ int __vpn_provider_create(DBusMessage *msg)
dbus_message_iter_next(&array);
}
- if (host == NULL || domain == NULL)
+ if (!host || !domain)
return -EINVAL;
DBG("Type %s name %s networks %p", type, name, networks);
- if (type == NULL || name == NULL)
+ if (!type || !name)
return -EOPNOTSUPP;
ident = __vpn_provider_create_identifier(host, domain);
DBG("ident %s", ident);
provider = __vpn_provider_lookup(ident);
- if (provider == NULL) {
+ if (!provider) {
provider = vpn_provider_get(ident);
- if (provider == NULL) {
+ if (!provider) {
DBG("can not create provider");
g_free(ident);
return -EOPNOTSUPP;
@@ -1840,7 +1847,7 @@ int __vpn_provider_create(DBusMessage *msg)
provider_resolv_host_addr(provider);
}
- if (networks != NULL) {
+ if (networks) {
g_slist_free_full(provider->user_networks, free_route);
provider->user_networks = networks;
set_user_networks(provider, provider->user_networks);
@@ -1904,25 +1911,25 @@ static GSList *parse_user_networks(const char *network_str)
char **elems;
int i = 0;
- if (network_str == NULL)
+ if (!network_str)
return NULL;
elems = g_strsplit(network_str, ",", 0);
- if (elems == NULL)
+ if (!elems)
return NULL;
- while (elems[i] != NULL) {
+ while (elems[i]) {
struct vpn_route *vpn_route;
char *network, *netmask, *gateway;
int family;
char **route;
route = g_strsplit(elems[i], "/", 0);
- if (route == NULL)
+ if (!route)
goto next;
network = route[0];
- if (network == NULL || network[0] == '\0')
+ if (!network || network[0] == '\0')
goto next;
family = connman_inet_check_ipaddress(network);
@@ -1944,13 +1951,13 @@ static GSList *parse_user_networks(const char *network_str)
}
netmask = route[1];
- if (netmask == NULL || netmask[0] == '\0')
+ if (!netmask || netmask[0] == '\0')
goto next;
gateway = route[2];
vpn_route = g_try_new0(struct vpn_route, 1);
- if (vpn_route == NULL) {
+ if (!vpn_route) {
g_strfreev(route);
break;
}
@@ -1994,14 +2001,14 @@ int __vpn_provider_create_from_config(GHashTable *settings,
networks_str = get_string(settings, "Networks");
networks = parse_user_networks(networks_str);
- if (host == NULL || domain == NULL) {
+ if (!host || !domain) {
err = -EINVAL;
goto fail;
}
DBG("type %s name %s networks %s", type, name, networks_str);
- if (type == NULL || name == NULL) {
+ if (!type || !name) {
err = -EOPNOTSUPP;
goto fail;
}
@@ -2010,9 +2017,9 @@ int __vpn_provider_create_from_config(GHashTable *settings,
DBG("ident %s", ident);
provider = __vpn_provider_lookup(ident);
- if (provider == NULL) {
+ if (!provider) {
provider = vpn_provider_get(ident);
- if (provider == NULL) {
+ if (!provider) {
DBG("can not create provider");
err = -EOPNOTSUPP;
goto fail;
@@ -2031,7 +2038,7 @@ int __vpn_provider_create_from_config(GHashTable *settings,
provider_resolv_host_addr(provider);
}
- if (networks != NULL) {
+ if (networks) {
g_slist_free_full(provider->user_networks, free_route);
provider->user_networks = networks;
set_user_networks(provider, provider->user_networks);
@@ -2039,10 +2046,10 @@ int __vpn_provider_create_from_config(GHashTable *settings,
g_hash_table_iter_init(&hash, settings);
- while (g_hash_table_iter_next(&hash, &key, &value) == TRUE)
+ while (g_hash_table_iter_next(&hash, &key, &value))
__vpn_provider_set_string_immutable(provider, key, value);
- provider->immutable = TRUE;
+ provider->immutable = true;
vpn_provider_save(provider);
@@ -2076,12 +2083,12 @@ static void append_connection_structs(DBusMessageIter *iter, void *user_data)
g_hash_table_iter_init(&hash, provider_hash);
- while (g_hash_table_iter_next(&hash, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&hash, &key, &value)) {
struct vpn_provider *provider = value;
DBG("path %s", provider->path);
- if (provider->identifier == NULL)
+ if (!provider->identifier)
continue;
dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT,
@@ -2100,7 +2107,7 @@ DBusMessage *__vpn_provider_get_connections(DBusMessage *msg)
DBG("");
reply = dbus_message_new_method_return(msg);
- if (reply == NULL)
+ if (!reply)
return NULL;
__connman_dbus_append_objpath_dict_array(reply,
@@ -2109,9 +2116,9 @@ DBusMessage *__vpn_provider_get_connections(DBusMessage *msg)
return reply;
}
-const char * __vpn_provider_get_ident(struct vpn_provider *provider)
+const char *__vpn_provider_get_ident(struct vpn_provider *provider)
{
- if (provider == NULL)
+ if (!provider)
return NULL;
return provider->identifier;
@@ -2119,26 +2126,26 @@ const char * __vpn_provider_get_ident(struct vpn_provider *provider)
static int set_string(struct vpn_provider *provider,
const char *key, const char *value,
- gboolean hide_value, gboolean immutable)
+ bool hide_value, bool immutable)
{
DBG("provider %p key %s immutable %s value %s", provider, key,
immutable ? "yes" : "no",
hide_value ? "<not printed>" : value);
- if (g_str_equal(key, "Type") == TRUE) {
+ if (g_str_equal(key, "Type")) {
g_free(provider->type);
provider->type = g_ascii_strdown(value, -1);
send_value(provider->path, "Type", provider->type);
- } else if (g_str_equal(key, "Name") == TRUE) {
+ } else if (g_str_equal(key, "Name")) {
g_free(provider->name);
provider->name = g_strdup(value);
send_value(provider->path, "Name", provider->name);
- } else if (g_str_equal(key, "Host") == TRUE) {
+ } else if (g_str_equal(key, "Host")) {
g_free(provider->host);
provider->host = g_strdup(value);
send_value(provider->path, "Host", provider->host);
- } else if (g_str_equal(key, "VPN.Domain") == TRUE ||
- g_str_equal(key, "Domain") == TRUE) {
+ } else if (g_str_equal(key, "VPN.Domain") ||
+ g_str_equal(key, "Domain")) {
g_free(provider->domain);
provider->domain = g_strdup(value);
send_value(provider->path, "Domain", provider->domain);
@@ -2146,23 +2153,23 @@ static int set_string(struct vpn_provider *provider,
struct vpn_setting *setting;
setting = g_hash_table_lookup(provider->setting_strings, key);
- if (setting != NULL && immutable == FALSE &&
- setting->immutable == TRUE) {
+ if (setting && !immutable &&
+ setting->immutable) {
DBG("Trying to set immutable variable %s", key);
return -EPERM;
}
setting = g_try_new0(struct vpn_setting, 1);
- if (setting == NULL)
+ if (!setting)
return -ENOMEM;
setting->value = g_strdup(value);
setting->hide_value = hide_value;
- if (immutable == TRUE)
- setting->immutable = TRUE;
+ if (immutable)
+ setting->immutable = true;
- if (hide_value == FALSE)
+ if (!hide_value)
send_value(provider->path, key, setting->value);
g_hash_table_replace(provider->setting_strings,
@@ -2175,19 +2182,19 @@ static int set_string(struct vpn_provider *provider,
int vpn_provider_set_string(struct vpn_provider *provider,
const char *key, const char *value)
{
- return set_string(provider, key, value, FALSE, FALSE);
+ return set_string(provider, key, value, false, false);
}
int vpn_provider_set_string_hide_value(struct vpn_provider *provider,
const char *key, const char *value)
{
- return set_string(provider, key, value, TRUE, FALSE);
+ return set_string(provider, key, value, true, false);
}
int __vpn_provider_set_string_immutable(struct vpn_provider *provider,
const char *key, const char *value)
{
- return set_string(provider, key, value, FALSE, TRUE);
+ return set_string(provider, key, value, false, true);
}
const char *vpn_provider_get_string(struct vpn_provider *provider,
@@ -2197,43 +2204,43 @@ const char *vpn_provider_get_string(struct vpn_provider *provider,
DBG("provider %p key %s", provider, key);
- if (g_str_equal(key, "Type") == TRUE)
+ if (g_str_equal(key, "Type"))
return provider->type;
- else if (g_str_equal(key, "Name") == TRUE)
+ else if (g_str_equal(key, "Name"))
return provider->name;
- else if (g_str_equal(key, "Host") == TRUE)
+ else if (g_str_equal(key, "Host"))
return provider->host;
- else if (g_str_equal(key, "HostIP") == TRUE) {
- if (provider->host_ip == NULL ||
- provider->host_ip[0] == NULL)
+ else if (g_str_equal(key, "HostIP")) {
+ if (!provider->host_ip ||
+ !provider->host_ip[0])
return provider->host;
else
return provider->host_ip[0];
- } else if (g_str_equal(key, "VPN.Domain") == TRUE ||
- g_str_equal(key, "Domain") == TRUE)
+ } else if (g_str_equal(key, "VPN.Domain") ||
+ g_str_equal(key, "Domain"))
return provider->domain;
setting = g_hash_table_lookup(provider->setting_strings, key);
- if (setting == NULL)
+ if (!setting)
return NULL;
return setting->value;
}
-connman_bool_t __vpn_provider_check_routes(struct vpn_provider *provider)
+bool __vpn_provider_check_routes(struct vpn_provider *provider)
{
- if (provider == NULL)
- return FALSE;
+ if (!provider)
+ return false;
- if (provider->user_routes != NULL &&
+ if (provider->user_routes &&
g_hash_table_size(provider->user_routes) > 0)
- return TRUE;
+ return true;
- if (provider->routes != NULL &&
+ if (provider->routes &&
g_hash_table_size(provider->routes) > 0)
- return TRUE;
+ return true;
- return FALSE;
+ return false;
}
void *vpn_provider_get_data(struct vpn_provider *provider)
@@ -2250,10 +2257,10 @@ void vpn_provider_set_index(struct vpn_provider *provider, int index)
{
DBG("index %d provider %p", index, provider);
- if (provider->ipconfig_ipv4 == NULL) {
+ if (!provider->ipconfig_ipv4) {
provider->ipconfig_ipv4 = __vpn_ipconfig_create(index,
AF_INET);
- if (provider->ipconfig_ipv4 == NULL) {
+ if (!provider->ipconfig_ipv4) {
DBG("Couldnt create ipconfig for IPv4");
goto done;
}
@@ -2261,10 +2268,10 @@ void vpn_provider_set_index(struct vpn_provider *provider, int index)
__vpn_ipconfig_set_index(provider->ipconfig_ipv4, index);
- if (provider->ipconfig_ipv6 == NULL) {
+ if (!provider->ipconfig_ipv6) {
provider->ipconfig_ipv6 = __vpn_ipconfig_create(index,
AF_INET6);
- if (provider->ipconfig_ipv6 == NULL) {
+ if (!provider->ipconfig_ipv6) {
DBG("Couldnt create ipconfig for IPv6");
goto done;
}
@@ -2300,7 +2307,7 @@ int vpn_provider_set_ipaddress(struct vpn_provider *provider,
DBG("provider %p ipconfig %p family %d", provider, ipconfig,
ipaddress->family);
- if (ipconfig == NULL)
+ if (!ipconfig)
return -EINVAL;
provider->family = ipaddress->family;
@@ -2342,7 +2349,7 @@ int vpn_provider_set_nameservers(struct vpn_provider *provider,
g_strfreev(provider->nameservers);
provider->nameservers = NULL;
- if (nameservers == NULL)
+ if (!nameservers)
return 0;
provider->nameservers = g_strsplit(nameservers, " ", 0);
@@ -2367,13 +2374,13 @@ static int route_env_parse(struct vpn_provider *provider, const char *key,
DBG("name %s", provider->name);
if (!strcmp(provider->type, "openvpn")) {
- if (g_str_has_prefix(key, "route_network_") == TRUE) {
+ if (g_str_has_prefix(key, "route_network_")) {
start = key + strlen("route_network_");
*type = PROVIDER_ROUTE_TYPE_ADDR;
- } else if (g_str_has_prefix(key, "route_netmask_") == TRUE) {
+ } else if (g_str_has_prefix(key, "route_netmask_")) {
start = key + strlen("route_netmask_");
*type = PROVIDER_ROUTE_TYPE_MASK;
- } else if (g_str_has_prefix(key, "route_gateway_") == TRUE) {
+ } else if (g_str_has_prefix(key, "route_gateway_")) {
start = key + strlen("route_gateway_");
*type = PROVIDER_ROUTE_TYPE_GW;
} else
@@ -2383,11 +2390,11 @@ static int route_env_parse(struct vpn_provider *provider, const char *key,
*idx = g_ascii_strtoull(start, &end, 10);
} else if (!strcmp(provider->type, "openconnect")) {
- if (g_str_has_prefix(key, "CISCO_SPLIT_INC_") == TRUE) {
+ if (g_str_has_prefix(key, "CISCO_SPLIT_INC_")) {
*family = AF_INET;
start = key + strlen("CISCO_SPLIT_INC_");
} else if (g_str_has_prefix(key,
- "CISCO_IPV6_SPLIT_INC_") == TRUE) {
+ "CISCO_IPV6_SPLIT_INC_")) {
*family = AF_INET6;
start = key + strlen("CISCO_IPV6_SPLIT_INC_");
} else
@@ -2426,9 +2433,9 @@ int vpn_provider_append_route(struct vpn_provider *provider,
DBG("idx %lu family %d type %d", idx, family, type);
route = g_hash_table_lookup(provider->routes, GINT_TO_POINTER(idx));
- if (route == NULL) {
+ if (!route) {
route = g_try_new0(struct vpn_route, 1);
- if (route == NULL) {
+ if (!route) {
connman_error("out of memory");
return -ENOMEM;
}
@@ -2453,9 +2460,9 @@ int vpn_provider_append_route(struct vpn_provider *provider,
break;
}
- if (handle_routes == FALSE) {
- if (route->netmask != NULL && route->gateway != NULL &&
- route->network != NULL)
+ if (!handle_routes) {
+ if (route->netmask && route->gateway &&
+ route->network)
provider_schedule_changed(provider);
}
@@ -2464,7 +2471,7 @@ int vpn_provider_append_route(struct vpn_provider *provider,
const char *vpn_provider_get_driver_name(struct vpn_provider *provider)
{
- if (provider->driver == NULL)
+ if (!provider->driver)
return NULL;
return provider->driver->name;
@@ -2484,7 +2491,7 @@ static void clean_provider(gpointer key, gpointer value, gpointer user_data)
{
struct vpn_provider *provider = value;
- if (provider->driver != NULL && provider->driver->remove)
+ if (provider->driver && provider->driver->remove)
provider->driver->remove(provider);
connection_unregister(provider);
@@ -2510,10 +2517,10 @@ void vpn_provider_driver_unregister(struct vpn_provider_driver *driver)
driver_list = g_slist_remove(driver_list, driver);
g_hash_table_iter_init(&iter, provider_hash);
- while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) {
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
struct vpn_provider *provider = value;
- if (provider != NULL && provider->driver != NULL &&
+ if (provider && provider->driver &&
provider->driver->type == driver->type &&
g_strcmp0(provider->driver->name,
driver->name) == 0) {
@@ -2555,7 +2562,7 @@ static struct connman_agent_driver agent_driver = {
.remove = agent_remove,
};
-static void remove_unprovisioned_providers()
+static void remove_unprovisioned_providers(void)
{
gchar **providers;
GKeyFile *keyfile, *configkeyfile;
@@ -2563,30 +2570,30 @@ static void remove_unprovisioned_providers()
int i = 0;
providers = __connman_storage_get_providers();
- if (providers == NULL)
+ if (!providers)
return;
- for (; providers[i] != NULL; i++) {
+ for (; providers[i]; i++) {
char *group = providers[i] + sizeof("provider_") - 1;
file = section = NULL;
keyfile = configkeyfile = NULL;
keyfile = __connman_storage_load_provider(group);
- if (keyfile == NULL)
+ if (!keyfile)
continue;
- file = g_key_file_get_string(keyfile, group,
+ file = __vpn_config_get_string(keyfile, group,
"Config.file", NULL);
- if (file == NULL)
+ if (!file)
goto next;
- section = g_key_file_get_string(keyfile, group,
+ section = __vpn_config_get_string(keyfile, group,
"Config.ident", NULL);
- if (section == NULL)
+ if (!section)
goto next;
configkeyfile = __connman_storage_load_provider_config(file);
- if (configkeyfile == NULL) {
+ if (!configkeyfile) {
/*
* Config file is missing, remove the provisioned
* service.
@@ -2595,7 +2602,7 @@ static void remove_unprovisioned_providers()
goto next;
}
- if (g_key_file_has_group(configkeyfile, section) == FALSE)
+ if (!g_key_file_has_group(configkeyfile, section))
/*
* Config section is missing, remove the provisioned
* service.
@@ -2603,10 +2610,10 @@ static void remove_unprovisioned_providers()
__connman_storage_remove_provider(group);
next:
- if (keyfile != NULL)
+ if (keyfile)
g_key_file_free(keyfile);
- if (configkeyfile != NULL)
+ if (configkeyfile)
g_key_file_free(configkeyfile);
g_free(section);
@@ -2616,7 +2623,7 @@ static void remove_unprovisioned_providers()
g_strfreev(providers);
}
-int __vpn_provider_init(gboolean do_routes)
+int __vpn_provider_init(bool do_routes)
{
int err;
@@ -2644,12 +2651,12 @@ void __vpn_provider_cleanup(void)
{
DBG("");
+ connman_agent_driver_unregister(&agent_driver);
+
g_hash_table_foreach(provider_hash, clean_provider, NULL);
g_hash_table_destroy(provider_hash);
provider_hash = NULL;
- connman_agent_driver_unregister(&agent_driver);
-
dbus_connection_unref(connection);
}
diff --git a/vpn/vpn-provider.h b/vpn/vpn-provider.h
index 56266454..22b2062d 100644
--- a/vpn/vpn-provider.h
+++ b/vpn/vpn-provider.h
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-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
@@ -22,8 +22,9 @@
#ifndef __VPN_PROVIDER_H
#define __VPN_PROVIDER_H
+#include <stdbool.h>
+
#include <glib.h>
-#include <connman/types.h>
#ifdef __cplusplus
extern "C" {
@@ -125,7 +126,8 @@ struct vpn_provider_driver {
int (*probe) (struct vpn_provider *provider);
int (*remove) (struct vpn_provider *provider);
int (*connect) (struct vpn_provider *provider,
- vpn_provider_connect_cb_t cb, void *user_data);
+ vpn_provider_connect_cb_t cb, const char *dbus_sender,
+ void *user_data);
int (*disconnect) (struct vpn_provider *provider);
int (*save) (struct vpn_provider *provider, GKeyFile *keyfile);
};
diff --git a/vpn/vpn-rtnl.c b/vpn/vpn-rtnl.c
index 5ce14e42..a7565dba 100644
--- a/vpn/vpn-rtnl.c
+++ b/vpn/vpn-rtnl.c
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * 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
@@ -69,7 +69,6 @@ static guint update_timeout = 0;
struct interface_data {
int index;
- char *name;
char *ident;
};
@@ -80,7 +79,6 @@ static void free_interface(gpointer data)
struct interface_data *interface = data;
g_free(interface->ident);
- g_free(interface->name);
g_free(interface);
}
@@ -100,7 +98,7 @@ unsigned int vpn_rtnl_add_newlink_watch(int index,
struct watch_data *watch;
watch = g_try_new0(struct watch_data, 1);
- if (watch == NULL)
+ if (!watch)
return 0;
watch->id = ++watch_id;
@@ -237,24 +235,24 @@ static void extract_link(struct ifinfomsg *msg, int bytes,
attr = RTA_NEXT(attr, bytes)) {
switch (attr->rta_type) {
case IFLA_ADDRESS:
- if (address != NULL)
+ if (address)
memcpy(address, RTA_DATA(attr), ETH_ALEN);
break;
case IFLA_IFNAME:
- if (ifname != NULL)
+ if (ifname)
*ifname = RTA_DATA(attr);
break;
case IFLA_MTU:
- if (mtu != NULL)
+ if (mtu)
*mtu = *((unsigned int *) RTA_DATA(attr));
break;
case IFLA_STATS:
- if (stats != NULL)
+ if (stats)
memcpy(stats, RTA_DATA(attr),
sizeof(struct rtnl_link_stats));
break;
case IFLA_OPERSTATE:
- if (operstate != NULL)
+ if (operstate)
*operstate = *((unsigned char *) RTA_DATA(attr));
break;
case IFLA_LINKMODE:
@@ -315,10 +313,9 @@ static void process_newlink(unsigned short type, int index, unsigned flags,
operstate2str(operstate));
interface = g_hash_table_lookup(interface_list, GINT_TO_POINTER(index));
- if (interface == NULL) {
+ if (!interface) {
interface = g_new0(struct interface_data, 1);
interface->index = index;
- interface->name = g_strdup(ifname);
interface->ident = g_strdup(ident);
g_hash_table_insert(interface_list,
@@ -387,15 +384,15 @@ static void extract_ipv4_route(struct rtmsg *msg, int bytes, int *index,
attr = RTA_NEXT(attr, bytes)) {
switch (attr->rta_type) {
case RTA_DST:
- if (dst != NULL)
+ if (dst)
*dst = *((struct in_addr *) RTA_DATA(attr));
break;
case RTA_GATEWAY:
- if (gateway != NULL)
+ if (gateway)
*gateway = *((struct in_addr *) RTA_DATA(attr));
break;
case RTA_OIF:
- if (index != NULL)
+ if (index)
*index = *((int *) RTA_DATA(attr));
break;
}
@@ -412,16 +409,16 @@ static void extract_ipv6_route(struct rtmsg *msg, int bytes, int *index,
attr = RTA_NEXT(attr, bytes)) {
switch (attr->rta_type) {
case RTA_DST:
- if (dst != NULL)
+ if (dst)
*dst = *((struct in6_addr *) RTA_DATA(attr));
break;
case RTA_GATEWAY:
- if (gateway != NULL)
+ if (gateway)
*gateway =
*((struct in6_addr *) RTA_DATA(attr));
break;
case RTA_OIF:
- if (index != NULL)
+ if (index)
*index = *((int *) RTA_DATA(attr));
break;
}
@@ -726,20 +723,20 @@ static void rtnl_route(struct nlmsghdr *hdr)
}
}
-static connman_bool_t is_route_rtmsg(struct rtmsg *msg)
+static bool is_route_rtmsg(struct rtmsg *msg)
{
if (msg->rtm_table != RT_TABLE_MAIN)
- return FALSE;
+ return false;
if (msg->rtm_protocol != RTPROT_BOOT &&
msg->rtm_protocol != RTPROT_KERNEL)
- return FALSE;
+ return false;
if (msg->rtm_type != RTN_UNICAST)
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
static void rtnl_newroute(struct nlmsghdr *hdr)
@@ -859,13 +856,13 @@ static int process_response(guint32 seq)
debug("seq %d", seq);
req = find_request(seq);
- if (req != NULL) {
+ if (req) {
request_list = g_slist_remove(request_list, req);
g_free(req);
}
req = g_slist_nth_data(request_list, 0);
- if (req == NULL)
+ if (!req)
return 0;
return send_request(req);
@@ -923,8 +920,7 @@ static void rtnl_message(void *buf, size_t len)
}
}
-static gboolean netlink_event(GIOChannel *chan,
- GIOCondition cond, gpointer data)
+static gboolean netlink_event(GIOChannel *chan, GIOCondition cond, gpointer data)
{
unsigned char buf[4096];
struct sockaddr_nl nladdr;
@@ -969,7 +965,7 @@ static int send_getlink(void)
debug("");
req = g_try_malloc0(RTNL_REQUEST_SIZE);
- if (req == NULL)
+ if (!req)
return -ENOMEM;
req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
@@ -989,7 +985,7 @@ static int send_getaddr(void)
debug("");
req = g_try_malloc0(RTNL_REQUEST_SIZE);
- if (req == NULL)
+ if (!req)
return -ENOMEM;
req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
@@ -1009,7 +1005,7 @@ static int send_getroute(void)
debug("");
req = g_try_malloc0(RTNL_REQUEST_SIZE);
- if (req == NULL)
+ if (!req)
return -ENOMEM;
req->hdr.nlmsg_len = RTNL_REQUEST_SIZE;
@@ -1080,7 +1076,7 @@ unsigned int __vpn_rtnl_update_interval_remove(unsigned int interval)
update_list = g_slist_remove(update_list, GINT_TO_POINTER(interval));
- if (update_list != NULL)
+ if (update_list)
min = GPOINTER_TO_UINT(g_slist_nth_data(update_list, 0));
if (min > update_interval)
diff --git a/vpn/vpn.h b/vpn/vpn.h
index 53b117de..3fca03cc 100644
--- a/vpn/vpn.h
+++ b/vpn/vpn.h
@@ -2,7 +2,7 @@
*
* ConnMan VPN daemon
*
- * 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
@@ -19,12 +19,13 @@
*
*/
+#include <stdbool.h>
+
#include <glib.h>
#define VPN_API_SUBJECT_TO_CHANGE
#include <connman/dbus.h>
-#include <connman/types.h>
int __vpn_manager_init(void);
void __vpn_manager_cleanup(void);
@@ -72,7 +73,7 @@ void __vpn_ipconfig_cleanup(void);
#include "vpn-provider.h"
char *__vpn_provider_create_identifier(const char *host, const char *domain);
-connman_bool_t __vpn_provider_check_routes(struct vpn_provider *provider);
+bool __vpn_provider_check_routes(struct vpn_provider *provider);
int __vpn_provider_append_user_route(struct vpn_provider *provider,
int family, const char *network,
const char *netmask, const char *gateway);
@@ -96,7 +97,7 @@ int __vpn_provider_disconnect(struct vpn_provider *provider);
int __vpn_provider_remove(const char *path);
int __vpn_provider_delete(struct vpn_provider *provider);
void __vpn_provider_cleanup(void);
-int __vpn_provider_init(gboolean handle_routes);
+int __vpn_provider_init(bool handle_routes);
#include "vpn-rtnl.h"
@@ -111,3 +112,7 @@ int __vpn_rtnl_send(const void *buf, size_t len);
int __vpn_config_init(void);
void __vpn_config_cleanup(void);
+char *__vpn_config_get_string(GKeyFile *key_file,
+ const char *group_name, const char *key, GError **error);
+char **__vpn_config_get_string_list(GKeyFile *key_file,
+ const char *group_name, const char *key, gsize *length, GError **error);