Get the proxy address of the current connection 28/31628/2
authorChengyi Zhao <chengyi1.zhao@archermind.com>
Mon, 8 Dec 2014 09:36:55 +0000 (17:36 +0800)
committerChengyi Zhao <chengyi1.zhao@archermind.com>
Wed, 10 Dec 2014 01:39:18 +0000 (09:39 +0800)
Change-Id: I4c26aaa780d731b378350a427932e8917f404594
Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
include/net_connection_private.h
src/connection.c
src/libnetwork.c

index 2471c772abc83ed7257305ca0e6851bbec0ff19a..79685956e41825fed775d1b5e4a16ae5432c6c44 100644 (file)
@@ -98,6 +98,7 @@ struct connman_service *_connection_libnet_get_service_h(
                                                connection_profile_h profile);
 int _connection_libnet_get_default_device_type(net_device_t *net_type);
 int _connection_libnet_get_default_ip_address(char **ip_address);
+int _connection_libnet_get_default_proxy(char **proxy_address);
 
 void _connection_inter_mutex_lock(void);
 void _connection_inter_mutex_unlock(void);
index 848d2922eb89139d51a069db09ab73528b6316f5..0dc8d3c1cedb3b621a8e39021ef37aa9f2c42771 100644 (file)
@@ -362,7 +362,9 @@ EXPORT_API int connection_get_proxy(connection_h connection,
 
        switch (address_family) {
        case CONNECTION_ADDRESS_FAMILY_IPV4:
-               *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
+               if (_connection_libnet_get_default_proxy(proxy) !=
+                                                       CONNECTION_ERROR_NONE)
+                       return CONNECTION_ERROR_OPERATION_FAILED;
                break;
        case CONNECTION_ADDRESS_FAMILY_IPV6:
                CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n");
@@ -374,7 +376,7 @@ EXPORT_API int connection_get_proxy(connection_h connection,
        }
 
        if (*proxy == NULL) {
-               CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n");
+               CONNECTION_LOG(CONNECTION_ERROR, "Get Proxy Failed\n");
                return CONNECTION_ERROR_OPERATION_FAILED;
        }
 
index c5b8668538a63826bb72fd0efbfbc0e6adbc2bab..32e78021ba95e76a80a3ff9ee6056c92ce44116e 100755 (executable)
@@ -230,6 +230,21 @@ static void __libnet_clear_profile_list(struct _profile_list_s *profile_list)
        profile_list->profiles = NULL;
 }
 
+static net_proxy_type_t __libnet_proxy_type_string2type(const char *str)
+{
+       if (str == NULL)
+               return NET_PROXY_TYPE_UNKNOWN;
+
+       if (g_strcmp0(str, "direct") == 0)
+               return NET_PROXY_TYPE_DIRECT;
+       if (g_strcmp0(str, "manual") == 0)
+               return NET_PROXY_TYPE_MANUAL;
+       if (g_strcmp0(str, "auto") == 0)
+               return NET_PROXY_TYPE_AUTO;
+
+       return NET_PROXY_TYPE_UNKNOWN;
+}
+
 static net_device_t __libnet_service_type_string2type(const char *str)
 {
        if (str == NULL)
@@ -967,3 +982,33 @@ int _connection_libnet_get_default_ip_address(char **ip_address)
 
        return CONNECTION_ERROR_NONE;
 }
+
+int _connection_libnet_get_default_proxy(char **proxy_address)
+{
+       int rv;
+       struct connman_service *default_service;
+       const struct service_proxy *proxy;
+       net_proxy_type_t proxy_type;
+
+       rv = __libnet_get_default_service(&default_service);
+       if (rv == CONNECTION_ERROR_NO_CONNECTION)
+               return CONNECTION_ERROR_NO_CONNECTION;
+
+       proxy = connman_service_get_proxy_info(default_service);
+       if (proxy->method == NULL)
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
+       proxy_type = __libnet_proxy_type_string2type(proxy->method);
+
+       if (proxy_type == NET_PROXY_TYPE_AUTO && proxy->url != NULL)
+               *proxy_address = g_strdup(proxy->url);
+       else if (proxy_type == NET_PROXY_TYPE_MANUAL && proxy->servers != NULL)
+               *proxy_address = g_strdup(proxy->servers[0]);
+       else
+               return CONNECTION_ERROR_OPERATION_FAILED;
+
+       if (*proxy_address == NULL)
+               return CONNECTION_ERROR_OUT_OF_MEMORY;
+
+       return CONNECTION_ERROR_NONE;
+}