Change parsing structure
authornshero.lee <nshero.lee@samsung.com>
Wed, 20 Dec 2017 11:09:27 +0000 (20:09 +0900)
committernshero.lee <nshero.lee@samsung.com>
Wed, 20 Dec 2017 11:09:27 +0000 (20:09 +0900)
Signed-off-by: nshero.lee <nshero.lee@samsung.com>
src/input_file.c
src/setup_network.c

index 8fc83505c604e298b484fe0919bef850b8643436..e8c4f42410425f4d246e7972e294d9a1a103467c 100644 (file)
@@ -336,46 +336,51 @@ static int __parse_network_wifi(json_object *inputObj, sa_wifi_s *wifi)
        return ret;
 }
 
-static int __parse_network_data(json_object *inputObj, sa_network_s *network)
+static int __parse_network_data(json_object *inputObj, sa_config_s *setupConfig)
 {
        struct json_object *wifiObj = NULL;
        struct json_object *ethernetObj = NULL;
        int wifiRet = 0, ethRet = 0;
 
-       if (inputObj == NULL || network == NULL) {
+       if (inputObj == NULL || setupConfig == NULL) {
                _E("__parse_network_data input error");
                return -1;
        }
 
-       //parse wifi
-       if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_WIFI, &wifiObj)) {
-               if (json_object_get_type(wifiObj) == json_type_object) {
-                       // malloc
-                       network->wifi = (sa_wifi_s *)malloc(sizeof(sa_wifi_s));
-                       if (network->wifi != NULL) {
-                               wifiRet = __parse_network_wifi(wifiObj, network->wifi);
-                       } else {
-                               _E("network->wifi malloc fail");
+       setupConfig->networkData = (sa_network_s *)malloc(sizeof(sa_network_s));
+       if (setupConfig->networkData != NULL) {
+               //parse wifi
+               if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_WIFI, &wifiObj)) {
+                       if (json_object_get_type(wifiObj) == json_type_object) {
+                               // malloc
+                               setupConfig->networkData->wifi = (sa_wifi_s *)malloc(sizeof(sa_wifi_s));
+                               if (setupConfig->networkData->wifi != NULL) {
+                                       wifiRet = __parse_network_wifi(wifiObj, setupConfig->networkData->wifi);
+                               } else {
+                                       _E("network->wifi malloc fail");
+                               }
                        }
                }
-       }
 
-       //parse eth
-       if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_ETHERNET, &ethernetObj)) {
-               if (json_object_get_type(ethernetObj) == json_type_object) {
-                       // malloc
-                       network->eth = (sa_eth_s *)malloc(sizeof(sa_eth_s));
-                       if (network->eth != NULL) {
-                               ethRet = __parse_network_eth(ethernetObj, network->eth);
-                       } else {
-                               _E("network->eth malloc fail"); 
+               //parse eth
+               if (json_object_object_get_ex(inputObj, SA_CONFIG_NETWORKDATA_ETHERNET, &ethernetObj)) {
+                       if (json_object_get_type(ethernetObj) == json_type_object) {
+                               // malloc
+                               setupConfig->networkData->eth = (sa_eth_s *)malloc(sizeof(sa_eth_s));
+                               if (setupConfig->networkData->eth != NULL) {
+                                       ethRet = __parse_network_eth(ethernetObj, setupConfig->networkData->eth);
+                               } else {
+                                       _E("network->eth malloc fail");
+                               }
                        }
                }
+       } else {
+               _E("malloc fail etupConfig->networkData");
        }
 
        // if both of network interfaces are failed, it would return -1
        if (wifiRet != 0 && ethRet != 0) {
-               _E("__parse_network_data fail");        
+               _E("__parse_network_data fail");
                return -1;
        }
        
@@ -383,18 +388,40 @@ static int __parse_network_data(json_object *inputObj, sa_network_s *network)
 }
 
 
-static int __parse_system_data(json_object *inputObj, sa_system_s *system)
+static int __parse_system_data(json_object *inputObj, sa_config_s *setupConfig)
 {
        int ret = 0;
-       if (inputObj == NULL || system == NULL) {
+       char *httpProxyHost = NULL;
+       int httpProxyPort = 0;
+       if (inputObj == NULL || setupConfig == NULL) {
                _E("__parse_system_data input error");
                return -1;
        }
+       
+       //httpProxyHost
+       httpProxyHost = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYHOST);
+       if (httpProxyHost != NULL) {
+               setupConfig->systemData = (sa_system_s *)malloc(sizeof(sa_system_s));
+               if (setupConfig->systemData != NULL) {
+                       setupConfig->systemData->proxy = (sa_proxy_s *)malloc(sizeof(sa_proxy_s));
+                       if (setupConfig->systemData->proxy != NULL) {
+                               memcpy(setupConfig->systemData->proxy->httpProxyHost, httpProxyHost, MIN(strlen(httpProxyHost), sizeof(setupConfig->systemData->proxy->httpProxyHost)-1));
+                               free(httpProxyHost);
+                               httpProxyHost = NULL;
+                               
+                               //httpProxyPort
+                               httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
+                       } else {
+                               ret = -1;
+                               _E("malloc fail setupConfig->systemData->proxy");
+                       }
+               } else {
+                       ret = -1;
+                       _E("malloc fail setupConfig->systemData");
+               }
+       }
 
-       // parse proxy
-       ret = __parse_system_proxy(inputObj, system);
-
-       return ret ;
+       return ret;
 }
 
 
@@ -421,8 +448,6 @@ static int __parse_version(json_object *inputObj, sa_config_s *setupConfig)
 static int __parse_config(char *file, sa_config_s *setupConfig)
 {
        struct json_object *configObj = NULL;
-       struct json_object *networkObj = NULL;
-       struct json_object *systemObj = NULL;
        char *jsonData = NULL;
        int readLen = 0;
        int fd = 0;
@@ -446,27 +471,12 @@ static int __parse_config(char *file, sa_config_s *setupConfig)
                                if (configObj != NULL) {
                                        // parse version
                                        ret = __parse_version(configObj, setupConfig);
-
-                                       // parse system data
                                        if (ret == 0) {
-                                               if (json_object_object_get_ex(configObj, SA_CONFIG_SYSTEMDATA, &systemObj)) {
-                                                       if (json_object_get_type(systemObj) == json_type_object) {
-                                                               // malloc
-                                                               setupConfig->systemData = (sa_system_s *)malloc(sizeof(sa_system_s));
-                                                               ret = __parse_system_data(systemObj, setupConfig->systemData);
-                                                       }
-                                               }
+                                               ret = __parse_system_data(configObj, setupConfig);
                                        }
-
-                                       // parse network data
+                                       
                                        if (ret == 0) {
-                                               if (json_object_object_get_ex(configObj, SA_CONFIG_NETWORKDATA, &networkObj)) {
-                                                       if (json_object_get_type(networkObj) == json_type_object) {
-                                                               // malloc
-                                                               setupConfig->networkData = (sa_network_s *)malloc(sizeof(sa_network_s));
-                                                               ret = __parse_network_data(networkObj, setupConfig->networkData);
-                                                       }
-                                               }                                               
+                                               ret = __parse_network_data(configObj, setupConfig);
                                        }
                                } else {
                                        ret = -1;
@@ -529,4 +539,7 @@ sa_error_e sa_inputfile_register_cb(file_state_cb callback)
        }
 
        return ret;
-}
\ No newline at end of file
+}
+
+/* Sample Config */
+/*{"version":"0.1","wifi":{"ssid":"XXXX","password":"XXXXXX","enabled":true,"dhcpEnabled":true,"ipAddress":"127.0.0.1","netmask":"127.0.0.1","defaultGateway":"127.0.0.1","primaryDNSServer":"127.0.0.1","secondaryDNSServer":"127.0.0.1"},"ethernet":{"enabled":false,"dhcpEnabled":true,"ipAddress":"127.0.0.1","netmask":"127.0.0.1","defaultGateway":"127.0.0.1","primaryDnsServer":"127.0.0.1","secondaryDnsServer":"127.0.0.1"},"httpProxyHost":"127.0.0.1","httpProxyPort":8080}*/
\ No newline at end of file
index c7d81065f59e7e324135a962761fe3fcd8ebf336..b4c04e5094babe60bf8b858b06daee75460fee61 100644 (file)
@@ -48,6 +48,7 @@ static int __get_setup_network_wifi_state(void)
 static void __set_setup_network_wifi_password(char *password)
 {
        if (strcmp(wifi_password, password)) {
+               memset(wifi_password, 0x00, sizeof(wifi_password));
                memcpy(wifi_password, password, MIN(strlen(password), sizeof(wifi_password)-1));
        }
 }
@@ -367,21 +368,10 @@ static int __connect_ethernet(sa_eth_s *info)
        if (info == NULL) {
                return -1;
        }
-
-       err = connection_create(&connection);
-       if (CONNECTION_ERROR_NONE == err) {
-               // check network cable
-               // check dhcp / static
-               // set ip
-               rv = connection_destroy(connection);
-               if (rv != CONNECTION_ERROR_NONE) {
-                       ret = SA_ERROR_UNKNOWN;
-                       printf("Fail to get network state [%s]\n", __print_error(rv));
-               }
-
-       } else {
-               _E("fail creation connection handler [%s]\n", __print_error(err));
-       }
+       
+       // check network cable
+       // check dhcp / static
+       // set ip
 
        return 0;
 }