update issues
authorjunsuk77.oh <junsuk77.oh@samsung.com>
Mon, 15 Apr 2013 05:25:18 +0000 (14:25 +0900)
committerjunsuk77.oh <junsuk77.oh@samsung.com>
Mon, 15 Apr 2013 08:11:43 +0000 (17:11 +0900)
1. implement csc process
2. fix pkgcmd error message string, result
3. fix prevent

Change-Id: I6c47bba46091300752b298ff2b8ac98e27ddec61
Signed-off-by: junsuk77.oh <junsuk77.oh@samsung.com>
CMakeLists.txt
client/include/package-manager.h
client/src/pkgmgr.c
packaging/pkgmgr.spec
tool/pkg_cmd.c
tool/pkg_info.c

index fc707f6..d7f090b 100755 (executable)
@@ -23,13 +23,13 @@ set(CMAKE_SKIP_BUILD_RPATH true)
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/comm )
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED security-server dlog elementary evas ecore appcore-efl ecore-x ail ecore-file pkgmgr-info)
+pkg_check_modules(pkgs REQUIRED security-server dlog elementary evas ecore appcore-efl ecore-x ail ecore-file pkgmgr-info iniparser)
 
 FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-pkg_check_modules(libpkgs REQUIRED dbus-glib-1 dlog ail pkgmgr-info)
+pkg_check_modules(libpkgs REQUIRED dbus-glib-1 dlog ail pkgmgr-info iniparser)
 
 FOREACH(flag ${libpkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
index b7212b9..3ee7dbe 100755 (executable)
@@ -205,6 +205,13 @@ typedef enum {
        PM_DISTRIBUTOR2_SIGNER_CERT = 8,
 }pkgmgr_cert_type;
 
+typedef enum {
+       PM_REQUEST_CSC = 0,
+       PM_REQUEST_MOVE = 1,
+       PM_REQUEST_GET_SIZE = 2,
+       PM_REQUEST_MAX
+}pkgmgr_request_service_type;
+
 /**
  * @brief      This API creates pkgmgr client.
  *
@@ -456,6 +463,29 @@ pkgmgr_info *pkgmgr_client_check_pkginfo_from_file(const char *pkg_path);
 int pkgmgr_client_free_pkginfo(pkgmgr_info * pkg_info);
 
 /**
+ * @brief      This API installs package.
+ *
+ * This API is for package-manager client application.\n
+ *
+ * @param[in]  service_type            pkgmgr_request_service_type
+ * @param[in]  pc                              pkgmgr_client
+ * @param[in]  pkg_type                package type
+ * @param[in]  pkgid                   package id
+ * @param[in]  optional_file           optional file which is used for checking
+ * @param[in]  optional_mode   optional mode which is used for checking
+ * @param[in]  event_cb                user callback
+ * @param[in]  data                    user data
+ * @return     request_id (>0) if success, error code(<0) if fail\n
+ * @retval     PKGMGR_R_OK     success
+ * @retval     PKGMGR_R_EINVAL invalid argument
+ * @retval     PKGMGR_R_ECOMM  communication error
+*/
+int pkgmgr_client_request_service(pkgmgr_request_service_type service_type,
+                                       pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
+                                       const char *optional_file, void *optional_mode,
+                                       pkgmgr_handler event_cb, void *data);
+
+/**
  * @brief      This API provides package list
  *
  * This API is for package-manager client application.\n
index 8b31a98..28de124 100755 (executable)
@@ -36,6 +36,7 @@
 #include <vconf.h>
 #include <db-util.h>
 #include <pkgmgr-info.h>
+#include <iniparser.h>
 
 #include "package-manager.h"
 #include "pkgmgr-internal.h"
@@ -88,6 +89,131 @@ typedef struct _iter_data {
        void *data;
 } iter_data;
 
+typedef struct _csc_info {
+       int                             count ;                 /** Number of csc packages */
+       char            **      type ;                  /** package type */
+       char            **  description ;       /** description */
+} csc_info ;
+
+static int __xsystem(const char *argv[])
+{
+       int status = 0;
+       pid_t pid;
+       pid = fork();
+       switch (pid) {
+       case -1:
+               perror("fork failed");
+               return -1;
+       case 0:
+               /* child */
+               execvp(argv[0], (char *const *)argv);
+               _exit(-1);
+       default:
+               /* parent */
+               break;
+       }
+       if (waitpid(pid, &status, 0) == -1) {
+               perror("waitpid failed");
+               return -1;
+       }
+       if (WIFSIGNALED(status)) {
+               perror("signal");
+               return -1;
+       }
+       if (!WIFEXITED(status)) {
+               /* shouldn't happen */
+               perror("should not happen");
+               return -1;
+       }
+       return WEXITSTATUS(status);
+}
+
+static int __csc_process(const char *csc_path, const char *result_path)
+{
+       int ret = 0;
+       int cnt = 0;
+       int count = 0;
+       int csc_fail = 0;
+       int fd = 0;
+       char *pkgtype = NULL;
+       char *des = NULL;
+       char buf[PKG_STRING_LEN_MAX] = {0,};
+       char type_buf[1024] = { 0 };
+       char des_buf[1024] = { 0 };
+       csc_info *csc = NULL;
+       FILE* file = NULL;
+
+       csc = iniparser_load(csc_path);
+       retvm_if(csc == NULL, PKGMGR_R_EINVAL, "cannot open parse file [%s]", csc_path);
+
+       file = fopen(result_path, "w");
+       retvm_if(file == NULL, PKGMGR_R_EINVAL, "cannot open result file [%s]", result_path);
+
+       count = iniparser_getint(csc, "csc packages:count", -1);
+       retvm_if(count == 0, PKGMGR_R_ERROR, "csc [%s] dont have packages", csc_path);
+
+       snprintf(buf, PKG_STRING_LEN_MAX, "[csc %d packages]\n", count);
+       fwrite(buf, 1, strlen(buf), file);
+
+       for(cnt = 1 ; cnt <= count ; cnt++)
+       {
+               snprintf(type_buf, PKG_STRING_LEN_MAX - 1, "csc packages:type_%03d", cnt);
+               snprintf(des_buf, PKG_STRING_LEN_MAX - 1, "csc packages:description_%03d", cnt);
+
+               pkgtype = iniparser_getstr(csc, type_buf);
+               des = iniparser_getstr(csc, des_buf);
+               ret = 0;
+
+               if (pkgtype == NULL) {
+                       csc_fail++;
+                       snprintf(buf, PKG_STRING_LEN_MAX, "[%03d]Fail to get information[%s]\n", cnt, type_buf);
+                       fwrite(buf, 1, strlen(buf), file);
+                       continue;
+               } else if (des == NULL) {
+                       csc_fail++;
+                       snprintf(buf, PKG_STRING_LEN_MAX, "[%03d]Fail to get information[%s]\n", cnt, des_buf);
+                       fwrite(buf, 1, strlen(buf), file);
+                       continue;
+               }
+
+               if (strcmp(pkgtype, "tpk") == 0) {
+                       const char *ospinstaller_argv[] = { "/usr/bin/osp-installer", "-c", des, NULL };
+                       ret = __xsystem(ospinstaller_argv);
+               } else if (strcmp(pkgtype, "wgt")== 0) {
+                       const char *wrtinstaller_argv[] = { "/usr/bin/wrt-installer", "-c", des, NULL };
+                       ret = __xsystem(wrtinstaller_argv);
+               } else {
+                       csc_fail++;
+                       ret = -1;
+               }
+
+               if (ret != 0)
+                       snprintf(buf, PKG_STRING_LEN_MAX, "[%03d][%s] csc result : Fail\n", cnt, pkgtype);
+               else
+                       snprintf(buf, PKG_STRING_LEN_MAX, "[%03d][%s] csc result : Sucess\n", cnt, pkgtype);
+
+               fwrite(buf, 1, strlen(buf), file);
+       }
+
+       if (csc_fail > 0) {
+               ret = PKGMGR_R_ERROR;
+               snprintf(buf, PKG_STRING_LEN_MAX, "[csc result] total : [%d], sucess : [%d]packages, fail : [%d]packages\n", count,  count-csc_fail, csc_fail);
+
+       } else {
+               ret = PKGMGR_R_OK;
+               snprintf(buf, PKG_STRING_LEN_MAX, "[csc result] total : [%d], sucess : all packages\n", count);
+
+       }
+       fwrite(buf, 1, strlen(buf), file);
+
+       iniparser_freedict(csc);
+       fflush(file);
+       fd = fileno(file);
+       fsync(fd);
+       fclose(file);
+
+       return ret;
+}
 
 static void __add_op_cbinfo(pkgmgr_client_t * pc, int request_id,
                            const char *req_key, pkgmgr_handler event_cb,
@@ -1497,6 +1623,58 @@ API int pkgmgr_client_free_pkginfo(pkgmgr_info * pkg_info)
        return PKGMGR_R_OK;
 }
 
+API int pkgmgr_client_request_service(pkgmgr_request_service_type service_type, 
+                                 pkgmgr_client * pc, const char *pkg_type, const char *pkgid,
+                             const char *optional_file, void *optional_mode,
+                             pkgmgr_handler event_cb, void *data)
+{
+       char *installer_path;
+       char *req_key;
+       int req_id;
+       int ret;
+
+       /* Check for NULL value of service type */
+       retvm_if(service_type > PM_REQUEST_MAX, PKGMGR_R_EINVAL, "service type is not defined\n");
+
+       /* check optional_file length */
+       if (optional_file)
+               retvm_if(strlen(optional_file) >= PKG_STRING_LEN_MAX, PKGMGR_R_EINVAL, "optional_file over PKG_STRING_LEN_MAX");
+
+       /* add callback info - add callback info to pkgmgr_client if there is pc and pkgid */
+       if (pc && pkgid) {
+               pkgmgr_client_t *mpc = (pkgmgr_client_t *) pc;
+               retv_if(mpc->ctype != PC_REQUEST, PKGMGR_R_EINVAL);
+               req_key = __get_req_key(pkgid);
+               req_id = _get_request_id();
+               __add_op_cbinfo(mpc, req_id, req_key, event_cb, data);
+       }
+
+       switch (service_type) {
+       case PM_REQUEST_CSC:
+               ret = __csc_process(optional_file, (char *)data);
+               if (ret < 0)
+                       _LOGE("__csc_process fail \n");
+               break;
+
+       case PM_REQUEST_MOVE:
+               ret = 0;
+               break;
+
+       case PM_REQUEST_GET_SIZE:
+               ret = 0;
+               break;
+
+       default:
+               printf("Wrong Request\n");
+               ret = -1;
+               break;
+       }
+
+       return req_id;
+}
+
+
+#define __START_OF_OLD_API
 ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
 {
        char *type;
@@ -1521,10 +1699,6 @@ ail_cb_ret_e __appinfo_func(const ail_appinfo_h appinfo, void *user_data)
        return AIL_CB_RET_CONTINUE;
 }
 
-
-
-#define __START_OF_OLD_API
-
 API int pkgmgr_get_pkg_list(pkgmgr_iter_fn iter_fn, void *data)
 {
        int cnt = -1;
index ad6a9da..608fc8f 100755 (executable)
@@ -1,7 +1,7 @@
 #sbs-git:slp/pkgs/s/slp-pkgmgr pkgmgr 0.1.103 29b53909a5d6e8728429f0a188177eac691cb6ce
 Name:       pkgmgr
 Summary:    Packager Manager client library package
-Version:    0.2.74
+Version:    0.2.75
 Release:    1
 Group:      System/Libraries
 License:    Apache License, Version 2.0
@@ -17,6 +17,7 @@ BuildRequires:  pkgconfig(ail)
 BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(appcore-efl)
 BuildRequires:  pkgconfig(pkgmgr-info)
+BuildRequires:  pkgconfig(iniparser)
 BuildRequires:  pkgmgr-info-parser-devel
 BuildRequires:  pkgmgr-info-parser
 
index 2ed4198..ec71eaf 100755 (executable)
@@ -108,7 +108,7 @@ static int __pkgcmd_proc_iter_kill_cmdline(const char *apppath, int option);
 static int __app_list_cb(const pkgmgr_appinfo_h handle, void *user_data);
 
 /* Supported options */
-const char *short_options = "iurmcCkaADL:lsd:p:t:n:T:qh";
+const char *short_options = "iurmcCkaADL:lsd:p:t:n:T:S:qh";
 const struct option long_options[] = {
        {"install", 0, NULL, 'i'},
        {"uninstall", 0, NULL, 'u'},
@@ -128,6 +128,7 @@ const struct option long_options[] = {
        {"package-type", 1, NULL, 't'},
        {"package-name", 1, NULL, 'n'},
        {"move-type", 1, NULL, 'T'},
+       {"csc", 1, NULL, 'S'},
        {"quiet", 0, NULL, 'q'},
        {"help", 0, NULL, 'h'},
        {0, 0, 0, 0}            /* sentinel */
@@ -137,6 +138,7 @@ enum pm_tool_request_e {
        INSTALL_REQ = 1,
        UNINSTALL_REQ,
        REINSTALL_REQ,
+       CSC_REQ,
        CLEAR_REQ,
        MOVE_REQ,
        ACTIVATE_REQ,
@@ -244,13 +246,25 @@ static int __return_cb(int req_id, const char *pkg_type,
        if (strncmp(key, "error", strlen("error")) == 0) {
                int ret_val;
                char *errstr = NULL;
+               char delims[] = ":";
+               char *extra_str = NULL;
+               char *ret_result = NULL;
 
                ret_val = atoi(val);
                __error_no_to_string(ret_val, &errstr);
                data.result = ret_val;
 
-               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, errstr);
+               ret_result = strtok(val, delims);
+               ret_result = strtok(NULL, 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:%s\n",
+                                          req_id, pkg_type, pkgid, key, ret_val, errstr, extra_str);
+                       free(extra_str);
+               }
+               else
+                       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, errstr);
        } else
                printf("__return_cb req_id[%d] pkg_type[%s] "
                       "pkgid[%s] key[%s] val[%s]\n",
@@ -923,19 +937,22 @@ static int __process_request()
                ret = pkgmgr_pkginfo_get_pkginfo(data.pkgid, &handle);
                if (ret < 0) {
                        printf("Failed to get handle\n");
-                       return -1;
+                       data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
+                       return  0;
                }
                ret = pkgmgr_appinfo_get_list(handle, PM_UI_APP, __app_list_cb, NULL);
                if (ret < 0) {
                        printf("pkgmgr_appinfo_get_list() failed\n");
                        pkgmgr_pkginfo_destroy_pkginfo(handle);
-                       return -1;
+                       data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
+                       return  0;
                }
                ret = pkgmgr_appinfo_get_list(handle, PM_SVC_APP, __app_list_cb, NULL);
                if (ret < 0) {
                        printf("pkgmgr_appinfo_get_list() failed\n");
                        pkgmgr_pkginfo_destroy_pkginfo(handle);
-                       return -1;
+                       data.result = PKGCMD_ERR_PACKAGE_NOT_FOUND;
+                       return  0;
                }
                pkgmgr_pkginfo_destroy_pkginfo(handle);
                ret = 0;
@@ -1002,6 +1019,12 @@ static int __process_request()
                ret = -1;
                break;
 
+       case CSC_REQ:
+               ret = pkgmgr_client_request_service(PM_REQUEST_CSC, NULL, NULL, NULL, data.des_path, NULL, NULL, (void *)data.pkg_path);
+               if (ret < 0)
+                       data.result = PKGCMD_ERR_FATAL_ERROR;
+               break;
+
        case HELP_REQ:
                __print_usage();
                ret = 0;
@@ -1090,6 +1113,13 @@ int main(int argc, char *argv[])
                        data.request = MOVE_REQ;
                        break;
 
+               case 'S': /* csc packages */
+                       data.request = CSC_REQ;
+                       if (optarg)
+                               strncpy(data.des_path, optarg, PKG_NAME_STRING_LEN_MAX);
+                       printf("csc file is %s\n", data.des_path);
+                       break;
+
                case 'A':       /* activate */
                        data.request = ACTIVATE_REQ;
                        break;
@@ -1134,7 +1164,7 @@ int main(int argc, char *argv[])
                                printf("conversion of relative path to absolute path failed\n");
                                return -1;
                        }
-                       printf("package path is %s\n", data.pkg_path);
+                       printf("path is %s\n", data.pkg_path);
                        break;
 
                case 'd':       /* descriptor path */
@@ -1181,7 +1211,7 @@ int main(int argc, char *argv[])
                }
        }
        ret = __process_request();
-       if (ret == -1)
+       if ((ret == -1) && (data.result != 0))
                data.result = PKGCMD_ERR_ARGUMENT_INVALID;
 
        if (ret != 0) {
index dba3643..1237297 100755 (executable)
@@ -79,6 +79,8 @@ int __get_app_id(const pkgmgrinfo_appinfo_h handle, void *user_data)
                printf("Failed to get package\n");
        }
        printf("apptype [%s]\t appid [%s]\n", apptype, appid);
+
+       return 0;
 }
 
 static int __get_integer_input_data(void)