Drop plugin from this repo and integrate with libsyscommon 30/306630/2 accepted/tizen/unified/20240311.012815 accepted/tizen/unified/x/20240311.100242
authorAntoni <a.adaszkiewi@samsung.com>
Thu, 18 Jan 2024 15:38:41 +0000 (16:38 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Tue, 5 Mar 2024 02:57:28 +0000 (11:57 +0900)
Plugin is moved into
platform/core/system/plugin/update-control-generic. Update control API
now uses libsyscommon to manage plugins, should behave very similarlly.

Change-Id: I790f457f222746f19f9784378e5c7a91c412ab43

CMakeLists.txt
include/update_control.h
packaging/update-control.spec
src/plugin/CMakeLists.txt [deleted file]
src/plugin/http_util.c [deleted file]
src/plugin/http_util.h [deleted file]
src/plugin/plugin.c [deleted file]
src/plugin/plugin.h [deleted file]
src/update_control.c

index cf19d0ae580bd1cd5dbcfb532a8768474fce563a..af791c2e3d7ae211da768c985cdb3b49f3e9399c 100644 (file)
@@ -16,10 +16,9 @@ SET(requires
        gio-2.0
        gio-unix-2.0
        glib-2.0
+       libsyscommon-plugin-api-update-control
 )
 
-ADD_DEFINITIONS("-DPLUGIN_PATH=\"${PLUGIN_PATH}\"")
-
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${requires})
 FOREACH(flag ${${fw_name}_CFLAGS})
@@ -68,7 +67,6 @@ CONFIGURE_FILE(
 )
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
-ADD_SUBDIRECTORY(src/plugin)
 ADD_SUBDIRECTORY(update-manager)
 ADD_SUBDIRECTORY(delta-verifier)
 ADD_SUBDIRECTORY(tools)
index e4ae75810d01123aa8bca748eeecb0f8923b2862..fee2cf23cb073a8b35dd16fa913e671947ab9d83 100644 (file)
@@ -18,8 +18,8 @@
 #ifndef __TIZEN_SYSTEM_UPDATE_CONTROL_H__
 #define __TIZEN_SYSTEM_UPDATE_CONTROL_H__
 
-#include <tizen.h>
 #include <time.h>
+#include <tizen.h>
 
 #ifdef __cplusplus
 extern "C" {
index 7144463622f7ee658bf148f6928ceb88d4ab50ed..67ef66717090722ed89373d662ffca53a5fa9361 100644 (file)
@@ -32,6 +32,7 @@ BuildRequires:  pkgconfig(key-manager)
 BuildRequires:  pkgconfig(pkgmgr-info)
 BuildRequires:  pkgconfig(storage)
 BuildRequires:  pkgconfig(vconf)
+BuildRequires:  pkgconfig(libsyscommon-plugin-api-update-control)
 BuildRequires:  libtar-devel
 
 %description
@@ -79,7 +80,6 @@ export CFLAGS+=" -Wno-stringop-truncation"
 %cmake . -DMAJORVER=${MAJORVER} \
         -DFULLVER=%{version} \
         -DDEBUG_MODE=on \
-        -DPLUGIN_PATH=%{_libdir} \
         -DBINARY_PATH=%{_bindir}
 
 %__make %{?jobs:-j%jobs}
@@ -119,12 +119,6 @@ ln -s ../%{service_file} %{buildroot}/%{_unitdir}/multi-user.target.wants/%{serv
 %{_libdir}/pkgconfig/*.pc
 %{_libdir}/libupdate-control.so
 
-%files plugin
-%manifest %{name}.manifest
-%license LICENSE
-# path is fixed in src/update_control.c
-%{_libdir}/libupdate-control-plugin.so*
-
 %files tools
 %manifest %{name}.manifest
 %license LICENSE
diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt
deleted file mode 100644 (file)
index adcf42a..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-SET(fw_name "update-control-plugin")
-
-PROJECT(${fw_name})
-
-SET(CMAKE_INSTALL_PREFIX /usr)
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-
-SET(SOURCES
-       plugin.c
-       http_util.c
-)
-
-#INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/plugin)
-#MESSAGE("INCLUDE dir: ${CMAKE_SOURCE_DIR}/src/plugin")
-
-SET(requires
-       capi-appfw-app-common
-       capi-system-info
-       dlog
-       gio-2.0
-       alarm-service
-       libcurl
-       libtzplatform-config
-       key-manager
-       hal-api-device
-)
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_name} REQUIRED ${requires})
-FOREACH(flag ${${fw_name}_CFLAGS})
-    SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -fvisibility=hidden")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-IF(DEBUG_MODE STREQUAL on)
-       ADD_DEFINITIONS(-DDEBUG_MODE)
-ENDIF()
-
-ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS})
-SET_TARGET_PROPERTIES(${fw_name}
-     PROPERTIES
-     VERSION ${FULLVER}
-     SOVERSION ${MAJORVER}
-     CLEAN_DIRECT_OUTPUT 1
-)
-
-INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
diff --git a/src/plugin/http_util.c b/src/plugin/http_util.c
deleted file mode 100644 (file)
index 11ba36b..0000000
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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.
- */
-
-#define HTTPS_TEST
-#define DOWNLOAD_MONITORING
-
-#include <curl/curl.h>
-#include "http_util.h"
-#include "plugin.h"
-
-#ifdef DOWNLOAD_MONITORING
-#include <unistd.h>
-#endif
-
-#define STDM_URL  "https://apis.samsungiotcloud.com/v1/stdm/fota/target"
-
-#ifdef DOWNLOAD_MONITORING
-#define GAUGE_LENGTH 30
-
-static int binary_size = 0;
-#endif
-
-static void __curl_set_response(CURL *curl,
-               GByteArray *response_header,
-               GByteArray *response_body,
-               char **res_header,
-               char **res_body,
-               void *user_data)
-{
-       CURLcode err = CURLE_OK;
-
-       long response = 0;
-
-       err = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
-       retm_if(err != CURLE_OK,
-                       "Failed to get info from curl handle[%s, %d]", curl_easy_strerror(err), err);
-
-       _D("Response Code[%ld]", response);
-
-       char *tmp_header = g_strndup((const gchar *)response_header->data, response_header->len);
-       char *tmp_body = g_strndup((const gchar *)response_body->data, response_body->len);
-
-       *res_header = tmp_header;
-       *res_body = tmp_body;
-}
-
-#ifdef HTTPS_TEST
-static int http_util_set_ssl_opt(CURL *curl)
-{
-       _D("Enable SSL verification");
-
-       /* For Debug */
-       int curl_ret_code = curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_VERBOSE failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_SSL_VERIFYPEER failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_SSL_VERIFYHOST failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       return 0;
-}
-#endif
-
-static void __curl_set_request_headers(CURL *curl)
-{
-       struct curl_slist *header = NULL;
-       char *tmp_header = NULL;
-
-       tmp_header = g_strconcat("Content-Type: ", "application/json", NULL);
-       header = curl_slist_append(header, tmp_header);
-       g_free(tmp_header);
-
-       int curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_HTTPHEADER failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-}
-
-static size_t __gather_data(void *downloaded_data,
-               size_t size,
-               size_t nmemb,
-               void *user_data)
-{
-       size_t total_size = size * nmemb;
-       g_byte_array_append((GByteArray *)user_data, (const unsigned char *) downloaded_data, total_size);
-       return total_size;
-}
-
-static void __curl_set_common_option(CURL *curl,
-               const char *url,
-               GByteArray **response_header_ptr,
-               GByteArray **response_body_ptr)
-{
-       CURLcode curl_ret_code;
-
-       _D("set URL = [%s]", url);
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, url);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_URL failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       GByteArray *response_header_data = g_byte_array_new();
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, __gather_data);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_HEADERFUNCTION failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_HEADERDATA, response_header_data);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_HEADERDATA failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       GByteArray *response_body_data = g_byte_array_new();
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, __gather_data);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_WRITEFUNCTION failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, response_body_data);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_WRITEDATA failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
-       if (CURLE_OK != curl_ret_code) {
-               _E("curl_easy_setopt: CURLOPT_NOPROGRESS failed!! curl_ret_code[%d]", curl_ret_code);
-       }
-
-       *response_header_ptr = response_header_data;
-       *response_body_ptr = response_body_data;
-}
-
-
-#ifdef DOWNLOAD_MONITORING
-static void *_print_download_progress(void *download_path)
-{
-       FILE *fp = NULL;
-       int retry = 0;
-       int cur = 0;
-       char buf[256];
-
-       do {
-               sleep(1);
-
-               if (!fp) {
-                       fp = fopen((char *)download_path, "r");
-                       if (!fp) {
-                               retry++;
-                               if (retry >= 3) {
-                                       _E("Failed to open %s", (char *)download_path);
-                                       strerror_r(errno, buf, sizeof(buf));
-                                       _E("%s", buf);
-                                       break;
-                               }
-                               continue;
-                       }
-               }
-
-               fseek(fp, 0L, SEEK_END);
-               int size = ftell(fp);
-               rewind(fp);
-
-               if (binary_size <= 0) {
-                       _E("Package size is not set. Can not print progress");
-                       fclose(fp);
-                       return 0;
-               }
-
-               double progress = ((double)size / binary_size);
-
-               if (progress <= 1) {
-                       char bar[GAUGE_LENGTH + 3];
-                       double speed = 0;
-                       char speed_str[16];
-
-                       snprintf(bar, sizeof(bar), "[");
-                       int i = 1;
-                       for (; i <= GAUGE_LENGTH * progress; i++)
-                               snprintf(bar + strlen(bar), sizeof(bar) - 1, "=");
-                       for (; i <= GAUGE_LENGTH; i++)
-                               snprintf(bar + strlen(bar), sizeof(bar) - 1, ".");
-                       snprintf(bar + strlen(bar), sizeof(bar) - 1, "]");
-
-                       speed = size - cur;
-                       cur = size;
-
-                       if (speed > 0 && speed < 1000)
-                               snprintf(speed_str, sizeof(speed_str), "%d B/s", (int)speed);
-                       else if (speed >= 1000 && speed < 1000000)
-                               snprintf(speed_str, sizeof(speed_str), "%.1f KB/s", speed / 1000);
-                       else if (speed >= 1000000)
-                               snprintf(speed_str, sizeof(speed_str), "%.1f MB/s", speed / 1000000);
-                       else
-                               snprintf(speed_str, sizeof(speed_str), "%d B/s", 0);
-
-                       _D("%s | %d / %d (%d %%) - %s",
-                                       bar, size, binary_size,
-                                       (int)(progress * 100), speed_str);
-               }
-
-               if (progress >= 1) {
-                       _D("Download Finished (%d / %d)", size, binary_size);
-                       break;
-               }
-       } while (1);
-
-       if (fp)
-               fclose(fp);
-
-       return 0;
-}
-#endif
-
-int http_util_check_request_to_fota(const char *uid,
-               const char *access_token,
-               const char *device_type,
-               const char *current_version,
-               char **res_header,
-               char **res_body)
-{
-       int ret = 0;
-       CURL *curl = NULL;
-       GByteArray *response_header = NULL;
-       GByteArray *response_body= NULL;
-       CURLcode err;
-       struct curl_slist *header = NULL;
-       char *tmp_header = NULL;
-       char *req_url = NULL;
-       char query[128];
-       int curl_ret_code = 0;
-
-       curl = curl_easy_init();
-       retvm_if(!curl, -EIO, "Failed to init curl");
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
-       retvmf_if(CURLE_OK != curl_ret_code, -EIO, curl_easy_cleanup(curl),
-                 "Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code);
-
-       tmp_header = g_strconcat("X-IOT-UID: ", uid, NULL);
-       header = curl_slist_append(header, tmp_header);
-       g_free(tmp_header);
-       tmp_header = g_strconcat("Authorization: ", "Bearer ", access_token, NULL);
-       header = curl_slist_append(header, tmp_header);
-       g_free(tmp_header);
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header);
-       retvmf_if(CURLE_OK != curl_ret_code, -EIO, curl_easy_cleanup(curl),
-                 "Failed to curl_easy_setopt with CURLOPT_HTTPHEADER : ret_code[%d]", curl_ret_code);
-
-       snprintf(query, sizeof(query), "?deviceType=%s&currentVersion=%s", device_type, current_version);
-       req_url = g_strconcat(STDM_URL, query, NULL);
-       _D("Query URL: [%s]", req_url);
-       __curl_set_common_option(curl, req_url, &response_header, &response_body);
-
-#ifdef HTTPS_TEST
-       http_util_set_ssl_opt(curl);
-#endif
-
-       err = curl_easy_perform(curl);
-       _I("curl_easy_perform(): [%s][%d]", curl_easy_strerror(err), err);
-
-       if (err == CURLE_ABORTED_BY_CALLBACK) {
-               ret = -1;
-               goto END;
-       } else if (err != CURLE_OK) {
-               ret = -1;
-               goto END;
-       }
-
-       __curl_set_response(curl, response_header, response_body, res_header, res_body, NULL);
-
-       //_D("header[%s], body[%s]", *res_header, *res_body);
-
-END:
-       if (response_header)
-               g_byte_array_free(response_header, TRUE);
-       if (response_body)
-               g_byte_array_free(response_body, TRUE);
-       if (req_url)
-               g_free(req_url);
-
-       curl_easy_cleanup(curl);
-       return ret;
-}
-
-int http_util_download_file(const char *download_url, const char *download_path,
-               int package_size)
-{
-       retvm_if(!download_url || !download_path, -EINVAL, "Invalid parameter");
-
-       FILE *fp = NULL;
-       CURL *curl = NULL;
-       CURLcode err = CURLE_OK;
-       int ret_code = 0;
-       int curl_ret_code = CURLE_OK;
-
-       curl = curl_easy_init();
-       retvm_if(!curl, -EIO, "Failed to init curl");
-
-#ifdef HTTPS_TEST
-       http_util_set_ssl_opt(curl);
-#endif
-
-#ifdef DOWNLOAD_MONITORING
-       binary_size = package_size;
-
-       pthread_t p_thread;
-       int thread = pthread_create(&p_thread, NULL, _print_download_progress, (void *)download_path);
-       if (thread < 0)
-               _E("Failed to create thread");
-       else
-               _D("Register timeout fn for monitoring");
-#endif
-
-       fp = fopen(download_path, "wb");
-       if (fp == NULL) {
-               _E("Failed to open %s", download_path);
-               goto clean;
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_URL, download_url);
-       if (CURLE_OK != curl_ret_code) {
-               _E("Failed to curl_easy_setopt with CURLOPT_URL : ret_code[%d]", curl_ret_code);
-               goto clean;
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
-       if (CURLE_OK != curl_ret_code) {
-               _E("Failed to curl_easy_setopt with CURLOPT_WRITEFUNCTION : ret_code[%d]", curl_ret_code);
-               goto clean;
-       }
-
-       curl_ret_code = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
-       if (CURLE_OK != curl_ret_code) {
-               _E("Failed to curl_easy_setopt with CURLOPT_WRITEDATA : ret_code[%d]", curl_ret_code);
-               goto clean;
-       }
-
-       err = curl_easy_perform(curl);
-
-clean:
-       curl_easy_cleanup(curl);
-
-       if (fp != NULL)
-               fclose(fp);
-       else
-               ret_code = -EIO;
-
-       if (CURLE_OK != curl_ret_code)
-               ret_code = -EIO;
-
-#ifdef DOWNLOAD_MONITORING
-       int status;
-       pthread_join(p_thread, (void **)&status);
-#endif
-
-       if (err != CURLE_OK) {
-               _I("Failed to download file[%s, %d]", curl_easy_strerror(err), err);
-               if (remove(download_path) < 0)
-                       _E("Failed to remove [%s]", download_path);
-               ret_code = -EIO;
-       }
-
-       return ret_code;
-}
-
-int http_util_send_request(fmwup_http_e type, const char *req_url, char **res_header, char **res_body)
-{
-       int ret = 0;
-       CURL *curl = NULL;
-       GByteArray *response_header = NULL;
-       GByteArray *response_body= NULL;
-       CURLcode err;
-       int curl_ret_code = 0;
-       curl_mime *mime = NULL;
-
-       curl = curl_easy_init();
-       retvm_if(!curl, -EIO, "Failed to init curl");
-
-       __curl_set_request_headers(curl);
-
-       if (type == FMWUP_HTTP_GET) {
-               curl_ret_code = curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
-               if (CURLE_OK != curl_ret_code) {
-                       _E("Failed to curl_easy_setopt with CURLOPT_HTTPGET : ret_code[%d]", curl_ret_code);
-                       ret = -EIO;
-                       goto END;
-               }
-       } else if (type == FMWUP_HTTP_POST) {
-               mime = curl_mime_init(curl);
-               if (!mime) {
-                       _E("curl_mime_init: Failed to init mime");
-                       ret = -EIO;
-                       goto END;
-               }
-
-               curl_ret_code = curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
-               if (curl_ret_code != CURLE_OK) {
-                       _E("Failed to curl_easy_setopt with CURLOPT_MIMEPOST : ret_code[%d]", curl_ret_code);
-                       ret = -EIO;
-                       goto END;
-               }
-       } else {
-               _E("Invalid http type: %d", type);
-               ret = -1;
-               goto END;
-       }
-
-       __curl_set_common_option(curl, (const char *)req_url, &response_header, &response_body);
-
-       err = curl_easy_perform(curl);
-       _I("curl_easy_perform(): [%s][%d]", curl_easy_strerror(err), err);
-
-       if (err == CURLE_ABORTED_BY_CALLBACK) {
-               ret = -1;
-               goto END;
-       } else if (err != CURLE_OK) {
-               ret = -1;
-               goto END;
-       }
-
-       __curl_set_response(curl, response_header, response_body, res_header, res_body, NULL);
-
-END:
-       if (mime)
-               curl_mime_free(mime);
-       if (response_header)
-               g_byte_array_free(response_header, TRUE);
-       if (response_body)
-               g_byte_array_free(response_body, TRUE);
-
-       curl_easy_cleanup(curl);
-       return ret;
-}
diff --git a/src/plugin/http_util.h b/src/plugin/http_util.h
deleted file mode 100644 (file)
index 3017f5c..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 __TIZEN_SYSTEM_UPDATE_CONTROL_HTTP_UTIL_H__
-#define __TIZEN_SYSTEM_UPDATE_CONTROL_HTTP_UTIL_H__
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-typedef enum {
-       FMWUP_HTTP_GET = 0,
-       FMWUP_HTTP_POST,
-       FMWUP_HTTP_PUT,
-       FMWUP_HTTP_DELETE
-} fmwup_http_e;
-
-int http_util_check_request_to_fota(const char *uid, const char *access_token,
-               const char *device_type, const char *current_version,
-               char **res_header, char **res_body);
-int http_util_download_file(const char *download_url, const char *download_path,
-               int package_size);
-int http_util_send_request(fmwup_http_e type, const char *req_url,
-               char **res_header, char **res_body);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_SYSTEM_UPDATE_CONTROL_HTTP_UTIL_H__ */
diff --git a/src/plugin/plugin.c b/src/plugin/plugin.c
deleted file mode 100644 (file)
index eea012f..0000000
+++ /dev/null
@@ -1,872 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 <stdlib.h>
-#include <update_control.h>
-#include <app_common.h>
-#include <alarm.h>
-#include <system_info.h>
-#include <tzplatform_config.h>
-#include <ckmc/ckmc-manager.h>
-#include <hal/device/hal-board.h>
-#include "plugin.h"
-#include "http_util.h"
-
-#define SET_POLLING
-
-#undef API
-#define API __attribute__ ((visibility("default")))
-
-/* Key manager information for ST cloud account info */
-#define ST_APP_THING_SERVICE_APP_ID          "com.samsung.tizen.smartthings-thing"
-#define DM_KEY_MANAGER_ALIAS_ACCESS_TOKEN    "access_token"
-#define DM_KEY_MANAGER_ALIAS_USER_ID         "user_id"
-
-/* Update dbus */
-#define UPDATE_BUS_NAME         "org.tizen.system.update"
-#define UPDATE_OBJECT_PATH      "/Org/Tizen/System/Update"
-#define UPDATE_INTERFACE_NAME   UPDATE_BUS_NAME".Update"
-#define UPDATE_METHOD           "do_update"
-
-#define FIRMWARE_FILE_NAME "delta.tar.gz"
-
-#ifdef DEBUG_MODE
-#define DEBUG_FLAG "/opt/etc/.debugupdate"
-#endif
-
-static struct _cloud_account {
-       const char *access_token;
-       const char *user_id;
-} *cloud_account;
-
-static struct _update_info {
-       char *new_version;
-       char *package_uri;
-       int updatable;
-       int package_size;
-} *update_info;
-
-static alarm_id_t reserved_update_alarm_id = -1;
-static bool package_downloaded = false;
-
-#ifdef SET_POLLING
-static alarm_id_t polling_alarm_id = -1;
-#endif // SET_POLLING
-
-#ifdef DEBUG_MODE
-static bool debug_mode = false;
-#endif
-
-static int get_keymanager_data(const char *alias, const char *password,
-               char **data)
-{
-       _D("Get alias [%s]", alias);
-
-       int ret = 0;
-       char *full_alias = NULL;
-       ckmc_raw_buffer_s *raw_buf = NULL;
-
-       ckmc_alias_new(ST_APP_THING_SERVICE_APP_ID, alias, &full_alias);
-       retvm_if(!full_alias, -1, "Failed to ckmc_alias_new");
-
-       ret = ckmc_get_data(full_alias, password, &raw_buf);
-       if (ret != 0) {
-               if (ret != CKMC_ERROR_DB_ALIAS_UNKNOWN)
-                       _E("Failed to ckmc_get_data [%d]", ret);
-               ret = -1;
-               goto out;
-       }
-
-       *data = strndup((const char *)raw_buf->data, raw_buf->size);
-       if (!*data) {
-               _E("Failed to strndup");
-               ret = -1;
-       }
-
-out:
-       if (raw_buf)
-               ckmc_buffer_free(raw_buf);
-       if (full_alias)
-               free(full_alias);
-
-       return ret;
-}
-
-static void get_cloud_accout(void)
-{
-       _D("Get cloud account through the key-manager");
-
-       get_keymanager_data(DM_KEY_MANAGER_ALIAS_ACCESS_TOKEN, NULL,
-                       (char **)&cloud_account->access_token);
-       get_keymanager_data(DM_KEY_MANAGER_ALIAS_USER_ID, NULL,
-                       (char **)&cloud_account->user_id);
-
-       if (!cloud_account->access_token || !cloud_account->user_id)
-               _E("Failed to get cloud account");
-       else
-               _D("Access Token: [%s], User ID: [%s]",
-                               cloud_account->access_token, cloud_account->user_id);
-}
-
-static int reservation_alarm_cb(alarm_id_t alarm_id, void *data)
-{
-       int ret;
-       _I("Update alarm: reserved update is triggered");
-
-       ret = update_control_check_new_version();
-       if (ret < 0) {
-               _E("Failed to check new version: %d", ret);
-               return -1;
-       }
-
-       if (!update_info->updatable)
-               return 0;
-
-       _I("New version found. Do update");
-
-       ret = update_control_download_package();
-       if (ret < 0) {
-               _E("Failed to download package: %d", ret);
-               return -1;
-       }
-
-       ret = update_control_do_update();
-       if (ret < 0) {
-               _E("Failed to update: %d", ret);
-               return -1;
-       }
-
-       return 0;
-}
-
-static void init_update_alarm(void)
-{
-       int ret;
-
-       ret = alarmmgr_init("update_reservation");
-       if (ret < 0) {
-               _E("alarmmgr_init failed [%d]", ret);
-               return;
-       }
-
-       ret = alarmmgr_set_cb(reservation_alarm_cb, NULL);
-       if (ret < 0) {
-               _E("alarmmgr_set_cb failed [%d]", ret);
-               return;
-       }
-
-}
-
-#ifdef SET_POLLING
-static int set_polling_alarm(void)
-{
-       int ret, week_flag;
-       time_t cur_time;
-       struct tm polling_time;
-       alarm_date_t alarm_time;
-       alarm_entry_t *alarm_info = NULL;
-
-       alarm_info = alarmmgr_create_alarm();
-       if (alarm_info == NULL) {
-               _E("alarmmgr_create_alarm failed");
-               return -1;
-       }
-
-       cur_time = time(NULL);
-       localtime_r(&cur_time, &polling_time);
-
-       /* Polling period: every AM 3:00 */
-       polling_time.tm_hour = 3;
-       polling_time.tm_min = 0;
-       polling_time.tm_sec = 0;
-
-       week_flag = ALARM_WDAY_SUNDAY | ALARM_WDAY_MONDAY |
-               ALARM_WDAY_TUESDAY | ALARM_WDAY_WEDNESDAY |
-               ALARM_WDAY_THURSDAY | ALARM_WDAY_FRIDAY |
-               ALARM_WDAY_SATURDAY;
-
-       alarm_time.year = polling_time.tm_year + 1900;
-       alarm_time.month = polling_time.tm_mon + 1;
-       alarm_time.day = polling_time.tm_mday;
-       alarm_time.hour = polling_time.tm_hour;
-       alarm_time.min = polling_time.tm_min;
-       alarm_time.sec = polling_time.tm_sec;
-
-       ret = alarmmgr_set_time(alarm_info, alarm_time);
-       if (ret != ALARMMGR_RESULT_SUCCESS) {
-               _E("alarmmgr_set_time failed [%d]", ret);
-               ret = -1;
-               goto out;
-       }
-       _D("Polling alarm is set at every %d:%d",
-                       polling_time.tm_hour, polling_time.tm_min);
-
-       ret = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag);
-       if (ret != ALARMMGR_RESULT_SUCCESS) {
-               _E("alarmmgr_set_repeat_mode failed [%d]", ret);
-               goto out;
-       }
-
-       ret = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &polling_alarm_id);
-       if (ret != ALARMMGR_RESULT_SUCCESS) {
-               _E("alarmmgr_add_alarm_with_localtime failed [%d]", ret);
-               ret = -1;
-               goto out;
-       }
-       _D("alarm_id [%d]", polling_alarm_id);
-
-out:
-       if (alarm_info)
-               alarmmgr_free_alarm(alarm_info);
-
-       return ret;
-}
-#endif // SET_POLLING
-
-static int parse_and_set_firmware_info(char *json)
-{
-       char *token;
-       char *key, *value;
-       char *saveptr = NULL;
-
-       retvm_if(!json || *json != '{', false, "Invalid json format");
-
-       token = strtok_r(json, "\"", &saveptr);
-       while ((token = strtok_r(NULL, ",\"", &saveptr)) != NULL) {
-               if (*token == '}')
-                       break;
-               key = strdup(token);
-               token = strtok_r(NULL, ",\"", &saveptr);
-               if (!token || *token != ':') {
-                       _E("Invalid json format");
-                       free(key);
-                       return -1;
-               }
-
-               if (strlen(token) == 1) {
-                       token = strtok_r(NULL, "\"", &saveptr);
-                       if (!token) {
-                               _E("Invalid json format");
-                               free(key);
-                               return -1;
-                       }
-                       else if (*token == ',' || *token == '}')
-                               *token = 0;
-               } else {
-                       token++;
-               }
-               value = strdup(token);
-
-               _D("key: [%s], value: [%s]", key, value);
-
-               /* [TODO] Version check logic */
-               if (STR_EQ(key, "version")) {
-                       /* Not Server role? */
-                       if (STR_EMPTY(value))
-                               system_info_get_platform_string("http://tizen.org/system/build.release",
-                                               &value);
-                       if (update_info->new_version)
-                               free(update_info->new_version);
-                       update_info->new_version = strdup(value);
-               } else if (STR_EQ(key, "binaryUrl")) {
-                       if (update_info->package_uri)
-                               free(update_info->package_uri);
-                       update_info->package_uri = strdup(value);
-               }
-               else if (STR_EQ(key, "binarySize")) {
-                       update_info->package_size = atoi(value);
-               }
-
-               free(key);
-               free(value);
-       }
-
-       return 0;
-}
-
-static bool check_new_version(const char *current, const char* new)
-{
-       retvm_if(!current || !new, false, "Invalid parameter");
-       retvm_if(STR_EMPTY(current) || STR_EMPTY(new), false,
-                       "Invalid firmware version[%s, %s]", current, new);
-
-       _D("current version[%s], new version[%s]", current, new);
-
-       /*
-        * Version policy
-        *  - Default version format: YYYYMMDD.N
-        *  - The later date and bigger following number mean the new one
-        */
-
-       return (strncmp(current, new, strlen(current)) < 0);
-}
-
-static int parse_secure_url(char *json, char **url_value)
-{
-       char *ret;
-       char *saveptr = NULL;
-
-       retvm_if(!json || *json != '{' || *(json + 1) != '\"', false, "Invalid json format");
-
-       ret = strtok_r(json, "{\"", &saveptr);
-       retvm_if(!ret && !STR_EQ(ret, "url"), -1, "Invalid json(url)");
-
-       ret = strtok_r(NULL, "\"", &saveptr);
-       retvm_if(!ret && !STR_EQ(ret, ":"), -1, "Invalid json(:)");
-
-       ret = strtok_r(NULL, "\"", &saveptr);
-       retvm_if(!ret, -1, "Invalid json(end)");
-
-       *url_value = g_strdup(ret);
-
-       return 0;
-}
-
-static char *get_download_url(const char *uri)
-{
-       int ret = 0;
-       char *header = NULL;
-       char *body = NULL;
-       char *download_url = NULL;
-
-       ret = http_util_send_request(FMWUP_HTTP_GET, uri, &header, &body);
-       retvm_if(ret < 0, NULL, "Failed to get info including download uri[%d]", ret);
-
-       _D("header[%s], body[%s]", header, body);
-
-       /* Parsing URL */
-       /* {"url":"https://iotm-dev-fota.s3-a...} */
-       ret = parse_secure_url(body, &download_url);
-       if (ret < 0) {
-               _E("Failed to parse download url from body[%d]", ret);
-               G_FREE(download_url);
-       }
-
-       G_FREE(header);
-       G_FREE(body);
-
-       return download_url;
-}
-
-static int send_update_signal(char *package_path)
-{
-       GDBusConnection *conn;
-       GVariant *parameters = NULL;
-       GVariant *reply = NULL;
-       GError *error = NULL;
-       int ret = -1;
-
-       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-       if (error) {
-               _E("Failed to get dbus: %s", error->message);
-               g_error_free(error);
-               return -1;
-       }
-
-       parameters = g_variant_new("(s)", package_path);
-
-       reply = g_dbus_connection_call_sync(conn,
-                                           UPDATE_BUS_NAME,
-                                           UPDATE_OBJECT_PATH,
-                                           UPDATE_INTERFACE_NAME,
-                                           UPDATE_METHOD,
-                                           parameters,
-                                           G_VARIANT_TYPE("(i)"),
-                                           G_DBUS_CALL_FLAGS_NONE,
-                                           120000,
-                                           NULL,
-                                           &error);
-       if (error) {
-               _E("Failed to get reply: %s", error->message);
-               g_error_free(error);
-               goto exit;
-       }
-
-       g_variant_get(reply, "(i)", &ret);
-       _I("Update signal was sent: (%d)", ret);
-
-exit:
-       if (reply)
-               g_variant_unref(reply);
-       if (parameters)
-               g_variant_unref(parameters);
-
-       return ret;
-}
-
-API int update_control_initialize(void)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-#ifdef DEBUG_MODE
-       if (access(DEBUG_FLAG, F_OK) == 0) {
-               debug_mode = true;
-               _D("DEBUG_MODE: Calling test");
-
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       cloud_account = (struct _cloud_account *)malloc(sizeof(*cloud_account));
-       if (!cloud_account) {
-               _E("Failed to malloc");
-               return UPDATE_CONTROL_ERROR_OUT_OF_MEMORY;
-       }
-
-       cloud_account->access_token = NULL;
-       cloud_account->user_id = NULL;
-
-       update_info = (struct _update_info *)malloc(sizeof(*update_info));
-       if (!update_info) {
-               _E("Failed to malloc");
-               return UPDATE_CONTROL_ERROR_OUT_OF_MEMORY;
-       }
-
-       update_info->new_version = NULL;
-       update_info->package_uri = NULL;
-       update_info->package_size = 0;
-       update_info->updatable = 0;
-
-       get_cloud_accout();
-
-       init_update_alarm();
-
-#ifdef SET_POLLING
-       set_polling_alarm();
-#endif // SET_POLLING
-
-       return UPDATE_CONTROL_ERROR_NONE;
-}
-
-API int update_control_deinitialize(void)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-#ifdef DEBUG_MODE
-       if (debug_mode) {
-               _D("DEBUG_MODE: Calling test");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       int ret;
-
-       if (update_info->new_version)
-               free(update_info->new_version);
-       if (update_info->package_uri)
-               free(update_info->package_uri);
-       free(update_info);
-
-       if (reserved_update_alarm_id != -1) {
-               if ((ret = alarmmgr_remove_alarm(reserved_update_alarm_id)) < 0)
-                       _E("Failed to alarmmgr_remove_alarm: %d", ret);
-               reserved_update_alarm_id = -1;
-       }
-
-#ifdef SET_POLLING
-       if (polling_alarm_id != -1) {
-               if ((ret = alarmmgr_remove_alarm(polling_alarm_id)) < 0)
-                       _E("Failed to alarmmgr_remove_alarm: %d", ret);
-               polling_alarm_id = -1;
-       }
-#endif // SET_POLLING
-
-       return UPDATE_CONTROL_ERROR_NONE;
-}
-
-API int update_control_check_new_version(void)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-#ifdef DEBUG_MODE
-       if (debug_mode) {
-               _D("DEBUG_MODE: Calling test");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       int ret = UPDATE_CONTROL_ERROR_NONE;
-       char *device_type = NULL;
-       char *version = NULL;
-       char *res_header = NULL;
-       char *res_body = NULL;
-
-       retvm_if(!update_info, UPDATE_CONTROL_ERROR_SYSTEM_ERROR,
-                       "update controller not initialized");
-       update_info->updatable = 0;
-
-       ret = system_info_get_platform_string("http://tizen.org/system/model_name",
-                       &device_type);
-       if (ret != SYSTEM_INFO_ERROR_NONE) {
-               _E("Failed to get model_name [%d]", ret);
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto exit;
-       }
-       ret = system_info_get_platform_string("http://tizen.org/system/build.release",
-                       &version);
-       if (ret != SYSTEM_INFO_ERROR_NONE) {
-               _E("Failed to get build.release [%d]", ret);
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto exit;
-       }
-       _D("Device info: Device Type [%s], Version [%s]", device_type, version);
-
-       if (!cloud_account->access_token || STR_EMPTY(cloud_account->access_token)
-                       || !cloud_account->user_id || STR_EMPTY(cloud_account->user_id)) {
-               _D("The cloud account info is not set so request it. Try again later");
-               get_cloud_accout();
-               /* Wait for response from smartthings-thing */
-               ret = UPDATE_CONTROL_ERROR_CONNECTION_REFUSED;
-               goto exit;
-       } else {
-               _D("The cloud account is not empty: token = [%s], id = [%s]",
-                               cloud_account->access_token, cloud_account->user_id);
-       }
-
-       http_util_check_request_to_fota(cloud_account->user_id,
-                       cloud_account->access_token, device_type, version,
-                       &res_header, &res_body);
-       if (!res_body || STR_EMPTY(res_body)) {
-               _E("No response for check request.");
-               ret = UPDATE_CONTROL_ERROR_CONNECTION_REFUSED;
-               goto exit;
-       }
-       parse_and_set_firmware_info(res_body);
-
-       if (check_new_version(version, update_info->new_version)) {
-               _D("New version available. Download and update the firmware");
-               update_info->updatable = 1;
-       } else {
-               _D("Already latest version: %s", version);
-       }
-
-exit:
-       if (device_type)
-               free(device_type);
-       if (version)
-               free(version);
-       if (res_header)
-               free(res_header);
-       if (res_body)
-               free(res_body);
-
-       return ret;
-}
-
-API int update_control_download_package(void)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-#ifdef DEBUG_MODE
-       if (debug_mode) {
-               _D("DEBUG_MODE: Calling test");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       int ret = 0;
-       char *app_path = NULL;
-       char *download_url = NULL;
-       char *download_path = NULL;
-
-       /* Check new version should be preceded */
-       if (!update_info->package_uri || STR_EMPTY(update_info->package_uri)) {
-               _E("The package uri is empty. Check new version first");
-               return UPDATE_CONTROL_ERROR_INVALID_URI;
-       }
-
-       /* Check if the found version is newer */
-       if (!update_info->updatable) {
-               _D("Already latest version");
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-       }
-
-       /* Downloading state */
-       _D("Download package from [%s]", update_info->package_uri);
-
-       app_path = app_get_data_path();
-       retvm_if(!app_path, UPDATE_CONTROL_ERROR_SYSTEM_ERROR,
-                       "Failed to app_get_data_path");
-       download_url = get_download_url(update_info->package_uri);
-       download_path = g_strconcat(app_path, FIRMWARE_FILE_NAME, NULL);
-
-       if (!download_url) {
-               _E("Failed to get download url");
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto exit;
-       }
-       if (!download_path) {
-               _E("Failed to compose download path");
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto exit;
-       }
-
-       _I("Download url[%s] download path[%s]", download_url, download_path);
-
-       ret = http_util_download_file((const char *)download_url, (const char *)download_path,
-                       update_info->package_size);
-       if (ret < 0) {
-               _E("Failed to download firmware[%d]", ret);
-               ret = UPDATE_CONTROL_ERROR_CONNECTION_REFUSED;
-               goto exit;
-       }
-
-       package_downloaded = true;
-
-exit:
-       free(app_path);
-       G_FREE(download_url);
-       G_FREE(download_path);
-
-       return ret;
-}
-
-API int update_control_do_update(void)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-#ifdef DEBUG_MODE
-       if (debug_mode) {
-               _D("DEBUG_MODE: Calling test");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       char *app_path = NULL;
-       char *path = NULL;
-
-       if (!package_downloaded) {
-               _E("Update package does not exist. Download it first");
-               return UPDATE_CONTROL_ERROR_INVALID_PACKAGE;
-       }
-
-       /* TODO: Check privilege */
-
-       _D("Firmware Updating...");
-
-       app_path = app_get_data_path();
-       retvm_if(!app_path, UPDATE_CONTROL_ERROR_SYSTEM_ERROR,
-                       "Failed to app_get_data_path");
-       path = g_strconcat(app_path, FIRMWARE_FILE_NAME, NULL);
-       if (!path) {
-               _E("Failed to g_strconcat");
-               free(app_path);
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-       }
-
-       /* DBus activation */
-       send_update_signal(path);
-
-       /* Wait for update reboot */
-       sleep(180);
-
-       /* Should be unreachable */
-       _E("Update reboot timed out");
-
-       free(app_path);
-       G_FREE(path);
-
-       return UPDATE_CONTROL_ERROR_TIMED_OUT;
-}
-
-API int update_control_make_reservation(struct tm *reservation_time)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-       retvm_if(!reservation_time, UPDATE_CONTROL_ERROR_INVALID_PARAMETER,
-                       "reservation_time is NULL");
-
-#ifdef DEBUG_MODE
-       if (debug_mode) {
-               _D("DEBUG_MODE: Calling test");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       int ret;
-       alarm_date_t alarm_time;
-       alarm_entry_t *alarm_info = NULL;
-
-       alarm_info = alarmmgr_create_alarm();
-       if (alarm_info == NULL) {
-               _E("alarmmgr_create_alarm failed");
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-       }
-
-       alarm_time.year = reservation_time->tm_year + 1900;
-       alarm_time.month = reservation_time->tm_mon + 1;
-       alarm_time.day = reservation_time->tm_mday;
-       alarm_time.hour = reservation_time->tm_hour;
-       alarm_time.min = reservation_time->tm_min;
-       alarm_time.sec = reservation_time->tm_sec;
-
-       ret = alarmmgr_set_time(alarm_info, alarm_time);
-       if (ret != ALARMMGR_RESULT_SUCCESS) {
-               _E("alarmmgr_set_time failed [%d]", ret);
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto out;
-       }
-
-       ret = alarmmgr_set_type(alarm_info, ALARM_TYPE_VOLATILE);
-       if (ret != ALARMMGR_RESULT_SUCCESS) {
-               _E("alarmmgr_set_type failed [%d]", ret);
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto out;
-       }
-
-       ret = alarmmgr_add_alarm_with_localtime(alarm_info, NULL, &reserved_update_alarm_id);
-       if (ret != ALARMMGR_RESULT_SUCCESS) {
-               _E("alarmmgr_add_alarm_with_localtime failed [%d]", ret);
-               ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               goto out;
-       }
-       _D("alarm_id [%d]", reserved_update_alarm_id);
-
-       ret = UPDATE_CONTROL_ERROR_NONE;
-out:
-       if (alarm_info)
-               alarmmgr_free_alarm(alarm_info);
-
-       return ret;
-}
-
-API int update_control_cancel_reservation(void)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-#ifdef DEBUG_MODE
-       if (debug_mode) {
-               _D("DEBUG_MODE: Calling test");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-#endif
-
-       int ret = 0;
-
-       if (reserved_update_alarm_id == -1) {
-               _I("No reserved update");
-               return UPDATE_CONTROL_ERROR_NONE;
-       }
-       _D("Update reservation found. Cancel it");
-
-       ret = alarmmgr_remove_alarm(reserved_update_alarm_id);
-       if (ret < 0) {
-               _E("alarmmgr_remove_alarm failed [%d]", ret);
-               return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-       }
-       reserved_update_alarm_id = -1;
-
-       return UPDATE_CONTROL_ERROR_NONE;
-}
-
-API int update_control_get_property(update_control_property_e property, void **value)
-{
-       _D("FN CALLED>>>>>>>>>>>>>>>>>>");
-
-       retvm_if(!value, UPDATE_CONTROL_ERROR_INVALID_PARAMETER,
-                       "value is NULL");
-
-#ifdef DEBUG_MODE
-       if (debug_mode)
-               switch (property) {
-               case UPDATE_CONTROL_PROPERTY_NEW_VERSION:
-               case UPDATE_CONTROL_PROPERTY_PACKAGE_URI:
-               case UPDATE_CONTROL_PROPERTY_RESULT:
-               case UPDATE_CONTROL_PROPERTY_PACKAGE_SIZE:
-               case UPDATE_CONTROL_PROPERTY_DESCRIPTION:
-               case UPDATE_CONTROL_PROPERTY_UPDATE_AVAILABLE:
-                       _D("DEBUG_MODE: Calling test");
-                       return UPDATE_CONTROL_ERROR_NONE;
-               default:
-                       _E("Not supported property key: %d", property);
-                       return UPDATE_CONTROL_ERROR_KEY_NOT_FOUND;
-               }
-#endif
-
-       int ret = UPDATE_CONTROL_ERROR_NONE;
-
-       switch (property) {
-       case UPDATE_CONTROL_PROPERTY_NEW_VERSION:
-               if (update_info->new_version)
-                       *value = (void *)strdup(update_info->new_version);
-               else
-                       _D("New version is NULL");
-               break;
-       case UPDATE_CONTROL_PROPERTY_PACKAGE_URI:
-               if (update_info->package_uri)
-                       *value = (void *)strdup(update_info->package_uri);
-               else
-                       _D("Package URI is NULL");
-               break;
-       case UPDATE_CONTROL_PROPERTY_PACKAGE_SIZE:
-               if (update_info->package_size) {
-                       *value = malloc(sizeof(int));
-                       if (!*value) {
-                               _E("Failed to malloc");
-                               return UPDATE_CONTROL_ERROR_OUT_OF_MEMORY;
-                       }
-
-                       *(int *)(*value) = update_info->package_size;
-               } else {
-                       _D("Package size is not set");
-               }
-               break;
-       case UPDATE_CONTROL_PROPERTY_RESULT:
-       {
-               *value = malloc(sizeof(int));
-               if (!*value) {
-                       _E("Failed to malloc");
-                       return UPDATE_CONTROL_ERROR_OUT_OF_MEMORY;
-               }
-
-               int r = hal_device_board_get_upgrade_status(*value);
-               if (r >= 0) {
-                       ret = UPDATE_CONTROL_ERROR_NONE;
-                       break;
-               }
-
-               free(*value);
-
-               if (r == -ENODEV) {
-                       _E("get_upgrade_status not implemented in HAL");
-                       ret = UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-               } else {
-                       _E("Unable to get upgrade progress from HAL");
-                       ret = UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               }
-               break;
-       }
-       case UPDATE_CONTROL_PROPERTY_DESCRIPTION:
-               _D("Not implemented for key: %d", property);
-               ret = UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-               break;
-       case UPDATE_CONTROL_PROPERTY_UPDATE_AVAILABLE:
-               *value = malloc(sizeof(int));
-               if (!*value) {
-                       _E("Failed to malloc");
-                       return UPDATE_CONTROL_ERROR_OUT_OF_MEMORY;
-               }
-
-               *(int *)(*value) = update_info->updatable;
-               break;
-       default:
-               _E("Not supported property key: %d", property);
-               ret = UPDATE_CONTROL_ERROR_KEY_NOT_FOUND;
-               break;
-       }
-
-       return ret;
-}
diff --git a/src/plugin/plugin.h b/src/plugin/plugin.h
deleted file mode 100644 (file)
index e09a833..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 __TIZEN_SYSTEM_UPDATE_CONTROL_COMMON_H__
-#define __TIZEN_SYSTEM_UPDATE_CONTROL_COMMON_H__
-
-#include <dlog.h>
-#include <glib.h>
-#include <gio/gio.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#undef LOG_TAG
-#define LOG_TAG "CAPI_UPDATE_CONTROL_PLUGIN"
-#define _D(fmt, args...)   SLOGD(fmt, ##args)
-#define _E(fmt, args...)   SLOGE(fmt, ##args)
-#define _I(fmt, args...)   SLOGI(fmt, ##args)
-#define STR_EQ(X, Y) (g_strcmp0((X), (Y)) == 0)
-#define STR_EMPTY(X) STR_EQ((X), "")
-
-#define G_FREE(p) do { if (p) { g_free(p); p = NULL; } } while (0);
-
-#define retm_if(expr, fmt, arg...) \
-       do { if (expr) { _E(fmt, ##arg); return; } } while (0)
-
-#define retvm_if(expr, val, fmt, arg...) \
-       do { if (expr) { _E(fmt, ##arg); return (val); } } while (0)
-
-#define retvmf_if(expr, val, func, fmt, arg...) \
-       do { if (expr) { _E(fmt, ##arg); func; return (val); } } while (0)
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_SYSTEM_UPDATE_CONTROL_COMMON_H__ */
index b154f19f3e903c33e0cf12c1127ac984d6dfccaa..efa87906ae0a9b14b00d31647639d2e727468b5a 100644 (file)
 #include <unistd.h>
 #include "update_control_internal.h"
 
+#include <system/syscommon-plugin-update-control.h>
+#include <system/syscommon-plugin-update-control-interface.h>
+
+
 #ifndef API
 #define API __attribute__ ((visibility("default")))
 #endif
 
-#define UPDATE_CONTROL_PLUGIN PLUGIN_PATH"/libupdate-control-plugin.so"
-
 static bool initialized = false;
-static void *plugin_handle = NULL;
+static bool plugin_found = false;
 static OrgTizenUpdateManager *proxy = NULL;
 
 API int update_control_initialize(void)
@@ -33,8 +35,7 @@ API int update_control_initialize(void)
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
        _I("update_control_initialize called");
 
-       int ret = 0;
-       int (*plugin_update_control_initialize)(void) = NULL;
+       int ret, plugin_exists;
        GError *error = NULL;
 
        if (initialized) {
@@ -54,28 +55,23 @@ API int update_control_initialize(void)
 
        g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(proxy), DBUS_PROXY_TIMEOUT);
 
-       if (access(UPDATE_CONTROL_PLUGIN, F_OK) == 0) {
-               _I("Success to find update control plugin");
-
-               plugin_handle = dlopen(UPDATE_CONTROL_PLUGIN, RTLD_NOW);
-               if (!plugin_handle) {
-                       _E("dlopen failed: %s", dlerror());
-                       return UPDATE_CONTROL_ERROR_SYSTEM_ERROR;
-               }
+       ret = syscommon_plugin_update_control_get_backend(&plugin_exists);
+       if (ret < 0) {
+               _E("Unable to load the plugin. dlopen() or dlsym() likely failed, error: %d", ret);
+               return ret;
+       }
 
-               plugin_update_control_initialize = dlsym(plugin_handle, "update_control_initialize");
-               if (!plugin_update_control_initialize) {
-                       _E("dlsym failed: %s", dlerror());
-                       return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-               }
+       plugin_found = (bool)plugin_exists;
 
-               ret = plugin_update_control_initialize();
-               if (ret != UPDATE_CONTROL_ERROR_NONE) {
-                       _E("update_control_initialize error: %d", ret);
+       if (plugin_found) {
+               _I("Successfully loaded the plugin. Begin initializing");
+               ret = syscommon_plugin_update_control_initialize();
+               if (ret < 0) {
+                       _E("Unable to initialize plugin data, error: %d", ret);
                        return ret;
                }
        } else {
-               _I("Failed to find update control plugin, passed");
+               _I("Failed to find update-control plugin, passed");
        }
 
        initialized = true;
@@ -87,8 +83,7 @@ API int update_control_deinitialize(void)
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
        _I("update_control_deinitialize called");
 
-       int ret = 0;
-       int (*plugin_update_control_deinitialize)(void) = NULL;
+       int ret;
 
        if (!initialized) {
                _D("Not initialized");
@@ -101,28 +96,19 @@ API int update_control_deinitialize(void)
                _I("Success to unref proxy");
        }
 
-       if (plugin_handle) {
+       if (plugin_found) {
                _I("Success to find initialized plugin");
-
-               plugin_update_control_deinitialize = dlsym(plugin_handle, "update_control_deinitialize");
-               if (!plugin_update_control_deinitialize) {
-                       _E("dlsym failed: %s", dlerror());
-                       return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-               }
-
-               ret = plugin_update_control_deinitialize();
-               if (ret != UPDATE_CONTROL_ERROR_NONE) {
-                       _E("update_control_deinitialize error: %d", ret);
+               ret = syscommon_plugin_update_control_deinitialize();
+               if (ret <  0) {
+                       _E("Plugin deinitialize error: %d", ret);
                        return ret;
                }
-
-               dlclose(plugin_handle);
-               plugin_handle = NULL;
        } else {
                _I("Failed to find initialized plugin, passed");
        }
 
        initialized = false;
+       plugin_found = false;
        return UPDATE_CONTROL_ERROR_NONE;
 }
 
@@ -130,56 +116,24 @@ API int update_control_check_new_version(void)
 {
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
 
-       int ret;
-       int (*plugin_update_control_check_new_version)(void) = NULL;
-
-       if (!plugin_handle) {
-               _E("plugin not opened");
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
-
-       plugin_update_control_check_new_version = dlsym(plugin_handle,
-                       "update_control_check_new_version");
-       if (!plugin_update_control_check_new_version) {
-               _E("dlsym failed: %s", dlerror());
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       int ret = syscommon_plugin_update_control_check_new_version();
 
-       ret = plugin_update_control_check_new_version();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               _E("update_control_check_new_version error: %d", ret);
-               return ret;
-       }
+       if (ret < 0)
+               _E("Failed to update_control_check_new_version, error: %d", ret);
 
-       return UPDATE_CONTROL_ERROR_NONE;
+       return ret;
 }
 
 API int update_control_download_package(void)
 {
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
 
-       int ret;
-       int (*plugin_update_control_download_package)(void) = NULL;
-
-       if (!plugin_handle) {
-               _E("plugin not opened");
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       int ret = syscommon_plugin_update_control_download_package();
 
-       plugin_update_control_download_package = dlsym(plugin_handle,
-                       "update_control_download_package");
-       if (!plugin_update_control_download_package) {
-               _E("dlsym failed: %s", dlerror());
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       if (ret < 0)
+               _E("Failed to update_control_download_package, error: %d", ret);
 
-       ret = plugin_update_control_download_package();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               _E("update_control_download_package error: %d", ret);
-               return ret;
-       }
-
-       return UPDATE_CONTROL_ERROR_NONE;
+       return ret;
 }
 
 API int update_control_do_update(void)
@@ -216,56 +170,24 @@ API int update_control_make_reservation(struct tm *reservation_time)
 {
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
 
-       int ret;
-       int (*plugin_update_control_make_reservation)(struct tm *) = NULL;
-
-       if (!plugin_handle) {
-               _E("plugin not opened");
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
-
-       plugin_update_control_make_reservation = dlsym(plugin_handle,
-                       "update_control_make_reservation");
-       if (!plugin_update_control_make_reservation) {
-               _E("dlsym failed: %s", dlerror());
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       int ret = syscommon_plugin_update_control_make_reservation(reservation_time);
 
-       ret = plugin_update_control_make_reservation(reservation_time);
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               _E("update_control_make_reservation error: %d", ret);
-               return ret;
-       }
+       if (ret < 0)
+               _E("Failed to update_control_make_reservation, error: %d", ret);
 
-       return UPDATE_CONTROL_ERROR_NONE;
+       return ret;
 }
 
 API int update_control_cancel_reservation(void)
 {
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
 
-       int ret;
-       int (*plugin_update_control_cancel_reservation)(void) = NULL;
+       int ret = syscommon_plugin_update_control_cancel_reservation();
 
-       if (!plugin_handle) {
-               _E("plugin not opened");
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       if (ret < 0)
+               _E("Failed to update_control_cancel_reservation, error: %d", ret);
 
-       plugin_update_control_cancel_reservation = dlsym(plugin_handle,
-                       "update_control_cancel_reservation");
-       if (!plugin_update_control_cancel_reservation) {
-               _E("dlsym failed: %s", dlerror());
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
-
-       ret = plugin_update_control_cancel_reservation();
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               _E("update_control_cancel_reservation error: %d", ret);
-               return ret;
-       }
-
-       return UPDATE_CONTROL_ERROR_NONE;
+       return ret;
 }
 
 API int update_control_get_property(update_control_property_e property, void **value)
@@ -273,25 +195,11 @@ API int update_control_get_property(update_control_property_e property, void **v
        CHECK_FEATURE_SUPPORTED(DEVICE_UPDATE_FEATURE);
        _I("update_control_get_property called");
 
-       int ret = 0;
-       int (*plugin_update_control_get_property)(update_control_property_e, void **) = NULL;
+       int ret = syscommon_plugin_update_control_get_property(
+               (syscommon_update_control_property_e)property, value);
 
-       if (!plugin_handle) {
-               _E("plugin not opened");
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
+       if (ret < 0)
+               _E("Failed to syscommon_plugin_update_control_get_property, error: %d", ret);
 
-       plugin_update_control_get_property = dlsym(plugin_handle, "update_control_get_property");
-       if (!plugin_update_control_get_property) {
-               _E("dlsym failed: %s", dlerror());
-               return UPDATE_CONTROL_ERROR_INVALID_OPERATION;
-       }
-
-       ret = plugin_update_control_get_property(property, value);
-       if (ret != UPDATE_CONTROL_ERROR_NONE) {
-               _E("update_control_get_property error: %d", ret);
-               return ret;
-       }
-
-       return UPDATE_CONTROL_ERROR_NONE;
+       return ret;
 }