Add new API to check whether metered or non metered
[platform/core/api/connection.git] / src / connection.c
index 0cf5532..2b74071 100755 (executable)
@@ -205,6 +205,7 @@ static void *__connection_get_ip_changed_userdata(
 static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
 {
        char *ip_addr;
+       char *ip6_addr;
        void *data;
        connection_address_changed_cb callback;
        connection_handle_s *local_handle = (connection_handle_s *)user_data;
@@ -217,13 +218,19 @@ static gboolean __connection_cb_ip_changed_cb_idle(gpointer user_data)
                CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
                        "vconf_get_str(VCONFKEY_NETWORK_IP) is Failed");
 
+       ip6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
+       if (ip6_addr == NULL)
+               CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
+                       "vconf_get_str(VCONFKEY_NETWORK_IP6) is Failed");
+
        callback = __connection_get_ip_changed_callback(local_handle);
        data = __connection_get_ip_changed_userdata(local_handle);
-       /* TODO: IPv6 should be supported */
+
        if (callback)
-               callback(ip_addr, NULL, data);
+               callback(ip_addr, ip6_addr, data);
 
        free(ip_addr);
+       free(ip6_addr);
 
        return FALSE;
 }
@@ -254,9 +261,12 @@ static int __connection_set_ip_changed_callback(connection_h connection,
        local_handle = (connection_handle_s *)connection;
 
        if (callback) {
-               if (refcount == 0)
+               if (refcount == 0) {
                        vconf_notify_key_changed(VCONFKEY_NETWORK_IP,
                                        __connection_cb_ip_change_cb, NULL);
+                       vconf_notify_key_changed(VCONFKEY_NETWORK_IP6,
+                                       __connection_cb_ip_change_cb, NULL);
+               }
 
                refcount++;
                CONNECTION_LOG(CONNECTION_INFO, "Successfully registered(%d)", refcount);
@@ -272,6 +282,14 @@ static int __connection_set_ip_changed_callback(connection_h connection,
                                        CONNECTION_LOG(CONNECTION_INFO,
                                                        "Successfully de-registered(%d)", refcount);
                                }
+                               if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP6,
+                                               __connection_cb_ip_change_cb) < 0) {
+                                       CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
+                                                       "Error to de-register vconf callback(%d)", refcount);
+                               } else {
+                                       CONNECTION_LOG(CONNECTION_INFO,
+                                                       "Successfully de-registered(%d)", refcount);
+                               }
                        }
                }
        }
@@ -649,6 +667,26 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
 }
 
 
+EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+       if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       int rv = _connection_libnet_get_metered_state(is_metered);
+       if (rv != CONNECTION_ERROR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
+               return rv; //LCOV_EXCL_LINE
+       }
+
+       CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
+       return CONNECTION_ERROR_NONE;
+}
+
+
 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
 {
        int rv = 0;
@@ -1190,6 +1228,54 @@ EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char
        return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
 }
 
+EXPORT_API int connection_add_route_entry(connection_h connection,
+               connection_address_family_e address_family,     const char *interface_name,
+               const char *host_address, const char *gateway)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
+
+       if (!(__connection_check_handle_validity(connection)) ||
+               (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
+            address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
+           interface_name == NULL || host_address == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
+               return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
+                                                               interface_name, host_address, gateway);
+       else
+               return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
+                                                               interface_name, host_address, gateway);
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_remove_route_entry(connection_h connection,
+               connection_address_family_e address_family,     const char *interface_name,
+               const char *host_address, const char *gateway)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
+
+       if (!(__connection_check_handle_validity(connection)) ||
+               (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
+            address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
+           interface_name == NULL || host_address == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
+               return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
+                                                               interface_name, host_address, gateway);
+       else
+               return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
+                                                               interface_name, host_address, gateway);
+
+       return CONNECTION_ERROR_NONE;
+}
+
 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
 {
        int rv = VCONF_OK, rv1 = VCONF_OK;