return ret_buf;
}
-static char *json_getStringfromObj(json_object * inputObj, char *key)
+static int json_get_boolean_from_obj(json_object *inputObj, char *key)
+{
+ struct json_object *bodyObj;
+ enum json_type type;
+ int ret = 0;
+
+ type = json_object_get_type(inputObj);
+
+ if (type == json_type_object) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
+ ret = json_object_get_boolean(bodyObj);
+ } else {
+ _E("ERROR : no data");
+
+ }
+ }
+ json_object_put(inputObj);
+ return ret;
+}
+
+static char *json_get_string_from_obj(json_object *inputObj, char *key)
{
const char *buf = NULL;
char *ret_buf = NULL;
return ret_buf;
}
-static int __parse_networkData(char *data, sa_network_s * network)
+static int __parse_network_eth(json_object *inputObj, sa_eth_s *eth)
{
- struct json_object *configObj = NULL;
- struct json_object *networkObj = NULL;
- struct json_object *wifiObj = NULL;
- struct json_object *ethernetObj = NULL;
-
- char *ssid = NULL;
- char *password = NULL;
- int enabled = 0;
- int dhcpEnabled = 0;
- char *ipAddress = NULL;
- char *netmask = NULL;
- char *defaultGateway = NULL;
- char *primaryDnsServer = NULL;
- char *secondaryDnsServer = NULL;
-
- configObj = json_tokener_parse(data);
-
- if (configObj != NULL) {
-
- /*status = json_getStringfromObj(configObj, "Action");
- if(status != NULL) {
- memcpy(task_info->status, status, strlen(status)+1);
- if(status != NULL) {
- free(status);
- status = NULL;
- }
- }
- if(json_object_object_get_ex(eventObj, "Actor", &actorObj)) {
- if(json_object_object_get_ex(actorObj, "Attributes", &attributeObj)) {
- name = dockerform_json_getStringfromObj(attributeObj, "com.docker.swarm.service.name");
- if(name != NULL) {
- memcpy(task_info->id, name, strlen(name)+1);
- if(name != NULL) {
- free(name);
- name = NULL;
- }
- }
- }
- } */
- } else {
- _D("eventObj is null");
- return -1;
+}
+
+static int __parse_network_wifi(json_object *inputObj, sa_wifi_s *wifi)
+{
+
+}
+
+static int __parse_network_data(char *data, sa_network_s *network)
+{
+
+ return 0;
+}
+
+
+static int __parse_system_data(char *data, sa_systemdata_s *system)
+{
+ return 0;
+}
+
+
+static int __parse_version(json_object *inputObj, sa_config_s *setupConfig)
+{
+ char *version = NULL;
+
+ if (inputObj == NULL || setupConfig == NULL) {
+ return -1;
}
- _D("dockerform_parse_container_info end");
+ version = json_get_string_from_obj(inputObj, SA_CONFIG_VERSION);
+
+ if (version != NULL) {
+ memcpy(setupConfig->version, version, MIN(strlen(version), sizeof(setupConfig->version)-1));
+ free(version);
+ version = NULL;
+ }
return 0;
}
-static int __parse_config(char *file, sa_config_s * config)
+static int __parse_config(char *file, sa_config_s *setupConfig)
{
struct json_object *configObj = NULL;
- char *json_data = NULL;
- char *version = NULL;
- sa_network_s *network = NULL;
- int read_len = 0;
+ char *jsonData = NULL;
+ int readLen = 0;
int fd = 0;
int len = 0;
+ int ret = 0;
fd = open(file, O_RDONLY);
if (fd) {
- len = lseek(fd, 0L, SEEK_END) - 1;
-
- lseek(fd, 0L, SEEK_SET);
- json_data = (char *)malloc(len + 1);
- if (json_data) {
- memset(json_data, 0x00, len + 1);
-
- read_len = read(fd, json_data, len);
-
- _D("JSON full data[%s]", json_data);
-
- /* configObj = json_tokener_parse(json_data);
- if (configObj != NULL) {
-
- // version
- version = json_getStringfromObj(configObj, SA_CONFIG_VERSION);
-
- if(version != NULL) {
- memcpy(config->version, version, strlen(version)+1);
- if(version != NULL) {
- free(status);
- status = NULL;
- }
- }
- }
-
- // network
- config->network =
- // systemData
- config->systemData =
- container_create_info_h->name = json_getString(json_data, "name");
- container_create_info_h->image = json_getString(json_data, "image");
- container_create_info_h->entry_cmd = json_getString(json_data, "entry_cmd");
- container_create_info_h->volume = json_getString(json_data, "volume");
- container_create_info_h->net_mode = json_getString(json_data, "net_mode");
- container_create_info_h->privileged = json_getNumber(json_data, "privileged");
- container_create_info_h->enable = json_getNumber(json_data, "enable");
- */
- free(json_data);
+ len = lseek(fd, 0L, SEEK_END);
+
+ if (len > 0) {
+ lseek(fd, 0L, SEEK_SET);
+ jsonData = (char *)malloc(len + 1);
+ if (jsonData != NULL) {
+ memset(jsonData, 0x00, len + 1);
+ readLen = read(fd, jsonData, len);
+ _D("JSON full data[%s]", jsonData);
+
+ configObj = json_tokener_parse(jsonData);
+
+ if (configObj != NULL) {
+ // parse version
+ ret = __parse_version(configObj, setupConfig);
+
+ // parse system data
+ if (ret == 0) {
+ ret = __parse_system_data(configObj, setupConfig->systemData);
+ }
+
+ // parse network data
+ if (ret == 0) {
+ ret = __parse_network_data(configObj, setupConfig->networkData);
+ }
+ } else {
+ ret = -1;
+ _E("ConfigObj is not existed");
+ }
+
+ free(jsonData);
+ } else {
+ ret = -1;
+ _E("memory allocation fail for jsonData");
+ }
}
+
close(fd);
+ } else {
+ ret = -1;
+ _E("config file can't be opened");
}
- return 0;
+ return ret;
}
int sa_systemdata_get_config_info(char *file, sa_config_s * config)