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, ðernetObj)) {
- 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, ðernetObj)) {
+ 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;
}
}
-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;
}
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;
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;
}
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