From: Chengyi Zhao Date: Mon, 8 Dec 2014 09:36:55 +0000 (+0800) Subject: Get the proxy address of the current connection X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1bea3864ab45f12dd7be48787536ca0faef8e8f9;p=platform%2Fcore%2Fapi%2Fconnection.git Get the proxy address of the current connection Change-Id: I4c26aaa780d731b378350a427932e8917f404594 Signed-off-by: Chengyi Zhao --- diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 2471c77..7968595 100644 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -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); diff --git a/src/connection.c b/src/connection.c index 848d292..0dc8d3c 100644 --- a/src/connection.c +++ b/src/connection.c @@ -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; } diff --git a/src/libnetwork.c b/src/libnetwork.c index c5b8668..32e7802 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -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; +}