summaryrefslogtreecommitdiff
path: root/src/provider.c
diff options
context:
space:
mode:
authorZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 10:37:39 +0800
committerZhang zhengguang <zhengguang.zhang@intel.com>2014-07-17 10:37:39 +0800
commit1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7 (patch)
tree6e991827d28537f7f40f20786c2354fd04a9fdad /src/provider.c
parentfbe905ab58ecc31fe64c410c5f580cadc30e7f04 (diff)
downloadconnman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.gz
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.tar.bz2
connman-1b9d0a62f59bb48c8deb2f0b98d9acdffdd9abe7.zip
Imported Upstream version 1.24upstream/1.24
Diffstat (limited to 'src/provider.c')
-rw-r--r--src/provider.c138
1 files changed, 73 insertions, 65 deletions
diff --git a/src/provider.c b/src/provider.c
index 1c360172..693552ee 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -2,7 +2,7 @@
*
* Connection Manager
*
- * 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
@@ -40,6 +40,7 @@ static GSList *driver_list = NULL;
struct connman_provider {
int refcount;
+ bool immutable;
struct connman_service *vpn_service;
int index;
char *identifier;
@@ -53,22 +54,22 @@ void __connman_provider_append_properties(struct connman_provider *provider,
{
const char *host, *domain, *type;
- if (provider->driver == NULL || provider->driver->get_property == NULL)
+ if (!provider->driver || !provider->driver->get_property)
return;
host = provider->driver->get_property(provider, "Host");
domain = provider->driver->get_property(provider, "Domain");
type = provider->driver->get_property(provider, "Type");
- if (host != NULL)
+ if (host)
connman_dbus_dict_append_basic(iter, "Host",
DBUS_TYPE_STRING, &host);
- if (domain != NULL)
+ if (domain)
connman_dbus_dict_append_basic(iter, "Domain",
DBUS_TYPE_STRING, &domain);
- if (type != NULL)
+ if (type)
connman_dbus_dict_append_basic(iter, "Type", DBUS_TYPE_STRING,
&type);
}
@@ -87,7 +88,7 @@ connman_provider_ref_debug(struct connman_provider *provider,
static void provider_remove(struct connman_provider *provider)
{
- if (provider->driver != NULL) {
+ if (provider->driver) {
provider->driver->remove(provider);
provider->driver = NULL;
}
@@ -131,12 +132,12 @@ int connman_provider_disconnect(struct connman_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;
- if (provider->vpn_service != NULL)
+ if (provider->vpn_service)
provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_DISCONNECT);
@@ -169,9 +170,9 @@ int __connman_provider_connect(struct connman_provider *provider)
DBG("provider %p", provider);
- if (provider->driver != NULL && provider->driver->connect != NULL) {
+ if (provider->driver && provider->driver->connect)
err = provider->driver->connect(provider);
- } else
+ else
return -EOPNOTSUPP;
if (err < 0) {
@@ -196,11 +197,11 @@ int __connman_provider_remove_by_path(const char *path)
DBG("path %s", path);
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)) {
const char *srv_path;
provider = value;
- if (provider->vpn_service == NULL)
+ if (!provider->vpn_service)
continue;
srv_path = __connman_service_get_path(provider->vpn_service);
@@ -223,18 +224,18 @@ int __connman_provider_remove_by_path(const char *path)
}
static int set_connected(struct connman_provider *provider,
- connman_bool_t connected)
+ bool connected)
{
struct connman_service *service = provider->vpn_service;
struct connman_ipconfig *ipconfig;
- if (service == NULL)
+ if (!service)
return -ENODEV;
ipconfig = __connman_service_get_ipconfig(service, provider->family);
- if (connected == TRUE) {
- if (ipconfig == NULL) {
+ if (connected) {
+ if (!ipconfig) {
provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_FAILURE);
return -EIO;
@@ -246,12 +247,12 @@ static int set_connected(struct connman_provider *provider,
provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_READY);
- if (provider->driver != NULL && provider->driver->set_routes)
+ if (provider->driver && provider->driver->set_routes)
provider->driver->set_routes(provider,
CONNMAN_PROVIDER_ROUTE_ALL);
} else {
- if (ipconfig != NULL) {
+ if (ipconfig) {
provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_DISCONNECT);
__connman_ipconfig_gateway_remove(ipconfig);
@@ -267,19 +268,19 @@ static int set_connected(struct connman_provider *provider,
int connman_provider_set_state(struct connman_provider *provider,
enum connman_provider_state state)
{
- if (provider == NULL || provider->vpn_service == NULL)
+ if (!provider || !provider->vpn_service)
return -EINVAL;
switch (state) {
case CONNMAN_PROVIDER_STATE_UNKNOWN:
return -EINVAL;
case CONNMAN_PROVIDER_STATE_IDLE:
- return set_connected(provider, FALSE);
+ return set_connected(provider, false);
case CONNMAN_PROVIDER_STATE_CONNECT:
return provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_ASSOCIATION);
case CONNMAN_PROVIDER_STATE_READY:
- return set_connected(provider, TRUE);
+ return set_connected(provider, true);
case CONNMAN_PROVIDER_STATE_DISCONNECT:
return provider_indicate_state(provider,
CONNMAN_SERVICE_STATE_DISCONNECT);
@@ -317,17 +318,17 @@ int connman_provider_indicate_error(struct connman_provider *provider,
int connman_provider_create_service(struct connman_provider *provider)
{
- if (provider->vpn_service != NULL) {
- connman_bool_t connected;
+ if (provider->vpn_service) {
+ bool connected;
connected = __connman_service_is_connected_state(
provider->vpn_service, CONNMAN_IPCONFIG_TYPE_IPV4);
- if (connected == TRUE)
+ if (connected)
return -EALREADY;
connected = __connman_service_is_connected_state(
provider->vpn_service, CONNMAN_IPCONFIG_TYPE_IPV6);
- if (connected == TRUE)
+ if (connected)
return -EALREADY;
return 0;
@@ -336,7 +337,7 @@ int connman_provider_create_service(struct connman_provider *provider)
provider->vpn_service =
__connman_service_create_from_provider(provider);
- if (provider->vpn_service == NULL) {
+ if (!provider->vpn_service) {
connman_warn("service creation failed for provider %s",
provider->identifier);
@@ -347,17 +348,24 @@ int connman_provider_create_service(struct connman_provider *provider)
return 0;
}
+bool __connman_provider_is_immutable(struct connman_provider *provider)
+
+{
+ if (provider)
+ return provider->immutable;
+
+ return false;
+}
+
int connman_provider_set_immutable(struct connman_provider *provider,
- connman_bool_t immutable)
+ bool immutable)
{
- if (provider == NULL)
+ if (!provider)
return -EINVAL;
- if (provider->vpn_service == NULL)
- return -ESRCH;
+ provider->immutable = immutable;
- return __connman_service_set_immutable(provider->vpn_service,
- immutable);
+ return 0;
}
static struct connman_provider *provider_lookup(const char *identifier)
@@ -374,15 +382,15 @@ static void connection_ready(DBusMessage *msg, int error_code, void *user_data)
if (error_code != 0) {
reply = __connman_error_failed(msg, -error_code);
- if (g_dbus_send_message(connection, reply) == FALSE)
+ if (!g_dbus_send_message(connection, reply))
DBG("reply %p send failed", reply);
} else {
const char *path;
struct connman_provider *provider;
provider = provider_lookup(identifier);
- if (provider == NULL) {
- reply = __connman_error_failed(msg, -EINVAL);
+ if (!provider) {
+ reply = __connman_error_failed(msg, EINVAL);
g_dbus_send_message(connection, reply);
return;
}
@@ -399,11 +407,11 @@ int __connman_provider_create_and_connect(DBusMessage *msg)
{
struct connman_provider_driver *driver;
- if (driver_list == NULL)
+ if (!driver_list)
return -EINVAL;
driver = driver_list->data;
- if (driver == NULL || driver->create == NULL)
+ if (!driver || !driver->create)
return -EINVAL;
DBG("msg %p", msg);
@@ -411,9 +419,9 @@ int __connman_provider_create_and_connect(DBusMessage *msg)
return driver->create(msg, connection_ready);
}
-const char * __connman_provider_get_ident(struct connman_provider *provider)
+const char *__connman_provider_get_ident(struct connman_provider *provider)
{
- if (provider == NULL)
+ if (!provider)
return NULL;
return provider->identifier;
@@ -422,7 +430,7 @@ const char * __connman_provider_get_ident(struct connman_provider *provider)
int connman_provider_set_string(struct connman_provider *provider,
const char *key, const char *value)
{
- if (provider->driver != NULL && provider->driver->set_property)
+ if (provider->driver && provider->driver->set_property)
return provider->driver->set_property(provider, key, value);
return 0;
@@ -431,22 +439,22 @@ int connman_provider_set_string(struct connman_provider *provider,
const char *connman_provider_get_string(struct connman_provider *provider,
const char *key)
{
- if (provider->driver != NULL && provider->driver->get_property)
+ if (provider->driver && provider->driver->get_property)
return provider->driver->get_property(provider, key);
return NULL;
}
-connman_bool_t
+bool
__connman_provider_check_routes(struct connman_provider *provider)
{
- if (provider == NULL)
- return FALSE;
+ if (!provider)
+ return false;
- if (provider->driver != NULL && provider->driver->check_routes)
+ if (provider->driver && provider->driver->check_routes)
return provider->driver->check_routes(provider);
- return FALSE;
+ return false;
}
void *connman_provider_get_data(struct connman_provider *provider)
@@ -466,16 +474,16 @@ void connman_provider_set_index(struct connman_provider *provider, int index)
DBG("");
- if (service == NULL)
+ if (!service)
return;
ipconfig = __connman_service_get_ip4config(service);
- if (ipconfig == NULL) {
+ if (!ipconfig) {
connman_service_create_ip4config(service, index);
ipconfig = __connman_service_get_ip4config(service);
- if (ipconfig == NULL) {
+ if (!ipconfig) {
DBG("Couldnt create ipconfig");
goto done;
}
@@ -486,11 +494,11 @@ void connman_provider_set_index(struct connman_provider *provider, int index)
ipconfig = __connman_service_get_ip6config(service);
- if (ipconfig == NULL) {
+ if (!ipconfig) {
connman_service_create_ip6config(service, index);
ipconfig = __connman_service_get_ip6config(service);
- if (ipconfig == NULL) {
+ if (!ipconfig) {
DBG("Couldnt create ipconfig for IPv6");
goto done;
}
@@ -515,7 +523,7 @@ int connman_provider_set_ipaddress(struct connman_provider *provider,
ipconfig = __connman_service_get_ipconfig(provider->vpn_service,
ipaddress->family);
- if (ipconfig == NULL)
+ if (!ipconfig)
return -EINVAL;
provider->family = ipaddress->family;
@@ -552,7 +560,7 @@ int connman_provider_set_domain(struct connman_provider *provider,
}
int connman_provider_set_nameservers(struct connman_provider *provider,
- char * const * nameservers)
+ char * const *nameservers)
{
int i;
@@ -560,12 +568,12 @@ int connman_provider_set_nameservers(struct connman_provider *provider,
__connman_service_nameserver_clear(provider->vpn_service);
- if (nameservers == NULL)
+ if (!nameservers)
return 0;
- for (i = 0; nameservers[i] != NULL; i++)
+ for (i = 0; nameservers[i]; i++)
__connman_service_nameserver_append(provider->vpn_service,
- nameservers[i], FALSE);
+ nameservers[i], false);
return 0;
}
@@ -576,7 +584,7 @@ static void unregister_provider(gpointer data)
DBG("provider %p service %p", provider, provider->vpn_service);
- if (provider->vpn_service != NULL) {
+ if (provider->vpn_service) {
connman_service_unref(provider->vpn_service);
provider->vpn_service = NULL;
}
@@ -619,11 +627,11 @@ static void provider_disconnect_all(gpointer key, gpointer value,
connman_provider_disconnect(provider);
}
-static void provider_offline_mode(connman_bool_t enabled)
+static void provider_offline_mode(bool enabled)
{
DBG("enabled %d", enabled);
- if (enabled == TRUE)
+ if (enabled)
g_hash_table_foreach(provider_hash, provider_disconnect_all,
NULL);
@@ -642,7 +650,7 @@ static struct connman_provider *provider_new(void)
struct connman_provider *provider;
provider = g_try_new0(struct connman_provider, 1);
- if (provider == NULL)
+ if (!provider)
return NULL;
provider->refcount = 1;
@@ -658,11 +666,11 @@ struct connman_provider *connman_provider_get(const char *identifier)
struct connman_provider *provider;
provider = g_hash_table_lookup(provider_hash, identifier);
- if (provider != NULL)
+ if (provider)
return provider;
provider = provider_new();
- if (provider == NULL)
+ if (!provider)
return NULL;
DBG("provider %p", provider);
@@ -686,7 +694,7 @@ static struct connman_provider *provider_get(int index)
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 connman_provider *provider = value;
if (provider->index == index)
@@ -702,7 +710,7 @@ static void provider_service_changed(struct connman_service *service,
struct connman_provider *provider;
int vpn_index, service_index;
- if (service == NULL)
+ if (!service)
return;
switch (state) {
@@ -730,7 +738,7 @@ static void provider_service_changed(struct connman_service *service,
return;
provider = provider_get(vpn_index);
- if (provider == NULL)
+ if (!provider)
return;
DBG("disconnect %p index %d", provider, vpn_index);