summaryrefslogtreecommitdiff
path: root/installer
diff options
context:
space:
mode:
Diffstat (limited to 'installer')
-rw-r--r--installer/CMakeLists.txt55
-rw-r--r--installer/pkgmgr-installer.pc.in2
-rw-r--r--installer/pkgmgr_installer.c1418
-rw-r--r--installer/pkgmgr_installer_config.h33
-rw-r--r--installer/pkgmgr_installer_signal_agent.c337
-rw-r--r--installer/src/api_stub.cc364
-rw-r--r--installer/src/control.cc354
-rw-r--r--installer/src/control.hh60
-rw-r--r--installer/src/pkgmgr_installer.h (renamed from installer/pkgmgr_installer.h)2
-rw-r--r--installer/src/pkgmgr_installer_debug.h (renamed from installer/pkgmgr_installer_debug.h)12
-rw-r--r--installer/src/pkgmgr_installer_error.h (renamed from installer/pkgmgr_installer_error.h)0
-rw-r--r--installer/src/pkgmgr_installer_info.h (renamed from installer/pkgmgr_installer_info.h)0
-rw-r--r--installer/src/pkgmgr_installer_type.h (renamed from installer/pkgmgr_installer_type.h)0
-rw-r--r--installer/src/request.cc120
-rw-r--r--installer/src/request.hh90
15 files changed, 1019 insertions, 1828 deletions
diff --git a/installer/CMakeLists.txt b/installer/CMakeLists.txt
index 9c734d0..e5e9553 100644
--- a/installer/CMakeLists.txt
+++ b/installer/CMakeLists.txt
@@ -1,32 +1,30 @@
-### Description
-# Communication modules for pkg-mgr client lib and server process
-# By Youmin Ha <youmin.ha@samsung.com>
+include(FindPkgConfig)
-cmake_minimum_required(VERSION 2.6)
-#set(CMAKE_SKIP_BUILD_RPATH true)
-set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+AUX_SOURCE_DIRECTORY(src SRCS)
-### Get required CFLAGS, LDFLAGS from pkg-config
+PKG_CHECK_MODULES(INSTALLER_DEPS REQUIRED
+ glib-2.0
+ gio-2.0
+ dlog
+ pkgmgr-info
+ libtzplatform-config
+ rpc-port
+ capi-appfw-event
+)
-include(FindPkgConfig)
-pkg_check_modules(installer_pkgs REQUIRED glib-2.0 gio-2.0 dlog pkgmgr-info libtzplatform-config)
-foreach(flag ${installer_pkgs_CFLAGS})
- set(installer_pkgs_CFLAGS_str "${installer_pkgs_CFLAGS_str} ${flag}")
-endforeach()
+FOREACH(FLAGS ${INSTALLER_DEPS_CFLAGS})
+ SET(INSTALLER_CFLAGS "${INSTALLER_CFLAGS} ${FLAGS}")
+ENDFOREACH(FLAGS)
-PKG_CHECK_MODULES(AGENT_DEPS REQUIRED glib-2.0 gio-2.0 dlog libsystemd)
-FOREACH(FLAG ${AGENT_DEPS_CFLAGS})
- SET(AGENT_CFLAGS "${AGENT_CFLAGS} ${FLAG}")
-ENDFOREACH()
+SET(CMAKE_C_FLAGS "${INSTALLER_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${INSTALLER_CFLAGS} -std=c++17 -fPIC")
-### Build modules
+INCLUDE_DIRECTORIES(include)
-## pkgmgr_installer object (by youmin.ha)
-# This library is for installer backend
-add_library(pkgmgr_installer SHARED pkgmgr_installer.c)
+### Build modules
+add_library(pkgmgr_installer SHARED ${SRCS})
set_target_properties(pkgmgr_installer PROPERTIES SOVERSION ${MAJORVER})
set_target_properties(pkgmgr_installer PROPERTIES VERSION ${FULLVER})
-set_target_properties(pkgmgr_installer PROPERTIES COMPILE_FLAGS "${installer_pkgs_CFLAGS_str} -fPIC")
target_link_libraries(pkgmgr_installer ${installer_pkgs_LDFLAGS})
### Create pc file
@@ -34,15 +32,8 @@ configure_file(pkgmgr-installer.pc.in ${CMAKE_CURRENT_BINARY_DIR}/pkgmgr-install
## Install
INSTALL(TARGETS pkgmgr_installer DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
-INSTALL(FILES pkgmgr_installer.h DESTINATION include/pkgmgr)
-INSTALL(FILES pkgmgr_installer_info.h DESTINATION include/pkgmgr)
-INSTALL(FILES pkgmgr_installer_error.h DESTINATION include/pkgmgr)
-INSTALL(FILES pkgmgr_installer_type.h DESTINATION include/pkgmgr)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer.h DESTINATION include/pkgmgr)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer_info.h DESTINATION include/pkgmgr)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer_error.h DESTINATION include/pkgmgr)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/pkgmgr_installer_type.h DESTINATION include/pkgmgr)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/pkgmgr-installer.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-## pkgmgr_installer_signal_agent
-ADD_EXECUTABLE(pkgmgr-installer-signal-agent pkgmgr_installer_signal_agent.c)
-SET_TARGET_PROPERTIES(pkgmgr-installer-signal-agent PROPERTIES COMPILE_FLAGS "${AGENT_CFLAGS} -fPIE")
-TARGET_LINK_LIBRARIES(pkgmgr-installer-signal-agent ${AGENT_DEPS_LDFLAGS} "-pie")
-
-INSTALL(TARGETS pkgmgr-installer-signal-agent DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
diff --git a/installer/pkgmgr-installer.pc.in b/installer/pkgmgr-installer.pc.in
index f812a3b..fe02345 100644
--- a/installer/pkgmgr-installer.pc.in
+++ b/installer/pkgmgr-installer.pc.in
@@ -11,6 +11,6 @@ includedir=@INCLUDEDIR@
Name: package manager installer library
Description: SLP package manager's installer lib for each backends
Version: @FULLVER@
-Requires:
+Requires: capi-appfw-event
Libs: -L${libdir} -lpkgmgr_installer
Cflags: -I${includedir}/pkgmgr
diff --git a/installer/pkgmgr_installer.c b/installer/pkgmgr_installer.c
deleted file mode 100644
index 82285e0..0000000
--- a/installer/pkgmgr_installer.c
+++ /dev/null
@@ -1,1418 +0,0 @@
-/*
- * slp-pkgmgr
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <getopt.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <tzplatform_config.h>
-
-#include "package-manager.h"
-#include "pkgmgr_installer.h"
-#include "pkgmgr_installer_config.h"
-#include "pkgmgr_installer_debug.h"
-#include "pkgmgr_installer_info.h"
-#include "pkgmgr_installer_error.h"
-#include "package-manager-types.h"
-
-#include <pkgmgr-info.h>
-
-/* API export macro */
-#ifndef API
-#define API __attribute__ ((visibility("default")))
-#endif
-
-#define MAX_STRLEN 1024
-#define MAX_QUERY_LEN 4096
-
-#define CHK_PI_RET(r) \
- do { if (NULL == pi) return (r); } while (0)
-
-#define OPTVAL_PRELOAD 1000
-#define OPTVAL_FORCE_REMOVAL 1001
-#define OPTVAL_PRELOAD_RW 1002
-#define OPTVAL_NO_REMOVAL 1003
-#define OPTVAL_KEEP_RWDATA 1004
-#define OPTVAL_PARTIAL_RW 1005
-#define OPTVAL_MIGRATE_EXTIMG 1006
-#define OPTVAL_SKIP_CHECK_REFERENCE 1007
-#define OPTVAL_RECOVER_DB 1008
-#define OPTVAL_RECOVERY_CLEANUP 1009
-
-/* Supported options */
-const char *short_opts = "k:l:i:d:c:m:t:o:r:p:s:b:e:M:y:u:w:D:A:qGS";
-const struct option long_opts[] = {
- { "session-id", 1, NULL, 'k' },
- { "license-path", 1, NULL, 'l' },
- { "install", 1, NULL, 'i' },
- { "uninstall", 1, NULL, 'd' },
- { "clear", 1, NULL, 'c' },
- { "move", 1, NULL, 'm' },
- { "move-type", 1, NULL, 't' },
- { "optional-data", 0, NULL, 'o' },
- { "reinstall", 0, NULL, 'r' },
- { "caller-pkgid", 1, NULL, 'p' },
- { "tep-path", 1, NULL, 'e' },
- { "tep-move", 1, NULL, 'M' },
- { "smack", 1, NULL, 's' },
- { "manifest-direct-install", 1, NULL, 'y' },
- { "mount-install", 1, NULL, 'w' },
- { "recovery", 1, NULL, 'b' },
- { "debug-mode", 0, NULL, 'G' },
- { "skip-optimization", 0, NULL, 'S' },
- { "preload", 0, NULL, OPTVAL_PRELOAD }, /* for preload RO */
- { "force-remove", 0, NULL, OPTVAL_FORCE_REMOVAL }, /* for preload RO/RW */
- { "preload-rw", 0, NULL, OPTVAL_PRELOAD_RW }, /* for preload RW */
- { "no-remove", 0, NULL, OPTVAL_NO_REMOVAL }, /* for preload RW */
- { "keep-rwdata", 0, NULL, OPTVAL_KEEP_RWDATA }, /* for preload RW */
- { "partial-rw", 0, NULL, OPTVAL_PARTIAL_RW }, /* for preload RO */
- { "migrate-extimg", 1, NULL, OPTVAL_MIGRATE_EXTIMG },
- { "skip-check-reference", 0, NULL, OPTVAL_SKIP_CHECK_REFERENCE },
- { "recover-db", 1, NULL, OPTVAL_RECOVER_DB },
- { "recovery-cleanup", 0, NULL, OPTVAL_RECOVERY_CLEANUP },
- { 0, 0, 0, 0 } /* sentinel */
-};
-
-struct pkgmgr_installer {
- int request_type;
- int move_type;
- int is_upgrade;
- char *pkgmgr_info;
- char *session_id;
- char *license_path;
- char *optional_data;
- char *caller_pkgid;
- uid_t target_uid;
- char *tep_path;
- int tep_move;
- int is_tep_included;
- int is_preload;
- int force_removal;
- int is_preload_rw;
- int no_removal;
- int keep_rwdata;
- int partial_rw;
- int debug_mode;
- int skip_check_reference;
- int skip_optimization;
- int recovery_cleanup;
- GDBusConnection *conn;
- GHashTable *pkg_list;
- GList *pkgs;
-};
-
-typedef struct pkg_signal_info {
- char *pkgid;
- char *pkg_type;
-} pkg_signal_info;
-
-static uid_t g_target_uid;
-static int g_debug_mode;
-static int g_skip_optimization;
-static pkgmgr_privilege_level g_privilege_level = PM_PRIVILEGE_UNKNOWN;
-
-static const char *__get_signal_name(pkgmgr_installer *pi, const char *key,
- const char *pkg_type)
-{
- if (strcmp(key, PKGMGR_INSTALLER_INSTALL_PERCENT_KEY_STR) == 0)
- return key;
- else if (strcmp(key, PKGMGR_INSTALLER_GET_SIZE_KEY_STR) == 0)
- return key;
- else if (strcmp(key, PKGMGR_INSTALLER_APPID_KEY_STR) == 0)
- return PKGMGR_INSTALLER_UNINSTALL_EVENT_STR;
- else if (strcmp(pkg_type, PKGMGR_INSTALLER_CLEAR_CACHE_KEY_STR) == 0)
- return pkg_type;
- else if (pi->is_upgrade)
- return PKGMGR_INSTALLER_UPGRADE_EVENT_STR;
-
-
- switch (pi->request_type) {
- case PKGMGR_REQ_INSTALL:
- case PKGMGR_REQ_MANIFEST_DIRECT_INSTALL:
- case PKGMGR_REQ_MOUNT_INSTALL:
- case PKGMGR_REQ_REINSTALL:
- case PKGMGR_REQ_ENABLE_PKG:
- case PKGMGR_REQ_RECOVER:
- return PKGMGR_INSTALLER_INSTALL_EVENT_STR;
- case PKGMGR_REQ_UNINSTALL:
- case PKGMGR_REQ_DISABLE_PKG:
- return PKGMGR_INSTALLER_UNINSTALL_EVENT_STR;
- case PKGMGR_REQ_UPGRADE:
- return PKGMGR_INSTALLER_UPGRADE_EVENT_STR;
- case PKGMGR_REQ_MOVE:
- return PKGMGR_INSTALLER_MOVE_EVENT_STR;
- case PKGMGR_REQ_ENABLE_APP:
- return PKGMGR_INSTALLER_APP_ENABLE_EVENT_STR;
- case PKGMGR_REQ_DISABLE_APP:
- return PKGMGR_INSTALLER_APP_DISABLE_EVENT_STR;
- case PKGMGR_REQ_ENABLE_APP_SPLASH_SCREEN:
- return PKGMGR_INSTALLER_APP_ENABLE_SPLASH_SCREEN_EVENT_STR;
- case PKGMGR_REQ_DISABLE_APP_SPLASH_SCREEN:
- return PKGMGR_INSTALLER_APP_DISABLE_SPLASH_SCREEN_EVENT_STR;
- case PKGMGR_REQ_CLEAR:
- return PKGMGR_INSTALLER_CLEAR_EVENT_STR;
- case PKGMGR_REQ_GETSIZE:
- return PKGMGR_INSTALLER_GET_SIZE_KEY_STR;
- case PKGMGR_REQ_RES_COPY:
- return PKGMGR_INSTALLER_RES_COPY_EVENT_STR;
- case PKGMGR_REQ_RES_CREATE_DIR:
- return PKGMGR_INSTALLER_RES_CREATE_DIR_EVENT_STR;
- case PKGMGR_REQ_RES_REMOVE:
- return PKGMGR_INSTALLER_RES_REMOVE_EVENT_STR;
- case PKGMGR_REQ_RES_UNINSTALL:
- return PKGMGR_INSTALLER_RES_UNINSTALL_EVENT_STR;
- }
-
- ERR("cannot find type");
-
- return NULL;
-}
-
-static int __send_signal_for_event(pkgmgr_installer *pi, const char *pkg_type,
- const char *pkgid, const char *appid, const char *key,
- const char *val)
-{
- char *sid;
- const char *tmp_appid = appid;
- const char *signal_name;
- GVariant *v;
- GVariantBuilder *builder;
- GError *err = NULL;
-
- if (!pi || pi->conn == NULL)
- return -1;
-
- sid = pi->session_id;
- if (!sid)
- sid = "";
-
- signal_name = __get_signal_name(pi, key, pkg_type);
- if (!signal_name) {
- ERR("unknown signal type");
- return -1;
- }
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)"));
- g_variant_builder_add(builder, "(sss)", pkgid,
- (tmp_appid ? tmp_appid : ""), pkg_type);
- v = g_variant_new("(usa(sss)ss)",
- pi->target_uid, sid, builder, key, val);
- g_variant_builder_unref(builder);
- if (g_dbus_connection_emit_signal(pi->conn, NULL,
- PKGMGR_INSTALLER_DBUS_OBJECT_PATH,
- PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name,
- v, &err) != TRUE) {
- ERR("failed to send dbus signal");
- if (err) {
- ERR("err: %s", err->message);
- g_error_free(err);
- }
- return -1;
- }
-
- return 0;
-}
-
-static int __send_signal_to_agent(uid_t uid, void *data, size_t len)
-{
- int fd;
- struct sockaddr_un sa;
- int r;
-
- fd = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0);
- if (fd == -1) {
- ERR("failed to create socket: %d", errno);
- return -1;
- }
-
- sa.sun_family = AF_UNIX;
- snprintf(sa.sun_path, sizeof(sa.sun_path), "/run/pkgmgr/agent/%d", uid);
-
- r = connect(fd, (struct sockaddr *)&sa, sizeof(sa));
- if (r == -1) {
- ERR("failed to connect socket(%s): %d", sa.sun_path, errno);
- close(fd);
- return -1;
- }
-
- r = send(fd, data, len, MSG_NOSIGNAL);
- if (r < 0) {
- ERR("failed to send data: %d", errno);
- close(fd);
- return -1;
- }
-
- close(fd);
-
- return 0;
-}
-
-static int __send_signal_for_event_for_uid(pkgmgr_installer *pi, uid_t uid,
- const char *pkg_type, const char *pkgid, const char *appid,
- const char *key, const char *val)
-{
- char *sid;
- const char *signal_name;
- const char *tmp_appid = appid;
- size_t name_size;
- GVariantBuilder *builder;
- GVariant *gv;
- gsize gv_len;
- gpointer gv_data;
- void *data;
- void *ptr;
- size_t data_len;
-
- if (!pi || pi->conn == NULL)
- return -1;
-
- sid = pi->session_id;
- if (!sid)
- sid = "";
-
- data_len = sizeof(size_t) + sizeof(gsize);
-
- signal_name = __get_signal_name(pi, key, pkg_type);
- if (!signal_name) {
- ERR("unknown signal name");
- return -1;
- }
-
- /* including null byte */
- name_size = strlen(signal_name) + 1;
- data_len += name_size;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)"));
- g_variant_builder_add(builder, "(sss)", pkgid,
- (tmp_appid ? tmp_appid : ""), pkg_type);
- gv = g_variant_new("(usa(sss)ss)", pi->target_uid, sid,
- builder, key, val);
- g_variant_builder_unref(builder);
- if (gv == NULL) {
- ERR("failed to create GVariant instance");
- return -1;
- }
- gv_len = g_variant_get_size(gv);
- gv_data = g_malloc(gv_len);
- g_variant_store(gv, gv_data);
- g_variant_unref(gv);
- data_len += gv_len;
-
- data = malloc(data_len);
- if (data == NULL) {
- ERR("out of memory");
- g_free(gv_data);
- return -1;
- }
- ptr = data;
- memcpy(ptr, &name_size, sizeof(size_t));
- ptr += sizeof(size_t);
- memcpy(ptr, &gv_len, sizeof(gsize));
- ptr += sizeof(gsize);
- memcpy(ptr, signal_name, name_size);
- ptr += name_size;
- memcpy(ptr, gv_data, gv_len);
- g_free(gv_data);
-
- if (__send_signal_to_agent(uid, data, data_len)) {
- ERR("failed to send signal to agent");
- free(data);
- return -1;
- }
-
- free(data);
-
- return 0;
-}
-
-static void __free_pkg_list(gpointer data)
-{
- pkg_signal_info *info = (pkg_signal_info *)data;
- free(info->pkgid);
- free(info->pkg_type);
- free(info);
-}
-
-API pkgmgr_installer *pkgmgr_installer_new(void)
-{
- pkgmgr_installer *pi;
- GError *err = NULL;
-
- pi = calloc(1, sizeof(struct pkgmgr_installer));
- if (pi == NULL)
- return NULL;
-
- pi->conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
- if (pi->conn == NULL) {
- ERR("failed to get bus: %s", err->message);
- g_error_free(err);
- free(pi);
- return NULL;
- }
-
- pi->tep_path = NULL;
- pi->tep_move = 0;
- pi->request_type = PKGMGR_REQ_INVALID;
- pi->pkg_list = g_hash_table_new_full(
- g_str_hash, g_str_equal, NULL, __free_pkg_list);
- return pi;
-}
-
-API pkgmgr_installer *pkgmgr_installer_offline_new(void)
-{
- pkgmgr_installer *pi;
-
- pi = calloc(1, sizeof(struct pkgmgr_installer));
- if (pi == NULL)
- return NULL;
-
- pi->tep_path = NULL;
- pi->tep_move = 0;
- pi->request_type = PKGMGR_REQ_INVALID;
-
- return pi;
-}
-
-API int pkgmgr_installer_free(pkgmgr_installer *pi)
-{
- CHK_PI_RET(-EINVAL);
-
- /* free members */
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- if (pi->session_id)
- free(pi->session_id);
- if (pi->optional_data)
- free(pi->optional_data);
- if (pi->caller_pkgid)
- free(pi->caller_pkgid);
- if (pi->tep_path)
- free(pi->tep_path);
-
- if (pi->conn) {
- g_dbus_connection_flush_sync(pi->conn, NULL, NULL);
- g_object_unref(pi->conn);
- }
-
- if (pi->pkgs)
- g_list_free_full(pi->pkgs, free);
-
- if (pi->pkg_list)
- g_hash_table_destroy(pi->pkg_list);
-
- free(pi);
-
- return 0;
-}
-
-static void __parse_multiple_pkgs(pkgmgr_installer *pi, int argc, char **argv)
-{
- while ((optind <= argc) && (*argv[optind - 1] != '-')) {
- pi->pkgs = g_list_append(pi->pkgs, strdup(argv[optind - 1]));
- optind++;
- }
- optind--;
-}
-
-API int
-pkgmgr_installer_receive_request(pkgmgr_installer *pi,
- const int argc, char **argv)
-{
- CHK_PI_RET(-EINVAL);
-
- int r = 0;
-
- /* Parse argv */
- optind = 1; /* Initialize optind to clear prev. index */
- int opt_idx = 0;
- int c;
- int mode = 0;
-
- pi->target_uid = getuid();
- g_target_uid = pi->target_uid;
- g_debug_mode = 0;
- g_skip_optimization = 0;
-
- if (pi->pkgs) {
- g_list_free_full(pi->pkgs, free);
- pi->pkgs = NULL;
- }
-
- while (1) {
- c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx);
- /* printf("c=%d %c\n", c, c); //debug */
- if (-1 == c)
- break; /* Parse is end */
- switch (c) {
- case OPTVAL_PRELOAD: /* request for preload app */
- pi->is_preload = 1;
- DBG("preload request [%d]", pi->is_preload);
- break;
- case OPTVAL_FORCE_REMOVAL: /* request for force-remove */
- pi->force_removal = 1;
- DBG("force-remove request [%d]", pi->force_removal);
- break;
- case OPTVAL_PRELOAD_RW: /* request for preload-rw app */
- pi->is_preload_rw = 1;
- DBG("preload-rw request [%d]", pi->is_preload_rw);
- break;
- case OPTVAL_NO_REMOVAL: /* request for no-remove */
- pi->no_removal = 1;
- DBG("no-remove request [%d]", pi->no_removal);
- break;
- case OPTVAL_KEEP_RWDATA: /* request for keep-rwdata */
- pi->keep_rwdata = 1;
- DBG("keep-rwdata request [%d]", pi->keep_rwdata);
- break;
- case OPTVAL_PARTIAL_RW: /* request for partial-rw */
- pi->partial_rw = 1;
- DBG("partial-rw request [%d]", pi->partial_rw);
- break;
- case OPTVAL_MIGRATE_EXTIMG:
- /* request for legacy extimg migration */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = OPTVAL_MIGRATE_EXTIMG;
- pi->request_type = PKGMGR_REQ_MIGRATE_EXTIMG;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- DBG("legacy extimg migration requested");
- break;
- case OPTVAL_SKIP_CHECK_REFERENCE:
- pi->skip_check_reference = 1;
- break;
- case OPTVAL_RECOVER_DB:
- pi->request_type = PKGMGR_REQ_RECOVER_DB;
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
- case OPTVAL_RECOVERY_CLEANUP:
- pi->recovery_cleanup = 1;
- break;
- case 'k': /* session id */
- if (pi->session_id)
- free(pi->session_id);
- pi->session_id = strndup(optarg, MAX_STRLEN);
- break;
-
- case 'l': /* license path */
- if (pi->license_path)
- free(pi->license_path);
- pi->license_path = strndup(optarg, MAX_STRLEN);
- break;
-
- case 'i': /* install */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 'i';
- pi->request_type = PKGMGR_REQ_INSTALL;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- DBG("option is [i] pkgid[%s]", pi->pkgmgr_info);
- if (pi->pkgmgr_info && strlen(pi->pkgmgr_info) == 0) {
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = NULL;
- } else {
- mode = 'i';
- }
- break;
-
- case 'e': /* install */
- if (pi->tep_path)
- free(pi->tep_path);
- pi->tep_path = strndup(optarg, MAX_STRLEN);
- pi->is_tep_included = 1;
- DBG("option is [e] tep_path[%s]", pi->tep_path);
- break;
-
- case 'M': /* install */
- if (strcmp(optarg, "tep_move") == 0)
- pi->tep_move = 1;
- else
- pi->tep_move = 0;
- DBG("option is [M] tep_move[%d]", pi->tep_move);
- break;
-
- case 'd': /* uninstall */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 'd';
- pi->request_type = PKGMGR_REQ_UNINSTALL;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
-
- case 'c': /* clear */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 'c';
- pi->request_type = PKGMGR_REQ_CLEAR;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'm': /* move */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 'm';
- pi->request_type = PKGMGR_REQ_MOVE;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'r': /* reinstall */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 'r';
- pi->request_type = PKGMGR_REQ_REINSTALL;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 't': /* move type*/
- pi->move_type = atoi(optarg);
- break;
-
- case 'p': /* caller pkgid*/
- if (pi->caller_pkgid)
- free(pi->caller_pkgid);
- pi->caller_pkgid = strndup(optarg, MAX_STRLEN);
-
- break;
-
- case 's': /* smack */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 's';
- pi->request_type = PKGMGR_REQ_SMACK;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'o': /* optional data*/
- pi->optional_data = strndup(optarg, MAX_STRLEN);
- break;
-
- case 'y': /* pkgid for direct manifest installation */
- mode = 'y';
- pi->request_type = PKGMGR_REQ_MANIFEST_DIRECT_INSTALL;
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'w': /* pkgid for mount installation */
- mode = 'w';
- pi->request_type = PKGMGR_REQ_MOUNT_INSTALL;
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'b': /* recovery */
- if (mode) {
- r = -EINVAL;
- goto RET;
- }
- mode = 'b';
- pi->request_type = PKGMGR_REQ_RECOVER;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'D': /* disable pkg */
- pi->request_type = PKGMGR_REQ_DISABLE_PKG;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'A': /* enable pkg */
- pi->request_type = PKGMGR_REQ_ENABLE_PKG;
- if (pi->pkgmgr_info)
- free(pi->pkgmgr_info);
- pi->pkgmgr_info = strndup(optarg, MAX_STRLEN);
- __parse_multiple_pkgs(pi, argc, argv);
- break;
-
- case 'u': /* uid */
- g_target_uid = (uid_t)atoi(optarg);
- pi->target_uid = (uid_t)atoi(optarg);
- break;
-
- case 'G': /* debug mode */
- pi->debug_mode = 1;
- g_debug_mode = 1;
- break;
-
- case 'S': /* skip optimization */
- pi->skip_optimization = 1;
- g_skip_optimization = 1;
- break;
-
- /* Otherwise */
- case '?': /* Not an option */
- break;
-
- case ':': /* */
- break;
-
- }
- }
-
- /* if target user is not set, set as tizenglobalapp user */
- if (pi->target_uid == 0) {
- pi->target_uid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
- g_target_uid = pi->target_uid;
- }
- RET:
- return r;
-}
-
-API int pkgmgr_installer_get_request_type(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->request_type;
-}
-
-API uid_t pkgmgr_installer_get_uid(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->target_uid;
-}
-
-API const char *pkgmgr_installer_get_request_info(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->pkgmgr_info;
-}
-
-API const char *pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi,
- int at)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return (const char *)g_list_nth_data(pi->pkgs, at);
-}
-
-API int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return g_list_length(pi->pkgs);
-}
-
-API const char *pkgmgr_installer_get_tep_path(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->tep_path;
-}
-
-API int pkgmgr_installer_get_tep_move_type(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->tep_move;
-}
-
-API const char *pkgmgr_installer_get_session_id(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->session_id;
-}
-
-API const char *pkgmgr_installer_get_license_path(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->license_path;
-}
-
-API const char *pkgmgr_installer_get_optional_data(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->optional_data;
-}
-
-API int pkgmgr_installer_is_quiet(pkgmgr_installer *pi)
-{
- return 1;
-}
-
-API int pkgmgr_installer_get_move_type(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->move_type;
-}
-
-API const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->caller_pkgid;
-}
-
-API int pkgmgr_installer_get_is_preload(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->is_preload;
-}
-
-API int pkgmgr_installer_get_force_removal(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->force_removal;
-}
-
-API int pkgmgr_installer_get_is_preload_rw(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->is_preload_rw;
-}
-
-API int pkgmgr_installer_get_no_removal(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->no_removal;
-}
-
-API int pkgmgr_installer_get_keep_rwdata(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->keep_rwdata;
-}
-
-API int pkgmgr_installer_get_partial_rw(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->partial_rw;
-}
-
-API int pkgmgr_installer_get_debug_mode(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->debug_mode;
-}
-
-API int pkgmgr_installer_get_skip_check_reference(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->skip_check_reference;
-}
-
-API int pkgmgr_installer_get_skip_optimization(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->skip_optimization;
-}
-
-API int pkgmgr_installer_get_recovery_cleanup(pkgmgr_installer *pi)
-{
- CHK_PI_RET(PKGMGR_REQ_INVALID);
- return pi->recovery_cleanup;
-}
-
-API int pkgmgr_installer_send_app_uninstall_signal(pkgmgr_installer *pi,
- const char *pkg_type,
- const char *pkgid,
- const char *val)
-{
- int ret = 0;
- ret = __send_signal_for_event(pi, pkg_type, pkgid, NULL,
- PKGMGR_INSTALLER_APPID_KEY_STR, val);
- return ret;
-}
-
-API int pkgmgr_installer_send_app_uninstall_signal_for_uid(
- pkgmgr_installer *pi, uid_t uid, const char *pkg_type,
- const char *pkgid, const char *val)
-{
- int ret = 0;
- ret = __send_signal_for_event_for_uid(pi, uid, pkg_type, pkgid, NULL,
- PKGMGR_INSTALLER_APPID_KEY_STR, val);
- return ret;
-}
-
-API int pkgmgr_installer_set_uid(pkgmgr_installer *pi, uid_t uid)
-{
- if (pi == NULL)
- return -1;
-
- pi->target_uid = uid;
- g_target_uid = pi->target_uid;
-
- return 0;
-}
-
-API int
-pkgmgr_installer_send_app_signal(pkgmgr_installer *pi,
- const char *pkg_type,
- const char *pkgid,
- const char *appid,
- const char *key, const char *val)
-{
- int r = 0;
-
- if (!pi->conn) {
- ERR("connection is NULL");
- return -1;
- }
-
- r = __send_signal_for_event(pi, pkg_type, pkgid, appid, key, val);
-
- return r;
-}
-
-API int
-pkgmgr_installer_send_signal(pkgmgr_installer *pi,
- const char *pkg_type,
- const char *pkgid,
- const char *key, const char *val)
-{
- int r = 0;
-
- if (!pi->conn) {
- ERR("connection is NULL");
- return -1;
- }
-
- r = __send_signal_for_event(pi, pkg_type, pkgid, NULL, key, val);
-
- return r;
-}
-
-API int pkgmgr_installer_send_app_signal_for_uid(pkgmgr_installer *pi,
- uid_t uid, const char *pkg_type, const char *pkgid,
- const char *appid, const char *key, const char *val)
-{
- int r = 0;
-
- if (!pi->conn) {
- ERR("connection is NULL");
- return -1;
- }
-
- r = __send_signal_for_event_for_uid(pi, uid, pkg_type, pkgid, appid,
- key, val);
-
- return r;
-}
-
-API int pkgmgr_installer_send_signal_for_uid(pkgmgr_installer *pi,
- uid_t uid, const char *pkg_type, const char *pkgid,
- const char *key, const char *val)
-{
- int r = 0;
-
- if (!pi->conn) {
- ERR("connection is NULL");
- return -1;
- }
-
- r = __send_signal_for_event_for_uid(pi, uid, pkg_type, pkgid, NULL,
- key, val);
-
- return r;
-}
-
-API int pkgmgr_installer_set_request_type(pkgmgr_installer *pi, int request_type)
-{
- if (pi == NULL)
- return -1;
-
- pi->request_type = request_type;
- return 0;
-}
-
-API int pkgmgr_installer_set_session_id(pkgmgr_installer *pi, const char *session_id)
-{
- if (pi == NULL || session_id == NULL)
- return -1;
-
- pi->session_id = strndup(session_id, MAX_STRLEN);
- return 0;
-}
-
-API int pkgmgr_installer_create_certinfo_set_handle(pkgmgr_instcertinfo_h *handle)
-{
- int ret = 0;
- ret = pkgmgrinfo_create_certinfo_set_handle(handle);
- return ret;
-}
-
-API int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle, pkgmgr_instcert_type cert_type, char *cert_value)
-{
- int ret = 0;
- ret = pkgmgrinfo_set_cert_value(handle, cert_type, cert_value);
- return ret;
-}
-
-API int pkgmgr_installer_save_certinfo(const char *pkgid, pkgmgr_instcertinfo_h handle, uid_t uid)
-{
- int ret = 0;
- ret = pkgmgrinfo_save_certinfo(pkgid, handle, uid);
- return ret;
-}
-
-API int pkgmgr_installer_destroy_certinfo_set_handle(pkgmgr_instcertinfo_h handle)
-{
- int ret = 0;
- ret = pkgmgrinfo_destroy_certinfo_set_handle(handle);
- return ret;
-}
-
-API int pkgmgr_installer_delete_certinfo(const char *pkgid)
-{
- int ret = 0;
- ret = pkgmgrinfo_delete_certinfo(pkgid);
- return ret;
-}
-
-API int pkgmgr_installer_set_privilege_level(pkgmgr_privilege_level level)
-{
- g_privilege_level = level;
-
- return 0;
-}
-
-API int pkgmgr_installer_info_get_target_uid(uid_t *uid)
-{
- *uid = g_target_uid;
-
- return 0;
-}
-
-API int pkgmgr_installer_info_get_privilege_level(pkgmgr_privilege_level *level)
-{
- *level = g_privilege_level;
-
- return 0;
-}
-
-API int pkgmgr_installer_info_get_debug_mode(int *debug_mode)
-{
- *debug_mode = g_debug_mode;
- return 0;
-}
-
-API int pkgmgr_installer_info_get_skip_optimization(int *skip_optimization)
-{
- *skip_optimization = g_skip_optimization;
- return 0;
-}
-
-#define CASE_TO_STR(ERRCODE) case ERRCODE: return ERRCODE##_STR
-API const char *pkgmgr_installer_error_to_string(int error_code)
-{
- switch (error_code) {
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_GLOBALSYMLINK_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_GRANT_PERMISSION_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_IMAGE_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_UNZIP_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SECURITY_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_REGISTER_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PRIVILEGE_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PARSE_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_RECOVERY_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_DELTA_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_APP_DIR_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_CONFIG_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SIGNATURE_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_SIGNATURE_INVALID);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_CERT_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_MATCH);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_AUTHOR_CERT_NOT_FOUND);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ICON_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ICON_NOT_FOUND);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_MANIFEST_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_MANIFEST_NOT_FOUND);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_PACKAGE_NOT_FOUND);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OPERATION_NOT_ALLOWED);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OUT_OF_SPACE);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_INVALID_VALUE);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_ERROR);
- CASE_TO_STR(PKGMGR_INSTALLER_ERRCODE_OK);
- default:
- return PKGMGR_INSTALLER_ERRCODE_UNDEFINED_ERROR_STR;
- }
-}
-
-API int pkgmgr_installer_add_pkg(pkgmgr_installer *pi,
- const char *pkgid, const char *pkg_type)
-{
- pkg_signal_info *info;
- if (!pi || !pkgid || !pkg_type) {
- ERR("invalid argument");
- return -1;
- }
-
- info = calloc(1, sizeof(pkg_signal_info));
- if (!info) {
- ERR("out of memory");
- return -1;
- }
-
- info->pkgid = strdup(pkgid);
- info->pkg_type = strdup(pkg_type);
- if (!info->pkgid || !info->pkg_type) {
- ERR("out of memory");
- free(info->pkgid);
- free(info->pkg_type);
- free(info);
- return -1;
- }
- g_hash_table_insert(pi->pkg_list, (gpointer)info->pkgid, (gpointer)info);
-
- return 0;
-}
-
-static void __build_multi_signal(gpointer key, gpointer value,
- gpointer user_data)
-{
- GVariantBuilder *builder = (GVariantBuilder *)user_data;
- pkg_signal_info *info = (pkg_signal_info *)value;
-
- g_variant_builder_add(builder, "(sss)", info->pkgid, "", info->pkg_type);
-}
-
-API int pkgmgr_installer_send_signals(pkgmgr_installer *pi,
- const char *key, const char *val)
-{
- char *sid;
- const char *signal_name;
- GError *err = NULL;
- GVariantBuilder *builder;
-
- if (!pi || !key || !val) {
- ERR("invalid argument");
- return -1;
- }
-
- sid = pi->session_id;
- if (!sid)
- sid = "";
-
- signal_name = __get_signal_name(pi, key, "");
- if (!signal_name) {
- ERR("unknown signal type");
- return -1;
- }
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)"));
- g_hash_table_foreach(pi->pkg_list, __build_multi_signal, builder);
- if (g_dbus_connection_emit_signal(pi->conn, NULL,
- PKGMGR_INSTALLER_DBUS_OBJECT_PATH,
- PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name,
- g_variant_new("(usa(sss)ss)",
- pi->target_uid, sid, builder, key,
- val), &err) != TRUE) {
- ERR("failed to send dbus signal");
- if (err) {
- ERR("err: %s", err->message);
- g_error_free(err);
- }
- g_variant_builder_unref(builder);
- return -1;
- }
- g_variant_builder_unref(builder);
-
- return 0;
-}
-
-API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid,
- const char *key, const char *val)
-{
- char *sid;
- size_t data_len;
- size_t name_size;
- GVariant *gv;
- GVariantBuilder *builder;
- gsize gv_len;
- gpointer gv_data;
- void *data;
- void *ptr;
- const char *signal_name;
-
- if (!pi || !pi->conn) {
- ERR("connection is NULL");
- return -1;
- }
-
- sid = pi->session_id;
- if (!sid)
- sid = "";
-
- data_len = sizeof(size_t) + sizeof(gsize);
-
- /* including null byte */
- signal_name = __get_signal_name(pi, key, "");
- if (!signal_name) {
- ERR("unknown signal type");
- return -1;
- }
- name_size = strlen(signal_name) + 1;
- data_len += name_size;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(sss)"));
- g_hash_table_foreach(pi->pkg_list, __build_multi_signal, builder);
-
- gv = g_variant_new("(usa(sss)ss)", uid, sid, builder, key, val);
- g_variant_builder_unref(builder);
- if (gv == NULL) {
- ERR("failed to create GVariant instance");
- return -1;
- }
-
- gv_len = g_variant_get_size(gv);
- gv_data = g_malloc(gv_len);
- g_variant_store(gv, gv_data);
- g_variant_unref(gv);
- data_len += gv_len;
-
- data = malloc(data_len);
- if (data == NULL) {
- ERR("out of memory");
- g_free(gv_data);
- return -1;
- }
- ptr = data;
- memcpy(ptr, &name_size, sizeof(size_t));
- ptr += sizeof(size_t);
- memcpy(ptr, &gv_len, sizeof(gsize));
- ptr += sizeof(gsize);
- memcpy(ptr, signal_name, name_size);
- ptr += name_size;
- memcpy(ptr, gv_data, gv_len);
- g_free(gv_data);
-
- if (__send_signal_to_agent(uid, data, data_len)) {
- ERR("failed to send signal to agent");
- free(data);
- return -1;
- }
-
- free(data);
-
- return 0;
-}
-
-API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) {
- if (pi == NULL)
- return -1;
-
- pi->is_upgrade = is_upgrade;
- return 0;
-}
-
-static GVariant *__get_gvariant_from_event_info(pkgmgr_res_event_info *event_info)
-{
- pkgmgr_res_event_info_t *info = event_info;
- GVariantBuilder *builder;
- GVariant *result;
- GList *path_states;
- res_event_path_state_t *path_state;
-
- builder = g_variant_builder_new(G_VARIANT_TYPE("a(si)"));
- if (builder == NULL) {
- ERR("out of memory");
- return NULL;
- }
-
- for (path_states = info->path_states; path_states != NULL;
- path_states = path_states->next) {
- path_state = (res_event_path_state_t *)path_states->data;
- g_variant_builder_add(builder, "(si)",
- path_state->path, path_state->state);
- }
-
- result = g_variant_new("(ia(si))", info->error_code, builder);
- g_variant_builder_unref(builder);
-
- if (result == NULL) {
- ERR("Fail to create extra data");
- return NULL;
- }
-
- return result;
-}
-
-API int pkgmgr_installer_send_res_signal(pkgmgr_installer *pi,
- const char *pkgid, const char *status,
- pkgmgr_res_event_info *event_info)
-{
- char *sid;
- const char *signal_name;
- GError *err = NULL;
- GVariant *extra_param;
-
- if (!pi || !pkgid || !status) {
- ERR("invalid argument");
- return -1;
- }
-
- sid = pi->session_id;
- if (!sid)
- sid = "";
-
- signal_name = __get_signal_name(pi, "", "");
- if (!signal_name) {
- ERR("unknown signal type");
- return -1;
- }
-
- extra_param = __get_gvariant_from_event_info(event_info);
- if (extra_param == NULL) {
- ERR("Fail to get extra parameter");
- return -1;
- }
-
- if (g_dbus_connection_emit_signal(pi->conn, NULL,
- PKGMGR_INSTALLER_DBUS_OBJECT_PATH,
- PKGMGR_INSTALLER_DBUS_INTERFACE, signal_name,
- g_variant_new("(usssv)", pi->target_uid, sid,
- pkgid, status, extra_param),
- &err) != TRUE) {
- ERR("failed to send dbus signal");
- if (err) {
- ERR("err: %s", err->message);
- g_error_free(err);
- }
- return -1;
- }
-
- return 0;
-}
-
-API int pkgmgr_installer_send_res_signal_for_uid(pkgmgr_installer *pi,
- uid_t uid, const char *pkgid, const char *status,
- pkgmgr_res_event_info *event_info)
-{
- char *sid;
- size_t data_len;
- size_t name_size;
- GVariant *gv;
- gsize gv_len;
- gpointer gv_data;
- void *data;
- void *ptr;
- const char *signal_name;
- GVariant *extra_param;
-
- if (!pi || !pi->conn) {
- ERR("connection is NULL");
- return -1;
- }
-
- sid = pi->session_id;
- if (!sid)
- sid = "";
-
- data_len = sizeof(size_t) + sizeof(gsize);
-
- /* including null byte */
- signal_name = __get_signal_name(pi, "", "");
- if (!signal_name) {
- ERR("unknown signal type");
- return -1;
- }
- name_size = strlen(signal_name) + 1;
- data_len += name_size;
-
- extra_param = __get_gvariant_from_event_info(event_info);
- if (extra_param == NULL) {
- ERR("Fail to get extra parameter");
- return -1;
- }
-
- gv = g_variant_new("(usssv)", pi->target_uid, sid,
- pkgid, status, extra_param);
- if (gv == NULL) {
- ERR("failed to create GVariant instance");
- return -1;
- }
-
- gv_len = g_variant_get_size(gv);
- gv_data = g_malloc(gv_len);
- g_variant_store(gv, gv_data);
- g_variant_unref(gv);
- data_len += gv_len;
-
- data = malloc(data_len);
- if (data == NULL) {
- ERR("out of memory");
- g_free(gv_data);
- return -1;
- }
- ptr = data;
- memcpy(ptr, &name_size, sizeof(size_t));
- ptr += sizeof(size_t);
- memcpy(ptr, &gv_len, sizeof(gsize));
- ptr += sizeof(gsize);
- memcpy(ptr, signal_name, name_size);
- ptr += name_size;
- memcpy(ptr, gv_data, gv_len);
- g_free(gv_data);
-
- if (__send_signal_to_agent(uid, data, data_len)) {
- ERR("failed to send signal to agent");
- free(data);
- return -1;
- }
-
- free(data);
-
- return 0;
-}
diff --git a/installer/pkgmgr_installer_config.h b/installer/pkgmgr_installer_config.h
deleted file mode 100644
index 320620b..0000000
--- a/installer/pkgmgr_installer_config.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * slp-pkgmgr
- *
- * 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 __PACKAGE_INSTALLER_CONFIG_H__
-#define __PACKAGE_INSTALLER_CONFIG_H__
-
-#define PKGMGR_DBUS_SERVICE "org.tizen.pkgmgr"
-#define PKGMGR_DBUS_INTERFACE "org.tizen.pkgmgr"
-#define PKGMGR_DBUS_OBJECT_PATH "/org/tizen/pkgmgr"
-
-#define PKGMGR_INSTALLER_DBUS_INTERFACE "org.tizen.pkgmgr.signal"
-#define PKGMGR_INSTALLER_DBUS_OBJECT_PATH "/org/tizen/pkgmgr/signal"
-
-#endif /* __PACKAGE_INSTALLER_CONFIG_H__ */
diff --git a/installer/pkgmgr_installer_signal_agent.c b/installer/pkgmgr_installer_signal_agent.c
deleted file mode 100644
index 19c5b44..0000000
--- a/installer/pkgmgr_installer_signal_agent.c
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <linux/limits.h>
-#include <pwd.h>
-
-#include <glib.h>
-#include <glib-unix.h>
-#include <gio/gio.h>
-#include <systemd/sd-daemon.h>
-
-#include <dlog.h>
-
-#include "pkgmgr_installer_config.h"
-#include "pkgmgr_installer_type.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "PKGMGR_INSTALLER_SIGNAL_AGENT"
-
-#define BUFMAX 4096
-#define PWBUFSIZE sysconf(_SC_GETPW_R_SIZE_MAX)
-#define APPFW_USERNAME "app_fw"
-
-static int server_fd = -1;
-static GMainLoop *loop;
-static guint sid;
-static guint tid;
-static GDBusConnection *conn;
-
-static int __create_server_socket(const char *path)
-{
- int r;
- int fd;
- struct sockaddr_un sa;
-
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd == -1) {
- LOGE("socket create failed: %d", errno);
- return -1;
- }
-
- memset(&sa, 0, sizeof(sa));
- sa.sun_family = AF_UNIX;
- snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", path);
-
- r = unlink(sa.sun_path);
- if (r == -1 && errno != ENOENT) {
- LOGE("unlink(%s) failed: %d", sa.sun_path, errno);
- close(fd);
- return -1;
- }
-
- r = bind(fd, (struct sockaddr *)&sa, sizeof(sa));
- if (r == -1) {
- LOGE("bind(%s) failed: %d", sa.sun_path, errno);
- close(fd);
- return -1;
- }
-
- r = chmod(sa.sun_path, 0660);
- if (r == -1)
- LOGW("chmod(%s) failed: %d", sa.sun_path, errno);
-
- r = listen(fd, SOMAXCONN);
- if (r == -1) {
- LOGE("listen(%s) failed: %d", sa.sun_path, errno);
- close(fd);
- return -1;
- }
-
- return fd;
-}
-
-static int __get_server_socket(const char *path)
-{
- int i;
- int n;
- int r;
- int fd = -1;
-
- n = sd_listen_fds(0);
- if (n < 0) {
- LOGE("sd_listen_fds: %d", n);
- return -1;
- } else if (n == 0) {
- return __create_server_socket(path);
- }
-
- for (i = SD_LISTEN_FDS_START; i < SD_LISTEN_FDS_START + n; i++) {
- r = sd_is_socket_unix(i, SOCK_STREAM, -1, path, 0);
- if (r > 0) {
- fd = i;
- break;
- }
- }
-
- if (fd == -1) {
- LOGE("socket is not passed, create server socket");
- return __create_server_socket(path);
- }
-
- return fd;
-}
-
-static void __emit_signal(const char *name, GVariant *gv)
-{
- GError *err = NULL;
-
- if (g_dbus_connection_emit_signal(conn, NULL,
- PKGMGR_INSTALLER_DBUS_OBJECT_PATH,
- PKGMGR_INSTALLER_DBUS_INTERFACE,
- name, gv, &err) != TRUE) {
- LOGE("g_dbus_connection_emit_signal failed: %s", err->message);
- g_error_free(err);
- }
-}
-
-static gboolean __quit(gpointer user_data)
-{
- g_main_loop_quit(loop);
- return FALSE;
-}
-
-static int __check_authority(int fd)
-{
- int r;
- struct ucred cr;
- socklen_t len;
- struct passwd pwd;
- struct passwd *pwd_r;
- char buf[PWBUFSIZE];
-
- len = sizeof(struct ucred);
- r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len);
- if (r != 0) {
- LOGE("getsockopt failed: %d", errno);
- return -1;
- }
-
- /* allow root user */
- if (cr.uid == 0)
- return 0;
-
- r = getpwuid_r(cr.uid, &pwd, buf, sizeof(buf), &pwd_r);
- if (r != 0 || pwd_r == NULL) {
- LOGE("getpwuid failed: %d", r);
- return -1;
- }
-
- /* only app_fw user can send signal to agent */
- if (strcmp(pwd_r->pw_name, APPFW_USERNAME) != 0) {
- LOGE("unauthorized client");
- return -1;
- }
-
- return 0;
-}
-
-/**
- * packet format:
- * +----------------+-------------+-----------+-------------------+
- * |signal name size|GVariant size|signal name|serialized GVariant|
- * +----------------+-------------+-----------+-------------------+
- */
-static gboolean __handle_signal(gint fd, GIOCondition cond, gpointer user_data)
-{
- int r;
- unsigned char buf[BUFMAX];
- int clifd;
- struct sockaddr_un sa;
- socklen_t s = sizeof(sa);
- size_t type_len;
- char *type_name;
- gsize data_len;
- gpointer data;
- GVariant *gv;
-
- clifd = accept(fd, (struct sockaddr *)&sa, &s);
- if (clifd == -1) {
- LOGE("accept failed: %d", errno);
- return FALSE;
- }
-
- if (__check_authority(clifd)) {
- close(clifd);
- return TRUE;
- }
-
- r = recv(clifd, buf, sizeof(size_t) + sizeof(gsize), 0);
- if (r < 0) {
- LOGE("recv failed: %d", errno);
- close(clifd);
- return FALSE;
- } else if (r == 0) {
- LOGE("client fd already closed");
- close(clifd);
- return FALSE;
- }
-
- memcpy(&type_len, buf, sizeof(size_t));
- memcpy(&data_len, buf + sizeof(size_t), sizeof(gsize));
-
- if (type_len > BUFMAX || data_len > BUFMAX ||
- (type_len + data_len) > BUFMAX) {
- LOGE("received size is too large: %zu %zu", type_len, data_len);
- close(clifd);
- return FALSE;
- }
-
- r = recv(clifd, buf, type_len + data_len, 0);
- if (r < 0) {
- LOGE("recv failed: %d", errno);
- close(clifd);
- return FALSE;
- } else if (r == 0) {
- LOGE("client fd already closed");
- close(clifd);
- return FALSE;
- }
-
- if (type_len == 0) {
- LOGE("invalid type_len");
- close(clifd);
- return FALSE;
- }
-
- /* get signal name (including terminating null byte) */
- type_name = malloc(type_len);
- memcpy(type_name, buf, type_len);
-
- /* get data */
- data = malloc(data_len);
- memcpy(data, buf + type_len, data_len);
-
- /* floating type GVariant instance */
- if (!strcmp(type_name, PKGMGR_INSTALLER_RES_COPY_EVENT_STR) ||
- !strcmp(type_name, PKGMGR_INSTALLER_RES_CREATE_DIR_EVENT_STR) ||
- !strcmp(type_name, PKGMGR_INSTALLER_RES_REMOVE_EVENT_STR) ||
- !strcmp(type_name, PKGMGR_INSTALLER_RES_UNINSTALL_EVENT_STR)) {
- gv = g_variant_new_from_data(G_VARIANT_TYPE("(usssv)"),
- data, data_len, TRUE, NULL, NULL);
- } else {
- gv = g_variant_new_from_data(G_VARIANT_TYPE("(usa(sss)ss)"),
- data, data_len, TRUE, NULL, NULL);
- }
- __emit_signal(type_name, gv);
-
- free(data);
- free(type_name);
- close(clifd);
-
- /* renew timeout */
- g_source_remove(tid);
- tid = g_timeout_add_seconds(10, __quit, NULL);
-
- return TRUE;
-}
-
-static int __init(void)
-{
- char path[PATH_MAX];
- GError *err = NULL;
-
- snprintf(path, sizeof(path), "/run/pkgmgr/agent/%d", getuid());
- server_fd = __get_server_socket(path);
- if (server_fd < 0) {
- LOGE("server init failed");
- return -1;
- }
-
- conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &err);
- if (conn == NULL) {
- LOGE("g_bus_get_sync failed: %s", err->message);
- g_error_free(err);
- close(server_fd);
- return -1;
- }
-
- loop = g_main_loop_new(NULL, FALSE);
- sid = g_unix_fd_add(server_fd, G_IO_IN, __handle_signal, NULL);
- tid = g_timeout_add_seconds(10, __quit, NULL);
-
- return 0;
-}
-
-static void __fini(void)
-{
- if (sid > 0)
- g_source_remove(sid);
- if (loop)
- g_main_loop_unref(loop);
- if (conn)
- g_object_unref(conn);
- if (server_fd > 0)
- close(server_fd);
-}
-
-int main(int argc, char *argv[])
-{
- int r;
-
- r = __init();
- if (r < 0)
- return -1;
-
- g_main_loop_run(loop);
-
- __fini();
-
- return 0;
-}
diff --git a/installer/src/api_stub.cc b/installer/src/api_stub.cc
new file mode 100644
index 0000000..d975965
--- /dev/null
+++ b/installer/src/api_stub.cc
@@ -0,0 +1,364 @@
+/*
+* Copyright (c) 2022 Samsung Electronics Co., Ltd.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+
+#include "pkgmgr_installer.h"
+
+#include <unistd.h>
+
+#include "control.hh"
+
+#ifdef API
+#undef API
+#endif
+#define API __attribute__ ((visibility("default")))
+
+API pkgmgr_installer* pkgmgr_installer_new() {
+ return new pkgmgr::installer::Control();
+}
+
+API pkgmgr_installer* pkgmgr_installer_offline_new() {
+ return new pkgmgr::installer::Control(true);
+}
+
+API int pkgmgr_installer_free(pkgmgr_installer* pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ delete cls;
+ return 0;
+}
+
+API int pkgmgr_installer_receive_request(pkgmgr_installer *pi,
+ const int argc, char **argv) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ return cls->SetRequestFromArgv(argc, argv);
+}
+
+API int pkgmgr_installer_get_request_type(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->GetRequestType();
+}
+
+API uid_t pkgmgr_installer_get_uid(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->GetUid();
+}
+
+API const char* pkgmgr_installer_get_request_info(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return nullptr;
+ return cls->GetRequest()->GetRequestInfo().c_str();
+}
+
+API const char* pkgmgr_installer_get_request_info_at(pkgmgr_installer *pi,
+ int at) {
+ //TODO
+ return nullptr;
+}
+
+API int pkgmgr_installer_get_request_info_count(pkgmgr_installer *pi) {
+ //TODO
+ return 0;
+}
+
+API const char *pkgmgr_installer_get_tep_path(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return nullptr;
+ return cls->GetRequest()->GetTepPath().c_str();
+}
+
+API int pkgmgr_installer_get_tep_move_type(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsTepMove() ? 1 : 0;
+}
+
+API const char* pkgmgr_installer_get_session_id(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return nullptr;
+ return cls->GetRequest()->GetSessionId().c_str();
+}
+
+API const char* pkgmgr_installer_get_license_path(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return nullptr;
+ return cls->GetRequest()->GetLicensePath().c_str();
+}
+
+API const char* pkgmgr_installer_get_optional_data(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return nullptr;
+ return cls->GetRequest()->GetOptionalData().c_str();
+}
+
+API int pkgmgr_installer_is_quiet(pkgmgr_installer *pi) {
+ return 1;
+}
+
+API int pkgmgr_installer_get_move_type(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->GetMoveType();
+}
+
+API const char *pkgmgr_installer_get_caller_pkgid(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return nullptr;
+ return cls->GetRequest()->GetCallerPkgid().c_str();
+}
+
+API int pkgmgr_installer_get_is_preload(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsPreload() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_force_removal(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsForceRemoval() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_is_preload_rw(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsPreloadRw() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_no_removal(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsNoRemoval() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_keep_rwdata(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsKeepRwData() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_partial_rw(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsPartialRw() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_debug_mode(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsDebugMode() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_skip_check_reference(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsSkipCheckReference() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_skip_optimization(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsSkipOptimization() ? 1 : 0;
+}
+
+API int pkgmgr_installer_get_recovery_cleanup(pkgmgr_installer *pi) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return PKGMGR_REQ_INVALID;
+ return cls->GetRequest()->IsRecoveryCleanup() ? 1 : 0;
+}
+
+API int pkgmgr_installer_send_app_uninstall_signal(pkgmgr_installer *pi,
+ const char *pkg_type, const char *pkgid, const char *val) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_send_app_uninstall_signal_for_uid(
+ pkgmgr_installer *pi, uid_t uid, const char *pkg_type,
+ const char *pkgid, const char *val) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_set_uid(pkgmgr_installer *pi, uid_t uid) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return -1;
+ cls->GetRequest()->SetUid(uid);
+ return 0;
+}
+
+API int pkgmgr_installer_send_app_signal(pkgmgr_installer *pi,
+ const char *pkg_type, const char *pkgid, const char *appid,
+ const char *key, const char *val) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return -1;
+ return cls->SendSignal(pkg_type, pkgid, appid, key, val);
+}
+
+API int pkgmgr_installer_send_signal(pkgmgr_installer *pi,
+ const char *pkg_type, const char *pkgid, const char *key,
+ const char *val) {
+ auto* cls = static_cast<pkgmgr::installer::Control*>(pi);
+ if (!cls->GetRequest())
+ return -1;
+ return cls->SendSignal(pkg_type, pkgid, "", key, val);
+}
+
+API int pkgmgr_installer_send_app_signal_for_uid(pkgmgr_installer *pi,
+ uid_t uid, const char *pkg_type, const char *pkgid,
+ const char *appid, const char *key, const char *val) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_send_signal_for_uid(pkgmgr_installer *pi,
+ uid_t uid, const char *pkg_type, const char *pkgid,
+ const char *key, const char *val) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_set_request_type(pkgmgr_installer *pi,
+ int request_type) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_set_session_id(pkgmgr_installer *pi,
+ const char *session_id) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_create_certinfo_set_handle(
+ pkgmgr_instcertinfo_h *handle) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_set_cert_value(pkgmgr_instcertinfo_h handle,
+ pkgmgr_instcert_type cert_type, char *cert_value) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_save_certinfo(const char *pkgid,
+ pkgmgr_instcertinfo_h handle, uid_t uid) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_destroy_certinfo_set_handle(
+ pkgmgr_instcertinfo_h handle) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_delete_certinfo(const char *pkgid) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_set_privilege_level(pkgmgr_privilege_level level) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_info_get_target_uid(uid_t *uid) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_info_get_privilege_level(
+ pkgmgr_privilege_level *level) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_info_get_debug_mode(int *debug_mode) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_info_get_skip_optimization(int *skip_optimization) {
+ //TODO
+ return 0;
+}
+
+API const char* pkgmgr_installer_error_to_string(int error_code) {
+ //TODO
+ return nullptr;
+}
+
+API int pkgmgr_installer_add_pkg(pkgmgr_installer *pi,
+ const char *pkgid, const char *pkg_type) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_send_signals(pkgmgr_installer *pi,
+ const char *key, const char *val) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_send_signals_for_uid(pkgmgr_installer *pi, uid_t uid,
+ const char *key, const char *val) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_set_is_upgrade(pkgmgr_installer *pi, int is_upgrade) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_send_res_signal(pkgmgr_installer *pi,
+ const char *pkgid, const char *status,
+ pkgmgr_res_event_info *event_info) {
+ //TODO
+ return 0;
+}
+
+API int pkgmgr_installer_send_res_signal_for_uid(pkgmgr_installer *pi,
+ uid_t uid, const char *pkgid, const char *status,
+ pkgmgr_res_event_info *event_info) {
+ //TODO
+ return 0;
+}
diff --git a/installer/src/control.cc b/installer/src/control.cc
new file mode 100644
index 0000000..d094c6a
--- /dev/null
+++ b/installer/src/control.cc
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "control.hh"
+
+#include <getopt.h>
+
+#include "pkgmgr_installer.h"
+#include "pkgmgr_installer_debug.h"
+
+namespace {
+
+constexpr int OPTVAL_PRELOAD = 1000;
+constexpr int OPTVAL_FORCE_REMOVAL = 1001;
+constexpr int OPTVAL_PRELOAD_RW = 1002;
+constexpr int OPTVAL_NO_REMOVAL = 1003;
+constexpr int OPTVAL_KEEP_RWDATA = 1004;
+constexpr int OPTVAL_PARTIAL_RW = 1005;
+constexpr int OPTVAL_MIGRATE_EXTIMG = 1006;
+constexpr int OPTVAL_SKIP_CHECK_REFERENCE = 1007;
+constexpr int OPTVAL_RECOVER_DB = 1008;
+constexpr int OPTVAL_RECOVERY_CLEANUP = 1009;
+
+constexpr const char short_opts[] = "k:l:i:d:c:m:t:o:r:p:s:b:e:M:y:u:w:D:A:qGS";
+constexpr const struct option long_opts[] = {
+ { "session-id", 1, nullptr, 'k' },
+ { "license-path", 1, nullptr, 'l' },
+ { "install", 1, nullptr, 'i' },
+ { "uninstall", 1, nullptr, 'd' },
+ { "clear", 1, nullptr, 'c' },
+ { "move", 1, nullptr, 'm' },
+ { "move-type", 1, nullptr, 't' },
+ { "optional-data", 0, nullptr, 'o' },
+ { "reinstall", 0, nullptr, 'r' },
+ { "caller-pkgid", 1, nullptr, 'p' },
+ { "tep-path", 1, nullptr, 'e' },
+ { "tep-move", 1, nullptr, 'M' },
+ { "smack", 1, nullptr, 's' },
+ { "manifest-direct-install", 1, nullptr, 'y' },
+ { "mount-install", 1, nullptr, 'w' },
+ { "recovery", 1, nullptr, 'b' },
+ { "debug-mode", 0, nullptr, 'G' },
+ { "skip-optimization", 0, nullptr, 'S' },
+ { "preload", 0, nullptr, OPTVAL_PRELOAD },
+ { "force-remove", 0, nullptr, OPTVAL_FORCE_REMOVAL },
+ { "preload-rw", 0, nullptr, OPTVAL_PRELOAD_RW },
+ { "no-remove", 0, nullptr, OPTVAL_NO_REMOVAL },
+ { "keep-rwdata", 0, nullptr, OPTVAL_KEEP_RWDATA },
+ { "partial-rw", 0, nullptr, OPTVAL_PARTIAL_RW },
+ { "migrate-extimg", 1, nullptr, OPTVAL_MIGRATE_EXTIMG },
+ { "skip-check-reference", 0, nullptr, OPTVAL_SKIP_CHECK_REFERENCE },
+ { "recover-db", 1, nullptr, OPTVAL_RECOVER_DB },
+ { "recovery-cleanup", 0, nullptr, OPTVAL_RECOVERY_CLEANUP },
+ { 0, 0, 0, 0 }
+};
+
+}
+
+namespace pkgmgr {
+namespace installer {
+
+Control::Control(bool offline) {
+ if (!offline) {
+ signal_.reset(new pkg_group::PkgSignal("", true));
+ }
+
+ option_map_[OPTVAL_PRELOAD] = [](const std::unique_ptr<Request>& req) {
+ req->is_preload_ = true;
+ _D("preload request [%d]", req->is_preload_);
+ return 0;
+ };
+
+ option_map_[OPTVAL_FORCE_REMOVAL] = [](const std::unique_ptr<Request>& req) {
+ req->force_removal_ = true;
+ _D("force-remove request [%d]", req->force_removal_);
+ return 0;
+ };
+
+ option_map_[OPTVAL_PRELOAD_RW] = [](const std::unique_ptr<Request>& req) {
+ req->is_preload_rw_ = true;
+ _D("preload-rw request [%d]", req->is_preload_rw_);
+ return 0;
+ };
+
+ option_map_[OPTVAL_NO_REMOVAL] = [](const std::unique_ptr<Request>& req) {
+ req->no_removal_ = true;
+ _D("no-remove request [%d]", req->no_removal_);
+ return 0;
+ };
+
+ option_map_[OPTVAL_KEEP_RWDATA] = [](const std::unique_ptr<Request>& req) {
+ req->keep_rwdata_ = true;
+ _D("keep-rwdata request [%d]", req->keep_rwdata_);
+ return 0;
+ };
+
+ option_map_[OPTVAL_PARTIAL_RW] = [](const std::unique_ptr<Request>& req) {
+ req->partial_rw_ = true;
+ _D("partial-rw request [%d]", req->partial_rw_);
+ return 0;
+ };
+
+ option_map_[OPTVAL_MIGRATE_EXTIMG] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = OPTVAL_MIGRATE_EXTIMG;
+ req->request_type_ = PKGMGR_REQ_MIGRATE_EXTIMG;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ _D("legacy extimg migration requested");
+ return 0;
+ };
+
+ option_map_[OPTVAL_SKIP_CHECK_REFERENCE] = [](const std::unique_ptr<Request>& req) {
+ req->skip_check_reference_ = true;
+ return 0;
+ };
+
+ option_map_[OPTVAL_RECOVER_DB] = [this](const std::unique_ptr<Request>& req) {
+ req->request_type_ = PKGMGR_REQ_RECOVER_DB;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_[OPTVAL_RECOVERY_CLEANUP] = [](const std::unique_ptr<Request>& req) {
+ req->recovery_cleanup_ = true;
+ return 0;
+ };
+
+ option_map_['k'] = [](const std::unique_ptr<Request>& req) {
+ req->session_id_ = optarg;
+ return 0;
+ };
+
+ option_map_['l'] = [](const std::unique_ptr<Request>& req) {
+ req->license_path_ = optarg;
+ return 0;
+ };
+
+ option_map_['i'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 'i';
+ req->request_type_ = PKGMGR_REQ_INSTALL;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ _D("option is [i] pkgid[%s]", req->pkgmgr_info_.c_str());
+ return 0;
+ };
+
+ option_map_['e'] = [](const std::unique_ptr<Request>& req) {
+ req->tep_path_ = optarg;
+ _D("option is [e] tep_path[%s]", req->tep_path_.c_str());
+ return 0;
+ };
+
+ option_map_['M'] = [](const std::unique_ptr<Request>& req) {
+ if (strcmp(optarg, "tep_move") == 0)
+ req->tep_move_ = true;
+ else
+ req->tep_move_ = false;
+ _D("option is [M] tep_move[%d]", req->tep_move_);
+ return 0;
+ };
+
+ option_map_['d'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 'd';
+ req->request_type_ = PKGMGR_REQ_UNINSTALL;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['c'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 'c';
+ req->request_type_ = PKGMGR_REQ_CLEAR;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['m'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 'm';
+ req->request_type_ = PKGMGR_REQ_MOVE;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['r'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 'r';
+ req->request_type_ = PKGMGR_REQ_REINSTALL;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['t'] = [](const std::unique_ptr<Request>& req) {
+ req->move_type_ = atoi(optarg);
+ return 0;
+ };
+
+ option_map_['p'] = [](const std::unique_ptr<Request>& req) {
+ req->caller_pkgid_ = optarg;
+ return 0;
+ };
+
+ option_map_['s'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 's';
+ req->request_type_ = PKGMGR_REQ_SMACK;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['o'] = [](const std::unique_ptr<Request>& req) {
+ req->optional_data_ = optarg;
+ return 0;
+ };
+
+ option_map_['y'] = [this](const std::unique_ptr<Request>& req) {
+ req->request_type_ = PKGMGR_REQ_MANIFEST_DIRECT_INSTALL;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['w'] = [this](const std::unique_ptr<Request>& req) {
+ req->request_type_ = PKGMGR_REQ_MOUNT_INSTALL;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['b'] = [this](const std::unique_ptr<Request>& req) {
+ if (mode_)
+ return -EINVAL;
+ mode_ = 'b';
+ req->request_type_ = PKGMGR_REQ_RECOVER;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['D'] = [this](const std::unique_ptr<Request>& req) {
+ req->request_type_ = PKGMGR_REQ_DISABLE_PKG;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['A'] = [this](const std::unique_ptr<Request>& req) {
+ req->request_type_ = PKGMGR_REQ_ENABLE_PKG;
+ req->pkgmgr_info_ = optarg;
+ ParseMultiplePkgs(req);
+ return 0;
+ };
+
+ option_map_['u'] = [](const std::unique_ptr<Request>& req) {
+ req->target_uid_ = (uid_t)atoi(optarg);
+ return 0;
+ };
+
+ option_map_['G'] = [](const std::unique_ptr<Request>& req) {
+ req->debug_mode_ = true;
+ return 0;
+ };
+
+ option_map_['S'] = [](const std::unique_ptr<Request>& req) {
+ req->skip_optimization_ = true;
+ return 0;
+ };
+}
+
+Control::~Control() = default;
+
+void Control::ParseMultiplePkgs(const std::unique_ptr<Request>& req) {
+ while ((optind <= argc_) && (*argv_[optind - 1] != '-')) {
+ req->pkgs_.push_back(argv_[optind - 1]);
+ optind++;
+ }
+ optind--;
+}
+
+const std::unique_ptr<Request>& Control::GetRequest() const {
+ return request_;
+}
+
+int Control::SendSignal(std::string pkg_type, std::string pkgid,
+ std::string appid, std::string key, std::string val) {
+ if (!signal_) {
+ _E("offline mode");
+ return -1;
+ }
+ auto& req = GetRequest();
+ std::vector<rpc_port::PkgSignal::PkgInfo> pkgs;
+ pkgs.push_back(rpc_port::PkgSignal::PkgInfo(std::move(pkgid),
+ std::move(appid), std::move(pkg_type)));
+ signal_->AsyncResult(req->GetUid(), req->GetSessionId(), std::move(pkgs),
+ key, val);
+ return 0;
+}
+
+int Control::SetRequestFromArgv(const int argc, char** argv) {
+ auto req = std::make_unique<Request>();
+ int opt_idx = 0;
+ optind = 1;
+ argc_ = argc;
+ argv_ = argv;
+ mode_ = 0;
+
+ while (true) {
+ int c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx);
+ if (c == -1)
+ break;
+
+ if (option_map_.find(c) != option_map_.end()) {
+ int ret = option_map_[c](req);
+ if (ret < 0)
+ return ret;
+ }
+ }
+
+ request_ = std::move(req);
+ return 0;
+}
+
+} // namespace installer
+} // namespace pkgmgr
diff --git a/installer/src/control.hh b/installer/src/control.hh
new file mode 100644
index 0000000..de80856
--- /dev/null
+++ b/installer/src/control.hh
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef INSTALLER_SRC_CONTROL_H_
+#define INSTALLER_SRC_CONTROL_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <list>
+#include <functional>
+
+#include "PkgSignal.h"
+#include "request.hh"
+
+namespace pkgmgr {
+namespace installer {
+
+namespace pkg_group = rpc_port::PkgSignal::group;
+
+class Control {
+ public:
+ Control(bool offline = false);
+ virtual ~Control();
+ int SetRequestFromArgv(const int argc, char** argv);
+ const std::unique_ptr<Request>& GetRequest() const;
+ int SendSignal(std::string pkg_type, std::string pkgid,
+ std::string appid, std::string key, std::string val);
+
+ private:
+ void ParseMultiplePkgs(const std::unique_ptr<Request>& req);
+
+ private:
+ std::unique_ptr<Request> request_;
+ std::unique_ptr<pkg_group::PkgSignal> signal_;
+ std::map<int, std::function<int(const std::unique_ptr<Request>&)>>
+ option_map_;
+ int argc_ = 0;
+ char** argv_ = nullptr;
+ int mode_ = 0;
+};
+
+} // namespace installer
+} // namespace pkgmgr
+
+#endif // INSTALLER_SRC_CONTROL_H_ \ No newline at end of file
diff --git a/installer/pkgmgr_installer.h b/installer/src/pkgmgr_installer.h
index a6848f5..7ecbabe 100644
--- a/installer/pkgmgr_installer.h
+++ b/installer/src/pkgmgr_installer.h
@@ -43,7 +43,7 @@ extern "C" {
/**
* pkgmgr_installer is an opaque type for an object
*/
-typedef struct pkgmgr_installer pkgmgr_installer;
+typedef void pkgmgr_installer;
typedef void *pkgmgr_instcertinfo_h;
/**
diff --git a/installer/pkgmgr_installer_debug.h b/installer/src/pkgmgr_installer_debug.h
index 26df677..a92a883 100644
--- a/installer/pkgmgr_installer_debug.h
+++ b/installer/src/pkgmgr_installer_debug.h
@@ -25,16 +25,16 @@
#endif /* LOG_TAG */
#define LOG_TAG "PKGMGR_INSTALLER"
-#ifndef ERR
-#define ERR(fmt, args...) LOGE("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#ifndef _E
+#define _E LOGE
#endif
-#ifndef DBG
-#define DBG(fmt, args...) LOGD("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#ifndef _D
+#define _D LOGD
#endif
-#ifndef INFO
-#define INFO(fmt, args...) LOGI("[%s:%d] "fmt"\n", __func__, __LINE__, ##args)
+#ifndef _I
+#define _I LOGI
#endif
#endif /* __PKGMGR_INSTALLER_DEBUG_H__ */
diff --git a/installer/pkgmgr_installer_error.h b/installer/src/pkgmgr_installer_error.h
index 7f60c03..7f60c03 100644
--- a/installer/pkgmgr_installer_error.h
+++ b/installer/src/pkgmgr_installer_error.h
diff --git a/installer/pkgmgr_installer_info.h b/installer/src/pkgmgr_installer_info.h
index 2d32446..2d32446 100644
--- a/installer/pkgmgr_installer_info.h
+++ b/installer/src/pkgmgr_installer_info.h
diff --git a/installer/pkgmgr_installer_type.h b/installer/src/pkgmgr_installer_type.h
index 9463fce..9463fce 100644
--- a/installer/pkgmgr_installer_type.h
+++ b/installer/src/pkgmgr_installer_type.h
diff --git a/installer/src/request.cc b/installer/src/request.cc
new file mode 100644
index 0000000..0593291
--- /dev/null
+++ b/installer/src/request.cc
@@ -0,0 +1,120 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "request.hh"
+
+#include <unistd.h>
+
+namespace pkgmgr {
+namespace installer {
+
+Request::Request() {
+ target_uid_ = getuid();
+}
+
+Request::~Request() = default;
+
+int Request::GetRequestType() const {
+ return request_type_;
+}
+
+int Request::GetMoveType() const {
+ return move_type_;
+}
+
+void Request::SetUpgrade(bool is_upgrade) {
+ is_upgrade_ = is_upgrade;
+}
+
+const std::string& Request::GetRequestInfo() const {
+ return pkgmgr_info_;
+}
+
+const std::string& Request::GetSessionId() const {
+ return session_id_;
+}
+
+const std::string& Request::GetLicensePath() const {
+ return license_path_;
+}
+
+const std::string& Request::GetOptionalData() const {
+ return optional_data_;
+}
+
+const std::string& Request::GetCallerPkgid() const {
+ return caller_pkgid_;
+}
+
+void Request::SetUid(uid_t uid) {
+ target_uid_ = uid;
+}
+
+uid_t Request::GetUid() const {
+ return target_uid_;
+}
+
+const std::string& Request::GetTepPath() const {
+ return tep_path_;
+}
+
+bool Request::IsTepMove() const {
+ return tep_move_;
+}
+
+bool Request::IsPreload() const {
+ return is_preload_;
+}
+
+bool Request::IsForceRemoval() const {
+ return force_removal_;
+}
+
+bool Request::IsPreloadRw() const {
+ return is_preload_rw_;
+}
+
+bool Request::IsNoRemoval() const {
+ return no_removal_;
+}
+
+bool Request::IsKeepRwData() const {
+ return keep_rwdata_;
+}
+
+bool Request::IsPartialRw() const {
+ return partial_rw_;
+}
+
+bool Request::IsDebugMode() const {
+ return debug_mode_;
+}
+
+bool Request::IsSkipCheckReference() const {
+ return skip_check_reference_;
+}
+
+bool Request::IsSkipOptimization() const {
+ return skip_optimization_;
+}
+
+bool Request::IsRecoveryCleanup() const {
+ return recovery_cleanup_;
+}
+
+} // namespace installer
+} // namespace pkgmgr
diff --git a/installer/src/request.hh b/installer/src/request.hh
new file mode 100644
index 0000000..217f561
--- /dev/null
+++ b/installer/src/request.hh
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#ifndef INSTALLER_SRC_REQUEST_H_
+#define INSTALLER_SRC_REQUEST_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <list>
+#include <vector>
+
+#include "PkgSignal.h"
+
+namespace pkgmgr {
+namespace installer {
+
+class Control;
+class Request {
+ public:
+ Request();
+ virtual ~Request();
+
+ int GetRequestType() const;
+ int GetMoveType() const;
+ void SetUpgrade(bool is_upgrade);
+ const std::string& GetRequestInfo() const;
+ const std::string& GetSessionId() const;
+ const std::string& GetLicensePath() const;
+ const std::string& GetOptionalData() const;
+ const std::string& GetCallerPkgid() const;
+ void SetUid(uid_t uid);
+ uid_t GetUid() const;
+ const std::string& GetTepPath() const;
+ bool IsTepMove() const;
+ bool IsPreload() const;
+ bool IsForceRemoval() const;
+ bool IsPreloadRw() const;
+ bool IsNoRemoval() const;
+ bool IsKeepRwData() const;
+ bool IsPartialRw() const;
+ bool IsDebugMode() const;
+ bool IsSkipCheckReference() const;
+ bool IsSkipOptimization() const;
+ bool IsRecoveryCleanup() const;
+
+ private:
+ friend class Control;
+ int request_type_ = 0;
+ int move_type_ = 0;
+ bool is_upgrade_ = false;
+ std::string pkgmgr_info_;
+ std::string session_id_;
+ std::string license_path_;
+ std::string optional_data_;
+ std::string caller_pkgid_;
+ uid_t target_uid_ = 0;
+ std::string tep_path_;
+ bool tep_move_ = false;
+ bool is_preload_ = false;
+ bool force_removal_ = false;
+ bool is_preload_rw_ = false;
+ bool no_removal_ = false;
+ bool keep_rwdata_ = false;
+ bool partial_rw_ = false;
+ bool debug_mode_ = false;
+ bool skip_check_reference_ = false;
+ bool skip_optimization_ = false;
+ bool recovery_cleanup_ = false;
+ std::vector<std::string> pkgs_;
+};
+
+} // namespace installer
+} // namespace pkgmgr
+
+#endif // INSTALLER_SRC_REQUEST_H_ \ No newline at end of file