Update source from tizen 2.3 80/32980/3
authorSangyoon Jang <s89.jang@samsung.com>
Wed, 31 Dec 2014 08:40:44 +0000 (17:40 +0900)
committerSangyoon Jang <s89.jang@samsung.com>
Wed, 31 Dec 2014 08:43:47 +0000 (17:43 +0900)
to support install native application(.tpk)
note that the rpm-installer will be deprecated and we are going to prepare a new native application installer for "app-installers"

Change-Id: I10c02a3ff745899b40542aa623d7b0fbd7912ffc
Signed-off-by: Sangyoon Jang <s89.jang@samsung.com>
61 files changed:
CMakeLists.txt
backend-lib/inc/librpminternals.h
backend-lib/src/librpm.c
backend-lib/src/librpminternals.c
backend/inc/coretpk-installer.h [new file with mode: 0644]
backend/inc/rpm-installer.h
backend/scripts/coretpk_category_converter.sh.in [new file with mode: 0644]
backend/scripts/coretpk_ro_xml_converter.sh.in [new file with mode: 0644]
backend/scripts/coretpk_rw_xml_converter.sh.in [new file with mode: 0644]
backend/scripts/cpio_rpm_package.sh.in [new file with mode: 0755]
backend/scripts/cpio_rpm_package_update_xml.sh.in [new file with mode: 0644]
backend/scripts/install_rpm_package.sh.in
backend/scripts/install_rpm_package_with_dbpath_ro.sh.in [new file with mode: 0644]
backend/scripts/install_rpm_package_with_dbpath_rw.sh.in [new file with mode: 0644]
backend/scripts/query_rpm_package.sh.in
backend/scripts/rpm_update_xml.sh.in [new file with mode: 0644]
backend/scripts/uninstall_rpm_package.sh.in
backend/scripts/upgrade_rpm_package.sh.in
backend/scripts/upgrade_rpm_package_with_dbpath_ro.sh.in [new file with mode: 0644]
backend/scripts/upgrade_rpm_package_with_dbpath_rw.sh.in [new file with mode: 0644]
backend/src/core/rpm-installer-core.c [deleted file]
backend/src/coretpk/coretpk-installer.c [new file with mode: 0755]
backend/src/coretpk/inc/coretpk-installer-internal.h [new file with mode: 0644]
backend/src/coretpk/inc/coretpk-installer-type.h [new file with mode: 0644]
backend/src/coretpk/xml-parser/coretpk-parser-hybrid.c [new file with mode: 0755]
backend/src/coretpk/xml-parser/dummy [new file with mode: 0644]
backend/src/rpm/inc/rpm-installer-privilege.h [moved from frontend/ui/include/rpm-homeview.h with 52% similarity, mode: 0644]
backend/src/rpm/inc/rpm-installer-signature.h [new file with mode: 0755]
backend/src/rpm/inc/rpm-installer-type.h [new file with mode: 0644]
backend/src/rpm/rpm-installer-core.c [new file with mode: 0755]
backend/src/rpm/rpm-installer-privilege.c [new file with mode: 0755]
backend/src/rpm/rpm-installer-signature.c [new file with mode: 0755]
backend/src/rpm/rpm-installer-tool.c [moved from backend/src/core/rpm-installer-tool.c with 56% similarity]
backend/src/rpm/rpm-installer.c
backend/src/vconf/rpm-vconf-intf.c
common/CMakeLists.txt
common/rpm-installer-util.c
debian/control
debian/rpm-installer.install.in
debian/rules
frontend/CMakeLists.txt
frontend/coretpk-installer-config.ini [new file with mode: 0644]
frontend/inc/rpm-frontend.h
frontend/rpm-installer-config.ini [new file with mode: 0644]
frontend/src/rpm-appcore-intf.c
frontend/src/rpm-cmdline.c
frontend/ui/src/rpm-homeview.c [deleted file]
inc/rpm-installer-util.h
packaging/rpm-installer.changes [deleted file]
packaging/rpm-installer.manifest [deleted file]
packaging/rpm-installer.spec
po/CMakeLists.txt [deleted file]
po/POTFILES.in [deleted file]
po/en_GB.po [deleted file]
po/en_US.po [deleted file]
po/ja_JP.po [deleted file]
po/ko_KR.po [deleted file]
po/update-po.sh [deleted file]
po/zh_CN.po [deleted file]
rpm-installer.manifest [new file with mode: 0644]
rpm_installer_deactvation_list.txt.in [new file with mode: 0644]

index 7a2b4b3..b2d1b14 100755 (executable)
@@ -16,11 +16,12 @@ SET(VERSION 1.0)
 
 set(CMAKE_SKIP_BUILD_RPATH true)
 
+configure_file(rpm_installer_deactvation_list.txt.in rpm_installer_deactvation_list.txt @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/rpm_installer_deactvation_list.txt DESTINATION /opt/share/packages/.pkgmgr/rpm-installer/)
+
 ##################
 ## build comm libraries
 add_subdirectory(common)
 add_subdirectory(frontend)
-add_subdirectory(po)
 add_subdirectory(backend-lib)
 ##################
-
index acdd4d2..ed2b385 100755 (executable)
 #include <sys/types.h>
 #include <dirent.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
 #define API __attribute__ ((visibility("default")))
 #define DEBUG_ERR      0x0001
 #define DEBUG_INFO     0x0002
 #define LIKELY(expr) __builtin_expect((expr), 1)
 #define UNLIKELY(expr) __builtin_expect((expr), 0)
 
-void _librpm_print_msg(int type, int exetype, char *format, ...);
-#define _librpm_print(type, fmtstr, args...) { \
-_librpm_print_msg(type, LIBRPM_LOG, "%s():%d: " fmtstr, \
-__func__, __LINE__, ##args); \
-}
-
-int _librpm_get_package_header_info(char *pkg_path,
+int _librpm_get_package_header_info(const char *pkg_path,
                        package_manager_pkg_detail_info_t *pkg_detail_info);
-int _librpm_get_installed_package_info(char *pkgid,
+int _librpm_get_installed_package_info(const char *pkgid,
                        package_manager_pkg_detail_info_t *pkg_detail_info);
-int _librpm_app_is_installed(char *pkgid);
-long long _librpm_calculate_dir_size(char *dirname);
+int _librpm_app_is_installed(const char *pkgid);
+long long _librpm_calculate_dir_size(const char *dirname);
 
 #ifdef __cplusplus
 }
index fd12ac6..ace2bb2 100755 (executable)
 #include <rpmts.h>
 #include <rpmdb.h>
 #include <vconf.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <ctype.h>
 
 /* For multi-user support */
 #include <tzplatform_config.h>
 
 #include "librpminternals.h"
+#include "rpm-installer-util.h"
 
 #define BASEDIR                                                tzplatform_getenv(TZ_SYS_SHARE)
-#define USER_APP_FOLDER                                tzplatform_getenv(TZ_USER_APP)
-#define BUFFSIZE                                               256
+#define USER_APP_FOLDER                                        tzplatform_getenv(TZ_USER_APP)
+#define BUFFSIZE                                               1024
+
+static int __xsystem(const char *argv[])
+{
+       int status = 0;
+       pid_t pid;
+       pid = fork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+       return WEXITSTATUS(status);
+}
+
+static void __str_trim(char *input)
+{
+       char *trim_str = input;
+
+       if (input == NULL)
+               return;
+
+       while (*input != 0) {
+               if (!isspace(*input)) {
+                       *trim_str = *input;
+                       trim_str++;
+               }
+               input++;
+       }
+
+       *trim_str = 0;
+       return;
+}
+
+static char *__get_value(const char *pBuf, const char *pKey, int seperator)
+{
+       const char *p = NULL;
+       const char *pStart = NULL;
+       const char *pEnd = NULL;
+
+       p = strstr(pBuf, pKey);
+       if (p == NULL)
+               return NULL;
+
+       pStart = p + strlen(pKey) + 1;
+       pEnd = strchr(pStart, seperator);
+       if (pEnd == NULL)
+               return NULL;
+
+       size_t len = pEnd - pStart;
+       if (len <= 0)
+               return NULL;
+
+       char *pRes = (char*)malloc(len + 1);
+       if(pRes == NULL){
+               _LOGE("malloc() failed.");
+               return NULL;
+       }
+
+       strncpy(pRes, pStart, len);
+       pRes[len] = 0;
+
+       _LOGD("key = [%s], value = [%s]", pKey, pRes);
+       return pRes;
+}
+
+static int __read_pkg_detail_info(const char *pkg_path, const char *manifest, package_manager_pkg_detail_info_t *pkg_detail_info)
+{
+       int ret = 0;
+       FILE *fp = NULL;
+       char buf[BUFFSIZE] = {0};
+       char icon_path[BUFFSIZE] = {0};
+       char *pkgid = NULL;
+       char *version = NULL;
+       char *label = NULL;
+       char *icon = NULL;
+//     char *api_version = NULL;
+
+       if(pkg_detail_info == NULL){
+               _LOGE("pkg_details_info is NULL");
+               return -1;
+       }
+
+       fp = fopen(manifest, "r");
+       if (fp == NULL) {
+               _LOGE("fopen(%s) failed.", manifest);
+               return -1;
+       }
+
+       while (fgets(buf, BUFFSIZE, fp) != NULL) {
+               __str_trim(buf);
+
+               if (strstr(buf, "?xml") != NULL)
+               {
+                       memset(buf, 0x00, BUFFSIZE);
+                       continue;
+               }
+
+               if (pkgid == NULL) {
+                       pkgid = __get_value(buf, "package=", '"');
+               }
+
+               if (version == NULL) {
+                       version = strstr(buf, "version=");
+                       /* if the result substring is "api-version", search again */
+                       if (buf != version && *(char *)(version - 1) == '-') {
+                               version = version + strlen("api-version=");
+                               version = __get_value(version, "version=", '"');
+                       } else {
+                               version = __get_value(buf, "version=", '"');
+                       }
+               }
+/*
+               if (api_version == NULL) {
+                       api_version = __get_value(buf, "api-version=", '"');
+               }
+*/
+               if (label == NULL) {
+                       label = __get_value(buf, "<label", '<');
+               }
+
+               if (icon == NULL) {
+                       icon = __get_value(buf, "<icon", '<');
+               }
+
+               char *privilege = __get_value(buf, "<privilege", '<');
+               if (privilege != NULL) {
+                       pkg_detail_info->privilege_list = g_list_append(pkg_detail_info->privilege_list, privilege);
+               }
+
+               memset(buf, 0x00, BUFFSIZE);
+       }
+       fclose(fp);
+
+       strncpy(pkg_detail_info->pkg_type, "coretpk", strlen("coretpk"));
+
+       if (pkgid) {
+               strncpy(pkg_detail_info->pkgid, pkgid, strlen(pkgid));
+               strncpy(pkg_detail_info->pkg_name, pkgid, strlen(pkgid));
+
+               free(pkgid);
+       }
+
+       if (version) {
+               strncpy(pkg_detail_info->version, version, strlen(version));
+
+               free(version);
+       }
+/*
+       if (api_version) {
+               strncpy(pkg_detail_info->api_version, api_version, strlen(api_version));
+
+               free(api_version);
+       }
+*/
+       if (label) {
+               strncpy(pkg_detail_info->label, label, strlen(label));
+
+               free(label);
+       }
+
+       if (icon) {
+               snprintf(icon_path, BUFFSIZE, "shared/res/%s", icon);
+               const char *unzip_icon_argv[] = { "/usr/bin/unzip", pkg_path, icon_path, "-d", "/tmp/coretpk-unzip", NULL };
+
+               ret = __xsystem(unzip_icon_argv);
+               if (ret == 0) {
+                       struct stat fileinfo;
+
+                       memset(icon_path, 0x00, BUFFSIZE);
+                       snprintf(icon_path, BUFFSIZE, "/tmp/coretpk-unzip/shared/res/%s", icon);
+
+                       if (lstat(icon_path, &fileinfo) < 0) {
+                               _LOGE("lstat(%s) failed.", icon_path);
+                       } else {
+                               FILE *icon_fp = NULL;
+                               pkg_detail_info->icon_size = fileinfo.st_size + 1;
+                               pkg_detail_info->icon_buf = (char*) calloc(1, (sizeof(char) * pkg_detail_info->icon_size));
+                               if(pkg_detail_info->icon_buf == NULL){
+                                       _LOGE("calloc failed!!");
+                                       free(icon);
+                                       return -1;
+                               }
+
+                               icon_fp = fopen(icon_path, "r");
+                               if (icon_fp) {
+                                       int readbyte = fread(pkg_detail_info->icon_buf, 1, pkg_detail_info->icon_size - 1, icon_fp);
+                                       _LOGD("icon_size = [%d], readbyte = [%d]", pkg_detail_info->icon_size, readbyte);
+
+                                       fclose(icon_fp);
+                               } else {
+                                       _LOGE("fopen(%s) failed.", icon_path);
+                               }
+                       }
+               } else {
+                       _LOGE("unzip(%s) failed.", icon_path);
+               }
+
+               free(icon);
+       }
+
+       return 0;
+}
+
+static int __is_core_tpk_app(const char *pkg_path, package_manager_pkg_detail_info_t *pkg_detail_info)
+{
+       int ret = 0;
+       const char *unzip_argv[] = { "/usr/bin/unzip", pkg_path, "tizen-manifest.xml", "-d", "/tmp/coretpk-unzip", NULL };
+       const char *delete_argv[] = { "/bin/rm", "-rf", "/tmp/coretpk-unzip", NULL };
+
+       __xsystem(delete_argv);
+
+       ret = mkdir("/tmp/coretpk-unzip", 0755);
+       if (ret != 0) {
+               _LOGE("mkdir(/tmp/coretpk-unzip) failed.");
+               return -1;
+       }
+
+       /* In case of installation request, pkgid contains the pkgpath */
+       ret = __xsystem(unzip_argv);
+       if (ret == 0) {
+               _LOGD("[%s] is core-tpk.", pkg_path);
+
+               if (access("/tmp/coretpk-unzip/tizen-manifest.xml", R_OK) == 0) {
+                       _LOGD("tizen-manifest.xml is found.");
+               } else {
+                       _LOGE("tizen-manifest.xml is not found.");
+                       __xsystem(delete_argv);
+                       return -1;
+               }
+
+               ret = __read_pkg_detail_info(pkg_path, "/tmp/coretpk-unzip/tizen-manifest.xml", pkg_detail_info);
+               if (ret != 0) {
+                       _LOGE("__read_pkg_detail_info() failed. [%s]", pkg_path);
+                       __xsystem(delete_argv);
+                       return -1;
+               }
+
+               ret = 1;
+       } else {
+               _LOGE("[%s] is not core-tpk.", pkg_path);
+               ret = -1;
+       }
+
+       __xsystem(delete_argv);
+       return ret;
+}
 
 void pkg_native_plugin_on_unload(void)
 {
+       _LOGD("pkg_native_plugin_on_unload() is called.");
+
        return;
 }
 
 int pkg_plugin_app_is_installed(const char *pkgid)
 {
-       _librpm_print(DEBUG_INFO,
-                     "pkg_plugin_app_is_installed() is called\n");
-       /* Check for valid arguments */
        if (pkgid == NULL) {
-               _librpm_print(DEBUG_ERR,
-                             "[pkg_plugin_get_app_detail_info_from_package] "
-                             "args supplied is NULL\n");
+               _LOGE("pkgid is NULL.");
                return LIBRPM_ERROR;
        }
+
+       _LOGD("pkg_plugin_app_is_installed(%s) is called.", pkgid);
+
        int ret = -1;
        ret = _librpm_app_is_installed(pkgid);
        if (ret == -1) {
-               _librpm_print(DEBUG_ERR, "_librpm_app_is_installed() failed\n");
+               _LOGE("_librpm_app_is_installed(%s) failed.", pkgid);
                return LIBRPM_ERROR;
        }
-       /*1 for installed, 0 for not installed*/
-       if (ret == 1)
+
+       // 1 for installed, 0 for not installed
+       if (ret == 1) {
+               _LOGD("pkgid[%s] is installed.", pkgid);
                return LIBRPM_SUCCESS;
-       else
+       }
+       else {
+               _LOGD("pkgid[%s] is not installed.", pkgid);
                return LIBRPM_ERROR;
+       }
 }
 
-int pkg_plugin_get_installed_apps_list(const char *category,
-                                      const char *option,
-                                      package_manager_pkg_info_t **list,
-                                      int *count)
+int pkg_plugin_get_installed_apps_list(const char *category, const char *option, package_manager_pkg_info_t **list, int *count)
 {
+       _LOGD("pkg_plugin_get_installed_apps_list() is called.");
+
        return LIBRPM_SUCCESS;
 }
 
-int pkg_plugin_get_app_detail_info(const char *pkgid,
-                                  package_manager_pkg_detail_info_t
-                                  *pkg_detail_info)
+int pkg_plugin_get_app_detail_info(const char *pkgid, package_manager_pkg_detail_info_t *pkg_detail_info)
 {
-       _librpm_print(DEBUG_INFO,
-                     "pkg_plugin_get_app_detail_info() is called\n");
-       /* Check for valid arguments */
        if (pkgid == NULL || pkg_detail_info == NULL) {
-               _librpm_print(DEBUG_ERR,
-                             "[pkg_plugin_get_app_detail_info_from_package] "
-                             "args supplied is NULL\n");
+               _LOGE("pkgid or pkg_detail_info is NULL.");
                return LIBRPM_ERROR;
        }
-       char dirname[BUFFSIZE] = { '\0' };
+
+       _LOGD("pkg_plugin_get_app_detail_info(%s) is called.", pkgid);
+
        int ret = 0;
+       char dirname[BUFFSIZE] = {'\0'};
        long long data_size = 0;
-       char buff[256] = {'\0'};
+       char buff[BUFFSIZE] = {'\0'};
        time_t install_time = 0;
 
        /* pkgtype is by default rpm */
@@ -103,20 +373,19 @@ int pkg_plugin_get_app_detail_info(const char *pkgid,
        /* Get the installed package info from rpm db */
        ret = _librpm_get_installed_package_info(pkgid, pkg_detail_info);
        if (ret) {
+               _LOGE("_librpm_get_installed_package_info(%s) failed.", pkgid);
                return LIBRPM_ERROR;
        }
 
-       /*get data_size*/
+       /* get data_size */
        snprintf(dirname, BUFFSIZE-1, "%s/%s/data", USER_APP_FOLDER, pkgid);
        data_size = _librpm_calculate_dir_size(dirname);
        if (data_size < 0) {
-               _librpm_print(DEBUG_ERR,
-                               "Calculate dir size failed\n");
+               _LOGE("_librpm_calculate_dir_size(%s) failed.", dirname);
                pkg_detail_info->data_size = 0 ;
        }
        else {
-               data_size += BLOCK_SIZE; /* the function does not adds 4096
-                                       bytes for the directory size itself*/
+               data_size += BLOCK_SIZE; /* the function does not adds 4096 bytes for the directory size itself*/
                pkg_detail_info->data_size = data_size/1024 ;
        }
 
@@ -127,44 +396,41 @@ int pkg_plugin_get_app_detail_info(const char *pkgid,
        pkg_detail_info->optional_id[0] = '\0';
 
        /* Total Installed Size*/
-       pkg_detail_info->installed_size = pkg_detail_info->app_size +
-                                               pkg_detail_info->data_size;
+       pkg_detail_info->installed_size = pkg_detail_info->app_size + pkg_detail_info->data_size;
+
        /* Installed Time*/
-       snprintf(buff, 256, "db/app-info/%s/installed-time", pkgid);
+       snprintf(buff, BUFFSIZE-1, "db/app-info/%s/installed-time", pkgid);
        ret = vconf_get_int(buff, (int *)&install_time);
        if (ret) {
-               _librpm_print(DEBUG_ERR, "get installed time failed\n");
+               _LOGE("vconf_get_int(%s) failed.", buff);
                pkg_detail_info->installed_time = 0;
        }
        else
                pkg_detail_info->installed_time = install_time;
 
-
        return LIBRPM_SUCCESS;
 }
 
-int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
-                                       package_manager_pkg_detail_info_t
-                                       *pkg_detail_info)
+int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path, package_manager_pkg_detail_info_t *pkg_detail_info)
 {
-       _librpm_print(DEBUG_INFO,
-                     "pkg_plugin_get_app_detail_info_from_package() is called\n");
-
-       /* Check for valid arguments */
        if (pkg_path == NULL || pkg_detail_info == NULL) {
-               _librpm_print(DEBUG_ERR,
-                             "[pkg_plugin_get_app_detail_info_from_package]"
-                             "args supplied is NULL\n");
+               _LOGE("pkg_path or pkg_detail_info is NULL.");
                return LIBRPM_ERROR;
        }
 
+       _LOGD("pkg_plugin_get_app_detail_info_from_package(%s) is called.", pkg_path);
+
        int ret = 0;
        long long data_size = 0;
        char *str = NULL;
-       char dirname[BUFFSIZE] = { '\0' };
-       char buff[256] = {'\0'};
+       char dirname[BUFFSIZE] = {'\0'};
+       char buff[BUFFSIZE] = {'\0'};
        time_t install_time = 0;
 
+       if (__is_core_tpk_app(pkg_path, pkg_detail_info) == 1) {
+               return LIBRPM_SUCCESS;
+       }
+
        /* populate pkg type */
        str = strrchr(pkg_path, 46);    /* 46 is ASCII for . */
        strncpy(pkg_detail_info->pkg_type, (str + 1), strlen(str + 1));
@@ -181,7 +447,7 @@ int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
 
         data_size = _librpm_calculate_dir_size(dirname);
         if (data_size < 0) {
-                _librpm_print(DEBUG_ERR,
+                _LOGE(
                                 "Calculate dir size failed\n");
                 pkg_detail_info->data_size = 0 ;
         }
@@ -206,7 +472,7 @@ int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
        snprintf(buff, 256, "db/app-info/%s/installed-time", pkg_detail_info->pkgid);
        ret = vconf_get_int(buff, (int *)&install_time);
        if (ret) {
-               _librpm_print(DEBUG_ERR, "get installed time failed\n");
+               _LOGE("get installed time failed\n");
                pkg_detail_info->installed_time = 0;
        }
        else
@@ -218,21 +484,27 @@ int pkg_plugin_get_app_detail_info_from_package(const char *pkg_path,
 
 API int pkg_plugin_on_load(pkg_plugin_set *set)
 {
-       static int initialized = 0;
-       rpmRC rc;
        if (set == NULL) {
+               _LOGE("set is NULL.");
                return LIBRPM_ERROR;
        }
 
+       _LOGD("pkg_plugin_on_load() is called.");
+
+       static int initialized = 0;
+       rpmRC rc;
        memset(set, 0x00, sizeof(pkg_plugin_set));
+
        if (!initialized) {
                rc = rpmReadConfigFiles(NULL, NULL);
-               if (rc == RPMRC_OK)
+               if (rc == RPMRC_OK) {
                        initialized = 1;
+                       _LOGD("rpmReadConfigFiles() is ok.");
+               }
                else {
-                       _librpm_print(DEBUG_ERR, "Unable to read RPM configuration.\n");
+                       _LOGE("rpmReadConfigFiles() failed.");
                        initialized = 0;
-                       return LIBRPM_ERROR;
+                       return LIBRPM_ERROR;
                }
        }
 
@@ -240,8 +512,7 @@ API int pkg_plugin_on_load(pkg_plugin_set *set)
        set->pkg_is_installed = pkg_plugin_app_is_installed;
        set->get_installed_pkg_list = pkg_plugin_get_installed_apps_list;
        set->get_pkg_detail_info = pkg_plugin_get_app_detail_info;
-       set->get_pkg_detail_info_from_package =
-           pkg_plugin_get_app_detail_info_from_package;
+       set->get_pkg_detail_info_from_package = pkg_plugin_get_app_detail_info_from_package;
 
        return LIBRPM_SUCCESS;
 }
index 1da7caf..c4ec86d 100755 (executable)
 #include <rpmts.h>
 #include <rpmdb.h>
 #include <rpmlog.h>
-#include "librpminternals.h"
-
-/* This is backend lib's filter string for dlogutil*/
-#define LOCAL_LOG_TAG   "librpm"
-int logging = 0x0004;
-#ifdef LOG_IN_FILE
-#define RPM_INSTALLER_LIBRPM_LOG_FILE "/tmp/librpm"
-FILE *logfile = NULL;
-#endif
-
-void _librpm_print_msg(int type, int exetype, char *format, ...)
-{
-       char buffer[FILENAME_MAX] = { 0 };
-       char tbuffer[FILENAME_MAX] = { 0 };
-
-       int nbuffer;
-       va_list args;
-       va_start(args, format);
-       nbuffer = vsnprintf(tbuffer, FILENAME_MAX, format, args);
-       va_end(args);
-
-       switch (type) {
-       case DEBUG_ERR:
-               LOG(LOG_ERROR, LOCAL_LOG_TAG, "%s", tbuffer);
-               break;
-       case DEBUG_RESULT:
-               LOG(LOG_WARN, LOCAL_LOG_TAG, "%s", tbuffer);
-               break;
-       case DEBUG_INFO:
-               LOG(LOG_DEBUG, LOCAL_LOG_TAG, "%s", tbuffer);
-       default:
-               break;
-       }
-
-       if (logging == 0)
-               return;
-
-       if (DEBUG_ERR == (logging & type)) {
-               nbuffer = snprintf(buffer, FILENAME_MAX, "ERROR:%s", tbuffer);
-               vfprintf(stderr, format, args);
-       } else if (DEBUG_INFO == (logging & type)) {
-               nbuffer = snprintf(buffer, FILENAME_MAX, "INFO:%s", tbuffer);
-               vfprintf(stdout, format, args);
-       } else if (DEBUG_RESULT == (logging & type)) {
-               nbuffer = snprintf(buffer, FILENAME_MAX, "RESULT:%s", tbuffer);
-               vfprintf(stdout, format, args);
-       } else {
-               return;
-       }
 
-#ifdef LOG_IN_FILE
-       if (logfile != NULL)
-               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
-#endif                         /*LOG_IN_FILE */
-}
+#include "librpminternals.h"
+#include "rpm-installer-util.h"
 
-int _librpm_app_is_installed(char *pkgid)
+int _librpm_app_is_installed(const char *pkgid)
 {
        rpmts ts = NULL;
        int ret = 0;
-        Header hdr = NULL;
         int found = 0;
         rpmdbMatchIterator mi;
-        rpmtd tn = NULL;
-        rpmRC rc;
 
-        tn = rpmtdNew();
         ts = rpmtsCreate();
-/*
-       hdr = headerNew();
-*/
-
-        mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
-        while (NULL != (hdr = rpmdbNextIterator(mi))) {
-
-                hdr = headerLink(hdr);
-                rc = headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM);
-                if (strcmp(pkgid, rpmtdGetString(tn) ) == 0) {
-                        found = 1;
-                        break;
-                } else {
-                        rpmtdReset(tn);
-                        headerFree(hdr);
-                }
+        mi = rpmtsInitIterator(ts, RPMTAG_NAME, pkgid, 0);
+        while (NULL != rpmdbNextIterator(mi)) {
+               found = 1;
+       }
 
-        }
        if (found == 0) {
-               _librpm_print(DEBUG_INFO, "Package not found in DB\n");
+               _LOGD("Package not found in DB\n");
                ret = 0;
                goto err;
        }
        else {
-                _librpm_print(DEBUG_INFO, "Package found in DB\n");
+                _LOGD("Package found in DB\n");
                 ret = 1;
                goto err;
        }
 err:
-       rpmtdFreeData(tn);
-       rpmtdFree(tn);
-       headerFree(hdr);
        rpmtsFree(ts);
        rpmdbFreeIterator(mi);
        return ret;
-
 }
 
-int _librpm_get_installed_package_info(char *pkgid,
+int _librpm_get_installed_package_info(const char *pkgid,
                         package_manager_pkg_detail_info_t *pkg_detail_info)
 {
        rpmts ts = NULL;
@@ -151,34 +78,23 @@ int _librpm_get_installed_package_info(char *pkgid,
        int ret = 0;
         rpmdbMatchIterator mi;
         rpmtd td, tn, tv, ta;
-        rpmRC rc;
 
         td = rpmtdNew();
         tn = rpmtdNew();
         tv = rpmtdNew();
         ta = rpmtdNew();
         ts = rpmtsCreate();
-/*
-       hdr = headerNew();
-*/
-        mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
-        while (NULL != (hdr = rpmdbNextIterator(mi))) {
 
+        mi = rpmtsInitIterator(ts, RPMTAG_NAME, pkgid, 0);
+        while (NULL != (hdr = rpmdbNextIterator(mi))) {
                 hdr = headerLink(hdr);
-                rc = headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM);
-                if (strcmp(pkgid, rpmtdGetString(tn) ) == 0) {
-                        found = 1;
-                        break;
-                } else {
-                        rpmtdReset(tn);
-                        headerFree(hdr);
-                }
-
+               found = 1;
+               break;
         }
 
        /*Print the header info */
         if (found == 0) {
-                _librpm_print(DEBUG_ERR, "Package not found in DB\n");
+                _LOGE("Package not found in DB\n");
                 ret = LIBRPM_ERROR;
                goto err;
         }
@@ -213,10 +129,9 @@ err:
 
 }
 
-int _librpm_get_package_header_info(char *pkg_path,
+int _librpm_get_package_header_info(const char *pkg_path,
                                package_manager_pkg_detail_info_t *pkg_detail_info)
 {
-       int i;
        int ret = 0;
        rpmts ts = NULL;
        rpmtd td = NULL;
@@ -227,7 +142,7 @@ int _librpm_get_package_header_info(char *pkg_path,
 
        fd = Fopen(pkg_path, "r.ufdio");
        if ((!fd) || Ferror(fd)) {
-               _librpm_print(DEBUG_ERR, "Failed to open package file (%s)\n", Fstrerror(fd));
+               _LOGE("Failed to open package file (%s)\n", Fstrerror(fd));
                ret = LIBRPM_ERROR;
                goto err;
        }
@@ -243,7 +158,7 @@ int _librpm_get_package_header_info(char *pkg_path,
 
        rc = rpmReadPackageFile(ts, fd, pkg_path, &hdr);
        if (rc != RPMRC_OK) {
-               _librpm_print(DEBUG_ERR, "Could not read package file\n");
+               _LOGE("Could not read package file\n");
                ret = LIBRPM_ERROR;
                goto err;
        }
@@ -274,7 +189,7 @@ err:
 
 }
 
-long long _librpm_calculate_dir_size(char *dirname)
+long long _librpm_calculate_dir_size(const char *dirname)
 {
        long long total = 0;
        long long ret = 0;
@@ -285,7 +200,7 @@ long long _librpm_calculate_dir_size(char *dirname)
        struct stat fileinfo;
        char abs_filename[FILENAME_MAX] = { 0, };
        if (dirname == NULL) {
-               _librpm_print(DEBUG_ERR,
+               _LOGE(
                                "dirname is NULL");
                return LIBRPM_ERROR;
        }
@@ -323,7 +238,7 @@ long long _librpm_calculate_dir_size(char *dirname)
                }
                (void)closedir(dp);
        } else {
-               _librpm_print(DEBUG_ERR,
+               _LOGE(
                             "Couldn't open the directory\n");
                return -1;
        }
diff --git a/backend/inc/coretpk-installer.h b/backend/inc/coretpk-installer.h
new file mode 100644 (file)
index 0000000..3272aed
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * coretpk-installer
+ *
+ * Copyright (c) 2000 - 2011 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 __CORETPK_INSTALLER_H_
+#define __CORETPK_INSTALLER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+/*use ri_frontend_cmdline_arg*/
+#include "rpm-frontend.h"
+
+int _coretpk_backend_interface(const char *reqcommand, const ri_frontend_cmdline_arg *data);
+int _coretpk_installer_prepare_package_install(char *pkgid, char *clientid);
+int _coretpk_installer_prepare_package_uninstall(const char *pkgid);
+int _coretpk_installer_prepare_directory_install(char* dirpath, char *clientid);
+int _coretpk_installer_package_move(char* pkgid, int movetype);
+int _coretpk_installer_request_hybrid(int hybridOperation, char* pPkgPath, int apiVisibility);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __CORETPK_INSTALLER_H_ */
index 706d4c6..b27bfc0 100755 (executable)
@@ -29,6 +29,7 @@ extern "C" {
 
 #include "rpm-installer-util.h"
 #include <stdbool.h>
+#include <glib.h>
 
 #define PM_UNLIKELY(expr) __builtin_expect((expr), 0)
 #define PM_LIKELY(expr) __builtin_expect((expr), 1)
@@ -40,12 +41,16 @@ extern "C" {
                REQUEST_COMPLETED
        };
        typedef enum backend_state backend_state;
-       struct pkginfo_t {
-               char package_name[128];
-               char version[11];
+
+       enum rpm_request_type {
+               INSTALL_REQ,
+               UNINSTALL_REQ,
+               UPGRADE_REQ,
        };
+       typedef enum rpm_request_type rpm_request_type;
 
-       typedef struct pkginfo_t pkginfo;
+#define MARGIN_FACTOR          12
+#define RPM_SIZE_MARGIN(size)  ( (int)(size/MARGIN_FACTOR) + 1)
 
 /**
  * Install the package
@@ -56,14 +61,27 @@ extern "C" {
  */
        int _rpm_installer_package_install(char *pkgfilepath,
                                           bool force_install,
-                                          char *install_options);
+                                          char *install_options,
+                                          char *clientid);
+
+/**
+ * Install the package
+ * @in :pkgfilepath : Package file path
+ */
+       int _rpm_installer_package_install_with_dbpath(char *pkgfilepath, char *clientid);
+
+/**
+ * Install the package manifest
+ * @in :pkgfilepath : Package manifest file path
+ */
+       int _rpm_installer_corexml_install(char *pkgfilepath);
 
 /**
  * get the package information from package name
  * return the package information
  * @in :pkgid : package id for which information is requested
  */
-       pkginfo *_rpm_installer_get_pkgname_info(char *pkgid);
+       pkginfo *_rpm_installer_get_pkgname_info(const char *pkgid);
 
 /**
  * get the package information from package file
@@ -78,16 +96,32 @@ extern "C" {
  */
        int _rpm_installer_package_uninstall(char *pkgid);
 
+/**
+ * Uninstall the Application
+ * @in :pkgid : package id to be uninstalled
+ */
+       int _rpm_installer_package_uninstall_with_dbpath(const char *pkgid);
+
 /* Dbus related prototype */
-       void _ri_broadcast_status_notification(char *pkgid, char *key,
-                                              char *val);
-       int _rpm_backend_interface(char *keyid, char *pkgid,
-                                  char *reqcommand);
+       void _ri_broadcast_status_notification(const char *pkgid, char *pkg_type, char *key, char *val);
+       int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand, char *clientid);
 
 /* RPM operations prototype */
        int _rpm_uninstall_pkg(char *pkgid);
-       int _rpm_install_pkg(char *pkgfilepath, char *installoptions);
-       int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions);
+
+       int _rpm_install_pkg_with_dbpath(char *pkgfilepath, char *pkgid, char *clientid);
+       int _rpm_upgrade_pkg_with_dbpath(char *pkgfilepath, char *pkgid);
+       int _rpm_uninstall_pkg_with_dbpath(const char *pkgid, bool is_system);
+
+       int _rpm_install_corexml(char *pkgfilepath, char *pkgid);
+       int _rpm_process_cscxml(char *xml_path);
+       int _rpm_process_csc_coretpk(char *xml_path);
+       int _rpm_process_fota(char *fota_script);
+       int _rpm_process_fota_for_rw(char *fota_script);
+
+       int _rpm_process_enable(char *pkgid);
+       int _rpm_process_disable(char *pkgid);
+
        int _ri_set_backend_state(int state);
        int _ri_get_backend_state();
        int _ri_get_backend_state_info();
@@ -100,6 +134,40 @@ extern "C" {
        int _rpm_installer_clear_private_data(char *pkgid);
        int _rpm_move_pkg(char *pkgid, int move_type);
 
+/* libprivilege-control specific operations prototype*/
+       int _ri_privilege_register_package(const char *pkgid);
+       int _ri_privilege_unregister_package(const char *pkgid);
+       int _ri_privilege_revoke_permissions(const char *pkgid);
+       int _ri_privilege_enable_permissions(const char *pkgid, int apptype,
+                                               const char **perms, int persistent);
+       int _ri_privilege_setup_path(const char *pkgid, const char *dirpath,
+                                               int apppathtype, const char *groupid);
+       int _ri_privilege_add_friend(const char *pkgid1, const char *pkgid2);
+       int _ri_privilege_change_smack_label(const char *path, const char *label,
+                                               int label_type);
+       void _ri_unregister_cert(const char *pkgid);
+       void _ri_register_cert(const char *pkgid);
+       void _ri_apply_smack(char *pkgname, int flag);
+       int _ri_apply_privilege(char *pkgid, int visibility);
+       void _ri_soft_reset(char *pkgid);
+
+       int _rpm_process_enabled_list(const char *enabled_list);
+       int _rpm_process_disabled_list(const char *disabled_list);
+
+       int __is_dir(char *dirname);
+       int __ri_change_dir(char *dirname);
+       void __rpm_apply_smack(char *pkgname, int flag);
+       int _rpm_xsystem(const char *argv[]);
+       int _ri_smack_reload(const char *pkgid, rpm_request_type request_type);
+       int _ri_smack_reload_all(void);
+       int _ri_verify_signatures(const char *root_path, const char *pkgid);
+       int __ri_check_running_app(const pkgmgrinfo_appinfo_h handle, void *user_data);
+       void __ri_remove_updated_dir(const char *pkgid);
+       int __ri_copy_smack_rule_file(int op_type, const char *pkgname, int is_system);
+       void __rpm_clear_dir_list(GList* dir_list);
+       GList * __rpm_populate_dir_list();
+       void __ri_make_directory(const char *pkgid);
+
 #ifdef __cplusplus
 }
 #endif                         /* __cplusplus */
diff --git a/backend/scripts/coretpk_category_converter.sh.in b/backend/scripts/coretpk_category_converter.sh.in
new file mode 100644 (file)
index 0000000..0a4c524
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+FILE_NAME=$1
+TMP_FILE=`mktemp`
+
+if [ -z "$1" ]
+then
+       echo "error!"
+       exit 2
+fi
+
+cp $FILE_NAME $TMP_FILE
+
+awk 'BEGIN {
+    exist=0;
+}
+{
+       if ($0 ~ "com.samsung.wmanager.WATCH_APP") exist=1;
+       if ($0 ~ "</ui-application>" && !exist)
+    {
+        print "<category name=\"com.samsung.wmanager.WATCH_APP\" />"
+        print
+        exist=0;
+    }
+  else
+    {
+        print
+    }
+}' $TMP_FILE > $FILE_NAME
+rm $TMP_FILE -f
\ No newline at end of file
diff --git a/backend/scripts/coretpk_ro_xml_converter.sh.in b/backend/scripts/coretpk_ro_xml_converter.sh.in
new file mode 100644 (file)
index 0000000..6132cf2
--- /dev/null
@@ -0,0 +1,92 @@
+#!/bin/sh
+INPUT=$1
+OUTPUT=$2
+PKGID=$3
+CLIENTID=$4
+INSTALLLOCATION=0
+
+if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
+then
+       echo "error!"
+       exit 2
+fi
+
+if [ $(grep -c " exec=\"/usr/" $INPUT) -gt 0 ] || [ $(grep -c "<icon>/usr/" $INPUT) -gt 0 ]
+then
+       exit 44
+fi
+
+if [ $(grep -c "install-location=" $INPUT) -gt 0 ]
+then
+       INSTALLLOCATION=1
+fi
+
+
+if [ -n "$4" ]
+then
+       if [ $(grep -c "<service-application" $INPUT) -gt 0 ]
+       then
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"internal-only\">#" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       else
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"auto\">#" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       fi
+else
+       if [ $(grep -c "<service-application" $INPUT) -gt 0 ]
+       then
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"internal-only\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       else
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"auto\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       fi
+fi
diff --git a/backend/scripts/coretpk_rw_xml_converter.sh.in b/backend/scripts/coretpk_rw_xml_converter.sh.in
new file mode 100644 (file)
index 0000000..f34d958
--- /dev/null
@@ -0,0 +1,92 @@
+#!/bin/sh
+INPUT=$1
+OUTPUT=$2
+PKGID=$3
+CLIENTID=$4
+INSTALLLOCATION=0
+
+if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
+then
+       echo "error!"
+       exit 2
+fi
+
+if [ $(grep -c " exec=\"/opt/" $INPUT) -gt 0 ] || [ $(grep -c "<icon>/opt/" $INPUT) -gt 0 ]
+then
+       exit 44
+fi
+
+if [ $(grep -c "install-location=" $INPUT) -gt 0 ]
+then
+       INSTALLLOCATION=1
+fi
+
+
+if [ -n "$4" ]
+then
+       if [ $(grep -c "<service-application" $INPUT) -gt 0 ]
+       then
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"internal-only\">#" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       else
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"auto\">#" \
+                                               -e      "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       fi
+else
+       if [ $(grep -c "<service-application" $INPUT) -gt 0 ]
+       then
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"internal-only\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       else
+               if [ $INSTALLLOCATION -eq 1 ]
+               then
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               else
+                       /bin/sed        -e      "s#<icon>#<icon>/opt/usr/apps/$PKGID/shared/res/#g" \
+                                               -e      "s#exec=\"#exec=\"/opt/usr/apps/$PKGID/bin/#g" \
+                                               -e "/<feature.*>/ d" -e "/<feature /,/<\/feature>/ d" \
+                                               -e "s#\(<manifest[^>]*\)>#\1 install-location=\"auto\">#" \
+                                               -e "s#package=\"#type=\"coretpk\" package=\"#g" $INPUT > $OUTPUT
+               fi
+       fi
+fi
diff --git a/backend/scripts/cpio_rpm_package.sh.in b/backend/scripts/cpio_rpm_package.sh.in
new file mode 100755 (executable)
index 0000000..1cda2b8
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+PKGFILE_PATH="$1"
+/usr/bin/rpm2cpio "$PKGFILE_PATH" | cpio -idmv find -name *.xml
\ No newline at end of file
diff --git a/backend/scripts/cpio_rpm_package_update_xml.sh.in b/backend/scripts/cpio_rpm_package_update_xml.sh.in
new file mode 100644 (file)
index 0000000..df9cd7a
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+INPUT=$1
+OUTPUT=$2
+if [ -z "$1" ] || [ -z "$2" ]
+then
+       echo "error!"
+       exit 2
+fi
+sed "s#/usr/apps/#/opt/usr/apps/#g" $INPUT > $OUTPUT
index 5a6fdfc..311c435 100755 (executable)
@@ -8,7 +8,7 @@ PKG_LOG_DIR=/var/pkgmgr/rpm
 
 
 debug () {
-       echo ">>$DEBUG" >> /tmp/rpmscriptlog
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
 }
 
 NOARG=$#
@@ -28,11 +28,11 @@ fi
 
 if [ ! -d $PKG_LOG_DIR ];then
        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
-       mkdir -p $PKG_LOG_DIR
+       /bin/mkdir -p $PKG_LOG_DIR
 fi
 
 
-rpm --install --percent --nodeps $OPTION_FLAGS "$PKGFILE_PATH"
+/bin/rpm --install --percent --nodeps --force $OPTION_FLAGS "$PKGFILE_PATH"
 rpmretval=$?
 if [ $rpmretval -ne 0 ]; then
        DEBUG="rpm returned error ";debug
diff --git a/backend/scripts/install_rpm_package_with_dbpath_ro.sh.in b/backend/scripts/install_rpm_package_with_dbpath_ro.sh.in
new file mode 100644 (file)
index 0000000..deebb53
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+       DEBUG="Usage: install.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+       OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps"  --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps"  --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+       DEBUG="rpm returned error ";debug
+       exit $E_RPM_ERROR
+else
+       DEBUG="rpm success ";debug
+fi
+
diff --git a/backend/scripts/install_rpm_package_with_dbpath_rw.sh.in b/backend/scripts/install_rpm_package_with_dbpath_rw.sh.in
new file mode 100644 (file)
index 0000000..01a8cf8
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+       DEBUG="Usage: install.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+       OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --install --percent --nodeps --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+       DEBUG="rpm returned error ";debug
+       exit $E_RPM_ERROR
+else
+       DEBUG="rpm success ";debug
+fi
+
index 84e4123..e41c8b8 100755 (executable)
@@ -10,7 +10,7 @@ CURDIR=`pwd`
 echo $CURDIR >> /tmp/rpmscriptlog
 
 debug () {
-       echo ">>$DEBUG" >> /tmp/rpmscriptlog
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
 }
 
 if [ $# -ne 1 ];then
@@ -19,19 +19,19 @@ if [ $# -ne 1 ];then
 fi
 
 PKGNAME=$1
-echo "pkg name = $PKGNAME" >> /tmp/rpmscriptlog
+/bin/echo "pkg name = $PKGNAME" >> /tmp/rpmscriptlog
 
 PKG_LOG_DIR=/var/pkgmgr/$PKGNAME
 if [ ! -d $PKG_LOG_DIR ];then
        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
-       mkdir -p $PKG_LOG_DIR
+       /bin/mkdir -p $PKG_LOG_DIR
 fi
 
 if [ -f $PKGNAME ]; then
-       rpm -qpi $PKGNAME
+       /bin/rpm -qpi $PKGNAME
        retval=$?
 else
-       rpm -qi $PKGNAME
+       /bin/rpm -qi $PKGNAME
        retval=$?
 fi
 echo "retval = $retval" >> /tmp/rpmscriptlog
diff --git a/backend/scripts/rpm_update_xml.sh.in b/backend/scripts/rpm_update_xml.sh.in
new file mode 100644 (file)
index 0000000..1c74705
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+INPUT=$1
+CLIENTID=$2
+OUTPUT=$3
+
+if [ -z "$1" ]
+then
+       echo "error!"
+       exit 2
+fi
+
+if [ -n "$2" ]
+then
+       /bin/sed "s#\(<manifest[^>]*\)>#\1 storeclient-id=\"$CLIENTID\">#" $INPUT > $OUTPUT 
+fi
\ No newline at end of file
index 623b4af..678f2dc 100755 (executable)
@@ -7,7 +7,7 @@ E_RPM_ERROR=15
 PKG_LOG_DIR=/var/pkgmgr/rpm
 
 debug () {
-        echo ">>$DEBUG" >> /tmp/rpmscriptlog
+        /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
 }
 
 NOARG=$#
@@ -20,13 +20,13 @@ fi
 
 if [ ! -d $PKG_LOG_DIR ];then
         DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
-        mkdir -p $PKG_LOG_DIR
+        /bin/mkdir -p $PKG_LOG_DIR
 fi
 
 PKGNAME=$1
 
 # 3. DELETE FILES
-rpm --erase --nodeps $PKGNAME
+/bin/rpm --erase --nodeps $PKGNAME
 ret=$?
 if [ $ret -ne 0 ];then
        DEBUG="rpm error";debug
index 9fb8523..3ee83a6 100755 (executable)
@@ -8,7 +8,7 @@ PKG_LOG_DIR=/var/pkgmgr/rpm
 
 
 debug () {
-       echo ">>$DEBUG" >> /tmp/rpmscriptlog
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
 }
 
 NOARG=$#
@@ -28,12 +28,12 @@ fi
 
 if [ ! -d $PKG_LOG_DIR ];then
        DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
-       mkdir -p $PKG_LOG_DIR
+       /bin/mkdir -p $PKG_LOG_DIR
 fi
 
 
 #rpm --upgrade --percent --nodeps --replacepkgs $OPTION_FLAGS "$PKGFILE_PATH"
-rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH"
+/bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH"
 rpmretval=$?
 if [ $rpmretval -ne 0 ]; then
        DEBUG="rpm returned error ";debug
diff --git a/backend/scripts/upgrade_rpm_package_with_dbpath_ro.sh.in b/backend/scripts/upgrade_rpm_package_with_dbpath_ro.sh.in
new file mode 100644 (file)
index 0000000..41fff69
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+       DEBUG="Usage: install.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+       OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps" --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --relocate "/usr/apps"="/opt/usr/apps"  --relocate "/usr/share"="/opt/usr/rpminstaller" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+       DEBUG="rpm returned error ";debug
+       exit $E_RPM_ERROR
+else
+       DEBUG="rpm success ";debug
+fi
+
diff --git a/backend/scripts/upgrade_rpm_package_with_dbpath_rw.sh.in b/backend/scripts/upgrade_rpm_package_with_dbpath_rw.sh.in
new file mode 100644 (file)
index 0000000..7de5084
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+E_WRONG_ARGS=17
+E_FILE_NOT_FOUND=11
+E_RPM_ERROR=15
+
+PKG_LOG_DIR=/var/pkgmgr/rpm
+
+
+debug () {
+       /bin/echo ">>$DEBUG" >> /tmp/rpmscriptlog
+}
+
+NOARG=$#
+
+if [ $NOARG -lt 1 ] || [ $NOARG -gt 2 ] ; then
+       DEBUG="Usage: install.sh PKG_FILE";debug
+       exit $E_WRONG_ARGS
+elif [ $NOARG -eq 2 ] ; then
+       OPTIONS_FLAGS=$2
+fi
+PKGFILE_PATH="$1"
+
+if [ ! -f "$1" ];then
+       DEBUG="File not found";debug
+       exit $E_FILE_NOT_FOUND
+fi
+
+if [ ! -d $PKG_LOG_DIR ];then
+       DEBUG="$PKG_LOG_DIR not exist -> mkdir(ok)";debug
+       /bin/mkdir -p $PKG_LOG_DIR
+fi
+
+echo /bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+/bin/rpm --upgrade --percent --nodeps --replacepkgs --force "$PKGFILE_PATH" --dbpath="/opt/usr/rpmdb_tmp"
+rpmretval=$?
+if [ $rpmretval -ne 0 ]; then
+       DEBUG="rpm returned error ";debug
+       exit $E_RPM_ERROR
+else
+       DEBUG="rpm success ";debug
+fi
+
diff --git a/backend/src/core/rpm-installer-core.c b/backend/src/core/rpm-installer-core.c
deleted file mode 100755 (executable)
index d70a684..0000000
+++ /dev/null
@@ -1,577 +0,0 @@
-/*
- * rpm-installer
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * 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.
- *
- */
-
-/* System Include files */
-#include <stdbool.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <wait.h>
-#include <regex.h>
-#include <pthread.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <rpmlib.h>
-#include <header.h>
-#include <rpmts.h>
-#include <rpmdb.h>
-
-/* For multi-user support */
-#include <tzplatform_config.h>
-
-/* SLP include files */
-#include "rpm-installer.h"
-#include "rpm-installer-util.h"
-#include "db-util.h"
-
-#define QUERY_PACKAGE          "/usr/bin/query_rpm_package.sh"
-#define RPM_PKG_INFO           "/var/rpmpkg.info"
-#define USER_APP_FOLDER                tzplatform_getenv(TZ_USER_APP)
-
-struct pkgfile_info_t {
-       char *pkg_filename;
-       char *pkg_type;
-};
-typedef struct pkgfile_info_t pkgfile_info;
-
-extern char *gpkgname;
-extern int do_upgrade;
-static int __ri_xsystem_with_dup(char *pkgid, int fd);
-static int __ri_recursive_delete_dir(char *dirname);
-
-static int __ri_recursive_delete_dir(char *dirname)
-{
-       DIR *dp;
-       struct dirent *ep;
-       char abs_filename[FILENAME_MAX];
-       struct stat stFileInfo;
-       dp = opendir(dirname);
-       if (dp != NULL) {
-               while (ep = readdir(dp)) {
-                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
-                                ep->d_name);
-                       if (lstat(abs_filename, &stFileInfo) < 0)
-                               perror(abs_filename);
-                       if (S_ISDIR(stFileInfo.st_mode)) {
-                               if (strcmp(ep->d_name, ".") &&
-                                   strcmp(ep->d_name, "..")) {
-                                       __ri_recursive_delete_dir(abs_filename);
-                                       remove(abs_filename);
-                               }
-                       } else {
-                               remove(abs_filename);
-                       }
-               }
-               (void)closedir(dp);
-       } else {
-               _d_msg(DEBUG_ERR, "Couldn't open the directory\n");
-               return RPM_INSTALLER_ERR_CLEAR_DATA_FAILED;
-       }
-
-       return RPM_INSTALLER_SUCCESS;
-}
-
-pkginfo *_rpm_installer_get_pkgfile_info(char *pkgfile)
-{
-       int i;
-       int ret = 0;
-       rpmts ts;
-       rpmtd td;
-       FD_t fd;
-       rpmRC rc;
-       Header hdr = NULL;
-       rpmVSFlags vsflags = 0;
-       pkginfo *info = NULL;
-       if (pkgfile == NULL)
-               return NULL;
-       info = malloc(sizeof(pkginfo));
-       if (info == NULL) {
-               _d_msg(DEBUG_ERR, "Malloc Failed\n");
-               return NULL;
-       }
-       ts = rpmtsCreate();
-       td = rpmtdNew();
-       hdr = headerNew();
-
-       fd = Fopen(pkgfile, "r.ufdio");
-       if ((!fd) || Ferror(fd)) {
-               _d_msg(DEBUG_ERR, "Failed to open package file (%s)\n", Fstrerror(fd));
-               if (fd) {
-                       Fclose(fd);
-               }
-               free(info);
-               info = NULL;
-               goto err;
-       }
-
-       vsflags |= _RPMVSF_NODIGESTS;
-       vsflags |= _RPMVSF_NOSIGNATURES;
-       vsflags |= RPMVSF_NOHDRCHK;
-       (void) rpmtsSetVSFlags(ts, vsflags);
-
-       rc = rpmReadPackageFile(ts, fd, pkgfile, &hdr);
-       if (rc != RPMRC_OK) {
-               _d_msg(DEBUG_ERR, "Could not read package file\n");
-               free(info);
-               info = NULL;
-               goto err;
-       }
-       Fclose(fd);
-       /*Name*/
-       headerGet(hdr, RPMTAG_NAME, td, HEADERGET_MINMEM);
-       strncpy(info->package_name, rpmtdGetString(td), sizeof(info->package_name) - 1);
-       _d_msg(DEBUG_INFO, "Package Name : %s\n", info->package_name);
-       rpmtdReset(td);
-       /*Version*/
-       headerGet(hdr, RPMTAG_VERSION, td, HEADERGET_MINMEM);
-       strncpy(info->version, rpmtdGetString(td), sizeof(info->version) - 1);
-       _d_msg(DEBUG_INFO, "Version : %s\n", info->version);
-       rpmtdReset(td);
-
-
-err:
-       rpmtdFreeData(td);
-       rpmtdFree(td);
-       headerFree(hdr);
-       rpmtsFree(ts);
-       return info;
-
-}
-
-pkginfo *_rpm_installer_get_pkgname_info(char *pkgid)
-{
-       rpmts ts = NULL;
-       Header hdr = NULL;
-       int found = 0;
-       rpmdbMatchIterator mi;
-       rpmtd tn, tv;
-       rpmRC rc;
-       pkginfo *info = NULL;
-       if (pkgid == NULL)
-               return NULL;
-       info = malloc(sizeof(pkginfo));
-       if (info == NULL) {
-               _d_msg(DEBUG_ERR, "Malloc Failed\n");
-               return NULL;
-       }
-
-       tn = rpmtdNew();
-       tv = rpmtdNew();
-       ts = rpmtsCreate();
-
-       mi = rpmtsInitIterator(ts, RPMDBI_PACKAGES, NULL, 0);
-       while (NULL != (hdr = rpmdbNextIterator(mi))) {
-
-               hdr = headerLink(hdr);
-               rc = headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM);
-               if (strcmp(pkgid, rpmtdGetString(tn)) == 0) {
-                       found = 1;
-                       break;
-               } else {
-                       rpmtdReset(tn);
-                       headerFree(hdr);
-               }
-
-       }
-
-       if (found == 0) {
-               _d_msg(DEBUG_ERR, "Package not found in DB\n");
-               free(info);
-               info = NULL;
-               goto err;
-       }
-       /*Name */
-       headerGet(hdr, RPMTAG_NAME, tn, HEADERGET_MINMEM);
-       strncpy(info->package_name, rpmtdGetString(tn),
-               sizeof(info->package_name)-1);
-       _d_msg(DEBUG_INFO, "Package Name : %s\n", info->package_name);
-       /*Version */
-       headerGet(hdr, RPMTAG_VERSION, tv, HEADERGET_MINMEM);
-       strncpy(info->version, rpmtdGetString(tv), sizeof(info->version)-1);
-       _d_msg(DEBUG_INFO, "Version : %s\n", info->version);
-
-
- err:
-       headerFree(hdr);
-       rpmtdFreeData(tn);
-       rpmtdFree(tn);
-       rpmtdFreeData(tv);
-       rpmtdFree(tv);
-       rpmdbFreeIterator(mi);
-       rpmtsFree(ts);
-
-       return info;
-
-}
-
-#if 0
-
-static int __ri_xsystem_with_dup(char *pkgname, int fd)
-{
-       int pid;
-       int status = 0;
-       const char *argv[] = { QUERY_PACKAGE, pkgname, NULL };
-       pid = fork();
-       switch (pid) {
-       case -1:
-               perror("fork failed");
-               return -1;
-       case 0:         /* child */
-               close(1);
-               close(2);
-               dup(fd);
-               dup(fd);        /* dup called twice to create copy of fd 1 and fd 2 */
-               execvp(argv[0], (char *const *)argv);
-               exit(-1);
-       default:                /*parent */
-               break;
-       }
-       if (waitpid(pid, &status, 0) == -1) {
-               perror("waitpid failed");
-               return -1;
-       }
-       if (WIFSIGNALED(status)) {
-               perror("signal");
-               printf("sig no. %d\n", WTERMSIG(status));
-               return -1;
-       }
-       if (!WIFEXITED(status)) {
-               perror("should not happen");
-               return -1;
-       }
-
-       return WEXITSTATUS(status);
-}
-
-pkginfo *_rpm_installer_get_pkg_info(char *pkgname)
-{
-       pkginfo *info = NULL;
-       int err = 0;
-       int fd = -1;
-       FILE *fp = NULL;
-       char *line = NULL;
-       size_t len = 0;
-       ssize_t read;
-       char *saveptr = NULL;
-       char *tok = NULL;
-
-       if (pkgname == NULL)
-               return NULL;
-
-       fd = open(RPM_PKG_INFO, O_CREAT | O_RDWR, 0644);
-       if (fd == -1) {
-               _d_msg(DEBUG_ERR, "open failed\n");
-               return NULL;
-       }
-
-       err = __ri_xsystem_with_dup(pkgname, fd);
-       _d_msg(DEBUG_INFO,
-              "[_rpm_installer_get_pkg_info] _xsystem returns %d\n", err);
-       if (err == 1) {
-               _d_msg(DEBUG_INFO,
-                      "[_rpm_installer_get_pkg_info] "
-                      "Package Not installed \n");
-               close(fd);
-               return NULL;
-       } else if (err == 2) {
-               _d_msg(DEBUG_INFO,
-                      "[_rpm_installer_get_pkg_info] "
-                      "package already install\n");
-               info = malloc(sizeof(pkginfo));
-               if (info == NULL) {
-                       _d_msg(DEBUG_ERR, "Malloc Failed\n");
-                       close(fd);
-                       return NULL;
-               }
-               memset(info, 0x00, sizeof(pkginfo));
-               close(fd);
-               fp = fopen(RPM_PKG_INFO, "r");
-               if (fp == NULL) {
-                       _d_msg(DEBUG_ERR, "fopen failed\n");
-                       return NULL;
-               }
-
-               /* Now open file and get pkgname and version */
-               while ((read = getline(&line, &len, fp)) != -1) {
-                       int len = strlen(line);
-                       line[len - 1] = '\0';
-
-                       _d_msg(DEBUG_INFO, "line[%s]\n", line);
-
-                       tok = strtok_r(line, " ", &saveptr);    /*Name */
-                       if (tok && strncmp(tok, "Name", 4) == 0) {
-                               /* : */
-                               tok = strtok_r(NULL, " ", &saveptr);
-                               /* <name> */
-                               tok = strtok_r(NULL, " ", &saveptr);
-                               if (tok) {
-                                       strncpy(info->package_name, tok,
-                                               sizeof(info->package_name));
-                               }
-                       } else if (tok && strncmp(tok, "Version", 7) == 0) {
-                               /* : */
-                               tok = strtok_r(NULL, " ", &saveptr);
-                               /* <version> */
-                               tok = strtok_r(NULL, " ", &saveptr);
-                               if (tok) {
-                                       strncpy(info->version, tok,
-                                               sizeof(info->version));
-                               }
-                               break;
-                       } else
-                               continue;
-               }
-               if (line) {
-                       free(line);
-                       line = NULL;
-               }
-               fclose(fp);
-               remove(RPM_PKG_INFO);
-               return info;
-
-       } else {
-               _d_msg(DEBUG_ERR,
-                      "[_rpm_installer_get_pkg_info] "
-                      "_xsystem returns error = %d\n", err);
-               close(fd);
-               return NULL;
-       }
-       remove(RPM_PKG_INFO);
-       return info;
-
-}
-
-#endif
-
-int _rpm_installer_package_install(char *pkgfilepath, bool forceinstall,
-                                  char *installoptions)
-{
-       int err = 0;
-       if (forceinstall == true && installoptions == NULL)
-               return RPM_INSTALLER_ERR_WRONG_PARAM;
-       pkginfo *info = NULL;
-       pkginfo *tmpinfo = NULL;
-       /*Check to see if the package is already installed or not
-          If it is installed, compare the versions. If the current version
-          is higher than the installed version, upgrade it automatically
-          else ask for user confirmation before downgrading */
-
-       info = _rpm_installer_get_pkgfile_info(pkgfilepath);
-       if (info == NULL) {
-               /* failed to get pkg info */
-               return RPM_INSTALLER_ERR_UNKNOWN;
-       }
-
-       _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
-       if (gpkgname) {
-               free(gpkgname);
-               gpkgname = NULL;
-       }
-       gpkgname = strdup(info->package_name);
-
-       tmpinfo = _rpm_installer_get_pkgname_info(info->package_name);
-       if (tmpinfo == NULL) {
-               /* package is not installed. Go for installation. */
-               if (info) {
-                       free(info);
-                       info = NULL;
-               }
-               err = _rpm_install_pkg(pkgfilepath, installoptions);
-               if (err != 0) {
-                       _d_msg(DEBUG_ERR,
-                              "install complete with error(%d)\n", err);
-                       return err;
-               } else {
-                       _ri_set_backend_state_info(REQUEST_COMPLETED);
-                       return RPM_INSTALLER_SUCCESS;
-               }
-       } else if (strcmp(info->version, tmpinfo->version) > 0) {
-               /*upgrade */
-               err = _rpm_upgrade_pkg(pkgfilepath, "--force");
-               if (err != 0) {
-                       _d_msg(DEBUG_ERR,
-                              "upgrade complete with error(%d)\n", err);
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       return err;
-               } else {
-                       _ri_set_backend_state_info(REQUEST_COMPLETED);
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       return RPM_INSTALLER_SUCCESS;
-               }
-       } else if (strcmp(info->version, tmpinfo->version) < 0) {
-               /*show popup and confirm from user */
-               switch (do_upgrade) {
-               case -1:
-                       _ri_set_backend_state_info(REQUEST_PENDING);
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       return RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION;
-               case 0:
-                       /*return */
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       _ri_set_backend_state_info(REQUEST_COMPLETED);
-                       return RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED;
-               case 1:
-                       /*continue with downgrade */
-                       _ri_set_backend_state_info
-                           (GOT_PACKAGE_INFO_SUCCESSFULLY);
-                       err = _rpm_upgrade_pkg(pkgfilepath, "--force");
-                       if (err != 0) {
-                               _d_msg(DEBUG_ERR,
-                                      "upgrade complete with error(%d)\n",
-                                      err);
-                               if (info) {
-                                       free(info);
-                                       info = NULL;
-                               }
-                               if (tmpinfo) {
-                                       free(tmpinfo);
-                                       tmpinfo = NULL;
-                               }
-                               return err;
-                       }
-                       _ri_set_backend_state_info(REQUEST_COMPLETED);
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       return RPM_INSTALLER_SUCCESS;
-
-               }
-
-       } else {
-               /*same package. Reinstall it. Manifest should be parsed again */
-               err = _rpm_upgrade_pkg(pkgfilepath, "--force");
-               if (err != 0) {
-                       _d_msg(DEBUG_ERR,
-                              "upgrade complete with error(%d)\n", err);
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       return err;
-               } else {
-                       _ri_set_backend_state_info(REQUEST_COMPLETED);
-                       if (info) {
-                               free(info);
-                               info = NULL;
-                       }
-                       if (tmpinfo) {
-                               free(tmpinfo);
-                               tmpinfo = NULL;
-                       }
-                       return RPM_INSTALLER_SUCCESS;
-               }
-       }
-       if (info) {
-               free(info);
-               info = NULL;
-       }
-       if (tmpinfo) {
-               free(tmpinfo);
-               tmpinfo = NULL;
-       }
-       return RPM_INSTALLER_SUCCESS;
-
-}
-
-int _rpm_installer_package_uninstall(char *pkgid)
-{
-       int ret = 0;
-       pkginfo *tmppkginfo = _rpm_installer_get_pkgname_info(pkgid);
-       if (tmppkginfo == NULL)
-               return RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
-       if (tmppkginfo) {
-               free(tmppkginfo);
-               tmppkginfo = NULL;
-       }
-#ifndef SEND_PKGPATH
-       if (gpkgname) {
-               free(gpkgname);
-               gpkgname = NULL;
-       }
-       gpkgname = strdup(pkgid);
-       _ri_broadcast_status_notification(pkgid, "start", "uninstall");
-       _ri_broadcast_status_notification(pkgid, "command", "Uninstall");
-#endif
-       _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
-       ret = _rpm_uninstall_pkg(pkgid);
-
-       _ri_set_backend_state_info(REQUEST_COMPLETED);
-
-       return ret;
-}
-
-int _rpm_installer_clear_private_data(char *pkgid)
-{
-       if (pkgid == NULL)
-               return RPM_INSTALLER_ERR_WRONG_PARAM;
-
-       char dir_path[256] = { '\0' };
-       int ret = -1;
-
-       snprintf(dir_path, 255, "%s/%s/data/", USER_APP_FOLDER, pkgid);
-       ret = __ri_recursive_delete_dir(dir_path);
-
-       return ret;
-}
diff --git a/backend/src/coretpk/coretpk-installer.c b/backend/src/coretpk/coretpk-installer.c
new file mode 100755 (executable)
index 0000000..d4e430e
--- /dev/null
@@ -0,0 +1,3500 @@
+/*
+ * coretpk-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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 _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <dirent.h>
+#include <unistd.h>
+#include <glib.h>
+#include <openssl/sha.h>
+#include <openssl/evp.h>
+#include <vconf.h>
+#include <unzip.h>
+#include <sys/smack.h>
+#include <ctype.h>
+
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+#include <privilege-control.h>
+//#include <privilege_manager.h>
+#include <app_manager.h>
+#include <app2ext_interface.h>
+#include <package-manager.h>
+
+#include "coretpk-installer-internal.h"
+#include "coretpk-installer-type.h"
+/*use rpm-installer exceptions*/
+#include "rpm-installer-util.h"
+/*because the logic of coretpk and rpm are similar, use rpm functions.*/
+#include "rpm-installer.h"
+#include "rpm-installer-type.h"
+
+extern pkgmgr_installer *pi;
+extern GList *privilege_list;
+
+int _coretpk_installer_get_group_id(char *pkgid, char **result);
+void _coretpk_installer_set_privilege_setup_path(char *pkgid, char *dirpath, app_path_type_t type, char *label);
+
+static int __get_unzip_size(const char *item, unsigned long long *size)
+{
+       if (!item || !size) {
+               _LOGE("Invalid argument.");
+               return PMINFO_R_ERROR;
+       }
+       int ret = 0;
+       unzFile uzf = unzOpen64(item);
+       if(uzf== NULL)
+       {
+               _LOGE("Fail to open item : %s", item);
+               *size = 0;
+               return PMINFO_R_ERROR;
+       } else {
+               ret = unzGoToFirstFile(uzf);
+               if(ret != UNZ_OK) {
+                       _LOGE("error get first zip file ");
+                       unzClose(uzf);
+                       *size = 0;
+                       return PMINFO_R_ERROR;
+               } else {
+                       do{
+                               ret = unzOpenCurrentFile(uzf);
+                               if(ret != UNZ_OK) {
+                                       _LOGE("error unzOpenCurrentFile ");
+                                       unzClose(uzf);
+                                       *size = 0;
+                                       return PMINFO_R_ERROR;
+                               }
+
+                               unz_file_info fileInfo = {0};
+                               char* filename = (char*) calloc(1, BUF_SIZE);
+                               ret= unzGetCurrentFileInfo(uzf, &fileInfo, filename, (BUF_SIZE-1), NULL, 0, NULL, 0);
+                               *size = (unsigned long long)fileInfo.uncompressed_size + *size;
+                               if(ret != UNZ_OK) {
+                                       _LOGE("error get current file info");
+                                       unzCloseCurrentFile(uzf);
+                                       *size = 0;
+                                       break;
+                               }
+
+                               if (filename) {
+                                       free(filename);
+                                       filename = NULL;
+                               }
+                       }while(unzGoToNextFile(uzf) == UNZ_OK);
+               }
+       }
+       unzClose(uzf);
+
+       return PMINFO_R_OK;
+}
+
+static int __is_default_external_storage()
+{
+       int ret = 0;
+       int storage = 0;
+       int mmc_status = VCONFKEY_SYSMAN_MMC_REMOVED;
+
+       ret = vconf_get_int("db/setting/default_memory/install_applications", &storage);
+       retvm_if(ret != 0, PMINFO_R_ERROR, "vconf_get_int(db/setting/default_memory/install_applications) is failed.");
+
+       if (storage == 1) {
+               ret = vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_status);
+               retvm_if(ret != 0, PMINFO_R_ERROR, "vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS) is failed.");
+
+               if((mmc_status == VCONFKEY_SYSMAN_MMC_REMOVED) || (mmc_status == VCONFKEY_SYSMAN_MMC_INSERTED_NOT_MOUNTED)) {
+                       _LOGD("mmc_status is MMC_REMOVED or NOT_MOUNTED.");
+               } else {
+                       _LOGD("mmc_status is MMC_MOUNTED.");
+                       return PMINFO_R_OK;
+               }
+       }
+
+       return PMINFO_R_ERROR;
+}
+
+static void __apply_smack_for_mmc(const char *pkgid)
+{
+#if 0
+       char dirpath[BUF_SIZE] = {'\0'};
+
+       snprintf(dirpath, BUF_SIZE, "%s/%s/.mmc", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK) != 0) {
+               _LOGE("Cannot access to [%s].", dirpath);
+               return;
+       }
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/.mmc/bin
+       snprintf(dirpath, BUF_SIZE, "%s/.mmc/bin", pkgid);
+       _coretpk_installer_set_privilege_setup_path((char*)pkgid, dirpath, APP_PATH_PRIVATE, (char*)pkgid);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/.mmc/lib
+       snprintf(dirpath, BUF_SIZE, "%s/.mmc/lib", pkgid);
+       _coretpk_installer_set_privilege_setup_path((char*)pkgid, dirpath, APP_PATH_PRIVATE, (char*)pkgid);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/.mmc/lost+found
+       snprintf(dirpath, BUF_SIZE, "%s/.mmc/lost+found", pkgid);
+       _coretpk_installer_set_privilege_setup_path((char*)pkgid, dirpath, APP_PATH_PRIVATE, (char*)pkgid);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/.mmc/res
+       snprintf(dirpath, BUF_SIZE, "%s/.mmc/res", pkgid);
+       _coretpk_installer_set_privilege_setup_path((char*)pkgid, dirpath, APP_PATH_PRIVATE, (char*)pkgid);
+       memset(dirpath, '\0', BUF_SIZE);
+#endif
+       return;
+}
+
+static int __pre_upgrade_for_mmc(const char *pkgid, const char *pkgfile, GList **dir_list, app2ext_handle **handle)
+{
+#if 0
+       int ret = 0;
+       unsigned long long archive_size_byte = 0;
+       int archive_size_mega = 0;
+
+       ret = __is_default_external_storage();
+       if (ret < 0) {
+               _LOGD("Upgrade storage is internal.");
+               return 0;
+       }
+       _LOGD("__pre_upgrade start.");
+
+       ret = __get_unzip_size(pkgfile, &archive_size_byte);
+       if (ret < 0) {
+               _LOGD("Failed to get uncompressed size.");
+               return PMINFO_R_ERROR;
+       }
+       archive_size_mega = archive_size_byte / (1024 * 1024) + 1;
+       _LOGD("Uncompressed size is converted from [%lld]bytes to [%d]Mb.", archive_size_byte, archive_size_mega);
+
+       *handle = app2ext_init(APP2EXT_SD_CARD);
+       if (*handle == NULL) {
+               _LOGE("@app2ext init failed\n");
+               return PMINFO_R_ERROR;
+       }
+       if ((&((*handle)->interface) != NULL) && ((*handle)->interface.pre_upgrade != NULL) && ((*handle)->interface.post_upgrade != NULL) &&
+                       ((*handle)->interface.disable != NULL)) {
+               ret = (*handle)->interface.disable(pkgid);
+               if (ret != APP2EXT_SUCCESS) {
+                       _LOGE("Unmount ret[%d]", ret);
+               }
+               *dir_list = __rpm_populate_dir_list();
+               if (*dir_list == NULL) {
+                       _LOGE("@ \nError in populating the directory list\n");
+                       return PMINFO_R_ERROR;
+               }
+               ret = (*handle)->interface.pre_upgrade(pkgid, *dir_list, archive_size_mega);
+               if (ret == APP2EXT_ERROR_MMC_STATUS) {
+                       _LOGE("@app2xt MMC is not here, go internal\n");
+               } else if (ret == APP2EXT_SUCCESS){
+                       _LOGD("@pre_upgrade done, go internal\n");
+               }
+               else {
+                       _LOGE("@app2xt pre upgrade API failed (%d)\n", ret);
+                       return PMINFO_R_ERROR;
+               }
+       } else {
+               _LOGE("handle is not proper.");
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("__pre_upgrade end.");
+#endif
+       return PMINFO_R_OK;
+}
+
+static int __post_upgrade_for_mmc(app2ext_handle *handle, const char *pkgid, GList *dir_list)
+{
+#if 0
+       int ret = __is_default_external_storage();
+       if (ret != 0) {
+               _LOGD("Upgrade storage is internal.");
+               return 0;
+       }
+       _LOGD("__post_upgrade start.");
+
+       /* set smack again for .mmc folder */
+       __apply_smack_for_mmc(pkgid);
+       _LOGD("__apply_smack_for_mmc is completed.");
+
+       if ((handle != NULL) && (handle->interface.post_upgrade != NULL)) {
+               __rpm_clear_dir_list(dir_list);
+               handle->interface.post_upgrade(pkgid, APP2EXT_STATUS_SUCCESS);
+               app2ext_deinit(handle);
+       } else {
+               _LOGE("handle->interface.post_upgrade is NULL.");
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("__post_upgrade end.");
+#endif
+       return PMINFO_R_OK;
+}
+
+static int __pre_install_for_mmc(const char *pkgid, const char *pkgfile, GList **dir_list, app2ext_handle **handle)
+{
+#if 0
+       int ret = 0;
+       unsigned long long archive_size_byte = 0;
+       int archive_size_mega = 0;
+
+       ret = __is_default_external_storage();
+       if (ret != 0) {
+               _LOGD("Installed storage is internal.");
+               return 0;
+       }
+       _LOGD("__pre_install start.");
+
+       ret = __get_unzip_size(pkgfile, &archive_size_byte);
+       if (ret < 0) {
+               _LOGD("Failed to get uncompressed size.");
+               return PMINFO_R_ERROR;
+       }
+       archive_size_mega = archive_size_byte / (1024 * 1024) + 1;
+       _LOGD("Uncompressed size is converted from [%lld]bytes to [%d]Mb.", archive_size_byte, archive_size_mega);
+
+       *handle = app2ext_init(APP2EXT_SD_CARD);
+       if (*handle == NULL) {
+               _LOGE("@app2ext init failed\n");
+               return PMINFO_R_ERROR;
+       }
+       if ((&((*handle)->interface) != NULL) && ((*handle)->interface.pre_install != NULL) && ((*handle)->interface.post_install != NULL)
+                       && ((*handle)->interface.force_clean != NULL)) {
+               ret = (*handle)->interface.force_clean(pkgid);
+               if (ret != APP2EXT_SUCCESS) {
+                       _LOGE("Force clean is failed. pkgid[%s] ret[%d]", pkgid, ret);
+                       return PMINFO_R_ERROR;
+               }
+               _LOGD("Force clean is OK");
+               *dir_list = __rpm_populate_dir_list();
+               if (*dir_list == NULL) {
+                       _LOGE("@ \nError in populating the directory list\n");
+                       return PMINFO_R_ERROR;
+               }
+               ret = (*handle)->interface.pre_install(pkgid, *dir_list, archive_size_mega);
+               if (ret == APP2EXT_ERROR_MMC_STATUS) {
+                       _LOGE("@app2xt MMC is not here, go internal\n");
+               } else if (ret == APP2EXT_SUCCESS){
+                       _LOGD("@pre_install done, go internal\n");
+               }
+               else {
+                       _LOGE("@app2xt pre install API failed (%d)\n", ret);
+                       return PMINFO_R_ERROR;
+               }
+       } else {
+               _LOGE("handle is not proper.");
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("__pre_install end.");
+#endif
+       return PMINFO_R_OK;
+}
+
+static int __post_install_for_mmc(app2ext_handle *handle, const char *pkgid, GList *dir_list, int install_status)
+{
+#if 0
+       int ret = __is_default_external_storage();
+       if (ret != 0) {
+               _LOGD("Installed storage is internal.");
+               return 0;
+       }
+       _LOGD("__post_install start.");
+
+       /* set smack again for .mmc folder */
+       __apply_smack_for_mmc(pkgid);
+       _LOGD("__apply_smack_for_mmc is completed.");
+
+       if ((handle != NULL) && (handle->interface.post_install != NULL)) {
+               __rpm_clear_dir_list(dir_list);
+               handle->interface.post_install(pkgid, install_status);
+               app2ext_deinit(handle);
+       } else {
+               _LOGE("handle->interface.post_install is NULL.");
+               return PMINFO_R_ERROR;
+       }
+       _LOGD("__post_install end.");
+#endif
+       return PMINFO_R_OK;
+}
+
+static void __str_trim(char *input)
+{
+       char *trim_str = input;
+
+       if (input == NULL)
+               return;
+
+       while (*input != 0) {
+               if (!isspace(*input)) {
+                       *trim_str = *input;
+                       trim_str++;
+               }
+               input++;
+       }
+
+       *trim_str = 0;
+       return;
+}
+
+static char *__find_info_from_xml(const char *manifest, const char *find_info)
+{
+       const char *val = NULL;
+       const xmlChar *node;
+       xmlTextReaderPtr reader;
+       char *info_val = NULL;
+       int ret = -1;
+
+       if(manifest == NULL) {
+               _LOGE("input argument is NULL\n");
+               return NULL;
+       }
+
+       if(find_info == NULL) {
+               _LOGE("find_info is NULL\n");
+               return NULL;
+       }
+
+       reader = xmlReaderForFile(manifest, NULL, 0);
+
+       if (reader) {
+               if (_child_element(reader, -1)) {
+                       node = xmlTextReaderConstName(reader);
+                       if (!node) {
+                               _LOGE("xmlTextReaderConstName value is NULL\n");
+                               goto end;
+                       }
+
+                       if (!strcmp(ASCII(node), "manifest")) {
+                               ret = _ri_get_attribute(reader,(char*)find_info,&val);
+                               if(ret != 0){
+                                       _LOGE("error in getting the attribute value");
+                                       goto end;
+                               }
+
+                               if(val) {
+                                       info_val = strdup(val);
+                                       if(info_val == NULL) {
+                                               _LOGE("malloc failed!!");
+                                       }
+                               }
+                       } else {
+                               _LOGE("unable to create xml reader\n");
+                       }
+               }
+       } else {
+               _LOGE("xmlReaderForFile value is NULL\n");
+       }
+
+end:
+       if (reader) {
+               xmlFreeTextReader(reader);
+       }
+
+       if(val)
+               free((void*)val);
+
+       return info_val;
+}
+
+static int __coretpk_privilege_func(const char *name, void *user_data)
+{
+       int ret = 0;
+#if 0
+       const char *perm[] = {NULL, NULL};
+       const char *ug_pkgid = "ui-gadget::client";
+
+       perm[0] = name;
+
+       _LOGD("privilege = [%s]", name);
+       _ri_privilege_register_package("ui-gadget::client");
+
+       ret = _ri_privilege_enable_permissions(ug_pkgid, PERM_APP_TYPE_EFL, perm, 1);
+       _LOGE("add ug privilege(%s, %s, %d) done.", ug_pkgid, name, ret);
+#endif
+       return ret;
+}
+
+static int __ui_gadget_func(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+#if 0
+       int ret = 0;
+       bool is_ug = 0;
+       char *pkgid = NULL;
+       char *exec = NULL;
+       char appdir[BUF_SIZE] = {'\0'};
+
+       ret = pkgmgrinfo_appinfo_is_ui_gadget(handle, &is_ug);
+       retvm_if(ret < 0, RPM_INSTALLER_ERR_PKG_NOT_FOUND, "Failed to get is_ui_gadget.\n");
+
+       if (is_ug == true) {
+
+               /*get pkgid*/
+               ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
+               retvm_if(ret < 0, RPM_INSTALLER_ERR_PKG_NOT_FOUND, "Failed to get pkgid\n");
+
+               _LOGD("@[%s] has ui-gadget", pkgid);
+
+               /*check bin directory*/
+               snprintf(appdir, BUF_SIZE, "%s/%s/bin", USR_APPS, pkgid);
+               if (access(appdir, F_OK) != 0) {
+                       /*permission(755)*/
+                       ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+                       if (ret < 0) {
+                               _LOGL("mkdir()", errno);
+                               return -1;
+                       }
+               }
+
+               /*get exec*/
+               ret = pkgmgrinfo_appinfo_get_exec(handle, &exec);
+               retvm_if(ret < 0, RPM_INSTALLER_ERR_PKG_NOT_FOUND, "Failed to get exec\n");
+
+               /*make symlink to exec*/
+               const char *ln_argv[] = { "/bin/ln", "-sf", "/usr/bin/ug-client", exec, NULL };
+               ret = _ri_xsystem(ln_argv);
+               retvm_if(ret < 0, RPM_INSTALLER_ERR_INTERNAL, "Failed to exec ln_argv\n");
+
+               _LOGD("@[%s] success symlink to [/usr/bin/ug-client]", exec);
+
+               * (bool *) user_data = true;
+       }
+#endif
+       return 0;
+}
+
+static int __check_updated_system_package(const char *pkgid)
+{
+       int ret = 0;
+       bool is_update = false;
+       bool is_system = false;
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       retvm_if(ret < 0, -1, "pkgmgrinfo_pkginfo_get_pkginfo(%s) failed.", pkgid);
+
+       ret = pkgmgrinfo_pkginfo_is_system(pkghandle, &is_system);
+       tryvm_if(ret < 0, ret = -1, "pkgmgrinfo_pkginfo_is_system(%s) failed.", pkgid);
+
+       ret = pkgmgrinfo_pkginfo_is_update(pkghandle, &is_update);
+       tryvm_if(ret < 0, ret = -1, "pkgmgrinfo_pkginfo_is_update(%s) failed.", pkgid);
+
+       if (is_system && is_update) {
+               _LOGD("pkgid=[%s] is updated system package.", pkgid);
+               ret = 1;
+       } else {
+               _LOGD("pkgid=[%s] is not updated system app.", pkgid);
+               ret = -1;
+       }
+
+catch:
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+       return ret;
+}
+
+static int __pkg_remove_update(const char *pkgid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char rootpath[BUF_SIZE] = {'\0'};
+
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL.");
+               return -1;
+       }
+
+       // start
+       _ri_broadcast_status_notification(pkgid, "coretpk", "start", "update");
+
+       // remove dir for clean (/opt/usr/apps/[pkgid])
+       snprintf(rootpath, BUF_SIZE, "%s/%s/", OPT_USR_APPS, pkgid);
+       if (__is_dir(rootpath)) {
+               _rpm_delete_dir(rootpath);
+       }
+
+       // Remove origin rule
+       _ri_privilege_unregister_package(pkgid);
+
+       // unzip pkg path from factory-reset data
+       memset(rootpath, '\0', BUF_SIZE);
+       snprintf(rootpath, BUF_SIZE, "opt/usr/apps/%s/*", pkgid);
+       const char *pkg_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, rootpath, "-d", "/", NULL };
+       ret = _ri_xsystem(pkg_argv);
+       if (ret != 0) {
+               _LOGE("/usr/bin/unzip(%s) failed.", rootpath);
+       }
+
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "30");
+
+       // remove opt xml
+       snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       (void)remove(buff);
+
+       // updated usr xml
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+
+       _LOGD("manifest = [%s].",buff);
+
+       ret = pkgmgr_parser_parse_manifest_for_upgrade(buff, NULL);
+       if (ret < 0) {
+               _LOGE("pkgmgr_parser_parse_manifest_for_upgrade(%s) is failed.", pkgid);
+               return ret;
+       }
+       _LOGD("pkgmgr_parser_parse_manifest_for_upgrade() is ok.");
+
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "60");
+
+       // apply smack for pkg root path
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+//     _ri_privilege_setup_path(pkgid, buff, PERM_APP_PATH_ANY_LABEL, pkgid);
+
+       // apply smack for defined directory
+       __rpm_apply_smack((char*)pkgid, 0);
+
+       // apply privilege
+       ret = _ri_apply_privilege((char*)pkgid, 0);
+       if (ret != 0) {
+               _LOGE("_ri_apply_privilege(%s) failed. ret = [%d]", pkgid, ret);
+       } else {
+               _LOGD("_ri_apply_privilege(%s) success.", pkgid);
+       }
+
+       // reload smack
+       ret = _ri_smack_reload(pkgid, UPGRADE_REQ);
+       if (ret != 0) {
+               _LOGE("_ri_smack_reload(%s) failed.", pkgid);
+       }
+
+       // finish
+       if (ret != 0) {
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "fail");
+       } else {
+               _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "100");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "ok");
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_remove_db_info(const char *pkgid)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret < 0) {
+               return PMINFO_R_OK;
+       }
+       ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+       tryvm_if(ret < 0, ret = PMINFO_R_ERROR, "pkgmgr_parser_parse_manifest_for_uninstallation is failed, pkgid=[%s]", pkgid);
+
+       _LOGD("Remove db info is OK.");
+
+catch:
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       return ret;
+}
+
+int _coretpk_installer_set_smack_label_access(const char *path, const char *label)
+{
+       int res = smack_lsetlabel(path, label, SMACK_LABEL_ACCESS);
+       if (res != 0)
+       {
+               _LOGE("smack set label(%s) failed[%d] (path:[%s]))", label, res, path);
+               return -1;
+       }
+       return 0;
+}
+
+int _coretpk_installer_get_smack_label_access(const char *path, char **label)
+{
+       int res = smack_lgetlabel(path, label, SMACK_LABEL_ACCESS);
+       if (res != 0)
+       {
+               _LOGE("Error in getting smack ACCESS label failed. result[%d] (path:[%s]))", res, path);
+               return -1;
+       }
+       return 0;
+}
+
+int _coretpk_installer_set_smack_label_transmute(const char *path, const char *flag)
+{
+       int res = smack_lsetlabel(path, flag, SMACK_LABEL_TRANSMUTE);
+       if (res != 0)
+       {
+               _LOGE("smack set label(%s) failed[%d] (path:[%s]))", flag, res, path);
+               return -1;
+       }
+       return 0;
+}
+
+int _coretpk_installer_verify_privilege_list(GList *privilege_list, int visibility)
+{
+       char *error_privilege_name = NULL;
+       GList *list = NULL;
+       int ret = 0;
+#if 0
+       ret = privilege_manager_verify_privilege_list(PRVMGR_PACKAGE_TYPE_CORE, privilege_list, visibility, &error_privilege_name);
+       if (ret != PRVMGR_ERR_NONE) {
+               _LOGE("privilege_manager_verify_privilege_list(PRVMGR_PACKAGE_TYPE_CORE) failed. ret = [%d][%s]", ret, error_privilege_name);
+               fprintf(stdout, "\n verify_privilege_list(PRVMGR_PACKAGE_TYPE_CORE) failed. [%d][%s]\n", ret, error_privilege_name);
+
+               if (error_privilege_name) {
+                       free(error_privilege_name);
+               }
+
+               list = g_list_first(privilege_list);
+               while (list) {
+                       if (list->data) {
+                               free(list->data);
+                       }
+                       list = g_list_next(list);
+               }
+               g_list_free(privilege_list);
+               privilege_list = NULL;
+
+               ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+               return ret;
+       } else {
+               _LOGD("privilege_manager_verify_privilege_list(PRVMGR_PACKAGE_TYPE_CORE) is ok.");
+       }
+
+       list = g_list_first(privilege_list);
+       while (list) {
+               if (list->data) {
+                       free(list->data);
+               }
+               list = g_list_next(list);
+       }
+       g_list_free(privilege_list);
+       privilege_list = NULL;
+#endif
+       return ret;
+}
+
+void _coretpk_installer_search_ui_gadget(const char *pkgid)
+{
+#if 0
+       int ret = 0;
+       bool is_ug_pkg = false;
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       retm_if(ret < 0, "@Failed to get the pkginfo handle.");
+
+       /* search ug app */
+       ret = pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ui_gadget_func, &is_ug_pkg);
+       tryvm_if(ret < 0, ret = RPM_INSTALLER_ERR_INTERNAL, "Fail to get applist");
+
+       /*if there is ug app,  apply privilege*/
+       if (is_ug_pkg == true) {
+               ret = pkgmgrinfo_pkginfo_foreach_privilege(pkghandle, __coretpk_privilege_func, NULL);
+               tryvm_if(ret < 0, ret = RPM_INSTALLER_ERR_INTERNAL, "Fail to get privilege list");
+       }
+
+catch :
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+#endif
+}
+
+int _coretpk_backend_interface(const char *reqcommand, const ri_frontend_cmdline_arg *data)
+{
+       if (reqcommand == NULL || data == NULL) {
+               _LOGE("reqcommand or data is NULL.");
+               return -1;
+       }
+
+       if (strncmp(reqcommand, CORETPK_INSTALL, strlen(CORETPK_INSTALL)) == 0) {
+               return _coretpk_installer_prepare_package_install(data->pkgid, data->clientid);
+       }  else if (strncmp(reqcommand, CORETPK_UNINSTALL, strlen(CORETPK_UNINSTALL)) == 0) {
+               return _coretpk_installer_prepare_package_uninstall(data->pkgid);
+       } else if (strncmp(reqcommand, CORETPK_DIRECTORY_INSTALL, strlen(CORETPK_DIRECTORY_INSTALL)) == 0) {
+               return _coretpk_installer_prepare_directory_install(data->pkgid, data->clientid);
+       } else if (strncmp(reqcommand, CORETPK_MOVE, strlen(CORETPK_MOVE)) == 0) {
+               return _coretpk_installer_package_move(data->pkgid, data->move_type);
+       } else if (strncmp(reqcommand, CORETPK_REINSTALL, strlen(CORETPK_REINSTALL)) == 0) {
+               return _coretpk_installer_package_reinstall(data->pkgid, data->clientid);
+       } else {
+               return -1;
+       }
+}
+
+#if 0
+static char * _coretpk_installer_get_pkg_path(const char *pkg_path, const char *pkgid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char *real_path = NULL;
+
+       snprintf(buff, BUF_SIZE, "%s/%s", pkg_path, pkgid);
+       do {
+               if (__is_dir(buff)) break;
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+               if (__is_dir(buff)) break;
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "/opt/apps/%s", pkgid);
+               if (__is_dir(buff)) break;
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "%s/%s", USR_APPS, pkgid);
+               if (__is_dir(buff)) break;
+       } while (0);
+
+       ret = chdir(buff);
+       if (ret != 0) {
+               _LOGE("chdir() failed [%s]\n", strerror(errno));
+               return NULL;
+       }
+
+       real_path = (char *)malloc(strlen(buff) + 1);
+       if (real_path == NULL) {
+               _LOGE("Malloc failed!\n");
+               return NULL;
+       }
+       memset(real_path, '\0', strlen(buff) + 1);
+       memcpy(real_path, buff, strlen(buff));
+
+       return real_path;
+}
+#endif
+
+int _coretpk_installer_verify_signatures(const char *root_path, const char *pkgid, int *visibility)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       const char *pkg_path = root_path;
+
+       _LOGD("root_path=[%s], pkgid=[%s]", root_path, pkgid);
+
+#if 0
+       // check for signature and certificate
+       pkg_path = _coretpk_installer_get_pkg_path(root_path, pkgid);
+       if (pkg_path == NULL) {
+               _LOGE("pkg_path is NULL.");
+               return 0;
+       }
+#endif
+
+       ret = chdir(root_path);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed. [%s]", root_path, strerror(errno));
+       }
+
+       // author-signature.xml is mandatory
+       snprintf(buff, BUF_SIZE, "%s/author-signature.xml", pkg_path);
+       if (access(buff, F_OK) == 0) {
+               _LOGD("author-signature.xml is found, path=[%s]", buff);
+               ret = _ri_verify_sig_and_cert(buff, visibility);
+               if (ret) {
+                       _LOGE("_ri_verify_sig_and_cert() failed, path=[%s]", buff);
+                       ret = -1;
+                       goto end;
+               }
+               _LOGD("_ri_verify_sig_and_cert succeed, path=[%s]", buff);
+       } else {
+               _LOGE("cannot access xml, path=[%s]", buff);
+               ret = -1;
+               goto end;
+       }
+       memset(buff, '\0', BUF_SIZE);
+
+       // signature1.xml is mandatory
+       snprintf(buff, BUF_SIZE, "%s/signature1.xml", pkg_path);
+       if (access(buff, F_OK) == 0) {
+               _LOGD("signature1.xml is found, path=[%s]", pkg_path);
+               ret = _ri_verify_sig_and_cert(buff, visibility);
+               if (ret) {
+                       _LOGE("_ri_verify_sig_and_cert() failed, path=[%s]", buff);
+                       ret = -1;
+                       goto end;
+               }
+               _LOGD("_ri_verify_sig_and_cert() succeed, path=[%s]", buff);
+       } else {
+               _LOGE("cannot access xml, path=[%s]", buff);
+               ret = -1;
+               goto end;
+       }
+       memset(buff, '\0', BUF_SIZE);
+       ret = 0;
+
+end:
+#if 0
+       if(pkg_path){
+               free(pkg_path);
+               pkg_path = NULL;
+       }
+#endif
+
+       return ret;
+}
+
+char* _coretpk_installer_load_directory(char *directory,char *pkgfile)
+{
+       DIR *dir;
+       struct dirent entry;
+       struct dirent *result;
+       int ret = 0;
+       char *buf = NULL;
+       char *pkgname = NULL;
+       char xml_file[MAX_BUF_SIZE] = {'\0'};
+
+       buf = malloc(BUF_SIZE);
+       if (buf == NULL) {
+               _LOGE("malloc() failed.");
+               return NULL;
+       }
+
+       dir = opendir(directory);
+       if (!dir) {
+               _LOGL("opendir()", errno);
+               free(buf);
+               return NULL;
+       }
+
+       _LOGD("loading manifest files, directory=[%s]", directory);
+
+       for (ret = readdir_r(dir, &entry, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dir, &entry, &result)) {
+               char *manifest = NULL;
+
+               if (!strcmp(entry.d_name, ".") ||
+                       !strcmp(entry.d_name, "..")) {
+                       continue;
+               }
+
+               manifest = _manifest_to_package(entry.d_name);
+               if (!manifest) {
+                       _LOGE("failed to convert file to xml, file=[%s].", entry.d_name);
+                       continue;
+               }
+
+               memset(xml_file,'\0',MAX_BUF_SIZE);
+               snprintf(xml_file,MAX_BUF_SIZE-1,"%s/%s", directory, manifest);
+               _LOGD("manifest=[%s], path=[%s]", manifest, xml_file);
+
+               ret = _get_package_name_from_xml(xml_file, &pkgname);
+               if (ret != PMINFO_R_OK || pkgname == NULL) {
+                       _LOGE("unable to read, xml_file=[%s]", xml_file);
+                       free(manifest);
+                       continue;
+               }
+
+               if (pkgname[0] != '\0') {
+                       snprintf(buf, BUF_SIZE, "%s/%s", directory, manifest);
+                       free(manifest);
+                       break;
+               }
+
+               free(manifest);
+       }
+
+       closedir(dir);
+
+       if (pkgname) {
+               free(pkgname);
+               pkgname = NULL;
+       }
+
+
+       return buf;
+}
+
+pkginfo *_coretpk_installer_get_pkgfile_info(char *pkgfile)
+{
+       pkginfo *info = NULL;
+       int ret = 0;
+       char cwd[BUF_SIZE] = {'\0'};
+       char buff[BUF_SIZE] = {'\0'};
+       char manifest[BUF_SIZE] = { '\0'};
+       char *temp = NULL;
+
+       char *tmp_pkgid = NULL;
+       char *tmp_version = NULL;
+
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGL("getcwd()", errno);
+               return NULL;
+       }
+
+       ret = mkdir(TEMP_DIR, DIRECTORY_PERMISSION_755);
+       if (ret < 0) {
+               if (access(TEMP_DIR, F_OK) == 0) {
+                       _rpm_delete_dir(TEMP_DIR);
+                       ret = mkdir(TEMP_DIR, DIRECTORY_PERMISSION_644);
+                       if (ret < 0) {
+                               _LOGL("mkdir()", errno);
+                               return NULL;
+                       }
+               } else {
+                       _LOGL("access()", errno);
+                       return NULL;
+               }
+       }
+
+       ret = chdir(TEMP_DIR);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               goto err;
+       }
+
+       _LOGD("switched to %s", TEMP_DIR);
+
+       snprintf(manifest, BUF_SIZE, "%s", CORETPK_XML);
+       const char *unzip_argv[] = { "/usr/bin/unzip", "-o", pkgfile, manifest, "-d", TEMP_DIR, NULL };
+       ret = _ri_xsystem(unzip_argv);
+       if (ret != 0) {
+               _LOGE("cannot find manifest in the package.");
+               ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+               goto err;
+       }
+
+       char* manifestpath = _coretpk_installer_load_directory(TEMP_DIR, pkgfile);
+       if (manifestpath != NULL) {
+               strcpy(buff, manifestpath);
+               free(manifestpath);
+       }
+
+       if (buff[0] == '\0') {
+               _LOGE("cannot find manifest in the package.");
+               goto err;
+       }
+
+       _LOGD("manifest file=[%s]",buff);
+
+       info = calloc(1, sizeof(pkginfo));
+       if (info == NULL) {
+               _LOGE("calloc() failed.");
+               goto err;
+       }
+
+       tmp_pkgid = __find_info_from_xml(buff, "package");
+       if (tmp_pkgid != NULL) {
+               strncpy(info->package_name, tmp_pkgid, sizeof(info->package_name) - 1);
+               free(tmp_pkgid);
+       } else {
+               _LOGE("can not get pkgid");
+               goto err;
+       }
+
+       tmp_version = __find_info_from_xml(buff, "version");
+       if (tmp_version != NULL) {
+               strncpy(info->version, tmp_version, sizeof(info->version) - 1);
+               free(tmp_version);
+       } else {
+               _LOGE("can not get version");
+               goto err;
+       }
+
+       _LOGD("pkgid=[%s], version=[%s]", info->package_name, info->version);
+
+err:
+       _rpm_delete_dir(TEMP_DIR);
+
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+       }
+
+       return info;
+}
+
+int _coretpk_installer_convert_manifest(char *manifestfilepath, char *pkgid, char* clientid)
+{
+       int ret = 0;
+       char rwmanifest[BUF_SIZE] = {'\0'};
+
+       if (clientid != NULL) {
+               _LOGD("client package id=[%s]", clientid);
+       }
+
+       /*run script*/
+       if (strstr(manifestfilepath, OPT_USR_APPS)) {
+               snprintf(rwmanifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+               const char *rw_xml_argv[] = { CORETPK_RW_XML_CONVERTER, manifestfilepath, rwmanifest, pkgid, clientid, NULL };
+               ret = _ri_xsystem(rw_xml_argv);
+       } else {
+               snprintf(rwmanifest, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+               const char *ro_xml_argv[] = { CORETPK_RO_XML_CONVERTER, manifestfilepath, rwmanifest, pkgid, clientid, NULL };
+               ret = _ri_xsystem(ro_xml_argv);
+       }
+
+       _LOGD("pkgid=[%s]", pkgid);
+       _LOGD("tizen-manifest=[%s]", manifestfilepath);
+       _LOGD("converted manifest=[%s]", rwmanifest);
+
+       if (ret != 0) {
+               if (ret == INCLUDE_ABSOLUTE_PATH) {
+                       _LOGE("path of exec or icon can not be started with absolute path.");
+               } else {
+                       _LOGL("converting the manifest file", errno);
+               }
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       _LOGD("manifest is converted successfully");
+
+err:
+       return ret;
+}
+
+int _coretpk_installer_get_configuration_value(char *value)
+{
+       char buffer[BUF_SIZE] = {'\0'};
+       char *p = NULL;
+       FILE *fi = NULL;
+       int len = 0;
+       int ret = 0;
+
+       if (access(CORETPK_CONFIG_PATH, F_OK) != 0) {
+               /* if there is no ini file, signature has to be checked */
+               return 1;
+       }
+
+       fi = fopen(CORETPK_CONFIG_PATH, "r");
+       if (fi == NULL) {
+               _LOGL("fopen()", errno);
+               return 0;
+       }
+
+       while (fgets(buffer, BUF_SIZE, fi) != NULL) {
+               /* buffer will be like signature=off\n\0*/
+               if (strncmp(buffer, value, strlen(value)) == 0) {
+                       len = strlen(buffer);
+                       /*remove newline character*/
+                       buffer[len - 1] = '\0';
+                       p = strchr(buffer, '=');
+                       if (p) {
+                               p++;
+                               if (strcmp(p, "on") == 0) {
+                                       ret = 1;
+                               } else {
+                                       ret = 0;
+                               }
+                       }
+               } else {
+                       continue;
+               }
+       }
+
+       fclose(fi);
+       return ret;
+}
+
+int _coretpk_installer_apply_file_policy(char *filepath)
+{
+       int ret = 0;
+
+       if (access(filepath, F_OK) == 0) {
+               /*permission(644)*/
+               ret = chmod(filepath, FILE_PERMISSION_644);
+               if (ret != 0) {
+                       _LOGL("chmod()", errno);
+               }
+       } else {
+               _LOGE("skip! empty filepath=[%s]", filepath);
+       }
+
+       return 0;
+}
+
+int _coretpk_installer_apply_directory_policy(char *dirpath, int mode, bool appowner)
+{
+       int ret = 0;
+       DIR *dir;
+       struct dirent entry;
+       struct dirent *result;
+       char fullpath[BUF_SIZE] = {'\0'};
+
+       if (access(dirpath, F_OK) != 0) {
+               _LOGE("skip! empty dirpath=[%s]", dirpath);
+               return 0;
+       }
+
+       dir = opendir(dirpath);
+       if (!dir) {
+               _LOGE("opendir(%s) failed. [%d][%s]", dirpath, errno, strerror(errno));
+               return -1;
+       }
+
+       // permission(755)
+       ret = _coretpk_installer_change_mode(dirpath, DIRECTORY_PERMISSION_755);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_change_mode is failed, dirpath=[%s]", dirpath);
+       }
+
+       for (ret = readdir_r(dir, &entry, &result); ret == 0 && result != NULL; ret = readdir_r(dir, &entry, &result)){
+               if (strcmp(entry.d_name, ".") == 0) {
+                       snprintf(fullpath, BUF_SIZE, "%s/", dirpath);
+                       if (appowner == true) {
+                               _coretpk_installer_change_directory_owner(fullpath, APP_OWNER_ID, APP_GROUP_ID);
+                       }
+                       ret = _coretpk_installer_change_mode(fullpath, DIRECTORY_PERMISSION_755);
+                       if (ret != 0) {
+                               _LOGE("_coretpk_installer_change_mode is failed, fullpath=[%s]", fullpath);
+                       }
+                       continue;
+               } else if (strcmp(entry.d_name, "..") == 0) {
+                       continue;
+               }
+
+               // sub dir
+               if (entry.d_type == DT_DIR) {
+                       snprintf(fullpath, BUF_SIZE, "%s/%s", dirpath, entry.d_name);
+
+                       // owner:group
+                       if (appowner == true) {
+                               ret = _coretpk_installer_change_directory_owner(fullpath, APP_OWNER_ID, APP_GROUP_ID);
+                               if (ret != 0) {
+                                       _LOGE("_coretpk_installer_change_directory_owner failed, fullpath=[%s]", fullpath);
+                               }
+                       }
+               // sub file
+               } else {
+                       snprintf(fullpath, BUF_SIZE, "%s/%s", dirpath, entry.d_name);
+
+                       // permission(input mode)
+                       ret = _coretpk_installer_change_mode(fullpath, mode);
+                       if (ret != 0) {
+                               _LOGE("_coretpk_installer_change_mode failed, fullpath=[%s]", fullpath);
+                       }
+
+                       // owner:group
+                       if (appowner == true) {
+                               ret = _coretpk_installer_change_file_owner(fullpath, APP_OWNER_ID, APP_GROUP_ID);
+                               if (ret != 0) {
+                                       _LOGE("_coretpk_installer_change_file_owner failed, fullpath=[%s]", fullpath);
+                               }
+                       }
+               }
+
+               // find next dir
+               if (entry.d_type == DT_DIR) {
+                       ret = _coretpk_installer_apply_directory_policy(fullpath, mode, appowner);
+                       if(ret != 0 ){
+                               _LOGE("_coretpk_installer_apply_directory_policy failed, fullpath=[%s]", fullpath);
+                       }
+               }
+               memset(fullpath, '\0', BUF_SIZE);
+       }
+
+       closedir(dir);
+
+       return ret;
+}
+
+int _coretpk_installer_make_directory_for_ext(char *pkgid)
+{
+       char ext_pkg_base_path[BUF_SIZE] = {0, };
+       char temp_path[BUF_SIZE] = {0, };
+       char pkg_shared_data_path[BUF_SIZE] = {0, };
+       char *shared_data_label = NULL;
+       int res = 0;
+
+       if (access(OPT_STORAGE_SDCARD, F_OK) != 0) {
+               _LOGL("There is no OPT_STORAGE_SDCARD", errno);
+               return -1;
+       }
+
+       /*pkg root path*/
+       if (access(OPT_STORAGE_SDCARD_APP_ROOT, F_OK) != 0) {
+               /*permission(755)*/
+               res = mkdir(OPT_STORAGE_SDCARD_APP_ROOT, DIRECTORY_PERMISSION_755);
+               if (res < 0) {
+                       _LOGL("mkdir()", errno);
+                       return -1;
+                       }
+       }
+
+       /*app root path*/
+       snprintf(ext_pkg_base_path, BUF_SIZE, "%s/%s", OPT_STORAGE_SDCARD_APP_ROOT, pkgid);
+       res = mkdir(ext_pkg_base_path, 0500);
+       if (res == -1 && errno != EEXIST)
+       {
+               _LOGE("mkdir() is failed. error = [%d] strerror = [%s]", errno, strerror(errno));
+               return -1;
+       }
+
+       res = _coretpk_installer_set_smack_label_access(ext_pkg_base_path, "_");
+       if (res != 0)
+       {
+               _LOGE("_coretpk_installer_set_smack_label_access() is failed.");
+               return -1;
+       }
+
+       //data
+       memset(temp_path, 0, BUF_SIZE);
+       strcpy(temp_path, ext_pkg_base_path);
+       strncat(temp_path, "/data", strlen("/data"));
+       res = mkdir(temp_path, 0700);
+       if (res == -1 && errno != EEXIST)
+       {
+               _LOGE("mkdir() is failed. error = [%d] strerror = [%s]", errno, strerror(errno));
+               return -1;
+       }
+       res = _coretpk_installer_set_smack_label_access(temp_path, pkgid);
+       if (res != 0)
+       {
+               _LOGE("_coretpk_installer_set_smack_label_access() is failed.");
+               return -1;
+       }
+
+       //cache
+       memset(temp_path, 0, BUF_SIZE);
+       strcpy(temp_path, ext_pkg_base_path);
+       strncat(temp_path, "/cache", strlen("/cache"));
+       res = mkdir(temp_path, 0700);
+       if (res == -1 && errno != EEXIST)
+       {
+               _LOGE("mkdir() is failed. error = [%d] strerror = [%s]", errno, strerror(errno));
+               return -1;
+       }
+       res = _coretpk_installer_set_smack_label_access(temp_path, pkgid);
+       if (res != 0)
+       {
+               _LOGE("_coretpk_installer_set_smack_label_access() is failed.");
+               return -1;
+       }
+
+       //shared
+       memset(temp_path, 0, BUF_SIZE);
+       strcpy(temp_path, ext_pkg_base_path);
+       strncat(temp_path, "/shared", strlen("/shared"));
+       res = mkdir(temp_path, 0500);
+       if (res == -1 && errno != EEXIST)
+       {
+               _LOGE("mkdir() is failed. error = [%d] strerror = [%s]", errno, strerror(errno));
+               return -1;
+       }
+       res = _coretpk_installer_set_smack_label_access(temp_path, "_");
+       if (res != 0)
+       {
+               _LOGE("_coretpk_installer_set_smack_label_access() is failed.");
+               return -1;
+       }
+
+       snprintf(pkg_shared_data_path, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid , "shared/data");
+
+       res = access(pkg_shared_data_path, F_OK);
+       if (res == 0)
+       {
+               _LOGD("Exist shared/data folder (path:[%s])", pkg_shared_data_path);
+               res = _coretpk_installer_get_smack_label_access(pkg_shared_data_path, &shared_data_label);
+               if (res != 0)
+               {
+                       _LOGE("_coretpk_installer_get_smack_label_access() is failed.");
+                       return -1;
+               }
+
+               //shared/data
+               strncat(temp_path, "/data", strlen("/data"));
+               res = mkdir(temp_path, 0705);
+               if (res == -1 && errno != EEXIST)
+               {
+                       _LOGE("mkdir() is failed. error = [%d] strerror = [%s]", errno, strerror(errno));
+                       return -1;
+               }
+
+               res = _coretpk_installer_set_smack_label_access(temp_path, shared_data_label);
+               if (res != 0)
+               {
+                       _LOGE("_coretpk_installer_set_smack_label_access() is failed.");
+                       return -1;
+               }
+
+               res = _coretpk_installer_set_smack_label_transmute(temp_path, "1");
+               if (res != 0)
+               {
+                       _LOGE("_coretpk_installer_set_smack_label_transmute() is failed.");
+//                     return -1;
+               }
+
+               //shared/cache
+               memset(temp_path, 0, BUF_SIZE);
+               strcpy(temp_path, ext_pkg_base_path);
+               strncat(temp_path, "/shared", strlen("/shared"));
+               strncat(temp_path, "/cache", strlen("/cache"));
+               res = mkdir(temp_path, 0700);
+               if (res == -1 && errno != EEXIST)
+               {
+                       _LOGE("mkdir() is failed. error = [%d] strerror = [%s]", errno, strerror(errno));
+                       return -1;
+               }
+               res = _coretpk_installer_set_smack_label_access(temp_path, shared_data_label);
+               if (res != 0)
+               {
+                       _LOGE("_coretpk_installer_set_smack_label_access() is failed.");
+                       return -1;
+               }
+               res = _coretpk_installer_set_smack_label_transmute(temp_path, "1");
+               if (res != 0)
+               {
+                       _LOGE("_coretpk_installer_set_smack_label_transmute() is failed.");
+//                     return -1;
+               }
+
+       }
+       else if (res == -1 && errno == ENOENT)
+       {
+               _LOGD("Directory dose not exist. path: %s, errno: %d (%s)",
+                               pkg_shared_data_path, errno, strerror(errno));
+               return 0;
+       }
+       else
+       {
+               _LOGE("access() failed. path: %s, errno: %d (%s)",
+                               pkg_shared_data_path, errno, strerror(errno));
+               return -1;
+       }
+
+       return 0;
+}
+
+
+int _coretpk_installer_make_directory(char *pkgid)
+{
+       int ret = 0;
+       char appdir[BUF_SIZE] = {'\0'};
+       char rootfile[BUF_SIZE] = {'\0'};
+       char *groupid = NULL;
+
+       // check param
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL.");
+               return -1;
+       }
+
+       // root
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               // permission(755)
+               ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("mkdir(%s) failed. [%d][%s]", appdir, errno, strerror(errno));
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // bin
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/bin", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               memset(appdir, '\0', BUF_SIZE);
+               snprintf(appdir, BUF_SIZE, "%s/%s/bin", USR_APPS, pkgid);
+               if (access(appdir, F_OK) != 0) {
+                       _LOGE("[%s] is not existed.", appdir);
+                       return -1;
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE | PERM_EXECUTE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // data
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/data", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               // permission(755)
+               ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("mkdir failed, appdir=[%s], errno=[%d][%s]", appdir, errno, strerror(errno));
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, true);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       //lib
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/lib", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               memset(appdir, '\0', BUF_SIZE);
+               snprintf(appdir, BUF_SIZE, "%s/%s/lib", USR_APPS, pkgid);
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE | PERM_EXECUTE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // res
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/res", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               memset(appdir, '\0', BUF_SIZE);
+               snprintf(appdir, BUF_SIZE, "%s/%s/res", USR_APPS, pkgid);
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // cache
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/cache", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               // permission(755)
+               ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("mkdir failed, appdir=[%s], errno=[%d][%s]", appdir, errno, strerror(errno));
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, true);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // shared
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("mkdir(%s) failed. [%d][%s]", appdir, errno, strerror(errno));
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared", USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("mkdir failed. appdir=[%s], errno=[%d][%s]", appdir, errno, strerror(errno));
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // shared/data
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared/data", OPT_USR_APPS, pkgid);
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, true);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // shared/cache
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared/cache", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("mkdir failed. appdir=[%s], errno=[%d][%s]", appdir, errno, strerror(errno));
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, true);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // shared/res
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared/res", OPT_USR_APPS, pkgid);
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared/res", USR_APPS, pkgid);
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, false);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // shared/trusted
+       memset(appdir, '\0', BUF_SIZE);
+       snprintf(appdir, BUF_SIZE, "%s/%s/shared/trusted", OPT_USR_APPS, pkgid);
+       if (access(appdir, F_OK) != 0) {
+               ret = _coretpk_installer_get_group_id(pkgid, &groupid);
+               if (ret == 0) {
+                       ret = mkdir(appdir, DIRECTORY_PERMISSION_755);
+                       if (ret < 0) {
+                               _LOGE("mkdir failed, appdir=[%s], errno=[%d][%s]", appdir, errno, strerror(errno));
+                       }
+                       free(groupid);
+               }
+       }
+       ret = _coretpk_installer_apply_directory_policy(appdir, PERM_BASE, true);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", appdir, ret);
+               return -1;
+       }
+
+       // [pkgid]/tizen-manifest.xml
+       snprintf(rootfile, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, CORETPK_XML);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s/%s", USR_APPS, pkgid, CORETPK_XML);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+
+       // [pkgid]/author-signature.xml
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s/%s", USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+
+       // [pkgid]/signature1.xml
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, SIGNATURE1_XML);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s/%s", USR_APPS, pkgid, SIGNATURE1_XML);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+
+       // /opt/share/packages/[pkgid].xml
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+       memset(rootfile, '\0', BUF_SIZE);
+       snprintf(rootfile, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+       ret = _coretpk_installer_apply_file_policy(rootfile);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_file_policy() failed, rootfile=[%s]", rootfile);
+               return -1;
+       }
+/*
+       // for external storage
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_MAKE_EXT_DIRECTORY)) {
+               int ret = _coretpk_installer_make_directory_for_ext(pkgid);
+               if (ret != 0) {
+                       _LOGE("_coretpk_installer_make_directory_for_ext() failed, pkgid=[%s]", pkgid);
+                       return -1;
+               }
+       }
+*/
+       return ret;
+}
+
+int _coretpk_installer_change_mode(char *path, int mode)
+{
+       int ret = 0;
+
+       ret = chmod(path, mode);
+       if (ret != 0) {
+               _LOGL("chmod()", errno);
+               return -1;
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_change_file_owner(char *path, int ownerid, int groupid)
+{
+       int ret = 0;
+
+       if (access(path, F_OK) == 0) {
+               ret = chown(path, ownerid, groupid);
+               if (ret != 0) {
+                       _LOGL("chown()", errno);
+                       return -1;
+               }
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_change_directory_owner(char *dirpath, int ownerid, int groupid)
+{
+       int ret = 0;
+
+       if (__is_dir(dirpath)) {
+               ret = chown(dirpath, ownerid, groupid);
+               if (ret != 0) {
+                       _LOGL("chown()", errno);
+                       return -1;
+               }
+       }
+
+       return ret;
+}
+
+void _coretpk_installer_set_privilege_setup_path_for_ext(char *pkgid, char *dirpath, app_path_type_t type, char *label)
+{
+       char path[BUF_SIZE] = {'\0'};
+
+       snprintf(path, BUF_SIZE, "%s/%s", OPT_STORAGE_SDCARD_APP_ROOT, dirpath);
+       if (access(path, F_OK) == 0) {
+               _ri_privilege_setup_path(pkgid, path, type, label);
+       }
+}
+
+void _coretpk_installer_set_privilege_setup_path(char *pkgid, char *dirpath, app_path_type_t type, char *label)
+{
+       char path[BUF_SIZE] = {'\0'};
+
+       snprintf(path, BUF_SIZE, "%s/%s", USR_APPS, dirpath);
+       if (access(path, F_OK) == 0) {
+               _ri_privilege_setup_path(pkgid, path, type, label);
+       }
+       memset(path, '\0', BUF_SIZE);
+
+       snprintf(path, BUF_SIZE, "%s/%s", OPT_USR_APPS, dirpath);
+       if (access(path, F_OK) == 0) {
+               _ri_privilege_setup_path(pkgid, path, type, label);
+       }
+}
+
+int _coretpk_installer_get_group_id(char *pkgid, char **result)
+{
+       int ret = 0;
+       const char *value = NULL;
+       char author_signature[BUF_SIZE] = {'\0'};
+       char *e_rootcert = NULL;
+       char *d_rootcert = NULL;
+       gsize d_size = 0;
+       unsigned char hashout[BUF_SIZE] = {'\0'};
+       unsigned int h_size = 0;
+       int e_size = 0;
+       int length = 0;
+       pkgmgrinfo_certinfo_h handle = NULL;
+
+       snprintf(author_signature, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+       if (access(author_signature, F_OK) != 0) {
+               _LOGE("[%s] is not found.", author_signature);
+
+               memset(author_signature, '\0', BUF_SIZE);
+               snprintf(author_signature, BUF_SIZE, "%s/%s/%s", USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+               if (access(author_signature, F_OK) != 0) {
+                       _LOGE("[%s] is not found.", author_signature);
+                       return -1;
+               } else {
+                       _LOGE("author_signature=[%s]", author_signature);
+               }
+       }
+
+       ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
+       if (ret < 0) {
+               _LOGE("failed to get cert info.");
+               goto err;
+       }
+
+       ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
+       if (ret < 0) {
+               _LOGE("failed to load cert info.");
+               goto err;
+       }
+
+       /*get root certificate*/
+       ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_SIGNER_CERT, &value);
+       if (ret < 0 || value == NULL) {
+               _LOGE("failed to get cert value.");
+               goto err;
+       }
+
+       /*decode cert*/
+       d_rootcert = (char *)g_base64_decode(value, &d_size);
+       if (d_rootcert == NULL) {
+               _LOGE("failed to execute decode.");
+               goto err;
+       }
+
+       /*hash*/
+       EVP_Digest(d_rootcert, d_size, hashout, &h_size, EVP_sha1(), NULL);
+       if (h_size <= 0) {
+               _LOGE("@Failed to get hash.");
+               goto err;
+       }
+
+       /*encode cert*/
+       e_rootcert = g_base64_encode((const guchar *)hashout, h_size);
+       if (e_rootcert == NULL) {
+               _LOGE("failed to execute encode.");
+               goto err;
+       }
+       e_size = strlen(e_rootcert);
+       _LOGD("encoding done, len=[%d]", e_size);
+
+       /*replace / to #*/
+       for (length = e_size; length >= 0; --length) {
+               if (e_rootcert[length] == '/') {
+                       e_rootcert[length] = '#';
+               }
+       }
+
+       *result = e_rootcert;
+
+err:
+       if (d_rootcert) {
+               free(d_rootcert);
+       }
+
+       /*destroy cert*/
+       if (handle) {
+               pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_apply_smack_for_ext(char *pkgname)
+{
+       int ret = 0;
+       char dirpath[BUF_SIZE] = {'\0'};
+
+       // approot
+       snprintf(dirpath, BUF_SIZE, "%s", pkgname);
+       _coretpk_installer_set_privilege_setup_path_for_ext(pkgname, dirpath, APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/data
+       snprintf(dirpath, BUF_SIZE, "%s/data", pkgname);
+       _coretpk_installer_set_privilege_setup_path_for_ext(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/cache
+       snprintf(dirpath, BUF_SIZE, "%s/cache", pkgname);
+       _coretpk_installer_set_privilege_setup_path_for_ext(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/shared
+       snprintf(dirpath, BUF_SIZE, "%s/shared", pkgname);
+       _coretpk_installer_set_privilege_setup_path_for_ext(pkgname, dirpath, APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid]/shared/data
+       snprintf(dirpath, BUF_SIZE, "%s/shared/data", pkgname);
+       _coretpk_installer_set_privilege_setup_path_for_ext(pkgname, dirpath, APP_PATH_PUBLIC_RO, NULL);
+
+       return ret;
+}
+
+int _coretpk_installer_apply_smack(char *pkgname, int flag)
+{
+       int ret = 0;
+       char dirpath[BUF_SIZE] = {'\0'};
+       char manifest[BUF_SIZE] = {'\0'};
+       char *groupid = NULL;
+       char *shared_data_label = NULL;
+
+       _ri_privilege_register_package(pkgname);
+
+       // app root
+       snprintf(dirpath, BUF_SIZE, "%s", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // shared
+       snprintf(dirpath, BUF_SIZE, "%s/shared", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // shared/res
+       snprintf(dirpath, BUF_SIZE, "%s/shared/res", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // shared/data
+       snprintf(dirpath, BUF_SIZE, "%s/shared/data", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PUBLIC_RO, NULL);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // shared/cache
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/data", OPT_USR_APPS, pkgname);
+       ret = _coretpk_installer_get_smack_label_access(dirpath, &shared_data_label);
+       if (ret == 0) {
+               memset(dirpath, '\0', BUF_SIZE);
+               snprintf(dirpath, BUF_SIZE, "%s/%s/shared/cache", OPT_USR_APPS, pkgname);
+               ret  = _coretpk_installer_set_smack_label_access(dirpath, shared_data_label);
+               if (ret != 0) {
+                       _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", dirpath, ret);
+               }
+               ret = _coretpk_installer_set_smack_label_transmute(dirpath, "1");
+               if (ret != 0) {
+                       _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", dirpath, ret);
+               }
+       }
+
+       // shared/trusted
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/shared/trusted", pkgname);
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_SIGNATURE)) {
+               ret = _coretpk_installer_get_group_id(pkgname, &groupid);
+               if (ret == 0) {
+                       LOGD("groupid = [%s] for shared/trusted.", groupid);
+                       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_GROUP_RW, groupid);
+                       if (groupid)
+                               free(groupid);
+               } else {
+                       LOGE("_coretpk_installer_get_group_id(%s) failed.", pkgname);
+                       return -1;
+               }
+       }
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // bin
+       snprintf(dirpath, BUF_SIZE, "%s/bin", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // data
+       snprintf(dirpath, BUF_SIZE, "%s/data", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // lib
+       snprintf(dirpath, BUF_SIZE, "%s/lib", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // res
+       snprintf(dirpath, BUF_SIZE, "%s/res", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // cache
+       snprintf(dirpath, BUF_SIZE, "%s/cache", pkgname);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // tizen-manifest.xml
+       snprintf(dirpath, BUF_SIZE, "%s/%s", pkgname, CORETPK_XML);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // author-signature.xml
+       snprintf(dirpath, BUF_SIZE, "%s/%s", pkgname, AUTHOR_SIGNATURE_XML);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // signature1.xml
+       snprintf(dirpath, BUF_SIZE, "%s/%s", pkgname, SIGNATURE1_XML);
+       _coretpk_installer_set_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+       memset(dirpath, '\0', BUF_SIZE);
+
+       // [pkgid].xml
+       snprintf(manifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgname);
+       if (access(manifest, F_OK) == 0) {
+               _ri_privilege_setup_path(pkgname, manifest, APP_PATH_PRIVATE, pkgname);
+       }
+
+       // external storage
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_MAKE_EXT_DIRECTORY)) {
+               if (access(OPT_STORAGE_SDCARD, F_OK) == 0) {
+                       ret = _coretpk_installer_apply_smack_for_ext(pkgname);
+                       if (ret != 0) {
+                               _LOGE("_coretpk_installer_apply_smack_for_ext(%s) failed.", pkgname);
+                               return -1;
+                       }
+               }
+       }
+
+       return ret;
+}
+
+static char * __getprivilege(const char* pBuf)
+{
+       const char* pKey = "<privilege>";
+       const char* p = NULL;
+       const char* pStart = NULL;
+       const char* pEnd = NULL;
+
+       p = strstr(pBuf, pKey);
+       if (p == NULL)
+               return NULL;
+
+       pStart = p + strlen(pKey);
+       pEnd = strchr(pStart, '<');
+       if (pEnd == NULL)
+               return NULL;
+
+       size_t len = pEnd - pStart;
+       if (len <= 0)
+               return NULL;
+
+       char *pRes = (char*)malloc(len + 1);
+       if(pRes == NULL){
+               _LOGE("malloc failed!!");
+               return NULL;
+       }
+       strncpy(pRes, pStart, len);
+       pRes[len] = 0;
+
+       return pRes;
+}
+
+int _coretpk_installer_apply_privilege(char *pkgid, char *pkgPath, int apiVisibility)
+{
+#if 0
+       int ret = 0;
+       FILE *fp = NULL;
+       char *find_str = NULL;
+       char buf[BUF_SIZE] = {0};
+       char manifest[BUF_SIZE] = {'\0'};
+       const char *perm[] = {NULL, NULL};
+       int apptype = PERM_APP_TYPE_EFL;
+
+       if (apiVisibility & CERT_SVC_VISIBILITY_PLATFORM) {
+               _LOGD("VISIBILITY_PLATFORM!");
+               apptype = PERM_APP_TYPE_EFL_PLATFORM;
+       } else if ((apiVisibility & CERT_SVC_VISIBILITY_PARTNER) ||
+                       (apiVisibility & CERT_SVC_VISIBILITY_PARTNER_OPERATOR) ||
+                       (apiVisibility & CERT_SVC_VISIBILITY_PARTNER_MANUFACTURER)) {
+               _LOGD("VISIBILITY_PARTNER!");
+               apptype = PERM_APP_TYPE_EFL_PARTNER;
+       }
+
+       snprintf(manifest, BUF_SIZE, "%s/%s", pkgPath, CORETPK_XML);
+       _LOGD("pkgid = [%s], manifest = [%s]", pkgid, manifest);
+
+       fp = fopen(manifest, "r");
+       if (fp == NULL) {
+               _LOGE("Fail get : %s\n", manifest);
+               return -1;
+       }
+
+       while (fgets(buf, BUF_SIZE, fp) != NULL) {
+               __str_trim(buf);
+
+               if (strstr(buf, "<privilege>")) {
+                       find_str = __getprivilege(buf);
+                       if (find_str !=  NULL) {
+                               _LOGD("privilege = [%s]", find_str);
+                               perm[0] = find_str;
+
+                               ret = _ri_privilege_enable_permissions(pkgid, apptype, perm, 1);
+                               if(ret < 0) {
+                                       _LOGE("_ri_privilege_enable_permissions(%s, %d) failed.", pkgid, apptype);
+                               } else {
+                                       _LOGD("_ri_privilege_enable_permissions(%s, %d) succeed.", pkgid, apptype);
+                               }
+
+                               free(find_str);
+                               find_str = NULL;
+                       } else {
+                               _LOGD("find_str is null.");
+                       }
+               }
+
+               memset(buf, 0x00, BUF_SIZE);
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+#endif
+       return 0;
+}
+
+int _coretpk_installer_package_install(char *pkgfile, char *pkgid, char *clientid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char manifest[BUF_SIZE] = {'\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       char *temp = NULL;
+       char rwmanifest[BUF_SIZE] = {'\0'};
+       int visibility = 0;
+
+       /* for external installation */
+       app2ext_handle *handle = NULL;
+       GList *dir_list = NULL;
+       int install_status = APP2EXT_STATUS_SUCCESS;
+
+       /*check param*/
+       if (pkgfile == NULL || pkgid == NULL) {
+               _LOGE("invalid input parameter, pkgfile or pkgid is NULL.");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       }
+
+       /*send event for start*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "start", "install");
+       _LOGD("[#]start : _coretpk_installer_package_install[%s]", pkgid);
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "30");
+
+       snprintf(buff, BUF_SIZE, "%s", OPT_USR_APPS);
+       const char *mkdir_argv[] = { "/bin/mkdir", "-p", buff, NULL };
+       ret = _ri_xsystem(mkdir_argv);
+       if (ret != 0) {
+               _LOGE("Failed to make usr application dir.");
+       }
+
+       /*If the directory which will be installed exists, remove it.*/
+       snprintf(buff, BUF_SIZE, "%s/%s/", OPT_USR_APPS, pkgid);
+       if (__is_dir(buff)) {
+               _rpm_delete_dir(buff);
+       }
+
+       /* pre_install */
+       ret = __pre_install_for_mmc(pkgid, pkgfile, &dir_list, &handle);
+       if (ret < 0) {
+               _LOGE("__pre_install_for_mmc is failed.");
+               goto err;
+       }
+
+       const char *unzip_argv[] = { "/usr/bin/unzip", "-o", pkgfile, "-d", buff, NULL };
+       ret = _ri_xsystem(unzip_argv);
+       if (ret != 0) {
+               _LOGE("failed to unzip for path=[%s], ret=[%d]", buff, ret);
+               goto err;
+       }
+       _LOGD("unzip is done successfully, path=[%s]", buff);
+
+       /*getcwd*/
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGL("getcwd()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("current working directory, path=[%s]", cwd);
+
+       /*change dir*/
+       ret = chdir(buff);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*check for signature and certificate*/
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_SIGNATURE)) {
+               ret = _coretpk_installer_verify_signatures(buff, pkgid, &visibility);
+               if (ret < 0) {
+                       _LOGE("failed to verify signature and certificate, pkgid=[%s].", pkgid);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto err;
+               }
+               _LOGD("signature and certificate are verified successfully.");
+       }
+
+   /*chdir*/
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*convert manifest and copy the file to /opt/share/packages*/
+       snprintf(manifest, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, CORETPK_XML);
+       ret = _coretpk_installer_convert_manifest(manifest, pkgid, clientid);
+       if (ret != 0) {
+               _LOGE("failed to convert the manifest.");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+       _LOGD("manifest is converted successfully.");
+
+       if (strstr(pkgfile, ".wgt") != NULL) {
+               _LOGD("wgt file=[%s]", pkgfile);
+
+               if (strstr(manifest, OPT_USR_APPS)) {
+                               snprintf(rwmanifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+                               const char *rw_xml_category[] = { CORETPK_CATEGORY_CONVERTER, rwmanifest, NULL };
+                               ret = _ri_xsystem(rw_xml_category);
+               }
+       }
+
+       /*check the manifest file.*/
+       memset(manifest, '\0', sizeof(manifest));
+       snprintf(manifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       /*compare manifest.xml with schema file(/usr/etc/package-manager/preload/manifest.xsd)*/
+       ret = pkgmgr_parser_check_manifest_validation(manifest);
+       if(ret < 0) {
+               _LOGE("invalid manifest file");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/
+       ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, getuid(), NULL);
+       if (ret < 0) {
+               _LOGE("failed to parse the manifest.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("manifest parsing done successfully.");
+
+       /*search_ug_app*/
+       _coretpk_installer_search_ui_gadget(pkgid);
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "60");
+
+       /*register cert info*/
+       _ri_register_cert(pkgid);
+
+       /*make directory*/
+       ret = _coretpk_installer_make_directory(pkgid);
+       if (ret != 0) {
+               _LOGE("failed to make the directory.");
+               goto err;
+       }
+#if 0
+       /*apply smack to app dir*/
+       ret = _coretpk_installer_apply_smack(pkgid, 1);
+       if (ret != 0) {
+               _LOGE("failed to apply the smack.");
+               goto err;
+       }
+
+       /*apply smack by privilege*/
+       ret = _ri_apply_privilege(pkgid, visibility);
+       if (ret != 0) {
+               _LOGE("failed to apply permission, ret=[%d]", ret);
+       }
+       _LOGD("permission applying done successfully.");
+
+       // Check privilege and visibility
+       if (privilege_list) {
+               ret = _coretpk_installer_verify_privilege_list(privilege_list, visibility);
+               if (ret != 0) {
+                       goto err;
+               } else {
+                       _LOGD("_coretpk_installer_verify_privilege_list done.");
+               }
+       }
+#endif
+#if 0
+       /*reload smack*/
+       ret = _ri_smack_reload(pkgid, REQUEST_TYPE_INSTALL);
+       if (ret != 0) {
+               _LOGD("failed to reload the smack.");
+       }
+#endif
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "100");
+
+       ret = RPM_INSTALLER_SUCCESS;
+
+err:
+       /* post_install */
+       if (ret != 0) {
+               install_status = APP2EXT_STATUS_FAILED;
+       }
+       _LOGD("install status is [%d].", install_status);
+       if (__post_install_for_mmc(handle, pkgid, dir_list, install_status)  < 0) {
+               _LOGE("__post_install_for_mmc is failed.");
+               ret = -1;
+       }
+
+       if (ret == 0) {
+               _LOGD("_coretpk_installer_package_install is done.");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "ok");
+       } else {
+               /*remove db info*/
+               ret = _coretpk_installer_remove_db_info(pkgid);
+               if (ret < 0) {
+                       _LOGE("_coretpk_installer_remove_db_info is failed.");
+               }
+
+               /*remove xml(/opt/share/packages/pkgid.xml)*/
+               if (access(manifest, F_OK) == 0) {
+                       (void)remove(manifest);
+               }
+
+               /*remove app dir(/opt/usr/apps/pkgid)*/
+               snprintf(buff, BUF_SIZE, "%s/%s/", OPT_USR_APPS, pkgid);
+               if (__is_dir(buff)) {
+                       _rpm_delete_dir(buff);
+               }
+
+               /*remove ext app dir(/opt/storage/sdcard/apps/pkgid)*/
+               if (_coretpk_installer_get_configuration_value(INI_VALUE_MAKE_EXT_DIRECTORY)) {
+                       char extpath[BUF_SIZE] = {'\0'};
+                       snprintf(extpath, BUF_SIZE, "%s/%s", OPT_STORAGE_SDCARD_APP_ROOT, pkgid);
+                       if (__is_dir(extpath)) {
+                               _rpm_delete_dir(extpath);
+                       }
+               }
+
+               char *errorstr = NULL;
+               _ri_error_no_to_string(ret, &errorstr);
+               _ri_broadcast_status_notification(pkgid, "coretpk", "error", errorstr);
+               sleep(2);
+
+               _LOGE("_coretpk_installer_package_install is failed.");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "fail");
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_package_uninstall(const char *pkgid)
+{
+       int ret = 0;
+       int update_system = 0;
+
+       update_system = __check_updated_system_package(pkgid);
+
+       if (update_system == 1) {
+               _LOGD("start remove_update, pkgid=[%s]", pkgid);
+               ret = __pkg_remove_update(pkgid);
+       } else {
+               _LOGD("start uninstall, pkgid=[%s]", pkgid);
+               ret = _rpm_uninstall_pkg_with_dbpath(pkgid, 0);
+       }
+
+       if (ret < 0) {
+               _LOGE("uninstallation is failed, pkgid=[%s], update_system=[%d]", pkgid, update_system);
+       } else {
+               _LOGD("uninstallation is done successfully, pkgid=[%s]", pkgid);
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_package_upgrade(char *pkgfile, char *pkgid, char *clientid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char manifest[BUF_SIZE] = { '\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       char rwmanifest[BUF_SIZE] = {'\0'};
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
+       char *temp = NULL;
+       int visibility = 0;
+
+       /* for external upgrade */
+       app2ext_handle *handle = NULL;
+       GList *dir_list = NULL;
+
+       /*check param*/
+       if (pkgfile == NULL || pkgid == NULL) {
+               _LOGE("invalid input parameter, pkgfile or pkgid is NULL.");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       }
+
+       /*send event for start*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "start", "update");
+
+       /*terminate running app*/
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       if (ret < 0) {
+               _LOGE("failed to get the pkginfo handle.");
+               ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+               goto err;
+       }
+       pkgmgrinfo_appinfo_get_list(pkghandle, PMINFO_UI_APP, __ri_check_running_app, NULL);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+    /*remove dir for clean*/
+       __ri_remove_updated_dir(pkgid);
+
+       /* pre_upgrade */
+       ret = __pre_upgrade_for_mmc(pkgid, pkgfile, &dir_list, &handle);
+       if (ret < 0) {
+               _LOGE("__pre_upgrade_for_mmc is failed.");
+               goto err;
+       }
+
+       snprintf(buff, BUF_SIZE, "%s/%s/", OPT_USR_APPS, pkgid);
+       const char *unzip_argv[] = { "/usr/bin/unzip", "-o", pkgfile, "-d", buff, NULL };
+       ret = _ri_xsystem(unzip_argv);
+       if (ret != 0) {
+               _LOGE("failed to unzip for [%s, %d].", buff, ret);
+               goto err;
+       }
+       _LOGD("#unzip[%s] success.", buff);
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "30");
+
+       /*getcwd*/
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGL("getcwd()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#Current working directory is %s.", cwd);
+
+       /*change dir*/
+       ret = chdir(buff);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*check for signature and certificate*/
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_SIGNATURE)) {
+               ret = _coretpk_installer_verify_signatures(buff, pkgid, &visibility);
+               if (ret < 0) {
+                       _LOGE("@Failed to verify signature and certificate[%s].", pkgid);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto err;
+               }
+               _LOGD("#signature and certificate verifying success");
+       }
+
+   /*chdir*/
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*convert manifest and copy the file to /opt/share/packages*/
+       snprintf(manifest, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, CORETPK_XML);
+       ret = _coretpk_installer_convert_manifest(manifest, pkgid, clientid);
+       if (ret != 0) {
+               _LOGE("@Failed to convert the manifest.");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+       _LOGD("#manifest converting success");
+
+       if (strstr(pkgfile, ".wgt") != NULL) {
+               _LOGD("wgt file = [%s]", pkgfile);
+
+               if (strstr(manifest, OPT_USR_APPS)) {
+                               snprintf(rwmanifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+                               const char *rw_xml_category[] = { CORETPK_CATEGORY_CONVERTER, rwmanifest, NULL };
+                               ret = _ri_xsystem(rw_xml_category);
+               }
+       }
+
+       /*check the manifest file.*/
+       memset(manifest, '\0', sizeof(manifest));
+       snprintf(manifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       /*compare manifest.xml with schema file(/usr/etc/package-manager/preload/manifest.xsd)*/
+       ret = pkgmgr_parser_check_manifest_validation(manifest);
+       if(ret < 0) {
+               _LOGE("@invalid manifest file");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "60");
+
+       /*Parse the manifest to get install location and size. If fails, remove manifest info from DB.*/
+       ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
+       if (ret < 0) {
+               _LOGE("@parsing manifest failed.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#parsing manifest success.");
+
+       /*search_ug_app*/
+       _coretpk_installer_search_ui_gadget(pkgid);
+
+       /*unregister cert info*/
+       _ri_unregister_cert(pkgid);
+
+       /*register cert info*/
+       _ri_register_cert(pkgid);
+
+       /*make directory*/
+       ret = _coretpk_installer_make_directory(pkgid);
+       if (ret != 0) {
+               _LOGE("@Failed to make the directory");
+               goto err;
+       }
+
+       // Remove origin rule
+       _ri_privilege_unregister_package(pkgid);
+
+       /*apply smack to app dir*/
+       ret = _coretpk_installer_apply_smack(pkgid, 1);
+       if (ret != 0) {
+               _LOGE("@Failed to apply the smack.");
+               goto err;
+       }
+
+       /*apply smack by privilege*/
+       ret = _ri_apply_privilege(pkgid, visibility);
+       if (ret != 0) {
+               _LOGE("@Failed to apply permission[%d].", ret);
+       }
+       _LOGD("#permission applying success.");
+
+       // Check privilege and visibility
+       if (privilege_list) {
+               ret = _coretpk_installer_verify_privilege_list(privilege_list, visibility);
+               if (ret != 0) {
+                       goto err;
+               } else {
+                       _LOGD("_coretpk_installer_verify_privilege_list(PRVMGR_PACKAGE_TYPE_CORE) is ok.");
+               }
+       }
+
+#if 0
+       /*reload smack*/
+       ret = _ri_smack_reload(pkgid, REQUEST_TYPE_UPGRADE);
+       if (ret != 0) {
+               _LOGE("@Failed to reload the smack.");
+       }
+#endif
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "coretpk", "install_percent", "100");
+       ret = RPM_INSTALLER_SUCCESS;
+
+err:
+       /* post_upgrade */
+       if (__post_upgrade_for_mmc(handle, pkgid, dir_list) < 0) {
+               _LOGE("__post_upgrade_for_mmc is failed.");
+               ret = -1;
+       }
+
+       if (ret == 0) {
+               _LOGD("[#]end : _coretpk_installer_package_upgrade");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "ok");
+       } else {
+
+               /*TODO:need to add recovery logic*/
+
+               char *errorstr = NULL;
+               _ri_error_no_to_string(ret, &errorstr);
+               _ri_broadcast_status_notification(pkgid, "coretpk", "error", errorstr);
+               sleep(2);
+
+               _LOGE("[@]end : _coretpk_installer_package_upgrade");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "fail");
+       }
+
+       return ret;
+}
+
+char* _coretpk_installer_get_pkgid_from_directory_path(char *dirpath)
+{
+       char* subpath = strrchr(dirpath, '/');
+       return subpath + 1;
+}
+
+int _coretpk_installer_directory_install(char *dirpath, char *clientid)
+{
+       int ret = 0;
+       char manifest[BUF_SIZE] = {'\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       char *temp = NULL;
+       char *pkgid = NULL;
+       int visibility = 0;
+
+       // check param
+       if (dirpath == NULL) {
+               _LOGE("dirpath is NULL.");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       }
+
+       _LOGD("directory_install start: dirpath = [%s]", dirpath);
+
+       // getcwd
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGE("getcwd() failed. [%d][%s]", errno, strerror(errno));
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       _LOGD("Current working directory is [%s].", cwd);
+
+       // change dir
+       ret = chdir(dirpath);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed. [%d][%s]", dirpath, errno, strerror(errno));
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       // check for signature and certificate
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_SIGNATURE)) {
+               pkgid = _coretpk_installer_get_pkgid_from_directory_path(dirpath);
+               _LOGD("pkgid=[%s]", pkgid);
+
+               ret = _coretpk_installer_verify_signatures(dirpath, pkgid, &visibility);
+               if (ret < 0) {
+                       _LOGE("_coretpk_installer_verify_signatures(%s, %s) failed.", dirpath, pkgid);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto err;
+               }
+               _LOGD("verify_signatures(%s, %s) succeed!", dirpath, pkgid);
+       }
+
+  // chdir
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed. [%d][%s]", cwd, errno, strerror(errno));
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       // convert manifest and copy the file to /usr/share/packages
+       snprintf(manifest, BUF_SIZE, "%s/%s", dirpath, CORETPK_XML);
+       if (pkgid == NULL) {
+               pkgid = _coretpk_installer_get_pkgid_from_directory_path(dirpath);
+               _LOGD("pkgid = [%s]", pkgid);
+       }
+
+       ret = _coretpk_installer_convert_manifest(manifest, pkgid, clientid);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_convert_manifest() failed. manifest = [%s], pkgid = [%s]", manifest, pkgid);
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+       _LOGD("convert_manifest(%s, %s) succeed!", manifest, pkgid);
+
+       // check the manifest file
+       memset(manifest, '\0', sizeof(manifest));
+       if (strstr(dirpath, OPT_USR_APPS)) {
+               snprintf(manifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       } else {
+               snprintf(manifest, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+       }
+       _LOGD("manifest = [%s]", manifest);
+
+       // compare manifest.xml with schema file(/usr/etc/package-manager/preload/manifest.xsd)
+       ret = pkgmgr_parser_check_manifest_validation(manifest);
+       if(ret < 0) {
+               _LOGE("pkgmgr_parser_check_manifest_validation(%s) failed.", manifest);
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       // Parse the manifest to get install location and size. If installation fails, remove manifest info from DB
+       ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+       if (ret < 0) {
+               _LOGE("pkgmgr_parser_parse_manifest_for_installation(%s) failed.", manifest);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("parse_manifest(%s) succeed!", manifest);
+
+       // register cert info
+       _ri_register_cert(pkgid);
+
+       // make directory
+       ret = _coretpk_installer_make_directory(pkgid);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_make_directory(%s) failed.", pkgid);
+               goto err;
+       }
+       _LOGD("make_directory(%s) succeed!", pkgid);
+
+       // apply smack to app dir
+       ret = _coretpk_installer_apply_smack(pkgid, 1);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_smack(%s) failed.", pkgid);
+       }
+       _LOGD("apply_smack(%s) succeed!", pkgid);
+
+       // apply smack by privilege
+       ret = _ri_apply_privilege(pkgid, visibility);
+       if (ret != 0) {
+               _LOGE("_ri_apply_privilege(%s, %d) failed. ret = [%d]", pkgid, visibility, ret);
+       }
+       _LOGD("apply_privilege(%s, %d) succeed!", pkgid, visibility);
+
+       ret = RPM_INSTALLER_SUCCESS;
+
+err:
+       _LOGD("directory_install end: dirpath = [%s], ret = [%d]", dirpath, ret);
+
+       return ret;
+}
+
+int _coretpk_installer_prepare_package_install(char *pkgfile, char *clientid)
+{
+       int ret = 0;
+       pkginfo *info = NULL;
+       pkginfo *dbinfo = NULL;
+       char *pkgid = NULL;
+
+       _LOGD("start");
+
+       info = _coretpk_installer_get_pkgfile_info(pkgfile);
+       if (info == NULL || (strlen(info->package_name) == 0)) {
+               _LOGE("failed to get the pkg info.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       pkgid = strdup(info->package_name);
+       if (pkgid == NULL) {
+               _LOGE("strdup() failed.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       dbinfo = _rpm_installer_get_pkgname_info(info->package_name);
+
+       if (dbinfo == NULL) {
+               /*package is not installed. Go for installation.*/
+               _LOGD("start to install");
+               ret = _coretpk_installer_package_install(pkgfile, pkgid, clientid);
+       } else if (strcmp(info->version, dbinfo->version) > 0) {
+               /*upgrade */
+               _LOGD("start to upgrade");
+               ret = _coretpk_installer_package_upgrade(pkgfile, info->package_name, clientid);
+       } else if (strcmp(info->version, dbinfo->version) < 0) {
+               /*downgrade*/
+               _LOGD("start to downgrade");
+               ret = _coretpk_installer_package_upgrade(pkgfile, info->package_name, clientid);
+       } else {
+               /*same package. Reinstall it. Manifest should be parsed again */
+               _LOGD("start to reinstall");
+               ret = _coretpk_installer_package_upgrade(pkgfile, info->package_name, clientid);
+       }
+
+       if (ret != 0) {
+               _LOGE("result=[%d]", ret);
+       } else {
+               _LOGD("success");
+       }
+
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+       if (dbinfo) {
+               free(dbinfo);
+               dbinfo = NULL;
+       }
+
+       if (pkgid) {
+               free(pkgid);
+               pkgid = NULL;
+       }
+
+       return ret;
+
+err:
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+
+       _ri_broadcast_status_notification("Invalid package", "invalid", "start", "install");
+       _ri_broadcast_status_notification("Invalid package", "invalid", "end", "fail");
+
+       return ret;
+}
+
+int _coretpk_installer_prepare_package_uninstall(const char *pkgid)
+{
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL.");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       }
+
+       _LOGD("pkgid=[%s]", pkgid);
+
+       int ret = 0;
+       pkginfo *dbinfo = NULL;
+
+       dbinfo = _rpm_installer_get_pkgname_info(pkgid);
+       if (dbinfo == NULL) {
+               _LOGE("[%s] is not installed.", pkgid);
+               return RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+       }
+
+       ret = _coretpk_installer_package_uninstall(pkgid);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_package_uninstall() failed, pkgid=[%s], ret=[%d]", pkgid, ret);
+       } else {
+               _LOGD("_coretpk_installer_package_uninstall() is done successfully, pkgid=[%s]", pkgid);
+       }
+
+       if (dbinfo) {
+               free(dbinfo);
+               dbinfo = NULL;
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_prepare_directory_install(char *dirpath, char *clientid)
+{
+       int ret = 0;
+
+       ret = _coretpk_installer_directory_install(dirpath, clientid);
+       _LOGD("path=[%s], result=[%d]", dirpath, ret);
+
+       return ret;
+}
+
+int _coretpk_installer_package_move(char* pkgid, int move_type)
+{
+#if 0
+       app2ext_handle *hdl = NULL;
+       int ret = 0;
+       int movetype = -1;
+       GList *dir_list = NULL;
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
+
+       _ri_broadcast_status_notification(pkgid, "coretpk", "start", "move");
+       _LOGD("[#]start : _coretpk_installer_package_move[%s][%d]", pkgid, move_type);
+
+       if (move_type == PM_MOVE_TO_INTERNAL) {
+               movetype = APP2EXT_MOVE_TO_PHONE;
+       } else if (move_type == PM_MOVE_TO_SDCARD) {
+               movetype = APP2EXT_MOVE_TO_EXT;
+       } else {
+               ret = RPM_INSTALLER_ERR_WRONG_PARAM;
+               goto err;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       if (ret < 0) {
+               _LOGE("@Failed to get the pkginfo handle.");
+               ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+               goto err;
+       }
+
+       /* Terminate the running instance of app */
+       pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+       hdl = app2ext_init(APP2EXT_SD_CARD);
+       if ((hdl != NULL) && (hdl->interface.move != NULL)) {
+               dir_list = __rpm_populate_dir_list();
+               if (dir_list == NULL) {
+                       _LOGE("@Failed to get the populate directory.");
+                       ret = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+                       goto err;
+               }
+
+               ret = hdl->interface.move(pkgid, dir_list, movetype);
+               __rpm_clear_dir_list(dir_list);
+               if (ret != 0) {
+                       _LOGE("@Failed to move app.");
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto err;
+               } else {
+                       if(move_type == PM_MOVE_TO_INTERNAL) {
+                               _LOGD("#updating the installed storage from external to internal");
+                               ret = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_INTERNAL);
+                       } else {
+                               _LOGD("#updating the installed storage from internal to external");
+                               ret = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_EXTERNAL);
+                       }
+
+                       if (ret != PMINFO_R_OK) {
+                               _LOGE("@Failed to udpate the installed storage.");
+                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                               goto err;
+                       }
+               }
+
+       } else {
+               _LOGE("@Failed to get app2ext handle.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+err:
+       if (hdl != NULL) {
+               app2ext_deinit(hdl);
+       }
+
+       if (ret == 0) {
+               _LOGD("[#]end : _coretpk_installer_package_move");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "ok");
+       } else {
+               _LOGE("[@]end : _coretpk_installer_package_move");
+               _ri_broadcast_status_notification(pkgid, "coretpk", "end", "fail");
+       }
+
+       return ret;
+#endif
+       return 0;
+}
+
+int _coretpk_installer_copy_file( const char *src_path, const char *dst_path)
+{
+       int ret = 0;
+       FILE *src, *dst;
+       int rc = 0;
+       unsigned char temp_buf[8192] = {'\0',};
+       size_t size_of_uchar = sizeof(unsigned char);
+       size_t size_of_temp_buf = sizeof(temp_buf);
+
+    src = fopen(src_path, "r");
+    if (src == NULL) {
+               _LOGE("@Failed to open(). path=%s, E:%d(%s)", src_path, errno, strerror(errno));
+        return  -1;
+    }
+
+    dst = fopen(dst_path, "w");
+    if (dst == NULL) {
+       /*No such file or directory*/
+       if (errno == ENOENT) {
+               /*make the path of parent dir for the data*/
+                       char *path = strdup(dst_path);
+                       char *p = strrchr(path, '/');
+                       if (p) {
+                               p++;
+                       } else {
+                               ret = -1;
+                               free(path);
+                               goto err;
+                       }
+                       int idx = strlen(path) - strlen(p);
+                       path[idx] = '\0';
+
+                       /*make the parent dir*/
+                       const char *mkdir_argv[] = { "/bin/mkdir", "-p", path, NULL };
+                       ret = _ri_xsystem(mkdir_argv);
+                       if (ret != 0) {
+                               _LOGE("Failed to make parent dir.");
+                       }
+
+                       _LOGD("#[%s] is created.", path);
+                       free(path);
+
+                       /*open the file*/
+                       dst = fopen(dst_path, "w");
+                       if (dst == NULL) {
+                               _LOGE("Failed to open dst file. file=%s, E:%d(%s)", dst_path, errno, strerror(errno));
+                               ret = -1;
+                               goto err;
+                       }
+       } else {
+                       _LOGE("Failed to open dst file. file=%s, E:%d(%s)", dst_path, errno, strerror(errno));
+                       ret = -1;
+                       goto err;
+       }
+    }
+
+    while (!feof(src)) {
+        rc = fread( temp_buf, size_of_uchar, size_of_temp_buf, src);
+        fwrite( temp_buf, size_of_uchar, rc, dst);
+    }
+
+ err:
+        if (src) {
+                fclose(src);
+        }
+        if (dst) {
+                fclose(dst);
+        }
+
+    return  ret;
+}
+
+int _coretpk_installer_handle_rds_data(char *pkgid, GList *delete, GList *add, GList *modify, int *updatexml)
+{
+       int ret = 0;
+       GList *list = NULL;
+       char handledata[BUF_SIZE] = {'\0'};
+       char srcfile[BUF_SIZE] = {'\0'};
+       char destfile[BUF_SIZE] = {'\0'};
+
+       /*delete*/
+       if (delete != NULL) {
+               list = g_list_first(delete);
+               while (list) {
+                       char *data = (char *)list->data;
+                       if (!strcasestr(data, RDS_DELTA_DELETE)) {
+                               snprintf(handledata, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, data);
+
+                               const char *delete_argv[] = { "/bin/rm", "-rf", handledata, NULL };
+                               ret = _ri_xsystem(delete_argv);
+                               if (ret == 0) {
+                                       _LOGD("#[delete] success : %s", data);
+                               } else {
+                                       _LOGD("#[delete] fail : %s", data);
+                               }
+                               memset(handledata, '\0', sizeof(handledata));
+                       }
+
+                       list = g_list_next(list);
+               }
+       } else {
+               _LOGD("#There is no deleted data.");
+       }
+
+       /*add*/
+       if (add != NULL) {
+               list = g_list_first(add);
+               while (list) {
+                       char *data = (char *)list->data;
+                       if (!strcasestr(data, RDS_DELTA_ADD)) {
+                               snprintf(srcfile, BUF_SIZE, "%s/tmp/%s/%s", OPT_USR_APPS, pkgid, data);
+                               snprintf(destfile, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, data);
+
+                               if (__is_dir((char *)srcfile)) {
+                                       const char *mkdir_argv[] = { "/bin/mkdir", "-p", destfile, NULL };
+                                       _ri_xsystem(mkdir_argv);
+                                       _LOGD("#[%s] is created.", destfile);
+                               } else {
+                                       ret =_coretpk_installer_copy_file(srcfile, destfile);
+                                       if (ret == 0) {
+                                               _LOGD("#[add] success : %s", data);
+                                       } else {
+                                               _LOGD("#[add] fail : %s", data);
+                                       }
+                               }
+                               memset(srcfile, '\0', sizeof(srcfile));
+                               memset(destfile, '\0', sizeof(destfile));
+                       }
+
+                       list = g_list_next(list);
+               }
+       } else {
+               _LOGD("#There is no added data.");
+       }
+
+       /*modify*/
+       if (modify != NULL) {
+               list = g_list_first(modify);
+               while (list) {
+                       char *data = (char *)list->data;
+                       if (!strcasestr(data, RDS_DELTA_MODIFY)) {
+                               /*If XML is modified, the checking codes for xml has to be executed.*/
+                               if (strcmp(data, CORETPK_XML) == 0) {
+                                       *updatexml = 1;
+                               }
+
+                               snprintf(srcfile, BUF_SIZE, "%s/tmp/%s/%s", OPT_USR_APPS, pkgid, data);
+                               snprintf(destfile, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, data);
+
+                               ret =_coretpk_installer_copy_file(srcfile, destfile);
+                               if (ret == 0) {
+                                       _LOGD("#[modify] success : %s", data);
+                               } else {
+                                       _LOGD("#[modify] fail : %s", data);
+                               }
+
+                               memset(srcfile, '\0', sizeof(srcfile));
+                               memset(destfile, '\0', sizeof(destfile));
+                       }
+                       list = g_list_next(list);
+               }
+       } else {
+               _LOGD("#There is no modified data.");
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_read_rds_file(char *pkgid, char *rdsfile, int *updatexml)
+{
+       int ret = 0;
+       int state = RDS_STATE_NONE;
+
+       char buffer[BUF_SIZE] = {'\0'};
+       FILE *fi = NULL;
+
+       GList *delete_list = NULL;
+       GList *add_list = NULL;
+       GList *modify_list = NULL;
+
+       if (access(rdsfile, F_OK) != 0) {
+               _LOGL("access()", errno);
+               return -1;
+       }
+
+       fi = fopen(rdsfile, "r");
+       if (fi == NULL) {
+               _LOGL("fopen()", errno);
+               return -1;
+       }
+
+       while (fgets(buffer, BUF_SIZE, fi) != NULL) {
+               buffer[strlen(buffer) - 1] = '\0';
+
+               /*check rds state*/
+               if (buffer[0] == '#') {
+                       if (strcasestr(buffer, RDS_DELTA_DELETE)) {
+                               state = RDS_STATE_DELETE;
+                       } else if (strcasestr(buffer, RDS_DELTA_ADD)) {
+                               state = RDS_STATE_ADD;
+                       } else if (strcasestr(buffer, RDS_DELTA_MODIFY)) {
+                               state = RDS_STATE_MODIFY;
+                       } else {
+                               state = RDS_STATE_NONE;
+                       }
+               }
+
+               if (state == RDS_STATE_NONE) {
+                       _LOGE("Unknown RDS State, INSTALLER_RDS_STATE_NONE");
+                       continue;
+               }
+
+               /*make rds data list*/
+               switch (state) {
+                       case RDS_STATE_DELETE:
+                               _LOGD("RDS_STATE_DELETE data : %s", buffer);
+                               delete_list = g_list_append(delete_list, g_strdup(buffer));
+                               break;
+
+                       case RDS_STATE_ADD:
+                               _LOGD("RDS_STATE_ADD data : %s", buffer);
+                               add_list = g_list_append(add_list, g_strdup(buffer));
+                               break;
+
+                       case RDS_STATE_MODIFY:
+                               _LOGD("RDS_STATE_MODIFY data : %s", buffer);
+                               modify_list = g_list_append(modify_list, g_strdup(buffer));
+                               break;
+               }
+       }
+
+       ret = _coretpk_installer_handle_rds_data(pkgid, delete_list, add_list, modify_list, updatexml);
+       if (ret != 0) {
+               _LOGE("@Failed to handle rds data.");
+       }
+
+       if (delete_list != NULL) {
+               g_list_free(delete_list);
+       }
+       if (add_list != NULL) {
+               g_list_free(add_list);
+       }
+       if (modify_list != NULL) {
+               g_list_free(modify_list);
+       }
+
+       fclose(fi);
+       return ret;
+}
+
+int _coretpk_installer_package_reinstall(char *pkgid, char *clientid)
+{
+       int ret = 0;
+       char manifest[BUF_SIZE] = {'\0'};
+       char rdsfile[BUF_SIZE] = {'\0'};
+       char dirpath[BUF_SIZE] = {'\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       char *temp = NULL;
+       int updatexml = 0;
+       int visibility = 0;
+
+       /*check param*/
+       if (pkgid == NULL) {
+               _LOGE("@The input param[pkgid] is NULL.");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       }
+
+       pkgmgr_installer_send_signal(pi, "coretpk", pkgid, "start", "update");
+       _LOGD("[#]start : _coretpk_installer_package_reinstall[%s]", pkgid);
+
+       snprintf(rdsfile, BUF_SIZE, "%s/tmp/%s/%s", OPT_USR_APPS, pkgid, RDS_DELTA_FILE);
+       ret = _coretpk_installer_read_rds_file(pkgid, rdsfile, &updatexml);
+       if (ret != 0) {
+               _LOGE("@Failed to read the rds file.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#RDS file reading success");
+
+       pkgmgr_installer_send_signal(pi, "coretpk", pkgid, "install_percent", "30");
+
+       /*getcwd*/
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGL("getcwd()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#Current working directory is %s.", cwd);
+
+       /*change dir*/
+       snprintf(dirpath, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+       ret = chdir(dirpath);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*check for signature and certificate*/
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_SIGNATURE)) {
+
+               pkgid = _coretpk_installer_get_pkgid_from_directory_path(dirpath);
+               _LOGD("pkgid[%s]", pkgid);
+
+               ret = _coretpk_installer_verify_signatures(dirpath, pkgid, &visibility);
+               if (ret < 0) {
+                       _LOGE("failed to verify signature and certificate, pkgid=[%s].", pkgid);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto err;
+               }
+               _LOGD("signature and certificate verifying success");
+       }
+
+   /*chdir*/
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       if (updatexml) {
+               /*convert manifest and copy the file to /opt/share/packages*/
+               snprintf(manifest, BUF_SIZE, "%s/%s", dirpath, CORETPK_XML);
+               if (pkgid == NULL) {
+                       pkgid = _coretpk_installer_get_pkgid_from_directory_path(dirpath);
+                       _LOGD("pkgid[%s]", pkgid);
+               }
+               ret = _coretpk_installer_convert_manifest(manifest, pkgid, clientid);
+               if (ret != 0) {
+                       _LOGE("@Failed to convert the manifest.");
+                       ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+                       goto err;
+               }
+               _LOGD("#manifest converting success");
+
+               /*check the manifest file.*/
+               memset(manifest, '\0', sizeof(manifest));
+               snprintf(manifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+               /*compare manifest.xml with schema file(/usr/etc/package-manager/preload/manifest.xsd)*/
+               ret = pkgmgr_parser_check_manifest_validation(manifest);
+               if(ret < 0) {
+                       _LOGE("@invalid manifest file");
+                       ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+                       goto err;
+               }
+
+               /*Parse the manifest to get install location and size. If failed, remove manifest info from DB.*/
+               ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
+               if (ret < 0) {
+                       _LOGE("@Failed to parse the manifest.");
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto err;
+               }
+               _LOGD("#manifest parsing success");
+       }
+
+       pkgmgr_installer_send_signal(pi, "coretpk", pkgid, "install_percent", "60");
+
+       /*register cert info*/
+       _ri_register_cert(pkgid);
+
+       /*make directory*/
+       ret = _coretpk_installer_make_directory(pkgid);
+       if (ret != 0) {
+               _LOGE("@Failed to make directory");
+               goto err;
+       }
+
+       _ri_privilege_unregister_package(pkgid);
+
+       /*apply smack to app dir*/
+       ret = _coretpk_installer_apply_smack(pkgid, 1);
+       if (ret != 0) {
+               _LOGE("@Failed to apply smack.");
+               goto err;
+       }
+
+       /*apply smack by privilege*/
+       ret = _ri_apply_privilege(pkgid, visibility);
+       if (ret != 0) {
+               _LOGE("@Failed to apply permission[%d].", ret);
+       }
+       _LOGD("#permission applying success.");
+
+       // Check privilege and visibility
+       if (privilege_list) {
+               ret = _coretpk_installer_verify_privilege_list(privilege_list, visibility);
+               if (ret != 0) {
+                       goto err;
+               } else {
+                       _LOGD("_coretpk_installer_verify_privilege_list(PRVMGR_PACKAGE_TYPE_CORE) is ok.");
+               }
+       }
+
+#if 0
+       /*reload smack*/
+       ret = _ri_smack_reload(pkgid, REQUEST_TYPE_UPGRADE);
+       if (ret != 0) {
+               _LOGE("@Failed to reload the smack.");
+       }
+#endif
+
+       pkgmgr_installer_send_signal(pi, "coretpk", pkgid, "install_percent", "100");
+       ret = RPM_INSTALLER_SUCCESS;
+
+err:
+       if (ret == 0) {
+               _LOGD("[#]end : _coretpk_installer_package_reinstall");
+               pkgmgr_installer_send_signal(pi, "coretpk", pkgid, "end", "ok");
+       } else {
+               /*remove db info*/
+               ret = _coretpk_installer_remove_db_info(pkgid);
+               if (ret < 0) {
+                       _LOGE("_coretpk_installer_remove_db_info is failed.");
+               }
+
+               /*remove xml(/opt/share/packages/pkgid.xml)*/
+               if (access(manifest, F_OK) == 0) {
+                       (void)remove(manifest);
+               }
+
+               /*remove app dir(/opt/usr/apps/pkgid)*/
+               if (__is_dir(dirpath)) {
+                       _rpm_delete_dir(dirpath);
+               }
+
+               _LOGE("[@]end : _coretpk_installer_package_reinstall");
+               pkgmgr_installer_send_signal(pi, "coretpk", pkgid, "end", "fail");
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_csc_install(char *path_str, char *remove_str)
+{
+       int ret = 0;
+       pkginfo *info = NULL;
+       char buff[BUF_SIZE] = {'\0'};
+       char manifest[BUF_SIZE] = {'\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       char *temp = NULL;
+       char *csc_tags[3] = {NULL, };
+       int visibility = 0;
+
+       /*check param*/
+       if (path_str == NULL || remove_str == NULL) {
+               _LOGE("@The input param[pkgfile or pkgid] is NULL.");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       }
+
+       _LOGD("[##]csc-core : start csc_install[path=%s]", path_str);
+
+       info = _coretpk_installer_get_pkgfile_info(path_str);
+       if (info == NULL || (strlen(info->package_name) == 0)) {
+               _LOGE("[@@]end : _coretpk_installer_prepare_package_install: failed to get the pkg info.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : get pkgid [%s]", info->package_name);
+
+       /*If the directory which will be installed exists, remove it.*/
+       snprintf(buff, BUF_SIZE, "%s/%s/", OPT_USR_APPS, info->package_name);
+       if (__is_dir(buff)) {
+               _rpm_delete_dir(buff);
+       }
+
+       _LOGD("[##]csc-core : real path [%s]", buff);
+
+       const char *unzip_argv[] = { "/usr/bin/unzip", "-o", path_str, "-d", buff, NULL };
+       ret = _ri_xsystem(unzip_argv);
+       if (ret != 0) {
+               _LOGE("@Failed to unzip for [%s, %d].", buff, ret);
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : unzip success[%s]", buff);
+
+       /*getcwd*/
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGL("getcwd()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*change dir*/
+       ret = chdir(buff);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : check signature");
+
+       /*check for signature and certificate*/
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_SIGNATURE)) {
+               ret = _coretpk_installer_verify_signatures(buff, info->package_name, &visibility);
+               if (ret < 0) {
+                       _LOGE("@Failed to verify signature and certificate[%s].", info->package_name);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto err;
+               }
+               _LOGD("[##]csc-core : signature verify success[%s]", buff);
+       }
+
+   /*chdir*/
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGL("chdir()", errno);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       /*convert manifest and copy the file to /opt/share/packages*/
+       snprintf(manifest, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, info->package_name, CORETPK_XML);
+       ret = _coretpk_installer_convert_manifest(manifest, info->package_name, NULL);
+       if (ret != 0) {
+               _LOGE("@Failed to convert the manifest.");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : manifest converting success");
+
+       /*check the manifest file.*/
+       memset(manifest, '\0', sizeof(manifest));
+       snprintf(manifest, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, info->package_name);
+       /*compare manifest.xml with schema file(/usr/etc/package-manager/preload/manifest.xsd)*/
+       ret = pkgmgr_parser_check_manifest_validation(manifest);
+       if(ret < 0) {
+               _LOGE("@invalid manifest file");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : manifest validation success");
+
+       /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/
+       if (strcmp(remove_str,"true")==0)
+               csc_tags[0] = "removable=true";
+       else
+               csc_tags[0] = "removable=false";
+
+       csc_tags[1] = "preload=true";
+       csc_tags[2] = NULL;
+
+       ret = pkgmgr_parser_parse_manifest_for_installation(manifest, csc_tags);
+       if (ret < 0) {
+               _LOGE("@Failed to parse the manifest.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : register manifest success");
+
+       /*register cert info*/
+       _ri_register_cert(info->package_name);
+
+       /*make directory*/
+       ret = _coretpk_installer_make_directory(info->package_name);
+       if (ret != 0) {
+               _LOGE("@Failed to make the directory");
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : make directory success");
+
+       /*apply smack to app dir*/
+       ret = _coretpk_installer_apply_smack(info->package_name, 1);
+       if (ret != 0) {
+               _LOGE("@Failed to apply the smack.");
+               goto err;
+       }
+
+       _LOGD("[##]csc-core : apply_smack success");
+
+       /*apply smack by privilege*/
+       ret = _ri_apply_privilege(info->package_name, visibility);
+       if (ret != 0) {
+               _LOGE("@Failed to apply permission[%d].", ret);
+       }
+
+       _LOGD("[##]csc-core : apply_privilege success");
+
+#if 0
+       /*reload smack*/
+       ret = _ri_smack_reload(info->package_name, REQUEST_TYPE_INSTALL);
+       if (ret != 0) {
+               _LOGD("@Failed to reload the smack.");
+       }
+#endif
+
+       _LOGD("[##]csc-core : smack_reload success");
+
+       ret = RPM_INSTALLER_SUCCESS;
+
+err:
+       if (ret == 0) {
+               _LOGD("[##]csc-core : finish csc core success");
+       } else {
+               /*remove xml(/opt/share/packages/pkgid.xml)*/
+               if (access(manifest, F_OK) == 0) {
+                       (void)remove(manifest);
+               }
+
+               /*remove app dir(/opt/usr/apps/pkgid)*/
+               snprintf(buff, BUF_SIZE, "%s/%s/", OPT_USR_APPS, info->package_name);
+               if (__is_dir(buff)) {
+                       _rpm_delete_dir(buff);
+               }
+               _LOGD("[##]csc-core : finish csc core fail");
+
+       }
+
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+
+       return ret;
+}
diff --git a/backend/src/coretpk/inc/coretpk-installer-internal.h b/backend/src/coretpk/inc/coretpk-installer-internal.h
new file mode 100644 (file)
index 0000000..5a9df5c
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * coretpk-installer-internal
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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 __CORETPK_INSTALLER_INTERNAL_H_
+#define __CORETPK_INSTALLER_INTERNAL_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+/*use pkginfo*/
+#include "rpm-installer-util.h"
+#include "coretpk-installer.h"
+#include "coretpk-installer-type.h"
+
+int _coretpk_installer_directory_install(char* dirpath, char *clientid);
+
+int _coretpk_installer_package_install(char *pkgfile, char *pkgid, char *clientid);
+int _coretpk_installer_package_uninstall(const char *pkgid);
+int _coretpk_installer_package_reinstall(char *dirpath, char *clientid);
+int _coretpk_installer_package_upgrade(char *pkgfile, char *pkgid, char *clientid);
+
+int _coretpk_installer_csc_install(char *path_str, char *remove_str);
+
+pkginfo *_coretpk_installer_get_pkgfile_info(char *pkgfile);
+char* _coretpk_installer_load_directory(char *directory,char* pkgfile);
+int _coretpk_installer_convert_manifest(char *manifestfilepath, char *pkgid, char *clientid);
+int _coretpk_installer_get_configuration_value(char *value);
+
+int _coretpk_installer_change_mode(char* path, int mode);
+int _coretpk_installer_change_file_owner(char* path, int ownerid, int groupid);
+int _coretpk_installer_change_directory_owner(char* dirpath, int ownerid, int groupid);
+int _coretpk_installer_make_directory_for_ext(char *pkgid);
+int _coretpk_installer_make_directory(char *pkgid);
+int _coretpk_installer_apply_smack(char *pkgname, int flag);
+int _coretpk_installer_apply_privilege(char *pkgid, char *pkgPath, int apiVisibility);
+void _coretpk_installer_search_ui_gadget(const char *pkgid);
+int _coretpk_installer_set_smack_label_access(const char *path, const char *label);
+int _coretpk_installer_get_smack_label_access(const char *path, char **label);
+int _coretpk_installer_set_smack_label_transmute(const char *path, const char *flag);
+int _coretpk_installer_remove_db_info(const char *pkgid);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __CORETPK_INSTALLER_INTERNAL_H_ */
diff --git a/backend/src/coretpk/inc/coretpk-installer-type.h b/backend/src/coretpk/inc/coretpk-installer-type.h
new file mode 100644 (file)
index 0000000..4c8bfb0
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * coretpk-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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 __CORETPK_INSTALLER_TYPE_H_
+#define __CORETPK_INSTALLER_TYPE_H_
+
+/* For multi-user support */
+#include <tzplatform_config.h>
+#include <pkgmgr-info.h>
+#include <unistd.h>
+
+#include "rpm-installer-util.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+#define CORETPK_INSTALL                                                                        "coretpk-install"
+#define CORETPK_UNINSTALL                                                              "coretpk-uninstall"
+#define CORETPK_DIRECTORY_INSTALL                              "coretpk-directory-install"
+#define CORETPK_MOVE                                                                           "coretpk-move"
+#define CORETPK_REINSTALL                                                              "coretpk-reinstall"
+#define MAX_BUF_SIZE                                                   4096
+#define BUF_SIZE                                                               1024
+#define TEMP_DIR                                                               tzplatform_mkpath(TZ_USER_HOME, ".rpminstaller")
+#define TEMP_XML_DIR                                                   "/tmp/rpminstaller"
+#define CORETPK_XML                                                    "tizen-manifest.xml"
+#define USR_APPS                                                               tzplatform_getenv(TZ_SYS_RO_APP)
+#define OPT_USR_APPS                                                   tzplatform_getenv(TZ_USER_APP)
+#define USR_SHARE_PACKAGES                                     tzplatform_getenv(TZ_SYS_RO_PACKAGES)
+#define OPT_SHARE_PACKAGES                                     getUserManifestPath(getuid())
+#define CORETPK_RO_XML_CONVERTER                       "/usr/bin/coretpk_ro_xml_converter.sh"
+#define CORETPK_RW_XML_CONVERTER                       "/usr/bin/coretpk_rw_xml_converter.sh"
+#define CORETPK_CATEGORY_CONVERTER             "/usr/bin/coretpk_category_converter.sh"
+
+#define SIGNATURE1_XML                                         "signature1.xml"
+#define AUTHOR_SIGNATURE_XML                           "author-signature.xml"
+#define APP_OWNER_ID                                                   5000
+#define APP_GROUP_ID                                                   5000
+#define PERM_BASE                                                      (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) // 0644
+#define PERM_EXECUTE                                                   (S_IXUSR | S_IXGRP | S_IXOTH)
+#define PERM_WRITE                                                     (S_IWUSR | S_IWGRP | S_IWOTH)
+#define CORETPK_CONFIG_PATH                                    "/usr/etc/coretpk-installer-config.ini"
+#define INCLUDE_ABSOLUTE_PATH                          44
+#define OPT_STORAGE_SDCARD                                     "/opt/storage/sdcard/"
+#define OPT_STORAGE_SDCARD_APP_ROOT            "/opt/storage/sdcard/apps"
+#define INI_VALUE_MAKE_EXT_DIRECTORY           "make-ext-directory"
+#define INI_VALUE_SIGNATURE                                    "signature"
+#define INI_VALUE_AUTHOR_SIGNATURE                     "author-signature"
+#define RDS_DELTA_FILE                                         ".rds_delta"
+#define RDS_DELTA_ADD                                          "#add"
+#define RDS_DELTA_DELETE                                       "#delete"
+#define RDS_DELTA_MODIFY                                       "#modify"
+
+enum rds_state_type {
+       RDS_STATE_NONE,
+       RDS_STATE_DELETE,
+       RDS_STATE_ADD,
+       RDS_STATE_MODIFY,
+};
+
+enum request_type {
+       REQUEST_TYPE_INSTALL,
+       REQUEST_TYPE_UNINSTALL,
+       REQUEST_TYPE_UPGRADE,
+};
+
+#define _LOGL(message, error)   \
+       char exception[BUF_SIZE] = {'\0'}; \
+       char *ret = NULL; \
+       ret = strerror_r(error, exception, BUF_SIZE); \
+       if (ret) strcpy(exception, ret); \
+       _LOGP("@%s failed[%s]. func:[%s] line:[%d]\n", message, exception, __FUNCTION__, __LINE__)
+
+#define ret_if(expr) do { \
+       if (expr) { \
+               _LOGE("(%s) ", #expr); \
+               return; \
+       } \
+} while (0)
+
+#define retm_if(expr, fmt, arg...) do { \
+        if (expr) { \
+                _LOGE("(%s) "fmt, #expr, ##arg); \
+                return; \
+        } \
+ } while (0)
+
+#define retv_if(expr, val) do { \
+               if (expr) { \
+                       _LOGE("(%s) ", #expr); \
+                       return (val); \
+               } \
+       } while (0)
+
+#define retvm_if(expr, val, fmt, arg...) do { \
+       if (expr) { \
+               _LOGE("(%s) "fmt, #expr, ##arg); \
+               return (val); \
+       } \
+} while (0)
+
+#define tryvm_if(expr, val, fmt, arg...) do { \
+       if (expr) { \
+               _LOGE("(%s) "fmt, #expr, ##arg); \
+               val; \
+               goto catch; \
+       } \
+} while (0)
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __CORETPK_INSTALLER_TYPE_H_ */
diff --git a/backend/src/coretpk/xml-parser/coretpk-parser-hybrid.c b/backend/src/coretpk/xml-parser/coretpk-parser-hybrid.c
new file mode 100755 (executable)
index 0000000..ff01c69
--- /dev/null
@@ -0,0 +1,660 @@
+/*
+ * coretpk-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, junsuk.oh <junsuk77.oh@samsung.com>,
+ *
+ * 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 _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+#include <privilege-control.h>
+
+#include "coretpk-installer-internal.h"
+#include "rpm-installer-util.h"
+#include "rpm-installer.h"
+
+#define LOG_PRINT_LINE_MAX 20
+#define LOG_BUFFER_COUNT_MAX 4096
+
+static int __coretpk_parser_hybrid_to_file(const char *web_xml, const char *core_xml);
+static int __coretpk_parser_hybrid_merge_privilege(char* merged_buf, char* core_buf, int* filesize);
+static int __coretpk_parser_hybrid_merge_ui_application(char* merged_buf, char* core_buf, int* filesize);
+static int __coretpk_parser_hybrid_merge_service_application(char* merged_buf, char* core_buf, int* filesize);
+static int __coretpk_parser_hybrid_merge_tag(char* merged_buf, char* core_buf, int* filesize, const char* start_tag, const char* end_tag);
+
+static int __coretpk_parser_hybrid_get_part(const char* start_point, const char* start_tag, const char* end_tag, char** buf, int* length, char** next);
+static int __coretpk_parser_hybrid_merge_to(const char* merged_buf, int* filesize, const char* tag, const char* buf, int length);
+static int __coretpk_parser_hybrid_dump_log_data(char *data, int length);
+
+static int _coretpk_installer_hybrid_convert_manifest(char *manifest, const char* pkgid);
+
+int __coretpk_parser_hybrid_to_file(const char *web_xml, const char *core_xml)
+{
+       int ret = RPM_INSTALLER_ERR_WRONG_PARAM;
+       int res = 0;
+       FILE* web_xml_file = NULL;
+       FILE* core_xml_file = NULL;
+       struct stat web_fileinfo;
+       struct stat core_fileinfo;
+       int web_xml_filesize = 0;
+       int core_xml_filesize = 0;
+       int merged_size = 0;
+       char* merged_buf = NULL;
+       char* core_buf = NULL;
+       int read_bytes = 0;
+       char* manifest_tag = NULL;
+       int filesize = 0;
+       FILE* result_xml_file = NULL;
+       int result_write_bytes = 0;
+
+       res = stat(web_xml, &web_fileinfo);
+       tryvm_if(res < 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fstat() failed, web_xml=[%s]\n", web_xml);
+
+       res = stat(core_xml, &core_fileinfo);
+       tryvm_if(res < 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fstat() failed, core_xml=[%s]\n", core_xml);
+
+       web_xml_filesize = web_fileinfo.st_size;
+       core_xml_filesize = core_fileinfo.st_size;
+       merged_size = web_xml_filesize + core_xml_filesize;
+
+       web_xml_file = fopen(web_xml, "r");
+       tryvm_if(web_xml_file == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fopen() failed, web_xml=[%s]\n", web_xml);
+
+       merged_buf = (char*)calloc(1, merged_size + 1);
+       tryvm_if(merged_buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "merged_buf is NULL");
+
+       read_bytes = fread(merged_buf, 1, web_xml_filesize, web_xml_file);
+       tryvm_if(read_bytes <= 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fread() failed, web_xml=[%s]", web_xml);
+
+       core_xml_file = fopen(core_xml, "r");
+       tryvm_if(core_xml_file == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fopen() failed, core_xml=[%s]\n", core_xml);
+
+       core_buf = (char*)calloc(1, core_xml_filesize + 1);
+       tryvm_if(core_buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "core_buf is NULL");
+
+       read_bytes = fread(core_buf, 1, core_xml_filesize, core_xml_file);
+       tryvm_if(read_bytes <= 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fread() failed, core_xml=[%s]", core_xml);
+       core_buf[read_bytes] = '\0';
+
+       manifest_tag = strcasestr(merged_buf, "</manifest>");
+       tryvm_if(manifest_tag == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "manifest_tag is NULL");
+
+       filesize = web_xml_filesize;
+
+       __coretpk_parser_hybrid_merge_privilege(merged_buf, core_buf, &filesize);
+       __coretpk_parser_hybrid_merge_ui_application(merged_buf, core_buf, &filesize);
+       __coretpk_parser_hybrid_merge_service_application(merged_buf, core_buf, &filesize);
+
+       result_xml_file = fopen(web_xml, "w");
+       tryvm_if(result_xml_file == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fopen() failed, result_xml=[%s]", web_xml);
+
+       result_write_bytes = fwrite(merged_buf, 1, filesize, result_xml_file);
+       tryvm_if(result_write_bytes != filesize, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "fwrite() failed, result_write_bytes=[%d]", result_write_bytes);
+
+
+    ret = RPM_INSTALLER_SUCCESS;
+
+catch:
+
+       if(result_xml_file != NULL){
+               fclose(result_xml_file);
+               result_xml_file = NULL;
+       }
+       if(core_xml_file != NULL){
+               fclose(core_xml_file);
+               core_xml_file = NULL;
+       }
+       if(web_xml_file != NULL){
+               fclose(web_xml_file);
+               web_xml_file = NULL;
+       }
+       FREE_AND_NULL(merged_buf);
+       FREE_AND_NULL(core_buf);
+       return ret;
+}
+
+int __coretpk_parser_hybrid_merge_privilege(char* merged_buf, char* core_buf, int* filesize)
+{
+       int ret = RPM_INSTALLER_ERR_WRONG_PARAM;
+       char* merged_privilege_detected = NULL;
+       char* merged_point = NULL;
+       char* core_privilege_start = NULL;
+       char* core_privilege_end = NULL;
+       int privilege_len = 0;
+       int core_buf_len = 0;
+       char* selected_privilege_buf = NULL;
+
+       retvm_if(merged_buf == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "merged_buf is NULL");
+       retvm_if(core_buf == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "core_buf is NULL");
+       retvm_if(filesize <= 0, RPM_INSTALLER_ERR_WRONG_PARAM, "filesize is NULL");
+
+       if (strcasestr(core_buf, "</privileges>") == NULL) {
+               return RPM_INSTALLER_SUCCESS;
+    }
+
+       merged_privilege_detected = strcasestr(merged_buf, "</privileges>");
+       core_buf_len = strlen(core_buf);
+
+       selected_privilege_buf = (char*)calloc(1, core_buf_len + 1);
+       tryvm_if(selected_privilege_buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "selected_privilege_buf is NULL");
+
+       if (merged_privilege_detected == NULL) {
+               _LOGD("no privileges are detected in web xml");
+
+               core_privilege_start = strcasestr(core_buf, "<privileges>");
+               core_privilege_end = strcasestr(core_buf, "</privileges>");
+
+               privilege_len = core_privilege_end - core_privilege_start + strlen("</privileges>");
+               merged_point = strcasestr(merged_buf, "<ui-application");
+
+               _LOGD("inserted privileges of core xml");
+               __coretpk_parser_hybrid_dump_log_data(core_privilege_start, privilege_len);
+       } else {
+               char* privilege_buf = NULL;
+               char* each_privilege_start = NULL;
+               char* each_privilege_end = NULL;
+               int each_privilege_len = 0;
+               char each_privilege_buf[512] = {0};
+
+               _LOGD("privileges are detected in web xml");
+
+               core_privilege_start = strcasestr(core_buf, "<privilege>");
+               core_privilege_end = strcasestr(core_buf, "</privileges>");
+
+               privilege_len = core_privilege_end - core_privilege_start;
+               merged_point = strcasestr(merged_buf, "</privileges>");
+
+               _LOGD("original privilege of core xml");
+               __coretpk_parser_hybrid_dump_log_data(core_privilege_start, privilege_len);
+
+               privilege_buf = (char*)calloc(1, privilege_len + 1);
+               tryvm_if(privilege_buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "privilege_buf is NULL");
+               strncpy(privilege_buf, core_privilege_start, privilege_len);
+
+               each_privilege_start = privilege_buf;
+
+               while (each_privilege_start && (each_privilege_start < privilege_buf + privilege_len))
+               {
+                       each_privilege_end = strcasestr(each_privilege_start, "</privilege>");
+                       each_privilege_len = each_privilege_end - each_privilege_start + strlen("</privilege>");
+                       if ((each_privilege_end > 0) && each_privilege_len > 0)
+                       {
+                               memset(each_privilege_buf, 0, sizeof(each_privilege_buf));
+                               memcpy(each_privilege_buf, each_privilege_start, each_privilege_len);
+                               _LOGD("[%s]", each_privilege_buf);
+
+                       if (strcasestr(merged_buf, each_privilege_buf) == 0)
+                       {
+                               strncat(selected_privilege_buf, each_privilege_buf, core_buf_len);
+                       }
+                       else
+                       {
+                               _LOGD("this privilege is discarded, [%s]", each_privilege_buf);
+                       }
+                       }
+                       else
+                       {
+                               _LOGD("end of privileges merging");
+                               break;
+                       }
+
+                               each_privilege_start = strcasestr(each_privilege_end, "<privilege>");
+               }
+
+               core_privilege_start = selected_privilege_buf;
+               privilege_len = strlen(core_privilege_start);
+
+               _LOGD("filtered privileges of core xml");
+               __coretpk_parser_hybrid_dump_log_data(core_privilege_start, privilege_len);
+               FREE_AND_NULL(privilege_buf);
+       }
+
+       if ((merged_point > 0) && (core_privilege_start > 0) && (privilege_len > 0))
+       {
+               int last_part_len = 0;
+               char* last_part_buf = NULL;
+
+               last_part_len = *filesize - (merged_point - merged_buf);
+               last_part_buf = (char*)calloc(1, *filesize + 1);
+               tryvm_if(last_part_buf == NULL, ret = RPM_INSTALLER_ERR_INTERNAL,"@calloc failed!!");
+
+               if (last_part_len > 0)
+               {
+                       memcpy(last_part_buf, merged_point, last_part_len);
+
+                       _LOGD("last part of merged xml for backup");
+                       __coretpk_parser_hybrid_dump_log_data(last_part_buf, last_part_len);
+
+                       memcpy(merged_point, core_privilege_start, privilege_len);
+
+                       memcpy(merged_point + privilege_len, last_part_buf, last_part_len);
+                       *filesize += privilege_len;
+               }
+               FREE_AND_NULL(last_part_buf);
+
+       }
+       ret = RPM_INSTALLER_SUCCESS;
+
+catch:
+       FREE_AND_NULL(selected_privilege_buf);
+       return ret;
+}
+
+int __coretpk_parser_hybrid_merge_ui_application(char* merged_buf, char* core_buf, int* filesize)
+{
+    retvm_if(merged_buf == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "merged_buf is NULL");
+    retvm_if(core_buf == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "core_buf is NULL");
+    retvm_if(filesize <= 0, RPM_INSTALLER_ERR_WRONG_PARAM, "filesize is NULL");
+
+    if (strcasestr(core_buf, "</ui-application>") == NULL)
+    {
+        _LOGD("<ui-application> is NOT detected in core xml");
+        return RPM_INSTALLER_SUCCESS;
+    }
+
+    _LOGD("<ui-application> is detected in core xml");
+    __coretpk_parser_hybrid_merge_tag(merged_buf, core_buf, filesize, "<ui-application", "</ui-application>");
+
+    return RPM_INSTALLER_SUCCESS;
+}
+
+int __coretpk_parser_hybrid_merge_service_application(char* merged_buf, char* core_buf, int* filesize)
+{
+    retvm_if(merged_buf == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "merged_buf is NULL");
+    retvm_if(core_buf == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "core_buf is NULL");
+    retvm_if(filesize <= 0, RPM_INSTALLER_ERR_WRONG_PARAM, "filesize is NULL");
+
+    if (strcasestr(core_buf, "</service-application>") == NULL)
+    {
+        _LOGD("<service-application> is NOT detected in core xml");
+        return RPM_INSTALLER_SUCCESS;
+    }
+
+    _LOGD("<service-application> is detected in core xml");
+    __coretpk_parser_hybrid_merge_tag(merged_buf, core_buf, filesize, "<service-application", "</service-application>");
+
+    return RPM_INSTALLER_SUCCESS;
+}
+
+int __coretpk_parser_hybrid_merge_tag(char* merged_buf, char* core_buf, int* filesize, const char* start_tag, const char* end_tag)
+{
+    do
+    {
+        char* buf = NULL;
+        int length = 0;
+        char* next = NULL;
+
+        __coretpk_parser_hybrid_get_part(core_buf, start_tag, end_tag, &buf, &length, &next);
+        if (length > 0)
+        {
+               __coretpk_parser_hybrid_merge_to(merged_buf, filesize, "</manifest>", buf, length);
+        }
+
+        if (buf)
+                       free(buf);
+
+        core_buf = next;
+    }
+    while (core_buf > 0);
+
+    return RPM_INSTALLER_SUCCESS;
+}
+
+int __coretpk_parser_hybrid_get_part(const char* start_point, const char* start_tag, const char* end_tag, char** buf, int* length, char** next)
+{
+       int ret = RPM_INSTALLER_ERR_WRONG_PARAM;
+       const char* start_buf_point = NULL;
+       const char* end_buf_point = NULL;
+       int len = 0;
+
+       tryvm_if(start_point == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "start_point is NULL");
+       tryvm_if(start_tag == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "start_tag is NULL");
+       tryvm_if(end_tag == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "end_tag is NULL");
+       tryvm_if(buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "buf is NULL");
+       tryvm_if(length == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "length is NULL");
+       tryvm_if(next == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "next is NULL");
+
+       start_buf_point = strcasestr(start_point, start_tag);
+       tryvm_if(start_buf_point == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "start_buf_point is NULL");
+
+       end_buf_point = strcasestr(start_buf_point, end_tag);
+       tryvm_if(end_buf_point == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "end_buf_point is NULL");
+
+       len = end_buf_point - start_buf_point + strlen(end_tag);
+       tryvm_if(len <= 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "len is invalid");
+
+       *buf = (char*)calloc(1, len + 1);
+       tryvm_if(*buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "*buf is NULL");
+       memcpy(*buf, start_buf_point, len);
+
+       _LOGD("extracted part, len=[%d]", len);
+       __coretpk_parser_hybrid_dump_log_data(*buf, len);
+
+       *length = len;
+       next = (char**)end_buf_point;
+
+       ret = RPM_INSTALLER_SUCCESS;
+
+catch:
+    return ret;
+}
+
+int __coretpk_parser_hybrid_merge_to(const char* merged_buf, int* filesize, const char* tag, const char* buf, int length)
+{
+       int ret = RPM_INSTALLER_ERR_WRONG_PARAM;
+       char* merged_point = NULL;
+       char* last_part_buf = NULL;
+       int last_part_length = 0;
+
+    tryvm_if(merged_buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "merged_buf is NULL");
+    tryvm_if(*filesize <= 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "filesize is invalid");
+    tryvm_if(tag == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "tag is NULL");
+    tryvm_if(buf == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "buf is NULL");
+    tryvm_if(length <= 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "length is invalid");
+
+    merged_point = (char*)strcasestr(merged_buf, tag);
+    tryvm_if(merged_point == NULL, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "tag is not found, tag=[%s]", tag);
+
+    last_part_length = *filesize - (merged_point - merged_buf);
+    last_part_buf = (char*)calloc(1, *filesize + 1);
+       tryvm_if(last_part_buf == NULL, ret = RPM_INSTALLER_ERR_INTERNAL, "@calloc failed!!");
+
+       if (last_part_length > 0)
+       {
+               memcpy(last_part_buf, merged_point, last_part_length);
+
+               _LOGD("last part of merged xml for backup");
+               __coretpk_parser_hybrid_dump_log_data(last_part_buf, last_part_length);
+
+               memcpy(merged_point, buf, length);
+               memcpy(merged_point + length, last_part_buf, last_part_length);
+               *filesize += length;
+       }
+
+    ret = RPM_INSTALLER_SUCCESS;
+
+catch:
+       FREE_AND_NULL(last_part_buf);
+       return ret;
+}
+
+char __coretpk_parser_hybrid_log_change_hex_to_str(int hex)
+{
+       char ch = '0';
+
+       const static char       hexValues[]     = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 0};
+
+
+       if (hex >= 0 && hex <= 0x0F)
+       {
+               ch      = hexValues[hex];
+       }
+       else
+       {
+               _LOGD("LogChangeHexToStr: Error! [Hex Val: %d]\n", hex);
+       }
+
+       return ch;
+}
+
+int __coretpk_parser_hybrid_dump_log_data(char *pData, int dataLen)
+{
+       if(pData == NULL){
+               _LOGE("@No data to dump");
+               return 0;
+       }
+       const char      *szData = (const char*)pData;
+       char            ch = 0;
+       int                     i = 0, j = 0, idx = 0, idx2 = 0, high = 0, low = 0, temp = 0;
+
+       char            buf[LOG_PRINT_LINE_MAX + 2]                     = {0};
+       char            buf2[(LOG_PRINT_LINE_MAX + 2) * 3]      = {0};
+       char            buf_out[sizeof(buf) + sizeof(buf2) + 1] = {0};
+
+
+       if (dataLen > LOG_BUFFER_COUNT_MAX)
+       {
+               dataLen = LOG_BUFFER_COUNT_MAX;
+       }
+
+       _LOGD("------------------------------------------");
+
+       while (i < (int)dataLen)
+       {
+               ch      = szData[i];
+
+               /* make ascii table */
+               if (ch >= 32 && ch <= 128)
+               {
+                       buf[idx++]      = ch;
+               }
+               else
+                       buf[idx++]      = '.';
+
+               // make binary table
+               high = (ch & 0xf0)>>4;
+               low = ch & 0x0f;
+
+               buf2[idx2++]    = __coretpk_parser_hybrid_log_change_hex_to_str(high);
+               buf2[idx2++]    = __coretpk_parser_hybrid_log_change_hex_to_str(low);
+               buf2[idx2++]    = ' ';
+
+               if (idx >= LOG_PRINT_LINE_MAX)
+               {
+                       memcpy(buf_out, buf2, idx2);
+
+                       buf_out[idx2++] = ' ';
+                       buf_out[idx2++] = ' ';
+
+                       memcpy(buf_out + idx2, buf, idx);
+                       buf_out[idx2+idx]       = '\0';
+
+                       idx             = 0;
+                       idx2    = 0;
+
+                       _LOGD("%s\n", buf_out);
+               }
+
+               i++;
+       }
+
+       // last line
+       if (idx > 0)
+       {
+               memcpy(buf_out, buf2, idx2);
+               temp    = idx2;
+
+               for (j = 0; j < (LOG_PRINT_LINE_MAX * 3) - temp; j++)
+               {
+                       buf_out[idx2++] = ' ';
+               }
+
+               buf_out[idx2++] = ' ';
+               buf_out[idx2++] = ' ';
+
+               memcpy(buf_out+idx2, buf, idx);
+               buf_out[idx2+idx]       = '\0';
+
+               _LOGD("%s\n", buf_out);
+       }
+
+       _LOGD("------------------------------------------");
+
+       return 0;
+}
+
+#if 0
+static void __coretpk_parser_hybrid_clean_db(const char *pkgid)
+{
+    retm_if(pkgid == NULL, "pkgid is NULL");
+
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if ((ret < 0) || (handle == NULL)) {
+               _LOGD("pkgid[%s] dont have package info", pkgid);
+       } else {
+               _LOGD("pkgid[%s] have package info, need clean db for hybrid", pkgid);
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+               //request pkginfo unregister
+               ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+               if (ret < 0)
+                       _LOGE("[%s]fail delete pkg info", pkgid);
+       }
+}
+#endif
+
+int _coretpk_installer_hybrid_convert_manifest(char *manifest, const char* pkgid)
+{
+       int ret = 0;
+       char outputxml[BUF_SIZE] = {'\0'};
+
+       ret = mkdir(TEMP_XML_DIR, DIRECTORY_PERMISSION_755);
+       if (ret != 0) {
+               _LOGL("mkdir()", errno);
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       // run script
+       snprintf(outputxml, BUF_SIZE, "%s/%s", TEMP_XML_DIR, CORETPK_XML);
+       _LOGD("input xml = [%s], out xml = [%s]", manifest, outputxml);
+
+       const char *unzip_argv_rw[] = { CORETPK_RW_XML_CONVERTER, manifest, outputxml, pkgid, NULL, NULL };
+       const char *unzip_argv_ro[] = { CORETPK_RO_XML_CONVERTER, manifest, outputxml, pkgid, NULL, NULL };
+
+       if (strstr(manifest, OPT_USR_APPS)) {
+               ret = _ri_xsystem(unzip_argv_rw);
+       } else {
+               ret = _ri_xsystem(unzip_argv_ro);
+       }
+
+       if (ret != 0) {
+               _LOGL("converting the manifest file", errno);
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       return ret;
+}
+
+int _coretpk_installer_request_hybrid(int hybridOperation, char *pPkgPath, int apiVisibility)
+{
+       retvm_if(pPkgPath == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "pPkgPath is NULL.");
+
+       int ret = 0;
+       char wgt_xml[BUF_SIZE] = {'\0'};
+       char core_xml[BUF_SIZE] = {'\0'};
+       char converted_core_xml[BUF_SIZE] = {'\0'};
+       char native_id[BUF_SIZE] = {0,};
+       manifest_x *mfx = NULL;
+
+       _LOGD("request_hybrid(%s) start.", pPkgPath);
+
+       snprintf(core_xml, BUF_SIZE, "%s/%s", pPkgPath, CORETPK_XML);
+       retvm_if(access(core_xml, F_OK) != 0, RPM_INSTALLER_ERR_WRONG_PARAM, "cannot access core xml. [%s]", core_xml);
+
+       _LOGD("core xml = [%s]", core_xml);
+
+       // get pkgid and version from xml file
+       mfx = pkgmgr_parser_process_manifest_xml(core_xml);
+       retvm_if(mfx == NULL, RPM_INSTALLER_ERR_WRONG_PARAM, "pkgmgr_parser_process_manifest_xml(%s) failed.", core_xml);
+
+       _LOGD("pkgid = [%s], version = [%s]", mfx->package, mfx->version);
+
+#if 0
+       // clean pkgmgr db
+       __coretpk_parser_hybrid_clean_db(mfx->package);
+       _LOGD("hybrid_clean_db(%s) called.", mfx->package);
+#endif
+
+       if (strstr(pPkgPath, OPT_USR_APPS)) {
+               snprintf(wgt_xml, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, mfx->package);
+       } else {
+               snprintf(wgt_xml, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, mfx->package);
+       }
+
+       _LOGD("wgt xml = [%s]", wgt_xml);
+
+       // convert core xml
+       ret = _coretpk_installer_hybrid_convert_manifest(core_xml, mfx->package);
+       if (ret != 0) {
+               _LOGD("_coretpk_installer_hybrid_convert_manifest(%s, %s) failed.", core_xml, mfx->package);
+               pkgmgr_parser_free_manifest_xml(mfx);
+               return -1;
+       }
+
+       snprintf(converted_core_xml, BUF_SIZE, "%s/%s", TEMP_XML_DIR, CORETPK_XML);
+       _LOGD("hybrid_convert_manifest(%s) is done.", converted_core_xml);
+
+       // merge xml start
+       ret = __coretpk_parser_hybrid_to_file(wgt_xml, converted_core_xml);
+       //tryvm_if(ret != 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "__coretpk_parser_hybrid_to_file(%s, %s) failed.", wgt_xml, converted_core_xml);
+       _LOGD("hybrid_to_file(%s, %s) success", wgt_xml, converted_core_xml);
+
+       // make directory
+       ret = _coretpk_installer_make_directory((char*)mfx->package);
+       //tryvm_if(ret != 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "_coretpk_installer_make_directory(%s) failed.", mfx->package);
+       _LOGD("make_directory(%s) success", mfx->package);
+
+       // apply smack to app dir
+       ret = _coretpk_installer_apply_smack((char*)mfx->package, 1);
+       //tryvm_if(ret != 0, ret = RPM_INSTALLER_ERR_WRONG_PARAM, "@Failed to apply_smack");
+       _LOGD("apply_smack(%s, %d) success", mfx->package, ret);
+
+       // apply smack by privilege
+       strcat(native_id, (char*)mfx->package);
+       strcat(native_id, ".native");
+
+       ret = _ri_privilege_register_package(native_id);
+       if (ret != 0) {
+               _LOGE("_ri_privilege_register_package(%s) failed. ret = [%d].", native_id, ret);
+       } else {
+               _LOGD("_ri_privilege_register_package(%s) success.", native_id);
+       }
+
+       ret = _coretpk_installer_apply_privilege(native_id, pPkgPath, apiVisibility);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_privilege(%s) failed. ret = [%d].", native_id, ret);
+       } else {
+               _LOGD("_coretpk_installer_apply_privilege(%s) success.", native_id);
+       }
+
+       ret = perm_app_add_friend((char*)mfx->package, native_id);
+       if (ret != 0) {
+               _LOGE("perm_app_add_friend(%s, %s, %d) failed", mfx->package, native_id, ret);
+       } else {
+               _LOGD("perm_app_add_friend(%s) success.", native_id);
+       }
+
+       pkgmgr_parser_free_manifest_xml(mfx);
+
+       const char *delete_argv[] = {"/bin/rm", "-rf", TEMP_XML_DIR, NULL};
+       ret = _ri_xsystem(delete_argv);
+       if(ret != 0){
+               _LOGE("delete the directory failed. [%s]",TEMP_XML_DIR);
+               //return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       _LOGD("request_hybrid(%s) end.", pPkgPath);
+       return 0;
+}
diff --git a/backend/src/coretpk/xml-parser/dummy b/backend/src/coretpk/xml-parser/dummy
new file mode 100644 (file)
index 0000000..e69de29
old mode 100755 (executable)
new mode 100644 (file)
similarity index 52%
rename from frontend/ui/include/rpm-homeview.h
rename to backend/src/rpm/inc/rpm-installer-privilege.h
index 49c1599..c22e1da
  *
  */
 
-#ifndef HOME_VIEW_H_
-#define HOME_VIEW_H_
+#ifndef __RPM_INSTALLER_PRIVILEGE_H_
+#define __RPM_INSTALLER_PRIVILEGE_H_
 
-void _ri_information_popup(Evas_Smart_Cb func, const char *output,
-                          void *user_param);
-void _ri_package_downgrade_popup(Evas_Smart_Cb func1, Evas_Smart_Cb func2, const char *output,
-                                void *user_param);
-Eina_Bool _ri_init_appdata(struct appdata *ad);
-Eina_Bool _ri_init_home_view(struct appdata *ad);
-void _ri_destroy_home_view(struct appdata *ad);
-int _ri_frontend_launch_main_view(struct appdata *data);
-void _ri_frontend_update_progress_info(struct appdata *data,
-                                      char *progressinfo);
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
 
-#endif                         /* HOME_VIEW_H_ */
+int _ri_privilege_register_package(const char *pkgid);
+int _ri_privilege_unregister_package(const char *pkgid);
+int _ri_privilege_revoke_permissions(const char *pkgid);
+int _ri_privilege_enable_permissions(const char *pkgid, int apptype, const char **perms, int persistent);
+int _ri_privilege_setup_path(const char *pkgid, const char *dirpath, int apppathtype, const char *groupid);
+int _ri_privilege_add_friend(const char *pkgid1, const char *pkgid2);
+int _ri_privilege_change_smack_label(const char *path, const char *label,      int label_type);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __RPM_INSTALLER_PRIVILEGE_H_ */
diff --git a/backend/src/rpm/inc/rpm-installer-signature.h b/backend/src/rpm/inc/rpm-installer-signature.h
new file mode 100755 (executable)
index 0000000..ee66a06
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 __RPM_INSTALLER_SIGNATURE_H_
+#define __RPM_INSTALLER_SIGNATURE_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+typedef struct transform_x {
+       const char *algorithm;
+       struct transform_x *prev;
+       struct transform_x *next;
+} transform_x;
+
+typedef struct digestmethod_x {
+       const char *algorithm;
+       struct digestmethod_x *prev;
+       struct digestmethod_x *next;
+} digestmethod_x;
+
+typedef struct digestvalue_x {
+       const char *text;
+       struct digestvalue_x *prev;
+       struct digestvalue_x *next;
+} digestvalue_x;
+
+typedef struct transforms_x {
+       struct transform_x *transform;
+       struct transforms_x *prev;
+       struct transforms_x *next;
+} transforms_x;
+
+typedef struct x509certificate_x {
+       const char *text;
+       struct x509certificate_x *prev;
+       struct x509certificate_x *next;
+} x509certificate_x;
+
+typedef struct reference_x {
+       const char *uri;
+       struct transforms_x *transforms;
+       struct digestmethod_x *digestmethod;
+       struct digestvalue_x *digestvalue;
+       struct reference_x *prev;
+       struct reference_x *next;
+} reference_x;
+
+typedef struct cannonicalizationmethod_x {
+       const char *algorithm;
+       struct cannonicalizationmethod_x *prev;
+       struct cannonicalizationmethod_x *next;
+} cannonicalizationmethod_x;
+
+typedef struct signaturemethod_x {
+       const char *algorithm;
+       struct signaturemethod_x *prev;
+       struct signaturemethod_x *next;
+} signaturemethod_x;
+
+typedef struct x509data_x {
+       x509certificate_x *x509certificate;
+       struct x509data_x *prev;
+       struct x509data_x *next;
+} x509data_x;
+
+typedef struct signedinfo_x {
+       struct cannonicalizationmethod_x *cannonicalizationmethod;
+       struct signaturemethod_x *signaturemethod;
+       struct reference_x *reference;
+       struct signedinfo_x *prev;
+       struct signedinfo_x *next;
+} signedinfo_x;
+
+typedef struct signaturevalue_x {
+       const char *text;
+       struct signaturevalue_x *prev;
+       struct signaturevalue_x *next;
+} signaturevalue_x;
+
+typedef struct keyinfo_x {
+       struct x509data_x *x509data;
+       struct keyinfo_x *prev;
+       struct keyinfo_x *next;
+} keyinfo_x;
+
+/*This will be parsed later when requirement arises*/
+typedef struct object_x {
+       const char *id;
+       struct object_x *prev;
+       struct object_x *next;
+} object_x;
+
+typedef struct signature_x {   /*signature xml*/
+       const char *id;         /* distributor or author sign*/
+       const char *xmlns;      /* namespace*/
+       struct signedinfo_x *signedinfo;        /*signature data*/
+       struct signaturevalue_x *signaturevalue;        /* signature value*/
+       struct keyinfo_x *keyinfo;      /*cert info*/
+       struct object_x *object;        /*other parameters in object tag*/
+} signature_x;
+
+
+signature_x *_ri_process_signature_xml(const char *signature_file);
+void _ri_free_signature_xml(signature_x *sigx);
+
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __RPM_INSTALLER_SIGNATURE_H_ */
diff --git a/backend/src/rpm/inc/rpm-installer-type.h b/backend/src/rpm/inc/rpm-installer-type.h
new file mode 100644 (file)
index 0000000..1bcd657
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ *
+ * 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 __RPM_INSTALLER_TYPE_H_
+#define __RPM_INSTALLER_TYPE_H_
+
+/* For multi-user support */
+#include <tzplatform_config.h>
+#include <pkgmgr-info.h>
+#include <unistd.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif                         /* __cplusplus */
+
+#define MAX_BUF_SIZE                                           4096
+#define BUF_SIZE                                                               1024
+#define TEMP_DIR                                                               tzplatform_mkpath(TZ_USER_HOME, ".rpminstaller")
+#define CPIO_SCRIPT                                                    "/usr/bin/cpio_rpm_package.sh"
+#define CPIO_SCRIPT_UPDATE_XML                         "/usr/bin/cpio_rpm_package_update_xml.sh"
+#define RPM_UPDATE_XML                                                 "/usr/bin/rpm_update_xml.sh"
+#define MANIFEST_RW_DIRECTORY                          tzplatform_getenv(TZ_SYS_RW_PACKAGES)
+#define MANIFEST_RO_DIRECTORY                          tzplatform_getenv(TZ_SYS_RO_PACKAGES)
+#define USR_APPS                                                               tzplatform_getenv(TZ_SYS_RO_APP)
+#define OPT_USR_APPS                                                   tzplatform_getenv(TZ_USER_APP)
+#define OPT_SHARE_PACKAGES                                     getUserManifestPath(getuid())
+#define USR_SHARE_PACKAGES                                     tzplatform_getenv(TZ_SYS_RO_PACKAGES)
+#define PRE_CHECK_FOR_MANIFEST
+#define INSTALL_SCRIPT                                         "/usr/bin/install_rpm_package.sh"
+#define INSTALL_SCRIPT_WITH_DBPATH_RO          "/usr/bin/install_rpm_package_with_dbpath_ro.sh"
+#define INSTALL_SCRIPT_WITH_DBPATH_RW          "/usr/bin/install_rpm_package_with_dbpath_rw.sh"
+#define UNINSTALL_SCRIPT                                       "/usr/bin/uninstall_rpm_package.sh"
+#define UPGRADE_SCRIPT                                         "/usr/bin/upgrade_rpm_package.sh"
+#define UPGRADE_SCRIPT_WITH_DBPATH_RO          "/usr/bin/upgrade_rpm_package_with_dbpath_ro.sh"
+#define UPGRADE_SCRIPT_WITH_DBPATH_RW          "/usr/bin/upgrade_rpm_package_with_dbpath_rw.sh"
+#define TEMP_DBPATH                                                    "/opt/usr/rpmdb_tmp"
+#define RPM2CPIO                                                               "/usr/bin/rpm2cpio"
+#define DEACTIVATION_PKGID_LIST                        "/opt/share/packages/.pkgmgr/rpm-installer/rpm_installer_deactvation_list.txt"
+#define OPT_ZIP_FILE                                                   "/usr/system/RestoreDir/opt.zip"
+#define EFLWGT_TYPE_STR                                                "eflwgt"
+#define TOKEN_PACKAGE_STR                                      "package="
+#define TOKEN_PKGID_STR                                                "pkgid="
+#define TOKEN_STATE_STR                                                "state="
+#define TOKEN_PATH_STR                                         "path="
+#define TOKEN_OPERATION_STR                                    "op="
+#define TOKEN_REMOVE_STR                                       "removable="
+#define SEPERATOR_END                                          ':'
+#define SEPERATOR_START                                                '"'
+#define APP_OWNER_ID                                                   5000
+#define APP_GROUP_ID                                                   5000
+#define MAX_BUFF_LEN                                                   4096
+#define MAX_CERT_NUM                                                   9
+#define TERMINATE_RETRY_COUNT                          100
+#define BIN_DIR_STR                                                    "bin"
+#define RES_DIR_STR                                                    "res"
+#define SHARED_RES_DIR_STR                                     "shared/res"
+#define LIBAIL_PATH                                                    "/usr/lib/libail.so.0"
+#define QUERY_PACKAGE                                          "/usr/bin/query_rpm_package.sh"
+#define RPM_PKG_INFO                                                   "/var/rpmpkg.info"
+#define RPM                                                                    "/usr/etc/package-manager/backend/rpm"
+#define SMACK_RULES_ALT_PATH                                   "/etc/smack/accesses2.d/"
+#define CORETPK_XML                                                    "tizen-manifest.xml"
+#ifdef __cplusplus
+}
+#endif                         /* __cplusplus */
+#endif                         /* __RPM_INSTALLER_TYPE_H_ */
diff --git a/backend/src/rpm/rpm-installer-core.c b/backend/src/rpm/rpm-installer-core.c
new file mode 100755 (executable)
index 0000000..a33d3ea
--- /dev/null
@@ -0,0 +1,659 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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.
+ *
+ */
+
+/* System Include files */
+#include <stdbool.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <wait.h>
+#include <regex.h>
+#include <pthread.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <errno.h>
+
+/* SLP include files */
+#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
+#include "rpm-installer.h"
+#include "rpm-installer-type.h"
+#include "rpm-installer-util.h"
+#include "db-util.h"
+#include "rpm-frontend.h"
+
+
+extern char *gpkgname;
+extern int do_upgrade;
+
+char* _rpm_load_directory(char *directory,char* pkgfile)
+{
+       DIR *dir;
+       struct dirent entry, *result;
+       int ret;
+       char *buf = NULL;
+       char *pkgname = NULL;
+//     char *rpm_pkgname = NULL;
+       char xml_file[PATH_MAX] = {0};
+
+       buf = malloc(BUF_SIZE);
+       if (buf == NULL) {
+               _LOGE("malloc failed.\n");
+               return NULL;
+       }
+
+       dir = opendir(directory);
+       if (!dir) {
+               if (strerror_r(errno, buf, BUF_SIZE) == 0)
+               _LOGE("Can not access to the [%s] because %s.\n", directory, buf);
+               free(buf);
+               return NULL;
+       }
+
+       _LOGD("Loading manifest files from %s\n", directory);
+
+       for (ret = readdir_r(dir, &entry, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dir, &entry, &result)) {
+               char *manifest = NULL;
+
+               if (!strcmp(entry.d_name, ".") ||
+                       !strcmp(entry.d_name, "..")) {
+                       continue;
+               }
+
+               manifest = _manifest_to_package(entry.d_name);
+               if (!manifest) {
+                       _LOGE("Failed to convert file to xml[%s].\n", entry.d_name);
+                       continue;
+               }
+
+               memset(xml_file, '\0', PATH_MAX);
+               snprintf(xml_file,PATH_MAX-1,"%s/%s",directory,manifest);
+               _LOGD("manifest is [%s] and its full path is [%s]",manifest,xml_file);
+               ret = _get_package_name_from_xml(xml_file,&pkgname);
+               if(ret != PMINFO_R_OK || pkgname == NULL){
+                       _LOGE("Unable To read [%s] manifest file",xml_file);
+                       free(manifest);
+                       continue;
+               }
+
+               else
+               {
+                       snprintf(buf, BUF_SIZE, "%s/%s", directory, manifest);
+                       _LOGD("Manifest file is %s\n",manifest);
+                       free(manifest);
+                       break;
+               }
+
+#if 0  //dont check pkgname from rpm-name, there is a bug
+               ret = _get_pkgname_from_rpm_name(pkgfile, &rpm_pkgname);
+               if(ret != RPM_INSTALLER_SUCCESS || rpm_pkgname == NULL){
+                       _LOGE("Couldn't get the pkgname from rpm file [%s]",pkgfile);
+                       if(pkgname){
+                               free(pkgname);
+                               pkgname = NULL;
+                       }
+                       if(buf){
+                               free(buf);
+                               buf = NULL;
+                       }
+                       closedir(dir);
+                       free(manifest);
+                       return NULL;
+               }
+               _LOGD("Pkgname from xml is [%s] and pkgname from rpm's name is [%s]",pkgname,rpm_pkgname);
+
+               /*
+               Compare the package name which is extracted from manifest file with package name which is extracted from rpm file's name.
+               If match is successful then it is required manifest file.
+               */
+
+               if(!strcmp(pkgname,rpm_pkgname)){
+                       snprintf(buf, BUF_SIZE, "%s/%s", directory, manifest);
+                       _LOGD("Manifest file is %s\n",buf);
+                       free(manifest);
+                       break;
+               }else{
+                       free(manifest);
+                       if(pkgname){
+                               free(pkgname);
+                               pkgname = NULL;
+                       }
+                       if(rpm_pkgname){
+                               free(rpm_pkgname);
+                               rpm_pkgname = NULL;
+                       }
+               }
+#endif
+       }
+
+       closedir(dir);
+
+       if(pkgname){
+               free(pkgname);
+               pkgname = NULL;
+       }
+#if 0
+       if(rpm_pkgname){
+               free(rpm_pkgname);
+               rpm_pkgname = NULL;
+       }
+#endif
+
+       return buf;
+}
+
+pkginfo *_rpm_installer_get_pkgfile_info(char *pkgfile)
+{
+       pkginfo *info = NULL;
+       manifest_x *mfx = NULL;
+       int ret = 0;
+       int m_exist = 0;
+       char cwd[BUF_SIZE] = {'\0'};
+       char buff[BUF_SIZE] = {'\0'};
+       char manifest[BUF_SIZE] = { '\0'};
+       char *temp = NULL;
+
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) || (cwd[0] == '\0')) {
+               _LOGE("getcwd() failed.\n");
+               return NULL;
+       }
+
+       ret = mkdir(TEMP_DIR, 0644);
+       if (ret < 0) {
+               if (access(TEMP_DIR, F_OK) == 0) {
+                       _rpm_delete_dir(TEMP_DIR);
+                       ret = mkdir(TEMP_DIR, 0644);
+                       if (ret < 0) {
+                               _LOGE("mkdir() failed.\n");
+                               return NULL;
+                       }
+               } else {
+                       _LOGE("mkdir() failed.\n");
+                       return NULL;
+               }
+       }
+
+       ret = chdir(TEMP_DIR);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed [%s].\n", TEMP_DIR, strerror(errno));
+               goto err;
+       }
+
+       _LOGD("switched to %s\n", TEMP_DIR);
+
+       const char *cpio_argv[] = { CPIO_SCRIPT, pkgfile, NULL };
+       ret = _ri_xsystem(cpio_argv);
+
+       snprintf(manifest, BUF_SIZE, "%s/opt/share/packages", TEMP_DIR);
+       char* manifestpath = _rpm_load_directory(manifest,pkgfile);
+       if (manifestpath != NULL) {
+               strncpy(buff, manifestpath, sizeof(buff) - 1);
+               free(manifestpath);
+       }
+
+       if (buff[0] == '\0') {
+               snprintf(manifest, BUF_SIZE, "%s/usr/share/packages", TEMP_DIR);
+               manifestpath = _rpm_load_directory(manifest,pkgfile);
+               if (manifestpath != NULL) {
+                       strncpy(buff, manifestpath, sizeof(buff) - 1);
+                       free(manifestpath);
+               }
+
+               if (buff[0] == '\0') {
+                       goto err;
+               } else {
+                       m_exist = 1;
+               }
+       } else {
+               m_exist = 1;
+       }
+
+       _LOGD("Manifest file is [%s]",buff);
+
+       if (m_exist) {
+
+               _LOGD("The path of manifest.xml is %s.\n", buff);
+
+               /*get package name from xml*/
+               mfx = pkgmgr_parser_process_manifest_xml(buff);
+               if (mfx != NULL) {
+
+                       info = calloc(1, sizeof(pkginfo));
+                       if (info == NULL) {
+                               _LOGE("calloc failed.\n");
+                               goto err;
+                       }
+
+                       strncpy(info->package_name, mfx->package, sizeof(info->package_name) - 1);
+                       strncpy(info->version, mfx->version, sizeof(info->version) - 1);
+                       _LOGD("_rpm_installer_get_pkgfile_info, pkgname: (%s), version(%s)\n", info->package_name, info->version);
+               }
+       }
+
+err:
+       _rpm_delete_dir(TEMP_DIR);
+
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed [%s].\n", cwd, strerror(errno));
+       }
+
+       if (mfx != NULL) {
+               pkgmgr_parser_free_manifest_xml(mfx);
+       }
+
+       return info;
+}
+
+pkginfo *_rpm_installer_get_pkgname_info(const char *pkgid)
+{
+       pkginfo *info = NULL;
+       int ret = 0;
+       char *packageid = NULL;
+       char *version = NULL;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL.\n");
+               return NULL;
+       }
+
+       info = malloc(sizeof(pkginfo));
+       if (info == NULL) {
+               _LOGE("malloc failed.\n");
+               return NULL;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret != PMINFO_R_OK || handle == NULL) {
+               _LOGE("fisrt installation, pkgid=[%s]", pkgid);
+               free(info);
+               return NULL;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &packageid);
+       if (ret != PMINFO_R_OK) {
+               _LOGE("failed to get the pkgid.\n");
+               goto err;
+       }
+       strncpy(info->package_name, packageid, sizeof(info->package_name) - 1);
+
+       ret = pkgmgrinfo_pkginfo_get_version(handle, &version);
+       if (ret != PMINFO_R_OK) {
+               _LOGE("failed to get the version.\n");
+               goto err;
+       }
+       strncpy(info->version, version, sizeof(info->version) - 1);
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       _LOGD("pkgid=[%s], version=[%s]", info->package_name, info->version);
+
+       return info;
+
+err:
+       if(info){
+               free(info);
+               info = NULL;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       return NULL;
+}
+
+int _rpm_installer_corexml_install(char *pkgfilepath)
+{
+       /* Get package ID from filepath <pkgid.xml>*/
+       char *p = NULL;
+       char *q = NULL;
+       char *temp = NULL;
+       int ret = 0;
+       int idx = 0;
+       temp = strdup(pkgfilepath);
+       if (temp == NULL)
+               return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+       p = strrchr(temp, '/');
+       if (p) {
+               p++;
+       } else {
+               free(temp);
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+       /*p now points to pkgid.xml*/
+       q = strrchr(p, '.');
+       if (q == NULL) {
+               _LOGE("Failed to extract pkgid from xml name\n");
+               free(temp);
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+       idx = strlen(p) - strlen(q);
+       p[idx] = '\0';
+       _LOGD("package id is [%s]", p);
+       ret = _rpm_install_corexml(pkgfilepath, p);
+       free(temp);
+       return ret;
+}
+
+int _rpm_installer_package_install(char *pkgfilepath, bool forceinstall,
+                                  char *installoptions, char *clientid)
+{
+       int err = 0;
+       char *p = NULL;
+       if (forceinstall == true && installoptions == NULL)
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+
+       /* Check for core xml installation */
+       p = strrchr(pkgfilepath, '.');
+       if (p) {
+               if (strncmp(p+1, "xml", 3) == 0) {
+                       err = _rpm_installer_corexml_install(pkgfilepath);
+                       if (err) {
+                               _LOGE("_rpm_installer_corexml_install() failed\n");
+                       } else {
+                               _LOGE("_rpm_installer_corexml_install() success\n");
+                       }
+                       return err;
+               }
+       } else {
+               _LOGE("pkgfilepath does not have an extension\n");
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+       /* rpm installation */
+       pkginfo *info = NULL;
+       pkginfo *tmpinfo = NULL;
+       /*Check to see if the package is already installed or not
+          If it is installed, compare the versions. If the current version
+          is higher than the installed version, upgrade it automatically
+          else ask for user confirmation before downgrading */
+
+       info = _rpm_installer_get_pkgfile_info(pkgfilepath);
+       if (info == NULL) {
+               /* failed to get pkg info */
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+       _ri_save_last_input_info(pkgfilepath,INSTALL_CMD,0);
+       if (gpkgname) {
+               free(gpkgname);
+               gpkgname = NULL;
+       }
+       gpkgname = strdup(info->package_name);
+       if(gpkgname == NULL){
+               _LOGE("Malloc failed!!");
+               if(info){
+                       free(info);
+                       info = NULL;
+               }
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       tmpinfo = _rpm_installer_get_pkgname_info(info->package_name);
+       if (tmpinfo == NULL) {
+               _LOGD("tmpinfo is null.\n");
+
+               /* package is not installed. Go for installation. */
+               if (info) {
+                       free(info);
+                       info = NULL;
+               }
+
+               err = _rpm_install_pkg_with_dbpath(pkgfilepath, gpkgname, clientid);
+               if (err != 0) {
+                       _LOGE(
+                              "install complete with error(%d)\n", err);
+                       return err;
+               } else {
+                       _ri_set_backend_state_info(REQUEST_COMPLETED);
+                       return RPM_INSTALLER_SUCCESS;
+               }
+       } else if (strcmp(info->version, tmpinfo->version) > 0) {
+               /*upgrade */
+
+               _LOGD("[upgrade] %s, %s\n", info->version, tmpinfo->version);
+
+               err = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, gpkgname);
+               if (err != 0) {
+                       _LOGE(
+                              "upgrade complete with error(%d)\n", err);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return err;
+               } else {
+                       _ri_set_backend_state_info(REQUEST_COMPLETED);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return RPM_INSTALLER_SUCCESS;
+               }
+       } else if (strcmp(info->version, tmpinfo->version) < 0) {
+
+               _LOGD("[down grade] %s, %s\n", info->version, tmpinfo->version);
+
+                       err = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, gpkgname);
+                       if (err != 0) {
+                               _LOGE(
+                                      "upgrade complete with error(%d)\n",
+                                      err);
+                               if (info) {
+                                       free(info);
+                                       info = NULL;
+                               }
+                               if (tmpinfo) {
+                                       free(tmpinfo);
+                                       tmpinfo = NULL;
+                               }
+                               return err;
+                       }else{
+                       _ri_set_backend_state_info(REQUEST_COMPLETED);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return RPM_INSTALLER_SUCCESS;
+
+               }
+
+       } else {
+               /*same package. Reinstall it. Manifest should be parsed again */
+
+               _LOGD("[same pkg] %s, %s\n", info->package_name, info->version);
+
+               err = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, gpkgname);
+               if (err != 0) {
+                       _LOGE(
+                              "upgrade complete with error(%d)\n", err);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return err;
+               } else {
+                       _ri_set_backend_state_info(REQUEST_COMPLETED);
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       if (tmpinfo) {
+                               free(tmpinfo);
+                               tmpinfo = NULL;
+                       }
+                       return RPM_INSTALLER_SUCCESS;
+               }
+       }
+
+       return RPM_INSTALLER_SUCCESS;
+
+}
+
+int _rpm_installer_package_install_with_dbpath(char *pkgfilepath, char *clientid)
+{
+       int ret = 0;
+       pkginfo *info = NULL;
+       pkginfo *tmpinfo = NULL;
+
+       /*Check to see if the package is already installed or not
+          If it is installed, compare the versions. If the current version
+          is higher than the installed version, upgrade it automatically
+          else ask for user confirmation before downgrading */
+
+       _LOGD("[##]start : _rpm_installer_package_install_with_dbpath\n");
+
+       info = _rpm_installer_get_pkgfile_info(pkgfilepath);
+       if (info == NULL) {
+               _LOGE("@Failed to get pkg info.\n");
+               /* failed to get pkg info */
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+       _ri_save_last_input_info(info->package_name,EFLWGT_INSTALL_CMD,0);
+       if (gpkgname) {
+               free(gpkgname);
+               gpkgname = NULL;
+       }
+       gpkgname = strdup(info->package_name);
+       if(gpkgname == NULL){
+               _LOGE("Malloc failed!!");
+               if(info){
+                       free(info);
+                       info = NULL;
+               }
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       tmpinfo = _rpm_installer_get_pkgname_info(info->package_name);
+       if (tmpinfo == NULL) {
+               /* package is not installed. Go for installation. */
+               _LOGD("#package is not installed. Go for installation\n");
+               ret = _rpm_install_pkg_with_dbpath(pkgfilepath, info->package_name, clientid);
+
+       } else if (strcmp(info->version, tmpinfo->version) > 0) {
+               /*upgrade */
+               _LOGD("#package is installed. Go for upgrade\n");
+               ret = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, info->package_name);
+       } else if (strcmp(info->version, tmpinfo->version) < 0) {
+               /*downgrade */
+               _LOGD("#package is installed. Go for upgrade\n");
+               ret = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, info->package_name);
+
+       } else {
+               /*same package. Reinstall it. Manifest should be parsed again */
+               _LOGD( "#package is same. Go for reinstall(upgrade)\n");
+               ret = _rpm_upgrade_pkg_with_dbpath(pkgfilepath, info->package_name);
+       }
+
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+       if (tmpinfo) {
+               free(tmpinfo);
+               tmpinfo = NULL;
+       }
+
+       if (ret != 0) {
+               _LOGE("[@@]end : _rpm_installer_package_install_with_dbpath(%d)\n", ret);
+       } else {
+               _LOGD( "[##]end : _rpm_installer_package_install_with_dbpath \n");
+       }
+
+       return ret;
+}
+
+int _rpm_installer_package_uninstall_with_dbpath(const char *pkgid)
+{
+       return _rpm_uninstall_pkg_with_dbpath(pkgid, 0);
+}
+
+int _rpm_installer_package_uninstall(char *pkgid)
+{
+       int ret = 0;
+
+       _LOGD( "start : _rpm_installer_package_uninstall\n");
+
+       pkginfo *tmppkginfo = _rpm_installer_get_pkgname_info(pkgid);
+       if (tmppkginfo == NULL) {
+               _LOGE("tmppkginfo is NULL.\n");
+               return RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+       }
+       if (tmppkginfo) {
+               free(tmppkginfo);
+               tmppkginfo = NULL;
+       }
+#ifndef SEND_PKGPATH
+       if (gpkgname) {
+               free(gpkgname);
+               gpkgname = NULL;
+       }
+
+       gpkgname = strdup(pkgid);
+//     _ri_broadcast_status_notification(pkgid, "command", "Uninstall");
+#endif
+       _ri_set_backend_state_info(GOT_PACKAGE_INFO_SUCCESSFULLY);
+       _ri_save_last_input_info(pkgid,DELETE_CMD,0);
+       ret = _rpm_uninstall_pkg(pkgid);
+
+       _ri_set_backend_state_info(REQUEST_COMPLETED);
+
+       _LOGD("end : _rpm_installer_package_uninstall(%d)\n", ret);
+
+       return ret;
+}
+
+int _rpm_installer_clear_private_data(char *pkgid)
+{
+       if (pkgid == NULL)
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+       char dir_path[BUF_SIZE] = { '\0' };
+       int ret = -1;
+       snprintf(dir_path, 255, "/opt/usr/apps/%s/data/", pkgid);
+       ret = _ri_recursive_delete_dir(dir_path);
+       return ret;
+}
diff --git a/backend/src/rpm/rpm-installer-privilege.c b/backend/src/rpm/rpm-installer-privilege.c
new file mode 100755 (executable)
index 0000000..a5a64f8
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#define __USE_GNU
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <privilege-control.h>
+#include "sys/smack.h"
+
+#include "rpm-installer.h"
+
+
+
+static int __ri_privilege_perm_begin(void)
+{
+       int ret = 0;
+
+       ret = perm_begin();
+       _LOGD("[smack] perm_begin, result=[%d]",ret);
+
+       return ret;
+}
+
+static int __ri_privilege_perm_end(void)
+{
+       int ret = 0;
+
+       ret = perm_end();
+       _LOGD("[smack] perm_end, result=[%d]",ret);
+
+       return ret;
+}
+
+int _ri_privilege_register_package(const char *pkgid)
+{
+       int ret = 0;
+
+       ret = perm_app_install(pkgid);
+       _LOGD("[smack] app_install(%s), result=[%d]", pkgid, ret);
+
+       return ret;
+}
+
+int _ri_privilege_unregister_package(const char *pkgid)
+{
+       int ret = 0;
+
+       ret = perm_app_uninstall(pkgid);
+       _LOGD("[smack] app_uninstall(%s), result=[%d]", pkgid, ret);
+
+       return ret;
+}
+
+int _ri_privilege_revoke_permissions(const char *pkgid)
+{
+       int ret = 0;
+
+       ret = perm_app_revoke_permissions(pkgid);
+       _LOGD("[smack] app_revoke_permissions(%s), result=[%d]", pkgid, ret);
+
+       return ret;
+}
+
+int _ri_privilege_enable_permissions(const char *pkgid, int apptype,
+                                               const char **perms, int persistent)
+{
+       int ret = 0;
+
+       __ri_privilege_perm_begin();
+
+       ret = perm_app_enable_permissions(pkgid, apptype, perms, persistent);
+       _LOGD("[smack] app_enable_permissions(%s, %d), result=[%d]", pkgid, apptype, ret);
+
+       __ri_privilege_perm_end();
+
+       return ret;
+}
+
+int _ri_privilege_setup_path(const char *pkgid, const char *dirpath, int apppathtype, const char *groupid)
+{
+       int ret = 0;
+
+       if (groupid == NULL) {
+               ret = perm_app_setup_path(pkgid, dirpath, apppathtype);
+               _LOGD("[smack] app_setup_path(%s, %s, %d), result=[%d]", pkgid, dirpath, apppathtype, ret);
+       } else {
+               ret = perm_app_setup_path(pkgid, dirpath, apppathtype, groupid);
+               _LOGD("[smack] app_setup_path(%s, %s, %d, %s), result=[%d]", pkgid, dirpath, apppathtype, groupid, ret);
+       }
+
+       return ret;
+}
+
+int _ri_privilege_add_friend(const char *pkgid1, const char *pkgid2)
+{
+       int ret = 0;
+
+       ret = perm_app_add_friend(pkgid1, pkgid2);
+       _LOGD("[smack] app_add_friend(%s, %s), result=[%d]", pkgid1, pkgid2, ret);
+
+       return ret;
+}
+
+int _ri_privilege_change_smack_label(const char *path, const char *label,
+                                               int label_type)
+{
+       if (path == NULL || label == NULL)
+               return -1;
+       int ret = 0;
+
+       ret = smack_lsetlabel(path, label, label_type);
+       _LOGD("[smack] smack_lsetlabel(%s, %s, %d), result=[%d]", path, label, label_type, ret);
+
+       return ret;
+}
diff --git a/backend/src/rpm/rpm-installer-signature.c b/backend/src/rpm/rpm-installer-signature.c
new file mode 100755 (executable)
index 0000000..4ef0331
--- /dev/null
@@ -0,0 +1,765 @@
+/*
+ * rpm-installer
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
+ * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
+ *
+ * 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 <pkgmgr_parser.h>
+#include "rpm-installer-util.h"
+#include "rpm-installer-signature.h"
+
+
+static int _ri_next_child_element(xmlTextReaderPtr reader, int depth)
+{
+       int ret = xmlTextReaderRead(reader);
+       int cur = xmlTextReaderDepth(reader);
+       while (ret == 1) {
+
+               switch (xmlTextReaderNodeType(reader)) {
+               case XML_READER_TYPE_ELEMENT:
+                       if (cur == depth + 1)
+                               return 1;
+                       break;
+               case XML_READER_TYPE_TEXT:
+                       if (cur == depth + 1)
+                               return 0;
+                       break;
+               case XML_READER_TYPE_END_ELEMENT:
+                       if (cur == depth)
+                               return 0;
+                       break;
+               default:
+                       if (cur <= depth)
+                               return 0;
+                       break;
+               }
+               ret = xmlTextReaderRead(reader);
+               cur = xmlTextReaderDepth(reader);
+       }
+       return ret;
+}
+
+static void _ri_free_transform(transform_x *transform)
+{
+       if (transform == NULL)
+               return;
+       if (transform->algorithm) {
+               free((void *)transform->algorithm);
+               transform->algorithm = NULL;
+       }
+       free((void*)transform);
+       transform = NULL;
+}
+
+static void _ri_free_cannonicalizationmethod(cannonicalizationmethod_x *cannonicalizationmethod)
+{
+       if (cannonicalizationmethod == NULL)
+               return;
+       if (cannonicalizationmethod->algorithm) {
+               free((void *)cannonicalizationmethod->algorithm);
+               cannonicalizationmethod->algorithm = NULL;
+       }
+       free((void*)cannonicalizationmethod);
+       cannonicalizationmethod = NULL;
+}
+
+static void _ri_free_signaturemethod(signaturemethod_x *signaturemethod)
+{
+       if (signaturemethod == NULL)
+               return;
+       if (signaturemethod->algorithm) {
+               free((void *)signaturemethod->algorithm);
+               signaturemethod->algorithm = NULL;
+       }
+       free((void*)signaturemethod);
+       signaturemethod = NULL;
+}
+
+static void _ri_free_digestmethod(digestmethod_x *digestmethod)
+{
+       if (digestmethod == NULL)
+               return;
+       if (digestmethod->algorithm) {
+               free((void *)digestmethod->algorithm);
+               digestmethod->algorithm = NULL;
+       }
+       free((void*)digestmethod);
+       digestmethod = NULL;
+}
+
+static void _ri_free_digestvalue(digestvalue_x *digestvalue)
+{
+       if (digestvalue == NULL)
+               return;
+       if (digestvalue->text) {
+               free((void *)digestvalue->text);
+               digestvalue->text = NULL;
+       }
+       free((void*)digestvalue);
+       digestvalue = NULL;
+}
+
+static void _ri_free_signaturevalue(signaturevalue_x *signaturevalue)
+{
+       if (signaturevalue == NULL)
+               return;
+       if (signaturevalue->text) {
+               free((void *)signaturevalue->text);
+               signaturevalue->text = NULL;
+       }
+       free((void*)signaturevalue);
+       signaturevalue = NULL;
+}
+
+static void _ri_free_x509certificate(x509certificate_x *x509certificate)
+{
+       if (x509certificate == NULL)
+               return;
+       if (x509certificate->text) {
+               free((void *)x509certificate->text);
+               x509certificate->text = NULL;
+       }
+       free((void*)x509certificate);
+       x509certificate = NULL;
+}
+
+static void _ri_free_x509data(x509data_x *x509data)
+{
+       if (x509data == NULL)
+               return;
+       if (x509data->x509certificate) {
+               x509certificate_x *x509certificate = x509data->x509certificate;
+               x509certificate_x *tmp = NULL;
+               while(x509certificate != NULL) {
+                       tmp = x509certificate->next;
+                       _ri_free_x509certificate(x509certificate);
+                       x509certificate = tmp;
+               }
+       }
+       free((void*)x509data);
+       x509data = NULL;
+}
+
+static void _ri_free_keyinfo(keyinfo_x *keyinfo)
+{
+       if (keyinfo == NULL)
+               return;
+       if (keyinfo->x509data) {
+               x509data_x *x509data = keyinfo->x509data;
+               x509data_x *tmp = NULL;
+               while(x509data != NULL) {
+                       tmp = x509data->next;
+                       _ri_free_x509data(x509data);
+                       x509data = tmp;
+               }
+       }
+       free((void*)keyinfo);
+       keyinfo = NULL;
+}
+
+static void _ri_free_transforms(transforms_x *transforms)
+{
+       if (transforms == NULL)
+               return;
+       if (transforms->transform) {
+               transform_x *transform = transforms->transform;
+               transform_x *tmp = NULL;
+               while(transform != NULL) {
+                       tmp = transform->next;
+                       _ri_free_transform(transform);
+                       transform = tmp;
+               }
+       }
+       free((void*)transforms);
+       transforms = NULL;
+}
+
+static void _ri_free_reference(reference_x *reference)
+{
+       if (reference == NULL)
+               return;
+       if (reference->digestmethod) {
+               digestmethod_x *digestmethod = reference->digestmethod;
+               digestmethod_x *tmp = NULL;
+               while(digestmethod != NULL) {
+                       tmp = digestmethod->next;
+                       _ri_free_digestmethod(digestmethod);
+                       digestmethod = tmp;
+               }
+       }
+       if (reference->digestvalue) {
+               digestvalue_x *digestvalue = reference->digestvalue;
+               digestvalue_x *tmp = NULL;
+               while(digestvalue != NULL) {
+                       tmp = digestvalue->next;
+                       _ri_free_digestvalue(digestvalue);
+                       digestvalue = tmp;
+               }
+       }
+       if (reference->transforms) {
+               transforms_x *transforms = reference->transforms;
+               transforms_x *tmp = NULL;
+               while(transforms != NULL) {
+                       tmp = transforms->next;
+                       _ri_free_transforms(transforms);
+                       transforms = tmp;
+               }
+       }
+       if(reference->uri)
+               free((void*)reference->uri);
+
+       free((void*)reference);
+       reference = NULL;
+}
+
+static void _ri_free_signedinfo(signedinfo_x *signedinfo)
+{
+       if (signedinfo == NULL)
+               return;
+       if (signedinfo->cannonicalizationmethod) {
+               cannonicalizationmethod_x *cannonicalizationmethod = signedinfo->cannonicalizationmethod;
+               cannonicalizationmethod_x *tmp = NULL;
+               while(cannonicalizationmethod != NULL) {
+                       tmp = cannonicalizationmethod->next;
+                       _ri_free_cannonicalizationmethod(cannonicalizationmethod);
+                       cannonicalizationmethod = tmp;
+               }
+       }
+       if (signedinfo->signaturemethod) {
+               signaturemethod_x *signaturemethod = signedinfo->signaturemethod;
+               signaturemethod_x *tmp = NULL;
+               while(signaturemethod != NULL) {
+                       tmp = signaturemethod->next;
+                       _ri_free_signaturemethod(signaturemethod);
+                       signaturemethod = tmp;
+               }
+       }
+       if (signedinfo->reference) {
+               reference_x *reference = signedinfo->reference;
+               reference_x *tmp = NULL;
+               while(reference != NULL) {
+                       tmp = reference->next;
+                       _ri_free_reference(reference);
+                       reference = tmp;
+               }
+       }
+       free((void*)signedinfo);
+       signedinfo = NULL;
+}
+
+void _ri_free_signature_xml(signature_x *sigx)
+{
+       if (sigx == NULL)
+               return;
+       if (sigx->id) {
+               free((void *)sigx->id);
+               sigx->id = NULL;
+       }
+       if (sigx->xmlns) {
+               free((void *)sigx->xmlns);
+               sigx->xmlns = NULL;
+       }
+       if (sigx->signedinfo) {
+               signedinfo_x *signedinfo = sigx->signedinfo;
+               signedinfo_x *tmp = NULL;
+               while(signedinfo != NULL) {
+                       tmp = signedinfo->next;
+                       _ri_free_signedinfo(signedinfo);
+                       signedinfo = tmp;
+               }
+       }
+       if (sigx->signaturevalue) {
+               signaturevalue_x *signaturevalue = sigx->signaturevalue;
+               signaturevalue_x *tmp = NULL;
+               while(signaturevalue != NULL) {
+                       tmp = signaturevalue->next;
+                       _ri_free_signaturevalue(signaturevalue);
+                       signaturevalue = tmp;
+               }
+       }
+       if (sigx->keyinfo) {
+               keyinfo_x *keyinfo = sigx->keyinfo;
+               keyinfo_x *tmp = NULL;
+               while(keyinfo != NULL) {
+                       tmp = keyinfo->next;
+                       _ri_free_keyinfo(keyinfo);
+                       keyinfo = tmp;
+               }
+       }
+       /*Object will be freed when it will be parsed in future*/
+       free((void*)sigx);
+       sigx = NULL;
+}
+
+static int _ri_process_digestmethod(xmlTextReaderPtr reader, digestmethod_x *digestmethod)
+{
+       int ret = -1;
+       ret = _ri_get_attribute(reader,"Algorithm",&digestmethod->algorithm);
+       if(ret != 0){
+               _LOGE("@Error in getting the attribute value");
+       }
+       return ret;
+}
+
+static int _ri_process_digestvalue(xmlTextReaderPtr reader, digestvalue_x *digestvalue)
+{
+       xmlTextReaderRead(reader);
+       xmlChar *tmp = NULL;
+       tmp = xmlTextReaderValue(reader);
+       if (tmp)
+               digestvalue->text = ASCII(tmp);
+       return 0;
+}
+
+static int _ri_process_transform(xmlTextReaderPtr reader, transform_x *transform)
+{
+       int ret = -1;
+       ret = _ri_get_attribute(reader,"Algorithm",&transform->algorithm);
+       if(ret != 0){
+               _LOGE("@Error in getting the attribute value");
+       }
+       return ret;
+}
+
+static int _ri_process_transforms(xmlTextReaderPtr reader, transforms_x *transforms)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       transform_x *tmp1 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "Transform") == 0) {
+                       transform_x *transform = calloc(1, sizeof(transform_x));
+                       if (transform == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(transforms->transform, transform);
+                       ret = _ri_process_transform(reader, transform);
+               } else {
+                       _LOGD("Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (transforms->transform) {
+               LISTHEAD(transforms->transform, tmp1);
+               transforms->transform = tmp1;
+       }
+       return ret;
+}
+
+static int _ri_process_cannonicalizationmethod(xmlTextReaderPtr reader, cannonicalizationmethod_x *cannonicalizationmethod)
+{
+       int ret = -1;
+       ret = _ri_get_attribute(reader,"Algorithm",&cannonicalizationmethod->algorithm);
+       if(ret != 0){
+               _LOGE("@Error in getting the attribute value");
+       }
+       return ret;
+}
+
+static int _ri_process_signaturemethod(xmlTextReaderPtr reader, signaturemethod_x *signaturemethod)
+{
+       int ret = -1;
+       ret = _ri_get_attribute(reader,"Algorithm",&signaturemethod->algorithm);
+       if(ret != 0){
+               _LOGE("@Error in getting the attribute value");
+       }
+       return ret;
+}
+
+static int _ri_process_reference(xmlTextReaderPtr reader, reference_x *reference)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       digestmethod_x *tmp1 = NULL;
+       digestvalue_x *tmp2 = NULL;
+       transforms_x *tmp3 = NULL;
+
+       ret = _ri_get_attribute(reader,"URI",&reference->uri);
+       if(ret != 0){
+               _LOGE("@Error in getting the attribute value");
+               return -1;
+       }
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "DigestMethod") == 0) {
+                       digestmethod_x *digestmethod = calloc(1, sizeof(digestmethod_x));
+                       if (digestmethod == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(reference->digestmethod, digestmethod);
+                       ret = _ri_process_digestmethod(reader, digestmethod);
+               } else if (strcmp(ASCII(node), "DigestValue") == 0) {
+                       digestvalue_x *digestvalue = calloc(1, sizeof(digestvalue_x));
+                       if (digestvalue == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(reference->digestvalue, digestvalue);
+                       ret = _ri_process_digestvalue(reader, digestvalue);
+               } else if (strcmp(ASCII(node), "Transforms") == 0) {
+                       transforms_x *transforms = calloc(1, sizeof(transforms_x));
+                       if (transforms == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(reference->transforms, transforms);
+                       ret = _ri_process_transforms(reader, transforms);
+               } else {
+                       _LOGD("Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (reference->digestmethod) {
+               LISTHEAD(reference->digestmethod, tmp1);
+               reference->digestmethod = tmp1;
+       }
+       if (reference->digestvalue) {
+               LISTHEAD(reference->digestvalue, tmp2);
+               reference->digestvalue = tmp2;
+       }
+       if (reference->transforms) {
+               LISTHEAD(reference->transforms, tmp3);
+               reference->transforms = tmp3;
+       }
+       return ret;
+}
+
+static int _ri_process_x509certificate(xmlTextReaderPtr reader, x509certificate_x *x509certificate)
+{
+       xmlTextReaderRead(reader);
+       xmlChar *tmp = NULL;
+       tmp = xmlTextReaderValue(reader);
+       if (tmp) {
+               x509certificate->text = ASCII(tmp);
+               _LOGD("x509certificate, len=[%d]\n%s", strlen(x509certificate->text), x509certificate->text);
+       }
+       return 0;
+}
+
+static int _ri_process_x509data(xmlTextReaderPtr reader, x509data_x *x509data)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       x509certificate_x *tmp1 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "X509Certificate") == 0) {
+                       x509certificate_x *x509certificate = calloc(1, sizeof(x509certificate_x));
+                       if (x509certificate == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(x509data->x509certificate, x509certificate);
+                       ret = _ri_process_x509certificate(reader, x509certificate);
+               } else {
+                       _LOGD("Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (x509data->x509certificate) {
+               LISTHEAD(x509data->x509certificate, tmp1);
+               x509data->x509certificate = tmp1;
+       }
+       return ret;
+}
+
+#if 0
+static int _ri_process_object(xmlTextReaderPtr reader, object_x *object)
+{
+       /*To be parsed later*/
+       return 0;
+}
+#endif
+
+static int _ri_process_keyinfo(xmlTextReaderPtr reader, keyinfo_x *keyinfo)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       x509data_x *tmp1 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "X509Data") == 0) {
+                       x509data_x *x509data = calloc(1, sizeof(x509data_x));
+                       if (x509data == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(keyinfo->x509data, x509data);
+                       ret = _ri_process_x509data(reader, x509data);
+               } else {
+                       _LOGD("Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (keyinfo->x509data) {
+               LISTHEAD(keyinfo->x509data, tmp1);
+               keyinfo->x509data = tmp1;
+       }
+       return ret;
+}
+
+static int _ri_process_signaturevalue(xmlTextReaderPtr reader, signaturevalue_x *signaturevalue)
+{
+       xmlTextReaderRead(reader);
+       xmlChar *tmp = NULL;
+       tmp = xmlTextReaderValue(reader);
+       if (tmp) {
+               signaturevalue->text = ASCII(tmp);
+               _LOGD("SignatureValue, len=[%d]\n%s", strlen(signaturevalue->text), signaturevalue->text);
+       }
+       return 0;
+}
+
+static int _ri_process_signedinfo(xmlTextReaderPtr reader, signedinfo_x *signedinfo)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       cannonicalizationmethod_x *tmp1 = NULL;
+       signaturemethod_x *tmp2 = NULL;
+       reference_x *tmp3 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "CanonicalizationMethod") == 0) {
+                       cannonicalizationmethod_x *cannonicalizationmethod = calloc(1, sizeof(cannonicalizationmethod_x));
+                       if (cannonicalizationmethod == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(signedinfo->cannonicalizationmethod, cannonicalizationmethod);
+                       ret = _ri_process_cannonicalizationmethod(reader, cannonicalizationmethod);
+               } else if (strcmp(ASCII(node), "SignatureMethod") == 0) {
+                       signaturemethod_x *signaturemethod = calloc(1, sizeof(signaturemethod_x));
+                       if (signaturemethod == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(signedinfo->signaturemethod, signaturemethod);
+                       ret = _ri_process_signaturemethod(reader, signaturemethod);
+               } else if (strcmp(ASCII(node), "Reference") == 0) {
+                       reference_x *reference = calloc(1, sizeof(reference_x));
+                       if (reference == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(signedinfo->reference, reference);
+                       ret = _ri_process_reference(reader, reference);
+               } else {
+                       _LOGD("Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (signedinfo->cannonicalizationmethod) {
+               LISTHEAD(signedinfo->cannonicalizationmethod, tmp1);
+               signedinfo->cannonicalizationmethod = tmp1;
+       }
+       if (signedinfo->signaturemethod) {
+               LISTHEAD(signedinfo->signaturemethod, tmp2);
+               signedinfo->signaturemethod = tmp2;
+       }
+       if (signedinfo->reference) {
+               LISTHEAD(signedinfo->reference, tmp3);
+               signedinfo->reference = tmp3;
+       }
+       return ret;
+}
+
+static int _ri_process_sign(xmlTextReaderPtr reader, signature_x *sigx)
+{
+       const xmlChar *node = NULL;
+       int ret = 0;
+       int depth = 0;
+       signedinfo_x *tmp1 = NULL;
+       signaturevalue_x *tmp2 = NULL;
+       keyinfo_x *tmp3 = NULL;
+       object_x *tmp4 = NULL;
+
+       depth = xmlTextReaderDepth(reader);
+       while ((ret = _ri_next_child_element(reader, depth))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("node is NULL\n");
+                       return -1;
+               }
+               if (strcmp(ASCII(node), "SignedInfo") == 0) {
+                       signedinfo_x *signedinfo = calloc(1, sizeof(signedinfo_x));
+                       if (signedinfo == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->signedinfo, signedinfo);
+                       ret = _ri_process_signedinfo(reader, signedinfo);
+               } else if (strcmp(ASCII(node), "SignatureValue") == 0) {
+                       signaturevalue_x *signaturevalue = calloc(1, sizeof(signaturevalue_x));
+                       if (signaturevalue == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->signaturevalue, signaturevalue);
+                       ret = _ri_process_signaturevalue(reader, signaturevalue);
+               } else if (strcmp(ASCII(node), "KeyInfo") == 0) {
+                       keyinfo_x *keyinfo = calloc(1, sizeof(keyinfo_x));
+                       if (keyinfo == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->keyinfo, keyinfo);
+                       ret = _ri_process_keyinfo(reader, keyinfo);
+               } else if (strcmp(ASCII(node), "Object") == 0) {
+                       /*
+                       object_x *object = calloc(1, sizeof(object_x));
+                       if (object == NULL) {
+                               _LOGE("Calloc Failed\n");
+                               return -1;
+                       }
+                       LISTADD(sigx->object, object);
+                       ret = _ri_process_object(reader, object);
+                       */
+                       continue;
+               } else {
+                       _LOGD("Invalid tag %s", ASCII(node));
+                       return -1;
+               }
+               if (ret < 0)
+                       return ret;
+       }
+       if (sigx->signedinfo) {
+               LISTHEAD(sigx->signedinfo, tmp1);
+               sigx->signedinfo = tmp1;
+       }
+       if (sigx->signaturevalue) {
+               LISTHEAD(sigx->signaturevalue, tmp2);
+               sigx->signaturevalue = tmp2;
+       }
+       if (sigx->keyinfo) {
+               LISTHEAD(sigx->keyinfo, tmp3);
+               sigx->keyinfo = tmp3;
+       }
+       if (sigx->object) {
+               LISTHEAD(sigx->object, tmp4);
+               sigx->object = tmp4;
+       }
+       return ret;
+}
+
+static int _ri_process_signature(xmlTextReaderPtr reader, signature_x *sigx)
+{
+       const xmlChar *node = NULL;
+       int ret = -1;
+
+       if ((ret = _ri_next_child_element(reader, -1))) {
+               node = xmlTextReaderConstName(reader);
+               if (!node) {
+                       _LOGE("Node is null");
+                       return -1;
+               }
+               if (!strcmp(ASCII(node), "Signature")) {
+                       ret = _ri_get_attribute(reader,"Id",&sigx->id);
+                       if(ret != 0){
+                               _LOGE("@Error in getting the attribute value");
+                               return -1;
+                       }
+
+                       ret = _ri_get_attribute(reader,"xmlns",&sigx->xmlns);
+                       if(ret != 0){
+                               _LOGE("@Error in getting the attribute value");
+                               return -1;
+                       }
+
+                       ret = _ri_process_sign(reader, sigx);
+               } else {
+                       _LOGE("No Signature element found\n");
+                       return -1;
+               }
+       }
+       return ret;
+}
+
+signature_x *_ri_process_signature_xml(const char *signature_file)
+{
+       xmlTextReaderPtr reader;
+       signature_x *sigx = NULL;
+
+       reader = xmlReaderForFile(signature_file, NULL, 0);
+
+       if (reader) {
+               sigx = calloc(1, sizeof(signature_x));
+               if (sigx) {
+                       if (_ri_process_signature(reader, sigx) < 0) {
+                               /* error in parsing. Let's display some hint where we failed */
+                               _LOGE("Syntax error in processing signature in the above line\n");
+                               _ri_free_signature_xml(sigx);
+                               xmlFreeTextReader(reader);
+                               return NULL;
+                       }
+               } else {
+                       _LOGE("Calloc failed\n");
+               }
+               xmlFreeTextReader(reader);
+       } else {
+               _LOGE("Unable to create xml reader\n");
+       }
+       return sigx;
+}
similarity index 56%
rename from backend/src/core/rpm-installer-tool.c
rename to backend/src/rpm/rpm-installer-tool.c
index e396e69..efdb970 100755 (executable)
 #include <header.h>
 #include <rpmts.h>
 #include <rpmdb.h>
-#include "rpm-installer.h"
-#include "rpm-frontend.h"
 #include <pkgmgr_installer.h>
 
-#define RPM    "/usr/etc/package-manager/backend/rpm"
+#include "rpm-installer.h"
+#include "rpm-frontend.h"
+#include "rpm-installer-type.h"
 
 char *gpkgname = NULL;
 extern char scrolllabel[256];
@@ -73,14 +73,14 @@ static int __ri_uninstall_package(char *pkgid)
        int ret = 0;
        ret = _rpm_installer_package_uninstall(pkgid);
        if (ret == RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED) {
-               _d_msg(DEBUG_ERR, "[__ri_uninstall_package]%s "
+               _LOGE("[__ri_uninstall_package]%s "
                       "not installed\n", pkgid);
        } else if (ret != 0) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "[__ri_uninstall_package]%s uninstall failed(%d)\n",
                       pkgid, ret);
        } else {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "[__ri_uninstall_package]%s successfully uninstalled\n",
                       pkgid);
        }
@@ -94,11 +94,11 @@ static int __ri_clear_private_data(char *pkgid)
        int ret = 0;
        ret = _rpm_installer_clear_private_data(pkgid);
        if (ret == RPM_INSTALLER_SUCCESS) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "[__clear_private_data]%s clear data successful\n",
                       pkgid);
        } else {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "[__clear_private_data]%s clear data failed(%d)\n",
                       pkgid, ret);
        }
@@ -110,13 +110,22 @@ static int __ri_move_package(char *pkgid, int move_type)
        if (pkgid == NULL)
                return RPM_INSTALLER_ERR_WRONG_PARAM;
        int ret = 0;
+       if(gpkgname){
+               free(gpkgname);
+               gpkgname = NULL;
+       }
+       gpkgname = strdup(pkgid);
+       if(!gpkgname){
+               _LOGE("Malloc failed!!");
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
        ret = _rpm_move_pkg(pkgid, move_type);
        if (ret == RPM_INSTALLER_SUCCESS) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "[__ri_move_package]%s move successful\n",
                       pkgid);
        } else {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "[__ri_move_package]%s move failed(%d)\n",
                       pkgid, ret);
        }
@@ -200,9 +209,8 @@ static int __ri_native_recovery(int lastbackstate)
        int lreq;
        int opt;
        int err = 0;
-       char *installoptions = NULL;
 
-       _d_msg(DEBUG_INFO, "Rpm Installer Recovery Entry \n");
+       _LOGD("Rpm Installer Recovery Entry \n");
 
        /* which package it was installing and what was state at that time */
        _ri_get_last_input_info(&pn, &lreq, &opt);
@@ -213,12 +221,12 @@ static int __ri_native_recovery(int lastbackstate)
                /*
                 * restart the last operation
                 */
-               _d_msg(DEBUG_INFO,
+               _LOGD(
                              "Rpm Installer Recovery started. state=%d \n", lastbackstate);
                switch (lreq) {
                case INSTALL_CMD:
                        err =
-                           _rpm_installer_package_install(pn, true, "--force");
+                           _rpm_installer_package_install(pn, true, "--force", NULL);
                        if (err)
                                goto RECOVERYERROR;
                        break;
@@ -228,34 +236,40 @@ static int __ri_native_recovery(int lastbackstate)
                        if (err)
                                goto RECOVERYERROR;
                        break;
+               case EFLWGT_INSTALL_CMD:
+                       err = _rpm_installer_package_uninstall(pn);
+                       if(err)
+                               goto RECOVERYERROR;
+                       break;
 
                case CLEARDATA_CMD:
                case MOVE_CMD:
                case RECOVER_CMD:
                        /*TODO*/
-                       _d_msg(DEBUG_INFO,
+                       _LOGD(
                                        "Recovery of command(%d) is to be implemented\n", lreq);
+                       if(pn) free(pn);
                        return 0;
                }
-               _d_msg(DEBUG_INFO,
+               _LOGD(
                              " Rpm Installer Recovery Ended \n");
                break;
        case REQUEST_COMPLETED:
-               _d_msg(DEBUG_INFO,
+               _LOGD(
                              " Rpm Installer Recovery. Nothing To Be Done\n");
                _ri_set_backend_state_info(REQUEST_COMPLETED);
                break;
 
        case REQUEST_PENDING:
-               _d_msg(DEBUG_INFO,
+               _LOGD(
                                "Rpm Installer Recovery started. state=%d\n", lastbackstate);
                /*Only package downgradation can be the case*/
-               err = _rpm_installer_package_install(pn, true, "--force");
+               err = _rpm_installer_package_install(pn, true, "--force", NULL);
                if (err != RPM_INSTALLER_SUCCESS &&
                        err != RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION) {
                        goto RECOVERYERROR;
                }
-               _d_msg(DEBUG_INFO,
+               _LOGD(
                              " Rpm Installer Recovery ended \n");
                _ri_set_backend_state_info(REQUEST_COMPLETED);
                break;
@@ -265,75 +279,274 @@ static int __ri_native_recovery(int lastbackstate)
                 * Unknown state
                 * No need to recover
                 */
-               _d_msg(DEBUG_INFO,
+               _LOGD(
                              " Rpm Installer Recovery Default state \n");
                break;
 
        }
+       if(pn) free(pn);
        return 0;
 
  RECOVERYERROR:
-       _d_msg(DEBUG_ERR, "Error in Recovery error number = (%d)\n",
+       _LOGE("Error in Recovery error number = (%d)\n",
                      err);
+       if(pn) free(pn);
        return err;
 
 }
 
-int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
+static int __ri_check_root_path(const char *pkgid)
+{
+       char dirpath[BUF_SIZE] = {'\0'};
+       struct stat stFileInfo;
+
+       snprintf(dirpath, BUF_SIZE, "/usr/apps/%s", pkgid);
+
+       (void)stat(dirpath, &stFileInfo);
+
+       if (S_ISDIR(stFileInfo.st_mode)) {
+               return 0;       //it menas "/usr/apps/pkgid"
+       }
+       return 1;               //it menas "/opt/usr/apps/pkgid"
+}
+
+void __ri_make_directory(const char *pkgid)
+{
+       char usr_pkg[BUF_SIZE] = {'\0'};
+       char opt_pkg[BUF_SIZE] = {'\0'};
+       int ret = 0;
+
+       snprintf(usr_pkg, BUF_SIZE, "%s/%s/%s", USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+       snprintf(opt_pkg, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+
+       // check author signature
+       if ((access(opt_pkg, R_OK) == 0) || (access(usr_pkg, R_OK) == 0)) {
+               _LOGE("pkgid[%s] has author-signature",pkgid);
+
+               // root path
+               memset(opt_pkg, '\0', BUF_SIZE);
+               snprintf(opt_pkg, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+               if (access(opt_pkg, R_OK) != 0) {
+                       _LOGE("dont have [%s]\n",opt_pkg);
+                       ret = mkdir(opt_pkg, DIRECTORY_PERMISSION_755);
+                       if (ret < 0) {
+                               _LOGE("directory making is failed.\n");
+                       }else{
+                               _LOGE("directory[%s] is created", opt_pkg);
+                       }
+               }
+
+               // shared
+               memset(opt_pkg, '\0', BUF_SIZE);
+               snprintf(opt_pkg, BUF_SIZE, "%s/%s/shared", OPT_USR_APPS, pkgid);
+               if (access(opt_pkg, R_OK) != 0) {
+                       _LOGE("dont have [%s]\n",opt_pkg);
+                       ret = mkdir(opt_pkg, DIRECTORY_PERMISSION_755);
+                       if (ret < 0) {
+                               _LOGE("directory making is failed.\n");
+                       }else{
+                               _LOGE("directory[%s] is created", opt_pkg);
+                       }
+               }
+
+               // shared/data
+               memset(opt_pkg, '\0', BUF_SIZE);
+               snprintf(opt_pkg, BUF_SIZE, "%s/%s/shared/data", OPT_USR_APPS, pkgid);
+               if (access(opt_pkg, R_OK) != 0) {
+                       _LOGE("dont have [%s]\n",opt_pkg);
+                       ret = mkdir(opt_pkg, DIRECTORY_PERMISSION_755);
+                       if (ret < 0) {
+                               _LOGE("directory making is failed.\n");
+                       }else{
+                               _LOGE("directory[%s] is created", opt_pkg);
+                       }
+               }
+
+               // shared/trusted
+               memset(opt_pkg, '\0', BUF_SIZE);
+               snprintf(opt_pkg, BUF_SIZE, "%s/%s/shared/trusted", OPT_USR_APPS, pkgid);
+               if (access(opt_pkg, R_OK) != 0) {
+                       _LOGE("dont have [%s],\n",opt_pkg);
+                       ret = mkdir(opt_pkg, DIRECTORY_PERMISSION_755);
+                       if (ret < 0) {
+                               _LOGE("directory making is failed.\n");
+                       }else{
+                               _LOGE("directory[%s] is created", opt_pkg);
+                       }
+               }
+
+       }
+}
+
+static int __ri_process_smack(char *keyid, char *pkgid)
+{
+       int ret = 0;
+
+       /*apply smack for ug*/
+       if(strcmp(keyid,"ug-smack")==0) {
+               _LOGD("only apply smack for ug\n");
+               const char *perm[] = {"http://tizen.org/privilege/appsetting", NULL};
+               _ri_apply_smack(pkgid,__ri_check_root_path(pkgid));
+               _ri_privilege_enable_permissions(pkgid, 1, perm, 1);
+       /*apply smack for rpm package*/
+       } else if (strcmp(keyid,"rpm-smack")==0) {
+               _LOGD("apply smack for rpm");
+               __ri_make_directory(pkgid);
+               _ri_apply_smack(pkgid,__ri_check_root_path(pkgid));
+
+       /*soft-reset for rpm package*/
+       } else if (strcmp(keyid,"soft-reset")==0) {
+               _LOGD("soft-reset\n");
+               _ri_soft_reset(pkgid);
+
+       /*register xml to db, call pkgmgr parser*/
+       } else if (strcmp(keyid,"core-xml")==0) {
+               _LOGD("install corexml");
+               ret = _rpm_installer_corexml_install(pkgid);
+               if (ret != 0) {
+                       _LOGE("corexml_install failed with err(%d)\n", ret);
+               } else {
+                       _LOGD("manifest is installed successfully");
+               }
+       /*apply privilege for rpm package*/
+       } else if (strcmp(keyid,"rpm-perm")==0) {
+               _LOGD("apply privileges for rpm");
+               ret = _ri_apply_privilege(pkgid, 0);
+               if (ret != 0) {
+                       _LOGE("apply privileges failed with err(%d)", ret);
+               } else {
+                       _LOGD("apply privileges success");
+               }
+       /*check csc xml*/
+       } else if (strcmp(keyid,"csc-xml")==0) {
+               _LOGD("csc xml for rpm\n");
+               ret = _rpm_process_cscxml(pkgid);
+               if (ret != 0) {
+                       _LOGE("install csc xml failed with err(%d)\n", ret);
+               } else {
+                       _LOGD("install csc xml success\n");
+               }
+
+       /*check csc coretpk*/
+       } else if (strcmp(keyid,"csc-core")==0) {
+               _LOGD("csc for coretpk\n");
+               ret = _rpm_process_csc_coretpk(pkgid);
+               if (ret != 0) {
+                       _LOGE("install coretpk csc failed with err(%d)\n", ret);
+               } else {
+                       _LOGD("install coretpk csc success\n");
+               }
+
+       /*check fota*/
+       } else if (strcmp(keyid,"rpm-fota")==0) {
+               _LOGD("fota process for rpm\n");
+               ret = _rpm_process_fota(pkgid);
+               if (ret != 0) {
+                       _LOGE("fota process failed with err(%d)\n", ret);
+               } else {
+                       _LOGD("fota process success\n");
+               }
+       /*check fota*/
+       } else if (strcmp(keyid,"rpm-rw-fota")==0) {
+               _LOGD("rw fota process for rpm\n");
+               ret = _rpm_process_fota_for_rw(pkgid);
+               if (ret != 0) {
+                       _LOGE("rw fota process failed with err(%d)\n", ret);
+               } else {
+                       _LOGD("rw fota process success\n");
+               }
+       } else {
+               _LOGE("smack cmd error\n");
+               ret = -1;
+       }
+
+       return ret;
+}
+
+int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand, char *clientid)
 {
        int ret = -1;
        ri_backend_data data = { 0 };
        int backendstate;
        rpmRC rc;
        if (reqcommand == NULL) {
-               _d_msg(DEBUG_ERR, "reqcommand is NULL\n");
+               _LOGE("reqcommand is NULL\n");
                return RPM_INSTALLER_ERR_WRONG_PARAM;
        }
        if (keyid == NULL || pkgid == NULL) {
                if (strncmp(reqcommand, "recover", strlen("recover"))) {
-                       _d_msg(DEBUG_ERR, " Either keyid/pkgid is NULL\n");
+                       _LOGE(" Either keyid/pkgid is NULL\n");
                        return RPM_INSTALLER_ERR_WRONG_PARAM;
                }
+               _LOGE(" Either keyid/pkgid is NULL\n");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
        }
 
        if (strncmp(reqcommand, "install", strlen("install")) == 0) {
                data.req_cmd = INSTALL_CMD;
                data.cmd_string = strdup("install");
                if (data.cmd_string == NULL) {
-                       _d_msg(DEBUG_ERR,
+                       _LOGE(
                               "strdup failed due to insufficient memory\n");
+                       return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
                }
        } else if (strncmp(reqcommand, "remove", strlen("remove")) == 0) {
                data.req_cmd = DELETE_CMD;
                data.cmd_string = strdup("uninstall");
                if (data.cmd_string == NULL) {
-                       _d_msg(DEBUG_ERR,
+                       _LOGE(
                               "strdup failed due to insufficient memory\n");
+                       return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
                }
        } else if (strncmp(reqcommand, "recover", strlen("recover")) == 0) {
                data.req_cmd = RECOVER_CMD;
                data.cmd_string = strdup("recover");
                if (data.cmd_string == NULL) {
-                       _d_msg(DEBUG_ERR,
+                       _LOGE(
                               "strdup failed due to insufficient memory\n");
+                       return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
                }
        } else if (strncmp(reqcommand, "cleardata", strlen("cleardata")) == 0) {
                data.req_cmd = CLEARDATA_CMD;
                data.cmd_string = strdup("cleardata");
                if (data.cmd_string == NULL) {
-                       _d_msg(DEBUG_ERR,
+                       _LOGE(
                               "strdup failed due to insufficient memory\n");
+                       return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
                }
        } else if (strncmp(reqcommand, "move", strlen("move")) == 0) {
                data.req_cmd = MOVE_CMD;
                data.cmd_string = strdup("move");
                if (data.cmd_string == NULL) {
-                       _d_msg(DEBUG_ERR,
+                       _LOGE(
                               "strdup failed due to insufficient memory\n");
+                       return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
                }
+       } else if (strncmp(reqcommand, "smack", strlen("smack")) == 0) {
+               return __ri_process_smack(keyid, pkgid);
+       } else if (strncmp(reqcommand, "eflwgt-install", strlen("eflwgt-install")) == 0) {
+               data.req_cmd = EFLWGT_INSTALL_CMD;
+               data.cmd_string = strdup("eflwgt-install");
+               if (data.cmd_string == NULL) {
+                       _LOGE(
+                               "strdup failed due to insufficient memory\n");
+                       return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+               }
+       } else if (strncmp(reqcommand, "rpm-enable", strlen("rpm-enable")) == 0) {
+               if (strstr(pkgid, ":") == NULL)
+                       ret = _rpm_process_enable(pkgid);
+               else
+                       ret = _rpm_process_enabled_list(pkgid);
+               return ret;
+       } else if (strncmp(reqcommand, "rpm-disable", strlen("rpm-disable")) == 0) {
+               if (strstr(pkgid, ":") == NULL)
+                       ret = _rpm_process_disable(pkgid);
+               else
+                       ret = _rpm_process_disabled_list(pkgid);
+               return ret;
        } else {
-               _d_msg(DEBUG_INFO, "wrong input parameter\n");
-               _d_msg(DEBUG_RESULT, "%d\n", RPM_INSTALLER_ERR_WRONG_PARAM);
+               _LOGD("wrong input parameter\n");
+               _LOGD("%d\n", RPM_INSTALLER_ERR_WRONG_PARAM);
                return RPM_INSTALLER_ERR_WRONG_PARAM;
        }
 
@@ -342,9 +555,13 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
 
        rc = rpmReadConfigFiles(NULL, NULL);
        if (rc == RPMRC_OK) {
-               _d_msg(DEBUG_INFO, "Successfully read rpm configuration\n");
+               _LOGD("Successfully read rpm configuration\n");
        } else {
-               _d_msg(DEBUG_ERR, "Unable to read RPM configuration.\n");
+               _LOGE("Unable to read RPM configuration.\n");
+               if (data.cmd_string) {
+                       free(data.cmd_string);
+                       data.cmd_string = NULL;
+               }
                return RPM_INSTALLER_ERR_INTERNAL;
        }
 
@@ -356,30 +573,34 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
                        lastbackstate = _ri_get_backend_state_info();
 
                        if (REQUEST_COMPLETED == lastbackstate) {
-                               _d_msg(DEBUG_INFO,
+                               _LOGD(
                                       " Rpm Installer recovery is in REQUEST_COMPLETED  \n");
                                snprintf(scrolllabel, sizeof(scrolllabel),
                                         "No Recovery Needed");
-                       } else
+                       } else{
                                ret = __ri_native_recovery(lastbackstate);
-                       if (ret == 0)
-                               snprintf(scrolllabel, sizeof(scrolllabel),
-                                        "Recovery Success");
-                       else
-                               snprintf(scrolllabel, sizeof(scrolllabel),
-                                       "Recovery Failed");
-
+                               if (ret == 0)
+                                       snprintf(scrolllabel, sizeof(scrolllabel),
+                                                "Recovery Success");
+                               else
+                                       snprintf(scrolllabel, sizeof(scrolllabel),
+                                               "Recovery Failed");
+                       }
                        /* set the backend state as completed */
                        _ri_set_backend_state(1);
                } else {
                        /* nothing to recover */
-                       _d_msg(DEBUG_INFO,
+                       _LOGD(
                               " Rpm Installer recovery Nothing to be done\n");
                        ret = 0;
                        snprintf(scrolllabel, sizeof(scrolllabel),
                                 "No Recovery Needed");
                }
-               _d_msg(DEBUG_RESULT, "%d\n", ret);
+               _LOGD("%d\n", ret);
+               if (data.cmd_string) {
+                       free(data.cmd_string);
+                       data.cmd_string = NULL;
+               }
                return ret;
 
        }
@@ -394,53 +615,55 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
                if (__ri_is_another_instance_running(RPM)) {
                        if (data.pkgid) {
                                _ri_broadcast_status_notification
-                                   (data.pkgid, "error",
+                                   (data.pkgid, "rpm", "error",
                                     "Another Instance Running");
                                _ri_stat_cb(data.pkgid, "error",
                                            "Another Instance Running");
                                _ri_broadcast_status_notification
-                                   (data.pkgid, "end", "fail");
+                                   (data.pkgid, "rpm", "end", "fail");
                                _ri_stat_cb(data.pkgid, "end",
                                            "fail");
                        } else {
                                _ri_broadcast_status_notification
-                                   ("unknown", "error",
+                                   ("unknown", "unknown", "error",
                                     "Another Instance Running");
                                _ri_stat_cb("unknown", "error",
                                            "Another Instance Running");
                                _ri_broadcast_status_notification
-                                   ("unknown", "end", "fail");
+                                   ("unknown", "unknown", "end", "fail");
                                _ri_stat_cb("unknown", "end", "fail");
                        }
-                       _d_msg(DEBUG_INFO,
+                       _LOGD(
                               "Request Failed as "
                               "Another Instance is running \n");
                        ret = RPM_INSTALLER_ERR_RESOURCE_BUSY;
+                       if (data.cmd_string) {
+                               free(data.cmd_string);
+                               data.cmd_string = NULL;
+                       }
                        return ret;
                } else {
                        int lastbackstate;
 
                        /* check the current state of backend */
                        lastbackstate = _ri_get_backend_state_info();
+
                        /* Publish Notification that backend has started */
-                       _ri_broadcast_status_notification(data.pkgid,
-                                                         "start",
-                                                         data.cmd_string);
-                       _ri_broadcast_status_notification(data.pkgid,
-                                                         "command",
-                                                         data.cmd_string);
+//                     _ri_broadcast_status_notification(data.pkgid, "rpm", "start", data.cmd_string);
+//                     _ri_broadcast_status_notification(data.pkgid, "rpm", "command", data.cmd_string);
+
                        if (REQUEST_COMPLETED == lastbackstate) {
-                               _d_msg(DEBUG_INFO,
+                               _LOGD(
                                       " Rpm Installer recovery"
                                       " is in REQUEST_COMPLETED  \n");
                                ret = 0;
                        } else
                                ret = __ri_native_recovery(lastbackstate);
                        if (ret != 0) {
-                               _d_msg(DEBUG_INFO,
+                               _LOGD(
                                        "recovery of last request failed\n");
                        } else {
-                               _d_msg(DEBUG_INFO,
+                               _LOGD(
                                       "recovery of last request success\n");
                        }
 
@@ -457,7 +680,7 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
 
        /* Publish Notification that backend has started */
        if (data.pkgid)
-               _ri_broadcast_status_notification(data.pkgid, "start",
+               _ri_broadcast_status_notification(data.pkgid, "rpm", "start",
                                                  data.cmd_string);
        else
                _ri_broadcast_status_notification("unknown", "start",
@@ -467,116 +690,82 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
        _ri_set_backend_state_info(REQUEST_ACCEPTED);
 
        /* Set the input request info */
+       if(data.pkgid == NULL)
+               return RPM_INSTALLER_ERR_PKG_NOT_FOUND;
        _ri_save_last_input_info(data.pkgid, data.req_cmd,
-                                data.force_overwrite);
+                                        data.force_overwrite);
 
        switch (data.req_cmd) {
        case INSTALL_CMD:
                {
-                       _d_msg(DEBUG_INFO, "[%s] --install %s\n",
+                       _LOGD("[%s] --install %s\n",
                               "backend", data.pkgid);
 #ifdef SEND_PKGPATH
-                       _ri_broadcast_status_notification(data.pkgid,
+                       _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                          "command", "Install");
 #endif
                        if (data.force_overwrite == FORCE_OVERWITE) {
-                               _d_msg(DEBUG_INFO,
+                               _LOGD(
                                       "[%s] --install %s --force-overwrite\n",
                                       "backend", data.pkgid);
                                ret =
                                    _rpm_installer_package_install
-                                   (data.pkgid, true, "--force");
+                                   (data.pkgid, true, "--force", clientid);
                        } else {
-                               _d_msg(DEBUG_INFO, "[%s] --install %s\n",
+                               if(data.pkgid == NULL) {
+                                       _LOGE("pkgid is null");
+                                       break;
+                               }
+                               _LOGD("[%s] --install %s\n",
                                       "backend", data.pkgid);
                                ret =
                                    _rpm_installer_package_install
-                                   (data.pkgid, false, NULL);
-                       }
-                       if (ret == RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION) {
-                               break;
-                       } else if (ret == RPM_INSTALLER_SUCCESS) {
-                               _d_msg(DEBUG_INFO, "install success\n");
-                               _ri_broadcast_status_notification(data.pkgid,
-                                                                 "end", "ok");
-                               _ri_stat_cb(data.pkgid, "end", "ok");
-                       } else {
-
-                               char *errstr = NULL;
-                               _ri_error_no_to_string(ret, &errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
-                                                                 "error",
-                                                                 errstr);
-                               _ri_stat_cb(data.pkgid, "error", errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
-                                                                 "end",
-                                                                 "fail");
-                               sleep(2);
-                               _ri_stat_cb(data.pkgid, "end", "fail");
-                               _d_msg(DEBUG_ERR,
-                                      "install failed with err(%d) (%s)\n",
-                                      ret, errstr);
+                                   (data.pkgid, false, NULL, clientid);
                        }
                }
                break;
        case DELETE_CMD:
                {
-                       _d_msg(DEBUG_INFO, "[%s] uninstall %s\n",
+                       _LOGD("[%s] uninstall %s\n",
                               "backend", data.pkgid);
 #ifdef SEND_PKGPATH
-                       _ri_broadcast_status_notification(data.pkgid,
+                       _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                          "command", "Remove");
 #endif
                        ret = __ri_uninstall_package(data.pkgid);
                        if (ret != 0) {
-                               char *errstr = NULL;
-                               _ri_error_no_to_string(ret, &errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
-                                                                 "error",
-                                                                 errstr);
-                               _ri_stat_cb(data.pkgid, "error", errstr);
-                               sleep(2);
-                               _ri_broadcast_status_notification(data.pkgid,
-                                                                 "end",
-                                                                 "fail");
-                               _ri_stat_cb(data.pkgid, "end", "fail");
-                               _d_msg(DEBUG_ERR,
-                                      "remove failed with err(%d) (%s)\n",
-                                      ret, errstr);
+                               _LOGD("remove fail\n");
                        } else {
-                               _d_msg(DEBUG_INFO, "remove success\n");
-                               _ri_broadcast_status_notification(data.pkgid,
-                                                                 "end", "ok");
-                               _ri_stat_cb(data.pkgid, "end", "ok");
+                               _LOGD("remove success\n");
                        }
                }
                break;
        case CLEARDATA_CMD:
                {
-                       _d_msg(DEBUG_INFO, "[%s] clear data %s\n",
+                       _LOGD("[%s] clear data %s\n",
                               "backend", data.pkgid);
 #ifdef SEND_PKGPATH
-                       _ri_broadcast_status_notification(data.pkgid,
+                       _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                          "command", "clear");
 #endif
                        ret = __ri_clear_private_data(data.pkgid);
                        if (ret != 0) {
                                char *errstr = NULL;
                                _ri_error_no_to_string(ret, &errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                                  "error",
                                                                  errstr);
                                _ri_stat_cb(data.pkgid, "error", errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                                  "end",
                                                                  "fail");
                                _ri_stat_cb(data.pkgid, "end", "fail");
-                               _d_msg(DEBUG_ERR,
+                               _LOGE(
                                       "clear data failed with err(%d) (%s)\n",
                                       ret, errstr);
                        } else {
-                               _d_msg(DEBUG_INFO, "clear data success\n");
-                               _ri_broadcast_status_notification(data.pkgid,
+                               _LOGD("clear data success\n");
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                                  "end", "ok");
                                _ri_stat_cb(data.pkgid, "end", "ok");
                        }
@@ -584,46 +773,82 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
                }
        case MOVE_CMD:
                {
-                       _d_msg(DEBUG_INFO, "[%s] move %s\n",
+                       _LOGD("[%s] move %s\n",
                               "backend", data.pkgid);
 #ifdef SEND_PKGPATH
-                       _ri_broadcast_status_notification(data.pkgid,
+                       _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                          "command", "move");
 #endif
                        ret = __ri_move_package(data.pkgid, move_type);
                        if (ret != 0) {
                                char *errstr = NULL;
                                _ri_error_no_to_string(ret, &errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                                  "error",
                                                                  errstr);
                                _ri_stat_cb(data.pkgid, "error", errstr);
-                               _ri_broadcast_status_notification(data.pkgid,
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                                  "end",
                                                                  "fail");
                                _ri_stat_cb(data.pkgid, "end", "fail");
-                               _d_msg(DEBUG_ERR,
+                               _LOGE(
                                       "move failed with err(%d) (%s)\n",
                                       ret, errstr);
                        } else {
-                               _d_msg(DEBUG_INFO, "move success\n");
-                               _ri_broadcast_status_notification(data.pkgid,
+                               _LOGD("move success\n");
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
                                                                  "end", "ok");
                                _ri_stat_cb(data.pkgid, "end", "ok");
                        }
                        break;
                }
+               case EFLWGT_INSTALL_CMD:
+                       {
+
+                       _LOGD("[%s] eflwgt-install %s\n",
+                                                  "backend", data.pkgid);
+#ifdef SEND_PKGPATH
+                       _ri_broadcast_status_notification(data.pkgid, "rpm",
+                                                                 "command", "eflwgt-install");
+#endif
+                       ret = _rpm_installer_package_install_with_dbpath(data.pkgid, clientid);
+                       if (ret != 0) {
+                               char *errstr = NULL;
+                               _ri_error_no_to_string(ret, &errstr);
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
+                                                                         "error",
+                                                                         errstr);
+                               _ri_stat_cb(data.pkgid, "error", errstr);
+                               sleep(2);
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
+                                                                 "end",
+                                                                 "fail");
+                               _ri_stat_cb(data.pkgid, "end", "fail");
+                               _LOGE("eflwgt-install failed with err(%d) (%s)\n",
+                                                  ret, errstr);
+                       } else {
+                               _LOGD("eflwgt-install success\n");
+                               _ri_broadcast_status_notification(data.pkgid, "rpm",
+                                                                 "end", "ok");
+                               _ri_stat_cb(data.pkgid, "end", "ok");
+                       }
+                               _ri_remove_wgt_unzip_dir();
+                               break;
+                       }
+
        default:
                {
-                       _ri_broadcast_status_notification("unknown", "command",
+                       _ri_broadcast_status_notification("unknown", "unknown",
+                                                         "command",
                                                          "unknown");
-                       _ri_broadcast_status_notification("unknown", "error",
+                       _ri_broadcast_status_notification("unknown", "unknown",
+                                                         "error",
                                                          "not supported");
                        _ri_stat_cb("unknown", "error", "not supported");
-                       _ri_broadcast_status_notification("unknown",
+                       _ri_broadcast_status_notification("unknown", "unknown",
                                                          "end", "fail");
                        _ri_stat_cb("unknown", "end", "fail");
-                       _d_msg(DEBUG_ERR, "unknown command \n");
+                       _LOGE("unknown command \n");
                        ret = RPM_INSTALLER_ERR_WRONG_PARAM;
                }
        }
@@ -642,8 +867,7 @@ int _rpm_backend_interface(char *keyid, char *pkgid, char *reqcommand)
                _ri_set_backend_state_info(REQUEST_COMPLETED);
                /* set the backend state as completed */
                _ri_set_backend_state(1);
-               _d_msg(DEBUG_RESULT, "%d\n", ret);
-               _d_msg_deinit();
+               _LOGD("%d\n", ret);
        }
        return ret;
 }
index 6df475e..cad8577 100755 (executable)
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
-#include <glib.h>
+#include <dirent.h>
 #include <ctype.h>             /* for isspace () */
+#include <wctype.h>            /* for towlower() */
+#include <vconf.h>
+#include <cert-service.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <libxml/xmlmemory.h>
+#include <sqlite3.h>
+#include <db-util.h>
+#include <sys/xattr.h>
+
+#ifndef XMLSEC_NO_XSLT
+#include <libxslt/xslt.h>
+#include <libxslt/security.h>
+#endif
+
+#include <xmlsec/xmlsec.h>
+#include <xmlsec/xmltree.h>
+#include <xmlsec/xmldsig.h>
+#include <xmlsec/crypto.h>
+#include <xmlsec/errors.h>
 #include <pkgmgr-info.h>
 #include <pkgmgr_parser.h>
 #include <package-manager.h>
+#include <privilege-control.h>
+#include <app_manager.h>
+#include <aul.h>
+#include <dlfcn.h>
+#define APP2EXT_ENABLE
+#ifdef APP2EXT_ENABLE
+#include <app2ext_interface.h>
+#endif
 
 #include "rpm-installer-util.h"
+#include "rpm-installer-signature.h"
 #include "rpm-installer.h"
 #include "rpm-frontend.h"
+#include "rpm-installer-type.h"
+#include "coretpk-installer-internal.h"
 
-#define PRE_CHECK_FOR_MANIFEST
-#define INSTALL_SCRIPT         "/usr/bin/install_rpm_package.sh"
-#define UNINSTALL_SCRIPT       "/usr/bin/uninstall_rpm_package.sh"
-#define UPGRADE_SCRIPT "/usr/bin/upgrade_rpm_package.sh"
-#define RPM2CPIO       "/usr/bin/rpm2cpio"
 
-enum rpm_request_type {
-       INSTALL_REQ,
-       UNINSTALL_REQ,
-       UPGRADE_REQ,
+enum rpm_sig_type {
+       SIG_AUTH,
+       SIG_DIST1,
+       SIG_DIST2,
 };
 
-#define APP2EXT_ENABLE
-#ifdef APP2EXT_ENABLE
-#include <app2ext_interface.h>
-#endif
+enum rpm_sig_sub_type {
+       SIG_SIGNER,
+       SIG_INTERMEDIATE,
+       SIG_ROOT,
+};
+
+typedef struct cert_chain_t {
+       int cert_type;
+       char *cert_value;
+} cert_chain;
+
+cert_chain list[MAX_CERT_NUM];
+GList *privilege_list;
+
+#define PKGMGR_DB              "/opt/dbspace/.pkgmgr_parser.db"
+#define EXT_APPDATA_PRIVILEGE_NAME     "http://tizen.org/privilege/externalstorage.appdata"
 
-typedef enum rpm_request_type rpm_request_type;
 extern char *gpkgname;
+extern int sig_enable;
 
-static int __rpm_xsystem(const char *argv[]);
 static void __rpm_process_line(char *line);
 static void __rpm_perform_read(int fd);
-static void __rpm_clear_dir_list(GList* dir_list);
-static GList * __rpm_populate_dir_list();
+static int __ri_xmlsec_verify_signature(const char *sigxmlfile, char *rootca);
+static xmlSecKeysMngrPtr __ri_load_trusted_certs(char *files, int files_size);
+static int __ri_verify_file(xmlSecKeysMngrPtr mngr, const char *sigxmlfile);
+static int __ri_create_cert_chain(int sigtype, int sigsubtype, char *value);
+static void __ri_free_cert_chain(void);
+static char *__ri_get_cert_from_file(const char *file);
+static int __privilege_func(const char *name, void *user_data);
+static char *__ri_get_str(const char* str, const char* pKey);
+static void __ri_xmlsec_debug_print(const char* file, int line, const char* func,
+                                                                       const char* errorObject, const char* errorSubject, int reason, const char* msg);
+
+int _ri_set_group_id(const char *pkgid, const char *groupid);
+
+static void __str_trim(char *input)
+{
+       char *trim_str = input;
+
+       if (input == NULL)
+               return;
+
+       while (*input != 0) {
+               if (!isspace(*input)) {
+                       *trim_str = *input;
+                       trim_str++;
+               }
+               input++;
+       }
+
+       *trim_str = 0;
+       return;
+}
+
+static int __ri_check_pkgid_for_deactivation(const char *pkgid)
+{
+       FILE *fp = NULL;
+       char deactivation_str[FILENAME_MAX] = { 0 };
+       char *deactivation_pkgid = NULL;
+       char *deactivation_state = NULL;
+
+       fp = fopen(DEACTIVATION_PKGID_LIST, "r");
+       if (fp == NULL) {
+               _LOGE("fopen fail\n");
+               return 0;
+       }
+
+       while (fgets(deactivation_str, sizeof(deactivation_str), fp) != NULL) {
+               __str_trim(deactivation_str);
+
+               deactivation_pkgid = __ri_get_str(deactivation_str, TOKEN_PKGID_STR);
+               if(deactivation_pkgid == NULL)
+                       continue;
+
+               deactivation_state = __ri_get_str(deactivation_str, TOKEN_STATE_STR);
+               if(deactivation_state == NULL) {
+                       free(deactivation_pkgid);
+                       continue;
+               }
+
+               if ((strcmp(deactivation_pkgid, pkgid) == 0) && (strcmp(deactivation_state, "off") == 0)) {
+                       fclose(fp);
+                       free(deactivation_pkgid);
+                       free(deactivation_state);
+                       _LOGE("Find pkgid[%s] form deactivation list.\n", pkgid);
+                       return -1;
+               }
+
+               free(deactivation_pkgid);
+               free(deactivation_state);
+               memset(deactivation_str, 0x00, sizeof(deactivation_str));
+       }
+
+       if (fp != NULL)
+               fclose(fp);
+
+       return 0;
+
+}
+
+static int __ri_get_op_type(char *op_str)
+{
+       if (strcmp(op_str,"install")==0)
+               return INSTALL_REQ;
+       else if (strcmp(op_str,"update")==0)
+               return UPGRADE_REQ;
+       else if (strcmp(op_str,"uninstall")==0)
+               return UNINSTALL_REQ;
+       else
+               return -1;
+}
+
+static char *__ri_get_str(const char* str, const char* pKey)
+{
+       const char* p = NULL;
+       const char* pStart = NULL;
+       const char* pEnd = NULL;
+
+       if (str == NULL)
+               return NULL;
+
+       char *pBuf = strdup(str);
+       if(!pBuf){
+               _LOGE("Malloc failed !");
+               return NULL;
+       }
+
+       p = strstr(pBuf, pKey);
+       if (p == NULL){
+               if(pBuf){
+                       free(pBuf);
+                       pBuf = NULL;
+               }
+               return NULL;
+       }
+
+       pStart = p + strlen(pKey);
+       pEnd = strchr(pStart, SEPERATOR_END);
+       if (pEnd == NULL){
+               if(pBuf){
+                       free(pBuf);
+                       pBuf = NULL;
+               }
+               return NULL;
+       }
+       size_t len = pEnd - pStart;
+       if (len <= 0){
+               if(pBuf){
+                       free(pBuf);
+                       pBuf = NULL;
+               }
+               return NULL;
+       }
+       char *pRes = (char*)malloc(len + 1);
+       if(!pRes){
+               if(pBuf){
+                       free(pBuf);
+                       pBuf = NULL;
+               }
+               _LOGE("Malloc failed!");
+               return NULL;
+       }
+       strncpy(pRes, pStart, len);
+       pRes[len] = 0;
+
+       if(pBuf){
+               free(pBuf);
+               pBuf = NULL;
+       }
+
+       return pRes;
+}
+
+static int __ri_init_csc_xml(char *xml_path, char *removable)
+{
+       int ret = 0;
+       char* csc_tags[3] = {NULL, };
+
+       if (strcmp(removable,"true")==0)
+               csc_tags[0] = "removable=true";
+       else
+               csc_tags[0] = "removable=false";
+
+       csc_tags[1] = "preload=true";
+       csc_tags[2] = NULL;
+
+       ret = pkgmgr_parser_parse_manifest_for_installation(xml_path, csc_tags);
+
+       return ret;
+}
+
+static int __ri_create_cert_chain(int sigtype, int sigsubtype, char *value)
+{
+       if (value == NULL)
+               return -1;
+       // _LOGD("Push in list [%d] [%d] [%s]", sigtype, sigsubtype, value);
+       switch (sigtype) {
+       case SIG_AUTH:
+               switch (sigsubtype) {
+               case SIG_SIGNER:
+                       list[PMINFO_SET_AUTHOR_SIGNER_CERT].cert_type = PMINFO_SET_AUTHOR_SIGNER_CERT;
+                       list[PMINFO_SET_AUTHOR_SIGNER_CERT].cert_value = strdup(value);
+                       break;
+               case SIG_INTERMEDIATE:
+                       list[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT].cert_type = PMINFO_SET_AUTHOR_INTERMEDIATE_CERT;
+                       list[PMINFO_SET_AUTHOR_INTERMEDIATE_CERT].cert_value = strdup(value);
+                       break;
+               case SIG_ROOT:
+                       /*value is already a mallocd pointer*/
+                       list[PMINFO_SET_AUTHOR_ROOT_CERT].cert_type = PMINFO_SET_AUTHOR_ROOT_CERT;
+                       list[PMINFO_SET_AUTHOR_ROOT_CERT].cert_value = value;
+                       break;
+               default:
+                       break;
+               }
+               break;
+       case SIG_DIST1:
+               switch (sigsubtype) {
+               case SIG_SIGNER:
+                       list[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT].cert_type = PMINFO_SET_DISTRIBUTOR_SIGNER_CERT;
+                       list[PMINFO_SET_DISTRIBUTOR_SIGNER_CERT].cert_value = strdup(value);
+                       break;
+               case SIG_INTERMEDIATE:
+                       list[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT].cert_type = PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT;
+                       list[PMINFO_SET_DISTRIBUTOR_INTERMEDIATE_CERT].cert_value = strdup(value);
+                       break;
+               case SIG_ROOT:
+                       /*value is already a mallocd pointer*/
+                       list[PMINFO_SET_DISTRIBUTOR_ROOT_CERT].cert_type = PMINFO_SET_DISTRIBUTOR_ROOT_CERT;
+                       list[PMINFO_SET_DISTRIBUTOR_ROOT_CERT].cert_value = value;
+                       break;
+               default:
+                       break;
+               }
+               break;
+       case SIG_DIST2:
+               switch (sigsubtype) {
+               case SIG_SIGNER:
+                       list[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT].cert_type = PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT;
+                       list[PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT].cert_value = strdup(value);
+                       break;
+               case SIG_INTERMEDIATE:
+                       list[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT].cert_type = PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT;
+                       list[PMINFO_SET_DISTRIBUTOR2_INTERMEDIATE_CERT].cert_value = strdup(value);
+                       break;
+               case SIG_ROOT:
+                       /*value is already a mallocd pointer*/
+                       list[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT].cert_type = PMINFO_SET_DISTRIBUTOR2_ROOT_CERT;
+                       list[PMINFO_SET_DISTRIBUTOR2_ROOT_CERT].cert_value = value;
+                       break;
+               default:
+                       break;
+               }
+               break;
+       default:
+               break;
+       }
+       return 0;
+}
+
+static void __ri_free_cert_chain()
+{
+       int i = 0;
+       for (i = 0; i < MAX_CERT_NUM; i++) {
+               if (list[i].cert_value)
+                       free(list[i].cert_value);
+       }
+}
+
+static void __ri_xmlsec_debug_print(const char* file, int line, const char* func,
+                                  const char* errorObject, const char* errorSubject, int reason, const char* msg)
+{
+       char total[BUF_SIZE];
+       snprintf(total, sizeof(total), "[%s(%d)] : [%s] : [%s] : [%s]", func, line, errorObject, errorSubject, msg);
+       if(reason != 256) {
+               fprintf(stderr, "## [validate error]: %s\n", total);
+               _LOGE("%s",total);
+       } else {
+               _LOGE("%s",total);
+       }
+}
+
+static int __ri_verify_file(xmlSecKeysMngrPtr sec_key_mngr, const char *sigxmlfile)
+{
+       xmlDocPtr doc = NULL;
+       xmlNodePtr node = NULL;
+       xmlSecDSigCtxPtr dsigCtx = NULL;
+       int res = -1;
+       if (sigxmlfile == NULL)
+               return -1;
+       if (sec_key_mngr == NULL)
+               return -1;
+
+       /* set error callback to xmlsec1 */
+       xmlSecErrorsSetCallback(__ri_xmlsec_debug_print);
+
+       /* load file */
+       doc = xmlParseFile(sigxmlfile);
+       if ((doc == NULL) || (xmlDocGetRootElement(doc) == NULL)) {
+               _LOGE("unable to parse file \"%s\"\n", sigxmlfile);
+               goto err;
+       }
+       /* find start node */
+       node = xmlSecFindNode(xmlDocGetRootElement(doc), xmlSecNodeSignature, xmlSecDSigNs);
+       if (node == NULL) {
+               _LOGE("start node not found in \"%s\"\n", sigxmlfile);
+               goto err;
+       }
+       /* create signature context */
+       dsigCtx = xmlSecDSigCtxCreate(sec_key_mngr);
+       if (dsigCtx == NULL) {
+               _LOGE("failed to create signature context\n");
+               goto err;
+       }
+       /* Verify signature */
+       if (xmlSecDSigCtxVerify(dsigCtx, node) < 0) {
+               _LOGE("failed to verify signature\n");
+               goto err;
+       }
+       /* print verification result to stdout */
+       if (dsigCtx->status == xmlSecDSigStatusSucceeded) {
+               res = 0;
+               _LOGD("valid signature");
+       } else {
+               res = -1;
+               _LOGD("invalid signature");
+       }
+
+err:
+       /* cleanup */
+       if(dsigCtx != NULL) {
+               xmlSecDSigCtxDestroy(dsigCtx);
+       }
+       if(doc != NULL) {
+               xmlFreeDoc(doc);
+       }
+       return res;
+}
+
+static xmlSecKeysMngrPtr __ri_load_trusted_certs(char *files, int files_size)
+{
+       xmlSecKeysMngrPtr sec_key_mngr;
+       if (files == NULL)
+               return NULL;
+       if (files_size < 0)
+               return NULL;
+       sec_key_mngr = xmlSecKeysMngrCreate();
+       if (sec_key_mngr == NULL) {
+               _LOGE("failed to create keys manager.\n");
+               return NULL;
+       }
+       if (xmlSecCryptoAppDefaultKeysMngrInit(sec_key_mngr) < 0) {
+               _LOGE("failed to initialize keys manager.\n");
+               xmlSecKeysMngrDestroy(sec_key_mngr);
+               return NULL;
+       }
+       /* load trusted cert */
+       if (xmlSecCryptoAppKeysMngrCertLoad(sec_key_mngr, files, xmlSecKeyDataFormatPem, xmlSecKeyDataTypeTrusted) < 0) {
+               _LOGE("failed to load pem certificate from \"%s\"\n", files);
+               xmlSecKeysMngrDestroy(sec_key_mngr);
+               return NULL;
+       }
+       return sec_key_mngr;
+}
+
+static int __ri_xmlsec_verify_signature(const char *sigxmlfile, char *rootca)
+{
+       int ret = 0;
+       xmlSecKeysMngrPtr sec_key_mngr = NULL;
+       xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
+       xmlSubstituteEntitiesDefault(1);
+
+#ifndef XMLSEC_NO_XSLT
+       xmlIndentTreeOutput = 1;
+       xsltSecurityPrefsPtr sec_prefs = xsltNewSecurityPrefs();
+       xsltSetSecurityPrefs(sec_prefs,  XSLT_SECPREF_WRITE_FILE, xsltSecurityForbid);
+       xsltSetSecurityPrefs(sec_prefs,  XSLT_SECPREF_READ_FILE, xsltSecurityForbid);
+       xsltSetSecurityPrefs(sec_prefs,  XSLT_SECPREF_CREATE_DIRECTORY, xsltSecurityForbid);
+       xsltSetSecurityPrefs(sec_prefs,  XSLT_SECPREF_WRITE_NETWORK, xsltSecurityForbid);
+       xsltSetSecurityPrefs(sec_prefs,  XSLT_SECPREF_READ_NETWORK, xsltSecurityForbid);
+       xsltSetDefaultSecurityPrefs(sec_prefs);
+#endif
+
+       ret = xmlSecInit();
+       if (ret < 0) {
+               _LOGE("xmlsec initialization failed [%d]\n", ret);
+               goto end;
+       }
+       ret = xmlSecCheckVersion();
+       if (ret != 1) {
+               _LOGE("Incompatible version of loaded xmlsec library [%d]\n", ret);
+               goto end;
+       }
+#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
+       ret = xmlSecCryptoDLLoadLibrary(BAD_CAST "openssl");
+       if (ret < 0) {
+               _LOGE("unable to load openssl library [%d]\n", ret);
+               goto end;
+       }
+#endif
+
+       ret = xmlSecCryptoAppInit(NULL);
+       if (ret < 0) {
+               _LOGE("crypto initialization failed [%d]\n", ret);
+               goto end;
+       }
+       ret = xmlSecCryptoInit();
+       if (ret < 0) {
+               _LOGE("xmlsec-crypto initialization failed [%d]\n", ret);
+               goto end;
+       }
+
+       sec_key_mngr = __ri_load_trusted_certs(rootca, 1);
+       if (sec_key_mngr == NULL) {
+               _LOGE("loading of trusted certs failed\n");
+               ret = -1;
+               goto end;
+       }
+
+       if (__ri_verify_file(sec_key_mngr, sigxmlfile) < 0) {
+               ret = -1;
+       }
+
+end:
+       if (sec_key_mngr)
+               xmlSecKeysMngrDestroy(sec_key_mngr);
+       xmlSecCryptoShutdown();
+       xmlSecCryptoAppShutdown();
+       xmlSecShutdown();
+#ifndef XMLSEC_NO_XSLT
+       xsltFreeSecurityPrefs(sec_prefs);
+       xsltCleanupGlobals();
+#endif
+       return ret;
+}
+
+int _rpm_installer_get_group_id(char *pkgid, char **result)
+{
+       int ret = 0;
+       const char *value = NULL;
+       char author_signature[BUF_SIZE] = {'\0'};
+       char *e_rootcert = NULL;
+       char *d_rootcert = NULL;
+       gsize d_size = 0;
+       unsigned char hashout[BUF_SIZE] = {'\0'};
+       unsigned int h_size = 0;
+       int e_size = 0;
+       int length = 0;
+       pkgmgrinfo_certinfo_h handle = NULL;
+
+       snprintf(author_signature, BUF_SIZE, "%s/%s/%s", USR_APPS, pkgid, AUTHOR_SIGNATURE_XML);
+       if (access(author_signature, F_OK) != 0) {
+               _LOGE("[%s] isn't existed.", author_signature);
+               return -1;
+       }
+
+       ret = pkgmgrinfo_pkginfo_create_certinfo(&handle);
+       if (ret < 0) {
+               _LOGE("pkgmgrinfo_pkginfo_create_certinfo(%s) failed.", pkgid);
+               goto err;
+       }
+
+       ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle);
+       if (ret < 0) {
+               _LOGE("pkgmgrinfo_pkginfo_load_certinfo(%s) failed.", pkgid);
+               goto err;
+       }
+
+       // get root certificate
+       ret = pkgmgrinfo_pkginfo_get_cert_value(handle, PMINFO_AUTHOR_SIGNER_CERT, &value);
+       if (ret < 0 || value == NULL) {
+               _LOGE("pkgmgrinfo_pkginfo_get_cert_value(%s) failed. [%d]", pkgid, ret);
+               goto err;
+       }
+
+       // decode cert
+       d_rootcert = (char *)g_base64_decode(value, &d_size);
+       if (d_rootcert == NULL) {
+               _LOGE("g_base64_decode() failed.");
+               goto err;
+       }
+       _LOGD("g_base64_decode() succeed, d_size=[%d]", d_size);
+
+       // hash
+       EVP_Digest(d_rootcert, d_size, hashout, &h_size, EVP_sha1(), NULL);
+       if (h_size <= 0) {
+               _LOGE("EVP_Digest(hash) failed.");
+               goto err;
+       }
+       _LOGD("EVP_Digest() succeed, h_size=[%d]", h_size);
+
+       // encode cert
+       e_rootcert = g_base64_encode((const guchar *)hashout, h_size);
+       if (e_rootcert == NULL) {
+               _LOGE("g_base64_encode() failed.");
+               goto err;
+       }
+       e_size = strlen(e_rootcert);
+       _LOGD("g_base64_encode() succeed, e_size=[%d]", e_size);
+
+       // replace / to #
+       for (length = e_size; length >= 0; --length) {
+               if (e_rootcert[length] == '/') {
+                       e_rootcert[length] = '#';
+               }
+       }
+
+       *result = e_rootcert;
+
+err:
+       if (d_rootcert) {
+               free(d_rootcert);
+       }
+
+       // destroy cert
+       if (handle) {
+               pkgmgrinfo_pkginfo_destroy_certinfo(handle);
+       }
+
+       return ret;
+}
+
+void __rpm_apply_smack(char *pkgname, int flag)
+{
+#if 0
+       int ret = -1;
+       char dirpath[BUF_SIZE] = {'\0'};
+       char* groupid = NULL;
+       char *shared_data_label = NULL;
+
+       /*execute privilege APIs. The APIs should not fail*/
+       _ri_privilege_register_package(pkgname);
+
+       /*home dir. Dont setup path but change smack access to "_" */
+       snprintf(dirpath, BUF_SIZE, "%s/%s", USR_APPS, pkgname);
+       if (__is_dir(dirpath))
+               _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgname);
+       if (__is_dir(dirpath))
+               _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+
+       // data
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s/data", OPT_USR_APPS, pkgname);
+       if (__is_dir(dirpath))
+               _ri_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+
+       // cache
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s/cache", OPT_USR_APPS, pkgname);
+       if (!__is_dir(dirpath)) {
+               ret = mkdir(dirpath, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("directory making is failed.\n");
+               }
+       }
+       ret = chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+       if(ret != 0){
+               _LOGE("chown failed!! [%s]",strerror(errno));
+       }
+       _ri_privilege_setup_path(pkgname, dirpath, APP_PATH_PRIVATE, pkgname);
+
+       //shared
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared", USR_APPS, pkgname);
+       if (__is_dir(dirpath))
+               _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared", OPT_USR_APPS, pkgname);
+       if (!__is_dir(dirpath))
+               ret = mkdir(dirpath, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("directory making is failed.\n");
+               }
+       _ri_privilege_change_smack_label(dirpath, "_", 0);/*0 is SMACK_LABEL_ACCESS*/
+       memset(dirpath, '\0', BUF_SIZE);
+
+       //shared/res
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/res", USR_APPS, pkgname);
+       if (__is_dir(dirpath))
+               _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/res", OPT_USR_APPS, pkgname);
+       if (__is_dir(dirpath))
+               _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_ANY_LABEL, "_");
+       memset(dirpath, '\0', BUF_SIZE);
+
+       //shared/data
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/data", USR_APPS, pkgname);
+       if (__is_dir(dirpath)) {
+               ret = chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+               if(ret != 0){
+                       _LOGE("chown failed!! [%s]",strerror(errno));
+               }
+               _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_PUBLIC, NULL);
+       }
+       memset(dirpath, '\0', BUF_SIZE);
+
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/data", OPT_USR_APPS, pkgname);
+       if (__is_dir(dirpath)) {
+               ret = chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+               if(ret != 0){
+                       _LOGE("chown failed!! [%s]",strerror(errno));
+               }
+               _ri_privilege_setup_path(pkgname, dirpath, PERM_APP_PATH_PUBLIC, NULL);
+       }
+
+       // shared/cache
+       ret = _coretpk_installer_get_smack_label_access(dirpath, &shared_data_label);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", dirpath, ret);
+       }
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/cache", OPT_USR_APPS, pkgname);
+       if (!__is_dir(dirpath)) {
+               ret = mkdir(dirpath, DIRECTORY_PERMISSION_755);
+               if (ret < 0) {
+                       _LOGE("directory making is failed.\n");
+               }
+       }
+       ret = chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+       if(ret != 0){
+               _LOGE("chown failed!! [%s]",strerror(errno));
+       }
+       ret  = _coretpk_installer_set_smack_label_access(dirpath, shared_data_label);
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", dirpath, ret);
+       }
+       ret = _coretpk_installer_set_smack_label_transmute(dirpath, "1");
+       if (ret != 0) {
+               _LOGE("_coretpk_installer_apply_directory_policy() failed, appdir=[%s], ret=[%d]", dirpath, ret);
+       }
+
+       /*/shared/trusted/*/
+       memset(dirpath, '\0', BUF_SIZE);
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/trusted", USR_APPS, pkgname);
+       if (__is_dir(dirpath)) {
+               ret = chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+               if(ret != 0){
+                       _LOGE("chown failed!! [%s]",strerror(errno));
+               }
+
+               ret = _rpm_installer_get_group_id(pkgname, &groupid);
+               if (ret == 0) {
+                       _LOGD("group id for trusted directory is [%s]", groupid);
+                       _ri_privilege_setup_path(pkgname, dirpath, APP_PATH_GROUP_RW, groupid);
+                       FREE_AND_NULL(groupid);
+               }
+       }
+       memset(dirpath, '\0', BUF_SIZE);
+
+       snprintf(dirpath, BUF_SIZE, "%s/%s/shared/trusted", OPT_USR_APPS, pkgname);
+
+       _LOGD("dirpath [%s]", dirpath);
+
+       ret = _rpm_installer_get_group_id(pkgname, &groupid);
+       if (ret == 0) {
+               if (__is_dir(dirpath) != 1) {
+                       _LOGE("dont have [%s]", dirpath);
+
+                       ret = mkdir(dirpath, DIRECTORY_PERMISSION_755);
+                       if (ret == -1 && errno != EEXIST) {
+                               _LOGE("mkdir failed!! [%s]",strerror(errno));
+                       }
+               }
+
+               ret = chown(dirpath, APP_OWNER_ID, APP_GROUP_ID);
+               if(ret != 0){
+                       _LOGE("chown failed!! [%s]",strerror(errno));
+               }
+
+               _LOGD("group id for trusted directory is [%s]", groupid);
+               _ri_privilege_setup_path(pkgname, dirpath, APP_PATH_GROUP_RW, groupid);
+               _ri_set_group_id(pkgname, groupid);
+
+               FREE_AND_NULL(groupid);
+       }
+#endif
+}
+
+int __is_dir(char *dirname)
+{
+       struct stat stFileInfo;
+       if(dirname == NULL) {
+               _LOGE("dirname is null\n");
+               return -1;
+       }
+
+       (void)stat(dirname, &stFileInfo);
+
+       if (S_ISDIR(stFileInfo.st_mode)) {
+               return 1;
+       }
+       return 0;
+}
 
 static void __rpm_process_line(char *line)
 {
@@ -78,9 +788,10 @@ static void __rpm_process_line(char *line)
                if (!strncmp(tok, "%%", 2)) {
                        tok = strtok(NULL, " ");
                        if (tok) {
-                               _d_msg(DEBUG_INFO, "Install percentage is %s\n",
+                               _LOGD("Install percentage is %s\n",
                                       tok);
                                _ri_broadcast_status_notification(gpkgname,
+                                                                 "rpm",
                                                                  "install_percent",
                                                                  tok);
                                _ri_stat_cb(gpkgname, "install_percent", tok);
@@ -96,7 +807,7 @@ static void __rpm_perform_read(int fd)
        char *buf_ptr = NULL;
        char *tmp_ptr = NULL;
        int size = 0;
-       static char buffer[1024] = { 0, };
+       static char buffer[BUF_SIZE] = { 0, };
        static int buffer_position;
 
        size = read(fd, &buffer[buffer_position],
@@ -130,15 +841,18 @@ static void __rpm_perform_read(int fd)
        buffer_position = buffer + buffer_position - buf_ptr;
 }
 
-static int __rpm_xsystem(const char *argv[])
+
+int _rpm_xsystem(const char *argv[])
 {
        int err = 0;
        int status = 0;
        pid_t pid;
        int pipefd[2];
+       int result = 0;
+       int fd = 0;
 
        if (pipe(pipefd) == -1) {
-               _d_msg(DEBUG_ERR, "pipe creation failed\n");
+               _LOGE("pipe creation failed\n");
                return -1;
        }
        /*Read progress info via pipe */
@@ -146,7 +860,7 @@ static int __rpm_xsystem(const char *argv[])
 
        switch (pid) {
        case -1:
-               _d_msg(DEBUG_ERR, "fork failed\n");
+               _LOGE("fork failed\n");
                return -1;
        case 0:
                /* child */
@@ -154,10 +868,20 @@ static int __rpm_xsystem(const char *argv[])
                        close(pipefd[0]);
                        close(1);
                        close(2);
-                       dup(pipefd[1]);
-                       dup(pipefd[1]);
+                       fd = dup(pipefd[1]);
+                       if (fd < 0) {
+                               _LOGE("dup failed\n");
+                               _exit(100);
+                       }
+
+                       result = dup(pipefd[1]);
+                       if (result < 0) {
+                               _LOGE("dup failed\n");
+                               _exit(100);
+                       }
+
                        if (execvp(argv[0], (char *const *)argv) == -1) {
-                               _d_msg(DEBUG_ERR, "execvp failed\n");
+                               _LOGE("execvp failed\n");
                        }
                        _exit(100);
                }
@@ -172,7 +896,7 @@ static int __rpm_xsystem(const char *argv[])
                if (err < 0) {
                        if (errno == EINTR)
                                continue;
-                       _d_msg(DEBUG_ERR, "waitpid failed\n");
+                       _LOGE("waitpid failed\n");
                        close(pipefd[0]);
                        return -1;
                }
@@ -192,7 +916,7 @@ static int __rpm_xsystem(const char *argv[])
                else if (select_ret < 0 && errno == EINTR)
                        continue;
                else if (select_ret < 0) {
-                       _d_msg(DEBUG_ERR, "select() returned error\n");
+                       _LOGE("select() returned error\n");
                        continue;
                }
                if (FD_ISSET(pipefd[0], &rfds))
@@ -217,7 +941,7 @@ static int __rpm_xsystem(const char *argv[])
        return WEXITSTATUS(status);
 }
 
-static void __rpm_clear_dir_list(GList* dir_list)
+void __rpm_clear_dir_list(GList* dir_list)
 {
        GList *list = NULL;
        app2ext_dir_details* dir_detail = NULL;
@@ -228,13 +952,14 @@ static void __rpm_clear_dir_list(GList* dir_list)
                        if (dir_detail && dir_detail->name) {
                                free(dir_detail->name);
                        }
+                       g_free(list->data);
                        list = g_list_next(list);
                }
                g_list_free(dir_list);
        }
 }
 
-static GList * __rpm_populate_dir_list()
+GList * __rpm_populate_dir_list()
 {
        GList *dir_list = NULL;
        GList *list = NULL;
@@ -275,6 +1000,7 @@ FINISH_OFF:
                        if (dir_detail && dir_detail->name) {
                                free(dir_detail->name);
                        }
+                       g_free(list->data);
                        list = g_list_next(list);
                }
                g_list_free(dir_list);
@@ -282,474 +1008,2593 @@ FINISH_OFF:
        return NULL;
 }
 
-static GList * __rpm_move_dir_list()
+static char *__ri_get_cert_from_file(const char *file)
 {
-       GList *dir_list = NULL;
-       GList *list = NULL;
-       app2ext_dir_details* dir_detail = NULL;
-       int i;
-       char pkg_ro_content_rpm[3][5] = { "bin", "res", };
+       FILE *fp_cert = NULL;
+       int certlen = 0;
+       char *certbuf = NULL;
+       char *startcert = NULL;
+       char *endcert = NULL;
+       int certwrite = 0;
+       char *cert = NULL;
+       int i = 0;
+       int ch = 0;
+       int error = 0;
 
+       if(!(fp_cert = fopen(file, "r"))) {
+               _LOGE("[ERR][%s] Fail to open file, [%s]\n", __func__, file);
+               return NULL;
+       }
 
-       for (i=0; i<3; i++) {
-               dir_detail = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details));
-               if (dir_detail == NULL) {
-                       printf("\nMemory allocation failed\n");
-                       goto FINISH_OFF;
-               }
-               dir_detail->name = (char*) calloc(1, sizeof(char)*(strlen(pkg_ro_content_rpm[i])+2));
-               if (dir_detail->name == NULL) {
-                       printf("\nMemory allocation failed\n");
-                       free(dir_detail);
-                       goto FINISH_OFF;
-               }
-               snprintf(dir_detail->name, (strlen(pkg_ro_content_rpm[i])+1), "%s", pkg_ro_content_rpm[i]);
-               dir_detail->type = APP2EXT_DIR_RO;
-               dir_list = g_list_append(dir_list, dir_detail);
+       fseek(fp_cert, 0L, SEEK_END);
+
+       if(ftell(fp_cert) < 0) {
+               _LOGE("[ERR][%s] Fail to find EOF\n", __func__);
+               error = 1;
+               goto err;
        }
-       if (dir_list) {
-               list = g_list_first(dir_list);
-               while (list) {
-                       dir_detail = (app2ext_dir_details *)list->data;
-                       list = g_list_next(list);
-               }
+
+       certlen = ftell(fp_cert);
+       fseek(fp_cert, 0L, SEEK_SET);
+
+       if(!(certbuf = (char*)malloc(sizeof(char) * (int)certlen))) {
+               _LOGE("[ERR][%s] Fail to allocate memory\n", __func__);
+               error = 1;
+               goto err;
        }
-       return dir_list;
-FINISH_OFF:
-       if (dir_list) {
-               list = g_list_first(dir_list);
-               while (list) {
-                       dir_detail = (app2ext_dir_details *)list->data;
-                       if (dir_detail && dir_detail->name) {
-                               free(dir_detail->name);
-                       }
-                       list = g_list_next(list);
+       memset(certbuf, 0x00, (int)certlen);
+
+       i = 0;
+       while((ch = fgetc(fp_cert)) != EOF) {
+               if(ch != '\n') {
+                       certbuf[i] = ch;
+                       i++;
                }
-               g_list_free(dir_list);
        }
-       return NULL;
+       certbuf[i] = '\0';
+
+       startcert = strstr(certbuf, "-----BEGIN CERTIFICATE-----") + strlen("-----BEGIN CERTIFICATE-----");
+       endcert = strstr(certbuf, "-----END CERTIFICATE-----");
+       certwrite = (int)endcert - (int)startcert;
+
+       cert = (char*)malloc(sizeof(char) * (certwrite+2));
+       if (cert == NULL) {
+               _LOGE("[ERR][%s] Fail to allocate memory\n", __func__);
+               error = 1;
+               goto err;
+       }
+       memset(cert, 0x00, certwrite+2);
+       snprintf(cert, certwrite+1, "%s", startcert);
+       _LOGD("Root CA, len=[%d]\n%s", certwrite, cert);
+
+err:
+       if (certbuf)
+               free(certbuf);
+       fclose(fp_cert);
+       if (error)
+               return NULL;
+       else
+               return cert;
 }
 
-int _rpm_uninstall_pkg(char *pkgid)
+static int __privilege_func(const char *name, void *user_data)
 {
+#if 0
        int ret = 0;
-       int err = 0;
-       char buff[256] = {'\0'};
-       pkgmgr_install_location location = 1;
-       int size = -1;
-#ifdef APP2EXT_ENABLE
-       app2ext_handle *handle = NULL;
-#endif
-       char *manifest = NULL;
-       pkgmgr_pkginfo_h pkghandle;
-       const char *argv[] = { UNINSTALL_SCRIPT, pkgid, NULL };
+       const char *perm[] = {NULL, NULL};
+       perm[0] = name;
+       int apptype = PERM_APP_TYPE_EFL;
+       privilegeinfo *info = (privilegeinfo*)user_data;
 
-#ifdef APP2EXT_ENABLE
-       ret = pkgmgr_pkginfo_get_pkginfo(pkgid, &pkghandle);
-       if (ret < 0) {
-               _d_msg(DEBUG_ERR, "Failed to get pkginfo handle\n");
-//             return RPM_INSTALLER_ERR_INTERNAL;
-       } else {
-               ret = pkgmgr_pkginfo_get_install_location(pkghandle, &location);
-               if (ret < 0) {
-                       _d_msg(DEBUG_ERR, "Failed to get install location\n");
-                       pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
-                       return RPM_INSTALLER_ERR_INTERNAL;
-               }
-               pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
-               if (location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) {
-                       handle = app2ext_init(APP2EXT_SD_CARD);
-                       if (handle == NULL) {
-                               _d_msg(DEBUG_ERR, "app2ext init failed\n");
-                               return RPM_INSTALLER_ERR_INTERNAL;
-                       }
-                       if ((&(handle->interface) != NULL) && (handle->interface.pre_uninstall != NULL) && (handle->interface.post_uninstall != NULL)){
-                               ret = app2ext_get_app_location(pkgid);
-                               if (ret == APP2EXT_INTERNAL_MEM){
-                                               _d_msg(DEBUG_ERR, "app2xt APP is not in MMC, go internal (%d)\n", ret);
-                               }
-                               else {
-                                       ret = handle->interface.pre_uninstall(pkgid);
-                                       if (ret == APP2EXT_ERROR_MMC_STATUS || ret == APP2EXT_SUCCESS ) {
-                                               _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal (%d)\n", ret);
-                                       }
-                                       else {
-                                               _d_msg(DEBUG_ERR, "app2xt pre uninstall API failed (%d)\n", ret);
-                                               handle->interface.post_uninstall(pkgid);
-                                               return RPM_INSTALLER_ERR_INTERNAL;
-                                       }
-                               }
-                       }
-               }
+       _LOGD("package_id = [%s], privilege = [%s]", info->package_id, name);
+       privilege_list = g_list_append(privilege_list, strdup((char*)name));
+
+       if (info->visibility & CERT_SVC_VISIBILITY_PLATFORM) {
+               _LOGD("VISIBILITY_PLATFORM!");
+               apptype = PERM_APP_TYPE_EFL_PLATFORM;
+       } else if ((info->visibility & CERT_SVC_VISIBILITY_PARTNER) ||
+                       (info->visibility & CERT_SVC_VISIBILITY_PARTNER_OPERATOR) ||
+                       (info->visibility & CERT_SVC_VISIBILITY_PARTNER_MANUFACTURER)) {
+               _LOGD("VISIBILITY_PARTNER!");
+               apptype = PERM_APP_TYPE_EFL_PARTNER;
        }
-#endif
 
-#ifdef PRE_CHECK_FOR_MANIFEST
-       /*Manifest info should be removed first because after installation manifest
-       file is uninstalled. If uninstallation fails, we need to re-insert manifest info for consistency*/
-       manifest = pkgmgr_parser_get_manifest_file(pkgid);
-       if (manifest == NULL) {
-               _d_msg(DEBUG_ERR, "manifest name is NULL\n");
-               return RPM_INSTALLER_ERR_INTERNAL;
+       ret = _ri_privilege_enable_permissions((char *)info->package_id, apptype, perm, 1);
+       if(ret < 0) {
+               _LOGE("_ri_privilege_enable_permissions(%s, %d) failed.", (char *)info->package_id, apptype);
+               return -1;
        }
-       _d_msg(DEBUG_INFO, "manifest name is %s\n", manifest);
-       pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
-#endif
 
-       ret = __rpm_xsystem(argv);
-       if (ret != 0) {
-               _d_msg(DEBUG_ERR, "uninstall failed with error(%d)\n", ret);
-               #ifdef PRE_CHECK_FOR_MANIFEST
-               err = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
-               if (err < 0) {
-                       _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
-               }
-               if (manifest) {
-                       free(manifest);
-                       manifest = NULL;
-               }
-               #endif
-               #ifdef APP2EXT_ENABLE
-               if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
-                       handle->interface.post_uninstall(pkgid);
+       if (strcmp(name, EXT_APPDATA_PRIVILEGE_NAME) == 0) {
+               _LOGD("it is EXT_APPDATA_PRIVILEGE_NAME");
+               if(_coretpk_installer_make_directory_for_ext((char *)info->package_id) < 0) {
+                       _LOGE("make_directory_for_ext failed.");
                }
-               #endif
-               return ret;
        }
 
-#ifdef APP2EXT_ENABLE
-       if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
-               handle->interface.post_uninstall(pkgid);
-               app2ext_deinit(handle);
-       }
+       _LOGD("_ri_privilege_enable_permissions(%s, %d) succeed.", (char *)info->package_id, apptype);
+       return ret;
 #endif
+       return 0;
+}
 
-#ifdef PRE_CHECK_FOR_MANIFEST
-       if (manifest) {
-               free(manifest);
-               manifest = NULL;
-       }
-#endif
-       /* Uninstallation Success. Remove the installation time key from vconf*/
-       snprintf(buff, 256, "db/app-info/%s/installed-time", pkgid);
-       err = vconf_unset(buff);
-       if (err) {
-               _d_msg(DEBUG_ERR, "unset installation time failed\n");
+char *__strlwr(char *str)
+{
+       int i = 0;
+
+       while(*(str+i) != '\0'){
+               if(*(str+i) >= 65 || *(str+i)<= 90) {
+                       *(str+i) = towlower(*(str+i));
+               }
+               i++;
        }
-       return ret;
+       return str;
 }
 
-int _rpm_install_pkg(char *pkgfilepath, char *installoptions)
+static int __ri_find_xml(char *pkgid, char **rpm_xml)
 {
-       int err = 0;
+       DIR *dir;
+       struct dirent entry, *result;
        int ret = 0;
-       time_t cur_time;
-       char buff[256] = {'\0'};
-       char manifest[1024] = { '\0'};
-       char *mfst = NULL;
-       pkgmgrinfo_install_location location = 1;
-       int size = -1;
-#ifdef APP2EXT_ENABLE
-       app2ext_handle *handle = NULL;
-       GList *dir_list = NULL;
-#endif
-       pkgmgr_pkginfo_h pkghandle;
-       const char *argv[] = {
-               INSTALL_SCRIPT, pkgfilepath, installoptions, NULL
-       };
+       char buf[BUF_SIZE];
 
-#ifdef PRE_CHECK_FOR_MANIFEST
-       char cwd[1024] = {'\0'};
-       char query[1024] = {'\0'};
-       int m_exist = 0;
-       getcwd(cwd, 1024);
-       if (cwd[0] == '\0') {
-               _d_msg(DEBUG_ERR, "getcwd() Failed\n");
-               return RPM_INSTALLER_ERR_INTERNAL;
+       dir = opendir(USR_SHARE_PACKAGES);
+       if (!dir) {
+               if (strerror_r(errno, buf, sizeof(buf)) == 0)
+                       _LOGE("fota-info : Failed to access the [%s] because %s", USR_SHARE_PACKAGES, buf);
+               return -1;
        }
-       _d_msg(DEBUG_ERR, "Current working directory is %s\n", cwd);
-       err = chdir("/tmp");
-       if (err != 0) {
-               _d_msg(DEBUG_ERR, "chdir() failed\n");
-               return RPM_INSTALLER_ERR_INTERNAL;
+
+       for (ret = readdir_r(dir, &entry, &result);
+                       ret == 0 && result != NULL;
+                       ret = readdir_r(dir, &entry, &result)) {
+               char *manifest = NULL;
+
+               if (entry.d_name[0] == '.') continue;
+
+               manifest = _manifest_to_package(entry.d_name);
+               if (!manifest) {
+                       _LOGE("fota-info : Failed to convert file to xml[%s]", entry.d_name);
+                       continue;
+               }
+
+               if (strstr(manifest, __strlwr(pkgid))) {
+                       snprintf(buf, sizeof(buf), "%s/%s", USR_SHARE_PACKAGES, manifest);
+                       _LOGD("fota-info : pkgid[%s] find xml[%s]\n", pkgid, buf);
+                       *rpm_xml = strdup(buf);
+                       closedir(dir);
+                       free(manifest);
+                       return 0;
+               }
+
+               free(manifest);
        }
-       _d_msg(DEBUG_ERR, "Switched to /tmp\n");
-       snprintf(query, 1024, "/usr/bin/rpm2cpio %s | cpio -idmv", pkgfilepath);
-       _d_msg(DEBUG_INFO, "query= %s\n", query);
-       system(query);
-       snprintf(manifest, 1024, "/tmp/opt/share/packages/%s.xml", gpkgname);
-       _d_msg(DEBUG_ERR, "Manifest name is %s\n", manifest);
-       if (access(manifest, F_OK)) {
-               _d_msg(DEBUG_ERR, "No rw Manifest File Found\n");
 
-               snprintf(manifest, 1024, "/tmp/usr/share/packages/%s.xml", gpkgname);
-               _d_msg(DEBUG_ERR, "Manifest ro name is %s\n", manifest);
+       _LOGE("fota-info : Failed to find xml for pkgid[%s]", pkgid);
+       closedir(dir);
+       return 0;
+}
 
-               if (access(manifest, F_OK)) {
-                       _d_msg(DEBUG_ERR, "No ro Manifest File Found\n");
-//                     unlink(manifest);
-//                     return RPM_INSTALLER_ERR_NO_MANIFEST;
-               } else
-                       m_exist = 1;
-       } else
-               m_exist = 1;
+static int __ri_install_fota(char *pkgid)
+{
+       int ret = 0;
+       char *manifest = NULL;
+       char *temp[] = {"fota=true", NULL};
 
-       _d_msg(DEBUG_ERR, "Manifest exists\n");
+       _LOGD("fota-info : pkgid[%s] start installation\n", pkgid);
 
-       err = chdir(cwd);
-       if (err != 0) {
-               _d_msg(DEBUG_ERR, "chdir() failed\n");
-//             unlink(manifest);
-//             return RPM_INSTALLER_ERR_INTERNAL;
+       /*if pkgid is one of deactivation, it does not need to install*/
+       ret = __ri_check_pkgid_for_deactivation(pkgid);
+       if (ret < 0) {
+               _LOGE("fota-info : pkgid[%s] for deactivation dont need to install.\n", pkgid);
+               return ret;
        }
 
-       if (m_exist) {
-               err = pkgmgr_parser_check_manifest_validation(manifest);
-               if(err < 0) {
-                       _d_msg(DEBUG_ERR, "Invalid manifest\n");
-                       unlink(manifest);
-                       return RPM_INSTALLER_ERR_INVALID_MANIFEST;
-               }
+       /*get manifest*/
+       manifest = pkgmgr_parser_get_manifest_file(pkgid);
+       if (manifest == NULL) {
+               _LOGE("fota-info : dont have manefest[pkgid=%s]\n", pkgid);
+               ret = -1;
+               goto end;
        }
-#endif
+       _LOGD("fota-info : pkgid[%s] has manefest[%s]\n", pkgid, manifest);
 
-#ifdef APP2EXT_ENABLE
-       ret = pkgmgrinfo_pkginfo_get_location_from_xml(manifest, &location);
+       ret = pkgmgr_parser_parse_manifest_for_installation(manifest, temp);
+       if (ret < 0) {
+               _LOGE("fota-info : installation fail[manifest=%s]\n", manifest);
+               ret = -1;
+               goto end;
+       }
+       _LOGD("fota-info : pkgid[%s] installation success\n", pkgid);
 
+       __rpm_apply_smack(pkgid,0);
+       __ri_make_directory(pkgid);
+
+       ret = _ri_apply_privilege(pkgid, 0);
        if (ret < 0) {
-               _d_msg(DEBUG_ERR, "Failed to get install location\n");
-               return RPM_INSTALLER_ERR_INTERNAL;
-       } else {
-               if (location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) {
-                       ret = pkgmgrinfo_pkginfo_get_size_from_xml(manifest, &size);
-                       if (ret < 0) {
-                               _d_msg(DEBUG_ERR, "Failed to get package size\n");
-                               return RPM_INSTALLER_ERR_INTERNAL;
-                       }
-               }
+               _LOGE("fota-info : _ri_apply_privilege fail[pkgid=%s]\n", pkgid);
+               ret = -1;
+               goto end;
        }
+       _LOGD("fota-info : pkgid[%s] apply smack success\n", pkgid);
 
-       if ((location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) {
-               handle = app2ext_init(APP2EXT_SD_CARD);
-               if (handle == NULL) {
-                       _d_msg(DEBUG_ERR, "app2ext init failed\n");
-                       return RPM_INSTALLER_ERR_INTERNAL;
-               }
-               if ((&(handle->interface) != NULL) && (handle->interface.pre_install != NULL) && (handle->interface.post_install != NULL)){
-                       dir_list = __rpm_populate_dir_list();
-                       if (dir_list == NULL) {
-                               _d_msg(DEBUG_ERR, "\nError in populating the directory list\n");
-                               app2ext_deinit(handle);
-                               return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
-                       }
-                       ret = handle->interface.pre_install(gpkgname, dir_list, size);
-                       if (ret == APP2EXT_ERROR_MMC_STATUS) {
-                               _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal\n");
-                       } else if (ret == APP2EXT_SUCCESS){
-                               _d_msg(DEBUG_ERR, "pre_install done, go internal\n");
-                       }
-                       else {
-                               _d_msg(DEBUG_ERR, "app2xt pre install API failed (%d)\n", ret);
-                               __rpm_clear_dir_list(dir_list);
-                               handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED);
-                               app2ext_deinit(handle);
-                               return RPM_INSTALLER_ERR_INTERNAL;
-                       }
-               }
+end:
+       if (manifest){
+               free(manifest);
+               manifest = NULL;
        }
-#endif
 
-       err = __rpm_xsystem(argv);
+       return ret;
+}
 
-       if (err != 0) {
-               _d_msg(DEBUG_ERR, "install complete with error(%d)\n", err);
+static int __ri_upgrade_fota(char *pkgid)
+{
+       _LOGD("fota-info : pkgid[%s] start upgrade\n", pkgid);
 
-               #ifdef APP2EXT_ENABLE
-               if ((handle != NULL) && (handle->interface.post_install != NULL)){
-                       __rpm_clear_dir_list(dir_list);
-                       handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED);
-               }
-               #endif
+       int ret = 0;
+       char *manifest = NULL;
+       char *temp[] = {"fota=true", NULL};
 
-               return err;
+       /*if pkgid is one of deactivation, it does not need to upgrade*/
+       ret = __ri_check_pkgid_for_deactivation(pkgid);
+       if (ret < 0) {
+               _LOGE("fota-info : pkgid[%s] for deactivation dont need to install.\n", pkgid);
+               return ret;
        }
 
-#ifdef APP2EXT_ENABLE
-       if ((handle != NULL) && (handle->interface.post_install != NULL)){
-               __rpm_clear_dir_list(dir_list);
-               handle->interface.post_install(gpkgname, APP2EXT_STATUS_SUCCESS);
-               app2ext_deinit(handle);
+       /*get manifest*/
+       manifest = pkgmgr_parser_get_manifest_file(pkgid);
+       if (manifest == NULL) {
+               _LOGE("fota-info : dont have manefest[pkgid=%s]\n", pkgid);
+               ret = -1;
+               goto end;
        }
-#endif
+       _LOGD("fota-info : pkgid[%s] has manefest[%s]\n", pkgid, manifest);
+       if (access(manifest, F_OK) != 0) {
+               _LOGE("fota-info : can not access[manifest=%s]\n", manifest);
+               free(manifest);
+               manifest = NULL;
 
-       /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/
-       err = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
-       if (err < 0) {
-               _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
-//             unlink(manifest);
-//             return RPM_INSTALLER_ERR_INTERNAL;
-       } else {
-               _d_msg(DEBUG_ERR, "Parsing Manifest Success\n");
-               return err;
+               /*find xml*/
+               ret = __ri_find_xml(pkgid, &manifest);
+               if (ret < 0) {
+                       _LOGE("fota-info : can not find xml[pkgid=%s]\n", pkgid);
+                       ret = -1;
+                       goto end;
+               }
        }
 
-#ifndef PRE_CHECK_FOR_MANIFEST
-       mfst = pkgmgr_parser_get_manifest_file(gpkgname);
-       if (mfst == NULL) {
-               _d_msg(DEBUG_ERR, "manifest name is NULL\n");
-               unlink(manifest);
-               return RPM_INSTALLER_ERR_INTERNAL;
+       if (manifest == NULL) {
+               return -1;
        }
-       pkgmgr_parser_parse_manifest_for_installation(mfst, NULL);
-       if (mfst) {
-               free(mfst);
-               mfst = NULL;
+
+       ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, temp);
+       if (ret < 0) {
+               _LOGE("fota-info : upgrade fail[manifest=%s]\n", manifest);
+               ret = -1;
+               goto end;
        }
-#endif
-       /* Install Success. Store the installation time*/
-       cur_time = time(NULL);
-       snprintf(buff, 256, "db/app-info/%s/installed-time", gpkgname);
-       /* The time is stored in time_t format. It can be converted to
-       local time or GMT time as per the need by the apps*/
-       ret = vconf_set_int(buff, cur_time);
-       if(ret) {
-               _d_msg(DEBUG_ERR, "setting installation time failed\n");
-               vconf_unset(buff);
+
+       __rpm_apply_smack(pkgid,0);
+       __ri_make_directory(pkgid);
+
+       ret = _ri_apply_privilege(pkgid, 0);
+       if (ret < 0) {
+               _LOGE("fota-info : _ri_apply_privilege fail[pkgid=%s]\n", pkgid);
        }
-       unlink(manifest);
-       return err;
+
+       _LOGD("fota-info : pkgid[%s] upgrade success\n", pkgid);
+
+end:
+       if (manifest)
+               free(manifest);
+
+       return ret;
 }
 
-int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions)
+static int __ri_uninstall_fota(char *pkgid)
 {
-       int err = 0;
+       _LOGD("fota-info : pkgid[%s] start uninstallation\n", pkgid);
+
        int ret = 0;
-       time_t cur_time;
-       char buff[256] = {'\0'};
-       char manifest[1024] = { '\0'};
-       char *mfst = NULL;
-       pkgmgr_install_location location = 1;
-       int size = -1;
-#ifdef APP2EXT_ENABLE
-       app2ext_handle *handle = NULL;
-       GList *dir_list = NULL;
-#endif
-       pkgmgr_pkginfo_h pkghandle;
-       const char *argv[] = {
-               UPGRADE_SCRIPT, pkgfilepath, installoptions, NULL
-       };
 
-#ifdef PRE_CHECK_FOR_MANIFEST
-       char cwd[1024] = {'\0'};
-       char query[1024] = {'\0'};
-       int m_exist = 0;
-       getcwd(cwd, 1024);
-       if (cwd[0] == '\0') {
-               _d_msg(DEBUG_ERR, "getcwd() Failed\n");
-               return RPM_INSTALLER_ERR_INTERNAL;
+       ret = _ri_privilege_unregister_package(pkgid);
+       if (ret < 0) {
+               _LOGE("fota-info : _ri_privilege_unregister_package fail[pkgid=%s]\n", pkgid);
        }
-       _d_msg(DEBUG_ERR, "Current working directory is %s\n", cwd);
-       err = chdir("/tmp");
-       if (err != 0) {
-               _d_msg(DEBUG_ERR, "chdir() failed\n");
-               return RPM_INSTALLER_ERR_INTERNAL;
+
+       ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+       if (ret < 0) {
+               _LOGE("fota-info : uninstall fail[manifest=%s]\n", pkgid);
        }
-       _d_msg(DEBUG_ERR, "Switched to /tmp\n");
-       snprintf(query, 1024, "/usr/bin/rpm2cpio %s | cpio -idmv", pkgfilepath);
-       _d_msg(DEBUG_INFO, "query= %s\n", query);
-       system(query);
-       snprintf(manifest, 1024, "/tmp/opt/share/packages/%s.xml", gpkgname);
-       _d_msg(DEBUG_ERR, "Manifest name is %s\n", manifest);
-       if (access(manifest, F_OK)) {
-               _d_msg(DEBUG_ERR, "No rw Manifest File Found\n");
 
-               snprintf(manifest, 1024, "/tmp/usr/share/packages/%s.xml", gpkgname);
-               _d_msg(DEBUG_ERR, "Manifest ro name is %s\n", manifest);
+       _LOGD("fota-info : pkgid[%s] uninstall success\n", pkgid);
 
-               if (access(manifest, F_OK)) {
-                       _d_msg(DEBUG_ERR, "No ro Manifest File Found\n");
-//                     unlink(manifest);
-//                     return RPM_INSTALLER_ERR_NO_MANIFEST;
-               } else
-                       m_exist = 1;
-       } else
-               m_exist = 1;
+       return ret;
+}
 
-       _d_msg(DEBUG_ERR, "Manifest exists\n");
+static char * __getvalue(const char* pBuf, const char* pKey)
+{
+       const char* p = NULL;
+       const char* pStart = NULL;
+       const char* pEnd = NULL;
 
-       err = chdir(cwd);
-       if (err != 0) {
-               _d_msg(DEBUG_ERR, "chdir() failed\n");
-//             unlink(manifest);
-//             return RPM_INSTALLER_ERR_INTERNAL;
+       p = strstr(pBuf, pKey);
+       if (p == NULL)
+               return NULL;
+
+       pStart = p + strlen(pKey) + 1;
+       pEnd = strchr(pStart, SEPERATOR_START);
+       if (pEnd == NULL)
+               return NULL;
+
+       size_t len = pEnd - pStart;
+       if (len <= 0)
+               return NULL;
+
+       char *pRes = (char*)malloc(len + 1);
+       if(pRes == NULL){
+               _LOGE("@malloc failed");
+               return NULL;
        }
+       strncpy(pRes, pStart, len);
+       pRes[len] = 0;
 
-       if (m_exist) {
-               err = pkgmgr_parser_check_manifest_validation(manifest);
-               if(err < 0) {
-                       _d_msg(DEBUG_ERR, "Invalid manifest\n");
-                       unlink(manifest);
-                       return RPM_INSTALLER_ERR_INVALID_MANIFEST;
-               }
+       return pRes;
+}
+
+static char *__find_rpm_pkgid(const char* manifest)
+{
+       FILE *fp = NULL;
+       char buf[BUF_SIZE] = {0};
+       char *pkgid = NULL;
+
+       fp = fopen(manifest, "r");
+       if (fp == NULL) {
+               _LOGE("csc-info : Fail get : %s\n", manifest);
+               return NULL;
        }
-       /*Parse the manifest to get install location and size. If upgradation fails, remove manifest info from DB*/
-       err = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
-       if (err < 0) {
-               _d_msg(DEBUG_ERR, "Parsing Manifest Failed\n");
-//             unlink(manifest);
-//             return RPM_INSTALLER_ERR_INTERNAL;
-       } else {
-               _d_msg(DEBUG_ERR, "Parsing Manifest Success\n");
+
+       while (fgets(buf, BUF_SIZE, fp) != NULL) {
+               __str_trim(buf);
+               pkgid = __getvalue(buf, TOKEN_PACKAGE_STR);
+               if (pkgid !=  NULL) {
+                       fclose(fp);
+                       return pkgid;
+               }
+               memset(buf, 0x00, BUF_SIZE);
        }
-#endif
 
-#ifdef APP2EXT_ENABLE
-       ret = pkgmgr_pkginfo_get_pkginfo(gpkgname, &pkghandle);
-       if (ret < 0) {
-               _d_msg(DEBUG_ERR, "Failed to get pkginfo handle\n");
-//             unlink(manifest);
-//             return RPM_INSTALLER_ERR_INTERNAL;
-       } else {
-               ret = pkgmgr_pkginfo_get_install_location(pkghandle, &location);
-               if (ret < 0) {
-                       _d_msg(DEBUG_ERR, "Failed to get install location\n");
-                       pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
-                       unlink(manifest);
+       if (fp != NULL)
+               fclose(fp);
+
+       return NULL;
+}
+
+static int __copy_file( const char *src_path, const char *dst_path)
+{
+       FILE            *src, *dst;
+       int             rc = 0;
+       unsigned char   temp_buf[8192] = {'\0',};
+       size_t          size_of_uchar = sizeof( unsigned char);
+       size_t          size_of_temp_buf = sizeof( temp_buf);
+
+    src = fopen(src_path, "r");
+    if( src == NULL) {
+               _LOGE("Failed to open(). path=%s, E:%d(%s)", src_path, errno, strerror(errno));
+        return  -1;
+    }
+
+    dst = fopen(dst_path, "w");
+    if( dst == NULL) {
+               _LOGE("Failed to open dst file. file=%s, E:%d(%s)", dst_path, errno, strerror(errno));
+        fclose(src);
+        return  -1;
+    }
+
+    while(!feof(src)) {
+        rc = fread( temp_buf, size_of_uchar, size_of_temp_buf, src);
+        fwrite( temp_buf, size_of_uchar, rc, dst);
+    }
+
+    fclose( src);
+    fclose( dst);
+    return  0;
+}
+
+static int __ri_install_csc(char *path_str, char *remove_str)
+{
+       int ret = 0;
+
+       char *pkgid = NULL;
+       char delims[] = "/";
+       char* token = NULL;
+       char argv[BUF_SIZE] = {'\0'};
+       char xml_name[BUF_SIZE] = {'\0'};
+       char src_file[BUF_SIZE] = {'\0'};
+       char dest_file[BUF_SIZE] = {'\0'};
+
+       snprintf(src_file, sizeof(src_file), "%s", path_str);
+
+       /*get pkgid from path str*/
+       pkgid = __find_rpm_pkgid(path_str);
+       if (pkgid == NULL) {
+               _LOGE("csc-info : fail to find pkgid\n");
+               return -1;
+       }
+       _LOGD("csc-info : find pkgid=[%s] for installation\n", pkgid);
+
+       /*find xml name*/
+       token = strtok(path_str, delims);
+       while(token)
+       {
+               memset(xml_name, 0x00, sizeof(xml_name));
+               strncat(xml_name, token, strlen(token));
+               token = strtok(NULL, delims);
+       }
+       _LOGD("csc-info : xml name = %s\n", xml_name);
+
+       /*copy xml to /opt/share/packages*/
+       snprintf(dest_file, sizeof(dest_file), "%s/%s", OPT_SHARE_PACKAGES, xml_name);
+       ret = __copy_file(src_file, dest_file);
+       if (ret != 0) {
+               _LOGE("csc-info : xml copy fail(%d)\n", ret);
+       } else {
+               _LOGE("csc-info : xml copy success to [%s] \n", dest_file);
+       }
+
+       /*remove old pkg info*/
+       ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+       if (ret < 0) {
+               _LOGD("csc-info : fail remove old pkg info\n");
+       } else {
+               _LOGD("csc-info : success remove old pkg info\n");
+       }
+
+       /*insert new pkg info*/
+       memset(argv, 0x00, sizeof(argv));
+       snprintf(argv, sizeof(argv), "%s/%s", OPT_SHARE_PACKAGES, xml_name);
+       ret = __ri_init_csc_xml(argv, remove_str);
+       if (ret < 0) {
+               _LOGD("csc-info : fail insert db\n");
+       } else {
+               _LOGD("csc-info : success xml name = %s\n", xml_name);
+       }
+       if(pkgid){
+               free(pkgid);
+               pkgid = NULL;
+       }
+
+       return 0;
+}
+
+static int __ri_uninstall_csc(char *pkgid)
+{
+       /*remove old pkg info*/
+       int ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+       if (ret < 0) {
+               _LOGD("csc-info : fail remove old pkg info\n");
+       } else {
+               _LOGD("csc-info : success remove old pkg info\n");
+       }
+
+       return 0;
+}
+
+
+static int __get_size_from_xml(const char *manifest, int *size)
+{
+       const char *val = NULL;
+       const xmlChar *node;
+       xmlTextReaderPtr reader;
+       int ret = PMINFO_R_OK;
+
+       if(manifest == NULL) {
+               _LOGE("Input argument is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       if(size == NULL) {
+               _LOGE("Argument supplied to hold return value is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       reader = xmlReaderForFile(manifest, NULL, 0);
+
+       if (reader){
+               if (_child_element(reader, -1)) {
+                       node = xmlTextReaderConstName(reader);
+                       if (!node) {
+                               _LOGE("xmlTextReaderConstName value is NULL\n");
+                               ret = PMINFO_R_ERROR;
+                               goto end;
+                       }
+
+                       if (!strcmp(ASCII(node), "manifest")) {
+                               ret = _ri_get_attribute(reader,"size",&val);
+                               if(ret != 0){
+                                       _LOGE("@Error in getting the attribute value");
+                                       ret = PMINFO_R_ERROR;
+                                       goto end;
+                               }
+                               if (val) {
+                                       *size = atoi(val);
+                                       free((void*)val);
+                               } else {
+                                       *size = 0;
+                                       _LOGE("package size is not specified\n");
+                                       ret =  PMINFO_R_ERROR;
+                                       goto end;
+                               }
+                       } else {
+                               _LOGE("Unable to create xml reader\n");
+                               ret = PMINFO_R_ERROR;
+                               goto end;
+                       }
+               }
+       } else {
+               _LOGE("xmlReaderForFile value is NULL\n");
+               ret =  PMINFO_R_ERROR;
+       }
+
+
+end:
+       xmlFreeTextReader(reader);
+       return PMINFO_R_OK;
+}
+
+static int __get_location_from_xml(const char *manifest, pkgmgrinfo_install_location *location)
+{
+       const char *val = NULL;
+       const xmlChar *node;
+       xmlTextReaderPtr reader;
+       int ret = -1;
+
+       if(manifest == NULL) {
+               _LOGE("Input argument is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       if(location == NULL) {
+               _LOGE("Argument supplied to hold return value is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       reader = xmlReaderForFile(manifest, NULL, 0);
+
+       if (reader){
+               if ( _child_element(reader, -1)) {
+                       node = xmlTextReaderConstName(reader);
+                       if (!node) {
+                               _LOGE("xmlTextReaderConstName value is NULL\n");
+                               xmlFreeTextReader(reader);
+                               return PMINFO_R_ERROR;
+                       }
+
+                       if (!strcmp(ASCII(node), "manifest")) {
+                               ret = _ri_get_attribute(reader,"install-location",&val);
+                               if(ret != 0){
+                                       _LOGE("@Error in getting the attribute value");
+                                       xmlFreeTextReader(reader);
+                                       return PMINFO_R_ERROR;
+                               }
+
+                               if (val) {
+                                       if (strcmp(val, "internal-only") == 0)
+                                               *location = PMINFO_INSTALL_LOCATION_INTERNAL_ONLY;
+                                       else if (strcmp(val, "prefer-external") == 0)
+                                               *location = PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL;
+                                       else
+                                               *location = PMINFO_INSTALL_LOCATION_AUTO;
+                                       free((void*)val);
+                               }
+                       } else {
+                               _LOGE("Unable to create xml reader\n");
+                               xmlFreeTextReader(reader);
+                               return PMINFO_R_ERROR;
+                       }
+               }
+       } else {
+               _LOGE("xmlReaderForFile value is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       xmlFreeTextReader(reader);
+
+       return PMINFO_R_OK;
+}
+
+static char *__get_pkg_path(const char *pkg_path, const char *pkgid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char *real_path = NULL;
+
+       snprintf(buff, BUF_SIZE, "%s/%s", pkg_path, pkgid);
+       do {
+               if (__is_dir(buff)) break;
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "%s/%s", USR_APPS,pkgid);
+               if (__is_dir(buff)) break;
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "/opt/apps/%s", pkgid);
+               if (__is_dir(buff)) break;
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS,pkgid);
+               if (__is_dir(buff)) break;
+       } while (0);
+
+       ret = chdir(buff);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed. [%s]", buff, strerror(errno));
+               return NULL;
+       }
+
+       real_path = (char *)malloc(strlen(buff) + 1);
+       if (real_path == NULL) {
+               _LOGE("malloc() failed.");
+               return NULL;
+       }
+       memset(real_path, '\0', strlen(buff) + 1);
+       memcpy(real_path, buff, strlen(buff));
+
+       return real_path;
+}
+
+static int __set_label_for_pkg_dir(const char *dirpath, const char* label)
+{
+       int ret = 0;
+       DIR *dir;
+       struct dirent entry;
+       struct dirent *result;
+       char fullpath[BUF_SIZE] = {'\0'};
+
+       if (access(dirpath, F_OK) != 0) {
+               _LOGE("skip! empty dirpath = [%s]", dirpath);
+               return 0;
+       }
+
+       dir = opendir(dirpath);
+       if (!dir) {
+               _LOGE("opendir(%s) failed. [%d][%s]", dirpath, errno, strerror(errno));
+               return -1;
+       }
+
+       if(lsetxattr(dirpath, "security.SMACK64", label, strlen(label), 0)) {
+               _LOGE("error(%d) in setting smack label",errno);
+       }
+
+       for (ret = readdir_r(dir, &entry, &result); ret == 0 && result != NULL; ret = readdir_r(dir, &entry, &result)){
+               if (!strcmp(entry.d_name, ".") ||
+                       !strcmp(entry.d_name, "..")) {
+                       continue;
+               }
+
+               // sub
+               snprintf(fullpath, BUF_SIZE, "%s/%s", dirpath, entry.d_name);
+               if(lsetxattr(fullpath, "security.SMACK64", label, strlen(label), 0)) {
+                       _LOGE("error(%d) in setting smack label",errno);
+               }
+
+
+               // find next dir
+               if (entry.d_type == DT_DIR) {
+                       ret = __set_label_for_pkg_dir(fullpath,label);
+                       if(ret != 0 ){
+                               _LOGE("_coretpk_installer_apply_directory_policy(%s) failed.", fullpath);
+                       }
+               }
+               memset(fullpath, '\0', BUF_SIZE);
+       }
+
+       closedir(dir);
+
+       return ret;
+
+}
+
+void _ri_soft_reset(char *pkgid)
+{
+       int ret = 0;
+       char dirpath[PKG_STRING_LEN_MAX] = {'\0'};
+
+       //home
+       snprintf(dirpath, PKG_STRING_LEN_MAX, "%s/%s", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK)==0) {
+               __set_label_for_pkg_dir(dirpath, "_");
+       }
+
+       // data
+       memset(dirpath, '\0', PKG_STRING_LEN_MAX);
+       snprintf(dirpath, PKG_STRING_LEN_MAX, "%s/%s/data", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK)==0) {
+               __set_label_for_pkg_dir(dirpath, pkgid);
+       }
+
+       //shared
+       memset(dirpath, '\0', PKG_STRING_LEN_MAX);
+       snprintf(dirpath, PKG_STRING_LEN_MAX, "%s/%s/shared", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK)==0) {
+               __set_label_for_pkg_dir(dirpath, "_");
+       }
+
+       //shared/res
+       memset(dirpath, '\0', PKG_STRING_LEN_MAX);
+       snprintf(dirpath, PKG_STRING_LEN_MAX, "%s/%s/shared/res", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK)==0) {
+               __set_label_for_pkg_dir(dirpath, "_");
+       }
+
+       //shared/data
+       memset(dirpath, '\0', PKG_STRING_LEN_MAX);
+       snprintf(dirpath, PKG_STRING_LEN_MAX, "%s/%s/shared/data", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK)==0) {
+               __set_label_for_pkg_dir(dirpath, "_");
+       }
+
+       //shared/trusted
+       memset(dirpath, '\0', PKG_STRING_LEN_MAX);
+       snprintf(dirpath, PKG_STRING_LEN_MAX, "%s/%s/shared/trusted", OPT_USR_APPS, pkgid);
+       if (access(dirpath, F_OK)==0) {
+               pkgmgrinfo_pkginfo_h handle = NULL;
+               char *groupid = NULL;
+               ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+               if (ret != PMINFO_R_OK)
+                       return;
+/*             ret = pkgmgrinfo_pkginfo_get_groupid(handle, &groupid);
+               if (ret == PMINFO_R_OK) {
+                       _ri_privilege_setup_path(pkgid, dirpath, APP_PATH_GROUP_RW, groupid);
+               }*/
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       }
+
+       return;
+}
+
+void _ri_register_cert(const char *pkgid)
+{
+       int error = 0;
+       pkgmgrinfo_instcertinfo_h handle = NULL;
+       int i = 0;
+       /* create Handle*/
+       error = pkgmgrinfo_create_certinfo_set_handle(&handle);
+       if (error != 0) {
+               _LOGE("Cert handle creation failed. Err:%d", error);
+               __ri_free_cert_chain();
+               return;
+       }
+
+       if (list[SIG_AUTH].cert_value == NULL) {
+               _LOGE("pkgid[%s] dont have SIG_AUTH.cert_value ", pkgid);
+               goto err;
+       }
+
+       for (i = 0; i < MAX_CERT_NUM; i++) {
+
+               if (list[i].cert_value) {
+                       error = pkgmgrinfo_set_cert_value(handle, list[i].cert_type, list[i].cert_value);
+                       if (error != 0) {
+                               _LOGE("pkgmgrinfo_set_cert_value failed. cert type:%d. Err:%d", list[i].cert_type, error);
+                               goto err;
+                       }
+               }
+       }
+       /* Save the certificates in cert DB*/
+       error = pkgmgrinfo_save_certinfo(pkgid, handle);
+       if (error != 0) {
+               _LOGE("pkgmgrinfo_save_certinfo failed. Err:%d", error);
+               goto err;
+       }
+err:
+       if (handle)
+               pkgmgrinfo_destroy_certinfo_set_handle(handle);
+       __ri_free_cert_chain();
+}
+
+void _ri_unregister_cert(const char *pkgid)
+{
+       int error = 0;
+       /* Delete the certifictes from cert DB*/
+       error = pkgmgrinfo_delete_certinfo(pkgid);
+       if (error != 0) {
+               _LOGE("pkgmgrinfo_delete_certinfo failed. Err:%d", error);
+               return;
+       }
+}
+
+int _ri_verify_sig_and_cert(const char *sigfile, int *visibility)
+{
+       char certval[MAX_BUFF_LEN] = {'\0'};
+       int err = 0;
+       int validity = 0;
+       int i = 0;
+       int j= 0;
+       int ret = RPM_INSTALLER_SUCCESS;
+       char *crt = NULL;
+       signature_x *signx = NULL;
+       struct keyinfo_x *keyinfo = NULL;
+       struct x509data_x *x509data = NULL;
+       CERT_CONTEXT *ctx = NULL;
+       int sigtype = 0;
+
+       ctx = cert_svc_cert_context_init();
+       if (ctx == NULL) {
+               _LOGE("cert_svc_cert_context_init() failed.");
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       if (strstr(sigfile, AUTHOR_SIGNATURE_XML))
+               sigtype = SIG_AUTH;
+       else if (strstr(sigfile, SIGNATURE1_XML))
+               sigtype = SIG_DIST1;
+       else if (strstr(sigfile, SIGNATURE2_XML))
+               sigtype = SIG_DIST2;
+       else {
+               _LOGE("Unsupported signature type! [%s]", sigfile);
+               cert_svc_cert_context_final(ctx);
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       signx = _ri_process_signature_xml(sigfile);
+       if (signx == NULL) {
+               _LOGE("_ri_process_signature_xml(%s) failed.", sigfile);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto end;
+       }
+
+       keyinfo = signx->keyinfo;
+       if ((keyinfo == NULL) || (keyinfo->x509data == NULL) || (keyinfo->x509data->x509certificate == NULL)) {
+               _LOGE("keyinfo is invalid. [%s]", sigfile);
+               ret = RPM_INSTALLER_ERR_CERT_INVALID;
+               goto end;
+       }
+
+       x509data = keyinfo->x509data;
+       x509certificate_x *cert = x509data->x509certificate;
+
+       // First cert is Signer certificate
+       if (cert->text != NULL) {
+               for (i = 0; i <= (int)strlen(cert->text); i++) {
+                       if (cert->text[i] != '\n') {
+                               certval[j++] = cert->text[i];
+                       }
+               }
+               certval[j] = '\0';
+
+               err = cert_svc_load_buf_to_context(ctx, (unsigned char*)certval);
+               if (err != 0) {
+                       _LOGE("cert_svc_load_buf_to_context() failed. cert = [%s], err = [%d]", certval, err);
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto end;
+               }
+               // _LOGD("SIG_SIGNER certval = [%d][%s]", strlen(certval), certval);
+
+               err = __ri_create_cert_chain(sigtype, SIG_SIGNER, certval);
+               if (err) {
+                       _LOGE("__ri_create_cert_chain() failed. sigtype = [%d], certval = [%s]", sigtype, certval);
+                       __ri_free_cert_chain();
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto end;
+               }
+       }
+
+       // Second cert is Intermediate certificate
+       cert = cert->next;
+       if (cert->text != NULL) {
+               memset(certval, 0x00, MAX_BUFF_LEN);
+               j = 0;
+               for (i = 0; i <= (int)strlen(cert->text); i++) {
+                       if (cert->text[i] != '\n') {
+                               certval[j++] = cert->text[i];
+                       }
+               }
+               certval[j] = '\0';
+
+               if (cert->text != NULL) {
+                       err = cert_svc_push_buf_into_context(ctx, (unsigned char*)certval);
+                       if (err != 0) {
+                               _LOGE("cert_svc_push_buf_into_context() failed. cert = [%s], err = [%d]", certval, err);
+                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                               goto end;
+                       }
+               }
+               // _LOGD("SIG_INTERMEDIATE certval = [%d][%s]", strlen(certval), certval);
+
+               err = __ri_create_cert_chain(sigtype, SIG_INTERMEDIATE, certval);
+               if (err) {
+                       _LOGE("__ri_create_cert_chain() failed. sigtype = [%d], certval = [%s]", sigtype, certval);
+                       __ri_free_cert_chain();
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto end;
+               }
+       } else {
+               _LOGE("Invalid CertChain! (cert->text is NULL.)");
+               ret = RPM_INSTALLER_ERR_CERT_INVALID;
+               goto end;
+       }
+
+       err = cert_svc_verify_certificate(ctx, &validity);
+       if (err != 0) {
+               _LOGE("cert_svc_verify_certificate() failed.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto end;
+       }
+       _LOGD("cert_svc_verify() is done successfully. validity=[%d]", validity);
+
+       if (validity == 0) {
+               _LOGE("Certificate Invalid/Expired (validity == 0)");
+               ret = RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED;
+               goto end;
+       }
+
+       // verify signature
+       // For reference validation, we should be in TEMP_DIR/usr/apps/<pkgid>
+       if (ctx->fileNames && ctx->fileNames->filename) {
+               _LOGD("Root CA cert path=[%s]", ctx->fileNames->filename);
+
+               err = __ri_xmlsec_verify_signature(sigfile, ctx->fileNames->filename);
+               if (err < 0) {
+                       _LOGE("__ri_xmlsec_verify_signature(%s) failed.", sigfile);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto end;
+               }
+
+               crt = __ri_get_cert_from_file(ctx->fileNames->filename);
+               err = __ri_create_cert_chain(sigtype, SIG_ROOT, crt);
+               if (err) {
+                       _LOGE("__ri_create_cert_chain(%d) failed.", sigtype);
+                       __ri_free_cert_chain();
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto end;
+               }
+/*
+               err = cert_svc_get_visibility(ctx, visibility);
+               if (err != 0) {
+                       _LOGE("cert_svc_get_visibility() failed. err = [%d]", err);
+                       ret = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+                       goto end;
+               }
+               _LOGD("cert_svc_get_visibility() returns visibility=[%d]", *visibility);*/
+       } else {
+               _LOGE("No Root CA cert found. Signature validation failed.");
+               ret = RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND;
+               goto end;
+       }
+
+       ret = 0;
+
+end:
+       cert_svc_cert_context_final(ctx);
+       ctx = NULL;
+       _ri_free_signature_xml(signx);
+       signx = NULL;
+       return ret;
+}
+
+int _ri_verify_signatures(const char *root_path, const char *pkgid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char *pkg_path = NULL;
+       int visibility = 0;
+
+       _LOGD("root_path=[%s], pkgid=[%s]", root_path, pkgid);
+
+       // check for signature and certificate
+       pkg_path = __get_pkg_path(root_path, pkgid);
+       if (pkg_path == NULL) {
+               _LOGE("__get_pkg_path(%s, %s) failed.", root_path, pkgid);
+               return 0;
+       }
+
+       _LOGD("switched to pkg_path=[%s]", pkg_path);
+
+       // author-signature.xml is mandatory
+       snprintf(buff, BUF_SIZE, "%s/author-signature.xml", pkg_path);
+       if (access(buff, F_OK) == 0) {
+               _LOGD("author-signature.xml, path=[%s]", buff);
+               ret = _ri_verify_sig_and_cert(buff, &visibility);
+               if (ret) {
+                       _LOGE("_ri_verify_sig_and_cert(%s) failed.", buff);
+                       ret = -1;
+                       goto end;
+               }
+               _LOGD("------------------------------------------------------");
+               _LOGD("signature is verified successfully");
+               _LOGD("path=[%s]", buff);
+               _LOGD("------------------------------------------------------");
+       }
+       memset(buff, '\0', BUF_SIZE);
+
+       // signature2.xml is optional
+       snprintf(buff, BUF_SIZE, "%s/signature2.xml", pkg_path);
+       if (access(buff, F_OK) == 0) {
+               _LOGD("signature2.xml found. [%s]", pkg_path);
+               ret = _ri_verify_sig_and_cert(buff, &visibility);
+               if (ret) {
+                       _LOGE("_ri_verify_sig_and_cert(%s) failed.", buff);
+                       ret = -1;
+                       goto end;
+               }
+               _LOGD("_ri_verify_sig_and_cert(%s) succeed.", buff);
+       }
+       memset(buff, '\0', BUF_SIZE);
+
+       // signature1.xml is mandatory
+       snprintf(buff, BUF_SIZE, "%s/signature1.xml", pkg_path);
+       if (access(buff, F_OK) == 0) {
+               _LOGD("signature1.xml, path=[%s]", buff);
+               ret = _ri_verify_sig_and_cert(buff, &visibility);
+               if (ret) {
+                       _LOGE("_ri_verify_sig_and_cert(%s) failed.", buff);
+                       ret = -1;
+                       goto end;
+               }
+               _LOGD("------------------------------------------------------");
+               _LOGD("signature is verified successfully");
+               _LOGD("path=[%s]", buff);
+               _LOGD("------------------------------------------------------");
+       }
+       memset(buff, '\0', BUF_SIZE);
+
+       ret = 0;
+
+end :
+       if(pkg_path){
+               free(pkg_path);
+               pkg_path = NULL;
+       }
+
+       if ((ret != 0) && (sig_enable == 0)) {
+               _LOGD("_ri_verify_signatures(%s, %s) failed, but it's ok for config.", root_path, pkgid);
+               ret = 0;
+       }
+
+       return ret;
+}
+
+void _ri_apply_smack(char *pkgname, int flag)
+{
+       __rpm_apply_smack(pkgname, flag);
+}
+
+int _ri_apply_privilege(char *pkgid, int visibility)
+{
+#if 0
+       int ret = -1;
+       pkgmgrinfo_pkginfo_h handle = NULL;
+       privilegeinfo info;
+       int apptype = PERM_APP_TYPE_EFL;
+
+       memset(&info, '\0', sizeof(info));
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret != PMINFO_R_OK)
+               return -1;
+
+       strncpy(info.package_id, pkgid, strlen(pkgid));
+       info.visibility = visibility;
+
+       ret = pkgmgrinfo_pkginfo_foreach_privilege(handle, __privilege_func, (void *)&info);
+       if (ret != PMINFO_R_OK) {
+               _LOGE("pkgmgrinfo_pkginfo_get_pkgid failed\n");
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return -1;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       if (visibility & CERT_SVC_VISIBILITY_PLATFORM) {
+               _LOGD("VISIBILITY_PLATFORM!");
+               apptype = PERM_APP_TYPE_EFL_PLATFORM;
+       } else if ((visibility & CERT_SVC_VISIBILITY_PARTNER) ||
+                       (visibility & CERT_SVC_VISIBILITY_PARTNER_OPERATOR) ||
+                       (visibility & CERT_SVC_VISIBILITY_PARTNER_MANUFACTURER)) {
+               _LOGD("VISIBILITY_PARTNER!");
+               apptype = PERM_APP_TYPE_EFL_PARTNER;
+       }
+
+       /*reload privilege*/
+       const char *perm[] = {NULL, NULL};
+       ret = _ri_privilege_enable_permissions(pkgid, apptype, perm, 1);
+#endif
+       return 0;
+}
+
+int _ri_set_group_id(const char *pkgid, const char *groupid)
+{
+       retvm_if(pkgid == NULL, PMINFO_R_EINVAL, "pkgid is NULL\n");
+       retvm_if(groupid == NULL, PMINFO_R_EINVAL, "groupid is NULL\n");
+       int ret = -1;
+       sqlite3 *pkginfo_db = NULL;
+       char *query = NULL;
+
+       /*open db*/
+       ret = db_util_open(PKGMGR_DB, &pkginfo_db, 0);
+       retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db [%s] failed!", PKGMGR_DB);
+
+       /*Begin transaction*/
+       ret = sqlite3_exec(pkginfo_db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
+       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Failed to begin transaction\n");
+       _LOGD("Transaction Begin\n");
+
+       query = sqlite3_mprintf("update package_info set package_reserve3=%Q where package=%Q", groupid, pkgid);
+
+       ret = sqlite3_exec(pkginfo_db, query, NULL, NULL, NULL);
+       tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
+
+       /*Commit transaction*/
+       ret = sqlite3_exec(pkginfo_db, "COMMIT", NULL, NULL, NULL);
+       if (ret != SQLITE_OK) {
+               _LOGE("Failed to commit transaction. Rollback now\n");
+               ret = sqlite3_exec(pkginfo_db, "ROLLBACK", NULL, NULL, NULL);
+               tryvm_if(ret != SQLITE_OK, ret = PMINFO_R_ERROR, "Don't execute query = %s\n", query);
+       }
+       _LOGD("Transaction Commit and End\n");
+
+       ret = PMINFO_R_OK;
+catch:
+       sqlite3_free(query);
+       sqlite3_close(pkginfo_db);
+       return ret;
+}
+
+static int __ri_install_fota_for_rw(char *pkgid)
+{
+#if 0
+       int ret = 0;
+       int home_dir = 1;
+       char buff[BUF_SIZE] = {'\0'};
+
+       _LOGD("fota-info : pkgid[%s] start installation\n", pkgid);
+
+       /*unzip pkg path from factoryrest data*/
+       snprintf(buff, BUF_SIZE, "opt/usr/apps/%s/*", pkgid);
+       const char *pkg_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+       ret = _ri_xsystem(pkg_argv);
+       if (ret != 0) {
+               _LOGE("fota-info : unzip root path[%s] is fail .\n", buff);
+               return ret;
+       }
+
+       _LOGD("fota-info : unzip root path[%s] is success\n", buff);
+
+       /*unzip manifest from factoryrest data*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "opt/share/packages/%s.xml", pkgid);
+
+       const char *xml_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+       ret = _ri_xsystem(xml_argv);
+       if (ret != 0) {
+               _LOGE("fota-info : xml_argv fail for pkgid[%s] .\n", pkgid);
+               return ret;
+       }
+
+       _LOGD("fota-info : xml_argv[%s] is success\n", pkgid);
+
+       /*get updated manifest path*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       _LOGE("Manifest name is %s\n", buff);
+
+       /*apply smack for manifest*/
+       _ri_privilege_change_smack_label(buff, pkgid, 0);/*0 is SMACK_LABEL_ACCESS*/
+
+       /*register manifest*/
+       char* fota_tags[3] = {NULL, };
+       fota_tags[0] = "removable=true";
+       fota_tags[1] = "preload=true";
+       fota_tags[2] = NULL;
+
+       ret = pkgmgr_parser_parse_manifest_for_installation(buff, fota_tags);
+       if (ret < 0) {
+               _LOGE("Parsing Manifest Failed\n");
+               ret = -1;
+               goto err;
+       } else {
+               _LOGD("Parsing Manifest Success\n");
+       }
+
+       /*Register cert info*/
+       _ri_register_cert(pkgid);
+
+       /*apply smack for pkg root path*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+       _ri_privilege_setup_path(pkgid, buff, PERM_APP_PATH_ANY_LABEL, pkgid);
+
+       /*apply smack for defined directory*/
+       __rpm_apply_smack(pkgid, home_dir);
+
+       /*apply privilege*/
+       ret = _ri_apply_privilege(pkgid, 0);
+       if (ret != 0) {
+               _LOGE("apply perm failed with err(%d)\n", ret);
+       } else {
+               _LOGD("apply perm success\n");
+       }
+
+err:
+       return ret;
+#endif
+       return 0;
+}
+
+static int __ri_upgrade_fota_for_rw(char *pkgid)
+{
+#if 0
+       int ret = 0;
+       int home_dir = 1;
+       char buff[BUF_SIZE] = {'\0'};
+
+       _LOGD("fota-info : pkgid[%s] start upgrade\n", pkgid);
+
+       /*unzip pkg dir from factoryrest data*/
+       snprintf(buff, BUF_SIZE, "opt/usr/apps/%s/*", pkgid);
+       const char *pkg_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+       ret = _ri_xsystem(pkg_argv);
+       if (ret != 0) {
+               _LOGE("fota-info : unzip root path[%s] is fail .\n", buff);
+               return ret;
+       }
+
+       _LOGD("fota-info : unzip root path[%s] is success\n", buff);
+
+       /*unzip manifest from factoryrest data*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "opt/share/packages/%s.xml", pkgid);
+       const char *xml_argv[] = { "/usr/bin/unzip", "-oX", OPT_ZIP_FILE, buff, "-d", "/", NULL };
+       ret = _ri_xsystem(xml_argv);
+       if (ret != 0) {
+               _LOGE("fota-info : unzip manifest[%s] is fail .\n", buff);
+               return ret;
+       }
+
+       _LOGD("fota-info : unzip manifest[%s] is success\n", buff);
+
+       /*get updated manifest path*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       _LOGE("Manifest name is %s\n", buff);
+
+       /*apply smack for manifest*/
+       _ri_privilege_change_smack_label(buff, pkgid, 0);/*0 is SMACK_LABEL_ACCESS*/
+
+       /*register manifest*/
+       ret = pkgmgr_parser_parse_manifest_for_upgrade(buff, NULL);
+       if (ret < 0) {
+               _LOGE("Parsing Manifest Failed\n");
+               ret = -1;
+               goto err;
+       } else {
+               _LOGD("Parsing Manifest Success\n");
+       }
+
+       /*Register new cert info*/
+       _ri_unregister_cert(pkgid);
+       _ri_register_cert(pkgid);
+
+       /*apply smack for pkg root path*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+       _ri_privilege_setup_path(pkgid, buff, PERM_APP_PATH_ANY_LABEL, pkgid);
+
+       /*apply smack for defined directory*/
+       __rpm_apply_smack(pkgid, home_dir);
+
+       /*apply privilege*/
+       ret = _ri_apply_privilege(pkgid, 0);
+       if (ret != 0) {
+               _LOGE("apply perm failed with err(%d)\n", ret);
+       } else {
+               _LOGD("apply perm success\n");
+       }
+
+err:
+       return ret;
+#endif
+       return 0;
+}
+
+static int __ri_uninstall_fota_for_rw(char *pkgid)
+{
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+
+       _LOGD("fota-info : pkgid[%s] start uninstall\n", pkgid);
+
+       /*del root path dir*/
+       snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+
+       if (__is_dir(buff)) {
+               _rpm_delete_dir(buff);
+       }
+
+       /*del manifest*/
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       (void)remove(buff);
+
+       /*del db info*/
+       ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+       if (ret < 0) {
+               _LOGE("Parsing Manifest Failed\n");
+       }
+
+       /*execute privilege APIs*/
+       _ri_privilege_revoke_permissions(pkgid);
+       _ri_privilege_unregister_package(pkgid);
+
+       /*Unregister cert info*/
+       _ri_unregister_cert(pkgid);
+
+       return 0;
+}
+
+/**
+ * callback for the pkgmgrinfo_appinfo_get_list used in _rpm_uninstall_pkg()
+ */
+int __ri_check_running_app(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       int ret = 0;
+       bool isRunning = 0;
+       char *appid = NULL;
+       app_context_h appCtx = NULL;
+
+       ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+       if (ret < 0) {
+               _LOGE("Failed to execute pkgmgrinfo_appinfo_get_appid[%d].\n", ret);
+               return ret;
+       }
+
+       ret = app_manager_is_running(appid, &isRunning);
+       if (ret < 0) {
+               _LOGE("Failed to execute app_manager_is_running[%d].\n", ret);
+               return ret;
+       }
+       _LOGE("app[%s] , running state[%d].\n", appid, isRunning);
+
+       if (isRunning) {
+               ret = app_manager_get_app_context(appid, &appCtx);
+               if (ret < 0) {
+                       _LOGE("Failed to execute app_manager_get_app_context[%d].\n", ret);
+                       return ret;
+               }
+
+               ret = app_manager_terminate_app(appCtx);
+               if (ret < 0) {
+                       _LOGE("Failed to execute app_manager_terminate_app[%d].\n", ret);
+                       app_context_destroy(appCtx);
+                       return ret;
+               }
+
+               int i = 0;
+               for (i = 0; i < TERMINATE_RETRY_COUNT; i++) {
+                       ret = app_manager_is_running(appid, &isRunning);
+                       if (ret < 0) {
+                               _LOGE("Failed to execute app_manager_is_running[%d].\n", ret);
+                               app_context_destroy(appCtx);
+                               return ret;
+                       }
+
+                       if (!isRunning) {
+                               _LOGD("App(%s) is terminated.\n", appid);
+                               break;
+                       } else {
+                               _LOGD("App(%s) is not terminated yet. wait count=[%d].\n", appid, i);
+                               usleep(100000);
+                       }
+               }
+
+               ret = app_context_destroy(appCtx);
+               if (ret < 0) {
+                       _LOGE("Failed to execute app_context_destroy[%d].\n", ret);
+                       return ret;
+               }
+       }
+
+       return ret;
+}
+
+int __ri_change_dir(char *dirname)
+{
+       int ret = 0;
+
+       ret = mkdir(dirname, 0644);
+       if (ret < 0) {
+               if (access(dirname, F_OK) == 0) {
+                       _rpm_delete_dir(dirname);
+                       ret = mkdir(dirname, 0644);
+                       if (ret < 0) {
+                               _LOGE("mkdir(%s) failed\n", dirname);
+                               return -1;
+                       }
+               } else {
+                       _LOGE("can not access[%s]\n", dirname);
+                       return -1;
+               }
+       }
+
+       ret = chdir(dirname);
+       if (ret != 0) {
+               _LOGE("chdir(%s) failed [%s]\n", dirname, strerror(errno));
+               return -1;
+       }
+       return 0;
+}
+
+int _ri_smack_reload(const char *pkgid, rpm_request_type request_type)
+{
+       int ret = 0;
+       char *op_type = NULL;
+
+       switch (request_type) {
+               case INSTALL_REQ:
+                       op_type = strdup("install");
+                       break;
+
+               case UPGRADE_REQ:
+                       op_type = strdup("update");
+                       break;
+
+               case UNINSTALL_REQ:
+                       op_type = strdup("uninstall");
+                       break;
+
+               default:
+                       break;
+       }
+
+       if(op_type == NULL) {
+               _LOGE("@Failed to reload smack. request_type not matched[pkgid=%s, op=%s]", pkgid, op_type);
+               return -1;
+       }
+
+       const char *smack_argv[] = { "/usr/bin/smack_reload.sh", op_type, pkgid, NULL };
+       ret = _ri_xsystem(smack_argv);
+       if (ret != 0) {
+               _LOGE("@Failed to reload smack[pkgid=%s, op=%s].", pkgid, op_type);
+       } else {
+               _LOGD("#success: smack reload[pkgid=%s, op=%s]", pkgid, op_type);
+       }
+       if(op_type){
+               free(op_type);
+               op_type = NULL;
+       }
+       return ret;
+}
+
+int _ri_smack_reload_all(void)
+{
+       int ret = 0;
+
+       const char *smack_argv[] = { "/usr/bin/smackload-fast", NULL};
+       ret = _ri_xsystem(smack_argv);
+       if (ret != 0) {
+               _LOGE("@Failed to reload all smack : %d", errno);
+       } else {
+               _LOGD("#success: smack reload all");
+       }
+
+       return ret;
+}
+
+void __ri_remove_updated_dir(const char *pkgid)
+{
+       char path_buf[BUF_SIZE] = {'\0'};
+
+       // check pkgid
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL.");
+               return;
+       }
+
+       // remove bin dir
+       snprintf(path_buf, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, BIN_DIR_STR);
+       if (__is_dir(path_buf)) {
+               _LOGE("@pkgid[%s] need to clean dir[%s]\n", pkgid, path_buf);
+               _rpm_delete_dir(path_buf);
+       }
+
+       // remove res dir
+       memset(path_buf, '\0', BUF_SIZE);
+       snprintf(path_buf, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, RES_DIR_STR);
+       if (__is_dir(path_buf)) {
+               _LOGE("@pkgid[%s] need to clean dir[%s]\n", pkgid, path_buf);
+               _rpm_delete_dir(path_buf);
+       }
+
+       // remove shared/res dir
+       memset(path_buf, '\0', BUF_SIZE);
+       snprintf(path_buf, BUF_SIZE, "%s/%s/%s", OPT_USR_APPS, pkgid, SHARED_RES_DIR_STR);
+       if (__is_dir(path_buf)) {
+               _LOGE("@pkgid[%s] need to clean dir[%s]\n", pkgid, path_buf);
+               _rpm_delete_dir(path_buf);
+       }
+}
+
+static int __metadata_func(const char *key, const char *value, void *user_data)
+{
+       int ret = 0;
+       bool isRunning = 0;
+
+       if (key == NULL) {
+               _LOGE("key is null\n");
+               return -1;
+       }
+       if (value == NULL) {
+               _LOGE("value is null\n");
+               return -1;
+       }
+       if (user_data == NULL) {
+               _LOGE("user_data is null\n");
+               return -1;
+       }
+
+       if ((strcmp(key, "launch-on-attach") == 0) && (strcmp(value, "true") == 0)) {
+               _LOGE("consumer[%s] : launch-on-attach is true \n", (char *)user_data);
+
+               ret = app_manager_is_running((char *)user_data, &isRunning);
+               if (ret < 0) {
+                       _LOGE("Failed to execute app_manager_is_running[%s].\n", (char *)user_data);
+                       return ret;
+               }
+
+               if (isRunning) {
+                       _LOGE("consumer[%s] is already launched \n", (char *)user_data);
+               } else {
+                       usleep(100 * 1000); /* 100ms sleep for infomation ready*/
+                       ret = aul_launch_app((char *)user_data, NULL);
+                       if (ret == AUL_R_ERROR) {
+                               _LOGE("consumer[%s] launch fail, sleep and retry  launch_app\n", (char *)user_data);
+                               usleep(100 * 1000);     /* 100ms sleep for infomation ready*/
+                               aul_launch_app((char *)user_data, NULL);
+                       }
+                       _LOGE("consumer[%s] is launched !!!! \n", (char *)user_data);
+               }
+       }
+       return 0;
+}
+
+static int __ri_find_svcapp(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+       int ret = 0;
+       char *appid = NULL;
+       char *component_type = NULL;
+
+       ret = pkgmgrinfo_appinfo_get_component_type(handle, &component_type);
+       if (ret != PMINFO_R_OK) {
+               _LOGE("@Failed to get component_type\n");
+               return -1;
+       }
+
+       if (strcmp(component_type, "svcapp") == 0) {
+               ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+               if (ret != PMINFO_R_OK) {
+                       _LOGE("@Failed to get appid\n");
+                       return -1;
+               }
+               _LOGE("@find consumer[%s], check metadata for launch\n", appid);
+
+               ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __metadata_func, (void *)appid);
+               if (ret != PMINFO_R_OK) {
+                       _LOGE("@Failed to get foreach_metadata\n");
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
+static void __ri_launch_consumer(const char *pkgid)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       if (ret < 0) {
+               _LOGE("@Failed to get pkginfo handle [%s]\n", pkgid);
+               return;
+       }
+
+       ret = pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_find_svcapp, NULL);
+       if (ret < 0) {
+               _LOGE("@Failed to get appinfo_get_list [%s]\n", pkgid);
+               return;
+       }
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+}
+
+static int __ail_change_info(int op, const char *appid)
+{
+       void *lib_handle = NULL;
+       int (*ail_desktop_operation) (const char *);
+       char *aop = NULL;
+       int ret = 0;
+
+       if ((lib_handle = dlopen(LIBAIL_PATH, RTLD_LAZY)) == NULL) {
+               _LOGE("dlopen is failed LIBAIL_PATH[%s]\n", LIBAIL_PATH);
+               goto END;
+       }
+
+
+       switch (op) {
+               case 0:
+                       aop  = "ail_desktop_add";
+                       break;
+               case 1:
+                       aop  = "ail_desktop_update";
+                       break;
+               case 2:
+                       aop  = "ail_desktop_remove";
+                       break;
+               case 3:
+                       aop  = "ail_desktop_clean";
+                       break;
+               case 4:
+                       aop  = "ail_desktop_fota";
+                       break;
+               default:
+                       goto END;
+                       break;
+       }
+
+       if ((ail_desktop_operation =
+            dlsym(lib_handle, aop)) == NULL || dlerror() != NULL) {
+               _LOGE("can not find symbol \n");
+
+               goto END;
+       }
+
+       ret = ail_desktop_operation(appid);
+
+END:
+       if (lib_handle)
+               dlclose(lib_handle);
+
+       return ret;
+}
+
+static int __ri_update_ail_info(const pkgmgrinfo_appinfo_h handle, void *user_data)
+{
+#if 0
+       int ret = 0;
+       char *appid = NULL;
+
+       ret = pkgmgrinfo_appinfo_get_appid(handle, &appid);
+       if (ret < 0) {
+               _LOGE("Failed to execute pkgmgrinfo_appinfo_get_appid[%d].\n", ret);
+               return ret;
+       }
+
+       ret = __ail_change_info(AIL_INSTALL, appid);
+       if (ret < 0) {
+               _LOGE("Failed to execute __ail_change_info[%s].\n", appid);
+       }
+
+       return ret;
+#endif
+       return 0;
+}
+
+static int __child_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data)
+{
+       int ret = 0;
+       char *pkgid = NULL;
+
+       ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid);
+       if(ret < 0) {
+               _LOGE("get_pkgid failed\n");
+               return ret;
+       }
+
+       _LOGD("@child pkgid is [%s] for uninstallation", pkgid);
+
+       ret = _rpm_uninstall_pkg_with_dbpath(pkgid, 0);
+       if(ret != 0) {
+               _LOGE("uninstall pkg(%s) failed\n",pkgid );
+       }
+
+       return ret;
+}
+
+static void __uninstall_child_package_by_mother_pkgid(const char *pkgid)
+{
+#if 0
+       int ret = 0;
+       pkgmgrinfo_pkginfo_filter_h handle = NULL;
+
+       ret = pkgmgrinfo_pkginfo_filter_create(&handle);
+       if (ret != 0) {
+               _LOGE("filter_create failed for (%s)\n", pkgid);
+               return;
+       }
+
+       ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_STORECLIENT_ID, pkgid);
+       if (ret < 0) {
+               _LOGE("PMINFO_PKGINFO_PROP_PACKAGE_STORECLIENT_ID add failed\n");
+               goto end;
+       }
+
+       ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __child_list_cb, NULL);
+       if (ret < 0) {
+               _LOGE("foreach_pkginfo failed\n");
+       }
+
+end:
+       pkgmgrinfo_pkginfo_filter_destroy(handle);
+#endif
+}
+
+int _rpm_install_pkg_with_dbpath(char *pkgfilepath, char *pkgid, char *clientid)
+{
+       int ret = 0;
+       char manifest[BUF_SIZE] = { '\0'};
+       char resultxml[BUF_SIZE] = {'\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       int home_dir = 0;
+       char *temp = NULL;
+#ifdef APP2EXT_ENABLE
+       app2ext_handle *handle = NULL;
+       GList *dir_list = NULL;
+       pkgmgrinfo_install_location location = 1;
+       int size = -1;
+       unsigned long rpm_size = 0;
+#endif
+       /*send event for start*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "start", "install");
+       _LOGD("[#]start : _rpm_install_pkg_with_dbpath");
+
+       /*getcwd*/
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) ||(cwd[0] == '\0')) {
+               _LOGE("@failed to get the current directory info.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#current working directory is %s", cwd);
+
+       /*change dir*/
+       ret = __ri_change_dir(TEMP_DIR);
+       if (ret == -1) {
+               _LOGE("@failed to change directory.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#switched to %s", TEMP_DIR);
+
+       /*run cpio script*/
+       const char *cpio_argv[] = { CPIO_SCRIPT, pkgfilepath, NULL };
+       ret = _ri_xsystem(cpio_argv);
+
+       /*get manifext.xml path*/
+       snprintf(manifest, BUF_SIZE, "%s/opt/share/packages/%s.xml", TEMP_DIR, pkgid);
+       _LOGD("#manifest name is %s", manifest);
+
+       if (access(manifest, F_OK)) {
+               _LOGD("#there is no RW manifest.xml. check RO manifest.xml.");
+
+               memset(manifest, '\0', sizeof(manifest));
+               snprintf(manifest, BUF_SIZE, "%s/usr/share/packages/%s.xml", TEMP_DIR, pkgid);
+               _LOGD("#manifest name is %s", manifest);
+
+               if (access(manifest, F_OK)) {
+                       _LOGE("@can not find manifest.xml in the pkg.");
+                       ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+                       goto err;
+               } else {
+                       home_dir = 0;
+               }
+
+#if 0  //disable "copy ro-xml to rw-xml", because of some bug
+               snprintf(srcpath, BUF_SIZE, "%s", manifest);
+               memset(manifest, '\0', sizeof(manifest));
+               snprintf(manifest, BUF_SIZE, "%s/%s.xml", MANIFEST_RW_DIRECTORY, pkgid);
+
+               const char *xml_update_argv[] = { CPIO_SCRIPT_UPDATE_XML, srcpath, manifest, NULL };
+               ret = _ri_xsystem(xml_update_argv);
+#endif
+       } else {
+               home_dir = 1;
+       }
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "install_percent", "30");
+
+       /*check manifest.xml validation*/
+       ret = pkgmgr_parser_check_manifest_validation(manifest);
+       if(ret < 0) {
+               _LOGE("@invalid manifest");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       /*check for signature and certificate*/
+       ret = _ri_verify_signatures(TEMP_DIR, pkgid);
+    if (ret < 0) {
+       _LOGE("@signature and certificate failed(%s).", pkgid);
+               ret = RPM_INSTALLER_ERR_SIG_INVALID;
+               goto err;
+    }
+    _LOGD("#_ri_verify_signatures success.");
+
+    /*chdir*/
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGE("@failed to change directory(%s)(%s)", cwd, strerror(errno));
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+#ifdef APP2EXT_ENABLE
+       ret = __get_location_from_xml(manifest, &location);
+       if (ret < 0) {
+               _LOGE("@Failed to get install location\n");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       } else {
+               if (location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) {
+                       _LOGD("#Install: external storage location");
+
+                       /*Get the rpm's size from rpm header*/
+                       rpm_size = _ri_calculate_rpm_size(pkgfilepath);
+                       if(rpm_size != 0){
+                               rpm_size = rpm_size/(1024*1024);      //rpm size in MB
+                               _LOGD("#Rpm file(%s) size is %lu MB",pkgfilepath,rpm_size);
+
+                               /*Add margin to the rpm size*/
+                               rpm_size = rpm_size + RPM_SIZE_MARGIN(rpm_size);
+                               _LOGD("#Rpm file (%s) size after margin is %lu MB",pkgfilepath,rpm_size);
+                       }else{
+                               _LOGE("@Failed to get size from rpm header\n");
+                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                               goto err;
+                       }
+
+                       /*
+                       Get the size from the manifest file.
+                       */
+                       ret = __get_size_from_xml(manifest, &size);
+                       if (ret != PMINFO_R_OK) {
+                               size = rpm_size;
+                               _LOGD(" #rpm size is %d MB",size);
+                       }else{
+                               size = size>rpm_size?size:rpm_size;
+                               _LOGD("#rpm size is %d MB",size);
+                       }
+               }
+       }
+
+       if ((location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) {
+               handle = app2ext_init(APP2EXT_SD_CARD);
+               if (handle == NULL) {
+                       _LOGE("@app2ext init failed\n");
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto err;
+               }
+               if ((&(handle->interface) != NULL) && (handle->interface.pre_install != NULL) && (handle->interface.post_install != NULL)){
+                       dir_list = __rpm_populate_dir_list();
+                       if (dir_list == NULL) {
+                               _LOGE("@ \nError in populating the directory list\n");
+                               app2ext_deinit(handle);
+                               ret = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+                               goto err;
+                       }
+                       ret = handle->interface.pre_install(gpkgname, dir_list, size);
+                       if (ret == APP2EXT_ERROR_MMC_STATUS) {
+                               _LOGE("@app2xt MMC is not here, go internal\n");
+                       } else if (ret == APP2EXT_SUCCESS){
+                               _LOGE("@pre_install done, go internal\n");
+                       }
+                       else {
+                               _LOGE("@app2xt pre install API failed (%d)\n", ret);
+                               __rpm_clear_dir_list(dir_list);
+                               handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED);
+                               app2ext_deinit(handle);
+                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                               goto err;
+                       }
+               }
+       }
+#endif
+
+
+       /*run script*/
+       if (home_dir == 0) {
+#if 0  //disable "INSTALL_SCRIPT_WITH_DBPATH_RO", because of some bug
+               const char *argv[] = { INSTALL_SCRIPT_WITH_DBPATH_RO, pkgfilepath, NULL };
+               ret = _ri_xsystem(argv);
+#endif
+               const char *argv[] = { INSTALL_SCRIPT, pkgfilepath, NULL };
+               ret = _ri_xsystem(argv);
+       } else {
+               const char *argv[] = { INSTALL_SCRIPT_WITH_DBPATH_RW, pkgfilepath, NULL };
+               ret = _ri_xsystem(argv);
+       }
+       if (ret != 0) {
+               _LOGE("@failed to install the pkg(%d).", ret);
+#ifdef APP2EXT_ENABLE
+               if ((handle != NULL) && (handle->interface.post_install != NULL)){
+                       __rpm_clear_dir_list(dir_list);
+                       handle->interface.post_install(gpkgname, APP2EXT_STATUS_FAILED);
+                       app2ext_deinit(handle);
+               }
+#endif
+               goto err;
+       }
+       _LOGD("#install success.");
+
+       /*write the storeclient-id to manifest.xml*/
+       if (clientid != NULL) {
+               if (home_dir == 0) {
+                       snprintf(resultxml, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+               } else {
+                       snprintf(resultxml, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+               }
+
+               const char *convert_argv[] = { RPM_UPDATE_XML, manifest, clientid, resultxml, NULL };
+               ret = _ri_xsystem(convert_argv);
+               if (ret != 0) {
+                       _LOGE("@Failed to convert the manifest.xml");
+                       goto err;
+               }
+
+               _LOGD("#client id[%s], input manifest:[%s], dest manifest:[%s]", clientid, manifest, resultxml);
+       }
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "install_percent", "60");
+
+#ifdef APP2EXT_ENABLE
+       if ((handle != NULL) && (handle->interface.post_install != NULL)){
+               __rpm_clear_dir_list(dir_list);
+               handle->interface.post_install(gpkgname, APP2EXT_STATUS_SUCCESS);
+               app2ext_deinit(handle);
+       }
+#endif
+
+       /*Parse the manifest to get install location and size. If installation fails, remove manifest info from DB*/
+       if (clientid != NULL) {
+               ret = pkgmgr_parser_parse_manifest_for_installation(resultxml, NULL);
+       } else {
+               ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+       }
+       if (ret < 0) {
+               _LOGE("@failed to parse the manifest.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#manifest parsing success");
+
+       /*register cert info*/
+       _ri_register_cert(pkgid);
+
+       /*search_ug_app*/
+       _coretpk_installer_search_ui_gadget(pkgid);
+
+       /*apply smack to shared dir*/
+       __rpm_apply_smack(pkgid, 1);
+
+       /*apply smack by privilege*/
+       ret = _ri_apply_privilege(pkgid, 0);
+       if (ret != 0) {
+               _LOGE("@failed to apply permission(%d).", ret);
+       }
+       _LOGD("#permission applying success.");
+
+       /*reload smack*/
+       ret = _ri_smack_reload_all();
+       if (ret != 0) {
+               _LOGD("@failed to reload_all the smack.");
+       }
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "install_percent", "100");
+
+err:
+       _rpm_delete_dir(TEMP_DIR);
+       _rpm_delete_dir(TEMP_DBPATH);
+
+        if (ret == RPM_INSTALLER_SUCCESS) {
+                _LOGD("[#]end : _rpm_install_pkg_with_dbpath");
+                __ri_launch_consumer(pkgid);
+               _ri_broadcast_status_notification(pkgid, "rpm", "end", "ok");
+               _ri_stat_cb(pkgid, "end", "ok");
+       } else {
+               _LOGE("[@]end : _rpm_install_pkg_with_dbpath");
+               /*remove db info*/
+               ret = _coretpk_installer_remove_db_info(pkgid);
+               if (ret < 0) {
+                       _LOGE("_coretpk_installer_remove_db_info is failed.");
+               }
+
+               char *errstr = NULL;
+               _ri_error_no_to_string(ret, &errstr);
+               _ri_broadcast_status_notification(pkgid, "rpm", "error", errstr);
+               _ri_stat_cb(pkgid, "error", errstr);
+               _ri_broadcast_status_notification(pkgid, "rpm", "end", "fail");
+               sleep(2);
+               _ri_stat_cb(pkgid, "end", "fail");
+               _LOGE("install failed with err(%d) (%s)\n", ret, errstr);
+       }
+
+       return ret;
+}
+
+int _rpm_upgrade_pkg_with_dbpath(char *pkgfilepath, char *pkgid)
+{
+       int ret = 0;
+       char manifest[BUF_SIZE] = { '\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       int home_dir = 0;
+       pkgmgrinfo_pkginfo_h pkghandle;
+       char *temp = NULL;
+#ifdef APP2EXT_ENABLE
+       app2ext_handle *handle = NULL;
+       GList *dir_list = NULL;
+       pkgmgrinfo_installed_storage location = 1;
+       int size = -1;
+       unsigned long rpm_size = 0;
+#endif
+       _ri_broadcast_status_notification(pkgid, "rpm", "start", "update");
+       _LOGD("[#]start : _rpm_upgrade_pkg_with_dbpath");
+
+       /*terminate running app*/
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       if (ret < 0) {
+               _LOGE("@failed to get pkginfo handle");
+               ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+               goto err;
+       }
+       pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+       /*getcwd*/
+       temp = getcwd(cwd, BUF_SIZE);
+       if ((temp == NULL) ||(cwd[0] == '\0')) {
+               _LOGE("@getcwd() failed.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#current working directory is %s.", cwd);
+
+       /*change dir*/
+       ret = __ri_change_dir(TEMP_DIR);
+       if (ret == -1) {
+               _LOGE("@change dir failed.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#switched to %s", TEMP_DIR);
+
+       /*run cpio script*/
+       const char *cpio_argv[] = { CPIO_SCRIPT, pkgfilepath, NULL };
+       ret = _ri_xsystem(cpio_argv);
+
+       /*get manifext.xml path*/
+       snprintf(manifest, BUF_SIZE, "%s/opt/share/packages/%s.xml", TEMP_DIR, pkgid);
+       _LOGD("#manifest name is %s.", manifest);
+
+       if (access(manifest, F_OK)) {
+               _LOGD("#there is no RW manifest.xml. check RO manifest.xml.");
+
+               memset(manifest, '\0', sizeof(manifest));
+               snprintf(manifest, BUF_SIZE, "%s/usr/share/packages/%s.xml", TEMP_DIR, pkgid);
+               _LOGD("#manifest name is %s.", manifest);
+
+               if (access(manifest, F_OK)) {
+                       _LOGE("@can not find manifest.xml in the pkg.");
+                       ret = RPM_INSTALLER_ERR_NO_MANIFEST;
+                       goto err;
+               } else {
+                       home_dir = 0;
+               }
+
+#if 0  //disable "copy ro-xml to rw-xml", because of some bug
+               snprintf(srcpath, BUF_SIZE, "%s", manifest);
+               memset(manifest, '\0', sizeof(manifest));
+               snprintf(manifest, BUF_SIZE, "%s/%s.xml", MANIFEST_RW_DIRECTORY, pkgid);
+
+               const char *xml_update_argv[] = { CPIO_SCRIPT_UPDATE_XML, srcpath, manifest, NULL };
+               ret = _ri_xsystem(xml_update_argv);
+#endif
+       } else {
+               home_dir = 1;
+       }
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "install_percent", "30");
+
+       /*check manifest.xml validation*/
+       ret = pkgmgr_parser_check_manifest_validation(manifest);
+       if(ret < 0) {
+               _LOGE("@invalid manifest");
+               ret = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+               goto err;
+       }
+
+       /*check for signature and certificate*/
+       ret = _ri_verify_signatures(TEMP_DIR, pkgid);
+    if (ret < 0) {
+               _LOGE("@signature and certificate failed(%s).", pkgid);
+               ret = RPM_INSTALLER_ERR_SIG_INVALID;
+               goto err;
+    }
+    _LOGD("#_ri_verify_signatures success.");
+
+    /*chdir*/
+       ret = chdir(cwd);
+       if (ret != 0) {
+               _LOGE("@chdir(%s) failed(%s).", cwd, strerror(errno));
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+
+    /*remove dir for clean*/
+       __ri_remove_updated_dir(pkgid);
+
+       _LOGD("#Preserve the smack file");
+       /*Preserve the smack rule file */
+       ret = __ri_copy_smack_rule_file(UPGRADE_REQ,pkgid,0);
+       if(ret != RPM_INSTALLER_SUCCESS)
+               goto err;
+#ifdef APP2EXT_ENABLE
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(gpkgname, &pkghandle);
+       if (ret < 0) {
+               _LOGE("Failed to get pkginfo handle\n");
+               ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+               goto err;
+       } else {
+               ret = pkgmgrinfo_pkginfo_get_installed_storage(pkghandle, &location);
+               if (ret < 0) {
+                       _LOGE("Failed to get install location\n");
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                       goto err;
+               } else {
+                       if (location == PMINFO_EXTERNAL_STORAGE) {
+                               /*Get the rpm's size from rpm header*/
+                               rpm_size = _ri_calculate_rpm_size(pkgfilepath);
+                               if(rpm_size != 0){
+                                       rpm_size = rpm_size/(1024*1024);      //rpm size in MB
+                                       _LOGD("#Rpm file(%s) size is %lu MB",pkgfilepath,rpm_size);
+
+                                       /*Add margin to the rpm size*/
+                                       rpm_size = rpm_size + RPM_SIZE_MARGIN(rpm_size);
+                                       _LOGD("#Rpm file (%s) size after margin is %lu MB",pkgfilepath,rpm_size);
+                               }else{
+                                       _LOGE("@Failed to get size from rpm header\n");
+                                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                                       goto err;
+                               }
+
+                               /*
+                               Get the size from the manifest file.
+                               */
+                               ret = __get_size_from_xml(manifest, &size);
+                               if (ret != PMINFO_R_OK) {
+                                       size = rpm_size;
+                                       _LOGD(" #rpm size is %d",size);
+                               }else{
+                                       size = size>rpm_size?size:rpm_size;
+                                       _LOGD("#rpm size is %d",size);
+                               }
+                       }
+               }
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+               if ((location == PMINFO_EXTERNAL_STORAGE) && size > 0) {
+                       handle = app2ext_init(APP2EXT_SD_CARD);
+                       if (handle == NULL) {
+                               _LOGE("app2ext init failed\n");
+                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                               goto err;
+                       }
+                       if ((&(handle->interface) != NULL) && (handle->interface.pre_upgrade != NULL) && (handle->interface.post_upgrade != NULL)){
+                               dir_list = __rpm_populate_dir_list();
+                               if (dir_list == NULL) {
+                                       _LOGE("\nError in populating the directory list\n");
+                                       ret = RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
+                                       app2ext_deinit(handle);
+                                       goto err;
+                               }
+                               ret = handle->interface.pre_upgrade(gpkgname, dir_list, size);
+                               if (ret == APP2EXT_ERROR_MMC_STATUS ) {
+                                       _LOGE("app2xt MMC is not here, go internal (%d)\n", ret);
+                               }else if(ret == APP2EXT_SUCCESS){
+                                       _LOGE("pre upgrade done, go internal");
+                               }else {
+                                       _LOGE("app2xt pre upgrade API failed (%d)\n", ret);
+                                       __rpm_clear_dir_list(dir_list);
+                                       handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED);
+                                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                                       app2ext_deinit(handle);
+                                       goto err;
+                               }
+                       }
+               }
+       }
+#endif
+
+       /*run script*/
+       if (home_dir == 0) {
+#if 0  //disable "UPGRADE_SCRIPT_WITH_DBPATH_RO", because of some bug
+               const char *argv[] = { UPGRADE_SCRIPT_WITH_DBPATH_RO, pkgfilepath, NULL };
+               ret = _ri_xsystem(argv);
+#endif
+               const char *argv[] = { UPGRADE_SCRIPT, pkgfilepath, NULL };
+               ret = _ri_xsystem(argv);
+       } else {
+               const char *argv[] = { UPGRADE_SCRIPT_WITH_DBPATH_RW, pkgfilepath, NULL };
+               ret = _ri_xsystem(argv);
+       }
+       if (ret != 0) {
+               _LOGE("@upgrade complete with error(%d)", ret);
+#ifdef APP2EXT_ENABLE
+               if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){
+                       __rpm_clear_dir_list(dir_list);
+                       handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED);
+                       app2ext_deinit(handle);
+               }
+#endif
+               goto err;
+       }
+       _LOGD("#upgrade script success.");
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "install_percent", "60");
+
+       /*Parse the manifest to get install location and size. If fails, remove manifest info from DB.*/
+       ret = pkgmgr_parser_parse_manifest_for_upgrade(manifest, NULL);
+       if (ret < 0) {
+               _LOGE("@parsing manifest failed.");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto err;
+       }
+       _LOGD("#parsing manifest success.");
+
+       /*unregister cert info*/
+       _ri_unregister_cert(pkgid);
+
+       /*register cert info*/
+       _ri_register_cert(pkgid);
+
+#ifdef APP2EXT_ENABLE
+       if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){
+               __rpm_clear_dir_list(dir_list);
+               handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_SUCCESS);
+               app2ext_deinit(handle);
+       }
+#endif
+
+       /*search_ug_app*/
+       _coretpk_installer_search_ui_gadget(pkgid);
+
+       /*apply smack to shared dir*/
+       __rpm_apply_smack(pkgid, 1);
+
+       /*apply smack by privilege*/
+       ret = _ri_apply_privilege(pkgid, 0);
+       if (ret != 0) {
+               _LOGE("@apply perm failed with err(%d)", ret);
+       }
+       _LOGD("#apply perm success.");
+
+       /*reload smack*/
+       ret = _ri_smack_reload_all();
+       if (ret != 0) {
+               _LOGD("_ri_smack_reload_all failed.");
+       }
+
+       /*send event for install_percent*/
+       _ri_broadcast_status_notification(pkgid, "rpm", "install_percent", "100");
+
+err:
+       _rpm_delete_dir(TEMP_DIR);
+       _rpm_delete_dir(TEMP_DBPATH);
+
+        if (ret == RPM_INSTALLER_SUCCESS) {
+                _LOGD("[#]end : _rpm_upgrade_pkg_with_dbpath");
+                __ri_launch_consumer(pkgid);
+               _ri_broadcast_status_notification(pkgid, "rpm", "end", "ok");
+               _ri_stat_cb(pkgid, "end", "ok");
+       } else {
+                _LOGE("[@]end : _rpm_upgrade_pkg_with_dbpath");
+               char *errstr = NULL;
+               _ri_error_no_to_string(ret, &errstr);
+               _ri_broadcast_status_notification(pkgid, "rpm", "error", errstr);
+               _ri_stat_cb(pkgid, "error", errstr);
+               _ri_broadcast_status_notification(pkgid, "rpm", "end", "fail");
+               sleep(2);
+               _ri_stat_cb(pkgid, "end", "fail");
+               _LOGE("install failed with err(%d) (%s)\n", ret, errstr);
+       }
+
+       return ret;
+}
+
+int _rpm_uninstall_pkg_with_dbpath(const char *pkgid, bool is_system)
+{
+       if (pkgid == NULL) {
+               _LOGE("pkgid is NULL.");
+               return -1;
+       }
+
+       int ret = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       char tizen_manifest[BUF_SIZE] = {'\0'};
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
+       bool mother_package = false;
+       bool coretpk = false;
+
+       #ifdef APP2EXT_ENABLE
+       app2ext_handle *handle = NULL;
+       pkgmgrinfo_installed_storage location = 1;
+       #endif
+
+       _LOGD("pkgid=[%s], is_system=[%d]", pkgid, is_system);
+
+       snprintf(tizen_manifest, BUF_SIZE, "%s/%s/tizen-manifest.xml", OPT_USR_APPS, pkgid);
+       if (access(tizen_manifest, R_OK) == 0) {
+               coretpk = true;
+               _LOGD("[%s] is existed.", tizen_manifest);
+       }
+
+       // send start event
+       if (is_system)
+               _ri_broadcast_status_notification(pkgid, coretpk ? "coretpk" : "rpm", "start", "update");
+       else
+               _ri_broadcast_status_notification(pkgid, coretpk ? "coretpk" : "rpm", "start", "uninstall");
+
+       // terminate running app
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       if (ret < 0) {
+               _LOGE("pkgmgrinfo_pkginfo_get_pkginfo(%s) failed.", pkgid);
+               ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+               goto end;
+       }
+       pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+
+       // If package is mother package, then uninstall child package
+/*     pkgmgrinfo_pkginfo_is_mother_package(pkghandle, &mother_package);
+       if (mother_package == true) {
+               _LOGD("[%s] is mother package", pkgid);
+               __uninstall_child_package_by_mother_pkgid(pkgid);
+       }*/
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+
+       snprintf(tizen_manifest, BUF_SIZE, "%s/%s/tizen-manifest.xml", OPT_USR_APPS, pkgid);
+       if (access(tizen_manifest, R_OK) == 0) {
+               coretpk = true;
+               _LOGD("[%s] is existing.", tizen_manifest);
+       }
+
+       // del root path dir
+       snprintf(buff, BUF_SIZE, "%s/%s", OPT_USR_APPS, pkgid);
+       if (__is_dir(buff)) {
+               _rpm_delete_dir(buff);
+       }
+
+       // del root path dir for ext
+       if (_coretpk_installer_get_configuration_value(INI_VALUE_MAKE_EXT_DIRECTORY)) {
+               char extpath[BUF_SIZE] = {'\0'};
+               snprintf(extpath, BUF_SIZE, "%s/%s", OPT_STORAGE_SDCARD_APP_ROOT, pkgid);
+               if (__is_dir(extpath)) {
+                       _rpm_delete_dir(extpath);
+               }
+       }
+
+       // del manifest
+       memset(buff, '\0', BUF_SIZE);
+       snprintf(buff, BUF_SIZE, "%s/%s.xml", OPT_SHARE_PACKAGES, pkgid);
+       (void)remove(buff);
+
+       // check system pkg, if pkg is system pkg, need to update xml on USR_SHARE_PACKAGES
+       if (is_system) {
+               memset(buff, '\0', BUF_SIZE);
+               snprintf(buff, BUF_SIZE, "%s/%s.xml", USR_SHARE_PACKAGES, pkgid);
+               _LOGE("manifest for upgrade, path=[%s]",buff);
+               ret = pkgmgr_parser_parse_manifest_for_upgrade(buff, NULL);
+               if (ret < 0) {
+                       _LOGE("parsing manifest failed.");
+               }
+               goto end;
+       } else {
+#ifdef APP2EXT_ENABLE
+               ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+               if (ret < 0) {
+                       _LOGE("failed to get pkginfo handle");
+                       ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+                       goto end;
+               }
+               ret = pkgmgrinfo_pkginfo_get_installed_storage(pkghandle, &location);
+               if (ret < 0) {
+                       _LOGE("failed to get install location\n");
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+                       return RPM_INSTALLER_ERR_INTERNAL;
+               }
+
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+               if (location == PMINFO_EXTERNAL_STORAGE) {
+                       handle = app2ext_init(APP2EXT_SD_CARD);
+                       if (handle == NULL) {
+                               _LOGE("app2ext init failed\n");
+                               return RPM_INSTALLER_ERR_INTERNAL;
+                       }
+                       if ((&(handle->interface) != NULL) && (handle->interface.pre_uninstall != NULL) && (handle->interface.post_uninstall != NULL) &&
+                                       (handle->interface.disable != NULL)){
+                               ret = handle->interface.disable(pkgid);
+                               if (ret != APP2EXT_SUCCESS) {
+                                       _LOGE("Unmount ret[%d]", ret);
+                               }
+                               ret = app2ext_get_app_location(pkgid);
+                               if (ret == APP2EXT_INTERNAL_MEM){
+                                       _LOGE("app2xt APP is not in MMC, go internal (%d)\n", ret);
+                               }
+                               else {
+                                       ret = handle->interface.pre_uninstall(pkgid);
+                                       if (ret == APP2EXT_ERROR_MMC_STATUS ) {
+                                               _LOGE("app2xt MMC is not here, go internal (%d)\n", ret);
+                                       }else if (ret == APP2EXT_SUCCESS){
+                                               _LOGE("pre uninstall done, go to internal");
+                                       }else {
+                                               _LOGE("app2xt pre uninstall API failed (%d)\n", ret);
+                                               handle->interface.post_uninstall(pkgid);
+                                               app2ext_deinit(handle);
+                                               return RPM_INSTALLER_ERR_INTERNAL;
+                                       }
+                               }
+                       }
+               }
+#endif
+
+               // del db info
+               ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+               if (ret < 0) {
+                       _LOGE("pkgmgr_parser_parse_manifest_for_uninstallation() failed, pkgid=[%s]", pkgid);
+               }
+
+#ifdef APP2EXT_ENABLE
+               if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
+                       handle->interface.post_uninstall(pkgid);
+                       app2ext_deinit(handle);
+               }
+#endif
+
+       }
+
+       // execute privilege APIs
+       _ri_privilege_revoke_permissions(pkgid);
+       _ri_privilege_unregister_package(pkgid);
+
+       // Unregister cert info
+       _ri_unregister_cert(pkgid);
+
+end:
+       // Restore the old smack file
+       if (coretpk == false) {
+               ret = __ri_copy_smack_rule_file(UNINSTALL_REQ,pkgid,is_system);
+               if (ret != RPM_INSTALLER_SUCCESS){
+                       _LOGD("smack restore failed");
+               }else{
+                       /*reload smack*/
+                       ret = _ri_smack_reload_all();
+                       if (ret != 0) {
+                               _LOGD("_ri_smack_reload_all failed.");
+                       }
+               }
+       }
+
+       if (ret != 0) {
+               _LOGE("failed, ret=[%d]", ret);
+               char *errstr = NULL;
+               _ri_error_no_to_string(ret, &errstr);
+               _ri_broadcast_status_notification(pkgid, coretpk ? "coretpk" : "rpm", "error",  errstr);
+               _ri_stat_cb(pkgid, "error", errstr);
+               sleep(2);
+               _ri_broadcast_status_notification(pkgid, coretpk ? "coretpk" : "rpm", "end",  "fail");
+               _ri_stat_cb(pkgid, "end", "fail");
+               _LOGE("remove failed with err(%d) (%s)\n", ret, errstr);
+       } else {
+               _LOGE("success");
+               _ri_broadcast_status_notification(pkgid, coretpk ? "coretpk" : "rpm", "end", "ok");
+               _ri_stat_cb(pkgid, "end", "ok");
+       }
+
+       return ret;
+}
+
+int _rpm_uninstall_pkg(char *pkgid)
+{
+       int ret = 0;
+       int err = 0;
+       bool is_update = 0;
+       bool is_system = 0;
+       bool is_removable = 0;
+       char buff[BUF_SIZE] = {'\0'};
+       pkgmgrinfo_install_location location = 1;
+#ifdef APP2EXT_ENABLE
+       app2ext_handle *handle = NULL;
+#endif
+       char *manifest = NULL;
+       pkgmgrinfo_pkginfo_h pkghandle;
+       const char *argv[] = { UNINSTALL_SCRIPT, pkgid, NULL };
+
+       _LOGD("start : _rpm_uninstall_pkg\n");
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkghandle);
+       if (ret < 0) {
+               _LOGE("Failed to get pkginfo handle\n");
+               return RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+       }
+       /*terminate running app*/
+       pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+
+       ret = pkgmgrinfo_pkginfo_is_system(pkghandle, &is_system);
+       if (ret < 0) {
+               _LOGE("pkgmgrinfo_pkginfo_is_system failed.\n");
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+       if (is_system) {
+               ret = pkgmgrinfo_pkginfo_is_update(pkghandle, &is_update);
+               if (ret < 0) {
+                       _LOGE("pkgmgrinfo_pkginfo_is_system failed.\n");
+                       return RPM_INSTALLER_ERR_INTERNAL;
+               }
+               if (is_update) {
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+                       /*updated and system pkg need to "remove-update"*/
+                       _LOGD("Remove Update[%s]",pkgid);
+                       ret = _rpm_uninstall_pkg_with_dbpath(pkgid, 1);
+                       if (ret < 0) {
+                               _LOGE("uninstall_pkg_with_dbpath for system, is_update fail\n");
+                       }
+                       return 0;
+               }
+       } else {
+               pkgmgrinfo_pkginfo_is_removable(pkghandle, &is_removable);
+               if (is_removable) {
+                       /*non-system and can be removable,  it should be deleted*/
+                       _LOGD("Delete Package [%s]",pkgid);
+                       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+                       ret = _rpm_uninstall_pkg_with_dbpath(pkgid, 0);
+                       if (ret < 0) {
+                               _LOGE("uninstall_pkg_with_dbpath for non-system, is_remove fail\n");
+                       }
+                       return 0;
+               }
+       }
+
+       _ri_broadcast_status_notification(pkgid, "rpm", "start", "uninstall");
+
+#ifdef APP2EXT_ENABLE
+       ret = pkgmgrinfo_pkginfo_get_install_location(pkghandle, &location);
+       if (ret < 0) {
+               _LOGE("Failed to get install location\n");
+               pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       pkgmgrinfo_appinfo_get_list(pkghandle, PM_UI_APP, __ri_check_running_app, NULL);
+
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
+       if (location == PMINFO_INSTALL_LOCATION_PREFER_EXTERNAL) {
+               handle = app2ext_init(APP2EXT_SD_CARD);
+               if (handle == NULL) {
+                       _LOGE("app2ext init failed\n");
                        return RPM_INSTALLER_ERR_INTERNAL;
-               } else {
-                       if (location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) {
-                               ret = pkgmgr_pkginfo_get_package_size(pkghandle, &size);
-                               if (ret < 0) {
-                                       _d_msg(DEBUG_ERR, "Failed to get package size\n");
-                                       pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
-                                       unlink(manifest);
-                                       return RPM_INSTALLER_ERR_INTERNAL;
-                               }
-                       }
                }
-               pkgmgr_pkginfo_destroy_pkginfo(pkghandle);
-               if ((location == PM_INSTALL_LOCATION_PREFER_EXTERNAL) && size > 0) {
-                       handle = app2ext_init(APP2EXT_SD_CARD);
-                       if (handle == NULL) {
-                               _d_msg(DEBUG_ERR, "app2ext init failed\n");
-                               unlink(manifest);
-                               return RPM_INSTALLER_ERR_INTERNAL;
+               if ((&(handle->interface) != NULL) && (handle->interface.pre_uninstall != NULL) && (handle->interface.post_uninstall != NULL)){
+                       ret = app2ext_get_app_location(pkgid);
+                       if (ret == APP2EXT_INTERNAL_MEM){
+                                       _LOGE("app2xt APP is not in MMC, go internal (%d)\n", ret);
                        }
-                       if ((&(handle->interface) != NULL) && (handle->interface.pre_upgrade != NULL) && (handle->interface.post_upgrade != NULL)){
-                               dir_list = __rpm_populate_dir_list();
-                               if (dir_list == NULL) {
-                                       _d_msg(DEBUG_ERR, "\nError in populating the directory list\n");
-                                       return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
-                               }
-                               ret = handle->interface.pre_upgrade(gpkgname, dir_list, size);
+                       else {
+                               ret = handle->interface.pre_uninstall(pkgid);
                                if (ret == APP2EXT_ERROR_MMC_STATUS || ret == APP2EXT_SUCCESS ) {
-                                       _d_msg(DEBUG_ERR, "app2xt MMC is not here, go internal (%d)\n", ret);
+                                       _LOGE("app2xt MMC is not here, go internal (%d)\n", ret);
                                }
                                else {
-                                       _d_msg(DEBUG_ERR, "app2xt pre upgrade API failed (%d)\n", ret);
-                                       __rpm_clear_dir_list(dir_list);
-                                       handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED);
-                                       unlink(manifest);
+                                       _LOGE("app2xt pre uninstall API failed (%d)\n", ret);
+                                       handle->interface.post_uninstall(pkgid);
+                                       app2ext_deinit(handle);
                                        return RPM_INSTALLER_ERR_INTERNAL;
                                }
                        }
@@ -757,52 +3602,125 @@ int _rpm_upgrade_pkg(char *pkgfilepath, char *installoptions)
        }
 #endif
 
-       err = __rpm_xsystem(argv);
-       if (err != 0) {
-               _d_msg(DEBUG_ERR, "upgrade complete with error(%d)\n", err);
-               /*remove manifest info*/
+#ifdef PRE_CHECK_FOR_MANIFEST
+       /*Manifest info should be removed first because after installation manifest
+       file is uninstalled. If uninstallation fails, we need to re-insert manifest info for consistency*/
+       manifest = pkgmgr_parser_get_manifest_file(pkgid);
+       if (manifest == NULL) {
+               _LOGE("manifest name is NULL\n");
+               app2ext_deinit(handle);
+               return RPM_INSTALLER_ERR_NO_MANIFEST;
+       }
+       _LOGD("manifest name is %s\n", manifest);
+       ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
+       if (ret < 0) {
+               _LOGE("pkgmgr_parser_parse_manifest_for_uninstallation failed.\n");
+       }
+
+#endif
+
+       ret = _rpm_xsystem(argv);
+       if (ret != 0) {
+               _LOGE("uninstall failed with error(%d)\n", ret);
                #ifdef PRE_CHECK_FOR_MANIFEST
-               pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL);
+               err = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+               if (err < 0) {
+                       _LOGE("Parsing Manifest Failed\n");
+               }
+               if (manifest) {
+                       free(manifest);
+                       manifest = NULL;
+               }
                #endif
                #ifdef APP2EXT_ENABLE
-               if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){
-                       __rpm_clear_dir_list(dir_list);
-                       handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_FAILED);
+               if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
+                       handle->interface.post_uninstall(pkgid);
+                       app2ext_deinit(handle);
                }
                #endif
-               unlink(manifest);
-               return err;
+               return ret;
        }
+
 #ifdef APP2EXT_ENABLE
-       if ((handle != NULL) && (handle->interface.post_upgrade != NULL)){
-               __rpm_clear_dir_list(dir_list);
-               handle->interface.post_upgrade(gpkgname, APP2EXT_STATUS_SUCCESS);
+       if ((handle != NULL) && (handle->interface.post_uninstall != NULL)){
+               handle->interface.post_uninstall(pkgid);
                app2ext_deinit(handle);
        }
 #endif
-#ifndef PRE_CHECK_FOR_MANIFEST
-       mfst = pkgmgr_parser_get_manifest_file(gpkgname);
-       if (mfst == NULL) {
-               _d_msg(DEBUG_ERR, "manifest name is NULL\n");
-               unlink(manifest);
-               return RPM_INSTALLER_ERR_INTERNAL;
-       }
-       pkgmgr_parser_parse_manifest_for_upgrade(mfst, NULL);
-       if (mfst) {
-               free(mfst);
-               mfst = NULL;
+
+#ifdef PRE_CHECK_FOR_MANIFEST
+       if (manifest) {
+               free(manifest);
+               manifest = NULL;
        }
 #endif
-       unlink(manifest);
-       return err;
+       /* Uninstallation Success. Remove the installation time key from vconf*/
+       snprintf(buff, BUF_SIZE, "db/app-info/%s/installed-time", pkgid);
+       err = vconf_unset(buff);
+       if (err) {
+               _LOGE("unset installation time failed\n");
+       }
+       /*execute privilege APIs*/
+       _ri_privilege_revoke_permissions(pkgid);
+       _ri_privilege_unregister_package(pkgid);
+       /*Unregister cert info*/
+       _ri_unregister_cert(gpkgname);
+
+       _LOGD("end : _rpm_uninstall_pkg(%d)\n", ret);
+       return ret;
+}
+
+int _rpm_install_corexml(char *pkgfilepath, char *pkgid)
+{
+       int ret = 0;
+       /*validate signature and certifictae*/
+       ret = _ri_verify_signatures(USR_APPS, pkgid);
+    if (ret < 0) {
+               _LOGE("_ri_verify_signatures Failed : %s\n", pkgid);
+               ret = RPM_INSTALLER_ERR_SIG_INVALID;
+               goto err;
+    }
+
+       /* check : given pkgid is deactivation*/
+       ret = __ri_check_pkgid_for_deactivation(pkgid);
+       if (ret < 0) {
+               _LOGE("pkgid[%s] for deactivation dont need to install.\n", pkgid);
+               goto err;
+       }
+
+       /* Parse and insert manifest in DB*/
+    ret = pkgmgr_parser_parse_manifest_for_installation(pkgfilepath, NULL);
+    if (ret < 0) {
+               _LOGD("Installing Manifest Failed : %s\n", pkgfilepath);
+               ret = RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED;
+               goto err;
+    }
+
+    // _ri_register_cert has __ri_free_cert_chain.
+    _ri_register_cert(pkgid);
+
+       /*search_ug_app*/
+       _coretpk_installer_search_ui_gadget(pkgid);
+
+       ret = RPM_INSTALLER_SUCCESS;
+
+err:
+       if (ret != 0) {
+               __ri_free_cert_chain();
+       }
+
+       return ret;
+
 }
 
 int _rpm_move_pkg(char *pkgid, int move_type)
 {
+#if 0
        app2ext_handle *hdl = NULL;
        int ret = 0;
        int movetype = -1;
        GList *dir_list = NULL;
+       pkgmgrinfo_pkginfo_h pkghandle = NULL;
 
        if (move_type == PM_MOVE_TO_INTERNAL)
                movetype = APP2EXT_MOVE_TO_PHONE;
@@ -811,24 +3729,515 @@ int _rpm_move_pkg(char *pkgid, int move_type)
        else
                return RPM_INSTALLER_ERR_WRONG_PARAM;
 
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(gpkgname,&pkghandle);
+       if(ret < 0){
+               _LOGE("@failed to get the pkginfo handle!!");
+               ret = RPM_INSTALLER_ERR_PKG_NOT_FOUND;
+               return ret;
+       }
+       /* Terminate the running instance of app */
+       pkgmgrinfo_appinfo_get_list(pkghandle,PM_UI_APP,__ri_check_running_app,NULL);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(pkghandle);
        hdl = app2ext_init(APP2EXT_SD_CARD);
        if ((hdl != NULL) && (hdl->interface.move != NULL)){
-               dir_list = __rpm_move_dir_list();
+               dir_list = __rpm_populate_dir_list();
                if (dir_list == NULL) {
-                       _d_msg(DEBUG_ERR, "\nError in populating the directory list\n");
+                       _LOGE("\nError in populating the directory list\n");
                        return RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS;
                }
                ret = hdl->interface.move(pkgid, dir_list, movetype);
                __rpm_clear_dir_list(dir_list);
                if (ret != 0) {
-                       _d_msg(DEBUG_ERR, "Failed to move app\n");
+                       _LOGE("Failed to move app\n");
                        return RPM_INSTALLER_ERR_INTERNAL;
+               }else{
+                       if(move_type == PM_MOVE_TO_INTERNAL){
+                               _LOGD("#updating the installed storage from external to internal");
+                               ret = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_INTERNAL);
+                       }
+                       else{
+                               _LOGD("#updating the installed storage from internal to external");
+                               ret = pkgmgrinfo_pkginfo_set_installed_storage(pkgid, INSTALL_EXTERNAL);
+                       }
+
+                       if(ret != PMINFO_R_OK){
+                               _LOGE("@failed to udpate the installed storage");
+                               return RPM_INSTALLER_ERR_INTERNAL;
+                       }
                }
                app2ext_deinit(hdl);
                return RPM_INSTALLER_SUCCESS;
        } else {
-               _d_msg(DEBUG_ERR,"Failed to get app2ext handle\n");
+               _LOGE("Failed to get app2ext handle\n");
                return RPM_INSTALLER_ERR_INTERNAL;
        }
+#endif
+       return 0;
+}
+
+int _rpm_process_cscxml(char *csc_script)
+{
+       int ret = 0;
+       int op_type = 0;
+
+       char *path_str = NULL;
+       char *op_str = NULL;
+       char *remove_str = NULL;
+       char csc_str[BUF_SIZE] = {'\0'};
+       snprintf(csc_str, BUF_SIZE - 1, "%s:", csc_script);
+
+       /*get params from csc script*/
+       path_str = __ri_get_str(csc_str, TOKEN_PATH_STR);
+       op_str = __ri_get_str(csc_str, TOKEN_OPERATION_STR);
+       remove_str = __ri_get_str(csc_str, TOKEN_REMOVE_STR);
+       if((path_str == NULL) || (op_str == NULL) || (remove_str == NULL)){
+               _LOGE("csc-info : input param is null[%s, %s, %s]\n", path_str, op_str, remove_str);
+               goto end;
+       }
+       _LOGD("csc-info : path=%s, op=%s, remove=%s\n", path_str, op_str, remove_str);
+
+       /*get operation type*/
+       op_type = __ri_get_op_type(op_str);
+       if(op_type < 0){
+               _LOGE("csc-info : operation error[%s, %s]\n", path_str, op_str);
+               goto end;
+       }
+
+       switch (op_type) {
+               case INSTALL_REQ:
+                       ret = __ri_install_csc(path_str, remove_str);
+                       break;
+
+               case UPGRADE_REQ:
+                       ret = __ri_install_csc(path_str, remove_str);
+                       break;
+
+               case UNINSTALL_REQ:
+                       ret = __ri_uninstall_csc(path_str);
+                       break;
+
+               default:
+                       break;
+       }
+
+       if (ret < 0)
+               _LOGE("fota-info : Fota fail [pkgid=%s, operation=%d]\n",path_str, op_type);
+
+end:
+       if(path_str)
+               free(path_str);
+       if(op_str)
+               free(op_str);
+       if(remove_str)
+               free(remove_str);
+
+       return ret;
+}
+
+int _rpm_process_csc_coretpk(char *csc_script)
+{
+       int ret = 0;
+       int op_type = 0;
+
+       char *path_str = NULL;
+       char *op_str = NULL;
+       char *remove_str = NULL;
+       char csc_str[BUF_SIZE] = {'\0'};
+       snprintf(csc_str, BUF_SIZE - 1, "%s:", csc_script);
+
+       /*get params from csc script*/
+       path_str = __ri_get_str(csc_str, TOKEN_PATH_STR);
+       op_str = __ri_get_str(csc_str, TOKEN_OPERATION_STR);
+       remove_str = __ri_get_str(csc_str, TOKEN_REMOVE_STR);
+       if((path_str == NULL) || (op_str == NULL) || (remove_str == NULL)){
+               _LOGE("csc-info : input param is null[%s, %s, %s]\n", path_str, op_str, remove_str);
+               goto end;
+       }
+       _LOGD("csc-info : path=%s, op=%s, remove=%s\n", path_str, op_str, remove_str);
+
+       /*get operation type*/
+       op_type = __ri_get_op_type(op_str);
+       if(op_type < 0){
+               _LOGE("csc-info : operation error[%s, %s]\n", path_str, op_str);
+               goto end;
+       }
+
+       switch (op_type) {
+               case INSTALL_REQ:
+                       ret = _coretpk_installer_csc_install(path_str, remove_str);
+                       break;
+
+               case UPGRADE_REQ:
+                       ret = _coretpk_installer_csc_install(path_str, remove_str);
+                       break;
+
+               case UNINSTALL_REQ:
+                       ret = __ri_uninstall_csc(path_str);
+                       break;
+
+               default:
+                       break;
+       }
+
+       if (ret < 0)
+               _LOGE("csc-info : csc fail [pkgid=%s, operation=%d]\n",path_str, op_type);
+
+end:
+       if(path_str)
+               free(path_str);
+       if(op_str)
+               free(op_str);
+       if(remove_str)
+               free(remove_str);
+
+       return ret;
+}
+
+int _rpm_process_fota(char *fota_script)
+{
+       int ret = 0;
+       int op_type = 0;
+       char *pkgid = NULL;
+       char *op_str = NULL;
+
+       char csc_str[BUF_SIZE] = {'\0'};
+       snprintf(csc_str, BUF_SIZE - 1, "%s:", fota_script);
+
+       /*get params from fota script*/
+       pkgid = __ri_get_str(csc_str, TOKEN_PATH_STR);
+       op_str = __ri_get_str(csc_str, TOKEN_OPERATION_STR);
+       if((pkgid == NULL) || (op_str == NULL)){
+               _LOGE("fota-info : input param is null[%s, %s]\n", pkgid, op_str);
+               goto end;
+       }
+       _LOGD("fota-info : path=%s, op=%s\n", pkgid, op_str);
+
+       /*get operation type*/
+       op_type = __ri_get_op_type(op_str);
+       if(op_type < 0){
+               _LOGE("fota-info : operation error[%s, %s]\n", pkgid, op_str);
+               goto end;
+       }
+
+       switch (op_type) {
+               case INSTALL_REQ:
+                       ret = __ri_install_fota(pkgid);
+                       break;
+
+               case UPGRADE_REQ:
+                       ret = __ri_upgrade_fota(pkgid);
+                       break;
+
+               case UNINSTALL_REQ:
+                       ret = __ri_uninstall_fota(pkgid);
+                       break;
+
+               default:
+                       break;
+       }
+
+       if (ret < 0)
+               _LOGE("fota-info : Fota fail [pkgid=%s, operation=%d]\n",pkgid, op_type);
+
+end:
+       if(pkgid)
+               free(pkgid);
+       if(op_str)
+               free(op_str);
+
+       return ret;
+}
+
+int _rpm_process_fota_for_rw(char *fota_script)
+{
+       int ret = 0;
+       int op_type = 0;
+       char *pkgid = NULL;
+       char *op_str = NULL;
+
+       char fota_str[BUF_SIZE] = {'\0'};
+       snprintf(fota_str, BUF_SIZE - 1, "%s:", fota_script);
+
+       /*get params from fota script*/
+       pkgid = __ri_get_str(fota_str, TOKEN_PATH_STR);
+       op_str = __ri_get_str(fota_str, TOKEN_OPERATION_STR);
+       if((pkgid == NULL) || (op_str == NULL)){
+               _LOGE("fota-info : input param is null[%s, %s]\n", pkgid, op_str);
+               goto end;
+       }
+       _LOGD("fota-info : path=%s, op=%s\n", pkgid, op_str);
+
+       /*get operation type*/
+       op_type = __ri_get_op_type(op_str);
+       if(op_type < 0){
+               _LOGE("fota-info : operation error[%s, %s]\n", pkgid, op_str);
+               goto end;
+       }
+
+       switch (op_type) {
+               case INSTALL_REQ:
+                       ret = __ri_install_fota_for_rw(pkgid);
+                       break;
+
+               case UPGRADE_REQ:
+                       ret = __ri_upgrade_fota_for_rw(pkgid);
+                       break;
+
+               case UNINSTALL_REQ:
+                       ret = __ri_uninstall_fota_for_rw(pkgid);
+                       break;
+
+               default:
+                       break;
+       }
+
+       if (ret < 0)
+               _LOGE("fota-info : Fota fail [pkgid=%s, operation=%d]\n",pkgid, op_type);
+
+end:
+       if(pkgid)
+               free(pkgid);
+       if(op_str)
+               free(op_str);
+
+       sync();
+
+       return ret;
+}
+
+int _rpm_process_enable(char *pkgid)
+{
+       int ret = 0;
+       char *manifest = NULL;
+       pkgmgrinfo_pkginfo_h handle;
+       bool is_system = 0;
+
+       _LOGE("start :: pkgid[%s] enable process\n",pkgid);
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if ((ret == 0) && (handle != NULL)) {
+               _LOGE("pkg[%s] is already installed.", pkgid);
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+               return 0;
+       }
+
+       manifest = pkgmgr_parser_get_manifest_file(pkgid);
+       if (manifest == NULL) {
+               _LOGE("Failed to fetch package manifest file\n");
+               return -1;
+       }
+
+       _ri_broadcast_status_notification(pkgid, "rpm", PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_INSTALL_EVENT_STR);
+
+       ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL);
+       free(manifest);
+       if (ret < 0) {
+               _ri_broadcast_status_notification(pkgid, "rpm", PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR);
+               _LOGE("insert in db failed\n");
+               return -1;
+       }
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if (ret < 0) {
+               _LOGE("insert in db failed\n");
+       } else {
+               ret = pkgmgrinfo_pkginfo_is_system(handle, &is_system);
+               if (is_system) {
+                       pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, __ri_update_ail_info, NULL);
+               }
+               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+       }
+
+       /*delete disabled pkg info from backup db table*/
+//     pkgmgr_parser_delete_disabled_pkg(pkgid, NULL);
+
+       _ri_broadcast_status_notification(pkgid, "rpm", PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR);
+
+       _LOGE("end :: pkgid[%s] enable process\n",pkgid);
+
+       return 0;
+}
+
+int _rpm_process_disable(char *pkgid)
+{
+       int ret = 0;
+       pkgmgrinfo_pkginfo_h handle;
+
+       _LOGE("start :: pkgid[%s] disable process\n",pkgid);
+
+       ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle);
+       if ((ret < 0) || (handle == NULL)) {
+               _LOGE("pkgid[%s] is already disabled\n", pkgid);
+               return 0;
+       }
+
+       _ri_broadcast_status_notification(pkgid, "rpm", PKGMGR_INSTALLER_START_KEY_STR, PKGMGR_INSTALLER_UNINSTALL_EVENT_STR);
+
+       pkgmgrinfo_appinfo_get_list(handle, PM_UI_APP, __ri_check_running_app, NULL);
+       pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+
+       ret = pkgmgr_parser_parse_manifest_for_uninstallation(pkgid, NULL);
+       if (ret < 0) {
+               _ri_broadcast_status_notification(pkgid, "rpm", PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_FAIL_EVENT_STR);
+               _LOGE("pkgmgr_parser_parse_manifest_for_uninstallation failed.\n");
+               return -1;
+       }
+
+       /*save disabled pkg info to backup db table*/
+//     pkgmgr_parser_insert_disabled_pkg(pkgid, NULL);
+
+       _ri_broadcast_status_notification(pkgid, "rpm", PKGMGR_INSTALLER_END_KEY_STR, PKGMGR_INSTALLER_OK_EVENT_STR);
+
+       _LOGE("end :: pkgid[%s] disable process\n",pkgid);
+       return 0;
+}
+
+int _rpm_process_enabled_list(const char *enabled_list)
+{
+       char* token = NULL;
+       char delims[] = ":";
+       char pkgid[MAX_BUF_SIZE] = {'\0'};
+       char pkgid_list[MAX_BUF_SIZE] = {'\0'};
+
+       if (enabled_list == NULL)
+               return -1;
+
+       snprintf(pkgid_list, MAX_BUF_SIZE, "%s", enabled_list);
+       token = strtok(pkgid_list, delims);
+
+       while(token)
+       {
+               memset(pkgid, 0x00, sizeof(pkgid));
+               strncat(pkgid, token, strlen(token));
+
+               _rpm_process_enable(pkgid);
+
+               token = strtok(NULL, delims);
+       }
+
+       return 0;
+}
+
+int _rpm_process_disabled_list(const char *disabled_list)
+{
+       char* token = NULL;
+       char delims[] = ":";
+       char pkgid[MAX_BUF_SIZE] = {'\0'};
+       char pkgid_list[MAX_BUF_SIZE] = {'\0'};
+
+       if (disabled_list == NULL)
+               return -1;
+
+       snprintf(pkgid_list, MAX_BUF_SIZE, "%s", disabled_list);
+       token = strtok(pkgid_list, delims);
+
+       while(token)
+       {
+               memset(pkgid, 0x00, sizeof(pkgid));
+               strncat(pkgid, token, strlen(token));
+
+               _rpm_process_disable(pkgid);
+
+               token = strtok(NULL, delims);
+       }
+
+       return 0;
 }
 
+int __ri_copy_smack_rule_file(int op, const char *pkgname, int is_system)
+{
+
+       mode_t mode = DIR_PERMS;
+       int ret = RPM_INSTALLER_SUCCESS;
+       char src[PATH_MAX]={0};
+       char dest[PATH_MAX]={0};
+
+       switch(op)
+               {
+               case UNINSTALL_REQ:
+                       /*
+                       For downloadable native app, restore the smack file.
+                       Otherwise, remove the stored smack file.
+                       */
+                       snprintf(dest,PATH_MAX-1,"%s%s.rule",SMACK_RULES_ALT_PATH,pkgname);
+                       snprintf(src,PATH_MAX-1,"%s%s.rule",DIR_RPM_WGT_SMACK_RULE_OPT,pkgname);
+                       _LOGD("#src:[%s] dest:[%s]",src,dest);
+
+                       if(!is_system){
+                               if(!access(src,F_OK)){
+                                       ret = remove(src);
+                                       if(!ret){
+                                               _LOGD("#File [%s] deleted.",src);
+                                       }else{
+                                               _LOGE("@Unable to delete the file [%s], error:(%s)",src,strerror(errno));
+                                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                                               goto end;
+                                       }
+                               }
+                               if(!access(dest,F_OK)){
+                                       ret = remove(dest);
+                                       if(!ret){
+                                               _LOGD("#File [%s] deleted.",dest);
+                                       }else{
+                                               _LOGE("@Unable to delete the file [%s], error:(%s)",dest,strerror(errno));
+                                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                                               goto end;
+                                       }
+                               }
+                       }else{
+                               _LOGD("#Restore smack files for uninstallation [%s]",pkgname);
+                               if(!access(src,F_OK)){
+                                       _LOGD("#Copying [%s] to [%s]",src,dest);
+                                       ret = __copy_file(src,dest);
+                                       if(!ret){
+                                               ret = remove(src);
+                                               if(!ret){
+                                                       _LOGD("#File [%s] deleted.",src);
+                                               }else{
+                                                       _LOGE("@Unable to delete the file [%s], error:(%s)",src,strerror(errno));
+                                                       ret = RPM_INSTALLER_ERR_INTERNAL;
+                                                       goto end;
+                                               }
+                                       }else{
+                                               _LOGE("@Copy Failed!!");
+                                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                                               goto end;
+                                       }
+                               }else{
+                                       _LOGE("@ %s.rule file is not preserved",pkgname);
+                               }
+                       }
+                       break;
+
+               case UPGRADE_REQ:
+
+                       _LOGD("#Preserve the smack file for upgrade [%s]",pkgname);
+
+                       /* Apply the new smack file and preserve the old smack rule file if it is not preserved.*/
+                       snprintf(src,PATH_MAX-1,"%s%s.rule",SMACK_RULES_ALT_PATH,pkgname);
+                       snprintf(dest,PATH_MAX-1,"%s%s.rule",DIR_RPM_WGT_SMACK_RULE_OPT,pkgname);
+
+                       _LOGD("#src[%s] dest[%s]",src,dest);
+
+                       /* Create the directory if not exist to preserve the smack files */
+                       if(mkdir(DIR_RPM_WGT_SMACK_RULE_OPT,mode) == 0 || errno == EEXIST){
+                               if((access(src,F_OK) == 0) && (access(dest,F_OK) != 0)){
+                                       ret = __copy_file(src,dest);
+                               }else{
+                                       _LOGD("#Smack file is already preserved");
+                               }
+                       }else{
+                               _LOGE("@Temporary folder creation failed");
+                               ret = RPM_INSTALLER_ERR_INTERNAL;
+                       }
+                       break;
+               default:
+                       _LOGE("@Unsupported Operation\n");
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+               }
+
+       end:
+               return ret;
+
+
+}
index 12a38d9..41413da 100755 (executable)
 #define VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS \
        VCONF_RPM_INSTALLER"/requestinfo/options"
 
-#define ERR_RETURN_LEN 32
+#define ERR_RETURN_LEN                 256
 
 extern pkgmgr_installer *pi;
 extern char *gpkgname;
+extern int broadcast_disable;
 
 int _ri_get_backend_state()
 {
        int ret = -1;
        int state = -1;
 
-       _d_msg(DEBUG_INFO,"_ri_get_backend_state\n");
+//     _LOGD("_ri_get_backend_state\n");
        ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATE, &state);
        if (ret == -1) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_get_backend_state: vconf_get_int FAIL\n");
        } else {
                ret = state;
@@ -71,10 +72,10 @@ int _ri_set_backend_state(int state)
                vconf_unset_recursive(VCONF_RPM_INSTALLER);
        }
 
-       _d_msg(DEBUG_INFO,"_ri_set_backend_state\n");
+//     _LOGD("_ri_set_backend_state\n");
        ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATE, state);
        if (ret == -1) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_set_backend_state: vconf_set_int FAIL\n");
        }
 
@@ -87,11 +88,11 @@ int _ri_get_backend_state_info()
        int state = -1;
        ret = vconf_get_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, &state);
        if (ret == -1) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_get_backend_state_info: vconf_get_int FAIL\n");
        } else {
                ret = state;
-       /*      _d_msg(DEBUG_INFO,"_ri_get_backend_state_info state[%d]\n", state);*/
+       /*      _LOGD("_ri_get_backend_state_info state[%d]\n", state);*/
        }
        return ret;
 }
@@ -99,10 +100,10 @@ int _ri_get_backend_state_info()
 int _ri_set_backend_state_info(int state)
 {
        int ret = -1;
-       _d_msg(DEBUG_INFO,"_ri_set_backend_state_info %d\n", state);
+//     _LOGD("_ri_set_backend_state_info %d\n", state);
        ret = vconf_set_int(VCONF_RPM_INSTALLER_BACKEND_STATEINFO, state);
        if (ret == -1)
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_set_backend_state_info: vconf_set_int FAIL\n");
 
        return ret;
@@ -116,13 +117,13 @@ int _ri_get_last_input_info(char **pkgid, int *preqcommand, int *poptions)
        ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND,
                            preqcommand);
        if (ret == -1)
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND: vconf_get_int FAIL\n");
 
        ret = vconf_get_int(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS,
                            poptions);
        if (ret == -1)
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_get_last_input_info: VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS: vconf_get_int FAIL\n");
 
        *pkgid = vconf_get_str(VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME);
@@ -139,49 +140,67 @@ void _ri_save_last_input_info(char *pkgid, int reqcommand, int options)
                            VCONF_RPM_INSTALLER_LAST_REQUESTINFO_COMMAND,
                            reqcommand);
        if (ret == -1)
-               _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n");
+               _LOGE("vconf_keylist_add_int FAIL\n");
        ret = vconf_keylist_add_str(kl,
                            VCONF_RPM_INSTALLER_LAST_REQUESTINFO_PKGNAME,
                            pkgid);
        if (ret == -1)
-               _d_msg(DEBUG_ERR, "vconf_keylist_add_str FAIL\n");
+               _LOGE("vconf_keylist_add_str FAIL\n");
        ret = vconf_keylist_add_int(kl,
                            VCONF_RPM_INSTALLER_LAST_REQUESTINFO_OPTIONS,
                            options);
        if (ret == -1)
-               _d_msg(DEBUG_ERR, "vconf_keylist_add_int FAIL\n");
+               _LOGE("vconf_keylist_add_int FAIL\n");
 
        if (vconf_set(kl))
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "_ri_save_last_input_info: Failure in writing vconf\n");
 
        ret = vconf_keylist_free(kl);
        if (ret == -1)
-               _d_msg(DEBUG_ERR, "vconf_keylist_free FAIL\n");
+               _LOGE("vconf_keylist_free FAIL\n");
 }
 
-void _ri_broadcast_status_notification(char *pkgid, char *key, char *val)
+void _ri_broadcast_status_notification(const char *pkgid, char *pkg_type, char *key, char *val)
 {
-       char *pkgid_tmp = NULL;
+       const char *pkgid_tmp = pkgid;
        char buf[ERR_RETURN_LEN] = {'\0'};
        int ret_val = 0;
 
+       if (broadcast_disable)
+               return;
+
+#if 0
        if (gpkgname != NULL)
                pkgid_tmp = gpkgname;
        else
                pkgid_tmp = pkgid;
+#endif
 
-       ret_val = _ri_string_to_error_no(val);
-       _d_msg(DEBUG_INFO, "pkgid = %s, key = %s, val = %s, ret_val = %d\n", pkgid_tmp, key, val, ret_val);
-
-       if (ret_val == RPM_INSTALLER_ERR_UNKNOWN){
-               if (pi != NULL)
-                       pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, val);
-               else
-                       _d_msg(DEBUG_ERR, "Failure in sending broadcast message\n");
+       if (pi == NULL) {
+               _LOGE("Failure in sending broadcast message\n");
+               return;
        }
-       else{
+
+       if (strcmp(key,PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR) == 0) {
+               ret_val = atoi(val);
+
+               _LOGD("pkgid=[%s], key=[%s], val=[%s]\n", pkgid_tmp, key, val);
+
                snprintf(buf, ERR_RETURN_LEN - 1, "%d", ret_val);
-               pkgmgr_installer_send_signal(pi, PKGTYPE, pkgid_tmp, key, buf);
+               pkgmgr_installer_send_signal(pi, pkg_type, pkgid_tmp, key, buf);
+               return;
+       } else {
+               ret_val = _ri_string_to_error_no(val);
+
+               _LOGD( "pkgid=[%s], key=[%s], val=[%s]\n", pkgid_tmp, key, val);
+
+               if (ret_val == RPM_INSTALLER_ERR_UNKNOWN){
+                       pkgmgr_installer_send_signal(pi, pkg_type, pkgid_tmp, key, val);
+               }
+               else{
+                       snprintf(buf, ERR_RETURN_LEN - 1, "%d:%s", ret_val, val);
+                       pkgmgr_installer_send_signal(pi, pkg_type, pkgid_tmp, key, buf);
+               }
        }
 }
index b12b2ef..13c42b4 100755 (executable)
@@ -16,7 +16,7 @@ FOREACH(flag ${pkgs_CFLAGS})
        SET(pkgs_CFLAGS_str "${pkgs_CFLAGS_str} ${flag}")
 ENDFOREACH(flag)
 
-pkg_check_modules(libpkgs REQUIRED dbus-glib-1 db-util vconf sqlite3 dlog)
+pkg_check_modules(libpkgs REQUIRED libxml-2.0 dbus-glib-1 db-util vconf sqlite3 dlog)
 
 FOREACH(flag ${libpkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index 2e1e87e..47bd50a 100755 (executable)
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <dirent.h>
+#include <sys/statvfs.h>
 
 #include <syslog.h>
 #include "rpm-installer-util.h"
 
-#include <dlog.h>
-
-#define LOG_TAG                                "rpminstaller"
-
-int logging = 0x0004;
-#ifdef LOG_IN_FILE
-#define RPM_INSTALLER_LOG_FILE "/tmp/rpm-installer"
-FILE *logfile = NULL;
-#endif
-
-/**
- * This is intended to be a faster splitter, it does not use dynamic
- *  memories. Input is changed to insert nulls at each token location.
- */
-int _ri_tok_split_string(char tok, char *input, char **list,
-                        unsigned long listmax)
-{
-       /* Strip any leading spaces */
-       char *start = input;
-       char *stop = start + strlen(start);
-       for (; *start != 0 && isspace(*start) != 0; start++) ;
-
-       unsigned long count = 0;
-       char *pos = start;
-       while (pos != stop) {
-               /* Skip to the next Token */
-               for (; pos != stop && *pos != tok; pos++) ;
-
-               /* Back remove spaces */
-               char *end = pos;
-               for (;
-                    end > start && (end[-1] == tok || isspace(end[-1]) != 0);
-                    end--) ;
-
-               *end = 0;
-
-               list[count++] = start;
-               if (count >= listmax) {
-                       list[count - 1] = 0;
-                       return -1;
-               }
-               /* Advance pos */
-               for (;
-                    pos != stop && (*pos == tok || isspace(*pos) != 0
-                                    || *pos == 0); pos++) ;
-
-               start = pos;
-       }
-
-       list[count] = 0;
-       return 0;
-}
-
-void _d_msg_init(char *program)
-{
-       if (logging == 0)
-               return;
-
-#ifdef LOG_IN_FILE
-       char logfilename[64] = { 0, };
-       char buffer[256] = { 0 };
-       snprintf(logfilename, 64, "%s-%s", RPM_INSTALLER_LOG_FILE, program);
-       logfile = fopen(logfilename, "a+");
-
-       if (logfile == NULL)
-               printf("Error opening log file\n");
-       else {
-               snprintf(buffer, 64, "\nLog File %s Created", logfilename);
-               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
-               snprintf(buffer, 64, "\nLog Started\n");
-               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
-       }
-#endif
-}
-
-void _d_msg_deinit()
-{
-       if (logging == 0)
-               return;
-
-#ifdef LOG_IN_FILE
-       if (logfile != NULL)
-               fclose(logfile);
-#endif
-}
-
-void _print_msg(int type, int exetype, char *format, ...)
+int _ri_get_attribute(xmlTextReaderPtr reader, char *attribute, const char **xml_attribute)
 {
-       char buffer[1024] = { 0 };
-       char tbuffer[1024] = { 0 };
-       int nbuffer = 0;
-       va_list args;
-       va_start(args, format);
-       nbuffer = vsnprintf(tbuffer, 1024, format, args);
-       va_end(args);
-
-       switch (type) {
-       case DEBUG_ERR:
-               LOG(LOG_ERROR, LOG_TAG, "%s", tbuffer);
-               break;
-       case DEBUG_RESULT:
-               LOG(LOG_WARN, LOG_TAG, "%s", tbuffer);
-               break;
-       case DEBUG_INFO:
-               LOG(LOG_DEBUG, LOG_TAG, "%s", tbuffer);
-       default:
-               break;
-       }
-
-       if (logging == 0)
-               return;
-
-       if (DEBUG_ERR == (logging & type)) {
-               nbuffer = snprintf(buffer, 1024, "ERROR:%s", tbuffer);
-               vfprintf(stderr, format, args);
-       } else if (DEBUG_INFO == (logging & type)) {
-               nbuffer = snprintf(buffer, 1024, "INFO:%s", tbuffer);
-               vfprintf(stdout, format, args);
-       } else if (DEBUG_RESULT == (logging & type)) {
-               nbuffer = snprintf(buffer, 1024, "RESULT:%s", tbuffer);
-               vfprintf(stdout, format, args);
-       } else {
-               return;
-       }
-
-#ifdef LOG_IN_FILE
-       if (logfile != NULL)
-               fwrite(buffer, sizeof(char), strlen(buffer), logfile);
-#endif                         /*LOG_IN_FILE */
-}
-
-/* Like system(3), but with error messages printed if the fork fails
-   or if the child process dies due to an uncaught signal. Also, the
-   return value is a bit simpler:
-
-   -1 if there was any problem
-   Otherwise, the 8-bit return value of the program ala WEXITSTATUS
-   as defined in <sys/wait.h>.
-   */
-int _ri_xsystem(const char *argv[])
-{
-       int status;
-       pid_t pid;
-       pid = vfork();
-       switch (pid) {
-       case -1:
-               perror("fork failed");
-               return -1;
-       case 0:
-               /* child */
-               execvp(argv[0], (char *const *)argv);
-               _exit(-1);
-       default:
-               /* parent */
-               break;
-       }
-
-       _d_msg(DEBUG_INFO, "parent\n");
-       if (waitpid(pid, &status, 0) == -1) {
-               perror("waitpid failed");
-               return -1;
-       }
-
-       if (WIFSIGNALED(status)) {
-               perror("signal");
-               return -1;
-       }
-
-       if (!WIFEXITED(status)) {
-               /* shouldn't happen */
-               perror("should not happen");
+       if(xml_attribute == NULL){
+               _LOGE("@xml_attribute is NULL!!");
                return -1;
        }
+       xmlChar *attrib_val = xmlTextReaderGetAttribute(reader,XMLCHAR(attribute));
+       if(attrib_val)
+               *xml_attribute = ASCII(attrib_val);
 
-       return WEXITSTATUS(status);
-}
-
-char *_ri_substring(const char *str, size_t begin, size_t len)
-{
-       if (str == 0 || strlen(str) == 0 || strlen(str) < (begin + len))
-               return 0;
-       return strndup(str + begin, len);
+       return 0;
 }
 
 void _ri_error_no_to_string(int errnumber, char **errstr)
@@ -289,6 +120,33 @@ void _ri_error_no_to_string(int errnumber, char **errstr)
        case RPM_INSTALLER_ERR_INVALID_MANIFEST:
                *errstr = RPM_INSTALLER_ERR_INVALID_MANIFEST_STR;
                break;
+       case RPM_INSTALLER_ERR_SIG_NOT_FOUND:
+               *errstr = RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR;
+               break;
+       case RPM_INSTALLER_ERR_SIG_INVALID:
+               *errstr = RPM_INSTALLER_ERR_SIG_INVALID_STR;
+               break;
+       case RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED:
+               *errstr = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR;
+               break;
+       case RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND:
+               *errstr = RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR;
+               break;
+       case RPM_INSTALLER_ERR_CERT_INVALID:
+               *errstr = RPM_INSTALLER_ERR_CERT_INVALID_STR;
+               break;
+       case RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED:
+               *errstr = RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR;
+               break;
+       case RPM_INSTALLER_ERR_NO_CONFIG:
+               *errstr = RPM_INSTALLER_ERR_NO_CONFIG_STR;
+               break;
+       case RPM_INSTALLER_ERR_INVALID_CONFIG:
+               *errstr = RPM_INSTALLER_ERR_INVALID_CONFIG_STR;
+               break;
+       case RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED:
+               *errstr = RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED_STR;
+               break;
        default:
                *errstr = RPM_INSTALLER_ERR_UNKNOWN_STR;
                break;
@@ -348,7 +206,841 @@ int _ri_string_to_error_no(char *errstr)
                errnumber = RPM_INSTALLER_ERR_NO_MANIFEST;
        else if (strcmp(errstr, RPM_INSTALLER_ERR_INVALID_MANIFEST_STR) == 0)
                errnumber = RPM_INSTALLER_ERR_INVALID_MANIFEST;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_SIG_NOT_FOUND;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_SIG_INVALID_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_SIG_INVALID;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_CERT_INVALID_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_CERT_INVALID;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_NO_CONFIG_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_NO_CONFIG;
+       else if (strcmp(errstr, RPM_INSTALLER_ERR_INVALID_CONFIG_STR) == 0)
+               errnumber = RPM_INSTALLER_ERR_INVALID_CONFIG;
        else
-               _d_msg(DEBUG_ERR, "Unsupported Error\n");
+               errnumber = RPM_INSTALLER_ERR_UNKNOWN;
+
        return errnumber;
 }
+
+int _rpm_delete_dir(char *dirname)
+{
+       int ret = 0;
+       DIR *dp;
+       struct dirent *ep;
+       char abs_filename[FILENAME_MAX];
+       struct stat stFileInfo;
+
+       if (dirname == NULL) {
+               _LOGE("dirname is NULL.");
+               return -1;
+       }
+
+       _LOGD("delete_dir=[%s]", dirname);
+
+       dp = opendir(dirname);
+       if (dp != NULL) {
+               while ((ep = readdir(dp))) {
+                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname, ep->d_name);
+                       if (lstat(abs_filename, &stFileInfo) < 0) {
+                               _LOGE("lstat(%s) failed.", abs_filename);
+                               perror(abs_filename);
+                       }
+
+                       if (S_ISDIR(stFileInfo.st_mode)) {
+                               if (strcmp(ep->d_name, ".") && strcmp(ep->d_name, "..")) {
+                                       _rpm_delete_dir(abs_filename);
+                                       (void)remove(abs_filename);
+                               }
+                       } else {
+                               (void)remove(abs_filename);
+                       }
+               }
+               (void)closedir(dp);
+       } else {
+               _LOGE("opendir(%s) failed.", dirname);
+               return -1;
+       }
+
+       ret = remove(dirname);
+       if (ret < 0)
+               _LOGE("remove(%s) failed.", dirname);
+
+       return 0;
+}
+
+char* _manifest_to_package(const char* manifest)
+{
+       char *package;
+
+       if(manifest == NULL) {
+               _LOGE("manifest is NULL.\n");
+               return NULL;
+       }
+
+       package = strdup(manifest);
+       if(package == NULL) {
+               _LOGE("strdup failed.\n");
+               return NULL;
+       }
+
+       if (!strstr(package, ".xml")) {
+               _LOGE("%s is not a manifest file\n", manifest);
+               free(package);
+               return NULL;
+       }
+
+       return package;
+}
+
+/* Extract the basename from the file's path */
+char *_ri_basename(char *name)
+{
+       int length;
+       length = name ? strlen(name) : 0;
+       if (!length)
+               return ".";
+
+       while (--length > 0 && name[length] != '/');
+
+       return length <= 0 ? name : name + length + (name[length] == '/');
+}
+
+int _child_element(xmlTextReaderPtr reader, int depth)
+{
+       int ret = xmlTextReaderRead(reader);
+       int cur = xmlTextReaderDepth(reader);
+       while (ret == 1) {
+
+               switch (xmlTextReaderNodeType(reader)) {
+                       case XML_READER_TYPE_ELEMENT:
+                               if (cur == depth + 1)
+                                       return 1;
+                               break;
+                       case XML_READER_TYPE_TEXT:
+                               /*text is handled by each function separately*/
+                               if (cur == depth + 1)
+                                       return 0;
+                               break;
+                       case XML_READER_TYPE_END_ELEMENT:
+                               if (cur == depth)
+                                       return 0;
+                               break;
+                       default:
+                               if (cur <= depth)
+                                       return 0;
+                               break;
+                       }
+
+               ret = xmlTextReaderRead(reader);
+               cur = xmlTextReaderDepth(reader);
+       }
+       return ret;
+}
+
+/*
+This Function get the package name from the rpm file's path..
+*/
+int  _get_pkgname_from_rpm_name(char * pkgfile, char **rpm_name){
+
+       char* rpm_file = NULL;
+       char  name[PATH_MAX] = {0};
+       char  temp[PATH_MAX]={0};
+       char *saveptr = NULL;;
+       char *str= NULL;
+       char c ;
+       int ret = RPM_INSTALLER_SUCCESS;
+
+       if(pkgfile == NULL || rpm_name == NULL){
+               _LOGE("Invalid Parameter!!");
+               return RPM_INSTALLER_ERR_WRONG_PARAM;
+
+       }
+       _LOGD("RPM path is [%s]",pkgfile);
+
+       /* Get the rpm name from rpm file's path */
+       rpm_file = _ri_basename(pkgfile);
+       _LOGD("RPM name is [%s]",rpm_file);
+
+       strncpy(name,rpm_file,strlen(rpm_file));
+       str = strtok_r(name, "-", &saveptr);
+       if(rpm_file[strlen(name)] != '\0'){
+               c = rpm_file[strlen(name) + 1];
+       }else{
+               if(strstr(name,".rpm")){
+                       name[strlen(name)-strlen(".rpm")]='\0';
+               }
+               *rpm_name = strdup(name);
+               if(*rpm_name == NULL){
+                       _LOGE("Malloc failed!!");
+                       ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+               }
+               goto end;
+       }
+
+       while(!isdigit(c)){
+               memset(temp,'\0',PATH_MAX);
+               str = strtok_r(NULL, "-", &saveptr);
+               snprintf(temp,PATH_MAX,"-%s",str);
+               strncat(name,temp,strlen(temp));
+               if(rpm_file[strlen(name)] != '\0'){
+                       c = rpm_file[strlen(name) + 1];
+               }else{
+                       break;
+               }
+       }
+       if(strstr(name,".rpm")){
+               name[strlen(name)-strlen(".rpm")]='\0';
+       }
+       *rpm_name = strdup(name);
+       if(*rpm_name == NULL){
+               _LOGE("Malloc failed!!");
+               ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+       }
+
+end:
+       return ret;
+
+}
+
+/*
+This Function reads the package field from the xml file.
+*/
+int  _get_package_name_from_xml(char* manifest, char** pkgname){
+
+       const char *val = NULL;
+       const xmlChar *node;
+       xmlTextReaderPtr reader;
+       int ret = PMINFO_R_OK;
+
+       if(manifest == NULL) {
+               _LOGE("Input argument is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       if(pkgname == NULL) {
+               _LOGE("Argument supplied to hold return value is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+       reader = xmlReaderForFile(manifest, NULL, 0);
+
+       if (reader){
+               if ( _child_element(reader, -1)) {
+                       node = xmlTextReaderConstName(reader);
+                       if (!node) {
+                               _LOGE("xmlTextReaderConstName value is NULL\n");
+                               ret =  PMINFO_R_ERROR;
+                               goto end;
+                       }
+
+                       if (!strcmp(ASCII(node), "manifest")) {
+                               ret = _ri_get_attribute(reader,"package",&val);
+                               if(ret != 0){
+                                       _LOGE("@Error in getting attribute value");
+                                       ret = PMINFO_R_ERROR;
+                                       goto end;
+                               }
+
+                               if(val){
+                                       *pkgname = strdup(val);
+                                       if(*pkgname == NULL){
+                                               _LOGE("Malloc Failed!!");
+                                               ret = PMINFO_R_ERROR;
+                                               goto end;
+                                       }
+                               }
+                       } else {
+                               _LOGE("Unable to create xml reader\n");
+                               ret =  PMINFO_R_ERROR;
+                       }
+               }
+       } else {
+               _LOGE("xmlReaderForFile value is NULL\n");
+               return PMINFO_R_ERROR;
+       }
+
+end:
+       xmlFreeTextReader(reader);
+
+       if(val)
+               free((void*)val);
+
+       return ret;
+}
+
+int _ri_recursive_delete_dir(char *dirname)
+{
+       int ret=0;
+       DIR *dp;
+       struct dirent *ep;
+       char abs_filename[FILENAME_MAX];
+       struct stat stFileInfo;
+       dp = opendir(dirname);
+       if (dp != NULL) {
+               while ((ep = readdir(dp))) {
+                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                                ep->d_name);
+                       if (lstat(abs_filename, &stFileInfo) < 0)
+                               perror(abs_filename);
+                       if (S_ISDIR(stFileInfo.st_mode)) {
+                               if (strcmp(ep->d_name, ".") &&
+                                   strcmp(ep->d_name, "..")) {
+                                       ret=_ri_recursive_delete_dir(abs_filename);
+                                       if(ret < 0)
+                                               _LOGE("_ri_recursive_delete_dir fail\n");
+
+                                       ret=remove(abs_filename);
+                                       if(ret < 0)
+                                               _LOGE("remove fail\n");
+                               }
+                       } else {
+                               ret = remove(abs_filename);
+                               if(ret < 0)
+                                       _LOGE("Couldn't remove abs_filename\n");
+                       }
+               }
+               (void)closedir(dp);
+       } else {
+               _LOGE("Couldn't open the directory\n");
+               if (errno == ENOENT)
+                       return RPM_INSTALLER_SUCCESS;
+               else
+                       return RPM_INSTALLER_ERR_CLEAR_DATA_FAILED;
+       }
+
+       return RPM_INSTALLER_SUCCESS;
+}
+
+ int _ri_xsystem(const char *argv[])
+{
+       int status = 0;
+       pid_t pid;
+       pid = fork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+       return WEXITSTATUS(status);
+}
+void _ri_remove_wgt_unzip_dir()
+{
+       if (!access(DIR_RPM_INSTALLER_APPLICATIONS_TEMP, F_OK)) {
+               _ri_recursive_delete_dir(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+               (void)remove(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+       }
+
+}
+
+int _ri_get_available_free_memory(const char *opt_path, unsigned long *free_mem)
+{
+       struct statvfs buf;
+       int ret = 0;
+       if (opt_path == NULL || free_mem == NULL) {
+               _LOGE("Invalid input parameter\n");
+               return -1;
+       }
+       memset((void *)&buf, '\0', sizeof(struct statvfs));
+       ret = statvfs(opt_path, &buf);
+       if (ret) {
+               _LOGE("Unable to get /opt/usr memory information\n");
+               return -1;
+       }
+       *free_mem = (buf.f_bfree * buf.f_bsize)/SIZE_KB;
+       return 0;
+}
+
+
+unsigned long  _ri_calculate_file_size(const char *filename)
+{
+       struct stat stFileInfo;
+
+       if (stat(filename, &stFileInfo) < 0) {
+               perror(filename);
+               return 0;
+       } else
+               return (stFileInfo.st_size/SIZE_KB);
+}
+
+void _ri_process_config_node(xmlTextReaderPtr reader, pkginfo * info)
+{
+       const xmlChar *node;
+       const char *pkgid = NULL;
+       const char *version = NULL;
+       node = xmlTextReaderConstName(reader);
+       if (node == NULL) {
+               return;
+       }
+       if (strcmp(ASCII(node), "widget") == 0) {
+               if (xmlTextReaderNodeType(reader) == 1) {
+                       if(_ri_get_attribute(reader,"version",&version) != 0){
+                               _LOGE("@Error while getting the attribute value");
+                               return;
+                       }
+                               snprintf(info->version, VERSION_MAX_LEN - 1, "%s", version);
+                               _LOGD("<version> %s", info->version);
+               }
+       }
+
+
+       if (strcmp(ASCII(node), "tizen:application") == 0) {
+               if (xmlTextReaderNodeType(reader) == 1) {
+                       if(_ri_get_attribute(reader,"package",&pkgid) != 0){
+                               _LOGE("@Error while getting the attribute value");
+                               return;
+                       }
+                       snprintf(info->package_name, PKG_MAX_LEN - 1, "%s", pkgid);
+                       _LOGD("<package> %s", info->package_name);
+               }
+       }
+       if(pkgid){
+               free((void*)pkgid);
+               pkgid = NULL;
+       }
+
+       if(version){
+               free((void*)version);
+               version = NULL;
+       }
+       return;
+
+}
+
+int  _ri_stream_config_file(const char* filename, pkginfo *info)
+{
+       xmlTextReaderPtr reader;
+       int ret = RPM_INSTALLER_SUCCESS;
+
+       _LOGD("Reading config file [%s]",filename);
+       reader = xmlReaderForFile(filename,NULL,0);
+       if (reader != NULL) {
+               ret = xmlTextReaderRead(reader);
+               while (ret == 1) {
+                       _ri_process_config_node(reader, info);
+                       ret = xmlTextReaderRead(reader);
+               }
+               xmlFreeTextReader(reader);
+               if (ret != 0) {
+                       _LOGE("%s : failed to parse\n", filename);
+                       ret = RPM_INSTALLER_ERR_INTERNAL;
+               }
+       } else {
+               _LOGE("Unable to open %s\n", filename);
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+       }
+       return ret;
+}
+
+unsigned long  _ri_calculate_rpm_size( char* rpm_file)
+{
+       Header  hdr = NULL;
+       rpmts   ts;
+       rpmtd   td;
+       FD_t    fd;
+       rpmRC   rc;
+       rpmVSFlags vsflags = 0;
+       unsigned long  size = 0;
+
+       /* Initialize rpm */
+       rc = rpmReadConfigFiles(NULL,NULL);
+       if( rc != RPMRC_OK){
+               _LOGE("\n failed to read RPM configuration files");
+               return size;
+       }
+       /* Open the rpm file */
+       fd = Fopen(rpm_file, "r.ufdio");
+       if ((!fd) || Ferror(fd)){
+               _LOGE("\n failed to open %s package file",rpm_file);
+               if(fd)
+                       Fclose(fd);
+               return size ;
+       }
+
+       hdr = headerNew();
+       ts = rpmtsCreate();
+       td = rpmtdNew();
+       vsflags |= _RPMVSF_NODIGESTS;
+       vsflags |= _RPMVSF_NOSIGNATURES;
+       vsflags |= RPMVSF_NOHDRCHK;
+       (void)rpmtsSetVSFlags(ts, vsflags);
+
+       rc = rpmReadPackageFile(ts,fd,rpm_file,&hdr);
+       if(rc != RPMRC_OK){
+               _LOGE("\n Couldn't read rpm package file");
+               size = 0;
+               Fclose(fd);
+               goto err;
+       }
+       headerGet(hdr,RPMTAG_SIZE,td,HEADERGET_MINMEM);
+       size = rpmtdGetNumber(td);
+
+       err:
+       rpmtdFreeData(td);
+       rpmtdFree(td);
+       headerFree(hdr);
+       rpmtsFree(ts);
+
+       return size;
+}
+
+unsigned long  _ri_calculate_dir_size(const char *dirname)
+{
+       static unsigned long  total = 0;
+       unsigned long  size = 0;
+       DIR *dp = NULL;
+       struct dirent *ep = NULL;
+       char abs_filename[FILENAME_MAX] = { 0, };;
+       dp = opendir(dirname);
+       if (dp != NULL) {
+               while ((ep = readdir(dp)) != NULL) {
+                       struct stat stFileInfo;
+
+                       snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                                ep->d_name);
+
+                       if (stat(abs_filename, &stFileInfo) < 0)
+                               perror(abs_filename);
+                       else {
+                               /* If file is rpm then get the size from rpm header. */
+                               if(strstr(ep->d_name,".rpm")){
+                                       size = _ri_calculate_rpm_size(abs_filename);
+                                       if( size == 0){
+                                               _LOGE("\n error in computing the rpm's size");
+                                       }
+                                       total += size;
+                               }else{
+                               total += (unsigned long)stFileInfo.st_size;
+                               }
+
+                               if (S_ISDIR(stFileInfo.st_mode)) {
+                                       if (strcmp(ep->d_name, ".")
+                                           && strcmp(ep->d_name, "..")) {
+                                               _ri_calculate_dir_size
+                                                   (abs_filename);
+                                       }
+                               } else {
+                                       /*Do Nothing */
+                               }
+                       }
+               }
+               (void)closedir(dp);
+       } else {
+               _LOGE("\n error in opening directory ");
+       }
+       return (total/SIZE_KB);
+}
+
+
+/*
+This function unzip the wgt package.
+It read and validate the config.xml file.
+It checks whether the free size avaiable to install this package.
+*/
+
+int _ri_wgt_package_extract(char *pkgid)
+{
+       if(pkgid == NULL)
+               return RPM_INSTALLER_ERR_INTERNAL;
+
+       int ret = RPM_INSTALLER_SUCCESS;
+       const char *argv[5] = { RPM_UNZIP, pkgid, "-d", DIR_RPM_INSTALLER_APPLICATIONS_TEMP, NULL};
+       char config_file_name[PATH_MAX] = {0};
+       pkginfo *info = NULL;
+       unsigned long free_mem = 0;
+       unsigned long reqd_size = 0;
+       mode_t mode = DIR_PERMS;
+
+       /* 1. Delete the temp folder if already present*/
+       if (!access(DIR_RPM_INSTALLER_APPLICATIONS_TEMP, F_OK)) {
+               _ri_recursive_delete_dir(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+               (void)remove(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+       }
+
+       /* 1.2 Create temp folder */
+       ret = mkdir(DIR_RPM_INSTALLER_APPLICATIONS_TEMP, mode);
+       if (ret != 0) {
+               _LOGE("Temporary folder creation failed");
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+       /* 1.3 Unzip wgt to temp folder*/
+       ret = _ri_xsystem(argv);
+       if (ret != 0) {
+               _LOGE("Unzip to Temporary folder failed");
+               return  RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       /* Read the config.xml file and get the information*/
+       snprintf(config_file_name,PATH_MAX,"%s/%s", DIR_RPM_INSTALLER_APPLICATIONS_TEMP,WGT_CONFIG);
+       _LOGD("Config File is [%s]",config_file_name);
+       if(access(config_file_name,F_OK)){
+               /* Return if info config is absent */
+               _LOGE("No Config File [%s] found\n", config_file_name);
+               return  RPM_INSTALLER_ERR_NO_CONFIG;
+       }
+       _LOGD("Config File [%s] found\n", config_file_name);
+
+       /*populate pkginfo */
+       info = (pkginfo *)calloc(1, sizeof(pkginfo));
+       if (info == NULL) {
+               _LOGE("Memory allocation failed");
+               return  RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+       }
+
+       /* Parse config file and store the info in pkginfo struct */
+       ret = _ri_stream_config_file(config_file_name,info);
+       if(ret != RPM_INSTALLER_SUCCESS){
+               _LOGE("Config file's parsing Failed");
+               if(info){
+                       free(info);
+                       info = NULL;
+               }
+               return RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       /* 3. Validate the pkginfo*/
+       if (strlen(info->package_name) == 0 || strlen(info->version) == 0) {
+               _LOGE("Package name or version is not found in Config File");
+               if (info) {
+                       free(info);
+                       info = NULL;
+               }
+               return RPM_INSTALLER_ERR_INVALID_CONFIG;
+       }
+
+       /* 4. Check the free memory  in RW partition*/
+       ret = _ri_get_available_free_memory(RPM_INSTALLER_RW_INSTALL_PATH, &free_mem);
+       if (ret<0) {
+               _LOGE("Error in getting available free memory");
+               if (info) {
+                       free(info);
+                       info = NULL;
+               }
+               return RPM_INSTALLER_ERR_INTERNAL;
+       } else {
+               /* Compare with size required by package*/
+               reqd_size = _ri_calculate_dir_size(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+               if (reqd_size ==0) {
+                       _LOGE("Error in getting file size");
+                       if (info) {
+                               free(info);
+                               info = NULL;
+                       }
+                       return RPM_INSTALLER_ERR_INTERNAL;
+               } else {
+                       if (reqd_size > free_mem) {
+                               _LOGE("Not enough memory");
+                               if (info) {
+                                       free(info);
+                                       info = NULL;
+                               }
+                               return  RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+                       }
+               }
+       }
+
+       _LOGD("Required size to install pkg is [%lu KB] and available memory is  [%lu KB]",reqd_size,free_mem);
+
+       if (info) {
+               free(info);
+               info = NULL;
+       }
+
+       return ret;
+}
+
+int _verify_wgt_package_signature_files(void)
+{
+
+       char buff[PATH_MAX] = {0};
+       int ret = RPM_INSTALLER_SUCCESS;
+       char cwd[PATH_MAX]={0};
+       char *temp = NULL;
+       int visibility = 0;
+
+       temp = getcwd(cwd, PATH_MAX);
+       if ( ( temp == NULL) || (cwd[0] == '\0')) {
+               _LOGE("@getcwd() failed.\n");
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+               goto end;
+       }
+
+       ret = chdir(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+       if(ret != 0){
+               _LOGE("Change directory failed!");
+               goto end;
+       }
+
+       /*Verify the author-signature file */
+       memset(buff, '\0', PATH_MAX);
+       snprintf(buff, PATH_MAX, "%s/%s",DIR_RPM_INSTALLER_APPLICATIONS_TEMP,AUTHOR_SIGNATURE_XML);
+
+       if (access(buff, F_OK) == 0) {
+               _LOGD("auth-signature.xml found in %s\n", DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+               ret = _ri_verify_sig_and_cert(buff, &visibility);
+               if (ret) {
+                       _LOGE("Failed to verify [%s]\n", buff);
+                       ret = RPM_INSTALLER_ERR_SIG_INVALID;
+                       goto end;
+               }else{
+               _LOGD("Successfully verified [%s]\n", buff);
+               }
+       }
+
+       /*Verify the signature2.xml file */
+       memset(buff, '\0', PATH_MAX);
+       snprintf(buff, PATH_MAX, "%s/%s",DIR_RPM_INSTALLER_APPLICATIONS_TEMP,SIGNATURE2_XML);
+
+       if (access(buff, F_OK) == 0) {
+               _LOGD("signature2.xml found in %s\n", DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+               ret = _ri_verify_sig_and_cert(buff, &visibility);
+               if (ret) {
+                       _LOGE("Failed to verify [%s]\n", buff);
+                       ret = RPM_INSTALLER_ERR_SIG_INVALID;
+                       goto end;
+               }else{
+               _LOGD("Successfully verified [%s]\n", buff);
+               }
+       }
+
+       /*Verify the signature1.xml file*/
+       memset(buff, '\0', PATH_MAX);
+       snprintf(buff,PATH_MAX,"%s/%s", DIR_RPM_INSTALLER_APPLICATIONS_TEMP,SIGNATURE1_XML);
+
+       if (access(buff, F_OK) == 0) {
+               _LOGD("signature1.xml found in %s\n", DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+               ret = _ri_verify_sig_and_cert(buff, &visibility);
+               if (ret) {
+                       _LOGE("Failed to verify [%s]\n", buff);
+                       ret = RPM_INSTALLER_ERR_SIG_INVALID;
+                       goto end;
+               }else{
+               _LOGD("Successfully verified [%s]\n", buff);
+               }
+       }
+
+       if(chdir(cwd)){
+               _LOGE("chdir failed [%s]",strerror(errno));
+               ret = RPM_INSTALLER_ERR_INTERNAL;
+       }
+
+       end:
+
+               return ret;
+
+}
+
+char* _get_rpm_file_from_wgt_package(char* dirname)
+{
+
+        DIR *dp = NULL;
+        struct dirent *ep = NULL;
+        char abs_filename[FILENAME_MAX] = { 0, };
+        dp = opendir(dirname);
+       int found = 0;
+        if (dp != NULL) {
+                while ((ep = readdir(dp)) != NULL) {
+                        snprintf(abs_filename, FILENAME_MAX, "%s/%s", dirname,
+                                 ep->d_name);
+                        if (strstr(abs_filename,".rpm")!=NULL){
+                               found = 1;
+                               break;
+                        }
+                }
+                (void)closedir(dp);
+        }
+
+       if(found){
+               _LOGD("rpm name is [%s]",abs_filename);
+               return strdup(abs_filename);
+       }
+
+       return NULL;
+
+}
+
+/*
+This function processes the modified wgt package .
+*/
+int _ri_process_wgt_package(char** pkgid)
+{
+       if(*pkgid == NULL)
+               return RPM_INSTALLER_ERR_INTERNAL;
+
+       unsigned long free_mem = 0;
+       unsigned long file_size = 0;
+       int ret = RPM_INSTALLER_SUCCESS;
+
+
+       /* check memory available*/
+       ret = _ri_get_available_free_memory(RPM_INSTALLER_RW_INSTALL_PATH, &free_mem);
+       if (ret<0) {
+               _LOGE("Error in getting available free memory");
+               return RPM_INSTALLER_ERR_INTERNAL;
+       } else {
+               file_size = _ri_calculate_file_size(*pkgid);
+               if (file_size <=0) {
+                       _LOGE("Error in getting file size");
+                       return RPM_INSTALLER_ERR_INTERNAL;
+               } else {
+                       if (file_size > free_mem) {
+                               _LOGE("Not enough memory");
+                               return RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
+                       }
+               }
+       }
+
+       _LOGD("Package file [%s] size is [%lu]KB and free size in RW directory is [%lu]KB",*pkgid,file_size,free_mem);
+
+       /* unzip the wgt package */
+       ret = _ri_wgt_package_extract(*pkgid);
+       if(ret != RPM_INSTALLER_SUCCESS)
+               return ret;
+
+       _LOGD("wgt package is extracted to [%s]",DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+
+       ret = _verify_wgt_package_signature_files();
+       if(ret != RPM_INSTALLER_SUCCESS){
+               _LOGE("signature verification [%d]",ret);
+               return ret;
+       }
+       _LOGD("Verification of wgt package's signature files is done");
+
+       if(*pkgid){
+               free(*pkgid);
+               *pkgid = NULL;
+       }
+       /* Change the data->pkgid to the unzipped package's rpm */
+       *pkgid = _get_rpm_file_from_wgt_package(DIR_RPM_INSTALLER_APPLICATIONS_TEMP);
+       if(*pkgid == NULL)
+               return RPM_INSTALLER_ERR_INTERNAL;
+       else
+               _LOGD("rpm is [%s]",*pkgid);
+
+       return RPM_INSTALLER_SUCCESS;
+}
index 9db9fce..8e4b999 100755 (executable)
@@ -2,7 +2,7 @@ Source: rpm-installer
 Section: base
 Priority: extra
 Maintainer: Shobhit Srivastava <shobhit.s@samsung.com>, Sewook Park <sewook7.park@samsung.com>
-Build-Depends: debhelper (>= 5), libslp-setting-dev, libsqlite3-dev, libslp-db-util-dev, libdbus-glib-1-dev, libglib2.0-dev, libpkgmgr-installer-dev, libsecurity-server-client-dev, libelm-dev, libappcore-efl-dev, dlog-dev, libpkgmgr-types-dev, libevas-dev, libecore-dev, libedje-dev
+Build-Depends: debhelper (>= 5), libslp-setting-dev, libsqlite3-dev, libslp-db-util-dev, libdbus-glib-1-dev, libglib2.0-dev, libpkgmgr-installer-dev, libsecurity-server-client-dev, libelm-dev, libappcore-efl-dev, dlog-dev, libpkgmgr-types-dev, libevas-dev, libecore-dev, libedje-dev, libmdm-dev
 Standards-Version: 3.7.2
 
 Package: rpm-installer
index b9b05ac..1293de5 100755 (executable)
@@ -1,7 +1,15 @@
 @PREFIX@/lib/rpm-installer/librpm-util.a
 @PREFIX@/bin/rpm-backend
 @PREFIX@/bin/install_rpm_package.sh
+@PREFIX@/bin/install_rpm_package_with_dbpath_ro.sh
+@PREFIX@/bin/install_rpm_package_with_dbpath_rw.sh
 @PREFIX@/bin/uninstall_rpm_package.sh
 @PREFIX@/bin/upgrade_rpm_package.sh
+@PREFIX@/bin/upgrade_rpm_package_with_dbpath_ro.sh
+@PREFIX@/bin/upgrade_rpm_package_with_dbpath_rw.sh
 @PREFIX@/bin/query_rpm_package.sh
+@PREFIX@/bin/cpio_rpm_package.sh.in
+@PREFIX@/bin/cpio_rpm_package_update_xml.sh.in
+@PREFIX@/bin/coretpk_update_xml.sh.in
+@PREFIX@/bin/rpm_update_xml.sh.in
 @PREFIX@/usr/share/data
index 1b29587..d0d752b 100755 (executable)
@@ -55,7 +55,7 @@ clean:
        rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
        cd backend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
        cd backend-lib && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
-       rm -f backend/install_rpm_package.sh  backend/uninstall_rpm_package.sh  backend/upgrade_rpm_package.sh backend/query_rpm__package.sh
+       rm -f backend/install_rpm_package.sh  backend/install_rpm_package_with_dbpath_ro.sh  backend/install_rpm_package_with_dbpath_rw.sh  backend/uninstall_rpm_package.sh  backend/upgrade_rpm_package.sh  backend/upgrade_rpm_package_with_dbpath_ro.sh  backend/upgrade_rpm_package_with_dbpath_rw.sh  backend/query_rpm__package.sh  backend/cpio_rpm_package.sh  backend/cpio_rpm_package_update_xml.sh backend/coretpk_update_xml.sh backend/rpm_update_xml.sh
        cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.sh rpm-backend
        cd common && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb *.a
        cd frontend && rm -rf Makefile CMakeCache.txt CMakeFiles cmake_install.cmake install_manifest.txt *.deb
index aa20e18..9547054 100755 (executable)
@@ -7,22 +7,25 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 set(CMAKE_SKIP_BUILD_RPATH true)
 
 #Verbose
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/backend/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/backend/inc ${CMAKE_SOURCE_DIR}/backend/src/inc ${CMAKE_CURRENT_SOURCE_DIR}/inc)
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl libxml-2.0 app2sd)
+pkg_check_modules(pkgs REQUIRED pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server security-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util libxml-2.0 app2sd cert-svc
+xmlsec1 libprivilege-control capi-appfw-app-manager aul capi-system-device minizip)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-pkg_check_modules(libpkgs REQUIRED security-server pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util elementary appcore-efl libxml-2.0 app2sd)
+pkg_check_modules(libpkgs REQUIRED security-server pkgmgr pkgmgr-installer pkgmgr-parser pkgmgr-info pkgmgr-installer-status-broadcast-server vconf sqlite3 dbus-glib-1 glib-2.0 db-util libxml-2.0 app2sd cert-svc
+xmlsec1 libprivilege-control capi-appfw-app-manager aul capi-system-device minizip)
 
 FOREACH(flag ${libpkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr pkgmgr-installer pkgmgr-parser libxml-2.0 app2sd pkgmgr-info libtzplatform-config)
+pkg_check_modules(STATUS pkgmgr-installer-status-broadcast-server pkgmgr pkgmgr-installer pkgmgr-parser libxml-2.0 app2sd pkgmgr-info cert-svc 
+xmlsec1 libprivilege-control capi-appfw-app-manager aul capi-system-device minizip libtzplatform-config)
 link_directories (${STATUS_LIBRARY_DIRS})
 include_directories (${STATUS_INCLUDE_DIRS})
 
@@ -30,32 +33,14 @@ pkg_check_modules(COMMCLIENT pkgmgr-installer-client)
 link_directories (${COMMCLIENT_LIBRARY_DIRS})
 include_directories (${COMMCLIENT_INCLUDE_DIRS})
 
-IF(X11_SUPPORT)
-       SET(WIN_PKG "ecore-x")
-ENDIF(X11_SUPPORT)
-IF(WAYLAND_SUPPORT)
-       SET(WIN_PKG "${WIN_PKG} ecore-wayland")
-ENDIF(WAYLAND_SUPPORT)
-pkg_check_modules(APPCODEEFL appcore-efl evas ecore edje ecore-input ${WIN_PKG})
-link_directories (${APPCODEEFL_LIBRARY_DIRS})
-include_directories (${APPCODEEFL_INCLUDE_DIRS})
-
 pkg_check_modules(SECURITYSERVER security-server)
 link_directories (${SECURITYSERVER_LIBRARY_DIRS})
 include_directories (${SECURITYSERVER_INCLUDE_DIRS})
 
 ## DEFINITIONS
-
-IF(WAYLAND_SUPPORT)
- ADD_DEFINITIONS("-DHAVE_WAYLAND")
-ENDIF(WAYLAND_SUPPORT)
-
-IF(X11_SUPPORT)
- ADD_DEFINITIONS("-DHAVE_X11")
-ENDIF(X11_SUPPORT)
-
 ADD_DEFINITIONS("-DAPP_DIR=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DPACKAGE=\"${PROJECT_NAME}\"")
+ADD_DEFINITIONS("-DXMLSEC_CRYPTO_OPENSSL")
 
 link_directories ("${STATUS_LIBRARY_DIRS} /usr/lib")
 include_directories (${STATUS_INCLUDE_DIRS})
@@ -63,8 +48,10 @@ find_library(RPM_LIBRARY rpm "/usr/lib")
 
 
 SET(backend_dir "${CMAKE_CURRENT_SOURCE_DIR}/../backend")
-SET(backend_inc_dir "${backend_dir}/include")
+SET(backend_inc_dir "${backend_dir}/inc")
 SET(backend_c_src_dir "${backend_dir}/src")
+SET(backend_c_src_rpm_inc_dir "${backend_dir}/src/rpm/inc")
+SET(backend_c_src_coretpk_inc_dir "${backend_dir}/src/coretpk/inc")
 SET(backend_script_dir "${backend_dir}/scripts")
 SET(SCRIPTS_DIR "${backend_script_dir}")
 
@@ -83,13 +70,18 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ####################################################################################################
 ## for rpm-backend (binary)
-SET(rpm-backend_SOURCES ${backend_c_src_dir}/core/rpm-installer-core.c ${backend_c_src_dir}/core/rpm-installer-tool.c ${backend_c_src_dir}/rpm/rpm-installer.c ${backend_c_src_dir}/vconf/rpm-vconf-intf.c ${frontend_c_src_dir}/rpm-appcore-intf.c  ${frontend_c_src_dir}/rpm-cmdline.c  ${frontend_c_ui_src_dir}/rpm-homeview.c)
-
-SET(rpm-backend_CFLAGS " -I. -I/usr/include/rpm -I${backend_inc_dir} -I${frontend_inc_dir} -I${frontend_c_ui_inc_dir} ${pkg_CFLAGS}")
+SET(rpm-backend_SOURCES ${backend_c_src_dir}/rpm/rpm-installer-core.c ${backend_c_src_dir}/rpm/rpm-installer-tool.c ${backend_c_src_dir}/rpm/rpm-installer.c
+                                               ${backend_c_src_dir}/rpm/rpm-installer-signature.c ${backend_c_src_dir}/rpm/rpm-installer-privilege.c
+                                               ${backend_c_src_dir}/coretpk/coretpk-installer.c
+                                               ${backend_c_src_dir}/coretpk/xml-parser/coretpk-parser-hybrid.c
+                                               ${backend_c_src_dir}/vconf/rpm-vconf-intf.c
+                                               ${frontend_c_src_dir}/rpm-appcore-intf.c  ${frontend_c_src_dir}/rpm-cmdline.c  )
+
+SET(rpm-backend_CFLAGS " -I. -I/usr/include/rpm -I${backend_inc_dir} -I${backend_c_src_rpm_inc_dir} -I${backend_c_src_coretpk_inc_dir} -I${frontend_inc_dir} -I${frontend_c_ui_inc_dir} ${pkg_CFLAGS}")
 SET(rpm-backend_LDFLAGS ${pkgs_LDFLAGS})
 
 ADD_EXECUTABLE(rpm-backend ${rpm-backend_SOURCES})
-TARGET_LINK_LIBRARIES(rpm-backend rpm-util "rpm" "rpmio")
+TARGET_LINK_LIBRARIES(rpm-backend rpm-util "rpm" "rpmio" "dl")
 TARGET_LINK_LIBRARIES(rpm-backend ${libpkgs_LDFLAGS})
 TARGET_LINK_LIBRARIES(rpm-backend ${COMMCLIENT_LIBRARIES})
 TARGET_LINK_LIBRARIES(rpm-backend ${APPCODEEFL_LIBRARIES})
@@ -110,17 +102,38 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CLEAN_FILE_LI
 
 ###################################################################################################i
 configure_file(${backend_script_dir}/install_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/install_rpm_package_with_dbpath_ro.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_ro.sh @ONLY)
+configure_file(${backend_script_dir}/install_rpm_package_with_dbpath_rw.sh.in ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_rw.sh @ONLY)
 configure_file(${backend_script_dir}/uninstall_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/uninstall_rpm_package.sh @ONLY)
 configure_file(${backend_script_dir}/upgrade_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/upgrade_rpm_package_with_dbpath_ro.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_ro.sh @ONLY)
+configure_file(${backend_script_dir}/upgrade_rpm_package_with_dbpath_rw.sh.in ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_rw.sh @ONLY)
 configure_file(${backend_script_dir}/query_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/query_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/cpio_rpm_package.sh.in ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package.sh @ONLY)
+configure_file(${backend_script_dir}/cpio_rpm_package_update_xml.sh.in ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package_update_xml.sh @ONLY)
+configure_file(${backend_script_dir}/rpm_update_xml.sh.in ${CMAKE_CURRENT_BINARY_DIR}/rpm_update_xml.sh @ONLY)
+configure_file(${backend_script_dir}/coretpk_ro_xml_converter.sh.in ${CMAKE_CURRENT_BINARY_DIR}/coretpk_ro_xml_converter.sh @ONLY)
+configure_file(${backend_script_dir}/coretpk_rw_xml_converter.sh.in ${CMAKE_CURRENT_BINARY_DIR}/coretpk_rw_xml_converter.sh @ONLY)
+configure_file(${backend_script_dir}/coretpk_category_converter.sh.in ${CMAKE_CURRENT_BINARY_DIR}/coretpk_category_converter.sh @ONLY)
 
 INSTALL(FILES
                 ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_ro.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/install_rpm_package_with_dbpath_rw.sh
                 ${CMAKE_CURRENT_BINARY_DIR}/uninstall_rpm_package.sh
                 ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_ro.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/upgrade_rpm_package_with_dbpath_rw.sh
                 ${CMAKE_CURRENT_BINARY_DIR}/query_rpm_package.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/cpio_rpm_package_update_xml.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/rpm_update_xml.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/coretpk_ro_xml_converter.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/coretpk_rw_xml_converter.sh
+                ${CMAKE_CURRENT_BINARY_DIR}/coretpk_category_converter.sh
                 DESTINATION bin)
 
-
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/rpm-installer-config.ini DESTINATION /usr/etc)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/coretpk-installer-config.ini DESTINATION /usr/etc)
 INSTALL(TARGETS rpm-backend DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_WRITE)
 
diff --git a/frontend/coretpk-installer-config.ini b/frontend/coretpk-installer-config.ini
new file mode 100644 (file)
index 0000000..255f395
--- /dev/null
@@ -0,0 +1,3 @@
+signature=on
+author-signature=on
+make-ext-directory=on
index 6a39cb8..1334807 100755 (executable)
@@ -23,7 +23,6 @@
 #ifndef __RPM_FRONTEND_H_
 #define __RPM_FRONTEND_H_
 
-#include <Elementary.h>
 #include <pkgmgr_installer.h>
 #include <bundle.h>
 
@@ -39,6 +38,8 @@
 #define PACKAGE        "rpm-installer"
 #endif                         /* PACKAGE */
 
+#define RPM_INSTALLER_VERSION "20141016.1"
+
 enum command {
        INVALID_CMD = -1,
        INSTALL_CMD = 1,
@@ -47,14 +48,22 @@ enum command {
        RECOVER_CMD = 4,
        CLEARDATA_CMD = 5,
        MOVE_CMD = 6,
+       SMACK_CMD = 7,
+       EFLWGT_INSTALL_CMD = 8,
+       ENABLE_CMD = 9,
+       DISABLE_CMD = 10,
+       CORETPK_INSTALL_CMD = 11,
+       CORETPK_DIRECTORY_INSTALL_CMD = 12,
+       CORETPK_REINSTALL_CMD = 13,
+       RPM_CMD_MAX = 14,
 };
 
 struct ri_frontend_cmdline_arg_t {
        int req_cmd;
        char *pkgid;
        char *keyid;
-       int quiet;
        int move_type;
+       char *clientid;
 };
 typedef struct ri_frontend_cmdline_arg_t ri_frontend_cmdline_arg;
 
@@ -65,24 +74,11 @@ struct ri_frontend_data_t {
 };
 typedef struct ri_frontend_data_t ri_frontend_data;
 
-struct appdata {
-       Evas *evas;
-       Evas_Object *win_main;
-       Evas_Coord root_w;
-       Evas_Coord root_h;
-       Evas_Object *main_view; /* for main view layout */
-       Evas_Object *scrollbar_label;
-};
 
-int app_create(void *user_data);
-int app_terminate(void *user_data);
-int app_pause(void *user_data);
-int app_resume(void *user_data);
-int app_reset(bundle *b, void *user_data);
-int app_rotation(enum appcore_rm, void *user_data);
 
 int _ri_cmdline_destroy(ri_frontend_data *data);
 int _ri_cmdline_process(ri_frontend_data *data);
+int _ri_parse_hybrid(int argc, char **argv);
 int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data);
 void _ri_stat_cb(const char *pkgid, const char *key, const char *val);
 
diff --git a/frontend/rpm-installer-config.ini b/frontend/rpm-installer-config.ini
new file mode 100644 (file)
index 0000000..769c929
--- /dev/null
@@ -0,0 +1 @@
+signature=off
\ No newline at end of file
index bc92dca..dbaa26a 100755 (executable)
 
 #include <stdio.h>
 #include <pthread.h>
-
-#include <Elementary.h>
-#include <appcore-efl.h>
 #include <string.h>
-#include <glib-object.h>
+//#include <device/power.h>
 
 #include "rpm-frontend.h"
-#include "rpm-homeview.h"
 #include "rpm-installer-util.h"
 #include "rpm-installer.h"
 #include <pkgmgr_installer.h>
 
+#define CONFIG_PATH            "/usr/etc/rpm-installer-config.ini"
 static void __ri_start_processing(void *user_data);
-static Eina_Bool __ri_elm_exit_cb(void *data);
+static int __ri_is_signature_verification_enabled();
 
 int ret_val = -1;
-struct appdata ad;
+/*flag to check whether signature verification is on/off*/
+int sig_enable = 0;
+int broadcast_disable = 0;
 extern char scrolllabel[256];
 extern ri_frontend_data front_data;
 pkgmgr_installer *pi = NULL;
 
-/**< Called before main loop */
-int app_create(void *user_data)
-{
-
-       int ret = 0;
-       struct appdata *data = (struct appdata *)user_data;
-       ri_frontend_cmdline_arg *fdata = front_data.args;
-       /*In case of downgrade, popup should be shown even if quiet mode*/
-       ret = _ri_frontend_launch_main_view(data);
-       return ret;
-}
-
-/**< Called after main loop */
-int app_terminate(void *user_data)
-{
-       struct appdata *data = (struct appdata *)user_data;
-       ri_frontend_cmdline_arg *fdata = front_data.args;
-       if (fdata->quiet == 0) {
-               _ri_destroy_home_view(data);
-       }
-       return 0;
-}
 
-/**< Called when every window goes back */
-int app_pause(void *user_data)
+static int __ri_is_signature_verification_enabled()
 {
-       return 0;
-}
-
-/**< Called when any window comes on top */
-int app_resume(void *user_data)
-{
-       return 0;
-}
-
-/**< Called at the first idler*/
-int app_reset(bundle *b, void *user_data)
-{
-       return 0;
-}
-
-/**< Called at rotate device*/
-int app_rotation(enum appcore_rm mode, void *user_data)
-{
-       if (user_data == NULL) {
-               _d_msg(DEBUG_ERR, "arg supplied is NULL \n");
-               return -1;
+       char buffer[1024] = {'\0'};
+       char *p = NULL;
+       FILE *fi = NULL;
+       int len = 0;
+       int ret = 0;
+       fi = fopen(CONFIG_PATH, "r");
+       if (fi == NULL) {
+               _LOGE("Failed to open config file [%s]\n", CONFIG_PATH);
+               return 0;
        }
-       struct appdata *data = (struct appdata *)user_data;
-       int angle;
-       switch (mode) {
-       case APPCORE_RM_LANDSCAPE_NORMAL:
-               angle = -90;
-               break;
-
-       case APPCORE_RM_LANDSCAPE_REVERSE:
-               angle = 90;
-               break;
-
-       case APPCORE_RM_PORTRAIT_REVERSE:
-               angle = 180;
-               break;
-
-       case APPCORE_RM_UNKNOWN:
-       case APPCORE_RM_PORTRAIT_NORMAL:
-       default:
-               angle = 0;
-               break;
+       while (fgets(buffer, 1024, fi) != NULL) {
+               /* buffer will be like signature=off\n\0*/
+               if (strncmp(buffer, "signature", strlen("signature")) == 0) {
+                       len = strlen(buffer);
+                       /*remove newline character*/
+                       buffer[len - 1] = '\0';
+                       p = strchr(buffer, '=');
+                       if (p) {
+                               p++;
+                               if (strcmp(p, "on") == 0)
+                                       ret = 1;
+                               else
+                                       ret = 0;
+                       }
+               } else {
+                       continue;
+               }
        }
-       elm_win_rotation_with_resize_set(data->win_main, angle);
-       return 0;
+       fclose(fi);
+       return ret;
 }
 
-Eina_Bool show_popup_cb(void *data)
-{
-       /*Avoid log printing as it is an idler function*/
-       int state = -1;
-       int ret = -1;
-       const char message[256] = {'\0'};
-       state = _ri_get_backend_state_info();
-       switch (state) {
-       case REQUEST_ACCEPTED:
-               break;
-       case GOT_PACKAGE_INFO_SUCCESSFULLY:
-               break;
-       case REQUEST_PENDING:
-               strncpy(message, _("Continue Downgrade?"), 255);
-               _ri_package_downgrade_information(message);
-               /*request is not completed yet. We just got confirmation
-               from user whether to downgrade or not*/
-               _ri_set_backend_state_info(REQUEST_ACCEPTED);
-               break;
-       case REQUEST_COMPLETED:
-       default:
-               if (front_data.args->quiet == 0) {
-                       _ri_frontend_update_progress_info(&ad, scrolllabel);
-                       return 0;
-               } else
-                       elm_exit();
-               break;
-       }
-
-       return 1;
-}
 
 static void __ri_start_processing(void *user_data)
 {
        int ret = 0;
        if (user_data == NULL) {
-               _d_msg(DEBUG_ERR, "arg supplied is NULL \n");
-               return -1;
+               _LOGE("arg supplied is NULL \n");
+               return;
        }
        ri_frontend_data *data = (ri_frontend_data *) user_data;
-       g_type_init();
        ret = _ri_cmdline_process(data);
        ret_val = ret;
        _ri_cmdline_destroy(data);
@@ -165,29 +94,57 @@ static void __ri_start_processing(void *user_data)
 
 int main(int argc, char *argv[])
 {
+       int i = 0;
        int ret = 0;
+       char *errstr = NULL;
        ri_frontend_cmdline_arg *data = NULL;
-       struct appcore_ops ops;
-       ops.create = app_create;
-       ops.terminate = app_terminate;
-       ops.pause = app_pause;
-       ops.resume = app_resume;
-       ops.reset = app_reset;
-       ops.data = &ad;
-       ecore_init();
-       appcore_set_i18n(PACKAGE, LOCALE_PATH);
-       _d_msg_init("rpm-installer");
+       struct stat st;
+
+       _LOGD("------------------------------------------------");
+       _LOGD(" [START] rpm-installer: version=[%s]", RPM_INSTALLER_VERSION);
+       _LOGD("------------------------------------------------");
+
+       // hybrid
+       ret = _ri_parse_hybrid(argc, argv);
+       if (ret == RPM_INSTALLER_SUCCESS) {
+               _LOGD("------------------------------------------------");
+               _LOGD(" [END] rpm-installer: _ri_parse_hybrid() succeed.");
+               _LOGD("------------------------------------------------");
+               fprintf(stdout, "%d", ret);
+               return 0;
+       }
+
+       for (i = 0; i < argc; i++)
+       {
+               const char* pStr = argv[i];
+               if (pStr)
+               {
+                       _LOGD("argv[%d] = [%s]", i, pStr);
+               }
+       }
+
+       // power_lock
+//     ret = device_power_request_lock(POWER_LOCK_CPU, 0);
+//     _LOGD("device_power_lock_state(POWER_LOCK_CPU, 0), ret = [%d]", ret);
+
+       /* Initialize the xml parser */
+       xmlInitParser();
+       // _LOGD("xml parser initialized");
+
+       /*get signature verification config*/
+       sig_enable = __ri_is_signature_verification_enabled();
+       _LOGD("signature verification mode is [%s]", sig_enable?"on":"off");
+
        data = (ri_frontend_cmdline_arg *) calloc(1,
                                                  sizeof
                                                  (ri_frontend_cmdline_arg));
        if (data == NULL) {
-               _d_msg(DEBUG_ERR, "Not Enough Memory\n");
+               _LOGE("Not Enough Memory\n");
                ret = RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY;
                goto ERROR;
        }
        data->keyid = NULL;
        data->pkgid = NULL;
-       data->quiet = 0;
        data->req_cmd = INVALID_CMD;
        data->move_type = -1;
 
@@ -195,49 +152,101 @@ int main(int argc, char *argv[])
           to parse the arguments */
        if ((ret =
             _ri_parse_cmdline(argc, argv, data)) != RPM_INSTALLER_SUCCESS) {
-               _d_msg(DEBUG_ERR, "_ri_parse_cmdline failed \n");
+               _LOGE("_ri_parse_cmdline failed \n");
                goto ERROR;
        }
 
+#if 0
+       /*
+       Check for converted wgt package.
+       */
+       if(strstr(data->pkgid,".wgt") != NULL){
+               _LOGD("[%s] is eflwgt package.\n", data->pkgid);
+               if(data->req_cmd == INSTALL_CMD){
+                       data->req_cmd = EFLWGT_INSTALL_CMD;
+                       ret = _ri_process_wgt_package(&data->pkgid);
+                       if(ret != RPM_INSTALLER_SUCCESS){
+                               _ri_error_no_to_string(ret, &errstr);
+                               _LOGE("ERROR:[%s]",errstr);
+                               goto ERROR;
+                       }
+               }else{
+                       ret = RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED;
+                       _ri_error_no_to_string(ret,&errstr);
+                       _LOGE("ERROR:[%s]",errstr);
+                       goto ERROR;
+               }
+       }
+#endif
+
+       if (strstr(data->keyid, "change-state") != NULL) {
+               _LOGE("change-state for [%s]\n", data->pkgid);
+               if (data->req_cmd == INSTALL_CMD) {
+                       data->req_cmd = ENABLE_CMD;
+               } else if (data->req_cmd == DELETE_CMD) {
+                       data->req_cmd = DISABLE_CMD;
+               } else {
+                       ret = RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED;
+                       _ri_error_no_to_string(ret,&errstr);
+                       _LOGE("ERROR:[%s]",errstr);
+                       goto ERROR;
+               }
+       }
+
+       /*installation for coretpk*/
+       if ((strstr(argv[0], "coretpk") != NULL)
+                       && (data->req_cmd == INSTALL_CMD)) {
+               if (stat(data->pkgid, &st)) {
+                       ret = RPM_INSTALLER_ERR_UNKNOWN;
+                       _ri_error_no_to_string(ret, &errstr);
+                       _LOGE("ERROR:[%s]",errstr);
+                       goto ERROR;
+               }
+
+               if (S_ISDIR(st.st_mode)) {
+                       _LOGD("[%s] is directory for tpk.\n", data->pkgid);
+                       data->req_cmd = CORETPK_DIRECTORY_INSTALL_CMD;
+               } else {
+                       _LOGD("[%s] is tpk package.\n", data->pkgid);
+                       data->req_cmd = CORETPK_INSTALL_CMD;
+               }
+       }
+
        front_data.args = data;
        front_data.security_cookie = NULL;
        front_data.error = NULL;
 
        __ri_start_processing(&front_data);
 
-       /*The installer has finished the installation/uninstallation.
-          Now, if it was a non quiet operation we need to show the popup. */
-       ecore_idler_add(show_popup_cb, NULL);
+       ret = ret_val;
+       if ((strstr(data->keyid, ".tpk") != NULL) || (strstr(data->pkgid,".wgt") != NULL)) {
+               if(!ret_val) {
+                       _LOGD("sync() start");
+                       sync();
+                       _LOGD("sync() end");
+               }
+       }
+
 
-       _d_msg(DEBUG_RESULT, "About to run EFL Main Loop");
-       appcore_efl_main(PACKAGE, &argc, &argv, &ops);
-       _d_msg(DEBUG_RESULT, "%d\n", ret_val);
+ERROR:
+//     device_power_release_lock(POWER_LOCK_CPU);
 
-       _d_msg_deinit();
        if (pi) {
                pkgmgr_installer_free(pi);
                pi = NULL;
        }
-       if(!ret_val)
-               sync();
 
-       return ret_val;
-
- ERROR:
        if (data) {
-               if (data->pkgid) {
-                       free(data->pkgid);
-                       data->pkgid = NULL;
-               }
-               if (data->keyid) {
-                       free(data->keyid);
-                       data->keyid = NULL;
-               }
                free(data);
                data = NULL;
        }
-       _d_msg(DEBUG_RESULT, "%d\n", ret);
-       _d_msg_deinit();
+
+       xmlCleanupParser();
+       _LOGD("------------------------------------------------");
+       _LOGD(" [END] rpm-installer: result=[%d]", ret);
+       _LOGD("------------------------------------------------");
+
+
        return ret;
 
 }
index 794fd15..c6da09a 100755 (executable)
 #include <getopt.h>
 #include <pthread.h>
 #include <stdio.h>
-#include <appcore-efl.h>
 #include <pkgmgr_installer.h>
 #include <security-server.h>
 #include "rpm-frontend.h"
 #include "rpm-installer-util.h"
 #include "rpm-installer.h"
-#include "rpm-homeview.h"
+#include "coretpk-installer.h"
 
 #define _FIX_POP_UP_
 extern struct appdata ad;
@@ -40,6 +39,8 @@ extern pkgmgr_installer *pi;
 ri_frontend_data front_data;
 char scrolllabel[256];
 int move_type;
+#define BUF_SIZE 1024
+#define OTP_USR_APPS "/opt/usr/apps"
 
 static void __ri_show_usage(char **arg);
 static int __ri_process_request(ri_frontend_cmdline_arg *fdata);
@@ -56,39 +57,68 @@ static void __ri_show_usage(char **arg)
                i++;
        }
 
-       _d_msg(DEBUG_INFO, "%s\n", buffer);
-       _d_msg(DEBUG_INFO,
+       _LOGD("%s\n", buffer);
+       _LOGD(
               "\nrpm-backend usage\n   rpm-backend -k <keyid>  <command> <pkgid | pkg_path> [-q] \n\n");
-       _d_msg(DEBUG_INFO, "<Commands> \n");
-       _d_msg(DEBUG_INFO,
+       _LOGD("<Commands> \n");
+       _LOGD(
               "\t -i <package file path>         : install package file \n");
-       _d_msg(DEBUG_INFO,
+       _LOGD(
               "\t -k <keyid>                   : key id file \n");
-       _d_msg(DEBUG_INFO,
+       _LOGD(
               "\t -r : (recover). Must ignore specific package name or path \n");
-       _d_msg(DEBUG_INFO,
+       _LOGD(
               "\t -d <package name>            : delete a package with package name \n");
-       _d_msg(DEBUG_INFO,
+       _LOGD(
               "\t -q : (quiet) run in background without any user interaction \n");
+       _LOGD(
+              "\t -s : (smack) apply smack rule and set smack label\n");
+}
+
+int _ri_parse_hybrid(int argc, char **argv)
+{
+       int i = 0;
+
+       if (argv[1] != NULL) {
+               if (!strcmp(argv[1], "-iv")) {
+                       _LOGE("Hybrid Installation start\n");
+
+                       for (i = 0; i < argc; i++) {
+                               const char* arg_str = argv[i];
+                               if (arg_str)
+                                       _LOGE("argv[%d] = [%s]\n", i, arg_str);
+                       }
+
+                       if (_coretpk_installer_request_hybrid(argv[1][1], argv[2], atoi(argv[4])) == 0) {
+                               return RPM_INSTALLER_SUCCESS;
+                       } else {
+                               return RPM_INSTALLER_ERR_INTERNAL;
+                       }
+               } else if (!strcmp(argv[1], "-uv")) {
+                       _LOGE("Hybrid Uninstallation start\n");
+                       return RPM_INSTALLER_SUCCESS;
+               }
+       }
+
+       return RPM_INSTALLER_ERR_WRONG_PARAM;
 }
 
 int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data)
 {
        int req_cmd = INVALID_CMD;
        const char *pkgid = NULL;
-       int quiet = 0;
        const char *pkeyid = NULL;
        int ret = 0;
        int move_type = -1;
        pi = pkgmgr_installer_new();
        if (!pi) {
-               _d_msg(DEBUG_ERR,
+               _LOGE(
                       "Failure in creating the pkgmgr_installer object \n");
                return RPM_INSTALLER_ERR_WRONG_PARAM;
        }
        ret = pkgmgr_installer_receive_request(pi, argc, argv);
        if (ret) {
-               _d_msg(DEBUG_ERR, "pkgmgr_installer_receive_request failed \n");
+               _LOGE("pkgmgr_installer_receive_request failed \n");
                return RPM_INSTALLER_ERR_WRONG_PARAM;
        }
        ret = pkgmgr_installer_get_request_type(pi);
@@ -96,6 +126,9 @@ int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data)
        case PKGMGR_REQ_INSTALL:
                req_cmd = INSTALL_CMD;
                break;
+       case PKGMGR_REQ_REINSTALL:
+               req_cmd = CORETPK_REINSTALL_CMD;
+               break;
        case PKGMGR_REQ_UNINSTALL:
                req_cmd = DELETE_CMD;
                break;
@@ -108,6 +141,9 @@ int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data)
        case PKGMGR_REQ_MOVE:
                req_cmd = MOVE_CMD;
                break;
+       case PKGMGR_REQ_SMACK:
+               req_cmd = SMACK_CMD;
+               break;
        case PKGMGR_REQ_PERM:
                goto PARSEERROR;
        case PKGMGR_REQ_INVALID:
@@ -119,43 +155,54 @@ int _ri_parse_cmdline(int argc, char **argv, ri_frontend_cmdline_arg *data)
        if (req_cmd != RECOVER_CMD) {
                pkgid = pkgmgr_installer_get_request_info(pi);
                if (!pkgid) {
-                       _d_msg(DEBUG_ERR,
+                       _LOGE(
                               "pkgmgr_installer_get_request_info failed \n");
                        return RPM_INSTALLER_ERR_WRONG_PARAM;
                }
                pkeyid = pkgmgr_installer_get_session_id(pi);
                if (!pkeyid) {
-                       _d_msg(DEBUG_ERR, "pkgmgr_installer_get_session_id failed \n");
-                       return RPM_INSTALLER_ERR_WRONG_PARAM;
-               }
-
-               quiet = pkgmgr_installer_is_quiet(pi);
-               if (quiet != 0 && quiet != 1) {
-                       _d_msg(DEBUG_ERR, "pkgmgr_installer_is_quiet failed \n");
+                       _LOGE("pkgmgr_installer_get_session_id failed \n");
                        return RPM_INSTALLER_ERR_WRONG_PARAM;
                }
-
                move_type = pkgmgr_installer_get_move_type(pi);
        }
-       if ((req_cmd < INSTALL_CMD) ||(req_cmd > MOVE_CMD)) {
-               _d_msg(DEBUG_ERR, "invalid command \n");
+//Logically dead code,the value of req_cmd never satisfies the condition
+#if 0
+       if ((req_cmd < INSTALL_CMD) ||(req_cmd > RPM_CMD_MAX)) {
+               _LOGE("invalid command \n");
                goto PARSEERROR;
        }
-
+#endif
        data->req_cmd = req_cmd;
        data->pkgid = (char *)pkgid;
-       data->quiet = quiet;
        data->keyid = (char *)pkeyid;
        data->move_type = move_type;
+       data->clientid = (char *)pkgmgr_installer_get_caller_pkgid(pi);
+
        return RPM_INSTALLER_SUCCESS;
 
  PARSEERROR:
-       _d_msg(DEBUG_ERR, "Error in parsing input parameter\n");
+       _LOGE("Error in parsing input parameter\n");
        __ri_show_usage(argv);
        return RPM_INSTALLER_ERR_WRONG_PARAM;
 
 }
 
+static int __ri_is_core_tpk_app(char *pkgid)
+{
+       char pkgpath[BUF_SIZE] = {'\0'};
+
+       snprintf(pkgpath, BUF_SIZE, "%s/%s/tizen-manifest.xml", OTP_USR_APPS, pkgid);
+
+       if (access(pkgpath, R_OK) == 0) {
+               _LOGE("This is a core tpk app.");
+               return 0;
+       } else {
+               _LOGE("This is not a core tpk app.");
+               return -1;
+       }
+}
+
 static int __ri_process_request(ri_frontend_cmdline_arg *data)
 {
        int ret = 0;
@@ -165,44 +212,92 @@ static int __ri_process_request(ri_frontend_cmdline_arg *data)
        char *keyid = NULL;
        if (data->req_cmd != RECOVER_CMD) {
                pkgid = strdup(data->pkgid);
-                if (PM_UNLIKELY(pkgid == NULL)) {
-                        _d_msg(DEBUG_ERR, "strdup failed\n");
-                        return RPM_INSTALLER_ERR_WRONG_PARAM;
-                }
-                keyid = strdup(data->keyid);
-                if (PM_UNLIKELY(keyid == NULL)) {
-                        _d_msg(DEBUG_ERR, "strdup failed\n");
-                        free(pkgid);
-                        return RPM_INSTALLER_ERR_WRONG_PARAM;
-                }
+               if (PM_UNLIKELY(pkgid == NULL)) {
+                       _LOGE("strdup failed\n");
+                       return RPM_INSTALLER_ERR_WRONG_PARAM;
+               }
+               keyid = strdup(data->keyid);
+               if (PM_UNLIKELY(keyid == NULL)) {
+                       _LOGE("strdup failed\n");
+                       free(pkgid);
+                       pkgid = NULL;
+                       return RPM_INSTALLER_ERR_WRONG_PARAM;
+               }
+       }
+
+       if (pkgid == NULL) {
+               _LOGE("pkgid is null\n");
+               return -1;
        }
+
        switch (data->req_cmd) {
        case INSTALL_CMD:
-               _d_msg(DEBUG_INFO, "rpm-backend -i %s\n", pkgid);
-               ret = _rpm_backend_interface(keyid, pkgid, "install");
+               _LOGD("rpm-backend -i %s\n", pkgid);
+               ret = _rpm_backend_interface(keyid, pkgid, "install", data->clientid);
                break;
        case DELETE_CMD:
-               _d_msg(DEBUG_INFO, "rpm-backend -d %s\n", pkgid);
-               ret = _rpm_backend_interface(keyid, pkgid, "remove");
+               if (__ri_is_core_tpk_app(pkgid) == 0) {
+                       _LOGD("------------------------------------------------");
+                       _LOGD("uninstallation: tpk, pkgid=[%s]", pkgid);
+                       _LOGD("------------------------------------------------");
+                       ret = _coretpk_backend_interface("coretpk-uninstall", data);
+               } else {
+                       _LOGD("uninstallation for rpm [%s]", pkgid);
+                       ret = _rpm_backend_interface(keyid, pkgid, "remove", NULL);
+               }
                break;
        case CLEARDATA_CMD:
-               _d_msg(DEBUG_INFO, "rpm-backend -c %s\n", pkgid);
-               ret = _rpm_backend_interface(keyid, pkgid, "cleardata");
+               _LOGD("rpm-backend -c %s\n", pkgid);
+               ret = _rpm_backend_interface(keyid, pkgid, "cleardata", NULL);
                break;
        case MOVE_CMD:
-               _d_msg(DEBUG_INFO, "rpm-backend -m %s -t %d\n", pkgid, data->move_type);
-               move_type = data->move_type;
-               ret = _rpm_backend_interface(keyid, pkgid, "move");
+               if (__ri_is_core_tpk_app(pkgid) == 0) {
+                       _LOGD("coretpk-move %s\n", pkgid);
+                       ret = _coretpk_backend_interface("coretpk-move", data);
+               } else {
+                       _LOGD("rpm-backend -m %s -t %d\n", pkgid, data->move_type);
+                       move_type = data->move_type;
+                       ret = _rpm_backend_interface(keyid, pkgid, "move", NULL);
+               }
                break;
        case RECOVER_CMD:
-               _d_msg(DEBUG_INFO, "rpm-backend -r \n");
-               ret = _rpm_backend_interface(keyid, pkgid, "recover");
+               _LOGD("rpm-backend -r \n");
+               ret = _rpm_backend_interface(keyid, pkgid, "recover", NULL);
+               break;
+       case SMACK_CMD:
+               _LOGD("rpm-backend -s %s", pkgid);
+               ret = _rpm_backend_interface(keyid, pkgid, "smack", NULL);
+               break;
+       case EFLWGT_INSTALL_CMD:
+               _LOGD("eflwgt-install %s\n", pkgid);
+               ret = _rpm_backend_interface(keyid, pkgid, "eflwgt-install", data->clientid);
+               break;
+       case CORETPK_INSTALL_CMD:
+               _LOGD("------------------------------------------------");
+               _LOGD("installation: tpk, arg=[%s]", pkgid);
+               _LOGD("------------------------------------------------");
+               ret = _coretpk_backend_interface("coretpk-install", data);
+               break;
+       case CORETPK_REINSTALL_CMD:
+               _LOGD("coretpk-reinstall %s\n", pkgid);
+               ret = _coretpk_backend_interface("coretpk-reinstall", data);
+               break;
+       case CORETPK_DIRECTORY_INSTALL_CMD:
+               _LOGD("coretpk-directory_install %s\n", pkgid);
+               ret = _coretpk_backend_interface("coretpk-directory-install", data);
+               break;
+       case ENABLE_CMD:
+               _LOGD("rpm enable %s\n", pkgid);
+               ret = _rpm_backend_interface(keyid, pkgid, "rpm-enable", NULL);
+               break;
+       case DISABLE_CMD:
+               _LOGD("rpm disable %s\n", pkgid);
+               ret = _rpm_backend_interface(keyid, pkgid, "rpm-disable", NULL);
                break;
        default:
-               _d_msg(DEBUG_ERR,
-                      "Error Never Come Here as Error is already checked\n");
-
+               _LOGE("Error Never Come Here as Error is already checked\n");
        }
+
        if (keyid) {
                free(keyid);
                keyid = NULL;
@@ -219,22 +314,16 @@ void _ri_stat_cb(const char *pkgid, const char *key, const char *val)
 {
 
        if (NULL == pkgid || NULL == key || NULL == val) {
-               _d_msg(DEBUG_ERR, "Either pkgid/key/val is NULL\n");
+               _LOGE("Either pkgid/key/val is NULL\n");
                return;         /*TODO: handle error. */
        }
 
-       char *pkgid_modified = NULL;
+       char pkgid_modified[PATH_MAX] = {0};
        char delims[] = "/";
        char *result = NULL;
        char *pkgid_tmp = NULL;
        char *saveptr = NULL;
 
-       pkgid_modified = (char *)malloc(strlen(pkgid) + 1);
-       if (pkgid_modified == NULL) {
-               _d_msg(DEBUG_ERR, "pkgid_modified is NULL. Malloc failed\n");
-               return;
-       }
-       memset(pkgid_modified, '\0', strlen(pkgid) + 1);
        memcpy(pkgid_modified, pkgid, strlen(pkgid));
 
        result = strtok_r(pkgid_modified, delims, &saveptr);
@@ -254,21 +343,21 @@ void _ri_stat_cb(const char *pkgid, const char *key, const char *val)
                switch (front_data.args->req_cmd) {
                case INSTALL_CMD:
                        snprintf(requesttype, sizeof(requesttype),
-                               _("Installation"));
+                               "installation");
                        break;
                case DELETE_CMD:
-                       snprintf(requesttype, sizeof(requesttype), _("Deletion"));
+                       snprintf(requesttype, sizeof(requesttype), "deletion");
                        break;
                case CLEARDATA_CMD:
                        snprintf(requesttype, sizeof(requesttype),
-                                _("Clear Data"));
+                                "clear data");
                        break;
                case MOVE_CMD:
                        snprintf(requesttype, sizeof(requesttype),
-                                _("Move"));
+                                "move");
                        break;
                default:
-                       snprintf(requesttype, sizeof(requesttype), _("Recovery"));
+                       snprintf(requesttype, sizeof(requesttype), "recovery");
                        break;
                }
 
@@ -276,17 +365,17 @@ void _ri_stat_cb(const char *pkgid, const char *key, const char *val)
                        /* Error Happened */
                        snprintf(scrolllabel, sizeof(scrolllabel),
                                 "%s :: %s:: %s:: %s", requesttype, pkgid_tmp,
-                                dgettext("sys_string", "IDS_COM_POP_ERROR"),
+                                "error",
                                 front_data.error);
-                       _d_msg(DEBUG_ERR, "%s\n", scrolllabel);
+                       _LOGE("%s\n", scrolllabel);
                        ret_val = _ri_string_to_error_no(front_data.error);
-                       _d_msg(DEBUG_ERR, "%d\n", ret_val);
+                       _LOGE("%d\n", ret_val);
 
                } else {
                        snprintf(scrolllabel, sizeof(scrolllabel),
                                 " %s :: %s :: %s", requesttype, pkgid_tmp,
-                                dgettext("sys_string", "IDS_COM_POP_SUCCESS"));
-                       _d_msg(DEBUG_INFO, "%s\n", scrolllabel);
+                               "success");
+                       _LOGD("%s\n", scrolllabel);
                        ret_val = 0;
                }
        }
@@ -294,49 +383,15 @@ void _ri_stat_cb(const char *pkgid, const char *key, const char *val)
 
 int _ri_cmdline_process(ri_frontend_data *data)
 {
-       char *cookie = NULL;
-       int cookie_size = 0;
-       int cookie_ret = 0;
-
        int ret = 0;
        ri_frontend_cmdline_arg *fdata = data->args;
-
-       cookie_size = security_server_get_cookie_size();
-       /* If security server is down or some other
-          error occured, raise failure */
-       if (0 >= cookie_size) {
-               /* TODO: raise error */
-               _d_msg(DEBUG_ERR,
-                      "security_server_get_cookie_size: Security server down \n");
-       } else {
-               cookie = calloc(cookie_size, sizeof(char));
-               cookie_ret =
-                   security_server_request_cookie(cookie, cookie_size);
-               /* TODO: Check cookie_ret...
-                  (See security-server.h to check return code) */
-       }
-
-       if (cookie != NULL)
-               _d_msg(DEBUG_INFO, "Got Cookie with size = %d\n", cookie_size);
-
-       data->security_cookie = cookie;
-
+       /*rpm-installer is invoked by pkgmgr-server hence server should do cookie validation*/
        ret = __ri_process_request(fdata);
        if (ret != RPM_INSTALLER_SUCCESS) {
-               _d_msg(DEBUG_ERR, "__ri_process_request: Error\n");
-               goto RETURN;
+               _LOGE("__ri_process_request: Error\n");
+               return ret;
        }
-
        return RPM_INSTALLER_SUCCESS;
-
- RETURN:
-
-       if (data->security_cookie) {
-               free(data->security_cookie);
-               data->security_cookie = NULL;
-       }
-
-       return ret;
 }
 
 int _ri_cmdline_destroy(ri_frontend_data *data)
@@ -344,8 +399,10 @@ int _ri_cmdline_destroy(ri_frontend_data *data)
        if (data == NULL)
                return 0;
 
-       if (data->security_cookie)
+       if (data->security_cookie){
                free(data->security_cookie);
+               data->security_cookie = NULL;
+       }
 
        return 0;
 
diff --git a/frontend/ui/src/rpm-homeview.c b/frontend/ui/src/rpm-homeview.c
deleted file mode 100755 (executable)
index 0a127b1..0000000
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * rpm-installer
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>,
- * Jaeho Lee <jaeho81.lee@samsung.com>, Shobhit Srivastava <shobhit.s@samsung.com>
- *
- * 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 <appcore-efl.h>
-#include <pthread.h>
-#ifdef HAVE_X11
-#include <Ecore_X.h>
-#endif
-#ifdef HAVE_WAYLAND
-#include <Ecore.h>
-#include <Ecore_Wayland.h>
-#endif
-
-#include "rpm-frontend.h"
-#include "rpm-installer-util.h"
-#include "rpm-homeview.h"
-#include "rpm-installer.h"
-
-#define DESKTOP_W   720.0
-
-extern struct appdata ad;
-int do_upgrade = -1;
-extern ri_frontend_data front_data;
-Evas_Object *popup_global;
-
-static void __ri_response_cb1(void *data, Evas_Object *obj, void *event);
-static void __ri_response_cb2(void *data, Evas_Object *obj, void *event);
-static void __ri_win_del(void *data, Evas_Object *obj, void *event);
-static Eina_Bool __ri_perform_downgrade(void *data);
-
-void _ri_information_popup(Evas_Smart_Cb func, const char *output,
-                          void *user_param)
-{
-       if (!ad.win_main)
-               return;
-       evas_object_show(ad.win_main);
-       Evas_Object *popup = NULL;
-       popup = elm_popup_add(ad.win_main);
-       if (!popup)
-               return;
-       elm_object_part_text_set(popup, dgettext("sys_string",
-                                               "IDS_COM_BODY_INFORMATION"), NULL);
-       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
-                                        EVAS_HINT_EXPAND);
-       elm_object_text_set(popup, output);
-       Evas_Object *button = NULL;
-       button = elm_button_add(popup);
-       elm_object_text_set(button, dgettext("sys_string", "IDS_COM_SK_OK"));
-       elm_object_part_content_set(popup, "button1", button);
-       evas_object_smart_callback_add(button, "clicked", func, user_param);
-       evas_object_show(popup);
-}
-
-void _ri_package_downgrade_popup(Evas_Smart_Cb func1,
-                               Evas_Smart_Cb func2,
-                               const char *output, void *user_param)
-{
-       if (!ad.win_main)
-               return;
-       evas_object_show(ad.win_main);
-       Evas_Object *popup = NULL;
-       popup = elm_popup_add(ad.win_main);
-       if (!popup)
-               return;
-       elm_object_part_text_set(popup, dgettext("sys_string",
-                                       "IDS_COM_BODY_INFORMATION"), NULL);
-       evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND,
-                                EVAS_HINT_EXPAND);
-       elm_object_text_set(popup, output);
-       Evas_Object *button1 = NULL;
-       Evas_Object *button2 = NULL;
-       button1 = elm_button_add(popup);
-       elm_object_text_set(button1, dgettext("sys_string", "IDS_COM_SK_YES"));
-       elm_object_part_content_set(popup, "button1", button1);
-       evas_object_smart_callback_add(button1, "clicked", func1, user_param);
-
-       button2 = elm_button_add(popup);
-       elm_object_text_set(button2, dgettext("sys_string", "IDS_COM_SK_NO"));
-       elm_object_part_content_set(popup, "button2", button2);
-       evas_object_smart_callback_add(button2, "clicked", func2, user_param);
-       popup_global = popup;
-       evas_object_show(popup);
-}
-
-static void __ri_win_del(void *data, Evas_Object *obj, void *event)
-{
-       elm_exit();
-}
-
-static Eina_Bool __ri_perform_downgrade(void *data)
-{
-       int ret = -1;
-       ret = _rpm_installer_package_install(front_data.args->pkgid,
-                                            true, "--force");
-       if (ret != 0) {
-               char *errstr = NULL;
-               _ri_error_no_to_string(ret, &errstr);
-               _ri_broadcast_status_notification(front_data.args->pkgid,
-                                                 "error", errstr);
-               _ri_stat_cb(front_data.args->pkgid, "error", errstr);
-               _ri_broadcast_status_notification(front_data.args->pkgid,
-                                                 "end", "fail");
-               _ri_stat_cb(front_data.args->pkgid, "end", "fail");
-               _d_msg(DEBUG_ERR,
-                      "install failed with err(%d) (%s)\n", ret, errstr);
-       } else {
-               _d_msg(DEBUG_INFO, "install success\n");
-               _ri_broadcast_status_notification(front_data.args->pkgid,
-                                                 "end", "ok");
-               _ri_stat_cb(front_data.args->pkgid, "end", "ok");
-       }
-       _ri_set_backend_state_info(REQUEST_COMPLETED);
-       _ri_set_backend_state(1);
-       return 0;
-}
-
-static void __ri_response_cb1(void *data, Evas_Object *obj, void *event)
-{
-       printf("\nresponse callback=%d\n", (int)event);
-       do_upgrade = 1;
-
-       ecore_idler_add(__ri_perform_downgrade, NULL);
-       _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
-       evas_object_del(obj);
-       evas_object_del(popup_global);
-       obj = NULL;
-}
-static void __ri_response_cb2(void *data, Evas_Object *obj, void *event)
-{
-       printf("\nresponse callback=%d\n", (int)event);
-       do_upgrade = 0;
-
-       ecore_idler_add(__ri_perform_downgrade, NULL);
-       evas_object_del(obj);
-       evas_object_del(popup_global);
-       _d_msg(DEBUG_INFO, "doUpgrade is %d\n", do_upgrade);
-       obj = NULL;
-}
-
-Eina_Bool _ri_init_appdata(struct appdata *user_data)
-{
-       unsigned char *prop_data = NULL;
-       int rotation = 0;
-       int w;
-       int h;
-       int x;
-       int y;
-       int count = 0;
-       int ret = 0;
-       user_data->win_main = elm_win_add(NULL, PACKAGE, ELM_WIN_DIALOG_BASIC);
-       if (!user_data->win_main)
-               return EINA_FALSE;
-
-       elm_win_title_set(user_data->win_main, PACKAGE);
-       elm_win_alpha_set(user_data->win_main, EINA_TRUE);
-       elm_win_borderless_set(user_data->win_main, EINA_TRUE);
-       elm_win_raise(user_data->win_main);
-#ifdef HAVE_X11
-       ecore_x_window_geometry_get(ecore_x_window_root_get
-                                       (ecore_x_window_focus_get()), &x, &y, &w,
-                                       &h);
-       ret = ecore_x_window_prop_property_get(ecore_x_window_root_get
-                                       (ecore_x_window_focus_get()),
-                                       ECORE_X_ATOM_E_ILLUME_ROTATE_ROOT_ANGLE,
-                                       ECORE_X_ATOM_CARDINAL, 32,
-                                       &prop_data, &count);
-#else /* HAVE_WAYLAND */ /* TO_DO_WAYLAND */
-       _d_msg(DEBUG_INFO, "Operation not supported in a pure Wayland\
-               environment. To do: replace the X11 dependant functions with\
-                Wayland compatible ones.\n");
-#endif
-       if (ret && prop_data)
-               memcpy(&rotation, prop_data, sizeof(int));
-       if (prop_data)
-               free(prop_data);
-       evas_object_resize(user_data->win_main, w, h);
-       evas_object_move(user_data->win_main, x, y);
-       /*evas_object_show(user_data->win_main);
-       evas_object_smart_callback_add(user_data->win_main, "delete,request",
-                                      __ri_win_del, NULL);
-       elm_win_indicator_state_set(user_data->win_main, EINA_TRUE);*/
-       double s;
-       s = w / DESKTOP_W;
-       elm_config_scale_set(s);
-       user_data->evas = evas_object_evas_get(user_data->win_main);
-       if (!user_data->evas)
-               return EINA_FALSE;
-
-       return EINA_TRUE;
-}
-
-Eina_Bool _ri_init_home_view(struct appdata *user_data)
-{
-       return EINA_TRUE;
-
-}
-
-void _ri_destroy_home_view(struct appdata *user_data)
-{
-
-       if (!user_data) {
-               return;
-       }
-       evas_object_del(user_data->main_view);
-}
-
-int _ri_frontend_launch_main_view(struct appdata *data)
-{
-       /* create UI */
-       if (!_ri_init_appdata(data)) {
-               return 0;
-       }
-       if (!_ri_init_home_view(data)) {
-               return 0;
-       }
-       return 0;
-}
-
-void _ri_frontend_update_progress_info(struct appdata *data, char *progressinfo)
-{
-       elm_object_text_set(data->scrollbar_label, progressinfo);
-       _ri_information_popup(__ri_win_del, progressinfo, data);
-}
-
-void _ri_package_downgrade_information(const char *message)
-{
-       _ri_package_downgrade_popup(__ri_response_cb1, __ri_response_cb2, message, &ad);
-}
index 3a1bcc1..813b2a4 100755 (executable)
@@ -35,33 +35,116 @@ extern "C" {
 #include <libgen.h>
 #include <wait.h>
 #include <stdio.h>
+#include <dirent.h>
+#include <rpm/header.h>
+#include <rpm/rpmts.h>
+#include <rpm/rpmlib.h>
+
+
+#include <libxml/parser.h>
+#include <libxml/xmlreader.h>
+#include <libxml/xmlschemas.h>
+#include <pkgmgr-info.h>
+
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#define        LOG_TAG         "rpm-installer"
+#endif
+
+#define _LOGE(fmt, arg...) do { \
+                       fprintf(stderr, "  ## "fmt"\n", ##arg); \
+                       LOGE(fmt, ##arg); \
+               } while (0)
+
+#define _LOGD(fmt, arg...) do { \
+                       fprintf(stderr, "  ## "fmt"\n", ##arg); \
+                       LOGD(fmt, ##arg); \
+               } while (0)
+
+#define _LOGP(fmt, arg...)     fprintf(stderr, "[coretpk-installer] "fmt"\n", ##arg)
 
 #define RPM_BACKEND_EXEC       "rpm-backend"
 
-#define PKGTYPE "rpm"
+#define WGT_CONFIG     "config.xml"
+#define SIGNATURE1_XML                                         "signature1.xml"
+#define SIGNATURE2_XML                                         "signature2.xml"
+#define AUTHOR_SIGNATURE_XML                           "author-signature.xml"
+
+#define ASCII(s) (const char *)s
+#define XMLCHAR(s) (const xmlChar *)s
+
+#define PKG_MAX_LEN            128
+#define VERSION_MAX_LEN        11
+
+#define DIRECTORY_PERMISSION_755                       0755
+#define DIRECTORY_PERMISSION_644                       0644
+#define FILE_PERMISSION_755                                    0755
+#define FILE_PERMISSION_644                                    0644
+
+struct pkginfo_t {
+       char package_name[PKG_MAX_LEN];
+       char version[VERSION_MAX_LEN];
+};
+typedef struct pkginfo_t pkginfo;
+
+struct privilegeinfo_t {
+       char package_id[PKG_MAX_LEN];
+       int visibility;
+};
+typedef struct privilegeinfo_t privilegeinfo;
 
-#define RPM_INSTALLER_SUCCESS                                          0
-#define RPM_INSTALLER_ERR_WRONG_PARAM                          101
+#ifndef PATH_MAX
+# define PATH_MAX 4096
+#endif
+
+#define FREE_AND_STRDUP(from, to) do { \
+               if (to) free((void *)to); \
+               if (from) to = strdup(from); \
+       } while (0)
+
+
+#define FREE_AND_NULL(ptr) do { \
+               if (ptr) { \
+                       free((void *)ptr); \
+                       ptr = NULL; \
+               } \
+       } while (0)
+
+
+/*Error number according to Tizen Native Package Manager Command Specification v1.0*/
+#define RPM_INSTALLER_SUCCESS                                  0
+#define RPM_INSTALLER_ERR_WRONG_PARAM                          64
 #define RPM_INSTALLER_ERR_DBUS_PROBLEM                         102
-#define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY                    62
-#define RPM_INSTALLER_ERR_PACKAGE_EXIST                                103
-#define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED                104
+#define RPM_INSTALLER_ERR_PACKAGE_EXIST                                121
+#define RPM_INSTALLER_ERR_PACKAGE_NOT_INSTALLED                        104
 #define RPM_INSTALLER_ERR_RESOURCE_BUSY                                105
-#define RPM_INSTALLER_ERR_UNKNOWN                                      120
-#define RPM_INSTALLER_ERR_PKG_NOT_FOUND                                1
-#define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION         107
-#define RPM_INSTALLER_ERR_NO_RPM_FILE                          108
+#define RPM_INSTALLER_ERR_NOT_ENOUGH_MEMORY                    63
+#define RPM_INSTALLER_ERR_NOT_SUPPOTED_VERSION                 107
+#define RPM_INSTALLER_ERR_NO_RPM_FILE                          2
 #define RPM_INSTALLER_ERR_DB_ACCESS_FAILED                     109
-#define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED         110
-#define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED         111
-#define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS                112
-#define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION       113
+#define RPM_INSTALLER_ERR_RPM_OPERATION_FAILED                 110
+#define RPM_INSTALLER_ERR_PACKAGE_NOT_UPGRADED                 111
+#define RPM_INSTALLER_ERR_RPM_SCRIPT_WRONG_ARGS                        112
+#define RPM_INSTALLER_ERR_NEED_USER_CONFIRMATION               113
 #define RPM_INSTALLER_ERR_PACKAGE_INSTALLATION_DISABLED                114
 #define RPM_INSTALLER_ERR_PACKAGE_UNINSTALLATION_DISABLED      115
 #define RPM_INSTALLER_ERR_CLEAR_DATA_FAILED                    116
-#define RPM_INSTALLER_ERR_INTERNAL                                     117
+#define RPM_INSTALLER_ERR_INTERNAL                             117
+#define RPM_INSTALLER_ERR_PKG_NOT_FOUND                                1
+#define RPM_INSTALLER_ERR_UNKNOWN                              119
 #define RPM_INSTALLER_ERR_NO_MANIFEST                          11
 #define RPM_INSTALLER_ERR_INVALID_MANIFEST                     12
+#define RPM_INSTALLER_ERR_SIG_NOT_FOUND                                21
+#define RPM_INSTALLER_ERR_SIG_INVALID                                  22
+#define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED                              23
+#define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND                          31
+#define RPM_INSTALLER_ERR_CERT_INVALID                                 32
+#define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED                33
+#define RPM_INSTALLER_ERR_NO_CONFIG                                         34
+#define RPM_INSTALLER_ERR_INVALID_CONFIG       35
+#define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED    36
 
 #define RPM_INSTALLER_SUCCESS_STR                      "Success"
 #define RPM_INSTALLER_ERR_WRONG_PARAM_STR              "Wrong Input Param"
@@ -84,29 +167,51 @@ extern "C" {
 #define RPM_INSTALLER_ERR_INTERNAL_STR "Internal Error"
 #define RPM_INSTALLER_ERR_NO_MANIFEST_STR      "Manifest File Not Found"
 #define RPM_INSTALLER_ERR_INVALID_MANIFEST_STR "Manifest Validation Failed"
-
+#define RPM_INSTALLER_ERR_SIG_NOT_FOUND_STR            "Signature Not Found"
+#define RPM_INSTALLER_ERR_SIG_INVALID_STR      "Invalid Signature"
+#define RPM_INSTALLER_ERR_SIG_VERIFICATION_FAILED_STR  "Signature Verification Failed"
+#define RPM_INSTALLER_ERR_ROOT_CERT_NOT_FOUND_STR              "Root Cert Not Found"
+#define RPM_INSTALLER_ERR_CERT_INVALID_STR     "Invalid Certificate"
+#define RPM_INSTALLER_ERR_CERTCHAIN_VERIFICATION_FAILED_STR    "Certificate Chain Verification Failed"
+#define RPM_INSTALLER_ERR_NO_CONFIG_STR                "Config file is not present"
+#define RPM_INSTALLER_ERR_INVALID_CONFIG_STR   "Config file is not valid"
+#define RPM_INSTALLER_ERR_CMD_NOT_SUPPORTED_STR        "Unsupported Command"
 
 #define DEBUG_ERR              0x0001
 #define DEBUG_INFO             0x0002
 #define DEBUG_RESULT   0x0004
 
 #define RPM_LOG        1
+#define SIZE_KB        1024
+#define BUFF_SZE    1024
+#define RPM_INSTALLER_RW_INSTALL_PATH "/opt/usr"
+#define DIR_RPM_INSTALLER_APPLICATIONS_TEMP "/tmp/wgt_unzip"
+#define RPM_UNZIP "/usr/bin/unzip"
+#define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
+#define DIR_RPM_WGT_SMACK_RULE_OPT "/opt/usr/.wgt/"
 
-       void _print_msg(int type, int exetype, char *format, ...);
-#define _d_msg(type, fmtstr, args...) { \
-_print_msg(type, RPM_LOG, "%s:%d:%s(): " fmtstr, basename(__FILE__), \
-__LINE__, __func__, ##args); \
-}
-
-       void _d_msg_init(char *program);
-       void _d_msg_deinit();
-       int _ri_xsystem(const char *argv[]);
-       char *_ri_substring(const char *str, size_t begin, size_t len);
-       int _ri_tok_split_string(char tok, char *input, char **list,
-                                unsigned long listmax);
        void _ri_error_no_to_string(int errnumber, char **errstr);
+       int _ri_recursive_delete_dir(char *dirname);
        int _ri_string_to_error_no(char *errstr);
+       int _ri_get_available_free_memory(const char *opt_path, unsigned long *free_mem);
+       int  _ri_process_wgt_package(char** pkgid);
+       unsigned long  _ri_calculate_file_size(const char *filename);
+       int  _ri_wgt_package_extract(char *pkgid);
+       int  _ri_stream_config_file(const char* filename, pkginfo *info);
+       void _ri_process_config_node(xmlTextReaderPtr reader, pkginfo * info);
+       int _verify_wgt_package_signature_files();
+       void _ri_remove_wgt_unzip_dir();
+       int _ri_xsystem(const char *argv[]);
 
+       int  _get_package_name_from_xml(char* manifest,char** pkgname);
+       int  _get_pkgname_from_rpm_name(char* pkgfile,char** pkgname);
+       int _child_element(xmlTextReaderPtr reader, int depth);
+       char *_ri_basename(char *name);
+       int _ri_verify_sig_and_cert(const char *sigfile, int *visibility);
+       char* _manifest_to_package(const char* manifest);
+       int _rpm_delete_dir(char *dirname);
+       unsigned long  _ri_calculate_rpm_size( char* rpm_file);
+       int _ri_get_attribute(xmlTextReaderPtr reader,char *attribute, const char **xml_attribute);
 #ifdef __cplusplus
 }
 #endif                         /* __cplusplus */
diff --git a/packaging/rpm-installer.changes b/packaging/rpm-installer.changes
deleted file mode 100644 (file)
index 80bb2c6..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-* Sun Aug 25 2013 Chengwei Yang <chengwei.yang@intel.com> accepted/tizen/20130710.221501@cefe683
-- Merge "resetting manifest requested domain to floor" into tizen
-- resetting manifest requested domain to floor
-- resetting manifest requested domain to floor
-- Fix wrong runtime dependence.
-- merge with master
-- Tizen 2.1 base
-- Initial empty repository
-
diff --git a/packaging/rpm-installer.manifest b/packaging/rpm-installer.manifest
deleted file mode 100644 (file)
index 017d22d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-<manifest>
- <request>
-    <domain name="_"/>
- </request>
-</manifest>
index 52eba85..76712a2 100755 (executable)
@@ -1,14 +1,10 @@
-%bcond_with wayland
-%bcond_with x
-
 Name:       rpm-installer
 Summary:    Native rpm installer
-Version:    0.1.25
-Release:    0
+Version:    0.1.146
+Release:    1
 Group:      System/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
-Source1001: rpm-installer.manifest
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 BuildRequires:  cmake
@@ -25,74 +21,87 @@ BuildRequires:  pkgconfig(pkgmgr-types)
 BuildRequires:  pkgconfig(pkgmgr-installer)
 BuildRequires:  pkgconfig(pkgmgr-parser)
 BuildRequires:  pkgconfig(pkgmgr)
-BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires: pkgconfig(pkgmgr-info)
 BuildRequires:  pkgconfig(app2sd)
 BuildRequires:  pkgconfig(libxml-2.0)
 BuildRequires:  pkgconfig(security-server)
-BuildRequires:  pkgconfig(elementary)
-BuildRequires:  pkgconfig(appcore-efl)
-BuildRequires:  pkgconfig(evas)
-BuildRequires:  pkgconfig(ecore)
+BuildRequires:  pkgconfig(cert-svc)
+BuildRequires:  pkgconfig(xmlsec1)
+BuildRequires:  pkgconfig(libxslt)
 BuildRequires:  pkgconfig(edje)
+BuildRequires: pkgconfig(libprivilege-control)
+BuildRequires:  pkgconfig(capi-appfw-app-manager)
+BuildRequires:  pkgconfig(capi-system-device)
+BuildRequires: pkgconfig(aul)
+BuildRequires:  pkgconfig(openssl)
+BuildRequires:  pkgconfig(minizip)
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  gettext-tools
-%if %{with x}
-BuildRequires:  pkgconfig(ecore-x)
-%endif
-%if %{with wayland}
-BuildRequires:  pkgconfig(ecore-wayland)
-%endif
-Requires:  cpio
+Requires:  /bin/cpio
 
 %description
 Native rpm installer
 
+Requires(post): pkgmgr
+
 %prep
 %setup -q
-cp %{SOURCE1001} .
 
 %build
 CFLAGS+=" -fpic"
-%cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
-%if %{with wayland}
-        -DWAYLAND_SUPPORT=On \
-%else
-        -DWAYLAND_SUPPORT=Off \
-%endif
-%if %{with x}
-        -DX11_SUPPORT=On
-%else
-        -DX11_SUPPORT=Off
+
+%if 0%{?tizen_build_binary_release_type_eng}
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS ?DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
 %endif
 
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+
 make %{?jobs:-j%jobs}
 
 %install
 rm -rf %{buildroot}
 %make_install
 
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE %{buildroot}/usr/share/license/%{name}
+
 %post
+mkdir -p /usr/etc/package-manager/backend
+mkdir -p /usr/etc/package-manager/backendlib
+mkdir -p /opt/share/packages/.pkgmgr/rpm-installer/
+
+ln -sf %{_bindir}/rpm-backend /etc/package-manager/backend/coretpk
 ln -sf %{_bindir}/rpm-backend /etc/package-manager/backend/rpm
 ln -sf /usr/lib/libnativerpm.so /etc/package-manager/backendlib/librpm.so
+ln -sf /usr/lib/libnativerpm.so /etc/package-manager/backendlib/libcoretpk.so
 
-chmod 700 %{_bindir}/rpm-backend
-
-vconftool set -t int db/private/rpm-installer/state "0"
-vconftool set -t int db/private/rpm-installer/stateinfo "0"
-vconftool set -t int db/private/rpm-installer/requestinfo/command "0"
-vconftool set -t string db/private/rpm-installer/requestinfo/pkgname ""
-vconftool set -t int db/private/rpm-installer/requestinfo/options "0"
+vconftool set -t int db/private/rpm-installer/state "0" -f -s system::vconf_inhouse
+vconftool set -t int db/private/rpm-installer/stateinfo "0" -f -s system::vconf_inhouse
+vconftool set -t int db/private/rpm-installer/requestinfo/command "0" -f -s system::vconf_inhouse
+vconftool set -t string db/private/rpm-installer/requestinfo/pkgname "" -f -s system::vconf_inhouse
+vconftool set -t int db/private/rpm-installer/requestinfo/options "0" -f -s system::vconf_inhouse
 
 %files
-%manifest %{name}.manifest
-%attr(0700,-,-) %{_bindir}/rpm-backend
+%manifest rpm-installer.manifest
+%attr(0755,-,-) %{_bindir}/rpm-backend
 %attr(0700,-,-) %{_bindir}/install_rpm_package.sh
+%attr(0700,-,-) %{_bindir}/install_rpm_package_with_dbpath_ro.sh
+%attr(0700,-,-) %{_bindir}/install_rpm_package_with_dbpath_rw.sh
 %attr(0755,-,-) %{_bindir}/query_rpm_package.sh
 %attr(0700,-,-) %{_bindir}/uninstall_rpm_package.sh
 %attr(0700,-,-) %{_bindir}/upgrade_rpm_package.sh
-%attr(0644,-,-) %lang(en_GB) /usr/share/locale/en_GB/LC_MESSAGES/rpm-installer.mo
-%attr(0644,-,-) %lang(ja) /usr/share/locale/ja_JP/LC_MESSAGES/rpm-installer.mo
-%attr(0644,-,-) %lang(zh) /usr/share/locale/zh_CN/LC_MESSAGES/rpm-installer.mo
-%attr(0644,-,-) %lang(en_US) /usr/share/locale/en_US/LC_MESSAGES/rpm-installer.mo
-%attr(0644,-,-) %lang(ko) /usr/share/locale/ko_KR/LC_MESSAGES/rpm-installer.mo
+%attr(0700,-,-) %{_bindir}/upgrade_rpm_package_with_dbpath_ro.sh
+%attr(0700,-,-) %{_bindir}/upgrade_rpm_package_with_dbpath_rw.sh
+%attr(0700,-,-) %{_bindir}/cpio_rpm_package.sh
+%attr(0700,-,-) %{_bindir}/cpio_rpm_package_update_xml.sh
+%attr(0755,-,-) %{_bindir}/coretpk_ro_xml_converter.sh
+%attr(0755,-,-) %{_bindir}/coretpk_rw_xml_converter.sh
+%attr(0700,-,-) %{_bindir}/coretpk_category_converter.sh
+%attr(0700,-,-) %{_bindir}/rpm_update_xml.sh
+%attr(0744,-,-) /usr/etc/rpm-installer-config.ini
+%attr(0744,-,-) /usr/etc/coretpk-installer-config.ini
 %attr(0644,-,-) /usr/lib/libnativerpm.so
+%attr(0755,-,-) /opt/share/packages/.pkgmgr/rpm-installer/rpm_installer_deactvation_list.txt
+/usr/share/license/%{name}
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
deleted file mode 100755 (executable)
index e3aebb4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-# for i18n
-
-SET(POFILES en_US.po en_GB.po ja_JP.po ko_KR.po zh_CN.po)
-
-SET(MSGFMT "/usr/bin/msgfmt")
-
-FOREACH(pofile ${POFILES})
-       SET(pofile ${CMAKE_CURRENT_SOURCE_DIR}/${pofile})
-       MESSAGE("PO: ${pofile}")
-       GET_FILENAME_COMPONENT(absPofile ${pofile} ABSOLUTE)
-       GET_FILENAME_COMPONENT(lang ${absPofile} NAME_WE)
-       SET(moFile ${CMAKE_CURRENT_BINARY_DIR}/${lang}.mo)
-       ADD_CUSTOM_COMMAND(
-                       OUTPUT ${moFile}
-                       COMMAND ${MSGFMT} -o ${moFile} ${absPofile}
-                       DEPENDS ${absPofile}
-       )
-       INSTALL(FILES ${moFile}
-                       DESTINATION share/locale/${lang}/LC_MESSAGES RENAME ${PROJECT_NAME}.mo)
-       SET(moFiles ${moFiles} ${moFile})
-ENDFOREACH(pofile)
-
-MESSAGE(".mo files: ${moFiles}")
-ADD_CUSTOM_TARGET(po ALL DEPENDS ${moFiles})
diff --git a/po/POTFILES.in b/po/POTFILES.in
deleted file mode 100755 (executable)
index d657f08..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-# List of source files containing translatable strings.
-frontend/src/rpm-cmdline.c
-frontend/src/rpm-appcore-intf.c
diff --git a/po/en_GB.po b/po/en_GB.po
deleted file mode 100755 (executable)
index a04a042..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-01-03 15:32+0900\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: frontend/src/rpm-appcore-intf.c:129
-#, c-format
-msgid "Continue Downgrade?"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:245
-#, c-format
-msgid "Installation"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:248
-#, c-format
-msgid "Deletion"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:255
-#, c-format
-msgid "Recovery"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:252
-#, c-format
-msgid "Clear Data"
-msgstr ""
diff --git a/po/en_US.po b/po/en_US.po
deleted file mode 100755 (executable)
index a04a042..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-01-03 15:32+0900\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: frontend/src/rpm-appcore-intf.c:129
-#, c-format
-msgid "Continue Downgrade?"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:245
-#, c-format
-msgid "Installation"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:248
-#, c-format
-msgid "Deletion"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:255
-#, c-format
-msgid "Recovery"
-msgstr ""
-
-#: frontend/src/rpm-cmdline.c:252
-#, c-format
-msgid "Clear Data"
-msgstr ""
diff --git a/po/ja_JP.po b/po/ja_JP.po
deleted file mode 100755 (executable)
index 41544d5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-01-03 15:32+0900\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: frontend/src/rpm-appcore-intf.c:129
-#, c-format
-msgid "Continue Downgrade?"
-msgstr "ダウングレード を続行しますか?"
-
-#: frontend/src/rpm-cmdline.c:245
-#, c-format
-msgid "Installation"
-msgstr "インストール"
-
-#: frontend/src/rpm-cmdline.c:248
-#, c-format
-msgid "Deletion"
-msgstr "削除"
-
-#: frontend/src/rpm-cmdline.c:255
-#, c-format
-msgid "Recovery"
-msgstr "回復"
-
-#: frontend/src/rpm-cmdline.c:252
-#, c-format
-msgid "Clear Data"
-msgstr "明確な データ"
diff --git a/po/ko_KR.po b/po/ko_KR.po
deleted file mode 100755 (executable)
index 521011d..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-01-03 15:32+0900\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: frontend/src/rpm-appcore-intf.c:129
-#, c-format
-msgid "Continue Downgrade?"
-msgstr "다운 그레이드 를 계속하시겠습니까?"
-
-#: frontend/src/rpm-cmdline.c:245
-#, c-format
-msgid "Installation"
-msgstr "설치"
-
-#: frontend/src/rpm-cmdline.c:248
-#, c-format
-msgid "Deletion"
-msgstr "삭제"
-
-#: frontend/src/rpm-cmdline.c:255
-#, c-format
-msgid "Recovery"
-msgstr "회복"
-
-#: frontend/src/rpm-cmdline.c:252
-#, c-format
-msgid "Clear Data"
-msgstr "삭제 데이터"
diff --git a/po/update-po.sh b/po/update-po.sh
deleted file mode 100755 (executable)
index 39ae5d5..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/sh
-
-PACKAGE=rpm-installer
-SRCROOT=..
-POTFILES=POTFILES.in
-
-#ALL_LINGUAS= am az be ca cs da de el en_CA en_GB es et fi fr hr hu it ja ko lv mk ml ms nb ne nl pa pl pt pt_BR ru rw sk sl sr sr@Latn sv ta tr uk vi zh_CN zh_TW
-ALL_LINGUAS="en_US en_GB ja_JP ko_KR zh_CN"
-
-XGETTEXT=/usr/bin/xgettext
-MSGMERGE=/usr/bin/msgmerge
-
-echo -n "Make ${PACKAGE}.pot  "
-if [ ! -e $POTFILES ] ; then
-       echo "$POTFILES not found"
-       exit 1
-fi
-
-$XGETTEXT --default-domain=${PACKAGE} --directory=${SRCROOT} \
-               --add-comments --keyword=_ --keyword=N_ --files-from=$POTFILES
-if [ $? -ne 0 ]; then
-       echo "xgettext error"
-       exit 1
-fi
-
-if [ ! -f ${PACKAGE}.po ]; then
-       echo "No such file: ${PACKAGE}.po"
-       exit 1
-fi
-
-rm -f ${PACKAGE}.pot && mv ${PACKAGE}.po ${PACKAGE}.pot
-echo "done"
-
-for LANG in $ALL_LINGUAS; do
-       echo "$LANG : "
-
-       if [ ! -e $LANG.po ] ; then
-               sed 's/CHARSET/UTF-8/g' ${PACKAGE}.pot > ${LANG}.po
-               echo "${LANG}.po created"
-       else
-               if $MSGMERGE ${LANG}.po ${PACKAGE}.pot -o ${LANG}.new.po ; then
-                       if cmp ${LANG}.po ${LANG}.new.po > /dev/null 2>&1; then
-                               rm -f ${LANG}.new.po
-                       else
-                               if mv -f ${LANG}.new.po ${LANG}.po; then
-                                       echo ""
-                               else
-                                       echo "msgmerge for $LANG.po failed: cannot move $LANG.new.po to $LANG.po" 1>&2
-                                       rm -f ${LANG}.new.po
-                                       exit 1
-                               fi
-                       fi
-               else
-                       echo "msgmerge for $LANG failed!"
-                       rm -f ${LANG}.new.po
-               fi
-       fi
-       echo ""
-done
diff --git a/po/zh_CN.po b/po/zh_CN.po
deleted file mode 100755 (executable)
index e2b11d6..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# SOME DESCRIPTIVE TITLE.
-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#
-#, fuzzy
-msgid ""
-msgstr ""
-"Project-Id-Version: PACKAGE VERSION\n"
-"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-01-03 15:32+0900\n"
-"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
-"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
-"Language-Team: LANGUAGE <LL@li.org>\n"
-"MIME-Version: 1.0\n"
-"Content-Type: text/plain; charset=UTF-8\n"
-"Content-Transfer-Encoding: 8bit\n"
-
-#: frontend/src/rpm-appcore-intf.c:129
-#, c-format
-msgid "Continue Downgrade?"
-msgstr "繼續 降級?"
-
-#: frontend/src/rpm-cmdline.c:245
-#, c-format
-msgid "Installation"
-msgstr "安裝"
-
-#: frontend/src/rpm-cmdline.c:248
-#, c-format
-msgid "Deletion"
-msgstr "刪除"
-
-#: frontend/src/rpm-cmdline.c:255
-#, c-format
-msgid "Recovery"
-msgstr "恢復"
-
-#: frontend/src/rpm-cmdline.c:252
-#, c-format
-msgid "Clear Data"
-msgstr "清除數據"
diff --git a/rpm-installer.manifest b/rpm-installer.manifest
new file mode 100644 (file)
index 0000000..89be23c
--- /dev/null
@@ -0,0 +1,22 @@
+<manifest>
+       <request>
+               <domain name="_"/>
+       </request>
+       <assign>
+               <filesystem path="/usr/bin/install_rpm_package.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/install_rpm_package_with_dbpath_ro.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/install_rpm_package_with_dbpath_rw.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/query_rpm_package.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/rpm-backend" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/uninstall_rpm_package.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/upgrade_rpm_package.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/upgrade_rpm_package_with_dbpath_ro.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/upgrade_rpm_package_with_dbpath_rw.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/cpio_rpm_package.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/cpio_rpm_package_update_xml.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/coretpk_ro_xml_converter.sh" label="_" exec_label="none"/>   
+               <filesystem path="/usr/bin/coretpk_rw_xml_converter.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/coretpk_category_converter.sh" label="_" exec_label="none"/>
+               <filesystem path="/usr/bin/rpm_update_xml.sh" label="_" exec_label="none"/>
+       </assign>
+</manifest>
diff --git a/rpm_installer_deactvation_list.txt.in b/rpm_installer_deactvation_list.txt.in
new file mode 100644 (file)
index 0000000..a40a8a3
--- /dev/null
@@ -0,0 +1,2 @@
+pkgid=com.samsung.joyn-chat:state=off:
+pkgid=com.samsung.joyn-share:state=off:
\ No newline at end of file