#define CONFIG_FILE "/opt/etc/setup-adaptor/config.json"
#define CONFIG_FOLDER "/opt/etc/setup-adaptor"
#define CONFIG_NAME "config.json"
+
+#define ENVIRONMENT_PROXY_FILE "/etc/dockzen/environment"
+
+#define FLAG_FILE_SYSTEM "/opt/etc/setup-adaptor/system_executed"
+#define FLAG_FILE_ETH "/opt/etc/setup-adaptor/ethernet_executed"
+#define FLAG_FILE_WIFI "/opt/etc/setup-adaptor/wifi_executed"
#define EVENT_NAME_MAX 256
#define EVENT_SIZE (sizeof(struct inotify_event))
#define EVENT_BUF_LEN (512 * (EVENT_SIZE + EVENT_NAME_MAX))
static void print_system_config(sa_system_s * systemData)
{
if (systemData != NULL) {
- if (systemData->proxy != NULL) {
- _D("systemData::httpProxyHost [%s]", systemData->proxy->httpProxyHost);
- _D("systemData::HttpProxyPort [%d]", systemData->proxy->httpProxyPort);
- }
+ if (systemData->proxy != NULL)
+ _D("systemData::httpProxy [%s]", systemData->proxy->httpProxy);
}
}
static int __parse_system_data(json_object * inputObj, sa_config_s * setupConfig)
{
int ret = 0;
- char *httpProxyHost = NULL;
+ char *httpProxy = NULL;
+
if (inputObj == NULL) {
_D("__parse_system_data input error");
return -1;
}
- //httpProxyHost
- httpProxyHost = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYHOST);
- if (httpProxyHost != NULL) {
+ //httpProxy
+ httpProxy = json_get_string_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXY);
+ if (httpProxy != 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));
- //httpProxyPort
- setupConfig->systemData->proxy->httpProxyPort = json_get_int_from_obj(inputObj, SA_CONFIG_NETWORKDATA_HTTPPROXYPORT);
-
+ memcpy(setupConfig->systemData->proxy->httpProxy, httpProxy, MIN(strlen(httpProxy), sizeof(setupConfig->systemData->proxy->httpProxy) - 1));
} else {
ret = -1;
_D("malloc fail setupConfig->systemData->proxy");
ret = -1;
_D("malloc fail setupConfig->systemData");
}
+ }
- free(httpProxyHost);
- httpProxyHost = NULL;
+ if (httpProxy != NULL) {
+ free(httpProxy);
+ httpProxy = NULL;
}
return ret;
}
}
-#define FLAG_FILE_SYSTEM "/opt/etc/setup-adaptor/system_executed"
-#define FLAG_FILE_ETH "/opt/etc/setup-adaptor/ethernet_executed"
-#define FLAG_FILE_WIFI "/opt/etc/setup-adaptor/wifi_executed"
-
void sa_inputfile_remove(void)
{
char buff[256];
else
return FALSE;
}
+
+sa_error_e sa_inputfile_set_proxy_env(sa_proxy_s * proxy)
+{
+ int fd = 0;
+ int len = 0;
+ sa_error_e ret = SA_ERROR_NONE;
+ char value[256] = {0, };
+ char writeBuff[512] = {0, };
+
+ if (proxy == NULL) {
+ _E("input parameter is null");
+ return SA_ERROR_INVALID_PARAMETER;
+ }
+
+ // HTTP_PROXY
+ _D("Proxy[%s]", proxy->httpProxy);
+
+ // make string
+ if (strlen(proxy->httpProxy) > 0 && strlen(proxy->httpProxy) < (sizeof(proxy->httpProxy)-1))
+ snprintf(writeBuff, strlen(SA_CONFIG_SERVICE_HTTP_PROXY) + strlen(SA_CONFIG_SERVICE_OPERATOR) + strlen(proxy->httpProxy) + 1, "%s%s%s", SA_CONFIG_SERVICE_HTTP_PROXY, SA_CONFIG_SERVICE_OPERATOR, proxy->httpProxy);
+ else {
+ ret = SA_ERROR_NOT_AVAILABLE;
+ _E("Not available to set due to buffer overflow");
+ }
+
+ //write data into file
+ if (ret == SA_ERROR_NONE) {
+ fd = open(ENVIRONMENT_PROXY_FILE, O_WRONLY | O_CREAT, 0644);
+ if (fd > 0) {
+ write(fd, writeBuff, strlen(writeBuff));
+ close(fd);
+ } else {
+ ret = SA_ERROR_NOT_AVAILABLE;
+ _E("Cannot open file");
+ }
+ }
+
+ return ret;
+}
#define SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER "primaryDnsServer"
#define SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER "secondaryDnsServer"
-#define SA_CONFIG_NETWORKDATA_HTTPPROXYHOST "httpProxyHost"
-#define SA_CONFIG_NETWORKDATA_HTTPPROXYPORT "httpProxyPort"
+#define SA_CONFIG_NETWORKDATA_HTTPPROXY "httpProxy"
+
+#define SA_CONFIG_SERVICE_ENVIRONMENTFILE "EnvironmentFile"
+#define SA_CONFIG_SERVICE_HTTP_PROXY "HTTP_PROXY"
+#define SA_CONFIG_SERVICE_OPERATOR "="
+
/**
* @brief This enum contains setup-adaptor error information
* @struct sa_proxy_s
* @brief This struct contains proxy information
*
- * The sa_network_s struct encapsulate httpproxyHost and httpProxyPort information in the one data
+ * The sa_network_s struct encapsulate httpProxy information in the one data
*
*/
typedef struct {
- char httpProxyHost[255 + 1];
- int httpProxyPort;
+ char httpProxy[255 + 1];
} sa_proxy_s;
/**
#include <stdio.h>
#include "sa_common.h"
#include "sa_types.h"
+#include "input_file.h"
#include "setup_system.h"
-static sa_error_e system_set_proxy(sa_proxy_s * info)
-{
- return SA_ERROR_NOT_SUPPORTED;
-}
-
static sa_error_e system_get_proxy(sa_proxy_s * info)
{
return SA_ERROR_NOT_SUPPORTED;
}
-static int compare_proxy_info(sa_proxy_s * devProxy, sa_proxy_s * newProxy)
-{
- // comapre proxy
- if (devProxy != NULL && newProxy != NULL) {
- if (strlen(devProxy->httpProxyHost) > 0) {
- if (strcmp(devProxy->httpProxyHost, newProxy->httpProxyHost)) {
- // proxy info is different
- return 1;
- } else {
- // Host address is the same, but port is different
- if (devProxy->httpProxyPort != newProxy->httpProxyPort)
- return 1;
- }
- }
- }
-
- return 0;
-}
-
sa_error_e sa_setup_system(sa_system_s * system)
{
sa_proxy_s *devProxy = NULL;
}
if (system->proxy != NULL) {
- ret = system_get_proxy(devProxy);
- if (ret == SA_ERROR_NONE && compare_proxy_info(devProxy, system->proxy)) {
- // set proxy
- ret = system_set_proxy(system->proxy);
- }
+ // set proxy
+ ret = sa_inputfile_set_proxy_env(system->proxy);
}
return ret;
"version":"0.1",
"wifi":{"ssid":"docker","password":"dockerdocker","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
+"httpProxy":"127.0.0.1:8080"
}
\ No newline at end of file