From 0a63eca0340db09d9de44963323f385d3531c82f Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Thu, 29 Oct 2015 10:54:18 +0900 Subject: [PATCH] seperate tool and server from slp-pkgmgr (for sync with tizen2.4) to prevent cyclic dependency Change-Id: Ibb3b820930b9be2d2496d597b76e7ab52f781e1a Signed-off-by: jongmyeongko --- CMakeLists.txt | 4 +- comm/CMakeLists.txt | 2 +- packaging/pkgmgr-server.manifest | 5 - packaging/pkgmgr.manifest | 3 - packaging/pkgmgr.spec | 52 +- server/CMakeLists.txt | 28 - server/include/pkgmgr-server.h | 83 -- server/include/pm-queue.h | 60 - server/org.tizen.pkgmgr.conf.in | 22 - server/org.tizen.pkgmgr.service.in | 4 - server/queue_status | 1 - server/src/pkgmgr-server.c | 1145 ------------------- server/src/pm-queue.c | 509 --------- server/src/request.c | 563 ---------- tool/10_package-manager-add.post | 1 - tool/CMakeLists.txt | 59 - tool/mime.tpk.xml | 10 - tool/mime.wac.xml | 12 - tool/pkg_clearcache.c | 212 ---- tool/pkg_cmd.c | 985 ---------------- tool/pkg_getsize.c | 649 ----------- tool/pkg_info.c | 2167 ------------------------------------ tool/pkg_initdb.c | 200 ---- tool/pkg_install_ug.c | 91 -- tool/pkg_privilege.c | 220 ---- tool/pkgmgr.patch.sh.in | 8 - 26 files changed, 11 insertions(+), 7084 deletions(-) delete mode 100644 packaging/pkgmgr-server.manifest delete mode 100644 server/CMakeLists.txt delete mode 100644 server/include/pkgmgr-server.h delete mode 100644 server/include/pm-queue.h delete mode 100644 server/org.tizen.pkgmgr.conf.in delete mode 100644 server/org.tizen.pkgmgr.service.in delete mode 100644 server/queue_status delete mode 100644 server/src/pkgmgr-server.c delete mode 100644 server/src/pm-queue.c delete mode 100644 server/src/request.c delete mode 100644 tool/10_package-manager-add.post delete mode 100644 tool/CMakeLists.txt delete mode 100644 tool/mime.tpk.xml delete mode 100644 tool/mime.wac.xml delete mode 100644 tool/pkg_clearcache.c delete mode 100644 tool/pkg_cmd.c delete mode 100644 tool/pkg_getsize.c delete mode 100644 tool/pkg_info.c delete mode 100644 tool/pkg_initdb.c delete mode 100644 tool/pkg_install_ug.c delete mode 100644 tool/pkg_privilege.c delete mode 100644 tool/pkgmgr.patch.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 01630e9..d468828 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ INCLUDE_DIRECTORIES(comm) INCLUDE(FindPkgConfig) ADD_SUBDIRECTORY(comm) -ADD_SUBDIRECTORY(server) ADD_SUBDIRECTORY(client) -ADD_SUBDIRECTORY(tool) ADD_SUBDIRECTORY(types) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/package-manager-debug.h DESTINATION include) diff --git a/comm/CMakeLists.txt b/comm/CMakeLists.txt index 6976924..6101f7d 100644 --- a/comm/CMakeLists.txt +++ b/comm/CMakeLists.txt @@ -8,7 +8,7 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) ### Versioning -if(DEFINED ${VERSION}) +if(DEFINED ${VERSION}) message("VERSION: ${VERSION}") else() message("VERSION is not defined. set it as 0.1.0") diff --git a/packaging/pkgmgr-server.manifest b/packaging/pkgmgr-server.manifest deleted file mode 100644 index c00c25b..0000000 --- a/packaging/pkgmgr-server.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/pkgmgr.manifest b/packaging/pkgmgr.manifest index 02dc527..a76fdba 100644 --- a/packaging/pkgmgr.manifest +++ b/packaging/pkgmgr.manifest @@ -2,7 +2,4 @@ - - - diff --git a/packaging/pkgmgr.spec b/packaging/pkgmgr.spec index f06ff0e..932054e 100644 --- a/packaging/pkgmgr.spec +++ b/packaging/pkgmgr.spec @@ -10,11 +10,10 @@ Source0: %{name}-%{version}.tar.gz Source1001: %{name}.manifest Source1002: %{name}-client.manifest Source1003: %{name}-client-devel.manifest -Source1004: %{name}-server.manifest -Source1005: %{name}-installer.manifest -Source1006: %{name}-installer-devel.manifest -Source1007: %{name}-types-devel.manifest -Source1008: %{name}.conf +Source1004: %{name}-installer.manifest +Source1005: %{name}-installer-devel.manifest +Source1006: %{name}-types-devel.manifest +Source1007: %{name}.conf BuildRequires: cmake BuildRequires: unzip @@ -58,14 +57,6 @@ Requires: pkgmgr-client Package Manager client library develpoment package for packaging -%package server -Summary: Package Manager server -Requires: %{name} = %{version}-%{release} - -%description server -Package Manager server for packaging - - %package installer Summary: Library for installer frontend/backend Requires: %{name} = %{version}-%{release} @@ -92,7 +83,7 @@ Package Manager client types develpoment package for packaging %prep %setup -q -cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} %{SOURCE1004} %{SOURCE1005} %{SOURCE1006} %{SOURCE1007} . +cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} %{SOURCE1004} %{SOURCE1005} %{SOURCE1006} . %build %cmake . @@ -106,7 +97,7 @@ rm -f %{buildroot}%{_libdir}/libpkgmgr_backend_lib_sample.so rm -f %{buildroot}%{_libdir}/libpkgmgr_parser_lib_sample.so mkdir -p %{buildroot}%{_tmpfilesdir}/ -install -m 0644 %{SOURCE1008} %{buildroot}%{_tmpfilesdir}/pkgmgr.conf +install -m 0644 %{SOURCE1007} %{buildroot}%{_tmpfilesdir}/pkgmgr.conf mkdir -p %{buildroot}%{_sysconfdir}/package-manager/backend mkdir -p %{buildroot}%{_sysconfdir}/package-manager/backendlib @@ -122,22 +113,14 @@ touch %{buildroot}%{_sysconfdir}/package-manager/backend/clearcache chmod 755 %{buildroot}%{_sysconfdir}/package-manager/backend/clearcache -mkdir -p %{buildroot}%{_sysconfdir}/package-manager/server - %fdupes %{buildroot} %post /sbin/ldconfig -# For pkgmgr-install: -# Update mime database to support package mime types -update-mime-database %{_datadir}/mime - # Create tizenglobalapp user needed for global installation useradd -d %TZ_SYS_RW_APP -m %TZ_SYS_GLOBALAPP_USER -r -c "system user for common applications" -g root -%post -n pkgmgr-server -p /sbin/ldconfig - %post -n pkgmgr-client -p /sbin/ldconfig %postun -n pkgmgr-client -p /sbin/ldconfig @@ -150,24 +133,13 @@ useradd -d %TZ_SYS_RW_APP -m %TZ_SYS_GLOBALAPP_USER -r -c "system user for commo %files %manifest %{name}.manifest %defattr(-,root,root,-) +%{_includedir}/package-manager-debug.h +%{_includedir}/pkgmgr/comm_config.h %dir %{_sysconfdir}/package-manager/backend %dir %{_sysconfdir}/package-manager/backendlib -%dir %{_sysconfdir}/opt/upgrade %{_sysconfdir}/package-manager/backend/* -%{_sysconfdir}/opt/upgrade/pkgmgr.patch.sh -%{_bindir}/pkgcmd -%attr(06755,root,root) %{_bindir}/pkg_initdb -%attr(755,root,root) %{_sysconfdir}/gumd/useradd.d/10_package-manager-add.post -%{_bindir}/pkg_getsize -%{_bindir}/pkg_clearcache -%{_bindir}/pkg_privilege -%{_bindir}/pkg_install_ug -%{_bindir}/pkginfo -%{_datadir}/mime/packages/mime.wac.xml -%{_datadir}/mime/packages/mime.tpk.xml %{_tmpfilesdir}/pkgmgr.conf %exclude %{_includedir}/pkgmgr/comm_client.h -%exclude %{_includedir}/pkgmgr/comm_config.h %exclude %{_sysconfdir}/package-manager/server/queue_status %files client @@ -184,14 +156,6 @@ useradd -d %TZ_SYS_RW_APP -m %TZ_SYS_GLOBALAPP_USER -r -c "system user for commo %{_libdir}/pkgconfig/pkgmgr.pc %{_libdir}/libpkgmgr-client.so -%files server -%manifest %{name}-server.manifest -%defattr(-,root,root,-) -%{_datadir}/dbus-1/system-services/org.tizen.pkgmgr.service -%config %{_sysconfdir}/dbus-1/system.d/org.tizen.pkgmgr.conf -%{_bindir}/pkgmgr-server -%{_sysconfdir}/package-manager/server - %files installer %manifest %{name}-installer.manifest %defattr(-,root,root,-) diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt deleted file mode 100644 index 4bdcfc2..0000000 --- a/server/CMakeLists.txt +++ /dev/null @@ -1,28 +0,0 @@ -# package manager server - -SET(PKGMGR_SERVER "pkgmgr-server") -SET(SRCS src/pkgmgr-server.c src/request.c src/pm-queue.c) - -pkg_check_modules(SERVER_DEPS REQUIRED - gio-2.0 - dlog - pkgmgr-parser - pkgmgr-info - libtzplatform-config) -FOREACH(SERVER_FLAGS ${SERVER_DEPS_CFLAGS}) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${SERVER_FLAGS}") -ENDFOREACH(SERVER_FLAGS) - -INCLUDE_DIRECTORIES(include) - -ADD_EXECUTABLE(${PKGMGR_SERVER} ${SRCS}) -TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} pkgmgr_installer) -TARGET_LINK_LIBRARIES(${PKGMGR_SERVER} ${SERVER_DEPS_LDFLAGS}) - -CONFIGURE_FILE(org.tizen.pkgmgr.service.in org.tizen.pkgmgr.service @ONLY) -CONFIGURE_FILE(org.tizen.pkgmgr.conf.in org.tizen.pkgmgr.conf @ONLY) - -INSTALL(TARGETS ${PKGMGR_SERVER} DESTINATION bin) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/queue_status DESTINATION ${SYSCONFDIR}/package-manager/server/) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.pkgmgr.service DESTINATION ${PREFIX}/share/dbus-1/system-services/) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.tizen.pkgmgr.conf DESTINATION ${SYSCONFDIR}/dbus-1/system.d/) diff --git a/server/include/pkgmgr-server.h b/server/include/pkgmgr-server.h deleted file mode 100644 index 69cca87..0000000 --- a/server/include/pkgmgr-server.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 _PKGMGR_SERVER_H_ -#define _PKGMGR_SERVER_H_ - -#include - -#ifdef LOG_TAG -#undef LOG_TAG -#endif /* LOG_TAG */ -#define LOG_TAG "PKGMGR_SERVER" -#include "package-manager-debug.h" - -#define CONF_FILE "/etc/package-manager/server/.config" -#define DESKTOP_FILE_DIRS "/usr/share/install-info/desktop.conf" - -#define PKG_BACKEND "backend:" -#define PKG_CONF_PATH "/etc/package-manager/pkg_path.conf" - -#define MAX_REQ_ID_LEN 256 -#define MAX_PKG_TYPE_LEN 128 -#define MAX_PKG_NAME_LEN 256 -#define MAX_PKG_ARGS_LEN 4096 -#define DESKTOP_FILE_DIRS_NUM 1024 - -enum request_type { - PKGMGR_REQUEST_TYPE_INSTALL, - PKGMGR_REQUEST_TYPE_REINSTALL, - PKGMGR_REQUEST_TYPE_UNINSTALL, - PKGMGR_REQUEST_TYPE_MOVE, - PKGMGR_REQUEST_TYPE_ENABLE, - PKGMGR_REQUEST_TYPE_DISABLE, - PKGMGR_REQUEST_TYPE_GETSIZE, - PKGMGR_REQUEST_TYPE_CLEARDATA, - PKGMGR_REQUEST_TYPE_CLEARCACHE, - PKGMGR_REQUEST_TYPE_KILL, - PKGMGR_REQUEST_TYPE_CHECK, -}; - -typedef struct { - char req_id[MAX_REQ_ID_LEN]; - int req_type; - uid_t uid; - char pkg_type[MAX_PKG_TYPE_LEN]; - char pkgid[MAX_PKG_NAME_LEN]; - char args[MAX_PKG_ARGS_LEN]; -} pm_dbus_msg; - -typedef struct backend_info_t { - int pid; - uid_t uid; - char pkgtype[MAX_PKG_TYPE_LEN]; - char pkgid[MAX_PKG_NAME_LEN]; - char args[MAX_PKG_ARGS_LEN]; -} backend_info; - -char *_get_backend_cmd(char *type); - -gboolean queue_job(void *data); -int __init_request_handler(void); -void __fini_request_handler(void); - -#endif/* _PKGMGR_SERVER_H_ */ diff --git a/server/include/pm-queue.h b/server/include/pm-queue.h deleted file mode 100644 index fac45d5..0000000 --- a/server/include/pm-queue.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 _PM_QUEUE_H_ -#define _PM_QUEUE_H_ - -#include "pkgmgr-server.h" - -#define STATUS_FILE "/etc/package-manager/server/queue_status" -/* #define STATUS_FILE "./queue_status" */ - -typedef struct _pm_queue_data { - pm_dbus_msg *msg; - struct _pm_queue_data *next; -} pm_queue_data; - -typedef struct queue_info_map_t { - char pkgtype[MAX_PKG_TYPE_LEN]; - char backend[MAX_PKG_NAME_LEN]; - int queue_slot; - pm_queue_data *head; -} queue_info_map; - -#define MAX_QUEUE_NUM 128 - -int _pm_queue_init(void); -int _pm_queue_push(uid_t uid, const char *req_id, int req_type, - const char *pkg_type, const char *pkgid, const char *argv); -/*position specifies the queue from which to pop request*/ -pm_dbus_msg *_pm_queue_pop(int position); -void _pm_queue_final(); -void _pm_queue_delete(pm_dbus_msg *item); -pm_queue_data *_add_node(); -void _save_queue_status(pm_dbus_msg *item, char *status); -void _print_queue(int position); - -#endif /* _PM_QUEUE_H_ */ diff --git a/server/org.tizen.pkgmgr.conf.in b/server/org.tizen.pkgmgr.conf.in deleted file mode 100644 index 266985f..0000000 --- a/server/org.tizen.pkgmgr.conf.in +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/server/org.tizen.pkgmgr.service.in b/server/org.tizen.pkgmgr.service.in deleted file mode 100644 index 38c9534..0000000 --- a/server/org.tizen.pkgmgr.service.in +++ /dev/null @@ -1,4 +0,0 @@ -[D-BUS Service] -User=root -Name=org.tizen.pkgmgr -Exec=@PREFIX@/bin/pkgmgr-server diff --git a/server/queue_status b/server/queue_status deleted file mode 100644 index 5baa80c..0000000 --- a/server/queue_status +++ /dev/null @@ -1 +0,0 @@ -This file is for creating required directory. diff --git a/server/src/pkgmgr-server.c b/server/src/pkgmgr-server.c deleted file mode 100644 index 350cb0e..0000000 --- a/server/src/pkgmgr-server.c +++ /dev/null @@ -1,1145 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include "pkgmgr_installer.h" -#include "pkgmgr-server.h" -#include "pm-queue.h" -#include "comm_config.h" -#include "package-manager.h" - -#define BUFMAX 128 -#define NO_MATCHING_FILE 11 - -#define OWNER_ROOT 0 -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) - -typedef struct { - char **env; - uid_t uid; - gid_t gid; -} user_ctx; - - -/* -8 bit value to represent maximum 8 backends. -Each bit position corresponds to a queue slot which -is dynamically determined. -*/ -char backend_busy = 0; -extern int num_of_backends; - -struct signal_info_t { - pid_t pid; - int status; -}; - -static int pipe_sig[2]; -static GIOChannel *pipe_io; -static guint pipe_wid; - -backend_info *begin; -extern queue_info_map *start; -extern int entries; - -GMainLoop *mainloop = NULL; - - -/* operation_type */ -typedef enum { - OPERATION_INSTALL = 0, - OPERATION_UNINSTALL, - OPERATION_ACTIVATE, - OPERATION_REINSTALL, - OPERATION_MAX -} OPERATION_TYPE; - -static int __check_backend_status_for_exit(void); -static int __check_queue_status_for_exit(void); -static int __is_backend_busy(int position); -static void __set_backend_busy(int position); -static void __set_backend_free(int position); -static void sighandler(int signo); - -gboolean exit_server(void *data); - -/* To check whether a particular backend is free/busy*/ -static int __is_backend_busy(int position) -{ - return backend_busy & 1<message); - pkgmgr_installer_free(pi); - return; - } - - pkgmgr_installer_receive_request(pi, argcp, argvp); - pkgmgr_installer_send_signal(pi, ptype, pname, "end", "fail"); - pkgmgr_installer_free(pi); - return; -} - -static gboolean pipe_io_handler(GIOChannel *io, GIOCondition cond, gpointer data) -{ - int x; - GError *err = NULL; - GIOStatus s; - gsize len; - struct signal_info_t info; - backend_info *ptr = begin; - - s = g_io_channel_read_chars(io, (gchar *)&info, sizeof(struct signal_info_t), &len, &err); - if (s != G_IO_STATUS_NORMAL) { - ERR("Signal pipe read failed: %s", err->message); - g_error_free(err); - return TRUE; - } - - for (x = 0; x < num_of_backends; x++, ptr++) { - if (ptr && ptr->pid == info.pid) - break; - } - - if (x == num_of_backends) { - ERR("Unknown child exit"); - return -1; - } - - __set_backend_free(x); - __unset_recovery_mode(ptr->uid, ptr->pkgid, ptr->pkgtype); - if (WIFSIGNALED(info.status) || WEXITSTATUS(info.status)) { - send_fail_signal(ptr->pkgid, ptr->pkgtype, ptr->args); - DBG("backend[%s] exit with error", ptr->pkgtype); - } else { - DBG("backend[%s] exit", ptr->pkgtype); - } - - g_idle_add(queue_job, NULL); - - return TRUE; -} - -static int __init_backend_info(void) -{ - backend_info *ptr; - - /*Allocate memory for holding pid, pkgtype and pkgid*/ - ptr = (backend_info*)calloc(num_of_backends, sizeof(backend_info)); - if (ptr == NULL) { - DBG("Malloc Failed\n"); - return -1; - } - begin = ptr; - - if (pipe(pipe_sig)) { - ERR("create pipe failed"); - return -1; - } - - pipe_io = g_io_channel_unix_new(pipe_sig[0]); - g_io_channel_set_encoding(pipe_io, NULL, NULL); - g_io_channel_set_buffered(pipe_io, FALSE); - pipe_wid = g_io_add_watch(pipe_io, G_IO_IN, pipe_io_handler, NULL); - - return 0; -} - -static void __fini_backend_info(void) -{ - g_source_remove(pipe_wid); - g_io_channel_unref(pipe_io); - close(pipe_sig[0]); - close(pipe_sig[1]); - - /*Free backend info */ - free(begin); -} - -static void sighandler(int signo) -{ - struct signal_info_t info; - - info.pid = waitpid(-1, &info.status, WNOHANG); - if (write(pipe_sig[1], &info, sizeof(struct signal_info_t)) < 0) - ERR("failed to write result: %s", strerror(errno)); -} - -static int __register_signal_handler(void) -{ - static int sig_reg = 0; - struct sigaction act; - - if (sig_reg) - return 0; - - act.sa_handler = sighandler; - sigemptyset(&act.sa_mask); - act.sa_flags = SA_NOCLDSTOP; - if (sigaction(SIGCHLD, &act, NULL) < 0) { - ERR("signal: SIGCHLD failed\n"); - return -1; - } - - g_timeout_add_seconds(2, exit_server, NULL); - - sig_reg = 1; - return 0; -} - -static int __check_backend_status_for_exit(void) -{ - int i = 0; - for(i = 0; i < num_of_backends; i++) - { - if (!__is_backend_busy(i)) - continue; - else - return 0; - } - return 1; -} - -static int __check_queue_status_for_exit(void) -{ - pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,}; - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - int c = 0; - int slot = -1; - for(i = 0; i < entries; i++) - { - if (ptr->queue_slot <= slot) { - ptr++; - continue; - } - else { - head[c] = ptr->head; - slot = ptr->queue_slot; - c++; - ptr++; - } - } - for(i = 0; i < num_of_backends; i++) - { - if (!head[i]) - continue; - else - return 0; - } - return 1; -} - -gboolean exit_server(void *data) -{ - DBG("exit_server Start\n"); - if (__check_backend_status_for_exit() && - __check_queue_status_for_exit()) { - if (!getenv("PMS_STANDALONE")) { - g_main_loop_quit(mainloop); - return FALSE; - } - } - return TRUE; -} - -static int __pkgcmd_read_proc(const char *path, char *buf, int size) -{ - int fd; - int ret; - if (buf == NULL || path == NULL) - return -1; - fd = open(path, O_RDONLY); - if (fd < 0) - return -1; - ret = read(fd, buf, size - 1); - if (ret <= 0) { - close(fd); - return -1; - } else - buf[ret] = 0; - close(fd); - return ret; -} - -static int __pkgcmd_find_pid_by_cmdline(const char *dname, - const char *cmdline, const char *apppath) -{ - int pid = 0; - - if (strcmp(cmdline, apppath) == 0) { - pid = atoi(dname); - if (pid != getpgid(pid)) - pid = 0; - } - return pid; -} - -static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option) -{ - DIR *dp; - struct dirent *dentry; - int pid; - int ret; - char buf[1024] = {'\0'}; - int pgid; - - dp = opendir("/proc"); - if (dp == NULL) { - return -1; - } - - while ((dentry = readdir(dp)) != NULL) { - if (!isdigit(dentry->d_name[0])) - continue; - - snprintf(buf, sizeof(buf), "/proc/%s/cmdline", dentry->d_name); - ret = __pkgcmd_read_proc(buf, buf, sizeof(buf)); - if (ret <= 0) - continue; - - pid = __pkgcmd_find_pid_by_cmdline(dentry->d_name, buf, apppath); - if (pid > 0) { - if (option == 0) { - closedir(dp); - return pid; - } - pgid = getpgid(pid); - if (pgid <= 1) { - closedir(dp); - return -1; - } - if (killpg(pgid, SIGKILL) < 0) { - closedir(dp); - return -1; - } - closedir(dp); - return pid; - } - } - closedir(dp); - return 0; -} - -static void __make_pid_info_file(char *req_key, int pid) -{ - FILE* file; - int fd; - char buf[MAX_PKG_TYPE_LEN] = {0}; - char info_file[PATH_MAX] = {'\0'}; - - if(req_key == NULL) - return; - - snprintf(info_file, PATH_MAX, "/tmp/%s", req_key); - - DBG("info_path(%s)", info_file); - file = fopen(info_file, "w"); - if (file == NULL) { - ERR("Couldn't open the file(%s)", info_file); - return; - } - - snprintf(buf, MAX_PKG_TYPE_LEN, "%d\n", pid); - fwrite(buf, 1, strlen(buf), file); - - fflush(file); - fd = fileno(file); - fsync(fd); - fclose(file); -} - -static int __pkgcmd_app_cb(const pkgmgrinfo_appinfo_h handle, void *user_data) -{ - char *pkgid; - char *exec; - int ret; - int pid = -1; - - if (handle == NULL) { - perror("appinfo handle is NULL\n"); - exit(1); - } - ret = pkgmgrinfo_appinfo_get_exec(handle, &exec); - if (ret) { - perror("Failed to get app exec path\n"); - exit(1); - } - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid); - if (ret) { - perror("Failed to get pkgid\n"); - exit(1); - } - - if (strcmp(user_data, "kill") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 1); - else if(strcmp(user_data, "check") == 0) - pid = __pkgcmd_proc_iter_kill_cmdline(exec, 0); - - __make_pid_info_file(pkgid, pid); - - return 0; -} - -void free_user_context(user_ctx* ctx) -{ - char **env = NULL; - int i = 0; - if (!ctx) - return; - env = ctx->env; - //env variable ends by NULL element - while (env[i]) { - free(env[i]); - i++; - } - free(env); - env = NULL; - free(ctx); -} - -int set_environement(user_ctx *ctx) -{ - int i = 0; - int res = 0; - char **env = NULL; - if (!ctx) - return -1;; - if (setgid(ctx->gid)) { - ERR("setgid failed: %d", errno); - return -1; - } - if (setuid(ctx->uid)) { - ERR("setuid failed: %d", errno); - return -1; - } - env = ctx->env; - //env variable ends by NULL element - while (env[i]) { - if (putenv(env[i]) != 0) - res = -1; - i++; - } - return res; -} - -user_ctx* get_user_context(uid_t uid) -{ - /* we can use getpwnam because this is used only after a - * fork and just before an execv - * No concurrencial call can corrupt the data - * returned by getpwuid - */ - user_ctx *context_res; - char **env = NULL; - struct passwd * pwd; - int len; - int ret = 0; - - pwd = getpwuid(uid); - if (!pwd) - return NULL; - - do { - context_res = (user_ctx *)malloc(sizeof(user_ctx)); - if (!context_res) { - ret = -1; - break; - } - env = (char**)malloc(3* sizeof(char *)); - if (!env) { - ret = -1; - break; - } - // Build environment context - len = snprintf(NULL,0, "HOME=%s", pwd->pw_dir); - env[0] = (char*)malloc((len + 1)* sizeof(char)); - if(env[0] == NULL) { - ret = -1; - break; - } - sprintf(env[0], "HOME=%s", pwd->pw_dir); - len = snprintf(NULL,0, "USER=%s", pwd->pw_name); - env[1] = (char*)malloc((len + 1)* sizeof(char)); - if(env[1] == NULL) { - ret = -1; - break; - } - - sprintf(env[1], "USER=%s", pwd->pw_name); - env[2] = NULL; - } while (0); - - if (ret == -1) { - free(context_res); - context_res = NULL; - int i = 0; - //env variable ends by NULL element - while (env && env[i]) { - free(env[i]); - i++; - } - free(env); - env = NULL; - } else { - context_res->env = env; - context_res->uid = uid; - context_res->gid = pwd->pw_gid; - } - return context_res; -} - -static char **__generate_argv(const char *args) -{ - /* Create args vector - * req_id + pkgid + args - * - * vector size = # of args + - *(req_id + pkgid + NULL termination = 3) - * Last value must be NULL for execv. - */ - gboolean ret_parse; - gint argcp; - gchar **argvp; - GError *gerr = NULL; - ret_parse = g_shell_parse_argv(args, - &argcp, &argvp, &gerr); - if (FALSE == ret_parse) { - DBG("Failed to split args: %s", args); - DBG("messsage: %s", gerr->message); - exit(1); - } - - /* Setup argument !!! */ - /*char **args_vector = - calloc(argcp + 4, sizeof(char *)); */ - char **args_vector = calloc(argcp + 1, sizeof(char *)); - if (args_vector == NULL) { - ERR("Out of memory"); - exit(1); - } - /*args_vector[0] = strdup(backend_cmd); - args_vector[1] = strdup(item->req_id); - args_vector[2] = strdup(item->pkgid); */ - int arg_idx; - for (arg_idx = 0; arg_idx < argcp; arg_idx++) { - /* args_vector[arg_idx+3] = argvp[arg_idx]; */ - args_vector[arg_idx] = argvp[arg_idx]; - } - - /* dbg */ - /*for(arg_idx = 0; arg_idx < argcp+3; arg_idx++) { */ - for (arg_idx = 0; arg_idx < argcp + 1; arg_idx++) { - DBG(">>>>>> args_vector[%d]=%s", - arg_idx, args_vector[arg_idx]); - } - - return args_vector; -} - -static void __exec_with_arg_vector(const char *cmd, char **argv, uid_t uid) -{ - user_ctx* user_context = get_user_context(uid); - if(!user_context) { - DBG("Failed to getenv for the user : %d", uid); - exit(1); - } - if(set_environement(user_context)){ - DBG("Failed to set env for the user : %d", uid); - exit(1); - } - free_user_context(user_context); - - /* Execute backend !!! */ - int ret = execv(cmd, argv); - - /* Code below: exec failure. Should not be happened! */ - DBG(">>>>>> OOPS 2!!!"); - - /* g_strfreev(args_vector); *//* FIXME: causes error */ - - if (ret == -1) { - perror("fail to exec"); - exit(1); - } -} - -static void __process_install(pm_dbus_msg *item) -{ - char *backend_cmd; - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - backend_cmd = _get_backend_cmd(item->pkg_type); - if (backend_cmd == NULL) - return; - - snprintf(args, sizeof(args), "%s -k %s -i %s", backend_cmd, - item->req_id, item->pkgid); - args_vector = __generate_argv(args); - args_vector[0] = backend_cmd; - - __exec_with_arg_vector(backend_cmd, args_vector, item->uid); -} - -static void __process_reinstall(pm_dbus_msg *item) -{ - char *backend_cmd; - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - backend_cmd = _get_backend_cmd(item->pkg_type); - if (backend_cmd == NULL) - return; - - snprintf(args, sizeof(args), "%s -k %s -r %s", backend_cmd, - item->req_id, item->pkgid); - args_vector = __generate_argv(args); - args_vector[0] = backend_cmd; - - __exec_with_arg_vector(backend_cmd, args_vector, item->uid); -} - -static void __process_uninstall(pm_dbus_msg *item) -{ - char *backend_cmd; - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - backend_cmd = _get_backend_cmd(item->pkg_type); - if (backend_cmd == NULL) - return; - - snprintf(args, sizeof(args), "%s -k %s -d %s", backend_cmd, - item->req_id, item->pkgid); - args_vector = __generate_argv(args); - args_vector[0] = backend_cmd; - - __exec_with_arg_vector(backend_cmd, args_vector, item->uid); -} - -static void __process_move(pm_dbus_msg *item) -{ - char *backend_cmd; - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - backend_cmd = _get_backend_cmd(item->pkg_type); - if (backend_cmd == NULL) - return; - - /* TODO: set movetype */ - snprintf(args, sizeof(args), "%s -k %s -m %s -t %s", backend_cmd, - item->req_id, item->pkgid, item->args); - args_vector = __generate_argv(args); - args_vector[0] = backend_cmd; - - __exec_with_arg_vector(backend_cmd, args_vector, item->uid); -} - -static void __process_enable(pm_dbus_msg *item) -{ - /* TODO */ -} - -static void __process_disable(pm_dbus_msg *item) -{ - /* TODO */ -} - -static void __process_getsize(pm_dbus_msg *item) -{ - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - snprintf(args, sizeof(args), "%s %s -k %s", item->pkgid, item->args, - item->req_id); - args_vector = __generate_argv(args); - __exec_with_arg_vector("/usr/bin/pkg_getsize", args_vector, item->uid); -} - -static void __process_cleardata(pm_dbus_msg *item) -{ - char *backend_cmd; - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - backend_cmd = _get_backend_cmd(item->pkg_type); - if (backend_cmd == NULL) - return; - - /* TODO: set movetype */ - snprintf(args, sizeof(args), "%s -k %s -c %s", backend_cmd, - item->req_id, item->pkgid); - args_vector = __generate_argv(args); - args_vector[0] = backend_cmd; - - __exec_with_arg_vector(backend_cmd, args_vector, item->uid); -} - -static void __process_clearcache(pm_dbus_msg *item) -{ - char **args_vector; - char args[MAX_PKG_ARGS_LEN]; - - snprintf(args, sizeof(args), "%s", item->pkgid); - args_vector = __generate_argv(args); - __exec_with_arg_vector("/usr/bin/pkg_clearcache", args_vector, - item->uid); -} - -static void __process_kill(pm_dbus_msg *item) -{ - int ret; - pkgmgrinfo_pkginfo_h handle; - - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, - &handle); - if (ret < 0) { - ERR("Failed to get handle"); - return; - } - - ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __pkgcmd_app_cb, "kill", item->uid); - if (ret < 0) - ERR("pkgmgrinfo_appinfo_get_list() failed"); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); -} - -static void __process_check(pm_dbus_msg *item) -{ - int ret; - pkgmgrinfo_pkginfo_h handle; - - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(item->pkgid, item->uid, - &handle); - if (ret < 0) { - ERR("Failed to get handle"); - return; - } - - ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, - __pkgcmd_app_cb, "check", item->uid); - if (ret < 0) - ERR("pkgmgrinfo_appinfo_get_list() failed"); - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); -} - -gboolean queue_job(void *data) -{ - pm_dbus_msg *item = NULL; - backend_info *ptr; - int x; - - /* Pop a job from queue */ - for (x = 0, ptr = begin; x < num_of_backends; x++, ptr++) { - if (__is_backend_busy(x)) - continue; - - item = _pm_queue_pop(x); - if (item && item->req_type != -1) - break; - free(item); - } - - /* all backend messages queue are empty or busy */ - if (x == num_of_backends) - return FALSE; - - __set_backend_busy(x); - __set_recovery_mode(item->uid, item->pkgid, item->pkg_type); - - /* fork */ - _save_queue_status(item, "processing"); - DBG("saved queue status. Now try fork()"); - /*save pkg type and pkg name for future*/ - strncpy(ptr->pkgtype, item->pkg_type, MAX_PKG_TYPE_LEN-1); - strncpy(ptr->pkgid, item->pkgid, MAX_PKG_NAME_LEN-1); - strncpy(ptr->args, item->args, MAX_PKG_ARGS_LEN-1); - ptr->uid = item->uid; - ptr->pid = fork(); - DBG("child forked [%d] for request type [%d]", ptr->pid, item->req_type); - - switch (ptr->pid) { - case 0: /* child */ - switch (item->req_type) { - case PKGMGR_REQUEST_TYPE_INSTALL: - __process_install(item); - break; - case PKGMGR_REQUEST_TYPE_REINSTALL: - __process_reinstall(item); - break; - case PKGMGR_REQUEST_TYPE_UNINSTALL: - __process_uninstall(item); - break; - case PKGMGR_REQUEST_TYPE_MOVE: - __process_move(item); - break; - case PKGMGR_REQUEST_TYPE_ENABLE: - __process_enable(item); - break; - case PKGMGR_REQUEST_TYPE_DISABLE: - __process_disable(item); - break; - case PKGMGR_REQUEST_TYPE_GETSIZE: - __process_getsize(item); - break; - case PKGMGR_REQUEST_TYPE_CLEARDATA: - __process_cleardata(item); - break; - case PKGMGR_REQUEST_TYPE_CLEARCACHE: - __process_clearcache(item); - break; - case PKGMGR_REQUEST_TYPE_KILL: - __process_kill(item); - break; - case PKGMGR_REQUEST_TYPE_CHECK: - __process_check(item); - break; - } - /* exit child */ - _save_queue_status(item, "done"); - exit(0); - break; - - case -1: - fprintf(stderr, "Fail to execute_fork()\n"); - exit(1); - - default: /* parent */ - DBG("parent exit\n"); - _save_queue_status(item, "done"); - break; - } - - free(item); - - return FALSE; -} - -#define IS_WHITESPACE(CHAR) \ -((CHAR == ' ' || CHAR == '\t' || CHAR == '\r' || CHAR == '\n') ? TRUE : FALSE) - -void _app_str_trim(char *input) -{ - char *trim_str = input; - - if (input == NULL) - return; - - while (*input != 0) { - if (!IS_WHITESPACE(*input)) { - *trim_str = *input; - trim_str++; - } - input++; - } - - *trim_str = 0; - return; -} - -char *_get_backend_cmd(char *type) -{ - FILE *fp = NULL; - char buffer[1024] = { 0 }; - char *command = NULL; - int size = 0; - fp = fopen(PKG_CONF_PATH, "r"); - if (fp == NULL) { - return NULL; - } - - char *path = NULL; - while (fgets(buffer, 1024, fp) != NULL) { - if (buffer[0] == '#') - continue; - - _app_str_trim(buffer); - - if ((path = strstr(buffer, PKG_BACKEND)) != NULL) { - DBG("buffer [%s]", buffer); - path = path + strlen(PKG_BACKEND); - DBG("path [%s]", path); - - command = - (char *)malloc(sizeof(char) * strlen(path) + - strlen(type) + 1); - if (command == NULL) { - fclose(fp); - return NULL; - } - - size = strlen(path) + strlen(type) + 1; - snprintf(command, size, "%s%s", path, type); - command[strlen(path) + strlen(type)] = '\0'; - DBG("command [%s]", command); - - if (fp != NULL) - fclose(fp); - - return command; - } - - memset(buffer, 0x00, 1024); - } - - if (fp != NULL) - fclose(fp); - - return NULL; /* cannot find proper command */ -} - -int main(int argc, char *argv[]) -{ - FILE *fp_status = NULL; - char buf[32] = { 0, }; - pid_t pid; - char *backend_cmd = NULL; - char *backend_name = NULL; - int r; - - DBG("server start"); - - if (argv[1] && (strcmp(argv[1], "init") == 0)) { - /* if current status is "processing", - execute related backend with '-r' option */ - if (!(fp_status = fopen(STATUS_FILE, "r"))) - return 0; /*if file is not exist, terminated. */ - /* if processing <-- unintended termination */ - if (fgets(buf, 32, fp_status) && - strcmp(buf, "processing") == 0) { - pid = fork(); - if (pid == 0) { /* child */ - if (fgets(buf, 32, fp_status)) - backend_cmd = _get_backend_cmd(buf); - if (!backend_cmd) { /* if NULL, */ - DBG("fail to get backend command"); - goto err; - } - backend_name = - strrchr(backend_cmd, '/'); - if (!backend_name) { - DBG("fail to get backend name"); - goto err; - } - - execl(backend_cmd, backend_name, "-r", - NULL); - if (backend_cmd) - free(backend_cmd); - fprintf(fp_status, " "); -err: - fclose(fp_status); - exit(13); - } else if (pid < 0) { /* error */ - DBG("fork fail"); - fclose(fp_status); - return 0; - } else { /* parent */ - - DBG("parent end\n"); - fprintf(fp_status, " "); - fclose(fp_status); - return 0; - } - } - } - - r = _pm_queue_init(); - if (r) { - DBG("Queue Initialization Failed\n"); - return -1; - } - - r = __init_backend_info(); - if (r) { - DBG("backend info init failed"); - return -1; - } - - r = __init_request_handler(); - if (r) { - ERR("dbus init failed"); - return -1; - } - - if (__register_signal_handler()) { - ERR("failed to register signal handler"); - return -1; - } - -#if !GLIB_CHECK_VERSION(2,35,0) - g_type_init(); -#endif - mainloop = g_main_loop_new(NULL, FALSE); - if (!mainloop) { - ERR("g_main_loop_new failed"); - return -1; - } - - DBG("Main loop is created."); - - g_main_loop_run(mainloop); - - DBG("Quit main loop."); - __fini_request_handler(); - __fini_backend_info(); - _pm_queue_final(); - - DBG("package manager server terminated."); - - return 0; -} diff --git a/server/src/pm-queue.c b/server/src/pm-queue.c deleted file mode 100644 index 0100a9d..0000000 --- a/server/src/pm-queue.c +++ /dev/null @@ -1,509 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include -#include -#include -#include - -#include "pkgmgr-server.h" -#include "pm-queue.h" - -#define BACKEND_INFO_DIR "/etc/package-manager/backend" - -static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type); -static void __update_head_from_pkgtype(pm_queue_data *data); -static int __entry_exist(char *backend); -static int __is_pkg_supported(const char *pkgtype); - -queue_info_map *start = NULL; -int entries = 0; -int slot = 0; -int num_of_backends = 0; - -/*Function to check whether a particular package type -is supported or not. It parses the queue info map -to get the information. -It will prevent the accidental hanging of server. -Returns 1 if found.*/ -static int __is_pkg_supported(const char *pkgtype) -{ - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - for(i = 0; i < entries; i++) - { - if (!strncmp(ptr->pkgtype, pkgtype, MAX_PKG_TYPE_LEN)) - return 1; - else { - ptr++; - continue; - } - } - return 0; -} - -/*tells whether a particular backend exists in the -* info map or not. -* on Success it return the queue slot of the already present entry -* on Failure -1 is returned*/ -static int __entry_exist(char *backend) -{ - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - for(i = 0; i < entries; i++) - { - if (!strncmp(ptr->backend, backend, MAX_PKG_NAME_LEN)) - return ptr->queue_slot; - else { - ptr++; - continue; - } - } - return -1; -} - -/*In case of first push, it updates the queue head -and copies it to all duplicate entries in queue info map*/ -static void __update_head_from_pkgtype(pm_queue_data *data) -{ - queue_info_map *ptr = NULL; - ptr = start; - int slot = -1; - int i = 0; - for(i = 0; i < entries; i++) - { - if (!strncmp(ptr->pkgtype, data->msg->pkg_type, MAX_PKG_TYPE_LEN)) { - ptr->head = data; - slot = ptr->queue_slot; - } - else { - ptr++; - continue; - } - } - /*update head for each duplicate entry*/ - ptr = start; - for(i = 0; i < entries; i++) - { - if(ptr->queue_slot == slot && !ptr->head) { - ptr->head = data; - } - ptr++; - } - return; -} - -/*Gets the queue head based on pkg type*/ -static pm_queue_data *__get_head_from_pkgtype(const char *pkg_type) -{ - queue_info_map *ptr = NULL; - ptr = start; - int i = 0; - for(i = 0; i < entries; i++) - { - if (!strncmp(ptr->pkgtype, pkg_type, MAX_PKG_TYPE_LEN)) - return ptr->head; - else { - ptr++; - continue; - } - } - return NULL; - -} - -int _pm_queue_init(void) -{ - /*Find the num of backends currently supported and initialize - that many queues. It is dynamically determined.*/ - struct dirent **namelist; - struct stat fileinfo; - queue_info_map *ptr = NULL; - int n = 0; - int c = 0; - int i = 0; - int ret = 0; - char abs_filename[MAX_PKG_NAME_LEN] = {'\0'}; - char buf[MAX_PKG_NAME_LEN] = {'\0'}; - n = scandir(BACKEND_INFO_DIR, &namelist, NULL, alphasort); - if (n < 0) { - perror("scandir"); - return -1; - } - i = n; - /*Find number of backends (symlinks + executables) - The /usr/etc/package-manager/backend dir should not conatin - any other file except the backends.*/ - while(n--) - { - if(!strcmp(namelist[n]->d_name, ".") || - !strcmp(namelist[n]->d_name, "..")) - continue; - snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s", - BACKEND_INFO_DIR, namelist[n]->d_name); - if (lstat(abs_filename, &fileinfo)) { - perror("lstat"); - continue; - } - if (S_ISDIR(fileinfo.st_mode)) - continue; - c++; - memset(abs_filename, 0x00, MAX_PKG_NAME_LEN); - } - /*Add entries to info map.*/ - ptr = (queue_info_map*)calloc(c , sizeof(queue_info_map)); - memset(ptr, '\0', c * sizeof(queue_info_map)); - start = ptr; - for(n = 0; n < c ; n++) - { - ptr->backend[0] = '\0'; - ptr->head = NULL; - ptr->queue_slot = -2;/*-1 can be error return*/ - ptr->pkgtype[0] = '\0'; - ptr++; - } - n = i; - ptr = start; - while(n--) - { - if(!strcmp(namelist[n]->d_name, ".") || - !strcmp(namelist[n]->d_name, "..")) - continue; - snprintf(abs_filename, MAX_PKG_NAME_LEN, "%s/%s", - BACKEND_INFO_DIR, namelist[n]->d_name); - if (lstat(abs_filename, &fileinfo) < 0) { - perror(abs_filename); - return -1; - } - if (S_ISDIR(fileinfo.st_mode)) - continue; - /*Found backend*/ - if (S_ISLNK(fileinfo.st_mode)) { - /*found a symlink*/ - ret = readlink(abs_filename, buf, MAX_PKG_NAME_LEN - 1); - if (ret == -1) { - perror("readlink"); - return -1; - } - buf[ret] = '\0'; - } - /*executable*/ - else { - snprintf(buf, sizeof(buf), "%s", abs_filename); - } - ret = __entry_exist(buf); - if (ret == -1) { - snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf); - snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name); - ptr->queue_slot = slot; - ptr->head = NULL; - entries++; - slot++; - ptr++; - } - else { - snprintf(ptr->backend, sizeof(ptr->backend), "%s", buf); - snprintf(ptr->pkgtype, sizeof(ptr->pkgtype), "%s", namelist[n]->d_name); - ptr->queue_slot = ret; - ptr->head = NULL; - entries++; - ptr++; - } - free(namelist[n]); - memset(buf, 0x00, MAX_PKG_NAME_LEN); - continue; - } - free(namelist); - num_of_backends = slot; - -#ifdef DEBUG_INFO - /*Debug info*/ - DBG("Queue Info Map"); - DBG("Number of Backends is %d", num_of_backends); - DBG("Number of Entries is %d", entries); - DBG("Backend\tType\tSlot\tHead"); - ptr = start; - for(n = 0; n < entries; n++) - { - DBG("%s\t%s\t%d\t%p", ptr->backend, ptr->pkgtype, ptr->queue_slot, ptr->head); - ptr++; - } -#endif - - return 0; -} - -int _pm_queue_push(uid_t uid, const char *req_id, int req_type, - const char *pkg_type, const char *pkgid, const char *args) -{ - pm_queue_data *data = NULL; - pm_queue_data *cur = NULL; - pm_queue_data *tmp = NULL; - int ret = 0; - ret = __is_pkg_supported(pkg_type); - if (ret == 0) - return -1; - - cur = __get_head_from_pkgtype(pkg_type); - tmp = cur; - - /* TODO: use glist */ - data = _add_node(); - if (!data) { /* fail to allocate mem */ - ERR("Fail to allocate memory\n"); - return -1; - } - - snprintf(data->msg->req_id, sizeof(data->msg->req_id), "%s", req_id); - data->msg->req_type = req_type; - data->msg->uid = uid; - snprintf(data->msg->pkg_type, sizeof(data->msg->pkg_type), "%s", pkg_type); - snprintf(data->msg->pkgid, sizeof(data->msg->pkgid), "%s", pkgid); - snprintf(data->msg->args, sizeof(data->msg->args), "%s", args); - - data->next = NULL; - - if (cur == NULL) { - /* first push */ - cur = data; - __update_head_from_pkgtype(data); - } - else { - while (tmp->next) - tmp = tmp->next; - - tmp->next = data; - } - return 0; -} - -/*pop request from queue slot "position" */ -pm_dbus_msg *_pm_queue_pop(int position) -{ - pm_dbus_msg *ret; - pm_queue_data *cur = NULL; - pm_queue_data *saveptr = NULL; - queue_info_map *ptr = NULL; - int i = 0; - - ret = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg)); - if (!ret) { - ERR("Mem alloc error"); - return NULL; - } - memset(ret, 0x00, sizeof(pm_dbus_msg)); - ptr = start; - for(i = 0; i < entries; i++) - { - if (ptr->queue_slot == position) { - cur = ptr->head; - break; - } - ptr++; - } - - if (!cur) { /* queue is empty */ - ret->req_type = -1; - return ret; - } - - snprintf(ret->req_id, sizeof(ret->req_id), "%s", cur->msg->req_id); - ret->req_type = cur->msg->req_type; - ret->uid = cur->msg->uid; - snprintf(ret->pkg_type, sizeof(ret->pkg_type), "%s", cur->msg->pkg_type); - snprintf(ret->pkgid, sizeof(ret->pkgid), "%s", cur->msg->pkgid); - snprintf(ret->args, sizeof(ret->args), "%s", cur->msg->args); - - ptr->head = cur->next; - saveptr = ptr->head; - cur->next = NULL; - free(cur->msg); - free(cur); - /*update head for each duplicate queue entry*/ - ptr = start; - for(i = 0; i < entries; i++) - { - if(ptr->queue_slot == position) { - ptr->head = saveptr; - } - ptr++; - } - return ret; -} - -/*populate an array of all queue heads and delete them one by one*/ -void _pm_queue_final() -{ - int c = 0; - int i = 0; - int slot = -1; - pm_queue_data *cur = NULL; - pm_queue_data *tail = NULL; - pm_queue_data *prev = NULL; - pm_queue_data *head[MAX_QUEUE_NUM] = {NULL,}; - queue_info_map *ptr = NULL; - ptr = start; - - for(i = 0; i < num_of_backends; i++) - { - head[i] = NULL; - } - - for(i = 0; i < entries; i++) - { - if (ptr->queue_slot <= slot) { - ptr++; - continue; - } - else { - head[c] = ptr->head; - slot = ptr->queue_slot; - c++; - ptr++; - } - } - - c = 0; - while(c < num_of_backends) { - if (!head[c]) { /* in case of head is NULL */ - ERR("queue is NULL"); - c = c + 1; - continue; - } - - while (head[c]->next) { - cur = head[c]->next; - - while (cur->next) { - prev = cur; - cur = cur->next; - } - - tail = cur; - - free(tail->msg); - free(tail); - prev->next = NULL; - } - - free(head[c]->msg); - free(head[c]); - - head[c] = NULL; - c = c + 1; - } - /*Free the info map*/ - if (start) { - free(start); - start = NULL; - } -} - -pm_queue_data *_add_node() -{ - pm_queue_data *newnode = NULL; - - newnode = (pm_queue_data *) malloc(sizeof(pm_queue_data)); - if (!newnode) { /* if NULL */ - ERR("Mem alloc error"); - return NULL; - } - memset(newnode, 0x00, sizeof(pm_queue_data)); - - newnode->msg = (pm_dbus_msg *) malloc(sizeof(pm_dbus_msg)); - if (!newnode->msg) { - ERR("Mem alloc error"); - free(newnode); - return NULL; - } - memset(newnode->msg, 0x00, sizeof(pm_dbus_msg)); - - return newnode; -} - -void _pm_queue_delete(pm_dbus_msg *item) -{ - /* Assume that pacakge name is unique */ - pm_queue_data *cur = NULL; - pm_queue_data *prev = NULL; - cur = __get_head_from_pkgtype(item->pkg_type); - prev = cur; - if (cur) { - while (cur->next) { - if (!strcmp(item->pkgid, cur->msg->pkgid)) { - prev->next = cur->next; - free(cur->msg); - free(cur); - break; - } - prev = cur; - cur = cur->next; - } - } -} - -void _save_queue_status(pm_dbus_msg *item, char *status) -{ - FILE *fp_status = NULL; - - fp_status = fopen(STATUS_FILE, "w"); /* overwrite always */ - if (!fp_status) { - ERR("Can't open status file:%s", STATUS_FILE); - return; - } - - fprintf(fp_status, "%s\n", status); - fprintf(fp_status, "%s\n", item->pkg_type); - - fsync(fileno(fp_status)); - - fclose(fp_status); -} - -void _print_queue(int position) -{ - pm_queue_data *cur = NULL; - queue_info_map *ptr = start; - int i = 0; - for(i =0; i < entries; i++) - { - if (ptr->queue_slot == position) { - cur = ptr->head; - break; - } - ptr++; - } - int index = 1; - if (!cur) { - return; - } - - while (cur) { - index++; - cur = cur->next; - } -} diff --git a/server/src/request.c b/server/src/request.c deleted file mode 100644 index 7b1d8d4..0000000 --- a/server/src/request.c +++ /dev/null @@ -1,563 +0,0 @@ -#include -#include - -#include -#include - -#include "comm_config.h" -#include "pm-queue.h" -#include "pkgmgr-server.h" -#include "package-manager.h" -#include "package-manager-debug.h" - -static const char instropection_xml[] = - "" - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - ""; -static GDBusNodeInfo *instropection_data; -static guint reg_id; -static guint owner_id; - -static char *__generate_reqkey(const char *pkgid) -{ - struct timeval tv; - long curtime; - char timestr[MAX_PKG_ARGS_LEN]; - char *str_req_key; - int size; - - gettimeofday(&tv, NULL); - curtime = tv.tv_sec * 1000000 + tv.tv_usec; - snprintf(timestr, sizeof(timestr), "%ld", curtime); - - size = strlen(pkgid) + strlen(timestr) + 2; - str_req_key = (char *)calloc(size, sizeof(char)); - if (str_req_key == NULL) { - DBG("calloc failed"); - return NULL; - } - snprintf(str_req_key, size, "%s_%s", pkgid, timestr); - - return str_req_key; -} - -static int __handle_request_install(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; - char *pkgpath = NULL; - char *reqkey; - - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgpath); - if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgpath == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ECOMM, "")); - return -1; - } - - reqkey = __generate_reqkey(pkgpath); - if (reqkey == NULL) - return -1; - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_INSTALL, pkgtype, - pkgpath, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); - free(reqkey); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - free(reqkey); - - return 0; -} - -static int __handle_request_reinstall(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; - char *pkgid = NULL; - char *reqkey; - - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ECOMM, "")); - return -1; - } - - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) - return -1; - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_REINSTALL, pkgtype, - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); - free(reqkey); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - free(reqkey); - - return 0; -} - -static int __handle_request_uninstall(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; - char *pkgid = NULL; - char *reqkey; - - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ECOMM, "")); - return -1; - } - - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) - return -1; - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_UNINSTALL, pkgtype, - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); - free(reqkey); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - free(reqkey); - - return 0; -} - -static int __handle_request_move(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; - char *pkgid = NULL; - char *reqkey; - - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ECOMM, "")); - return -1; - } - - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) - return -1; - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_MOVE, pkgtype, - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); - free(reqkey); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - free(reqkey); - - return 0; -} - -static int __handle_request_enable(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgid = NULL; - - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); - return -1; - } - - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_ENABLE, "pkg", - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); - - return 0; -} - -static int __handle_request_disable(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgid = NULL; - - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); - return -1; - } - - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_DISABLE, "pkg", - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); - - return 0; -} - -static int __handle_request_getsize(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgid = NULL; - int get_type = -1; - char *reqkey; - char buf[4]; - - g_variant_get(parameters, "(u&si)", &target_uid, &pkgid, &get_type); - if (target_uid == (uid_t)-1 || pkgid == NULL || get_type == -1) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ECOMM, "")); - return -1; - } - - reqkey = __generate_reqkey(pkgid); - if (reqkey == NULL) - return -1; - - snprintf(buf, sizeof(buf), "%d", get_type); - if (_pm_queue_push(target_uid, reqkey, PKGMGR_REQUEST_TYPE_GETSIZE, "getsize", - pkgid, buf)) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_ESYSTEM, "")); - free(reqkey); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(is)", PKGMGR_R_OK, reqkey)); - free(reqkey); - - return 0; -} - -static int __handle_request_cleardata(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgtype = NULL; - char *pkgid = NULL; - - g_variant_get(parameters, "(u&s&s)", &target_uid, &pkgtype, &pkgid); - if (target_uid == (uid_t)-1 || pkgtype == NULL || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); - return -1; - } - - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARDATA, pkgtype, - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); - - return 0; -} - -static int __handle_request_clearcache(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgid = NULL; - - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); - return -1; - } - - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CLEARCACHE, - "clearcache", pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); - - return 0; -} - -static int __handle_request_kill(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgid = NULL; - - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); - return -1; - } - - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_KILL, "pkg", - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); - - return 0; -} - -static int __handle_request_check(uid_t uid, - GDBusMethodInvocation *invocation, GVariant *parameters) -{ - uid_t target_uid = (uid_t)-1; - char *pkgid = NULL; - - g_variant_get(parameters, "(u&s)", &target_uid, &pkgid); - if (target_uid == (uid_t)-1 || pkgid == NULL) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ECOMM)); - return -1; - } - - if (_pm_queue_push(target_uid, "", PKGMGR_REQUEST_TYPE_CHECK, "pkg", - pkgid, "")) { - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_ESYSTEM)); - return -1; - } - - g_dbus_method_invocation_return_value(invocation, - g_variant_new("(i)", PKGMGR_R_OK)); - - return 0; -} - -static uid_t __get_caller_uid(GDBusConnection *connection, const char *name) -{ - GError *err = NULL; - GVariant *result; - uid_t uid; - - result = g_dbus_connection_call_sync(connection, - "org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "GetConnectionUnixUser", - g_variant_new("(s)", name), NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); - if (result == NULL) { - ERR("failed to get caller uid: %s", err->message); - g_error_free(err); - return (uid_t)-1; - } - - g_variant_get(result, "(u)", &uid); - - return uid; -} - -static void __handle_method_call(GDBusConnection *connection, - const gchar *sender, const gchar *object_path, - const gchar *interface_name, const gchar *method_name, - GVariant *parameters, GDBusMethodInvocation *invocation, - gpointer user_data) -{ - int ret; - uid_t uid; - - uid = __get_caller_uid(connection, - g_dbus_method_invocation_get_sender(invocation)); - if (uid == (uid_t)-1) - return; - - if (g_strcmp0(method_name, "install") == 0) - ret = __handle_request_install(uid, invocation, parameters); - else if (g_strcmp0(method_name, "reinstall") == 0) - ret = __handle_request_reinstall(uid, invocation, parameters); - else if (g_strcmp0(method_name, "uninstall") == 0) - ret = __handle_request_uninstall(uid, invocation, parameters); - else if (g_strcmp0(method_name, "cleardata") == 0) - ret = __handle_request_cleardata(uid, invocation, parameters); - else if (g_strcmp0(method_name, "move") == 0) - ret = __handle_request_move(uid, invocation, parameters); - else if (g_strcmp0(method_name, "enable") == 0) - ret = __handle_request_enable(uid, invocation, parameters); - else if (g_strcmp0(method_name, "disable") == 0) - ret = __handle_request_disable(uid, invocation, parameters); - else if (g_strcmp0(method_name, "getsize") == 0) - ret = __handle_request_getsize(uid, invocation, parameters); - else if (g_strcmp0(method_name, "clearcache") == 0) - ret = __handle_request_clearcache(uid, invocation, parameters); - else if (g_strcmp0(method_name, "kill") == 0) - ret = __handle_request_kill(uid, invocation, parameters); - else if (g_strcmp0(method_name, "check") == 0) - ret = __handle_request_check(uid, invocation, parameters); - else - ret = -1; - - if (ret == 0) - g_idle_add(queue_job, NULL); -} - -static const GDBusInterfaceVTable interface_vtable = -{ - __handle_method_call, - NULL, - NULL, -}; - -static void __on_bus_acquired(GDBusConnection *connection, const gchar *name, - gpointer user_data) -{ - GError *err = NULL; - - DBG("on bus acquired"); - - reg_id = g_dbus_connection_register_object(connection, - COMM_PKGMGR_DBUS_OBJECT_PATH, - instropection_data->interfaces[0], - &interface_vtable, NULL, NULL, &err); - - if (reg_id == 0) { - ERR("failed to register object: %s", err->message); - g_error_free(err); - } -} - -static void __on_name_acquired(GDBusConnection *connection, const gchar *name, - gpointer user_data) -{ - DBG("on name acquired: %s", name); -} - -static void __on_name_lost(GDBusConnection *connection, const gchar *name, - gpointer user_data) -{ - DBG("on name lost: %s", name); -} - -int __init_request_handler(void) -{ - instropection_data = g_dbus_node_info_new_for_xml(instropection_xml, NULL); - - owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, COMM_PKGMGR_DBUS_SERVICE, - G_BUS_NAME_OWNER_FLAGS_NONE, __on_bus_acquired, - __on_name_acquired, __on_name_lost, NULL, NULL); - - return 0; -} - -void __fini_request_handler(void) -{ - g_bus_unown_name(owner_id); - g_dbus_node_info_unref(instropection_data); -} diff --git a/tool/10_package-manager-add.post b/tool/10_package-manager-add.post deleted file mode 100644 index 337a4c9..0000000 --- a/tool/10_package-manager-add.post +++ /dev/null @@ -1 +0,0 @@ -pkg_initdb $2 diff --git a/tool/CMakeLists.txt b/tool/CMakeLists.txt deleted file mode 100644 index f839ebf..0000000 --- a/tool/CMakeLists.txt +++ /dev/null @@ -1,59 +0,0 @@ -# Test executables -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_CFLAGS}") - -#Verbose -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include) - -INCLUDE(FindPkgConfig) - -pkg_check_modules(pkgs_initdb REQUIRED libsmack libxml-2.0 bundle pkgmgr-parser pkgmgr-info libtzplatform-config) -FOREACH(flag ${pkgs_initdb_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -pkg_check_modules(pkgs_test REQUIRED dlog glib-2.0 libxml-2.0 bundle pkgmgr-parser pkgmgr-info libtzplatform-config security-manager) -FOREACH(flag ${pkgs_test_CFLAGS}) - SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") -ENDFOREACH(flag) - -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wl,-zdefs" ) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") -SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") -SET(CMAKE_C_FLAGS_RELEASE "-O2") - -ADD_EXECUTABLE(pkgcmd pkg_cmd.c) -TARGET_LINK_LIBRARIES(pkgcmd pkgmgr-client ${pkgs_test_LDFLAGS}) -INSTALL(TARGETS pkgcmd DESTINATION bin) - -ADD_EXECUTABLE(pkginfo pkg_info.c) -TARGET_LINK_LIBRARIES(pkginfo pkgmgr-client pkgmgr_installer ${pkgs_test_LDFLAGS}) -INSTALL(TARGETS pkginfo DESTINATION bin) - -ADD_EXECUTABLE(pkg_privilege pkg_privilege.c) -TARGET_LINK_LIBRARIES(pkg_privilege ${pkgs_test_LDFLAGS}) -INSTALL(TARGETS pkg_privilege DESTINATION bin) - -ADD_EXECUTABLE(pkg_install_ug pkg_install_ug.c) -TARGET_LINK_LIBRARIES(pkg_install_ug ${pkgs_test_LDFLAGS}) -INSTALL(TARGETS pkg_install_ug DESTINATION bin) - -ADD_EXECUTABLE(pkg_getsize pkg_getsize.c) -TARGET_LINK_LIBRARIES(pkg_getsize pkgmgr-client pkgmgr_installer ${pkgs_test_LDFLAGS}) -INSTALL(TARGETS pkg_getsize DESTINATION bin) - -ADD_EXECUTABLE(pkg_clearcache pkg_clearcache.c) -TARGET_LINK_LIBRARIES(pkg_clearcache ${pkgs_test_LDFLAGS}) -INSTALL(TARGETS pkg_clearcache DESTINATION bin) - -ADD_EXECUTABLE(pkg_initdb pkg_initdb.c) -TARGET_LINK_LIBRARIES(pkg_initdb ${pkgs_initdb_LDFLAGS}) -INSTALL(TARGETS pkg_initdb DESTINATION bin) -INSTALL(FILES 10_package-manager-add.post DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d/) - -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mime.wac.xml DESTINATION /usr/share/mime/packages/) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/mime.tpk.xml DESTINATION /usr/share/mime/packages/) - -CONFIGURE_FILE(pkgmgr.patch.sh.in pkgmgr.patch.sh @ONLY) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/pkgmgr.patch.sh DESTINATION ${SYSCONFDIR}/opt/upgrade/) diff --git a/tool/mime.tpk.xml b/tool/mime.tpk.xml deleted file mode 100644 index 3aedf49..0000000 --- a/tool/mime.tpk.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - Tizen Package - TPK - Tizen PacKage - - - diff --git a/tool/mime.wac.xml b/tool/mime.wac.xml deleted file mode 100644 index 099c661..0000000 --- a/tool/mime.wac.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - WAC Widget - WAC 위젯 - WGT - wac WidGeT - - - - diff --git a/tool/pkg_clearcache.c b/tool/pkg_clearcache.c deleted file mode 100644 index 9a20dd9..0000000 --- a/tool/pkg_clearcache.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#define MAX_PKG_NAME_LEN 256 -#define INTERNAL_CACHE_PATH_PREFIX tzplatform_getenv(TZ_USER_APP) -#define CACHE_PATH_POSTFIX "/cache" -#define SHARED_PATH_POSTFIX "/shared/cache" - - -#undef LOG_TAG -#ifndef LOG_TAG -#define LOG_TAG "PKGMGR_CLEARCACHE" -#endif /* LOG_TAG */ - -static int __clear_dir(const char *dirname) -{ - int ret = 0; - DIR *dp = NULL; - struct dirent *ep = NULL; - char *abs_filename = NULL; - struct stat stFileInfo; - - LOGD("Cache directory name to clear [%s]\n", dirname); - - abs_filename = (char *)malloc(sizeof(char) * PATH_MAX); - if (abs_filename == NULL) { - LOGE("Memory allocation failed\n"); - goto err; - } - - dp = opendir(dirname); - if (dp != NULL) { - while ((ep = readdir(dp))) { - snprintf(abs_filename, PATH_MAX - 1, "%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 = __clear_dir(abs_filename); - if (ret != 0) { - LOGE("Couldn't remove the directory. errno : %d (%s)\n", errno, strerror(errno)); - } - - ret = remove(abs_filename); - if (ret != 0) { - LOGE("Couldn't remove the directory. errno : %d (%s)\n", errno, strerror(errno)); - goto err; - } - } - } else { - ret = remove(abs_filename); - if (ret != 0) { - LOGE("Couldn't remove the directory. errno : %d (%s)\n", errno, strerror(errno)); - goto err; - } - } - } - (void)closedir(dp); - } else { - LOGE("Couldn't open the directory. errno : %d (%s)\n", errno, strerror(errno)); - goto err; - } - - free(abs_filename); - return 0; - -err: - if (abs_filename) { - free(abs_filename); - } - if(dp){ - (void)closedir(dp); - dp = NULL; - } - return -1; -} - -static int __clear_cache_dir(const char *pkgid) -{ - int ret = 0; - char dirname[PATH_MAX] = {0,}; - - if(pkgid == NULL) { - LOGE("pkgid is NULL\n"); - return -1; - } - - // cache internal - snprintf(dirname, sizeof(dirname), "%s/%s%s", - INTERNAL_CACHE_PATH_PREFIX, pkgid, CACHE_PATH_POSTFIX); - - ret = __clear_dir(dirname); - if (ret < 0) { - LOGE("Failed to clear internal cache dir."); - } - - // shared/cache internal - snprintf(dirname, sizeof(dirname), "%s/%s%s", - INTERNAL_CACHE_PATH_PREFIX, pkgid, SHARED_PATH_POSTFIX); - - ret = __clear_dir(dirname); - if (ret < 0) { - LOGE("Failed to clear external shared cache dir."); - } - - return 0; -} - -static int __clear_all_cache_dir_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data) -{ - int res = 0; - char *pkgid; - int *err_cnt = (int *)user_data; - - res = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if(res != PMINFO_R_OK) { - LOGE("pkgmgr_pkginfo_get_pkgid() failed"); - --(*err_cnt); - return 0; - } - - res = __clear_cache_dir(pkgid); - if (res != 0) - { // error flag - LOGE("Failed to clear cache dir of %s", pkgid); - --(*err_cnt); - return 0; - } - - return 0; -} - -static int __clear_all_cache_dir(void) -{ - int err_cnt = 0; - - int res = pkgmgrinfo_pkginfo_get_usr_list(__clear_all_cache_dir_cb, &err_cnt, getuid()); - if (res != PMINFO_R_OK) - { - LOGE("Failed to get pkg list. (%d)", res); - return -1; - } - else if (err_cnt != 0) - { - LOGE("Error occured in %d packages.", err_cnt); - return -1; - } - - return 0; -} - -int main(int argc, char *argv[]) -{ - int ret = 0; - - if(argv[0] == NULL) { - LOGE("pkgid is NULL\n"); - return -1; - } - - char pkgid[MAX_PKG_NAME_LEN]={0}; - - snprintf(pkgid,MAX_PKG_NAME_LEN,"%s",argv[0]); - - if (strcmp(pkgid, PKG_CLEAR_ALL_CACHE) == 0) - { // clear all - ret = __clear_all_cache_dir(); - } - else - { - ret = __clear_cache_dir(pkgid); - } - - - return ret; -} diff --git a/tool/pkg_cmd.c b/tool/pkg_cmd.c deleted file mode 100644 index 4757e52..0000000 --- a/tool/pkg_cmd.c +++ /dev/null @@ -1,985 +0,0 @@ - -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -/* For multi-user support */ -#include - -#include "package-manager.h" -#include "package-manager-types.h" - -#define PKG_TOOL_VERSION "0.1" -#define APP_INSTALLATION_PATH_RW tzplatform_getenv(TZ_USER_APP) -#define MAX_QUERY_LEN 4096 - -#define OWNER_ROOT 0 -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) - -static int __process_request(uid_t uid); -static void __print_usage(); -static int __is_app_installed(char *pkgid, uid_t uid); -static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type, - const char *pkgid, const char *key, const char *val, - const void *pmsg, void *data); -static int __convert_to_absolute_path(char *path); - -/* Supported options */ -const char *short_options = "iurmcgCkaADL:lsd:p:t:n:T:S:Gqh"; -const struct option long_options[] = { - {"install", 0, NULL, 'i'}, - {"uninstall", 0, NULL, 'u'}, - {"reinstall", 0, NULL, 'r'}, - {"move", 0, NULL, 'm'}, - {"clear", 0, NULL, 'c'}, - {"getsize", 0, NULL, 'g'}, - {"activate", 0, NULL, 'A'}, - {"deactivate", 0, NULL, 'D'}, - {"activate with Label", 1, NULL, 'L'}, - {"check", 0, NULL, 'C'}, - {"kill", 0, NULL, 'k'}, - {"app-path", 0, NULL, 'a'}, - {"list", 0, NULL, 'l'}, - {"show", 0, NULL, 's'}, - {"descriptor", 1, NULL, 'd'}, - {"package-path", 1, NULL, 'p'}, - {"package-type", 1, NULL, 't'}, - {"package-name", 1, NULL, 'n'}, - {"move-type", 1, NULL, 'T'}, - {"getsize-type", 1, NULL, 'T'}, - {"csc", 1, NULL, 'S'}, - {"global", 0, NULL, 'G'}, - {"quiet", 0, NULL, 'q'}, - {"help", 0, NULL, 'h'}, - {0, 0, 0, 0} /* sentinel */ -}; - -enum pm_tool_request_e { - INSTALL_REQ = 1, - UNINSTALL_REQ, - REINSTALL_REQ, - CSC_REQ, - GETSIZE_REQ, - CLEAR_REQ, - MOVE_REQ, - ACTIVATE_REQ, - DEACTIVATE_REQ, - APPPATH_REQ, - CHECKAPP_REQ, - KILLAPP_REQ, - LIST_REQ, - SHOW_REQ, - HELP_REQ -}; -typedef enum pm_tool_request_e req_type; - -struct pm_tool_args_t { - req_type request; - char pkg_path[PKG_NAME_STRING_LEN_MAX]; - char pkg_type[PKG_TYPE_STRING_LEN_MAX]; - char pkgid[PKG_NAME_STRING_LEN_MAX]; - char des_path[PKG_NAME_STRING_LEN_MAX]; - char label[PKG_NAME_STRING_LEN_MAX]; - int global; - int type; - int result; -}; -typedef struct pm_tool_args_t pm_tool_args; -pm_tool_args data; - -static GMainLoop *main_loop = NULL; - -static void __error_no_to_string(int errnumber, char **errstr) -{ - if (errstr == NULL) - return; - switch (errnumber) { - case PKGCMD_ERR_PACKAGE_NOT_FOUND: - *errstr = PKGCMD_ERR_PACKAGE_NOT_FOUND_STR; - break; - case PKGCMD_ERR_PACKAGE_INVALID: - *errstr = PKGCMD_ERR_PACKAGE_INVALID_STR; - break; - case PKGCMD_ERR_PACKAGE_LOWER_VERSION: - *errstr = PKGCMD_ERR_PACKAGE_LOWER_VERSION_STR; - break; - case PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND: - *errstr = PKGCMD_ERR_PACKAGE_EXECUTABLE_NOT_FOUND_STR; - break; - case PKGCMD_ERR_MANIFEST_INVALID: - *errstr = PKGCMD_ERR_MANIFEST_INVALID_STR; - break; - case PKGCMD_ERR_CONFIG_NOT_FOUND: - *errstr = PKGCMD_ERR_CONFIG_NOT_FOUND_STR; - break; - case PKGCMD_ERR_CONFIG_INVALID: - *errstr = PKGCMD_ERR_CONFIG_INVALID_STR; - break; - case PKGCMD_ERR_SIGNATURE_NOT_FOUND: - *errstr = PKGCMD_ERR_SIGNATURE_NOT_FOUND_STR; - break; - case PKGCMD_ERR_SIGNATURE_INVALID: - *errstr = PKGCMD_ERR_SIGNATURE_INVALID_STR; - break; - case PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED: - *errstr = PKGCMD_ERR_SIGNATURE_VERIFICATION_FAILED_STR; - break; - case PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND: - *errstr = PKGCMD_ERR_ROOT_CERTIFICATE_NOT_FOUND_STR; - break; - case PKGCMD_ERR_CERTIFICATE_INVALID: - *errstr = PKGCMD_ERR_CERTIFICATE_INVALID_STR; - break; - case PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED: - *errstr = PKGCMD_ERR_CERTIFICATE_CHAIN_VERIFICATION_FAILED_STR; - break; - case PKGCMD_ERR_CERTIFICATE_EXPIRED: - *errstr = PKGCMD_ERR_CERTIFICATE_EXPIRED_STR; - break; - case PKGCMD_ERR_INVALID_PRIVILEGE: - *errstr = PKGCMD_ERR_INVALID_PRIVILEGE_STR; - break; - case PKGCMD_ERR_MENU_ICON_NOT_FOUND: - *errstr = PKGCMD_ERR_MENU_ICON_NOT_FOUND_STR; - break; - case PKGCMD_ERR_FATAL_ERROR: - *errstr = PKGCMD_ERR_FATAL_ERROR_STR; - break; - case PKGCMD_ERR_OUT_OF_STORAGE: - *errstr = PKGCMD_ERR_OUT_OF_STORAGE_STR; - break; - case PKGCMD_ERR_OUT_OF_MEMORY: - *errstr = PKGCMD_ERR_OUT_OF_MEMORY_STR; - break; - case PKGCMD_ERR_ARGUMENT_INVALID: - *errstr = PKGCMD_ERR_ARGUMENT_INVALID_STR; - break; - default: - *errstr = PKGCMD_ERR_UNKNOWN_STR; - break; - } -} - -static int __return_cb(uid_t target_uid, int req_id, const char *pkg_type, - const char *pkgid, const char *key, const char *val, - const void *pmsg, void *priv_data) -{ - int ret_val; - char delims[] = ":"; - char *extra_str = NULL; - char *ret_result = NULL; - - if (strncmp(key, "error", strlen("error")) == 0) { - ret_val = atoi(val); - data.result = ret_val; - - ret_result = strstr((char *)val, delims); - if (ret_result){ - extra_str = strdup(ret_result); - printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d] error message: %s\n", - req_id, pkg_type, pkgid, key, ret_val, extra_str); - free(extra_str); - } - else - printf("__return_cb req_id[%d] pkg_type[%s] pkgid[%s] key[%s] val[%d]\n", - req_id, pkg_type, pkgid, key, ret_val); - } else - printf("__return_cb req_id[%d] pkg_type[%s] " - "pkgid[%s] key[%s] val[%s]\n", - req_id, pkg_type, pkgid, key, val); - - if (strncmp(key, "end", strlen("end")) == 0) { - if ((strncmp(val, "fail", strlen("fail")) == 0) && data.result == 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - } - g_main_loop_quit(main_loop); - } - - return 0; -} - -static int __convert_to_absolute_path(char *path) -{ - char abs[PKG_NAME_STRING_LEN_MAX] = {'\0'}; - char temp[PKG_NAME_STRING_LEN_MAX] = {'\0'}; - char *ptr = NULL; - if (path == NULL) { - printf("path is NULL\n"); - return -1; - } - strncpy(temp, path, PKG_NAME_STRING_LEN_MAX - 1); - if (strchr(path, '/') == NULL) { - if (getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1) == NULL) { - printf("getcwd() failed\n"); - return -1; - } - memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX); - snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, temp); - return 0; - } - if (strncmp(path, "./", 2) == 0) { - ptr = temp; - if (getcwd(abs, PKG_NAME_STRING_LEN_MAX - 1) == NULL) { - printf("getcwd() failed\n"); - return -1; - } - ptr = ptr + 2; - memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX); - snprintf(data.pkg_path, PKG_NAME_STRING_LEN_MAX - 1, "%s/%s", abs, ptr); - return 0; - } - return 0; -} - -static int __is_app_installed(char *pkgid, uid_t uid) -{ - pkgmgrinfo_pkginfo_h handle; - int ret; - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); - else - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - - if(ret < 0) { - printf("package is not in pkgmgr_info DB\n"); - return -1; - } else - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - - return 0; -} - -static void __print_usage() -{ - printf("\nPackage Manager Tool Version: %s\n\n", PKG_TOOL_VERSION); - printf("-i, --install install the package\n"); - printf("-u, --uninstall uninstall the package\n"); - printf("-r, --reinstall reinstall the package\n"); - printf("-c, --clear clear user data\n"); - printf("-m, --move move package\n"); - printf("-g, --getsize get size of given package\n"); - printf("-T, --getsize-type get type [0 : total size /1: data size]\n"); - printf("-l, --list display list of installed packages available for the current user [i.e. User's specific Apps and Global Apps] \n"); - printf("-s, --show show detail package info\n"); - printf("-a, --app-path show app installation path\n"); - printf("-C, --check check if applications belonging to a package are running or not\n"); - printf("-k, --kill terminate applications belonging to a package\n"); - printf("-d, --descriptor provide descriptor path\n"); - printf("-p, --package-path provide package path\n"); - printf("-n, --package-name provide package name\n"); - printf("-t, --package-type provide package type\n"); - printf("-T, --move-type provide move type [0 : move to internal /1: move to external]\n"); - printf("-G, --global Global Mode [Warning user should be privilegied to use this mode] \n"); - printf("-h, --help . print this help\n\n"); - - printf("Usage: pkgcmd [options]\n"); - printf("pkgcmd -i -t (-d ) -p (-G)\n"); - printf("pkgcmd -u -n (-G)\n"); - printf("pkgcmd -r -t -n (-G) \n"); - printf("pkgcmd -l (-t ) \n"); - printf("pkgcmd -s -t -p \n"); - printf("pkgcmd -s -t -n \n"); - printf("pkgcmd -m -t -T -n \n\n"); - printf("pkgcmd -g -T -n \n"); - printf("pkgcmd -C -n \n"); - printf("pkgcmd -k -n \n"); - - printf("Example:\n"); - printf("pkgcmd -u -n com.samsung.calculator\n"); - printf("pkgcmd -i -t rpm -p /mnt/nfs/com.samsung.calculator_0.1.2-95_armel.rpm\n"); - printf("pkgcmd -r -t rpm -n com.samsung.calculator\n"); - printf("pkgcmd -c -t rpm -n com.samsung.hello\n"); - printf("pkgcmd -m -t rpm -T 1 -n com.samsung.hello\n"); - printf("pkgcmd -C -n com.samsung.hello\n"); - printf("pkgcmd -k -n com.samsung.hello\n"); - printf("pkgcmd -a\n"); - printf("pkgcmd -a -t rpm -n com.samsung.hello\n"); - printf("pkgcmd -l\n"); - printf("pkgcmd -l -t tpk\n"); - printf("pkgcmd -g -T 0 -n com.samsung.calculator\n"); - - exit(0); - -} - -static int __pkgmgr_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) -{ - int ret = -1; - char *pkgid = NULL; - char *pkg_type = NULL; - char *pkg_version = NULL; - char *pkg_label = NULL; - bool for_all_users = 0; - - ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if (ret == -1) { - printf("Failed to get pkgmgrinfo_pkginfo_get_pkgid\n"); - return ret; - } - ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type); - if (ret == -1) { - printf("Failed to get pkgmgrinfo_pkginfo_get_type\n"); - return ret; - } - ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version); - if (ret == -1) { - printf("Failed to get pkgmgrinfo_pkginfo_get_version\n"); - return ret; - } - ret = pkgmgrinfo_pkginfo_get_label(handle, &pkg_label); - if (ret == -1) - pkg_label = "(null)"; - - ret = pkgmgrinfo_pkginfo_is_for_all_users(handle, &for_all_users); - if (ret == -1) { - printf("Failed to get pkgmgrinfo_pkginfo_is_for_all_users\n"); - return ret; - } - - printf("%s\tpkg_type [%s]\tpkgid [%s]\tname [%s]\tversion [%s]\n", for_all_users ? "system apps" : "user apps ", pkg_type, pkgid, pkg_label, pkg_version); - return ret; -} - -static int __pkg_list_cb(const pkgmgrinfo_pkginfo_h handle, void *user_data) -{ - int ret = -1; - char *pkgid; - pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle; - - ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if(ret < 0) { - printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n"); - } - if (uid_info->uid != GLOBAL_USER) - ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, uid_info->uid, NULL, NULL, NULL); - else - ret = pkgmgr_client_request_service(PM_REQUEST_GET_SIZE, PM_GET_TOTAL_SIZE, (pkgmgr_client *)user_data, NULL, pkgid, NULL, NULL, NULL); - if (ret < 0){ - printf("pkgmgr_client_request_service Failed\n"); - return -1; - } - - printf("pkg[%s] size = %d\n", pkgid, ret); - - return 0; -} - -static int __process_request(uid_t uid) -{ - int ret = -1; - pkgmgr_client *pc = NULL; - char buf[1024] = {'\0'}; - int pid = -1; -#if !GLIB_CHECK_VERSION(2,35,0) - g_type_init(); -#endif - switch (data.request) { - case INSTALL_REQ: - if (data.pkg_type[0] == '\0' || data.pkg_path[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - data.result = PKGCMD_ERR_ARGUMENT_INVALID; - break; - } - main_loop = g_main_loop_new(NULL, FALSE); - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - if (data.des_path[0] == '\0') - { - ret = - pkgmgr_client_usr_install(pc, data.pkg_type, NULL, - data.pkg_path, NULL, PM_QUIET, - __return_cb, pc, uid); - }else{ - ret = - pkgmgr_client_usr_install(pc, data.pkg_type, - data.des_path, data.pkg_path, - NULL, PM_QUIET, __return_cb, pc, uid); - - } - if (ret < 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - if (access(data.pkg_path, F_OK) != 0) - data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND; - break; - } - g_main_loop_run(main_loop); - ret = data.result; - break; - - case UNINSTALL_REQ: - if (data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - data.result = PKGCMD_ERR_ARGUMENT_INVALID; - break; - } - main_loop = g_main_loop_new(NULL, FALSE); - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } -//if global - ret = __is_app_installed(data.pkgid, uid); - if (ret == -1) { - printf("package is not installed\n"); - break; - } - - ret = - pkgmgr_client_usr_uninstall(pc, data.pkg_type, data.pkgid, - PM_QUIET, __return_cb, NULL,uid); - if (ret < 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - if (access(data.pkg_path, F_OK) != 0) - data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND; - break; - } - g_main_loop_run(main_loop); - ret = data.result; - break; - - case REINSTALL_REQ: - if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - data.result = PKGCMD_ERR_ARGUMENT_INVALID; - break; - } - main_loop = g_main_loop_new(NULL, FALSE); - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - - ret = pkgmgr_client_usr_reinstall(pc, data.pkg_type, data.pkgid, NULL, PM_QUIET, __return_cb, pc, uid); - if (ret < 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - if (access(data.pkg_path, F_OK) != 0) - data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND; - break; - } - g_main_loop_run(main_loop); - ret = data.result; - break; - - case CLEAR_REQ: - if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - ret = -1; - break; - } - - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - ret = -1; - break; - } - ret = __is_app_installed(data.pkgid, uid); - if (ret == -1) { - printf("package is not installed\n"); - break; - } - ret = pkgmgr_client_usr_clear_user_data(pc, data.pkg_type, - data.pkgid, PM_QUIET, uid); - if (ret < 0) - break; - ret = data.result; - break; - - case ACTIVATE_REQ: - if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - ret = -1; - break; - } - - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - ret = -1; - break; - } - - if ( strcmp(data.pkg_type, "app") == 0 ) { - if (strlen(data.label) == 0) { - ret = pkgmgr_client_usr_activate_app(pc, data.pkgid, uid); - if (ret < 0) - break; - } else { - printf("label [%s]\n", data.label); - char *largv[3] = {NULL, }; - largv[0] = "-l"; - largv[1] = data.label; - ret = pkgmgr_client_usr_activate_appv(pc, data.pkgid, largv, uid); - if (ret < 0) - break; - } - } else { - ret = pkgmgr_client_usr_activate(pc, data.pkg_type, data.pkgid, uid); - if (ret < 0) - break; - } - ret = data.result; - - break; - - - case DEACTIVATE_REQ: - if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - ret = -1; - break; - } - - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - ret = -1; - break; - } - - if ( strcmp(data.pkg_type, "app") == 0 ) { - ret = pkgmgr_client_usr_deactivate_app(pc, data.pkgid, uid); - if (ret < 0) - break; - }else { - ret = pkgmgr_client_usr_deactivate(pc, data.pkg_type, data.pkgid, uid); - if (ret < 0) - break; - } - ret = data.result; - - break; - - case MOVE_REQ: - if (data.pkg_type[0] == '\0' || data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - ret = -1; - break; - } - if (data.type < 0 || data.type > 1) { - printf("Invalid move type...See usage\n"); - ret = -1; - break; - } - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - ret = -1; - break; - } - ret = __is_app_installed(data.pkgid, uid); - if (ret == -1) { - printf("package is not installed\n"); - break; - } - ret = pkgmgr_client_usr_request_service(PM_REQUEST_MOVE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL); - - printf("pkg[%s] move result = %d\n", data.pkgid, ret); - - if (ret < 0) - break; - ret = data.result; - break; - - case APPPATH_REQ: - if (data.pkg_type[0] == '\0' && data.pkgid[0] == '\0') { - printf("Tizen Application Installation Path: %s\n", APP_INSTALLATION_PATH_RW); - ret = 0; - break; - } - if ((data.pkg_type[0] == '\0') || (data.pkgid[0] == '\0')) { - printf("Use -h option to see usage\n"); - ret = -1; - break; - } - if (strncmp(data.pkg_type, "rpm", PKG_TYPE_STRING_LEN_MAX - 1) == 0) { - snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid); - printf("Tizen Application Installation Path: %s\n", buf); - ret = 0; - break; - } else if (strncmp(data.pkg_type, "wgt", PKG_TYPE_STRING_LEN_MAX - 1) == 0) { - snprintf(buf, 1023, "%s/%s/res/wgt", APP_INSTALLATION_PATH_RW, data.pkgid); - printf("Tizen Application Installation Path: %s\n", buf); - ret = 0; - break; - } else if (strncmp(data.pkg_type, "tpk", PKG_TYPE_STRING_LEN_MAX - 1) == 0) { - snprintf(buf, 1023, "%s/%s", APP_INSTALLATION_PATH_RW, data.pkgid); - printf("Tizen Application Installation Path: %s\n", buf); - ret = 0; - break; - } else { - printf("Invalid package type.\n"); - printf("use -h option to see usage\n"); - ret = -1; - break; - } - break; - - case KILLAPP_REQ: - case CHECKAPP_REQ: - if (data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - data.result = PKGCMD_ERR_ARGUMENT_INVALID; - break; - } - - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - - if (data.request == KILLAPP_REQ) { - ret = pkgmgr_client_usr_request_service(PM_REQUEST_KILL_APP, 0, pc, NULL, data.pkgid, uid, NULL, NULL, &pid); - if (ret < 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - if (pid) - printf("Pkgid: %s is Terminated\n", data.pkgid); - else - printf("Pkgid: %s is already Terminated\n", data.pkgid); - - } else if (data.request == CHECKAPP_REQ) { - ret = pkgmgr_client_usr_request_service(PM_REQUEST_CHECK_APP, 0, pc, NULL, data.pkgid, uid, NULL, NULL, &pid); - if (ret < 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - - if (pid) - printf("Pkgid: %s is Running\n", data.pkgid); - else - printf("Pkgid: %s is Not Running\n", data.pkgid); - } - ret = data.result; - break; - - case LIST_REQ: - if (data.pkg_type[0] == '\0') { - ret = 0; - if (uid != GLOBAL_USER) { - ret = pkgmgrinfo_pkginfo_get_usr_list(__pkgmgr_list_cb, NULL, uid); - } else { - ret = pkgmgrinfo_pkginfo_get_list(__pkgmgr_list_cb, NULL); - } - if (ret == -1) - printf("no packages found\n"); - break; - } else { - pkgmgrinfo_pkginfo_filter_h handle; - ret = pkgmgrinfo_pkginfo_filter_create(&handle); - if (ret == -1) { - printf("Failed to get package filter handle\n"); - break; - } - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, PMINFO_PKGINFO_PROP_PACKAGE_TYPE, data.pkg_type); - if (ret == -1) { - printf("Failed to add package type filter\n"); - pkgmgrinfo_pkginfo_filter_destroy(handle); - break; - } - if (uid != GLOBAL_USER) { - ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL, uid); - } else { - ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkgmgr_list_cb, NULL); - } - if (ret != PMINFO_R_OK) - printf("no package filter list\n"); - pkgmgrinfo_pkginfo_filter_destroy(handle); - break; - } - - case SHOW_REQ: - /* unsupported */ - ret = -1; - break; - - case CSC_REQ: - ret = pkgmgr_client_usr_request_service(PM_REQUEST_CSC, 0, NULL, NULL, NULL, uid, data.des_path, NULL, (void *)data.pkg_path); - if (ret < 0) - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - - case GETSIZE_REQ: - if (data.pkgid[0] == '\0') { - printf("Please provide the arguments.\n"); - printf("use -h option to see usage\n"); - ret = -1; - break; - } - - pc = pkgmgr_client_new(PC_REQUEST); - if (pc == NULL) { - printf("PkgMgr Client Creation Failed\n"); - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - - if (data.type == 9) { - ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, (void *)pc, uid); - break; - } - ret = pkgmgr_client_usr_request_service(PM_REQUEST_GET_SIZE, data.type, pc, NULL, data.pkgid, uid, NULL, NULL, NULL); - if (ret < 0){ - data.result = PKGCMD_ERR_FATAL_ERROR; - break; - } - - printf("pkg[%s] size = %d\n", data.pkgid, ret); - ret = data.result; - break; - - case HELP_REQ: - __print_usage(); - ret = 0; - break; - - default: - printf("Wrong Request\n"); - ret = -1; - break; - } - - if (pc) { - pkgmgr_client_free(pc); - pc = NULL; - } - return ret; -} - -int main(int argc, char *argv[]) -{ - optind = 1; - int opt_idx = 0; - int c = -1; - int ret = -1; - char *errstr = NULL; - long starttime; - long endtime; - struct timeval tv; - - - if (argc == 1) - __print_usage(); - - gettimeofday(&tv, NULL); - starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; - - data.request = -1; - memset(data.des_path, '\0', PKG_NAME_STRING_LEN_MAX); - memset(data.pkg_path, '\0', PKG_NAME_STRING_LEN_MAX); - memset(data.pkgid, '\0', PKG_NAME_STRING_LEN_MAX); - memset(data.pkg_type, '\0', PKG_TYPE_STRING_LEN_MAX); - memset(data.label, '\0', PKG_TYPE_STRING_LEN_MAX); - data.global = 0; //By default pkg_cmd will manage for the current user - data.result = 0; - data.type = -1; - while (1) { - c = getopt_long(argc, argv, short_options, long_options, - &opt_idx); - if (c == -1) - break; /* Parse end */ - switch (c) { - case 'G': /* install */ - data.global = 1; - break; - - case 'i': /* install */ - data.request = INSTALL_REQ; - break; - - case 'u': /* uninstall */ - data.request = UNINSTALL_REQ; - break; - - case 'r': /* reinstall */ - data.request = REINSTALL_REQ; - break; - - case 'c': /* clear */ - data.request = CLEAR_REQ; - break; - - case 'g': /* get pkg size */ - data.request = GETSIZE_REQ; - break; - - case 'm': /* move */ - data.request = MOVE_REQ; - break; - - case 'S': /* csc packages */ - data.request = CSC_REQ; - if (optarg) - snprintf(data.des_path, sizeof(data.des_path), - "%s", optarg); - printf("csc file is %s\n", data.des_path); - break; - - case 'A': /* activate */ - data.request = ACTIVATE_REQ; - break; - - case 'D': /* deactivate */ - data.request = DEACTIVATE_REQ; - break; - - case 'L': /* activate with Label */ - data.request = ACTIVATE_REQ; - if (optarg) - snprintf(data.pkg_path, sizeof(data.pkg_path), - "%s", optarg); - break; - - case 'a': /* app installation path */ - data.request = APPPATH_REQ; - break; - - case 'k': /* Terminate applications of a package */ - data.request = KILLAPP_REQ; - break; - - case 'C': /* Check running status of applications of a package */ - data.request = CHECKAPP_REQ; - break; - - case 'l': /* list */ - data.request = LIST_REQ; - break; - - case 's': /* show */ - data.request = SHOW_REQ; - break; - - case 'p': /* package path */ - if (optarg) - snprintf(data.pkg_path, sizeof(data.pkg_path), - "%s", optarg); - ret = __convert_to_absolute_path(data.pkg_path); - if (ret == -1) { - printf("conversion of relative path to absolute path failed\n"); - return -1; - } - printf("path is %s\n", data.pkg_path); - break; - - case 'd': /* descriptor path */ - if (optarg) - snprintf(data.des_path, sizeof(data.des_path), - "%s", optarg); - break; - - case 'n': /* package name */ - if (optarg) - snprintf(data.pkgid, sizeof(data.pkgid), - "%s", optarg); - break; - - case 't': /* package type */ - if (optarg) - snprintf(data.pkg_type, sizeof(data.pkg_type), - "%s", optarg); - break; - - case 'T': /* move type */ - data.type = atoi(optarg); - break; - - case 'h': /* help */ - data.request = HELP_REQ; - break; - - case 'q': /* quiet mode is removed */ - break; - - /* Otherwise */ - case '?': /* Not an option */ - __print_usage(); - break; - - case ':': /* */ - break; - - default: - break; - - } - } - uid_t uid = getuid(); - if(uid == OWNER_ROOT) { - printf("Current User is Root! : Only regular users are allowed\n"); - return -1; - } - if(data.global == 1) { - uid = GLOBAL_USER; - } - ret = __process_request(uid); - if ((ret == -1) && (data.result != 0)) - data.result = PKGCMD_ERR_ARGUMENT_INVALID; - - if (ret != 0) { - __error_no_to_string(data.result, &errstr); - printf("processing result : %s [%d] failed\n", errstr, data.result); - } - - gettimeofday(&tv, NULL); - endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; - printf("spend time for pkgcmd is [%d]ms\n", (int)(endtime - starttime)); - - return data.result; -} diff --git a/tool/pkg_getsize.c b/tool/pkg_getsize.c deleted file mode 100644 index a9d8238..0000000 --- a/tool/pkg_getsize.c +++ /dev/null @@ -1,649 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include - -#include -#include -#include -#include - -#include -#include - -/* For multi-user support */ -#include - -#include "package-manager.h" -#include "package-manager-debug.h" -#include "pkgmgr_installer.h" -#include "comm_config.h" - -#undef LOG_TAG -#ifndef LOG_TAG -#define LOG_TAG "PKGMGR_GETSIZE" -#endif /* LOG_TAG */ - -#define MAX_PKG_BUF_LEN 1024 -#define BLOCK_SIZE 4096 /*in bytes*/ -#define MAX_PATH_LENGTH 512 -#define MAX_LONGLONG_LENGTH 32 -#define MAX_SIZE_INFO_SIZE 128 - -#define OWNER_ROOT 0 -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) - -#if 0 /* installed at external storage is not supported yet */ -#define APP_BASE_EXTERNAL_PATH "" -#endif - -typedef enum -{ - STORAGE_TYPE_INTERNAL, - STORAGE_TYPE_EXTERNAL, - STORAGE_TYPE_MAX = 255, -} STORAGE_TYPE; - -long long __stat_size(struct stat *s) -{ - long long blksize = s->st_blksize; - long long size = (long long)s->st_blocks * 512; - - if (blksize) { - size = (size + blksize - 1) & (~(blksize - 1)); - } - - return size; -} - -static long long __calculate_directory_size(int dfd, bool include_itself) -{ - long long size = 0; - struct stat st; - int subfd; - int ret; - DIR *dir; - struct dirent *dent; - const char *entry; - - if (include_itself) { - ret = fstat(dfd, &st); - if (ret < 0) { - ERR("fstat() failed, entry: ., errno: %d (%s)", errno, - strerror(errno)); - return -1; - } - size += __stat_size(&st); - } - - dir = fdopendir(dfd); - if (dir == NULL) { - ERR("fdopendir() failed, errno: %d (%s)", errno, - strerror(errno)); - return -1; - } - - while ((dent = readdir(dir))) { - entry = dent->d_name; - if (entry[0] == '.') { - if (entry[1] == '\0') - continue; - if ((entry[1] == '.') && (entry[2] == '\0')) - continue; - } - - if (dent->d_type == DT_DIR) { - subfd = openat(dfd, entry, O_RDONLY | O_DIRECTORY); - if (subfd < 0) { - ERR("openat() failed, entry:%s, errno: %d(%s)", - entry, errno, strerror(errno)); - goto error; - } - - DBG("traverse entry: %s", entry); - size += __calculate_directory_size(subfd, true); - close(subfd); - } else { - ret = fstatat(dfd, entry, &st, AT_SYMLINK_NOFOLLOW); - if (ret < 0) { - ERR("fstatat() failed, entry:%s, errno: %d(%s)", - entry, errno, strerror(errno)); - goto error; - } - size += __stat_size(&st); - } - } - - closedir(dir); - return size; - -error: - closedir(dir); - return -1; -} - -static long long __calculate_shared_dir_size(int dfd, const char *app_root_dir, - long long *data_size, long long *app_size) -{ - int fd = -1; - int subfd = -1; - long long size = 0; - struct stat st; - int ret; - - DBG("traverse path: %s/shared", app_root_dir); - - fd = openat(dfd, "shared", O_RDONLY | O_DIRECTORY); - if (fd < 0) { - ERR("openat() failed, path: %s/shared, errno: %d (%s)", - app_root_dir, errno, strerror(errno)); - return -1; - } - - ret = fstat(fd, &st); - if (ret < 0) { - ERR("fstat() failed, path: %s/shared, errno: %d (%s)", - app_root_dir, errno, strerror(errno)); - goto error; - } - *app_size += __stat_size(&st); // shared directory - DBG("app_size: %lld", *app_size); - - DBG("traverse path: %s/shared/data", app_root_dir); - - subfd = openat(fd, "data", O_RDONLY | O_DIRECTORY); - if (subfd >= 0) { - size = __calculate_directory_size(subfd, true); - if (size < 0) - { - ERR("Calculating shared/data directory failed."); - goto error; - } - *data_size += size; - DBG("data_size: %lld", *data_size); - close(subfd); - } else if (subfd < 0 && errno != ENOENT) { - ERR("openat() failed, entry: data, errno: %d (%s)", - errno, strerror(errno)); - goto error; - } - - DBG("traverse path: %s/shared/trusted", app_root_dir); - - subfd = openat(fd, "trusted", O_RDONLY | O_DIRECTORY); - if (subfd >= 0) { - size = __calculate_directory_size(subfd, true); - if (size < 0) { - ERR("Calculating shared/trusted directory failed."); - goto error; - } - *data_size += size; - DBG("data_size: %lld", *data_size); - close(subfd); - } else if (subfd < 0 && errno != ENOENT) { - DBG("openat() failed, entry: trusted, errno: %d (%s)", - errno, strerror(errno)); - goto error; - } - - DBG("traverse path: %s/shared/res", app_root_dir); - - subfd = openat(fd, "res", O_RDONLY | O_DIRECTORY); - if (subfd >= 0) { - size = __calculate_directory_size(subfd, true); - if (size < 0) { - ERR("Calculating shared/res directory failed."); - goto error; - } - *app_size += size; - DBG("app_size: %lld", *app_size); - close(subfd); - } else if (subfd < 0 && errno != ENOENT) { - ERR("openat() failed, entry: res, errno: %d (%s)", - errno, strerror(errno)); - goto error; - } - - DBG("traverse path: %s/shared/cache", app_root_dir); - - subfd = openat(fd, "cache", O_RDONLY | O_DIRECTORY); - if (subfd >= 0) { - size = __calculate_directory_size(subfd, true); - if (size < 0) { - ERR("Calculating shared/cache directory failed."); - goto error; - } - *data_size += size; - DBG("data_size: %lld", *data_size); - close(subfd); - } else if (subfd < 0 && errno != ENOENT) { - ERR("openat() failed, entry: data, errno: %d (%s)", - errno, strerror(errno)); - goto error; - } - - close(fd); - return 0; - -error: - if (fd != -1) - close(fd); - if (subfd != -1) - close(subfd); - - return -1; -} - -static int __is_global(uid_t uid) -{ - return (uid == OWNER_ROOT || uid == GLOBAL_USER) ? 1 : 0; -} - -static int __calculate_pkg_size_info(STORAGE_TYPE type, const char *pkgid, - long long *data_size, long long *cache_size, - long long *app_size) -{ - uid_t uid = getuid(); - char app_root_dir[MAX_PATH_LENGTH] = {0, }; - DIR *dir; - int dfd; - int subfd = -1; - struct stat st; - int ret; - struct dirent *ent; - long long size = 0; - - if (type == STORAGE_TYPE_INTERNAL) { - if (!__is_global(uid)) - tzplatform_set_user(uid); - snprintf(app_root_dir, sizeof(app_root_dir), "%s", - tzplatform_mkpath(__is_global(uid) - ? TZ_SYS_RW_APP : TZ_USER_APP, pkgid)); - tzplatform_reset_user(); -#if 0 /* installed at external storage is not supported yet */ - } else if (type == STORAGE_TYPE_EXTERNAL) { - snprintf(app_root_dir, MAX_PATH_LENGTH, "%s%s/", - APP_BASE_EXTERNAL_PATH, pkgid); -#endif - } else { - ERR("Invalid STORAGE_TYPE"); - return -1; - } - - dir = opendir(app_root_dir); - if (dir == NULL) { - ERR("opendir() failed, path: %s, errno: %d (%s)", - app_root_dir, errno, strerror(errno)); - return -1; - } - - dfd = dirfd(dir); - ret = fstat(dfd, &st); - if (ret < 0) { - ERR("fstat() failed, path: %s, errno: %d (%s)", app_root_dir, - errno, strerror(errno)); - goto error; - } - *app_size += __stat_size(&st); - - while ((ent = readdir(dir))) { - const char *name = ent->d_name; - if (name[0] == '.') { - if (name[1] == '\0') - continue; - if ((name[1] == '.') && (name[2] == '\0')) - continue; - } - - if (ent->d_type != DT_DIR) - continue; - - subfd = openat(dfd, name, O_RDONLY | O_DIRECTORY); - if (subfd < 0) { - if (errno != ENOENT) { - ERR("openat() failed, errno: %d (%s)", - errno, strerror(errno)); - goto error; - } - continue; - } - if (strncmp(name, "data", strlen("data")) == 0) { - DBG("traverse path: %s/%s", app_root_dir, name); - size = __calculate_directory_size(subfd, true); - if (size < 0) { - ERR("Calculating data directory failed."); - goto error; - } - *data_size += size; - DBG("data_size: %lld", *data_size); - } else if (strncmp(name, "cache", strlen("cache")) == 0) { - DBG("traverse path: %s/%s", app_root_dir, name); - size = __calculate_directory_size(subfd, true); - if (size < 0) { - ERR("Calculating cache directory failed."); - goto error; - } - *cache_size += size; - DBG("cache_size: %lld", *cache_size); - } else if (strncmp(name, "shared", strlen("shared")) == 0) { - size = __calculate_shared_dir_size(dfd, app_root_dir, - data_size, app_size); - if (size < 0) { - ERR("Calculating shared directory failed."); - goto error; - } - *app_size += size; - DBG("app_size: %lld", *app_size); - } else { - DBG("traverse path: %s/%s", app_root_dir, name); - size = __calculate_directory_size(subfd, true); - if (size < 0) { - ERR("Calculating %s directory failed.", name); - goto error; - } - *app_size += size; - DBG("app_size: %lld", *app_size); - } - close(subfd); - } - closedir(dir); - return 0; - -error: - if (dir) - closedir(dir); - if (subfd != -1) - close(subfd); - - return -1; -} - -static char *__get_pkg_size_info_str(const pkg_size_info_t* pkg_size_info) -{ - char *size_info_str; - - size_info_str = (char *)malloc(MAX_SIZE_INFO_SIZE); - if (size_info_str == NULL) { - ERR("Out of memory."); - return NULL; - } - - snprintf(size_info_str, MAX_LONGLONG_LENGTH, "%lld", - pkg_size_info->data_size); - strcat(size_info_str, ":"); - snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, - "%lld", pkg_size_info->cache_size); - strcat(size_info_str, ":"); - snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, - "%lld", pkg_size_info->app_size); - strcat(size_info_str, ":"); - snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, - "%lld", pkg_size_info->ext_data_size); - strcat(size_info_str, ":"); - snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, - "%lld", pkg_size_info->ext_cache_size); - strcat(size_info_str, ":"); - snprintf(size_info_str + strlen(size_info_str), MAX_LONGLONG_LENGTH, - "%lld", pkg_size_info->ext_app_size); - strcat(size_info_str, ":"); - - DBG("size_info_str: %s", size_info_str); - - return size_info_str; -} - -static int __get_pkg_size_info(const char *pkgid, - pkg_size_info_t *pkg_size_info) -{ - int ret; - - ret = __calculate_pkg_size_info(STORAGE_TYPE_INTERNAL, pkgid, - &pkg_size_info->data_size, &pkg_size_info->cache_size, - &pkg_size_info->app_size); - if (ret < 0) - DBG("Calculating internal package size info failed: %d", ret); - DBG("size_info: %lld %lld %lld", pkg_size_info->data_size, - pkg_size_info->cache_size, pkg_size_info->app_size); - -#if 0 - ret = __calculate_pkg_size_info(STORAGE_TYPE_EXTERNAL, pkgid, - &pkg_size_info->ext_data_size, - &pkg_size_info->ext_cache_size, - &pkg_size_info->ext_app_size); - if (ret < 0) - DBG("Calculating external package size info failed: %d", ret); - DBG("size_info(external): %lld %lld %lld", pkg_size_info->ext_data_size, - pkg_size_info->ext_cache_size, - pkg_size_info->ext_app_size); -#endif - return ret; -} - -static int __get_total_pkg_size_info_cb(const pkgmgrinfo_pkginfo_h handle, - void *user_data) -{ - int ret; - char *pkgid; - pkg_size_info_t temp_pkg_size_info = {0,}; - pkg_size_info_t *pkg_size_info = (void *)user_data; - - ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if (ret != PMINFO_R_OK) { - ERR("pkgmgrinfo_pkginfo_get_pkgid() failed"); - return -1; - } - - __get_pkg_size_info(pkgid, &temp_pkg_size_info); - - pkg_size_info->app_size += temp_pkg_size_info.app_size; - pkg_size_info->data_size += temp_pkg_size_info.data_size; - pkg_size_info->cache_size += temp_pkg_size_info.cache_size; - pkg_size_info->ext_app_size += temp_pkg_size_info.ext_app_size; - pkg_size_info->ext_data_size += temp_pkg_size_info.ext_data_size; - pkg_size_info->ext_cache_size += temp_pkg_size_info.ext_cache_size; - - return 0; -} - -int __make_size_info_file(char *req_key, long long size) -{ - FILE *file; - int fd = 0; - char buf[MAX_PKG_BUF_LEN]; - char info_file[MAX_PKG_BUF_LEN]; - - if (req_key == NULL) - return -1; - - snprintf(info_file, sizeof(info_file), "%s/%s", PKG_SIZE_INFO_PATH, - req_key); - ERR("File path = %s", info_file); - - file = fopen(info_file, "w"); - if (file == NULL) { - ERR("Couldn't open the file %s", info_file); - return -1; - } - - snprintf(buf, MAX_LONGLONG_LENGTH, "%lld", size); - fwrite(buf, 1, strlen(buf), file); - - fflush(file); - fd = fileno(file); - fsync(fd); - fclose(file); - - return 0; -} - -static int __send_sizeinfo_cb(const pkgmgrinfo_pkginfo_h handle, - void *user_data) -{ - int ret; - char *pkgid; - int data_size = 0; - int total_size = 0; - char total_buf[MAX_PKG_BUF_LEN]; - char data_buf[MAX_PKG_BUF_LEN]; - pkgmgr_installer *pi = (pkgmgr_installer *)user_data; - - pkg_size_info_t temp_pkg_size_info = {0, }; - - ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if (ret != PMINFO_R_OK) { - ERR("pkgmgrinfo_pkginfo_get_pkgid() failed"); - return -1; - } - - __get_pkg_size_info(pkgid, &temp_pkg_size_info); - - total_size = temp_pkg_size_info.app_size + - temp_pkg_size_info.data_size + temp_pkg_size_info.cache_size; - data_size = temp_pkg_size_info.data_size + - temp_pkg_size_info.cache_size; - - /* send size info to client */ - snprintf(total_buf, sizeof(total_buf), "%d", total_size); - snprintf(data_buf, sizeof(data_buf), "%d", data_size); - - return pkgmgr_installer_send_signal(pi, - PKGMGR_INSTALLER_GET_SIZE_KEY_STR, - pkgid, data_buf, total_buf); -} - -static int __send_result_to_signal(pkgmgr_installer *pi, const char *req_key, - const char *pkgid, pkg_size_info_t *info) -{ - int ret; - char *info_str; - - info_str = __get_pkg_size_info_str(info); - if (info_str == NULL) - return -1; - - ret = pkgmgr_installer_send_signal(pi, - PKGMGR_INSTALLER_GET_SIZE_KEY_STR, - pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, info_str); - free(info_str); - - return ret; -} - -int main(int argc, char *argv[]) -{ - int ret; - int get_type; - char *pkgid; - char *req_key; - long long size = 0; - pkgmgr_installer *pi; - pkg_size_info_t info = {0, }; - - // argv has bellowed meaning - // argv[0] = pkgid - // argv[1] = get type - // argv[3] = req_key - - if (argv[0] == NULL) { - ERR("pkgid is NULL\n"); - return -1; - } - - pkgid = argv[0]; - get_type = atoi(argv[1]); - req_key = argv[3]; - - DBG("start get size : [pkgid=%s, request type=%d]", pkgid, get_type); - - pi = pkgmgr_installer_new(); - if (pi == NULL) { - ERR("failed to create installer"); - return -1; - } - pkgmgr_installer_receive_request(pi, argc, argv); - - switch (get_type) { - case PM_GET_TOTAL_SIZE: - /* send result to file */ - ret = __get_pkg_size_info(pkgid, &info); - if (ret == 0) - size = info.app_size + info.data_size + info.cache_size; - ret = __make_size_info_file(req_key, size); - break; - case PM_GET_DATA_SIZE: - /* send result to file */ - ret = __get_pkg_size_info(pkgid, &info); - if (ret == 0) - size = info.data_size + info.cache_size; - ret = __make_size_info_file(req_key, size); - break; - case PM_GET_ALL_PKGS: - /* send result to file */ - ret = pkgmgrinfo_pkginfo_get_usr_list( - __get_total_pkg_size_info_cb, &info, getuid()); - if (ret == 0) - size = info.app_size + info.data_size + info.cache_size; - ret = __make_size_info_file(req_key, size); - break; - case PM_GET_SIZE_INFO: - /* send each result to signal */ - ret = pkgmgrinfo_pkginfo_get_usr_list(__send_sizeinfo_cb, pi, - getuid()); - ret = __make_size_info_file(req_key, 0); - break; - case PM_GET_PKG_SIZE_INFO: - /* send result to signal */ - ret = __get_pkg_size_info(pkgid, &info); - if (ret == 0) - ret = __send_result_to_signal(pi, req_key, - pkgid, &info); - ret = __make_size_info_file(req_key, 0); - break; - case PM_GET_TOTAL_PKG_SIZE_INFO: - /* send result to signal */ - ret = pkgmgrinfo_pkginfo_get_usr_list( - __get_total_pkg_size_info_cb, &info, getuid()); - if (ret == 0) - ret = __send_result_to_signal(pi, req_key, - PKG_SIZE_INFO_TOTAL, &info); - ret = __make_size_info_file(req_key, 0); - break; - default: - ret = -1; - ERR("unsupported or depreated type"); - break; - } - - if (pkgmgr_installer_send_signal(pi, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, - pkgid, PKGMGR_INSTALLER_GET_SIZE_KEY_STR, - PKGMGR_INSTALLER_END_KEY_STR)) - ERR("failed to send finished signal"); - - DBG("get size result = %d", ret); - pkgmgr_installer_free(pi); - - return ret; -} diff --git a/tool/pkg_info.c b/tool/pkg_info.c deleted file mode 100644 index fd7ebfe..0000000 --- a/tool/pkg_info.c +++ /dev/null @@ -1,2167 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include -#include -#include - -#include -#include - -#include "package-manager.h" -#include "package-manager-types.h" -#include "pkgmgr_installer.h" - -#define OWNER_ROOT 0 - -static void __print_usage(); -static int __get_pkg_info(char *pkgid, uid_t uid); -static int __get_app_info(char *appid); -static int __get_app_list(char *pkgid, uid_t uid); -static int __get_app_category_list(char *appid); -static int __get_app_metadata_list(char *appid); -static int __get_app_control_list(char *appid); -static int __get_pkg_list(uid_t uid); -static int __get_installed_app_list(uid_t uid); -static int __add_app_filter(uid_t uid); -static int __add_pkg_filter(uid_t uid); -static int __insert_manifest_in_db(char *manifest, uid_t uid); -static int __remove_manifest_from_db(char *manifest, uid_t uid); -static int __set_certinfo_in_db(char *pkgid, uid_t uid); -static int __get_certinfo_from_db(char *pkgid, uid_t uid); -static int __del_certinfo_from_db(char *pkgid); -static int __get_integer_input_data(void); -char *__get_string_input_data(void); -static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data); -static int __app_category_list_cb(const char *category_name, void *user_data); -static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data); -static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data); -int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data); - -static void __get_pkgmgrinfo_pkginfo(const pkgmgrinfo_pkginfo_h handle, void *user_data) -{ - int ret = -1; - char *type = NULL; - char *version = NULL; - char *author_name = NULL; - char *author_email = NULL; - char *author_href = NULL; - char *root_path = NULL; - char *mainappid = NULL; - pkgmgrinfo_install_location location = 0; - char *icon = NULL; - char *label = NULL; - char *desc = NULL; - bool removable = 0; - bool preload = 0; - bool readonly = 0; - bool update = 0; - bool system = 0; - int installed_time = -1; - - ret = pkgmgrinfo_pkginfo_get_type(handle, &type); - if (ret < 0) { - printf("Failed to get pkg type\n"); - } - if (type) - printf("Type: %s\n", type); - - ret = pkgmgrinfo_pkginfo_get_version(handle, &version); - if (ret < 0) { - printf("Failed to get version\n"); - } - if (version) - printf("Version: %s\n", version); - - ret = pkgmgrinfo_pkginfo_get_install_location(handle, &location); - if (ret < 0) { - printf("Failed to get install location\n"); - } - printf("Install Location: %d\n", location); - - ret = pkgmgrinfo_pkginfo_get_icon(handle, &icon); - if (ret < 0) { - printf("Failed to get icon\n"); - } - if (icon) - printf("Icon: %s\n", icon); - - ret = pkgmgrinfo_pkginfo_get_label(handle, &label); - if (ret < 0) { - printf("Failed to get label\n"); - } - if (label) - printf("Label: %s\n", label); - - ret = pkgmgrinfo_pkginfo_get_description(handle, &desc); - if (ret < 0) { - printf("Failed to get description\n"); - } - if (desc) - printf("Description: %s\n", desc); - - ret = pkgmgrinfo_pkginfo_get_author_name(handle, &author_name); - if (ret < 0) { - printf("Failed to get author name\n"); - } - if (author_name) - printf("Author Name: %s\n", author_name); - - ret = pkgmgrinfo_pkginfo_get_author_email(handle, &author_email); - if (ret < 0) { - printf("Failed to get author email\n"); - } - if (author_email) - printf("Author Email: %s\n", author_email); - - ret = pkgmgrinfo_pkginfo_get_author_href(handle, &author_href); - if (ret < 0) { - printf("Failed to get author href\n"); - } - if (author_href) - printf("Author Href: %s\n", author_href); - - ret = pkgmgrinfo_pkginfo_get_root_path(handle, &root_path); - if (ret < 0) { - printf("Failed to get root_path\n"); - } - if (author_href) - printf("root_path : %s\n", root_path); - - ret = pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid); - if (ret < 0) { - printf("Failed to get mainappid\n"); - } - if (author_href) - printf("mainappid : %s\n", mainappid); - - ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time); - if (ret < 0) { - printf("Failed to get install time\n"); - } - printf("Install time: %d\n", installed_time); - - ret = pkgmgrinfo_pkginfo_is_removable(handle, &removable); - if (ret < 0) { - printf("Failed to get removable\n"); - } - else - printf("Removable: %d\n", removable); - - ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload); - if (ret < 0) { - printf("Failed to get preload\n"); - } - else - printf("Preload: %d\n", preload); - - ret = pkgmgrinfo_pkginfo_is_readonly(handle, &readonly); - if (ret < 0) { - printf("Failed to get readonly\n"); - } - else - printf("Readonly: %d\n", readonly); - - ret = pkgmgrinfo_pkginfo_is_update(handle, &update); - if (ret < 0) { - printf("Failed to get update\n"); - } - else - printf("update: %d\n", update); - - ret = pkgmgrinfo_pkginfo_is_system(handle, &system); - if (ret < 0) { - printf("Failed to get system\n"); - } - else - printf("system: %d\n", system); -} - -int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data) -{ - char *appid = NULL; - char *apptype = NULL; - int ret = -1; - - ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (ret < 0) { - printf("Failed to get appid\n"); - } - - ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype); - if (ret < 0) { - printf("Failed to get package\n"); - } - printf("apptype [%s]\t appid [%s]\n", apptype, appid); - - return 0; -} - -static int __get_integer_input_data(void) -{ - char input_str[32] = { 0, }; - int data = 0; - - if (fgets(input_str, sizeof(input_str), stdin) == NULL) { - printf("fgets() failed....\n"); - return -1; - } - - if (sscanf(input_str, "%4d", &data) != 1) { - printf("Input only integer option....\n"); - return -1; - } - - return data; -} - - -char *__get_string_input_data(void) -{ - char *data = (char *)malloc(1024); - if (data == NULL) { - printf("Malloc Failed\n"); - return NULL; - } - if (fgets(data,1024,stdin) == NULL){ - printf("Buffer overflow!!! try again\n"); - exit(-1); - } - data[strlen(data) - 1] = '\0'; - return data; -} - -static void __print_usage() -{ - printf("For Getting package|App Info\n"); - printf("\tpkginfo --[pkg|app] \n\n"); - printf("For Getting list of installed packages\n"); - printf("\tpkginfo --listpkg \n\n"); - printf("For Getting list of installed applications\n"); - printf("\tpkginfo --listapp \n\n"); - printf("For Getting app list for a particular package\n"); - printf("\tpkginfo --list \n\n"); - printf("For Getting app category list for a particular application\n"); - printf("\tpkginfo --category \n\n"); - printf("For Getting app metadata list for a particular application\n"); - printf("\tpkginfo --metadata \n\n"); - printf("For Getting app control list for a particular application\n"); - printf("\tpkginfo --appcontrol \n\n"); - printf("To insert|remove manifest info in DB\n"); - printf("\tpkginfo --[imd|rmd] \n\n"); - printf("To set manifest validation\n"); - printf("\tpkginfo --check \n\n"); - printf("To set cert info in DB\n"); - printf("\tpkginfo --setcert \n\n"); - printf("To get cert info from DB\n"); - printf("\tpkginfo --getcert \n\n"); - printf("To compare pkg cert info from DB\n"); - printf("\tpkginfo --cmp-pkgcert \n\n"); - printf("To compare app cert info from DB\n"); - printf("\tpkginfo --cmp-appcert \n\n"); - printf("To delete all cert info from DB\n"); - printf("\tpkginfo --delcert \n\n"); - printf("To add application filter values [Multiple values can be added]\n"); - printf("\tpkginfo --app-flt\n\n"); - printf("To add package filter values [Multiple values can be added]\n"); - printf("\tpkginfo --pkg-flt\n\n"); - printf("To add metadata filter values\n"); - printf("\tpkginfo --metadata-flt\n\n"); -} - -static void __print_arg_filter_usage() -{ - printf("=========================================\n"); - printf("pkginfo --arg-flt key value\n"); - printf("ex : pkginfo --arg-flt 6 webapp\n"); - printf("key list is bellowed\n"); - printf("2 --> filter by app ID\n"); - printf("3 --> filter by app component\n"); - printf("4 --> filter by app exec\n"); - printf("5 --> filter by app icon\n"); - printf("6 --> filter by app type\n"); - printf("7 --> filter by app operation\n"); - printf("8 --> filter by app uri\n"); - printf("9 --> filter by app mime\n"); - printf("10 --> filter by app category\n"); - printf("11 --> filter by app nodisplay [0|1]\n"); - printf("12 --> filter by app multiple [0|1]\n"); - printf("13 --> filter by app onboot [0|1]\n"); - printf("14 --> filter by app autorestart [0|1]\n"); - printf("15 --> filter by app taskmanage [0|1]\n"); - printf("16 --> filter by app hwacceleration\n"); - printf("17 --> filter by app screenreader\n"); - printf("=========================================\n"); -} - -static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data) -{ - char *appid = NULL; - pkgmgrinfo_appinfo_get_appid(handle, &appid); - printf("appid : %s\n", appid); - return 0; -} - -static int __add_metadata_filter() -{ - int ret = 0; - pkgmgrinfo_appinfo_metadata_filter_h handle; - char *key = NULL; - char *value = NULL; - - ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle); - if (ret != PMINFO_R_OK){ - printf("pkgmgrinfo_appinfo_metadata_filter_create() failed\n"); - return ret; - } - - printf("enter metadata - key\n"); - key = __get_string_input_data(); - printf("enter metadata - value\n"); - value = __get_string_input_data(); - - printf("filter condition : key=[%s], value=[%s]\n", key, value); - - ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, key, value); - if (ret != PMINFO_R_OK){ - printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n"); - goto err; - } - - ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, __app_list_cb, NULL); - if (ret != PMINFO_R_OK){ - printf("pkgmgrinfo_appinfo_metadata_filter_add() failed\n"); - goto err; - } - -err: - pkgmgrinfo_appinfo_metadata_filter_destroy(handle); - if (key) { - free(key); - key = NULL; - } - if (value) { - free(value); - value = NULL; - } - return ret; -} - -static int __add_app_filter(uid_t uid) -{ - int ret = 0; - int choice = -1; - char *value = NULL; - int val = -1; - int count = 0; - pkgmgrinfo_appinfo_filter_h handle; - ret = pkgmgrinfo_appinfo_filter_create(&handle); - if (ret > 0) { - printf("appinfo filter handle create failed\n"); - return -1; - } - while (choice != 0 && choice != 1) - { - printf("Enter Choice\n"); - printf("0 --> Finalize filter and get count of apps\n"); - printf("1 --> Finalize filter and get list of apps\n"); - printf("2 --> filter by app ID\n"); - printf("3 --> filter by app component\n"); - printf("4 --> filter by app exec\n"); - printf("5 --> filter by app icon\n"); - printf("6 --> filter by app type\n"); - printf("7 --> filter by app operation\n"); - printf("8 --> filter by app uri\n"); - printf("9 --> filter by app mime\n"); - printf("10 --> filter by app category\n"); - printf("11 --> filter by app nodisplay [0|1]\n"); - printf("12 --> filter by app multiple [0|1]\n"); - printf("13 --> filter by app onboot [0|1]\n"); - printf("14 --> filter by app autorestart [0|1]\n"); - printf("15 --> filter by app taskmanage [0|1]\n"); - printf("16 --> filter by app hwacceleration\n"); - printf("17 --> filter by app screenreader\n"); - printf("18 --> filter by app ui-gadget [0|1]\n"); - printf("19 --> filter by app support disable [0|1]\n"); - choice = __get_integer_input_data(); - switch (choice) { - case 0: - ret = pkgmgrinfo_appinfo_filter_count(handle, &count); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_count() failed\n"); - ret = -1; - goto err; - } - printf("App count = %d\n", count); - break; - case 1: - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, app_func, NULL, uid); - else - ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, app_func, NULL); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n"); - ret = -1; - goto err; - } - break; - case 2: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_ID, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 3: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_COMPONENT, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 4: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_EXEC, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 5: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_ICON, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 6: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_TYPE, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 7: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_OPERATION, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 8: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_URI, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 9: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_MIME, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 10: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_CATEGORY, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 11: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_NODISPLAY, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 12: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_MULTIPLE, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 13: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_ONBOOT, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 14: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_AUTORESTART, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 15: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_TASKMANAGE, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 16: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_HWACCELERATION, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 17: - value = __get_string_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, - PMINFO_APPINFO_PROP_APP_SCREENREADER, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 18: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_UI_GADGET, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 19: - val = __get_integer_input_data(); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, - PMINFO_APPINFO_PROP_APP_SUPPORT_DISABLE, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - default: - printf("Invalid filter property\n"); - pkgmgrinfo_appinfo_filter_destroy(handle); - ret = -1; - goto err; - } - } - ret = 0; -err: - pkgmgrinfo_appinfo_filter_destroy(handle); - if (value) { - free(value); - value = NULL; - } - return ret; -} - -static int __add_pkg_filter(uid_t uid) -{ - int ret = 0; - int choice = -1; - char *value = NULL; - int val = -1; - int count = 0; - pkgmgrinfo_pkginfo_filter_h handle; - - ret = pkgmgrinfo_pkginfo_filter_create(&handle); - if (ret > 0) { - printf("pkginfo filter handle create failed\n"); - return -1; - } - while (choice != 0 && choice !=1) - { - printf("Enter Choice\n"); - printf("0 --> Finalize filter and get count of packages\n"); - printf("1 --> Finalize filter and get list of packages\n"); - printf("2 --> filter by package ID\n"); - printf("3 --> filter by package version\n"); - printf("4 --> filter by package type\n"); - printf("5 --> filter by package install location\n"); - printf("6 --> filter by author name\n"); - printf("7 --> filter by author email\n"); - printf("8 --> filter by author href\n"); - printf("9 --> filter by package removable [0|1]\n"); - printf("10 --> filter by package readonly [0|1]\n"); - printf("11 --> filter by package preload [0|1]\n"); - printf("12 --> filter by package update [0|1]\n"); - printf("13 --> filter by package appsetting [0|1]\n"); - printf("14 --> filter by package installed storage[installed_internal | installed_external]\n"); - printf("15 --> filter by package privilege\n"); - printf("16 --> filter by package support disable [0|1]\n"); - choice = __get_integer_input_data(); - switch (choice) { - case 0: - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_usr_filter_count(handle, &count, uid); - else - ret = pkgmgrinfo_pkginfo_filter_count(handle, &count); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_count() failed\n"); - ret = -1; - goto err; - } - printf("Package count = %d\n", count); - break; - case 1: - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_usr_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL, uid); - else - ret = pkgmgrinfo_pkginfo_filter_foreach_pkginfo(handle, __pkg_list_cb, NULL); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_(usr)_filter_foreach_pkginfo() failed\n"); - ret = -1; - goto err; - } - break; - case 2: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_ID, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 3: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_VERSION, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 4: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_TYPE, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 5: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_INSTALL_LOCATION, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 6: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_NAME, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 7: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_EMAIL, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 8: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_AUTHOR_HREF, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 9: - val = __get_integer_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, - PMINFO_PKGINFO_PROP_PACKAGE_REMOVABLE, val); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 10: - val = __get_integer_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, - PMINFO_PKGINFO_PROP_PACKAGE_READONLY, val); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 11: - val = __get_integer_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, - PMINFO_PKGINFO_PROP_PACKAGE_PRELOAD, val); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 12: - val = __get_integer_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, - PMINFO_PKGINFO_PROP_PACKAGE_UPDATE, val); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 13: - val = __get_integer_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, - PMINFO_PKGINFO_PROP_PACKAGE_APPSETTING, val); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 14: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_INSTALLED_STORAGE, value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 15: - value = __get_string_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_string(handle, - PMINFO_PKGINFO_PROP_PACKAGE_PRIVILEGE, - value); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 16: - val = __get_integer_input_data(); - ret = pkgmgrinfo_pkginfo_filter_add_bool(handle, - PMINFO_PKGINFO_PROP_PACKAGE_SUPPORT_DISABLE, val); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - default: - printf("Invalid filter property\n"); - ret = -1; - goto err; - } - } - ret = 0; -err: - pkgmgrinfo_pkginfo_filter_destroy(handle); - if (value) { - free(value); - value = NULL; - } - return ret; -} - -static int __add_arg_filter(char *key, char *value, uid_t uid) -{ - int ret = 0; - int choice = -1; - int val = -1; - pkgmgrinfo_appinfo_filter_h handle; - ret = pkgmgrinfo_appinfo_filter_create(&handle); - if (ret > 0) { - printf("appinfo filter handle create failed\n"); - return -1; - } - choice = atoi(key); - - switch (choice) { - case 2: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ID, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 3: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_COMPONENT, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 4: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_EXEC, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 5: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_ICON, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 6: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 7: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_OPERATION, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 8: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_URI, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 9: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_MIME, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 10: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_string() failed\n"); - ret = -1; - goto err; - } - break; - case 11: - val = atoi(value); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_NODISPLAY, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 12: - val = atoi(value); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_MULTIPLE, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 13: - val = atoi(value); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_ONBOOT, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 14: - val = atoi(value); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_AUTORESTART, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 15: - val = atoi(value); - ret = pkgmgrinfo_appinfo_filter_add_bool(handle, PMINFO_APPINFO_PROP_APP_TASKMANAGE, val); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 16: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_HWACCELERATION, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - case 17: - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_SCREENREADER, value); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_add_bool() failed\n"); - ret = -1; - goto err; - } - break; - - default: - __print_arg_filter_usage(); - goto err; - } - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __get_app_id, NULL, uid); - else - ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, __get_app_id, NULL); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_filter_foreach_appinfo() failed\n"); - ret = -1; - goto err; - } - -err: - pkgmgrinfo_appinfo_filter_destroy(handle); - return ret; -} -static int __del_certinfo_from_db(char *pkgid) -{ - int ret = 0; - if (pkgid == NULL) { - printf("pkgid is NULL\n"); - return -1; - } - ret = pkgmgr_installer_delete_certinfo(pkgid); - if (ret < 0) { - printf("pkgmgr_installer_delete_certinfo failed\n"); - return -1; - } - return 0; -} - -static int __get_certinfo_from_db(char *pkgid, uid_t uid) -{ - if (pkgid == NULL) { - printf("pkgid is NULL\n"); - return -1; - } - int ret = 0; - int choice = -1; - int i = 0; - const char *value = NULL; - pkgmgrinfo_certinfo_h handle = NULL; - ret = pkgmgrinfo_pkginfo_create_certinfo(&handle); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_create_certinfo failed\n"); - return -1; - } - ret = pkgmgrinfo_pkginfo_load_certinfo(pkgid, handle, uid); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_load_certinfo failed\n"); - return -1; - } - while (choice != 10) - { - printf("Enter the choice to get\n"); - printf("0 --> to get all cert values\n"); - printf("1 --> author root certificate\n"); - printf("2 --> author intermediate certificate\n"); - printf("3 --> author signer certificate\n"); - printf("4 --> distributor root certificate\n"); - printf("5 --> distributor intermediate certificate\n"); - printf("6 --> distributor signer certificate\n"); - printf("7 --> distributor2 root certificate\n"); - printf("8 --> distributor2 intermediate certificate\n"); - printf("9 --> distributor2 signer certificate\n"); - printf("10 --> exit\n"); - choice = __get_integer_input_data(); - switch (choice) { - case 0: - for (i = 0; i < 9; i++) - { - pkgmgrinfo_pkginfo_get_cert_value(handle, i, &value); - if (value) - printf("cert type[%d] value = %s\n", i, value); - } - ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_destroy_certinfo failed\n"); - ret = -1; - } - break; - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - ret = pkgmgrinfo_pkginfo_get_cert_value(handle, choice - 1, &value); - if (value) - printf("cert type[%d] value = %s\n", choice - 1, value); - if (ret < 0) - ret = -1; - break; - case 10: - ret = pkgmgrinfo_pkginfo_destroy_certinfo(handle); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_destroy_certinfo failed\n"); - ret = -1; - } - break; - default: - printf("Invalid choice entered\n"); - ret = -1; - break; - } - } - - return ret; -} - -static int __compare_pkg_certinfo_from_db(char *lhs_pkgid, char *rhs_pkgid, uid_t uid) -{ - if (lhs_pkgid == NULL || rhs_pkgid == NULL) { - printf("pkgid is NULL\n"); - return -1; - } - - int ret = 0; - pkgmgrinfo_cert_compare_result_type_e result; - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_pkgid, rhs_pkgid, uid, &result); - else - ret = pkgmgrinfo_pkginfo_compare_pkg_cert_info(lhs_pkgid, rhs_pkgid, &result); - if (ret != PMINFO_R_OK) { - return -1; - } - - printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n"); - printf("pkgid =[%s] and [%s] compare result = [%d] \n", lhs_pkgid, rhs_pkgid, result); - return 0; -} - -static int __compare_app_certinfo_from_db(char *lhs_appid, char *rhs_appid, uid_t uid) -{ - if (lhs_appid == NULL || rhs_appid == NULL) { - printf("appid is NULL\n"); - return -1; - } - - int ret = 0; - pkgmgrinfo_cert_compare_result_type_e result; - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_appid, rhs_appid, uid, &result); - else - ret = pkgmgrinfo_pkginfo_compare_app_cert_info(lhs_appid, rhs_appid, &result); - if (ret != PMINFO_R_OK) { - return -1; - } - - printf("Compare [match=0, mismatch=1, lhs_no=2, rhs_no=3, both_no=4]\n"); - printf("appid =[%s] and [%s] compare result = [%d] \n", lhs_appid, rhs_appid, result); - return 0; -} - -static int __set_certinfo_in_db(char *pkgid, uid_t uid) -{ - if (pkgid == NULL) { - printf("pkgid is NULL\n"); - return -1; - } - int ret = 0; - int choice = -1; - char *value = NULL; - pkgmgr_instcertinfo_h handle = NULL; - ret = pkgmgr_installer_create_certinfo_set_handle(&handle); - if (ret < 0) { - printf("pkgmgr_installer_create_certinfo_set_handle failed\n"); - return -1; - } - while (choice != 0) - { - printf("Enter the choice you want to set\n"); - printf("0 --> to set data in DB\n"); - printf("1 --> author root certificate\n"); - printf("2 --> author intermediate certificate\n"); - printf("3 --> author signer certificate\n"); - printf("4 --> distributor root certificate\n"); - printf("5 --> distributor intermediate certificate\n"); - printf("6 --> distributor signer certificate\n"); - printf("7 --> distributor2 root certificate\n"); - printf("8 --> distributor2 intermediate certificate\n"); - printf("9 --> distributor2 signer certificate\n"); - choice = __get_integer_input_data(); - switch (choice) { - case 0: - ret = pkgmgr_installer_save_certinfo(pkgid, handle, uid); - if (ret < 0) { - printf("pkgmgr_installer_save_certinfo failed\n"); - pkgmgr_installer_destroy_certinfo_set_handle(handle); - return -1; - } - ret = pkgmgr_installer_destroy_certinfo_set_handle(handle); - if (ret < 0) { - printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n"); - return -1; - } - return 0; - case 1: - printf("Enter Author Root Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 0, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 2: - printf("Enter Author Intermediate Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 1, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 3: - printf("Enter Author Signer Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 2, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 4: - printf("Enter Distributor Root Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 3, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 5: - printf("Enter Distributor Intermediate Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 4, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 6: - printf("Enter Distributor Signer Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 5, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 7: - printf("Enter Distributor2 Root Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 6, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 8: - printf("Enter Distributor2 Intermediate Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 7, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - case 9: - printf("Enter Distributor2 Signer Certificate Value: \n"); - value = __get_string_input_data(); - ret = pkgmgr_installer_set_cert_value(handle, 8, value); - if (ret < 0) { - printf("pkgmgr_installer_set_cert_value failed\n"); - ret = -1; - goto err; - } - free(value); - value = NULL; - break; - default: - printf("Invalid Number Entered\n"); - choice = 0; - ret = pkgmgr_installer_destroy_certinfo_set_handle(handle); - if (ret < 0) { - printf("pkgmgr_installer_destroy_certinfo_set_handle failed\n"); - return -1; - } - break; - } - } -err: - if (value) { - free(value); - value = NULL; - } - pkgmgr_installer_destroy_certinfo_set_handle(handle); - return ret; -} - -static int __insert_manifest_in_db(char *manifest, uid_t uid) -{ - int ret = 0; - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - if (uid == GLOBAL_USER || uid == OWNER_ROOT) - ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL); - else - ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, uid, NULL); - if (ret < 0) { - printf("insert in db failed\n"); - return -1; - } - return 0; -} - -static int __fota_insert_manifest_in_db(char *manifest, uid_t uid) -{ - int ret = 0; - - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - if (uid != GLOBAL_USER) - ret = pkgmgr_parser_parse_usr_manifest_for_installation(manifest, uid, NULL); - else - ret = pkgmgr_parser_parse_manifest_for_installation(manifest, NULL); - if (ret < 0) { - printf("insert in db failed\n"); - return -1; - } - return 0; -} - -static int __remove_manifest_from_db(char *manifest, uid_t uid) -{ - int ret = 0; - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - if (uid != GLOBAL_USER) - ret = pkgmgr_parser_parse_usr_manifest_for_uninstallation(manifest, uid, NULL); - else - ret = pkgmgr_parser_parse_manifest_for_uninstallation(manifest, NULL); - if (ret < 0) { - printf("remove from db failed\n"); - return -1; - } - return 0; -} - -int app_func(const pkgmgrinfo_appinfo_h handle, void *user_data) -{ - char *appid; - char *data = NULL; - if (user_data) { - data = (char *)user_data; - } - int ret = -1; - char *exec = NULL; - char *icon = NULL; - char *label = NULL; - pkgmgrinfo_app_component component = 0; - char *apptype = NULL; - bool nodisplay = 0; - bool multiple = 0; - bool taskmanage = 0; - pkgmgrinfo_app_hwacceleration hwacceleration; - pkgmgrinfo_app_screenreader screenreader; - bool onboot = 0; - bool autorestart = 0; - char *package = NULL; - - ret = pkgmgrinfo_appinfo_get_appid(handle, &appid); - if (ret < 0) { - printf("Failed to get appid\n"); - } - if (appid) - printf("Appid: %s\n", appid); - - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package); - if (ret < 0) { - printf("Failed to get package\n"); - } - if (package) - printf("Package: %s\n", package); - - ret = pkgmgrinfo_appinfo_get_exec(handle, &exec); - if (ret < 0) { - printf("Failed to get exec\n"); - } - if (exec) - printf("Exec: %s\n", exec); - - ret = pkgmgrinfo_appinfo_get_icon(handle, &icon); - if (ret < 0) { - printf("Failed to get icon\n"); - } - if (icon) - printf("Icon: %s\n", icon); - - ret = pkgmgrinfo_appinfo_get_label(handle, &label); - if (ret < 0) { - printf("Failed to get label\n"); - } - if (label) - printf("Label: %s\n", label); - - ret = pkgmgrinfo_appinfo_get_component(handle, &component); - if (ret < 0) { - printf("Failed to get component\n"); - } - - ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype); - if (ret < 0) { - printf("Failed to get apptype\n"); - } - if (apptype) - printf("Apptype: %s\n", apptype); - - if (component == PMINFO_UI_APP) { - printf("component: uiapp\n"); - ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); - if (ret < 0) { - printf("Failed to get multiple\n"); - } else { - printf("Multiple: %d\n", multiple); - } - - ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay); - if (ret < 0) { - printf("Failed to get nodisplay\n"); - } else { - printf("Nodisplay: %d \n", nodisplay); - } - - ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage); - if (ret < 0) { - printf("Failed to get taskmanage\n"); - } else { - printf("Taskmanage: %d\n", taskmanage); - } - - ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration); - if (ret < 0) { - printf("Failed to get hwacceleration\n"); - } else { - printf("hw-acceleration: %d\n", hwacceleration); - } - - ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader); - if (ret < 0) { - printf("Failed to get screenreader\n"); - } else { - printf("screenreader: %d\n", screenreader); - } - - } - if (component == PMINFO_SVC_APP) { - printf("component: svcapp\n"); - ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot); - if (ret < 0) { - printf("Failed to get onboot\n"); - } else { - printf("Onboot: %d\n", onboot); - } - - ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart); - if (ret < 0) { - printf("Failed to get autorestart\n"); - } else { - printf("Autorestart: %d \n", autorestart); - } - } - if (data) - printf("user_data : %s\n\n", data); - - return 0; -} - - -static int __pkg_list_cb (const pkgmgrinfo_pkginfo_h handle, void *user_data) -{ - char *test_data = "test data"; - int ret = -1; - char *pkgid; - char *pkg_type; - char *pkg_version; - bool preload = 0; - int installed_time = -1; - - pkgmgrinfo_uidinfo_t *uid_info = (pkgmgrinfo_uidinfo_t *) handle; - ret = pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); - if(ret < 0) { - printf("pkgmgrinfo_pkginfo_get_pkgid() failed\n"); - } - ret = pkgmgrinfo_pkginfo_get_type(handle, &pkg_type); - if(ret < 0) { - printf("pkgmgrinfo_pkginfo_get_type() failed\n"); - } - ret = pkgmgrinfo_pkginfo_get_version(handle, &pkg_version); - if(ret < 0) { - printf("pkgmgrinfo_pkginfo_get_version() failed\n"); - } - ret = pkgmgrinfo_pkginfo_is_preload(handle, &preload); - if(ret < 0) { - printf("pkgmgrinfo_pkginfo_is_preload() failed\n"); - } - ret = pkgmgrinfo_pkginfo_get_installed_time(handle, &installed_time); - if(ret < 0) { - printf("pkgmgrinfo_pkginfo_get_installed_time() failed\n"); - } - - - printf("---------------------------------------\n"); - printf("pkg_type [%s]\tpkgid [%s]\tversion [%s]\tpreload [%d]\tinstalled_time [%d]\n", pkg_type, - pkgid, pkg_version, preload, installed_time); - - if (uid_info->uid != GLOBAL_USER) { - printf("**List of Ui-Apps**\n"); - ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid_info->uid); - if (ret < 0) { - printf("pkgmgr_get_info_app() failed\n"); - } - printf("**List of Svc-Apps**\n"); - ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid_info->uid); - if (ret < 0) { - printf("pkgmgr_get_info_app() failed\n"); - } - } else { - printf("**List of Ui-Apps**\n"); - ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data); - if (ret < 0) { - printf("pkgmgr_get_info_app() failed\n"); - } - printf("**List of Svc-Apps**\n"); - ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data); - if (ret < 0) { - printf("pkgmgr_get_info_app() failed\n"); - } - } - printf("---------------------------------------\n"); - - return 0; -} - -static int __get_pkg_list(uid_t uid) -{ - int ret = -1; - if (uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_get_usr_list(__pkg_list_cb, NULL, uid); - else - ret = pkgmgrinfo_pkginfo_get_list(__pkg_list_cb, NULL); - if (ret < 0) { - printf("pkgmgrinfo_pkginfo_get_list() failed\n"); - return -1; - } - return 0; -} - -static int __get_installed_app_list(uid_t uid) -{ - int ret = -1; - if(uid != GLOBAL_USER) - ret = pkgmgrinfo_appinfo_get_usr_installed_list(app_func, uid, NULL); - else - ret = pkgmgrinfo_appinfo_get_installed_list(app_func, NULL); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_get_installed_list() failed\n"); - return -1; - } - return 0; -} - - -static int __app_category_list_cb(const char *category_name, void *user_data) -{ - if (category_name) - printf("Category: %s\n", category_name); - return 0; -} - -static int __app_metadata_list_cb(const char *metadata_name, const char *metadata_value, void *user_data) -{ - if (metadata_name && metadata_value) { - printf("Name: %s\n", metadata_name); - printf("Value: %s\n", metadata_value); - printf("\n"); - } - return 0; -} - -static int __app_control_list_cb(const char *operation, const char *uri, const char *mime, void *user_data) -{ - printf("-------------------------------------------------------\n"); - printf("Operation: %s\n", operation); - printf("Uri: %s\n", uri); - printf("Mime: %s\n", mime); - printf("-------------------------------------------------------\n\n"); - return 0; -} - - -static int __get_app_category_list(char *appid) -{ - int ret = -1; - pkgmgrinfo_appinfo_h handle; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - ret = pkgmgrinfo_appinfo_foreach_category(handle, __app_category_list_cb, NULL); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_foreach_category() failed\n"); - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return -1; - } - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return 0; -} - -static int __get_app_metadata_list(char *appid) -{ - int ret = -1; - pkgmgrinfo_appinfo_h handle; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - ret = pkgmgrinfo_appinfo_foreach_metadata(handle, __app_metadata_list_cb, NULL); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_foreach_metadata() failed\n"); - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return -1; - } - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return 0; -} - -static int __get_app_control_list(char *appid) -{ - int ret = -1; - pkgmgrinfo_appinfo_h handle; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - ret = pkgmgrinfo_appinfo_foreach_appcontrol(handle, __app_control_list_cb, NULL); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_foreach_appcontrol() failed\n"); - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return -1; - } - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return 0; -} - -static int __set_app_enabled(char *appid, bool enabled) -{ - int ret = -1; - ret = pkgmgrinfo_appinfo_set_state_enabled(appid, enabled); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - return 0; -} - -static int __get_app_list(char *pkgid, uid_t uid) -{ - pkgmgrinfo_pkginfo_h handle; - int ret = -1; - char *test_data = "test data"; - if(uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); - else - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - if (uid != GLOBAL_USER) { - printf("List of Ui-Apps\n\n"); - ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_UI_APP, app_func, (void *)test_data, uid); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } - printf("List of Svc-Apps\n\n"); - ret = pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data, uid); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } - } else { - printf("List of Ui-Apps\n\n"); - ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_UI_APP, app_func, (void *)test_data); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } - printf("List of Svc-Apps\n\n"); - ret = pkgmgrinfo_appinfo_get_list(handle, PMINFO_SVC_APP, app_func, (void *)test_data); - if (ret < 0) { - printf("pkgmgrinfo_appinfo_get_list() failed\n"); - } - } - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return 0; -} - -static int __get_pkg_info(char *pkgid, uid_t uid) -{ - pkgmgrinfo_pkginfo_h handle; - int ret = -1; - - printf("Get Pkg Info Called [%s]\n", pkgid); - if(uid != GLOBAL_USER) - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); - else - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - - __get_pkgmgrinfo_pkginfo(handle, NULL); - - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return 0; -} - -static int __get_app_info(char *appid) -{ - printf("Get App Info Called [%s]\n", appid); - char *exec = NULL; - char *app_id = NULL; - char *apptype = NULL; - char *icon = NULL; - char *label = NULL; - char *package = NULL; - pkgmgrinfo_app_component component = 0; - bool nodisplay = 0; - bool multiple = 0; - bool taskmanage = 0; - pkgmgrinfo_app_hwacceleration hwacceleration; - pkgmgrinfo_app_screenreader screenreader; - bool onboot = 0; - bool autorestart = 0; - bool enabled = 0; - bool preload = 0; - pkgmgrinfo_appinfo_h handle; - int ret = -1; - - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &handle); - if (ret < 0) { - printf("Failed to get handle\n"); - return -1; - } - - ret = pkgmgrinfo_appinfo_get_pkgid(handle, &package); - if (ret < 0) { - printf("Failed to get package\n"); - } - - ret = pkgmgrinfo_appinfo_get_appid(handle, &app_id); - if (ret < 0) { - printf("Failed to get exec\n"); - } - - ret = pkgmgrinfo_appinfo_get_label(handle, &label); - if (ret < 0) { - printf("Failed to get label\n"); - } - ret = pkgmgrinfo_appinfo_get_icon(handle, &icon); - if (ret < 0) { - printf("Failed to get icon\n"); - } - - ret = pkgmgrinfo_appinfo_get_exec(handle, &exec); - if (ret < 0) { - printf("Failed to get exec\n"); - } - ret = pkgmgrinfo_appinfo_get_component(handle, &component); - if (ret < 0) { - printf("Failed to get component\n"); - } - ret = pkgmgrinfo_appinfo_get_apptype(handle, &apptype); - if (ret < 0) { - printf("Failed to get apptype\n"); - } - ret = pkgmgrinfo_appinfo_is_nodisplay(handle, &nodisplay); - if (ret < 0) { - printf("Failed to get nodisplay\n"); - } - ret = pkgmgrinfo_appinfo_is_multiple(handle, &multiple); - if (ret < 0) { - printf("Failed to get multiple\n"); - } - ret = pkgmgrinfo_appinfo_is_taskmanage(handle, &taskmanage); - if (ret < 0) { - printf("Failed to get taskmanage\n"); - } - ret = pkgmgrinfo_appinfo_get_hwacceleration(handle, &hwacceleration); - if (ret < 0) { - printf("Failed to get hwacceleration\n"); - } - ret = pkgmgrinfo_appinfo_get_screenreader(handle, &screenreader); - if (ret < 0) { - printf("Failed to get screenreader\n"); - } - ret = pkgmgrinfo_appinfo_is_onboot(handle, &onboot); - if (ret < 0) { - printf("Failed to get onboot\n"); - } - ret = pkgmgrinfo_appinfo_is_autorestart(handle, &autorestart); - if (ret < 0) { - printf("Failed to get autorestart\n"); - } - ret = pkgmgrinfo_appinfo_is_enabled(handle, &enabled); - if (ret < 0) { - printf("Failed to get enabled\n"); - } - ret = pkgmgrinfo_appinfo_is_preload(handle, &preload); - if (ret < 0) { - printf("Failed to get preload\n"); - } - - if (app_id) - printf("Appid: %s\n", app_id); - - if (package) - printf("Package: %s\n", package); - - if (exec) - printf("Exec: %s\n", exec); - if (apptype) - printf("Apptype: %s\n", apptype); - - if (component == PMINFO_UI_APP) { - printf("component: uiapp\n"); - - if (icon) - printf("Icon: %s\n", icon); - if (label) - printf("Label: %s\n", label); - - printf("Nodisplay: %d\n", nodisplay); - printf("Multiple: %d\n", multiple); - printf("Taskmanage: %d\n", taskmanage); - printf("Hw-Acceleration: %d\n", hwacceleration); - printf("Screenreader: %d\n", screenreader); - } else if (component == PMINFO_SVC_APP) { - printf("component: svcapp\n"); - - if (icon) - printf("Icon: %s\n", icon); - if (label) - printf("Label: %s\n", label); - - printf("Autorestart: %d\n", autorestart); - printf("Onboot: %d\n", onboot); - } else { - printf("Invalid Component Type\n"); - } - - printf("Enabled: %d\n", enabled); - printf("Preload: %d\n", preload); - - pkgmgrinfo_appinfo_destroy_appinfo(handle); - return 0; - -} - -static int __check_manifest_validation(char *manifest) -{ - int ret = 0; - if (manifest == NULL) { - printf("Manifest file is NULL\n"); - return -1; - } - ret = pkgmgr_parser_check_manifest_validation(manifest); - if (ret < 0) { - printf("check manifest validation failed\n"); - return -1; - } - return 0; -} - -int main(int argc, char *argv[]) -{ - int ret = 0; - long starttime; - long endtime; - struct timeval tv; - - gettimeofday(&tv, NULL); - starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; - - if (argc == 2) { - if (strcmp(argv[1], "--listpkg") == 0) { - ret = __get_pkg_list(getuid()); - if (ret == -1) { - printf("get pkg list failed\n"); - goto end; - } else { - goto end; - } - } else if (strcmp(argv[1], "--app-flt") == 0) { - ret = __add_app_filter(getuid()); - if (ret == -1) { - printf("Adding app filter failed\n"); - goto end; - } else { - goto end; - } - } else if (strcmp(argv[1], "--pkg-flt") == 0) { - ret = __add_pkg_filter(getuid()); - if (ret == -1) { - printf("Adding pkg filter failed\n"); - goto end; - } else { - goto end; - } - } else if (strcmp(argv[1], "--metadata-flt") == 0) { - ret = __add_metadata_filter(); - if (ret == -1) { - printf("Adding pkg filter failed\n"); - goto end; - } else { - goto end; - } - } else if (strcmp(argv[1], "--listapp") == 0) { - ret = __get_installed_app_list(getuid()); - if (ret == -1) { - printf("get installed app list failed\n"); - goto end; - } else { - goto end; - } - } else { - __print_usage(); - ret = -1; - goto end; - } - }else if (argc == 4) { - if (strcmp(argv[1], "--setappenabled") == 0) { - ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true); - if (ret == -1) { - printf("set app enabled failed\n"); - goto end; - } - goto end; - } else if(strcmp(argv[1], "--setpkgenabled") == 0) { - ret = __set_app_enabled(argv[2], (strcmp(argv[3], "0")==0)?false:true); - if (ret == -1) { - printf("set pkg enabled failed\n"); - goto end; - } - goto end; - } else if (strcmp(argv[1], "--cmp-pkgcert") == 0) { - ret = __compare_pkg_certinfo_from_db(argv[2], argv[3], getuid()); - if (ret == -1) { - printf("compare certinfo from db failed\n"); - goto end; - } - goto end; - } else if (strcmp(argv[1], "--cmp-appcert") == 0) { - ret = __compare_app_certinfo_from_db(argv[2], argv[3], getuid()); - if (ret == -1) { - printf("compare certinfo from db failed\n"); - goto end; - } - goto end; - } else if (strcmp(argv[1], "--arg-flt") == 0) { - ret = __add_arg_filter(argv[2], argv[3], getuid()); - if (ret == -1) { - printf("compare certinfo from db failed\n"); - goto end; - } - goto end; - } else { - __print_usage(); - ret = -1; - goto end; - } - } - - if (argc != 3) { - __print_usage(); - ret = -1; - goto end; - } - if (!argv[1] || !argv[2]) { - __print_usage(); - ret = -1; - goto end; - } - - if (strcmp(argv[1], "--pkg") == 0) { - ret = __get_pkg_info(argv[2], getuid()); - if (ret == -1) { - printf("get pkg info failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--app") == 0) { - ret = __get_app_info(argv[2]); - if (ret == -1) { - printf("get app info failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--list") == 0) { - ret = __get_app_list(argv[2], getuid()); - if (ret == -1) { - printf("get app list failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--imd") == 0) { - ret = __insert_manifest_in_db(argv[2], getuid()); - if (ret == -1) { - printf("insert in db failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--fota") == 0) { - ret = __fota_insert_manifest_in_db(argv[2], getuid()); - if (ret == -1) { - printf("insert in db failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--rmd") == 0) { - ret = __remove_manifest_from_db(argv[2], getuid()); - if (ret == -1) { - printf("remove from db failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--setcert") == 0) { - ret = __set_certinfo_in_db(argv[2], getuid()); - if (ret == -1) { - printf("set certinfo in db failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--getcert") == 0) { - ret = __get_certinfo_from_db(argv[2], getuid()); - if (ret == -1) { - printf("get certinfo from db failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--delcert") == 0) { - ret = __del_certinfo_from_db(argv[2]); - if (ret == -1) { - printf("del certinfo from db failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--check") == 0) { - ret = __check_manifest_validation(argv[2]); - if (ret == -1) { - printf("check manifest failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--category") == 0) { - ret = __get_app_category_list(argv[2]); - if (ret == -1) { - printf("get app category list failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--metadata") == 0) { - ret = __get_app_metadata_list(argv[2]); - if (ret == -1) { - printf("get app metadata list failed\n"); - goto end; - } - } else if (strcmp(argv[1], "--appcontrol") == 0) { - ret = __get_app_control_list(argv[2]); - if (ret == -1) { - printf("get app control list failed\n"); - goto end; - } - } else - __print_usage(); - -end: - - gettimeofday(&tv, NULL); - endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l; - - printf("spend time for pkginfo is [%d]ms\n", (int)(endtime - starttime)); - - return ret; -} diff --git a/tool/pkg_initdb.c b/tool/pkg_initdb.c deleted file mode 100644 index 91e32e9..0000000 --- a/tool/pkg_initdb.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * slp-pkgmgr - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , - * Jaeho Lee , Shobhit Srivastava - * - * 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 -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -/* For multi-user support */ -#include - -#define OWNER_ROOT 0 -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define BUFSZE 1024 - -#ifdef _E -#undef _E -#endif -#define _E(fmt, arg...) fprintf(stderr, "[PKG_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); - -#ifdef _D -#undef _D -#endif -#define _D(fmt, arg...) fprintf(stderr, "[PKG_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); - -#define PKGINFO_CMD "/usr/bin/pkginfo --imd" -#define PKGINSTALLUG_CMD "/usr/bin/pkg_install_ug" -#define PKGPRIVILEGE_CMD "/usr/bin/pkg_privilege -i" - -static int _is_global(uid_t uid) -{ - return (uid == OWNER_ROOT || uid == GLOBAL_USER) ? 1 : 0; -} - -static int _initdb_load_directory(uid_t uid, const char *directory) -{ - DIR *dir; - struct dirent entry, *result; - int ret; - char buf[BUFSZE]; - char buf2[BUFSZE]; - - dir = opendir(directory); - if (!dir) { - _E("Failed to access the [%s] because %s", directory, - strerror_r(errno, buf, sizeof(buf))); - return -1; - } - - _D("Loading manifest files from %s", directory); - - for (ret = readdir_r(dir, &entry, &result); - ret == 0 && result != NULL; - ret = readdir_r(dir, &entry, &result)) { - if (entry.d_name[0] == '.') - continue; - - snprintf(buf, sizeof(buf), "%s/%s", directory, entry.d_name); - _D("manifest file %s", buf); - - ret = pkgmgr_parser_check_manifest_validation(buf); - if (ret < 0) { - _E("check manifest validation failed code[%d] %s", - ret, buf); - continue; - } - - if (setresuid(uid, uid, OWNER_ROOT)) { - _E("Failed to setresuid: %s", - strerror_r(errno, buf, sizeof(buf))); - closedir(dir); - return -1; - } - snprintf(buf2, sizeof(buf2), "%s %s", PKGINFO_CMD, buf); - if (system(buf2)) - _E("[%s %s] returns error", PKGINFO_CMD, buf); - snprintf(buf2, sizeof(buf2), "%s %s", PKGINSTALLUG_CMD, buf); - if (system(buf2)) - _E("[%s %s] returns error", PKGINSTALLUG_CMD, buf); - snprintf(buf2, sizeof(buf2), "%s %s", PKGPRIVILEGE_CMD, buf); - if (system(buf2)) - _E("[%s %s] returns error", PKGPRIVILEGE_CMD, buf); - if (setresuid(OWNER_ROOT, OWNER_ROOT, OWNER_ROOT)) { - _E("Failed to setresuid: %s", - strerror_r(errno, buf, sizeof(buf))); - closedir(dir); - return -1; - } - } - - closedir(dir); - - return 0; -} - -static int _is_authorized() -{ - /* pkg_init db should be called by as root privilege. */ - uid_t uid = getuid(); - - if ((uid_t) OWNER_ROOT == uid) - return 1; - else - return 0; -} - -static void _remove_old_dbs(uid) -{ - const char *info_db_path; - const char *info_db_journal_path; - const char *cert_db_path; - const char *cert_db_journal_path; - - if (!_is_global(uid)) - tzplatform_set_user(uid); - - info_db_path = tzplatform_mkpath( - _is_global(uid) ? TZ_SYS_DB : TZ_USER_DB, - ".pkgmgr_parser.db"); - info_db_journal_path = tzplatform_mkpath( - _is_global(uid) ? TZ_SYS_DB : TZ_USER_DB, - ".pkgmgr_parser.db-journal"); - cert_db_path = tzplatform_mkpath( - _is_global(uid) ? TZ_SYS_DB : TZ_USER_DB, - ".pkgmgr_cert.db"); - cert_db_journal_path = tzplatform_mkpath( - _is_global(uid) ? TZ_SYS_DB : TZ_USER_DB, - ".pkgmgr_cert.db-journal"); - - if (remove(info_db_path)) - _E(" %s is not removed", info_db_path); - if (remove(info_db_journal_path)) - _E(" %s is not removed", info_db_journal_path); - if (remove(cert_db_path)) - _E(" %s is not removed", cert_db_path); - if (remove(cert_db_journal_path)) - _E(" %s is not removed", cert_db_journal_path); - - tzplatform_reset_user(); -} - -int main(int argc, char *argv[]) -{ - int ret; - const char *dir; - uid_t uid = 0; - - if (!_is_authorized()) { - _E("You are not an authorized user!"); - return -1; - } - - if (argc > 1) - uid = (uid_t)atoi(argv[1]); - - _remove_old_dbs(uid); - - ret = pkgmgr_parser_create_and_initialize_db(uid); - if (ret < 0) { - _E("cannot create db"); - return -1; - } - - if (!_is_global(uid)) - tzplatform_set_user(uid); - dir = tzplatform_getenv( - _is_global(uid) ? TZ_SYS_RW_PACKAGES : TZ_USER_PACKAGES); - tzplatform_reset_user(); - - return _initdb_load_directory(uid, dir); -} diff --git a/tool/pkg_install_ug.c b/tool/pkg_install_ug.c deleted file mode 100644 index 7b3bb48..0000000 --- a/tool/pkg_install_ug.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#define OWNER_ROOT 0 -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) -#define UG_CLIENT tzplatform_mkpath(TZ_SYS_BIN, "ug-client") - -static int _check_bin_directory(const char *pkgid) -{ - const char *path; - char buf[PATH_MAX]; - - path = tzplatform_mkpath(TZ_SYS_RO_APP, pkgid); - snprintf(buf, sizeof(buf), "%s/bin", path); - - if (access(buf, F_OK) == 0) - return 0; - - if (mkdir(buf, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH)) { - printf("create bin directory(%s) failed: %s\n", buf, - strerror(errno)); - return -1; - } - - return 0; -} - -static void _application_cb(gpointer data, gpointer user_data) -{ - int ret; - application_x *app = (application_x *)data; - package_x *pkg = (package_x *)user_data; - - if (app->exec == NULL || app->ui_gadget == NULL || - strcasecmp(app->ui_gadget, "true") != 0) - return; - - if (_check_bin_directory(pkg->package)) - return; - - ret = symlink(UG_CLIENT, app->exec); - if (ret != 0) - printf("failed to install ug %s: %s\n", app->exec, - strerror(errno)); -} - -static int _install_ug(char *manifest) -{ - package_x *pkg; - - pkg = pkgmgr_parser_process_manifest_xml(manifest); - if (pkg == NULL) { - printf("Parse manifest failed\n"); - return -1; - } - - g_list_foreach(pkg->application, _application_cb, pkg); - pkgmgr_parser_free_manifest_xml(pkg); - - return 0; -} - -static void _print_usage(const char *cmd) -{ - printf("usage: %s \n", cmd); -} - -int main(int argc, char *argv[]) -{ - if (getuid() != OWNER_ROOT && getuid() != GLOBAL_USER) { - printf("Only root or tizenglobalapp user is allowed\n"); - return -1; - } - - if (argc < 2) { - _print_usage(argv[0]); - return -1; - } - - return _install_ug(argv[1]); -} diff --git a/tool/pkg_privilege.c b/tool/pkg_privilege.c deleted file mode 100644 index 5eb411c..0000000 --- a/tool/pkg_privilege.c +++ /dev/null @@ -1,220 +0,0 @@ -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#define OWNER_ROOT 0 -#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) - -static const char *_get_pkg_root_path(const char *pkgid) -{ - const char *path; - uid_t uid = getuid(); - - tzplatform_set_user(uid); - path = tzplatform_mkpath((uid == OWNER_ROOT || uid == GLOBAL_USER) ? - TZ_SYS_RO_APP : TZ_USER_APP, pkgid); - tzplatform_reset_user(); - - return path; -} - -struct path_type { - const char *path; - enum app_install_path_type type; -}; - -struct path_type path_type_map[] = { - {"/", SECURITY_MANAGER_PATH_PUBLIC_RO}, - {"/bin", SECURITY_MANAGER_PATH_RO}, - {"/data", SECURITY_MANAGER_PATH_RW}, - {"/cache", SECURITY_MANAGER_PATH_RW}, - {"/lib", SECURITY_MANAGER_PATH_RO}, - {"/res", SECURITY_MANAGER_PATH_RO}, - {"/shared", SECURITY_MANAGER_PATH_PUBLIC_RO}, - {NULL, SECURITY_MANAGER_ENUM_END} -}; - -static app_inst_req *_prepare_request(const char *pkgid, const char *appid) -{ - int ret; - app_inst_req *req; - const char *root_path; - char buf[PATH_MAX]; - int i; - - if (security_manager_app_inst_req_new(&req)) { - printf("security_manager_app_inst_req_new failed\n"); - return NULL; - } - - ret = security_manager_app_inst_req_set_pkg_id(req, pkgid); - if (ret != SECURITY_MANAGER_SUCCESS) { - printf("set pkgid failed: %d\n", ret); - security_manager_app_inst_req_free(req); - return NULL; - } - - ret = security_manager_app_inst_req_set_app_id(req, appid); - if (ret != SECURITY_MANAGER_SUCCESS) { - printf("set appid failed: %d\n", ret); - security_manager_app_inst_req_free(req); - return NULL; - } - - root_path = _get_pkg_root_path(pkgid); - /* TODO: should be fixed */ - if (access(root_path, F_OK) == -1) { - printf("cannot find %s, but the smack rule for %s " - "will be installed\n", root_path, appid); - return req; - } - - for (i = 0; path_type_map[i].path; i++) { - snprintf(buf, sizeof(buf), "%s%s", root_path, - path_type_map[i].path); - if (access(buf, F_OK) == -1) - continue; - ret = security_manager_app_inst_req_add_path(req, buf, - path_type_map[i].type); - if (ret != SECURITY_MANAGER_SUCCESS) { - printf("set path failed: %d\n", ret); - security_manager_app_inst_req_free(req); - return NULL; - } - } - - return req; -} - -static void _insert_privilege_cb(gpointer data, gpointer user_data) -{ - const char *privilege = (const char *)data; - app_inst_req *req = (app_inst_req *)user_data; - - security_manager_app_inst_req_add_privilege(req, privilege); -} - -/* NOTE: We cannot use cert-svc api which checks signature level in this tool, - * because cert-svc does not provide c apis in Tizen 3.0. - * So we set default privilege as platform level temporarily. - */ -#define DEFAULT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/internal/default/public" -#define DEFAULT_PRIVILEGE_PARTNER "http://tizen.org/privilege/internal/default/partner" -#define DEFAULT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform" -static void _insert_application_cb(gpointer data, gpointer user_data) -{ - int ret; - app_inst_req *req; - application_x *app = (application_x *)data; - package_x *pkg = (package_x *)user_data; - - req = _prepare_request(pkg->package, app->appid); - if (req == NULL) { - printf("out of memory\n"); - return; - } - - if (getuid() == OWNER_ROOT) { - security_manager_app_inst_req_add_privilege(req, - DEFAULT_PRIVILEGE_PUBLIC); - security_manager_app_inst_req_add_privilege(req, - DEFAULT_PRIVILEGE_PARTNER); - security_manager_app_inst_req_add_privilege(req, - DEFAULT_PRIVILEGE_PLATFORM); - } - - g_list_foreach(pkg->privileges, _insert_privilege_cb, (gpointer)req); - - ret = security_manager_app_install(req); - if (ret != SECURITY_MANAGER_SUCCESS) - printf("app install failed: %d\n", ret); - security_manager_app_inst_req_free(req); -} - -static int _insert_privilege(char *manifest) -{ - package_x *pkg; - - pkg = pkgmgr_parser_process_manifest_xml(manifest); - if (pkg == NULL) { - printf("Parse manifest failed\n"); - return -1; - } - - g_list_foreach(pkg->application, _insert_application_cb, (gpointer)pkg); - pkgmgr_parser_free_manifest_xml(pkg); - - return 0; -} - -static void _remove_application_cb(gpointer data, gpointer user_data) -{ - int ret; - app_inst_req *req; - application_x *app = (application_x *)data; - package_x *pkg = (package_x *)user_data; - - req = _prepare_request(pkg->package, app->appid); - if (req == NULL) { - printf("out of memory\n"); - return; - } - - ret = security_manager_app_uninstall(req); - if (ret != SECURITY_MANAGER_SUCCESS) - printf("app uninstall failed: %d\n", ret); - - security_manager_app_inst_req_free(req); -} - -static int _remove_privilege(char *manifest) -{ - package_x *pkg; - - pkg = pkgmgr_parser_process_manifest_xml(manifest); - if (pkg == NULL) { - printf("Parse manifest failed\n"); - return -1; - } - - g_list_foreach(pkg->application, _remove_application_cb, (gpointer)pkg); - pkgmgr_parser_free_manifest_xml(pkg); - - return 0; -} - -static void _print_usage(const char *cmd) -{ - printf("usage: %s