Skeleton developement v0.1-Skeleton_Developement
authornshero.lee <nshero.lee@samsung.com>
Mon, 20 Nov 2017 07:28:42 +0000 (16:28 +0900)
committernshero.lee <nshero.lee@samsung.com>
Mon, 20 Nov 2017 07:28:42 +0000 (16:28 +0900)
Signed-off-by: nshero.lee <nshero.lee@samsung.com>
14 files changed:
CMakeLists.txt [new file with mode: 0644]
LICENSE.APLv2 [new file with mode: 0644]
include/sa_common.h [new file with mode: 0644]
include/sa_network.h [new file with mode: 0644]
include/sa_systemdata.h [new file with mode: 0644]
include/sa_types.h [new file with mode: 0644]
packaging/setup-adaptor.manifest [new file with mode: 0644]
packaging/setup-adaptor.service [new file with mode: 0644]
packaging/setup-adaptor.spec [new file with mode: 0644]
src/CMakeLists.txt [new file with mode: 0644]
src/sa_manager.c [new file with mode: 0644]
src/sa_network.c [new file with mode: 0644]
src/sa_systemdata.c [new file with mode: 0644]
test/sa_test.c [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..440b785
--- /dev/null
@@ -0,0 +1,11 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(setup-adaptor C)
+
+INCLUDE(FindPkgConfig)
+
+SET(EXTRA_CFLAGS "-Wall -Werror-implicit-function-declaration -fvisibility=hidden")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+SET(SETUP-ADAPTOR ${PROJECT_NAME})
+
+ADD_SUBDIRECTORY(src)
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..6b524fa
--- /dev/null
@@ -0,0 +1,204 @@
+Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
diff --git a/include/sa_common.h b/include/sa_common.h
new file mode 100644 (file)
index 0000000..4849229
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SA_COMMON_H__
+#define __SA_COMMON_H__
+
+#include <unistd.h>
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "SETUP-ADAPTOR"
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+
+#endif /* __SA_COMMON_H__ */
diff --git a/include/sa_network.h b/include/sa_network.h
new file mode 100644 (file)
index 0000000..6a74be3
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SA_NETWORK_H__
+#define __SA_NETWORK_H__
+
+/**
+ * @fn        int sa_network_get_state(int conn_state)
+ * @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
+ */
+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
+ */
+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
+ */
+int sa_network_deactivate(void);
+
+#endif /* __SA_NETWORK_H__ */
diff --git a/include/sa_systemdata.h b/include/sa_systemdata.h
new file mode 100644 (file)
index 0000000..21e615c
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef __SA_SYSTEMDATA_H__
+#define __SA_SYSTEMDATA_H__
+
+/**
+ * @fn        int sa_systemdata_get_config_info(char *path, sa_config_s *config)
+ * @brief     This function to get config info
+ * @param     file                                 [in] config path and name
+ * @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);
+
+#endif /* __SA_SYSTEMDATA_H__ */
diff --git a/include/sa_types.h b/include/sa_types.h
new file mode 100644 (file)
index 0000000..4595736
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#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_WIFI                                     "wifi"
+#define SA_CONFIG_NETWORKDATA_WIFI_SSID                                "ssid"
+#define SA_CONFIG_NETWORKDATA_WIFI_PASSWORD                    "password"
+
+#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_NETMASK                          "netmask"
+#define SA_CONFIG_NETWORKDATA_DEFAULTGATEWAY           "defaultGateway"
+#define SA_CONFIG_NETWORKDATA_PRIMARYDNSSERVER         "primaryDnsServer"
+#define SA_CONFIG_NETWORKDATA_SECONDARYDNSSERVER    "SecondaryDnsServer"
+
+#define SA_CONFIG_NETWORKDATA_HTTPPROXYHOST                    "httpProxyHost"
+#define SA_CONFIG_NETWORKDATA_HTTPPROXYPORT                    "httpProxyPort"
+
+
+
+/**
+ * @brief  This enum contains setup-adaptor error information
+ *
+ * The sa_error_e indicates what error is happened
+ *
+ */
+typedef enum {
+       SA_ERROR_NONE = 0,                      /**< Successful */
+       SA_ERROR_INVALID_PARAMETER,     /**< Invalid parameter */
+       SA_ERROR_INVALID_CONTENTS,      /**< Invalid contents */
+       SA_ERROR_OUT_OF_MEMORY,         /**< Out of memory */
+       SA_ERROR_PERMISSION_DENIED,     /**< Permission denied */
+       SA_ERROR_NOT_SUPPORTED,         /**< Not supported  */
+       SA_ERROR_UNKNOWN,                       /**< UNKNOWN  */
+} sa_error_e;
+
+/**
+ * @brief  This enum contains setup-adaptor error information
+ *
+ * The sa_error_e indicates what error is happened
+ *
+ */
+typedef enum {
+       SA_NETWORK_TYPE_WIFI = 0,       /**< wifi */
+       SA_NETWORK_TYPE_ETH,            /**< eth */
+       SA_NETWORK_TYPE_UNKNOWN,        /**< UNKNOWN  */
+} sa_network_type_e;
+
+
+/**
+ * @brief  This enum contains setup-adaptor error information
+ *
+ * The sa_network_state_e indicates connection info in the system
+ *
+ */
+typedef enum {
+       SA_NETWORK_STATE_DISCONNECTED = 0,              /**< Successful */
+       SA_NETWORK_STATE_PROGRESSING,               /**< Connecting/Association/Configuration */
+       SA_NETWORK_STATE_CONNECTED,                             /**< connected */
+       SA_NETWORK_STATE_UNKNOWN,                               /**< UNKNOWN  */
+} sa_network_state_e;
+
+/**
+ * @struct sa_network_static_s
+ * @brief  This struct contains network static information in the config
+ *
+ * The sa_network_static_s struct encapsulate ip, netmast, gateway and dns information in the one data
+ *
+ */
+typedef struct {
+       char *ipAddress;
+       char *netmask;
+       char *defaultGateway;
+       char *primaryDnsServer;
+       char *secondaryDnsServer;
+} sa_network_static_s;
+
+/**
+ * @struct sa_wifi_s
+ * @brief  This struct contains wifi information in the config
+ *
+ * The sa_wifi_s struct encapsulate enabled, dhcpEnabled, ssid, password and static information in the one data
+ *
+ */
+typedef struct {
+       int enabled;
+       int dhcpEnabled;
+       char *ssid;
+       char *password;
+       sa_network_static_s *staticInfo;
+} sa_wifi_s;
+
+/**
+ * @struct sa_eth_s
+ * @brief  This struct contains ethernet information in the config
+ *
+ * The sa_eth_s struct encapsulate enabled, dhcpEnabled and static information in the one data
+ *
+ */
+typedef struct {
+       int enabled;
+       int dhcpEnabled;
+       sa_network_static_s *staticInfo;
+} sa_eth_s;
+
+/**
+ * @struct sa_network_s
+ * @brief  This struct contains network information in the config
+ *
+ * The sa_network_s struct encapsulate wifi, ethernet and proxy information in the one data
+ *
+ */
+typedef struct {
+       sa_wifi_s *wifi;
+       sa_eth_s *eth;
+       char *httpProxyHost;
+       int httpProxyPort;
+} sa_network_s;
+
+
+/**
+ * @struct sa_network_activate_pararms_s
+ * @brief  This struct contains update params for activation of network
+ *
+ * The sa_network_activate_pararms_s struct encapsulate network type and network info to update in the one data
+ *
+ */
+typedef struct {
+       sa_network_type_e type;
+       sa_network_s *network;
+} sa_network_activate_pararms_s;
+
+/**
+ * @struct sa_systemdata_s
+ * @brief  This struct contains system data information in the config
+ *
+ * The sa_systemdata_s struct encapsulate device name information in the one data
+ *
+ */
+typedef struct {
+       char *deviceName;
+} sa_systemdata_s;
+
+/**
+ * @struct sa_config_s
+ * @brief  This struct contains config information
+ *
+ * The sa_config_s struct encapsulate version, network and system data information in the one data
+ *
+ */
+typedef struct {
+       char *version;
+       sa_network_s *network;
+       sa_systemdata_s *systemData;
+} sa_config_s;
+
+#endif /* __SA_TYPES_H__ */
\ No newline at end of file
diff --git a/packaging/setup-adaptor.manifest b/packaging/setup-adaptor.manifest
new file mode 100644 (file)
index 0000000..a76fdba
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
diff --git a/packaging/setup-adaptor.service b/packaging/setup-adaptor.service
new file mode 100644 (file)
index 0000000..0e73224
--- /dev/null
@@ -0,0 +1,15 @@
+[Unit]
+Description=Setup-Adaptor daemon
+After=connman.service
+Requires=connman.service
+
+[Service]
+SmackProcessLabel=System
+Type=notify
+ExecStart=/usr/bin/setup-adaptor
+Restart=always
+RestartSec=0
+
+[Install]
+WantedBy=multi-user.target
+
diff --git a/packaging/setup-adaptor.spec b/packaging/setup-adaptor.spec
new file mode 100644 (file)
index 0000000..665bdd7
--- /dev/null
@@ -0,0 +1,72 @@
+Name:       setup-adaptor
+Summary:    Provide network and system data setting daemon
+Version:    0.1.0
+Release:    0
+Group:      System & Docker Framework
+License:    Apache-2.0
+Source0:    %{name}-%{version}.tar.gz
+Source1:    %{name}.manifest
+Source2:    %{name}.service
+BuildRequires:  awk
+BuildRequires:  cmake
+BuildRequires:  pkgconfig(glib-2.0)
+BuildRequires:  pkgconfig(dlog)
+BuildRequires:  pkgconfig(libsystemd)
+BuildRequires:  pkgconfig(capi-network-wifi-manager)
+BuildRequires:  pkgconfig(capi-network-connection)
+BuildRequires:  pkgconfig(json-c)
+
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+%description
+provide setting for network and system data based on config
+
+%prep
+%setup -q
+cp %{SOURCE1} ./
+cp %{SOURCE2} ./
+
+%build
+export LDFLAGS+="-Wl,--as-needed"
+MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+
+%cmake . \
+               -DBUILD_TESTS=OFF\
+               -DMAJORVER=${MAJORVER}\
+               -DFULLVER=%{version}\
+               -DBIN_INSTALL_DIR:PATH=%{_bindir}
+
+%install
+%make_install
+mkdir -p %{buildroot}%{_unitdir}/multi-user.target.wants
+install -m 0644 %SOURCE2 %{buildroot}%{_unitdir}/%{name}.service
+%install_service multi-user.target.wants %{name}.service
+
+%post
+systemctl daemon-reload
+if [ $1 == 1 ]; then
+       # install
+       systemctl start %{name}.service
+elif [ $1 == 2 ]; then
+       # upgrade
+       systemctl restart %{name}.service
+fi
+
+%preun
+if [ $1 == 0 ]; then
+       # uninstall
+       systemctl stop %{name}.service
+fi
+
+%postun
+systemctl daemon-reload
+
+%files
+%manifest %{name}.manifest
+%defattr(-,root,root,-)
+%license LICENSE.APLv2
+%{_bindir}/%{name}
+%{_unitdir}/%{name}.service
+%{_unitdir}/multi-user.target.wants/%{name}.service
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..471640f
--- /dev/null
@@ -0,0 +1,21 @@
+LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pbus_pkgs REQUIRED dlog glib-2.0 capi-network-wifi-manager capi-network-connection json-c)
+
+
+INCLUDE_DIRECTORIES(${pbus_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${pbus_pkgs_LIBRARY_DIRS})
+
+FILE(GLOB SRCS *.c
+               sa_manager.c 
+               sa_network.c 
+               sa_systemdata.c)
+
+ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
+
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pbus_pkgs_LIBRARIES} pthread json-c)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BIN_INSTALL_DIR})
\ No newline at end of file
diff --git a/src/sa_manager.c b/src/sa_manager.c
new file mode 100644 (file)
index 0000000..f2415b9
--- /dev/null
@@ -0,0 +1,361 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/inotify.h>
+#include "sa_common.h"
+#include "sa_types.h"
+#include "sa_systemdata.h"
+#include "sa_network.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 ) )
+
+static int __check_config_file(char* filename) 
+{
+       int ret = 0;
+
+       if( access(filename, F_OK) != -1 ) {
+       // file exists
+       ret = 1;
+       } 
+
+       return ret;
+}
+
+static char* __print_connection_state(sa_network_state_e state)
+{
+       switch (state) {
+       case SA_NETWORK_STATE_DISCONNECTED:
+               return "Disconnected";
+       case SA_NETWORK_STATE_PROGRESSING:
+               return "Progressing";
+       case SA_NETWORK_STATE_CONNECTED:
+               return "connected";
+       default:
+               return "Unknown";
+       }
+}
+
+static char* __print_connection_type(sa_network_type_e type)
+{
+       switch (type) {
+       case SA_NETWORK_TYPE_WIFI:
+               return "wifi";
+       case SA_NETWORK_TYPE_ETH:
+               return "ethernet";
+       default:
+               return "Unknown";
+       }
+}
+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]");
+       }
+}
+
+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;
+
+       if (config != NULL) {
+               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->dhcpEnabled == 0) {
+                                       __print_config_network_static_info(wifi->staticInfo);
+                               }
+                       }
+
+                       eth = network->eth;
+                       if (eth != NULL) {
+                               _D("Network::eth::enabled[%d]", eth->enabled);
+                               _D("Network::eth::dhcpEnabled[%d]", eth->dhcpEnabled);
+
+                               if (eth->dhcpEnabled == 0) {
+                                       __print_config_network_static_info(wifi->staticInfo);
+                               }
+                       }
+
+                       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);
+               }
+       }
+}
+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->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);
+
+                               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);
+
+                               free(network->eth->staticInfo);
+                       }       
+               }
+
+               if (network->httpProxyHost != NULL) free(network->httpProxyHost);
+
+               free(network);
+       }
+}
+
+static void __release_config_resource(sa_config_s* config, sa_network_activate_pararms_s* activateParams) {
+       
+       if (config != NULL) {
+               if (config->version != NULL) {
+                       free(config->version);
+               }
+
+               if (config->network != NULL) {
+                       __release_network_resource(config->network);
+               }
+
+               if (config->systemData != NULL) {
+                       if (config->systemData->deviceName != NULL) {
+                               free(config->systemData->deviceName);
+                       }
+
+                       free(config->systemData);
+               }
+
+               free(config);
+       }
+
+       if (activateParams != NULL) {
+               __release_network_resource(activateParams->network);
+       }
+}
+static void* __config_event_loop(void* arg)
+{
+       int fd;
+       int wd;
+       char* config_path = NULL;
+       char buffer[BUF_LEN];
+
+       _D("__config_event_loop start\n");      
+       
+       config_path = (char *)arg;
+
+       if (config_path != NULL) {
+               _E("Config is null to register event");
+               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) {
+               int length, i = 0;
+               length = read(fd, buffer, BUF_LEN);
+
+               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");
+                       if (event->len) {
+                               if (event->mask & IN_CREATE) {
+                                       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 {
+                                               _D("The file %s was deleted.\n", event->name);
+                                       }
+                               } else if (event->mask & IN_MODIFY) {
+                                       if (event->mask & IN_ISDIR) {
+                                               _D("The directory %s was modified.\n", event->name);
+                                       } 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) {
+                                               _D("The directory %s was moved.\n", event->name);
+                                       } else {
+                                               _D("The file %s was moved.\n", event->name);
+                                       }
+                               }
+                       }
+
+                       i += EVENT_SIZE + event->len;
+               }
+       }
+
+       inotify_rm_watch(fd, wd);
+       close(fd);
+
+       pthread_exit((void *)0);
+
+       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;
+       }
+
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       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 
+       
+       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);
+               if (ret == SA_ERROR_NONE) {
+                       _D("Success to get config");
+                       // check config info
+                       if (config != NULL) {
+                               _D("Config value");
+                               __print_config_info(config);
+                       }
+               } 
+               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
+               */
+               if (ret == SA_ERROR_NONE) {
+                       for (index = 0; index < NETWORK_CHECK_RETRY_MAX; index++) {
+                               ret = sa_network_get_state(&conn_state, &conn_type);
+                               if (ret == SA_ERROR_NONE) {
+                                       if (conn_state == SA_NETWORK_STATE_CONNECTED) {
+                                               _D("Network is connected : Type[%d][%s]", conn_type, __print_connection_type(conn_type));
+                                               break;
+                                       }
+                                       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);
+                       }
+               }
+         
+
+           // 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
+               */
+
+           // 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");
+       }
+       
+       return 0;
+}
diff --git a/src/sa_network.c b/src/sa_network.c
new file mode 100644 (file)
index 0000000..e1a10bb
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include "sa_common.h"
+#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)
+{
+       sa_error_e ret = SA_ERROR_NONE;
+       // check network state(eth/wifi)
+       // return state according to enum
+       return ret;
+}
+
+int sa_network_activate(sa_network_activate_pararms_s* info)
+{
+       sa_error_e ret = SA_ERROR_NONE;
+
+       return ret;
+}
+
+int sa_network_deactivate(void)
+{
+       sa_error_e ret = SA_ERROR_NONE;
+
+       return ret;
+}
\ No newline at end of file
diff --git a/src/sa_systemdata.c b/src/sa_systemdata.c
new file mode 100644 (file)
index 0000000..7bf64c3
--- /dev/null
@@ -0,0 +1,360 @@
+/*
+ * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <json.h>
+#include "sa_common.h"
+#include "sa_types.h"
+#include "sa_systemdata.h"
+
+static char* json_getString(char* data, char* key)
+{
+       struct json_object *inputObj;
+       struct json_object *bodyObj;
+       enum json_type type;
+       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)) {
+                       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] == '\\')
+                                               continue;
+                                       ret_buf[j++] = buf[i];
+                               }
+                       }
+               }
+               else {
+                       _E("ERROR : no data");
+               }
+       }
+       json_object_put(inputObj);
+       _D("JSON>> ret_buf = %s", ret_buf);
+       return ret_buf;
+}
+
+static int json_getNumber(char* data, char* key)
+{
+       struct json_object *inputObj;
+       struct json_object *bodyObj;
+       enum json_type type;
+       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))
+               {
+                       ret_num = json_object_get_int(bodyObj);
+               }
+               else
+               {
+                       _E("ERROR : no data");
+
+               }
+       }
+       json_object_put(inputObj);
+       return ret_num;
+}
+
+
+static char* json_getObject(char *data, char *key)
+{
+       struct json_object *inputObj = NULL;
+       struct json_object *bodyObj = NULL;
+       const char *buf = NULL;
+       char *ret_buf = 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) {
+                               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);
+                               if (ret_buf != NULL) {
+                                       memset(ret_buf, 0x00, strlen(buf)+1);
+                                       memcpy(ret_buf, buf, strlen(buf));
+                               }
+                       }
+               }
+               json_object_put(inputObj);
+       }
+       return ret_buf;
+}
+
+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;
+
+       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))
+               {
+                       type = json_object_get_type(bodyObj);
+                       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)
+                               {
+                                       memset(ret_buf, 0x00, strlen(buf) + 1);
+                                       memcpy(ret_buf, buf, strlen(buf));
+                               }
+                       }
+               }
+       }
+
+       json_object_put(inputObj);
+       return ret_buf;
+}
+
+static int json_getArrayLength(char *data)
+{
+       struct json_object *inputObj;
+       enum json_type type;
+       int cnt = 0;
+
+       inputObj = json_tokener_parse(data);
+       type = json_object_get_type(inputObj);
+
+       if(type == json_type_array)
+       {
+               cnt = json_object_array_length(inputObj);
+       }
+
+       return cnt;
+}
+
+static char *json_getStringFromArray(char *data, char *arrayKey, int arrayIndex, char *key)
+{
+       struct json_object *inputObj;
+       struct json_object *bodyObj;
+       struct json_object *arrayObj;
+       struct json_object *elementObj;
+       char *ret_buf = NULL;
+       const char *buf = NULL;
+       int i, j = 0;
+
+       inputObj = json_tokener_parse(data);
+       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] == '\\')
+                                               continue;
+                                       ret_buf[j++] = buf[i];
+                               }
+                       }
+               }
+               else {
+                       _E("ERROR : no data");
+               }
+               json_object_put(inputObj);
+       }else {
+               _E("ERROR : not found(%s)", arrayKey);
+       }       
+
+       return ret_buf;
+}
+
+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))
+       {
+               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] == '\\')
+                                       continue;
+                               ret_buf[j++] = buf[i];
+                       }
+               } else {
+                       return NULL;
+               }
+       } else {
+               return NULL;
+       }
+
+       _D("ret_buf [%s]", ret_buf);
+       return ret_buf;
+}
+
+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;
+       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;
+
+       }
+
+       _D("dockerform_parse_container_info end");
+
+       return 0;
+}
+
+static int __parse_config(char *file, sa_config_s* config)
+{
+       struct json_object* configObj = NULL;
+       char *json_data = 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)
+       {
+               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);
+               }
+               close(fd);
+       }
+
+       return 0;
+}
+
+int sa_systemdata_get_config_info(char* file, sa_config_s* config)
+{
+       sa_error_e ret = SA_ERROR_NONE;
+
+       // check file
+       if (access(file, 0) != 0) {
+               _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
diff --git a/test/sa_test.c b/test/sa_test.c
new file mode 100644 (file)
index 0000000..e69de29