Simplify __net_extract_wifi_info by using functions dedicated to each key 62/188262/1
authorchleun.moon <chleun.moon@samsung.com>
Mon, 3 Sep 2018 10:35:30 +0000 (19:35 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Mon, 3 Sep 2018 10:35:36 +0000 (19:35 +0900)
Change-Id: Ib14f7b6638c0f52b3d849613645ca9adb7b5befd
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
src/network-profile-intf.c

index 5d3140b..4ff60f1 100755 (executable)
@@ -1363,182 +1363,223 @@ static wlan_eap_auth_type_t __convert_eap_auth_from_string(const char *eap_auth)
                return WLAN_SEC_EAP_AUTH_NONE;
 }
 
-static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t* ProfInfo)
+static void __net_set_wifi_mode(GVariant *var, net_wifi_profile_info_t *Wlan)
 {
-       net_err_t Error = NET_ERR_NONE;
-       net_wifi_profile_info_t *Wlan = &(ProfInfo->ProfileInfo.Wlan);
-       GVariant *var = NULL;
-       const gchar *key = NULL;
+       const gchar *value = g_variant_get_string(var, NULL);
 
-       __NETWORK_FUNC_ENTER__;
+       if (g_strcmp0(value, "managed") == 0)
+               Wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
+       else if (g_strcmp0(value, "adhoc") == 0)
+               Wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
+       else
+               Wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
+}
 
-       while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
-               const gchar *value = NULL;
+static void __net_set_wifi_security(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       GVariantIter *iter_sub = NULL;
+       const gchar *value = NULL;
 
-               if (g_strcmp0(key, "Mode") == 0) {
-                       value = g_variant_get_string(var, NULL);
+       g_variant_get(var, "as", &iter_sub);
+       while (g_variant_iter_loop(iter_sub, "s", &value)) {
+               if (g_strcmp0(value, "none") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
+               else if (g_strcmp0(value, "wep") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
+               else if (g_strcmp0(value, "psk") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
+               else if (g_strcmp0(value, "ft_psk") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_FT_PSK)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK;
+               else if (g_strcmp0(value, "ieee8021x") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
+               else if (g_strcmp0(value, "wpa") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
+               else if (g_strcmp0(value, "rsn") == 0 &&
+                               Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
+               else if (g_strcmp0(value, "wps") == 0)
+                       Wlan->security_info.wps_support = TRUE;
+               else if (Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
+                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
+       }
+       g_variant_iter_free(iter_sub);
+}
 
-                       if (g_strcmp0(value, "managed") == 0)
-                               Wlan->wlan_mode = NETPM_WLAN_CONNMODE_INFRA;
-                       else if (g_strcmp0(value, "adhoc") == 0)
-                               Wlan->wlan_mode = NETPM_WLAN_CONNMODE_ADHOC;
-                       else
-                               Wlan->wlan_mode = NETPM_WLAN_CONNMODE_AUTO;
+static void __net_set_wifi_encryption_mode(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-               } else if (g_strcmp0(key, "Security") == 0) {
-                       GVariantIter *iter_sub = NULL;
+       if (g_strcmp0(value, "none") == 0)
+               Wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
+       else if (g_strcmp0(value, "wep") == 0)
+               Wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
+       else if (g_strcmp0(value, "tkip") == 0)
+               Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
+       else if (g_strcmp0(value, "aes") == 0)
+               Wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
+       else if (g_strcmp0(value, "mixed") == 0)
+               Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
+}
 
-                       g_variant_get(var, "as", &iter_sub);
-                       while (g_variant_iter_loop(iter_sub, "s", &value)) {
-                               if (g_strcmp0(value, "none") == 0 &&
-                                       Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
-                               else if (g_strcmp0(value, "wep") == 0 &&
-                                                Wlan->security_info.sec_mode < WLAN_SEC_MODE_WEP)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WEP;
-                               else if (g_strcmp0(value, "psk") == 0 &&
-                                                Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
-                               else if (g_strcmp0(value, "ft_psk") == 0 &&
-                                       Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_FT_PSK)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_FT_PSK;
-                               else if (g_strcmp0(value, "ieee8021x") == 0 &&
-                                                Wlan->security_info.sec_mode < WLAN_SEC_MODE_IEEE8021X)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X;
-                               else if (g_strcmp0(value, "wpa") == 0 &&
-                                                Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK;
-                               else if (g_strcmp0(value, "rsn") == 0 &&
-                                                Wlan->security_info.sec_mode < WLAN_SEC_MODE_WPA_PSK)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK;
-                               else if (g_strcmp0(value, "wps") == 0)
-                                       Wlan->security_info.wps_support = TRUE;
-                               else if (Wlan->security_info.sec_mode < WLAN_SEC_MODE_NONE)
-                                       Wlan->security_info.sec_mode = WLAN_SEC_MODE_NONE;
-                       }
-                       g_variant_iter_free(iter_sub);
-               } else if (g_strcmp0(key, "EncryptionMode") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_name(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (g_strcmp0(value, "none") == 0)
-                               Wlan->security_info.enc_mode = WLAN_ENC_MODE_NONE;
-                       else if (g_strcmp0(value, "wep") == 0)
-                               Wlan->security_info.enc_mode = WLAN_ENC_MODE_WEP;
-                       else if (g_strcmp0(value, "tkip") == 0)
-                               Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP;
-                       else if (g_strcmp0(value, "aes") == 0)
-                               Wlan->security_info.enc_mode = WLAN_ENC_MODE_AES;
-                       else if (g_strcmp0(value, "mixed") == 0)
-                               Wlan->security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED;
+       if (value != NULL)
+               g_strlcpy(Wlan->essid, value, NET_WLAN_ESSID_LEN);
+}
 
-               } else if (g_strcmp0(key, "Passpoint") == 0) {
-                       gboolean passpoint;
+static void __net_set_wifi_passphrase(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       wlan_security_info_t *security_info = &(Wlan->security_info);
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       passpoint = g_variant_get_boolean(var);
-                       if (passpoint)
-                               Wlan->passpoint = TRUE;
-                       else
-                               Wlan->passpoint = FALSE;
+       if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
+               g_strlcpy(security_info->authentication.wep.wepKey,
+                               value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
+       else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
+                               security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
+                       value != NULL)
+               g_strlcpy(security_info->authentication.psk.pskKey,
+                               value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "Strength") == 0) {
-                       Wlan->Strength = g_variant_get_byte(var);
-               } else if (g_strcmp0(key, "Name") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_bssid(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               g_strlcpy(Wlan->essid, value, NET_WLAN_ESSID_LEN);
-               } else if (g_strcmp0(key, "Passphrase") == 0) {
-                       wlan_security_info_t *security_info = &(Wlan->security_info);
-                       value = g_variant_get_string(var, NULL);
+       if (value != NULL)
+               g_strlcpy(Wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
+}
 
-                       if (security_info->sec_mode == WLAN_SEC_MODE_WEP && value != NULL)
-                               g_strlcpy(security_info->authentication.wep.wepKey,
-                                               value, NETPM_WLAN_MAX_WEP_KEY_LEN+1);
-                       else if ((security_info->sec_mode == WLAN_SEC_MODE_WPA_PSK ||
-                                               security_info->sec_mode == WLAN_SEC_MODE_WPA2_PSK) &&
-                                               value != NULL)
-                               g_strlcpy(security_info->authentication.psk.pskKey,
-                                               value, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1);
-               } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
-                       gboolean val;
+static void __net_set_wifi_eap(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       val = g_variant_get_boolean(var);
+       if (value != NULL)
+               Wlan->security_info.authentication.eap.eap_type =
+                       __convert_eap_type_from_string(value);
+}
 
-                       if (val)
-                               Wlan->PassphraseRequired = TRUE;
-                       else
-                               Wlan->PassphraseRequired = FALSE;
-               } else if (g_strcmp0(key, "BSSID") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_phase2(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               g_strlcpy(Wlan->bssid, value, NET_MAX_MAC_ADDR_LEN);
+       if (value != NULL)
+               Wlan->security_info.authentication.eap.eap_auth =
+                       __convert_eap_auth_from_string(value);
+}
 
-               } else if (g_strcmp0(key, "MaxRate") == 0) {
-                       Wlan->max_rate = (unsigned int)g_variant_get_uint32(var);
+static void __net_set_wifi_identity(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-               } else if (g_strcmp0(key, "Frequency") == 0) {
-                       Wlan->frequency = (unsigned int)g_variant_get_uint16(var);
+       if (value != NULL)
+               g_strlcpy(Wlan->security_info.authentication.eap.username,
+                               value, NETPM_WLAN_USERNAME_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "EAP") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_password(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               Wlan->security_info.authentication.eap.eap_type =
-                                               __convert_eap_type_from_string(value);
+       if (value != NULL)
+               g_strlcpy(Wlan->security_info.authentication.eap.password,
+                               value, NETPM_WLAN_PASSWORD_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "Phase2") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_ca_cert_file(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               Wlan->security_info.authentication.eap.eap_auth =
-                                               __convert_eap_auth_from_string(value);
+       if (value != NULL)
+               g_strlcpy(Wlan->security_info.authentication.eap.ca_cert_filename,
+                               value, NETPM_WLAN_CA_CERT_FILENAME_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "Identity") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_client_cert_file(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               g_strlcpy(Wlan->security_info.authentication.eap.username,
-                                               value, NETPM_WLAN_USERNAME_LEN+1);
+       if (value != NULL)
+               g_strlcpy(Wlan->security_info.authentication.eap.client_cert_filename,
+                               value, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "Password") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_private_key_file(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               g_strlcpy(Wlan->security_info.authentication.eap.password,
-                                               value, NETPM_WLAN_PASSWORD_LEN+1);
+       if (value != NULL)
+               g_strlcpy(Wlan->security_info.authentication.eap.private_key_filename,
+                               value, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "CACertFile") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static void __net_set_wifi_private_key_passphrase(GVariant *var, net_wifi_profile_info_t *Wlan)
+{
+       const gchar *value = g_variant_get_string(var, NULL);
 
-                       if (value != NULL)
-                               g_strlcpy(Wlan->security_info.authentication.eap.ca_cert_filename,
-                                               value, NETPM_WLAN_CA_CERT_FILENAME_LEN+1);
+       if (value != NULL)
+               g_strlcpy(Wlan->security_info.authentication.eap.private_key_passwd,
+                               value, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
+}
 
-               } else if (g_strcmp0(key, "ClientCertFile") == 0) {
-                       value = g_variant_get_string(var, NULL);
+static int __net_extract_wifi_info(GVariantIter *array, net_profile_info_t* ProfInfo)
+{
+       net_err_t Error = NET_ERR_NONE;
+       net_wifi_profile_info_t *Wlan = &(ProfInfo->ProfileInfo.Wlan);
+       GVariant *var = NULL;
+       const gchar *key = NULL;
 
-                       if (value != NULL)
-                               g_strlcpy(Wlan->security_info.authentication.eap.client_cert_filename,
-                                               value, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1);
+       __NETWORK_FUNC_ENTER__;
 
+       while (g_variant_iter_loop(array, "{sv}", &key, &var)) {
+               if (g_strcmp0(key, "Mode") == 0) {
+                       __net_set_wifi_mode(var, Wlan);
+               } else if (g_strcmp0(key, "Security") == 0) {
+                       __net_set_wifi_security(var, Wlan);
+               } else if (g_strcmp0(key, "EncryptionMode") == 0) {
+                       __net_set_wifi_encryption_mode(var, Wlan);
+               } else if (g_strcmp0(key, "Passpoint") == 0) {
+                       Wlan->passpoint = g_variant_get_boolean(var);
+               } else if (g_strcmp0(key, "Strength") == 0) {
+                       Wlan->Strength = g_variant_get_byte(var);
+               } else if (g_strcmp0(key, "Name") == 0) {
+                       __net_set_wifi_name(var, Wlan);
+               } else if (g_strcmp0(key, "Passphrase") == 0) {
+                       __net_set_wifi_passphrase(var, Wlan);
+               } else if (g_strcmp0(key, "PassphraseRequired") == 0) {
+                       Wlan->PassphraseRequired = g_variant_get_boolean(var);
+               } else if (g_strcmp0(key, "BSSID") == 0) {
+                       __net_set_wifi_bssid(var, Wlan);
+               } else if (g_strcmp0(key, "MaxRate") == 0) {
+                       Wlan->max_rate = (unsigned int)g_variant_get_uint32(var);
+               } else if (g_strcmp0(key, "Frequency") == 0) {
+                       Wlan->frequency = (unsigned int)g_variant_get_uint16(var);
+               } else if (g_strcmp0(key, "EAP") == 0) {
+                       __net_set_wifi_eap(var, Wlan);
+               } else if (g_strcmp0(key, "Phase2") == 0) {
+                       __net_set_wifi_phase2(var, Wlan);
+               } else if (g_strcmp0(key, "Identity") == 0) {
+                       __net_set_wifi_identity(var, Wlan);
+               } else if (g_strcmp0(key, "Password") == 0) {
+                       __net_set_wifi_password(var, Wlan);
+               } else if (g_strcmp0(key, "CACertFile") == 0) {
+                       __net_set_wifi_ca_cert_file(var, Wlan);
+               } else if (g_strcmp0(key, "ClientCertFile") == 0) {
+                       __net_set_wifi_client_cert_file(var, Wlan);
                } else if (g_strcmp0(key, "PrivateKeyFile") == 0) {
-                       value = g_variant_get_string(var, NULL);
-
-                       if (value != NULL)
-                               g_strlcpy(Wlan->security_info.authentication.eap.private_key_filename,
-                                               value, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1);
-
+                       __net_set_wifi_private_key_file(var, Wlan);
                } else if (g_strcmp0(key, "PrivateKeyPassphrase") == 0) {
-                       value = g_variant_get_string(var, NULL);
-
-                       if (value != NULL)
-                               g_strlcpy(Wlan->security_info.authentication.eap.private_key_passwd,
-                                               value, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1);
-
+                       __net_set_wifi_private_key_passphrase(var, Wlan);
                } else if (g_strcmp0(key, "Keymgmt") == 0) {
                        Wlan->security_info.keymgmt = (unsigned int)g_variant_get_uint32(var);
-
                } else
                        Error = __net_extract_common_info(key, var, ProfInfo);
        }