Apply coding rule
[platform/core/connectivity/net-config.git] / src / network-state.c
index 8cf712f..5180cd2 100755 (executable)
 #include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <aul.h>
 #include <net/if.h>
 #include <arpa/inet.h>
 #include <netinet/in.h>
 #include <sys/ioctl.h>
 #include <ITapiSim.h>
 #include <TapiUtility.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <eventsystem.h>
 
 #include "log.h"
 #include "util.h"
@@ -105,9 +107,8 @@ static gboolean __netconfig_is_connected(GVariantIter *array)
        const gchar *value = NULL;
 
        while (g_variant_iter_loop(array, "{sv}", &key, &variant)) {
-               if (g_strcmp0(key, "State") != 0) {
+               if (g_strcmp0(key, "State") != 0)
                        continue;
-               }
 
                if (g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)) {
                        value = g_variant_get_string(variant, NULL);
@@ -141,13 +142,11 @@ static char *__netconfig_get_default_profile(void)
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &object_path, &next)) {
-               if (object_path == NULL) {
+               if (object_path == NULL)
                        continue;
-               }
 
-               if(netconfig_is_cellular_profile(object_path) && !netconfig_is_cellular_internet_profile(object_path)){
+               if (netconfig_is_cellular_profile(object_path) && !netconfig_is_cellular_internet_profile(object_path))
                        continue;
-               }
 
                if (__netconfig_is_connected(next) == TRUE) {
                        default_profile = g_strdup(object_path);
@@ -261,10 +260,10 @@ done:
                g_variant_unref(message);
 
        if (iter)
-               g_variant_iter_free (iter);
+               g_variant_iter_free(iter);
 
        if (iter1)
-               g_variant_iter_free (iter1);
+               g_variant_iter_free(iter1);
 
        return;
 }
@@ -439,36 +438,43 @@ static void __netconfig_update_default_connection_info(void)
 
                /* Disable clatd if it is in running state */
                netconfig_clatd_disable();
-       }
-       else if (profile != NULL) {
+       } else if (profile != NULL) {
                char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP);
                char *old_proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
 
                if (netconfig_is_wifi_profile(profile) == TRUE) {
                        netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_WIFI);
                        netconfig_set_vconf_int("memory/private/wifi/frequency", freq);
-               }
-               else if (netconfig_is_cellular_profile(profile) ){
 
-                       if( !netconfig_is_cellular_internet_profile(profile)){
+                       netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS,
+                               EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_WIFI);
+               } else if (netconfig_is_cellular_profile(profile)) {
+
+                       if (!netconfig_is_cellular_internet_profile(profile)) {
                                DBG("connection is not a internet profile - stop to update the cellular state");
                                return;
                        }
 
                        netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_CELLULAR);
 
+                       netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS,
+                               EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_CELLULAR);
+
                        /* Enable clatd if IPv6 is set and no IPv4 address */
-                       if (!ip_addr && ip_addr6 )
+                       if (!ip_addr && ip_addr6)
                                netconfig_clatd_enable();
-               }
-               else if (netconfig_is_ethernet_profile(profile) == TRUE){
+               } else if (netconfig_is_ethernet_profile(profile) == TRUE) {
                        netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_ETHERNET);
-               }
-               else if (netconfig_is_bluetooth_profile(profile) == TRUE){
+                       netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS,
+                               EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_ETHERNET);
+               } else if (netconfig_is_bluetooth_profile(profile) == TRUE) {
                        netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_BLUETOOTH);
-               }
-               else{
+                       netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS,
+                               EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_BT);
+               } else{
                        netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_OFF);
+                       netconfig_set_system_event(SYS_EVENT_NETWORK_STATUS,
+                               EVT_KEY_NETWORK_STATUS, EVT_VAL_NETWORK_DISCONNECTED);
                }
 
                if (g_strcmp0(old_ip, ip_addr) != 0 || old_ip == NULL) {
@@ -520,9 +526,8 @@ static gboolean __netconfig_is_tech_state_connected(void)
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
-               if (path == NULL) {
+               if (path == NULL)
                        continue;
-               }
 
                while (g_variant_iter_loop(next, "{sv}", &key, &variant)) {
                        gboolean data;
@@ -566,9 +571,8 @@ static void __netconfig_update_if_service_connected(void)
 
        g_variant_get(message, "(a(oa{sv}))", &iter);
        while (g_variant_iter_loop(iter, "(oa{sv})", &path, &next)) {
-               if (path == NULL) {
+               if (path == NULL)
                        continue;
-               }
 
                if (g_str_has_prefix(path,
                                                CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE) {
@@ -630,7 +634,7 @@ static void __netconfig_network_notify_result(const char *sig_name, const char *
                return;
        }
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE ("a{sv}"));
+       builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
        g_variant_builder_add(builder, "{sv}", prop_key, g_variant_new_string(key));
        params = g_variant_new("(@a{sv})", g_variant_builder_end(builder));
 
@@ -785,17 +789,17 @@ void netconfig_update_default_profile(const char *profile)
                }
        }
 
-       //default profile is NULL and new connected profile is NULL
-       if( !profile ){
+       /* default profile is NULL and new connected profile is NULL */
+       if (!profile) {
                profile = __netconfig_get_default_profile();
 
                if (profile && netconfig_is_cellular_profile(profile) &&
-                       !netconfig_is_cellular_internet_profile(profile)){
+                       !netconfig_is_cellular_internet_profile(profile)) {
                        DBG("not a default cellular profile");
                        profile = NULL;
                }
 
-               if(!profile){
+               if (!profile) {
                        __netconfig_update_default_connection_info();
                        return;
                }
@@ -856,7 +860,7 @@ char *netconfig_get_ifname(const char *profile)
 /* Check Ethernet Cable Plug-in /Plug-out Status */
 void netconfig_network_notify_ethernet_cable_state(const char *key)
 {
-       __netconfig_network_notify_result("EthernetCableState", key);
+       __netconfig_network_notify_result("EthernetCableState", key);
 }
 
 static gboolean handle_add_route(
@@ -877,48 +881,48 @@ static gboolean handle_add_route(
 
        DBG("ip_addr(%s), netmask(%s), interface(%s), gateway(%s)", ip_addr, netmask, interface, gateway);
 
-       switch(address_family) {
-               case AF_INET:
-                       if (ip_addr == NULL || netmask == NULL || interface == NULL) {
-                               ERR("Invalid parameter");
-                               netconfig_error_invalid_parameter(context);
-                               return FALSE;
-                       }
+       switch (address_family) {
+       case AF_INET:
+               if (ip_addr == NULL || netmask == NULL || interface == NULL) {
+                       ERR("Invalid parameter");
+                       netconfig_error_invalid_parameter(context);
+                       return FALSE;
+               }
 
-                       if (netconfig_execute_file(path, args, envs) < 0) {
-                               DBG("Failed to add a new route");
-                               netconfig_error_permission_denied(context);
-                               return FALSE;
-                       }
+               if (netconfig_execute_file(path, args, envs) < 0) {
+                       DBG("Failed to add a new route");
+                       netconfig_error_permission_denied(context);
+                       return FALSE;
+               }
 
-                       break;
-               case AF_INET6:
-                       if (ip_addr == NULL || interface == NULL || gateway == NULL) {
-                               ERR("Invalid parameter");
-                               netconfig_error_invalid_parameter(context);
-                               return FALSE;
-                       }
+               break;
+       case AF_INET6:
+               if (ip_addr == NULL || interface == NULL || gateway == NULL) {
+                       ERR("Invalid parameter");
+                       netconfig_error_invalid_parameter(context);
+                       return FALSE;
+               }
 
-                       buf = ip_addr;
-                       ch = strchr(buf, '/');
-                       pos = ch - buf + 1;
-                       if (ch) {
-                               prefix_len = atoi(ch + 1);
-                               ip_addr[pos-1] = '\0';
-                       } else {
-                               prefix_len = 128;
-                       }
+               buf = ip_addr;
+               ch = strchr(buf, '/');
+               pos = ch - buf + 1;
+               if (ch) {
+                       prefix_len = atoi(ch + 1);
+                       ip_addr[pos-1] = '\0';
+               } else {
+                       prefix_len = 128;
+               }
 
-                       if (netconfig_add_route_ipv6(ip_addr, interface, gateway, prefix_len) < 0) {
-                               DBG("Failed to add a new route");
-                               netconfig_error_permission_denied(context);
-                               return FALSE;
-                       }
-                       break;
-               default:
-                       DBG("Unknown Address Family");
-                       netconfig_error_invalid_parameter(context);
+               if (netconfig_add_route_ipv6(ip_addr, interface, gateway, prefix_len) < 0) {
+                       DBG("Failed to add a new route");
+                       netconfig_error_permission_denied(context);
                        return FALSE;
+               }
+               break;
+       default:
+               DBG("Unknown Address Family");
+               netconfig_error_invalid_parameter(context);
+               return FALSE;
        }
 
        DBG("Successfully added a new route");
@@ -944,46 +948,46 @@ static gboolean handle_remove_route(
 
        DBG("ip_addr(%s), netmask(%s), interface(%s), gateway(%s)", ip_addr, netmask, interface, gateway);
 
-       switch(address_family) {
-               case AF_INET:
-                       if (ip_addr == NULL || netmask == NULL || interface == NULL) {
-                               DBG("Invalid parameter!");
-                               netconfig_error_invalid_parameter(context);
-                               return FALSE;
-                       }
-                       if (netconfig_execute_file(path, args, envs) < 0) {
-                               DBG("Failed to remove the route");
-                               netconfig_error_permission_denied(context);
-                               return FALSE;
-                       }
-                       break;
-               case AF_INET6:
-                       if (ip_addr == NULL || interface == NULL || gateway == NULL) {
-                               DBG("Invalid parameter!");
-                               netconfig_error_invalid_parameter(context);
-                               return FALSE;
-                       }
+       switch (address_family) {
+       case AF_INET:
+               if (ip_addr == NULL || netmask == NULL || interface == NULL) {
+                       DBG("Invalid parameter!");
+                       netconfig_error_invalid_parameter(context);
+                       return FALSE;
+               }
+               if (netconfig_execute_file(path, args, envs) < 0) {
+                       DBG("Failed to remove the route");
+                       netconfig_error_permission_denied(context);
+                       return FALSE;
+               }
+               break;
+       case AF_INET6:
+               if (ip_addr == NULL || interface == NULL || gateway == NULL) {
+                       DBG("Invalid parameter!");
+                       netconfig_error_invalid_parameter(context);
+                       return FALSE;
+               }
 
-                       buf = ip_addr;
-                       ch = strchr(buf, '/');
-                       pos = ch - buf + 1;
-                       if (ch) {
-                               prefix_len = atoi(ch + 1);
-                               ip_addr[pos-1] = '\0';
-                       } else {
-                               prefix_len = 128;
-                       }
+               buf = ip_addr;
+               ch = strchr(buf, '/');
+               pos = ch - buf + 1;
+               if (ch) {
+                       prefix_len = atoi(ch + 1);
+                       ip_addr[pos-1] = '\0';
+               } else {
+                       prefix_len = 128;
+               }
 
-                       if (netconfig_del_route_ipv6(ip_addr, interface, gateway, prefix_len) < 0) {
-                               DBG("Failed to remove the route");
-                               netconfig_error_permission_denied(context);
-                               return FALSE;
-                       }
-                       break;
-               default:
-                       DBG("Unknown Address Family");
-                       netconfig_error_invalid_parameter(context);
+               if (netconfig_del_route_ipv6(ip_addr, interface, gateway, prefix_len) < 0) {
+                       DBG("Failed to remove the route");
+                       netconfig_error_permission_denied(context);
                        return FALSE;
+               }
+               break;
+       default:
+               DBG("Unknown Address Family");
+               netconfig_error_invalid_parameter(context);
+               return FALSE;
        }
 
        DBG("Successfully removed the route");
@@ -1013,7 +1017,7 @@ gboolean handle_ethernet_cable_state(Network *object,
        int state = 0;
 
        ret = netconfig_get_ethernet_cable_state(&state);
-       if(ret != 0) {
+       if (ret != 0) {
                DBG("Failed to get ethernet cable state");
                netconfig_error_fail_ethernet_cable_state(context);
                return FALSE;
@@ -1046,6 +1050,8 @@ void state_object_create_and_init(void)
                                G_CALLBACK(handle_check_get_privilege), NULL);
        g_signal_connect(netconfigstate, "handle-check-profile-privilege",
                                G_CALLBACK(handle_check_profile_privilege), NULL);
+       g_signal_connect(netconfigstate, "handle-ethernet-cable-state",
+                               G_CALLBACK(handle_ethernet_cable_state), NULL);
        g_signal_connect(netconfigstate, "handle-remove-route",
                                G_CALLBACK(handle_remove_route), NULL);