#define _D(fmt, arg...) LOGD(fmt, ##arg)
#define _W(fmt, arg...) LOGW(fmt, ##arg)
-#endif /* __SA_COMMON_H__ */
+#endif /* __SA_COMMON_H__ */
* @brief This function to get connection state
* @param conn_state [out] state of connection
* @param conn_type [out] type of connection
- * @return int return of function
+ * @return int return of function
*/
-int sa_network_get_state(sa_network_state_e *conn_state, sa_network_type_e *conn_type);
+int sa_network_get_state(sa_network_state_e * conn_state, sa_network_type_e * conn_type);
/**
* @fn int sa_network_activate(sa_network_activate_pararms_s *info)
* @brief This function to activate connection with info
* @param conn_state [in] activation params for network
- * @return int return of function
+ * @return int return of function
*/
-int sa_network_activate(sa_network_activate_pararms_s *info);
+int sa_network_activate(sa_network_activate_pararms_s * info);
/**
* @fn int sa_network_deactivate(void)
* @brief This function to deactivate current connection
- * @return int return of function
+ * @return int return of function
*/
int sa_network_deactivate(void);
-#endif /* __SA_NETWORK_H__ */
+#endif /* __SA_NETWORK_H__ */
* @param sa_config_s [out] fill config info
* @return int return of function
*/
-int sa_systemdata_get_config_info(char *flle, sa_config_s *config);
+int sa_systemdata_get_config_info(char *flle, sa_config_s * config);
-#endif /* __SA_SYSTEMDATA_H__ */
+#endif /* __SA_SYSTEMDATA_H__ */
#ifndef __SA_TYPES_H__
#define __SA_TYPES_H__
-
-
#define SA_CONFIG_VERSION "version"
#define SA_CONFIG_NETWORKDATA "networkData"
#define SA_CONFIG_SYSTEMDATA "systemData"
#define SA_CONFIG_NETWORKDATA_ETHERNET "ethernet"
-
#define SA_CONFIG_NETWORKDATA_ENABLED "enabled"
#define SA_CONFIG_NETWORKDATA_DHCPENABLED "dhcpEnabled"
#define SA_CONFIG_NETWORKDATA_IPADDRESS "ipAddress"
#define SA_CONFIG_NETWORKDATA_HTTPPROXYHOST "httpProxyHost"
#define SA_CONFIG_NETWORKDATA_HTTPPROXYPORT "httpProxyPort"
-
-
/**
* @brief This enum contains setup-adaptor error information
*
SA_NETWORK_TYPE_UNKNOWN, /**< UNKNOWN */
} sa_network_type_e;
-
/**
* @brief This enum contains setup-adaptor error information
*
*/
typedef enum {
SA_NETWORK_STATE_DISCONNECTED = 0, /**< Successful */
- SA_NETWORK_STATE_PROGRESSING, /**< Connecting/Association/Configuration */
+ SA_NETWORK_STATE_PROGRESSING, /**< Connecting/Association/Configuration */
SA_NETWORK_STATE_CONNECTED, /**< connected */
SA_NETWORK_STATE_UNKNOWN, /**< UNKNOWN */
} sa_network_state_e;
int httpProxyPort;
} sa_network_s;
-
/**
* @struct sa_network_activate_pararms_s
* @brief This struct contains update params for activation of network
sa_systemdata_s *systemData;
} sa_config_s;
-#endif /* __SA_TYPES_H__ */
\ No newline at end of file
+#endif /* __SA_TYPES_H__ */
#define CONFIG_FILE "/etc/setup-adaptor/config.json"
#define NETWORK_CHECK_RETRY_MAX 60
-#define EVENT_SIZE ( sizeof (struct inotify_event) )
-#define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) )
+#define EVENT_SIZE (sizeof(struct inotify_event))
+#define BUF_LEN (1024 * (EVENT_SIZE + 16))
-static int __check_config_file(char* filename)
+static int __check_config_file(char *filename)
{
int ret = 0;
- if( access(filename, F_OK) != -1 ) {
- // file exists
- ret = 1;
- }
+ if (access(filename, F_OK) != -1) {
+ // file exists
+ ret = 1;
+ }
return ret;
}
-static char* __print_connection_state(sa_network_state_e state)
+static char *__print_connection_state(sa_network_state_e state)
{
switch (state) {
case SA_NETWORK_STATE_DISCONNECTED:
}
}
-static char* __print_connection_type(sa_network_type_e type)
+static char *__print_connection_type(sa_network_type_e type)
{
switch (type) {
case SA_NETWORK_TYPE_WIFI:
return "Unknown";
}
}
-static void __print_config_network_static_info(sa_network_static_s *staticInfo)
+
+static void __print_config_network_static_info(sa_network_static_s * staticInfo)
{
if (staticInfo != NULL) {
- if (staticInfo->ipAddress != NULL) _D("static::ipAddress[%s]");
- if (staticInfo->netmask != NULL) _D("static::netmask[%s]");
- if (staticInfo->defaultGateway != NULL) _D("static::defaultGateway[%s]");
- if (staticInfo->primaryDnsServer != NULL) _D("static::primaryDnsServer[%s]");
- if (staticInfo->secondaryDnsServer != NULL) _D("static::secondaryDnsServer[%s]");
+ if (staticInfo->ipAddress != NULL)
+ _D("static::ipAddress[%s]");
+ if (staticInfo->netmask != NULL)
+ _D("static::netmask[%s]");
+ if (staticInfo->defaultGateway != NULL)
+ _D("static::defaultGateway[%s]");
+ if (staticInfo->primaryDnsServer != NULL)
+ _D("static::primaryDnsServer[%s]");
+ if (staticInfo->secondaryDnsServer != NULL)
+ _D("static::secondaryDnsServer[%s]");
}
}
-static void __print_config_info(sa_config_s* config)
+static void __print_config_info(sa_config_s * config)
{
- sa_network_s* network = NULL;
- sa_systemdata_s* systemData = NULL;
- sa_wifi_s* wifi = NULL;
- sa_eth_s* eth = NULL;
+ sa_network_s *network = NULL;
+ sa_systemdata_s *systemData = NULL;
+ sa_wifi_s *wifi = NULL;
+ sa_eth_s *eth = NULL;
if (config != NULL) {
- if (config->version != NULL) _D("Version [%s]", config->version);
+ if (config->version != NULL)
+ _D("Version [%s]", config->version);
network = config->network;
if (network != NULL) {
wifi = network->wifi;
if (wifi != NULL) {
_D("Network::wifi::enabled[%d]", wifi->enabled);
_D("Network::wifi::dhcpEnabled[%d]", wifi->dhcpEnabled);
- if (wifi->ssid != NULL) _D("Network::wifi::ssid[%s]", wifi->ssid);
- if (wifi->password != NULL) _D("Network::wifi::password[%s]", wifi->password);
+ if (wifi->ssid != NULL)
+ _D("Network::wifi::ssid[%s]", wifi->ssid);
+ if (wifi->password != NULL)
+ _D("Network::wifi::password[%s]", wifi->password);
- if (wifi->dhcpEnabled == 0) {
+ if (wifi->dhcpEnabled == 0)
__print_config_network_static_info(wifi->staticInfo);
- }
}
eth = network->eth;
_D("Network::eth::enabled[%d]", eth->enabled);
_D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
- if (eth->dhcpEnabled == 0) {
+ if (eth->dhcpEnabled == 0)
__print_config_network_static_info(wifi->staticInfo);
- }
}
- if (network->httpProxyHost != NULL) _D("Network::httpProxyHost [%s]", network->httpProxyHost);
+ if (network->httpProxyHost != NULL)
+ _D("Network::httpProxyHost [%s]", network->httpProxyHost);
_D("Network::HttpProxyHost [%d]", network->httpProxyPort);
}
systemData = config->systemData;
if (systemData != NULL) {
- if(systemData->deviceName != NULL) _D("SystemData::deviceName[%s]", systemData->deviceName);
+ if (systemData->deviceName != NULL)
+ _D("SystemData::deviceName[%s]", systemData->deviceName);
}
}
}
-static void __release_network_resource(sa_network_s* network)
+
+static void __release_network_resource(sa_network_s * network)
{
if (network != NULL) {
if (network->wifi != NULL) {
- if (network->wifi->ssid != NULL) free(network->wifi->ssid);
- if (network->wifi->password != NULL) free(network->wifi->password);
+ if (network->wifi->ssid != NULL)
+ free(network->wifi->ssid);
+ if (network->wifi->password != NULL)
+ free(network->wifi->password);
if (network->wifi->staticInfo != NULL) {
- if (network->wifi->staticInfo->ipAddress != NULL) free(network->wifi->staticInfo->ipAddress);
- if (network->wifi->staticInfo->netmask != NULL) free(network->wifi->staticInfo->netmask);
- if (network->wifi->staticInfo->defaultGateway != NULL) free(network->wifi->staticInfo->defaultGateway);
- if (network->wifi->staticInfo->primaryDnsServer != NULL) free(network->wifi->staticInfo->primaryDnsServer);
- if (network->wifi->staticInfo->secondaryDnsServer != NULL) free(network->wifi->staticInfo->secondaryDnsServer);
+ if (network->wifi->staticInfo->ipAddress != NULL)
+ free(network->wifi->staticInfo->ipAddress);
+ if (network->wifi->staticInfo->netmask != NULL)
+ free(network->wifi->staticInfo->netmask);
+ if (network->wifi->staticInfo->defaultGateway != NULL)
+ free(network->wifi->staticInfo->defaultGateway);
+ if (network->wifi->staticInfo->primaryDnsServer != NULL)
+ free(network->wifi->staticInfo->primaryDnsServer);
+ if (network->wifi->staticInfo->secondaryDnsServer != NULL)
+ free(network->wifi->staticInfo->secondaryDnsServer);
free(network->wifi->staticInfo);
}
if (network->eth != NULL) {
if (network->eth->staticInfo != NULL) {
- if (network->eth->staticInfo->ipAddress != NULL) free(network->eth->staticInfo->ipAddress);
- if (network->eth->staticInfo->netmask != NULL) free(network->eth->staticInfo->netmask);
- if (network->eth->staticInfo->defaultGateway != NULL) free(network->eth->staticInfo->defaultGateway);
- if (network->eth->staticInfo->primaryDnsServer != NULL) free(network->eth->staticInfo->primaryDnsServer);
- if (network->eth->staticInfo->secondaryDnsServer != NULL) free(network->eth->staticInfo->secondaryDnsServer);
+ if (network->eth->staticInfo->ipAddress != NULL)
+ free(network->eth->staticInfo->ipAddress);
+ if (network->eth->staticInfo->netmask != NULL)
+ free(network->eth->staticInfo->netmask);
+ if (network->eth->staticInfo->defaultGateway != NULL)
+ free(network->eth->staticInfo->defaultGateway);
+ if (network->eth->staticInfo->primaryDnsServer != NULL)
+ free(network->eth->staticInfo->primaryDnsServer);
+ if (network->eth->staticInfo->secondaryDnsServer != NULL)
+ free(network->eth->staticInfo->secondaryDnsServer);
free(network->eth->staticInfo);
- }
+ }
}
- if (network->httpProxyHost != NULL) free(network->httpProxyHost);
+ if (network->httpProxyHost != NULL)
+ free(network->httpProxyHost);
free(network);
}
}
-static void __release_config_resource(sa_config_s* config, sa_network_activate_pararms_s* activateParams) {
-
+static void __release_config_resource(sa_config_s * config, sa_network_activate_pararms_s * activateParams)
+{
+
if (config != NULL) {
- if (config->version != NULL) {
+ if (config->version != NULL)
free(config->version);
- }
- if (config->network != NULL) {
+ if (config->network != NULL)
__release_network_resource(config->network);
- }
if (config->systemData != NULL) {
- if (config->systemData->deviceName != NULL) {
+ if (config->systemData->deviceName != NULL)
free(config->systemData->deviceName);
- }
free(config->systemData);
}
free(config);
}
- if (activateParams != NULL) {
+ if (activateParams != NULL)
__release_network_resource(activateParams->network);
- }
}
-static void* __config_event_loop(void* arg)
+
+static void *__config_event_loop(void *arg)
{
int fd;
int wd;
- char* config_path = NULL;
+ char *config_path = NULL;
char buffer[BUF_LEN];
- _D("__config_event_loop start\n");
-
+ _D("__config_event_loop start\n");
+
config_path = (char *)arg;
if (config_path != NULL) {
return NULL;
}
- fd = inotify_init();
-
- if (fd < 0) {
- _E("inotify_init error");
- return NULL;
- }
+ fd = inotify_init();
+
+ if (fd < 0) {
+ _E("inotify_init error");
+ return NULL;
+ }
wd = inotify_add_watch(fd, config_path, IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO | IN_MOVE_SELF);
-
- while(1) {
+
+ while (1) {
int length, i = 0;
length = read(fd, buffer, BUF_LEN);
- if (length < 0) {
+ if (length < 0)
perror("read");
- }
while (i < length) {
- struct inotify_event *event = (struct inotify_event *) &buffer[i];
- _D("[debug] wd=%d mask=%d cookie=%d len=%d dir=%s\n", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR)?"yes":"no");
+ struct inotify_event *event = (struct inotify_event *)&buffer[i];
+ _D("[debug] wd=%d mask=%d cookie=%d len=%d dir=%s\n", event->wd, event->mask, event->cookie, event->len, (event->mask & IN_ISDIR) ? "yes" : "no");
if (event->len) {
if (event->mask & IN_CREATE) {
- if (event->mask & IN_ISDIR) {
- _D("The directory %s was created.\n", event->name);
- } else {
+ if (event->mask & IN_ISDIR)
+ _D("The directory %s was created.\n", event->name);
+ else
_D("The file %s was created.\n", event->name);
- }
} else if (event->mask & IN_DELETE) {
- if (event->mask & IN_ISDIR) {
- _D("The directory %s was deleted.\n", event->name);
- } else {
+ if (event->mask & IN_ISDIR)
+ _D("The directory %s was deleted.\n", event->name);
+ else
_D("The file %s was deleted.\n", event->name);
- }
} else if (event->mask & IN_MODIFY) {
- if (event->mask & IN_ISDIR) {
+ if (event->mask & IN_ISDIR)
_D("The directory %s was modified.\n", event->name);
- } else {
+ else
_D("The file %s was modified.\n", event->name);
- }
} else if (event->mask & IN_MOVED_FROM || event->mask & IN_MOVED_TO || event->mask & IN_MOVE_SELF) {
- if (event->mask & IN_ISDIR) {
+ if (event->mask & IN_ISDIR)
_D("The directory %s was moved.\n", event->name);
- } else {
+ else
_D("The file %s was moved.\n", event->name);
- }
}
}
return NULL;
}
+
static sa_error_e __init_event_listener(void)
{
pthread_t p_thread;
// register file change event
// Start thread to create in order to receive event
-
if (pthread_create(&p_thread, NULL, &__config_event_loop, CONFIG_FILE) < 0) {
_E("__init_event_listener create error");
return SA_ERROR_UNKNOWN;
int main(int argc, char *argv[])
{
- sa_config_s* config = NULL;
- sa_network_activate_pararms_s* activateParams = NULL;
+ sa_config_s *config = NULL;
+ sa_network_activate_pararms_s *activateParams = NULL;
sa_network_state_e conn_state = SA_NETWORK_STATE_DISCONNECTED;
sa_network_type_e conn_type;
sa_error_e ret = SA_ERROR_NONE;
int index = 0;
_D("start setup-adaptor");
- //Check Config file
-
+ //Check Config file
+
if (__check_config_file(CONFIG_FILE)) {
-
- // 1.Get config info from interface
- // memory will be allocated from interface layer
- ret = sa_systemdata_get_config_info(CONFIG_FILE, config);
+
+ // 1.Get config info from interface
+ // memory will be allocated from interface layer
+ ret = sa_systemdata_get_config_info(CONFIG_FILE, config);
if (ret == SA_ERROR_NONE) {
_D("Success to get config");
// check config info
_D("Config value");
__print_config_info(config);
}
- }
- else {
+ } else {
_E("sa_systemdata_get_config_info return error [%d]", ret);
}
-
- // 2.Check Network State - ethernet cable is attached or not, wifi state is connected
- /* Check network state whether is alive or not
- Even though connection is not established, need to wait for a while
- */
+
+ // 2.Check Network State - ethernet cable is attached or not, wifi state is connected
+ /* Check network state whether is alive or not
+ Even though connection is not established, need to wait for a while
+ */
if (ret == SA_ERROR_NONE) {
for (index = 0; index < NETWORK_CHECK_RETRY_MAX; index++) {
ret = sa_network_get_state(&conn_state, &conn_type);
if (conn_state == SA_NETWORK_STATE_CONNECTED) {
_D("Network is connected : Type[%d][%s]", conn_type, __print_connection_type(conn_type));
break;
- }
- else {
+ } else {
_D("conn_state [%d][%s]", conn_state, __print_connection_state(conn_state));
}
- }
- else {
- _E("sa_network_get_state return error [%d]", ret);
- break;
- }
- sleep(1);
+ } else {
+ _E("sa_network_get_state return error [%d]", ret);
+ break;
+ }
+ sleep(1);
}
}
-
-
- // 3.Try to connect with config value
- if (ret == SA_ERROR_NONE && conn_state != SA_NETWORK_STATE_CONNECTED) {
- ret = sa_network_activate(activateParams);
- }
-
- // 4.Register file change event
- if (ret == SA_ERROR_NONE) {
- // register file change event
- // Start thread to create in order to receive event
- __init_event_listener();
- }
- else {
+
+ // 3.Try to connect with config value
+ if (ret == SA_ERROR_NONE && conn_state != SA_NETWORK_STATE_CONNECTED)
+ ret = sa_network_activate(activateParams);
+ // 4.Register file change event
+ if (ret == SA_ERROR_NONE) {
+ // register file change event
+ // Start thread to create in order to receive event
+ __init_event_listener();
+ } else {
_E("sa_network_activate return error [%d]", ret);
}
- /* 5.Save System Data(device name)
- - TBD
- */
+ /* 5.Save System Data(device name)
+ - TBD
+ */
- // 6.free resource
- __release_config_resource(config, activateParams);
- }
- else {
- /* If the file is not existed, it would be enabled softAP
- - TBD
- */
+ // 6.free resource
+ __release_config_resource(config, activateParams);
+ } else {
+ /* If the file is not existed, it would be enabled softAP
+ - TBD
+ */
- _D("config file is not existed");
+ _D("config file is not existed, setup-adaptor exit");
}
-
+
return 0;
}
#include "sa_types.h"
#include "sa_network.h"
-
-int sa_network_get_state(sa_network_state_e* conn_state, sa_network_type_e* conn_type)
+int sa_network_get_state(sa_network_state_e * conn_state, sa_network_type_e * conn_type)
{
sa_error_e ret = SA_ERROR_NONE;
// check network state(eth/wifi)
return ret;
}
-int sa_network_activate(sa_network_activate_pararms_s* info)
+int sa_network_activate(sa_network_activate_pararms_s * info)
{
sa_error_e ret = SA_ERROR_NONE;
sa_error_e ret = SA_ERROR_NONE;
return ret;
-}
\ No newline at end of file
+}
#include "sa_types.h"
#include "sa_systemdata.h"
-static char* json_getString(char* data, char* key)
+static char *json_getString(char *data, char *key)
{
struct json_object *inputObj;
struct json_object *bodyObj;
enum json_type type;
- char *ret_buf=NULL;
+ char *ret_buf = NULL;
const char *buf = NULL;
int i, j = 0;
inputObj = json_tokener_parse(data);
type = json_object_get_type(inputObj);
- if(type == json_type_object) {
- if(json_object_object_get_ex(inputObj, key, &bodyObj)) {
+ if (type == json_type_object) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
buf = json_object_to_json_string_ext(bodyObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
- ret_buf = malloc(strlen(buf) -1);
+ ret_buf = malloc(strlen(buf) - 1);
if (ret_buf != NULL) {
- memset(ret_buf, 0x00, strlen(buf) -1); // "<-- exclude
- for(i = 1, j = 0; i<strlen(buf)-1; i++) { // "\ <-- exclude
- if(buf[i] == '\\')
+ memset(ret_buf, 0x00, strlen(buf) - 1); // "<-- exclude
+ for (i = 1, j = 0; i < strlen(buf) - 1; i++) { // "\ <-- exclude
+ if (buf[i] == '\\')
continue;
ret_buf[j++] = buf[i];
}
}
- }
- else {
+ } else {
_E("ERROR : no data");
}
}
return ret_buf;
}
-static int json_getNumber(char* data, char* key)
+static int json_getNumber(char *data, char *key)
{
struct json_object *inputObj;
struct json_object *bodyObj;
enum json_type type;
- int ret_num=0;
+ int ret_num = 0;
inputObj = json_tokener_parse(data);
type = json_object_get_type(inputObj);
- if(type == json_type_object)
- {
- if(json_object_object_get_ex(inputObj, key, &bodyObj))
- {
+ if (type == json_type_object) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
ret_num = json_object_get_int(bodyObj);
- }
- else
- {
+ } else {
_E("ERROR : no data");
}
return ret_num;
}
-
-static char* json_getObject(char *data, char *key)
+static char *json_getObject(char *data, char *key)
{
struct json_object *inputObj = NULL;
struct json_object *bodyObj = NULL;
inputObj = json_tokener_parse(data);
if (inputObj != NULL) {
- if(json_object_object_get_ex(inputObj, key, &bodyObj)) {
- if(json_object_get_type(bodyObj) == json_type_object) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
+ if (json_object_get_type(bodyObj) == json_type_object) {
buf = json_object_to_json_string_ext(bodyObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
- ret_buf = (char *)malloc(strlen(buf)+1);
+ ret_buf = (char *)malloc(strlen(buf) + 1);
if (ret_buf != NULL) {
- memset(ret_buf, 0x00, strlen(buf)+1);
+ memset(ret_buf, 0x00, strlen(buf) + 1);
memcpy(ret_buf, buf, strlen(buf));
}
}
return ret_buf;
}
-static char* json_getArray(char *data, char *key)
+static char *json_getArray(char *data, char *key)
{
struct json_object *inputObj, *bodyObj;
enum json_type type;
- const char * buf = NULL;
- char * ret_buf = NULL;
+ const char *buf = NULL;
+ char *ret_buf = NULL;
inputObj = json_tokener_parse(data);
type = json_object_get_type(inputObj);
- if(type == json_type_object)
- {
- if(json_object_object_get_ex(inputObj, key, &bodyObj))
- {
+ if (type == json_type_object) {
+ if (json_object_object_get_ex(inputObj, key, &bodyObj)) {
type = json_object_get_type(bodyObj);
- if(type == json_type_array)
- {
+ if (type == json_type_array) {
buf = json_object_to_json_string_ext(bodyObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
- ret_buf = malloc(strlen(buf) +1);
- if(ret_buf != NULL)
- {
+ ret_buf = malloc(strlen(buf) + 1);
+ if (ret_buf != NULL) {
memset(ret_buf, 0x00, strlen(buf) + 1);
memcpy(ret_buf, buf, strlen(buf));
}
inputObj = json_tokener_parse(data);
type = json_object_get_type(inputObj);
- if(type == json_type_array)
- {
+ if (type == json_type_array) {
cnt = json_object_array_length(inputObj);
}
int i, j = 0;
inputObj = json_tokener_parse(data);
- if(json_object_object_get_ex(inputObj, arrayKey, &arrayObj)) {
+ if (json_object_object_get_ex(inputObj, arrayKey, &arrayObj)) {
elementObj = json_object_array_get_idx(arrayObj, arrayIndex);
if (json_object_object_get_ex(elementObj, key, &bodyObj)) {
buf = json_object_to_json_string_ext(bodyObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
- ret_buf = malloc(strlen(buf) -1);
- if(ret_buf != NULL) {
- memset(ret_buf, 0x00, strlen(buf) -1); // "<-- exclude
- for(i = 1, j = 0; i<strlen(buf)-1; i++) { // "\ <-- exclude
- if(buf[i] == '\\')
+ ret_buf = malloc(strlen(buf) - 1);
+ if (ret_buf != NULL) {
+ memset(ret_buf, 0x00, strlen(buf) - 1); // "<-- exclude
+ for (i = 1, j = 0; i < strlen(buf) - 1; i++) { // "\ <-- exclude
+ if (buf[i] == '\\')
continue;
ret_buf[j++] = buf[i];
}
}
- }
- else {
+ } else {
_E("ERROR : no data");
}
json_object_put(inputObj);
- }else {
+ } else {
_E("ERROR : not found(%s)", arrayKey);
- }
+ }
return ret_buf;
}
-static char* json_getStringfromObj(json_object *inputObj, char *key)
+static char *json_getStringfromObj(json_object * inputObj, char *key)
{
const char *buf = NULL;
char *ret_buf = NULL;
json_object *elementObj = NULL;
int i = 0, j = 0;
- if(json_object_object_get_ex(inputObj, key, &elementObj))
- {
+ if (json_object_object_get_ex(inputObj, key, &elementObj)) {
buf = json_object_to_json_string_ext(elementObj, JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY);
- ret_buf = malloc(strlen(buf)-1);
- if(ret_buf != NULL) {
- memset(ret_buf, 0x00, strlen(buf)-1); // "<-- exclude
- for(i = 1, j = 0; i < strlen(buf)-1; i++) { // "\ <-- exclude
- if(buf[i] == '\\')
+ ret_buf = malloc(strlen(buf) - 1);
+ if (ret_buf != NULL) {
+ memset(ret_buf, 0x00, strlen(buf) - 1); // "<-- exclude
+ for (i = 1, j = 0; i < strlen(buf) - 1; i++) { // "\ <-- exclude
+ if (buf[i] == '\\')
continue;
ret_buf[j++] = buf[i];
}
return ret_buf;
}
-static int __parse_networkData(char* data, sa_network_s* network)
+static int __parse_networkData(char *data, sa_network_s * network)
{
- 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;
+ 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;
-
+ char *ipAddress = NULL;
+ char *netmask = NULL;
+ char *defaultGateway = NULL;
+ char *primaryDnsServer = NULL;
+ char *secondaryDnsServer = NULL;
+
configObj = json_tokener_parse(data);
- if(configObj != NULL) {
-
+ 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;
- }
- }
- }
- }*/
+ 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;
return 0;
}
-static int __parse_config(char *file, sa_config_s* config)
+static int __parse_config(char *file, sa_config_s * config)
{
- struct json_object* configObj = NULL;
+ struct json_object *configObj = NULL;
char *json_data = NULL;
- char* version = NULL;
- sa_network_s* network = NULL;
+ char *version = NULL;
+ sa_network_s *network = NULL;
int read_len = 0;
int fd = 0;
int len = 0;
fd = open(file, O_RDONLY);
- if(fd)
- {
+ if (fd) {
len = lseek(fd, 0L, SEEK_END) - 1;
lseek(fd, 0L, SEEK_SET);
json_data = (char *)malloc(len + 1);
- if(json_data) {
+ 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");
- */
+ /* 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);
}
close(fd);
return 0;
}
-int sa_systemdata_get_config_info(char* file, sa_config_s* config)
+int sa_systemdata_get_config_info(char *file, sa_config_s * config)
{
sa_error_e ret = SA_ERROR_NONE;
_D("there is no config file");
return SA_ERROR_UNKNOWN;
}
-
// parsing and fill into struct
ret = __parse_config(file, config);
if (ret != 0) {
_D("ret:DOCKER_STATUS_UNKNOWN --> exit for user recovery");
return -1;
}
-
// parsing
// fill the info into struct
return ret;
-}
\ No newline at end of file
+}