fix missing encoded_id related change & code clearing. 03/72503/7 accepted/tizen/common/20160606.141600 accepted/tizen/ivi/20160602.230739 accepted/tizen/mobile/20160602.230720 accepted/tizen/tv/20160602.230702 accepted/tizen/wearable/20160602.230637 submit/tizen/20160602.040935
authorjongmyeongko <jongmyeong.ko@samsung.com>
Wed, 1 Jun 2016 08:52:53 +0000 (17:52 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Thu, 2 Jun 2016 07:52:33 +0000 (16:52 +0900)
Change-Id: I4f653ec89c0ab5396678e859192e569f4a47d57e
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
16 files changed:
CMakeLists.txt
common/inc/app2ext_utils.h [new file with mode: 0644]
common/src/app2ext_utils.c [new file with mode: 0644]
inc/app2ext_interface.h
plugin/app2sd/CMakeLists.txt
plugin/app2sd/inc/app2sd_client_interface.h
plugin/app2sd/inc/app2sd_interface.h
plugin/app2sd/inc/app2sd_internals.h
plugin/app2sd/src/app2sd_client_interface.c
plugin/app2sd/src/app2sd_interface.c
plugin/app2sd/src/app2sd_internals.c
plugin/app2sd/src/app2sd_internals_registry.c
plugin/app2sd/src/app2sd_internals_utils.c
plugin/app2sd/src/app2sd_server.c
src/app2ext_interface.c
test/src/test_app2ext.c

index a51a703..6731fb7 100644 (file)
@@ -25,16 +25,18 @@ ENDFOREACH(flag)
 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ### Local include directories
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc ${CMAKE_SOURCE_DIR}/src)
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc
+       ${CMAKE_SOURCE_DIR}/common/inc)
 
 ## build app2ext library
 SET(app2ext_dir "${CMAKE_SOURCE_DIR}")
-SET(app2ext_inc_dir "${app2ext_dir}/inc")
 SET(app2ext_src_dir "${app2ext_dir}/src")
 SET(APP2EXT "app2ext")
-SET(libapp2ext_SOURCES ${app2ext_src_dir}/app2ext_interface.c)
+SET(libapp2ext_SOURCES
+       ${app2ext_src_dir}/app2ext_interface.c
+       ${CMAKE_SOURCE_DIR}/common/src/app2ext_utils.c)
 SET(libapp2ext_LDFLAGS " -L${LIB_INSTALL_DIR} -module -avoid-version -ldl ")
-SET(libapp2ext_CFLAGS  " ${CFLAGS} -fPIC -I${app2ext_inc_dir} ")
+SET(libapp2ext_CFLAGS  " ${CFLAGS} -fPIC ")
 
 ADD_DEFINITIONS("-DLIBPREFIX=\"${LIB_INSTALL_DIR}\"")
 
diff --git a/common/inc/app2ext_utils.h b/common/inc/app2ext_utils.h
new file mode 100644 (file)
index 0000000..f97d12b
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * app2ext
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _APP2EXT_UTILS_H
+#define _APP2EXT_UTILS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+#ifndef _DEFAULT_SOURCE
+#define _DEFAULT_SOURCE
+#endif
+
+#include <dlog.h>
+#include <glib.h>
+#include <tzplatform_config.h>
+
+#define _E(fmt, arg...) LOGE(fmt, ##arg)
+#define _D(fmt, arg...) LOGD(fmt, ##arg)
+#define _W(fmt, arg...) LOGW(fmt, ##arg)
+#define _I(fmt, arg...) LOGI(fmt, ##arg)
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "APP2EXT"
+
+#define APP2EXT_SUCCESS 0
+
+#define OWNER_ROOT 0
+#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+#define MMC_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1")
+#define APP2SD_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1/app2sd")
+
+#define APP2SD_BUS_NAME "org.tizen.app2sd"
+#define APP2SD_OBJECT_PATH "/org/tizen/app2sd"
+#define APP2SD_INTERFACE_NAME "org.tizen.app2sd"
+
+int _is_global(uid_t uid);
+char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/common/src/app2ext_utils.c b/common/src/app2ext_utils.c
new file mode 100644 (file)
index 0000000..bec4c2c
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * app2ext
+ *
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "app2ext_utils.h"
+
+int _is_global(uid_t uid)
+{
+       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
+               return 1;
+       else
+               return 0;
+}
+
+char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid)
+{
+       char *new_name = NULL;
+       char *temp_string = NULL;
+       char source_name[FILENAME_MAX] = { 0, };
+       GChecksum *checksum;
+
+       snprintf(source_name, FILENAME_MAX - 1, "%s_%d", pkgid, uid);
+       checksum = g_checksum_new(G_CHECKSUM_MD5);
+       g_checksum_update(checksum, (const guchar *)source_name, strlen(source_name));
+       temp_string = (char *)g_checksum_get_string(checksum);
+       _D("temp_string(%s)", temp_string);
+       new_name = strdup(temp_string);
+       g_checksum_free(checksum);
+
+       _D("new_name(%s)", new_name);
+
+       return new_name;
+}
index 92d319e..77bea37 100644 (file)
@@ -27,6 +27,7 @@
  * @version 0.5
  * @brief    This file declares API of app2ext library
  */
+
 /**
  * @addtogroup APPLICATION_FRAMEWORK
  * @{
@@ -49,34 +50,8 @@ extern "C" {
 #define API __attribute__ ((visibility("default")))
 #endif
 
-#include <dlog/dlog.h>
 #include <glib.h>
 
-/* for multi-user support */
-#include <tzplatform_config.h>
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-
-#define LOG_TAG "APP2EXT"
-
-#define _E(fmt, arg...) LOGE(fmt, ##arg)
-#define _D(fmt, arg...) LOGD(fmt, ##arg)
-#define _W(fmt, arg...) LOGW(fmt, ##arg)
-#define _I(fmt, arg...) LOGI(fmt, ##arg)
-
-#define APP2EXT_SUCCESS 0
-
-#define OWNER_ROOT 0
-#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-#define MMC_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1")
-#define APP2SD_PATH tzplatform_mkpath(TZ_SYS_MEDIA, "SDCardA1/app2sd")
-
-#define APP2SD_BUS_NAME "org.tizen.app2sd"
-#define APP2SD_OBJECT_PATH "/org/tizen/app2sd"
-#define APP2SD_INTERFACE_NAME "org.tizen.app2sd"
-
 /**
  * Enum for application installation location
  */
@@ -110,7 +85,7 @@ typedef enum app2ext_dir_type_t {
  */
 typedef enum app2ext_move_type_t {
        APP2EXT_MOVE_TO_EXT = 1,
-       APP2EXT_MOVE_TO_PHONE
+       APP2EXT_MOVE_TO_PHONE,
 } app2ext_move_type;
 
 /**
@@ -318,7 +293,7 @@ typedef int (*app2ext_client_force_clean)(const char *pkgid);
 /**
  * This structure defines the app2ext interfaces. Plugins have to implement these functions
  */
-typedef struct app2ext_interface_t{
+typedef struct app2ext_interface_t {
        /* for library function */
        app2ext_client_pre_install              client_pre_install;
        app2ext_client_post_install             client_post_install;
@@ -361,8 +336,8 @@ typedef struct {
  * type                        : permission (rw/ro)
  */
 typedef struct {
-       char *          name;
-       app2ext_dir_type        type;
+       char                    *name;
+       app2ext_dir_type        type;
 } app2ext_dir_details;
 
 /**
@@ -372,36 +347,6 @@ typedef struct {
  *                             [Ex: SD card, MicroUSB, Cloud]
  * @return     app2ext_handle pointer if success, NULL if fail
  *
- @code
- #include <app2ext_interface.h>
- app2ext_handle *handle = NULL;
- GLIst *dir_list = NULL;
- handle = app2ext_init(APP2EXT_SD_CARD); //Initializes SD card plug-in
- if(handle)
- {
-       printf("\n SUCCESS");
-       // Perform package install/uninstall/upgrade/move here
-       // Packge install example
-       // Package manager should polulate dir_list with directory structure information of the package
-       ret = handle->interface.pre_install("com.samsung.calculator", dir_list, 20);
-       if (ret) {
-               printf("\n TC : pre app install API fail. Reason %s", error_list[ret]);
-               return -1;
-       }
-
-       // Package manager installs the package
-
-       ret = handle->interface.post_install("com.samsung.calculator", APP2EXT_STATUS_SUCCESS);
-       if (ret) {
-               printf("\n TC : post app install API fail Reason %s", error_list[ret]);
-
-               return -1;
-       }
-       // Package manager should free dir_list
-       return;
- } else
-        printf("\n FAILURE");
- @endcode
  */
 API app2ext_handle *app2ext_init(int storage_type);
 
@@ -410,21 +355,8 @@ API app2ext_handle *app2ext_init(int storage_type);
  *         This should be called when use of the plugin is completed
  * @param[in] handle   pointer to app2ext_handle which is to be deinitialized
  * @pre                Initialization is done for the storage handle
- * @return     0 if success,  error code(>0) if fail
+ * @return     0 if success,  error < 0 if fail
  *
- @code
- #include <app2ext_interface.h>
- app2ext_handle *handle = NULL;
- handle = app2ext_init(APP2EXT_SD_CARD); //Initializes SD card plug-in
- int ret = -1;
- ret = app2ext_deinit(handle); // De-initializes the SD plugin
- if(!ret)
- {
-        printf("\n SUCCESS");
- }
- else
- printf("\n FAILURE");
- @endcode
  */
 API int app2ext_deinit(app2ext_handle *handle);
 
@@ -434,8 +366,9 @@ API int app2ext_deinit(app2ext_handle *handle);
  * @param[in] pkgid    package id
  * @param[in] uid      target user id of this instruction
  * @return     APP2EXT_SD_CARD if pkg is in SD card,
- *             APP2EXT_INTERNAL_MEM if app is in internal memory
- *             error code(>0) if fail
+ *             APP2EXT_INTERNAL_MEM if pkg is in internal memory,
+ *             APP2EXT_NOT_INSTALLED if there is no valid pkg path
+ *             error < 0 if fail
  *@remarks see app2ext_install_location for more details
  */
 API int app2ext_get_app_location(const char *pkgid);
index aa4c38c..eb0866f 100644 (file)
@@ -20,10 +20,10 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
 
 ### Local include directories
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/inc
-               ${CMAKE_SOURCE_DIR}/src)
+       ${CMAKE_SOURCE_DIR}/common/inc
+       ${CMAKE_SOURCE_DIR}/plugin/app2sd/inc)
 
 SET(app2sd_dir "${CMAKE_SOURCE_DIR}/plugin/app2sd")
-SET(app2sd_inc_dir "${app2sd_dir}/inc")
 SET(app2sd_src_dir "${app2sd_dir}/src")
 
 ## build app2sd library
@@ -31,7 +31,7 @@ SET(APP2SD "app2sd")
 SET(libapp2sd_SOURCES
        ${app2sd_src_dir}/app2sd_client_interface.c)
 SET(libapp2sd_LDFLAGS " -L${LIB_INSTALL_DIR} -lcrypto -module -avoid-version ")
-SET(libapp2sd_CFLAGS  " ${CFLAGS} -fPIC -I${app2sd_inc_dir} ")
+SET(libapp2sd_CFLAGS  " ${CFLAGS} -fPIC ")
 
 ADD_LIBRARY(${APP2SD} SHARED ${libapp2sd_SOURCES})
 SET_TARGET_PROPERTIES(${APP2SD} PROPERTIES SOVERSION ${VERSION_MAJOR})
@@ -53,9 +53,10 @@ SET(app2sd_server_SOURCES
        ${app2sd_src_dir}/app2sd_interface.c
        ${app2sd_src_dir}/app2sd_internals_registry.c
        ${app2sd_src_dir}/app2sd_internals_utils.c
-       ${app2sd_src_dir}/app2sd_server.c)
+       ${app2sd_src_dir}/app2sd_server.c
+       ${CMAKE_SOURCE_DIR}/common/src/app2ext_utils.c)
 ADD_EXECUTABLE(${APP2SD_SERVER} ${app2sd_server_SOURCES})
-SET_TARGET_PROPERTIES(${APP2SD_SERVER} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE -I${app2sd_inc_dir} ")
+SET_TARGET_PROPERTIES(${APP2SD_SERVER} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE ")
 SET_TARGET_PROPERTIES(${APP2SD_SERVER} PROPERTIES LINK_FLAGS "-pie")
 TARGET_LINK_LIBRARIES(${APP2SD_SERVER} app2sd ${pkgs_LDFLAGS})
 
index 48fed42..ede5655 100644 (file)
@@ -50,7 +50,7 @@
 extern "C" {
 #endif
 
-#include <app2ext_interface.h>
+#include "app2ext_interface.h"
 
 /**
  * @brief : This API prepares the setup for installation in SD card.
index 6b96462..23258e9 100644 (file)
@@ -28,7 +28,8 @@
 extern "C" {
 #endif
 
-#include <app2ext_interface.h>
+#include "app2ext_interface.h"
+#include "app2ext_utils.h"
 
 int app2sd_usr_pre_app_install(const char *pkgid,
                GList* dir_list, int size, uid_t uid);
index 1ee6274..1fa40cb 100644 (file)
 
 /*Include Headers*/
 #include <stdio.h>
+#include <stdlib.h>
 #include <fcntl.h>
-#include <errno.h>
 #include <string.h>
 #include <stdarg.h>
 #include <dirent.h>
 #include <unistd.h>
-#include <malloc.h>
-#include <stdlib.h>
 #include <sys/stat.h>
+#include <sys/statvfs.h>
 #include <sys/types.h>
-#include <errno.h>
 #include <sys/mount.h>
-#include <app2sd_interface.h>
+#include <sys/wait.h>
+#include <sys/xattr.h>
+#include <malloc.h>
 #include <math.h>
+#include <errno.h>
+
+#include "app2sd_interface.h"
 
 #define DIR_PERMS (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
 
@@ -185,8 +188,4 @@ int _app2sd_set_password_in_db(const char *pkgid, const char *passwd);
 /* This functions make result file */
 void _app2sd_make_result_info_file(char *pkgid, int size, uid_t uid);
 
-int _is_global(uid_t uid);
-
-char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid);
-
 #endif
index 9e1dff2..2c31350 100644 (file)
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <glib.h>
 #include <gio/gio.h>
-#include <app2sd_client_interface.h>
+
+#include "app2sd_client_interface.h"
+#include "app2ext_utils.h"
 
 static int app2sd_gdbus_shared_connection(GDBusConnection **connection)
 {
index b9e30c1..3aa8d01 100644 (file)
  *
  */
 
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 #include <pkgmgr-info.h>
 
+#include "app2sd_internals.h"
+
 static int __app2sd_create_app2sd_directories(uid_t uid)
 {
        int ret = 0;
@@ -108,8 +105,6 @@ int app2sd_usr_pre_app_install(const char *pkgid, GList* dir_list, int size, uid
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        ret = __app2sd_create_app2sd_directories(uid);
        if (ret) {
@@ -247,8 +242,6 @@ int app2sd_usr_post_app_install(const char *pkgid,
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        /* get the associated device node for SD card applicationer */
        device_name = _app2sd_find_associated_device_node(loopback_device);
@@ -360,8 +353,6 @@ int app2sd_usr_on_demand_setup_init(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        fp = fopen(loopback_device, "r+");
        if (fp == NULL) {
@@ -447,8 +438,6 @@ int app2sd_usr_on_demand_setup_exit(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        fp = fopen(loopback_device, "r+");
        if (fp == NULL) {
@@ -514,8 +503,6 @@ int app2sd_usr_pre_app_uninstall(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        /* check app entry is there in sd card or not. */
        fp = fopen(loopback_device, "r+");
@@ -614,8 +601,6 @@ int app2sd_usr_post_app_uninstall(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        /* unmount the loopback encrypted pseudo device from
         * the application installation path
@@ -793,8 +778,6 @@ int app2sd_usr_pre_app_upgrade(const char *pkgid, GList* dir_list,
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        /* check app entry is there in sd card or not. */
        fp = fopen(loopback_device, "r+");
@@ -981,8 +964,6 @@ int app2sd_usr_post_app_upgrade(const char *pkgid,
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        /* get the associated device node for SD card applicationer */
        device_name = _app2sd_find_associated_device_node(loopback_device);
@@ -1026,8 +1007,6 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
        char *encoded_id = NULL;
        int ret = APP2EXT_SUCCESS;
 
-       _D("start force_clean [%s]", pkgid);
-
        /* validate the function parameter recieved */
        if (pkgid == NULL) {
                _E("invalid func parameters");
@@ -1054,8 +1033,6 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
                tzplatform_reset_user();
        }
        free(encoded_id);
-       _D("application_path = (%s)", application_path);
-       _D("loopback_device = (%s)", loopback_device);
 
        /* unmount the loopback encrypted pseudo device from the application installation path */
        ret = _app2sd_unmount_app_content(application_path);
@@ -1088,7 +1065,5 @@ int app2sd_usr_force_clean(const char *pkgid, uid_t uid)
                _E("cannot remove password from db");
        }
 
-       _D("finish force_clean");
-
        return 0;
 }
index 0050a25..21eddd2 100644 (file)
  *
  */
 
-#include <sys/xattr.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
 #include <dirent.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
 #include <openssl/sha.h>
-#include <fcntl.h>
 #include <time.h>
-#include <dlog.h>
-#include <sys/statvfs.h>
 #include <pwd.h>
 
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-
-int _is_global(uid_t uid)
-{
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               return 1;
-       else
-               return 0;
-}
+#include "app2sd_internals.h"
 
 static int _app2sd_setup_path(const char* path, const char *label, uid_t uid)
 {
index 6e817b4..8ac0cbf 100644 (file)
  *
  */
 
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
 #include <dirent.h>
-#include <sys/stat.h>
-#include <dlog.h>
 #include <time.h>
 #include <db-util.h>
-#include <tzplatform_config.h>
+
+#include "app2sd_internals.h"
 
 #define MAX_QUERY_LEN 4096
 #define PASSWORD_LENGTH 64
index 300f86b..9b51ca0 100644 (file)
  *
  */
 
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
 #include <dirent.h>
-#include <sys/stat.h>
 #include <time.h>
-#include <dlog.h>
-#include <sys/statvfs.h>
-#include <errno.h>
+
+#include "app2sd_internals.h"
 
 #define        PASSWD_LEN              21
 #define        ASCII_PASSWD_CHAR       93
@@ -646,23 +635,3 @@ char *_app2sd_generate_password(const char *pkgid)
 
        return ret_result;
 }
-
-char *_app2sd_get_encoded_name(const char *pkgid, uid_t uid)
-{
-       char *new_name = NULL;
-       char *temp_string = NULL;
-       char source_name[FILENAME_MAX] = { 0, };
-       GChecksum *checksum;
-
-       snprintf(source_name, FILENAME_MAX - 1, "%s_%d", pkgid, uid);
-       checksum = g_checksum_new(G_CHECKSUM_MD5);
-       g_checksum_update(checksum, (const guchar *)source_name, strlen(source_name));
-       temp_string = (char *)g_checksum_get_string(checksum);
-       _D("temp_string(%s)", temp_string);
-       new_name = strdup(temp_string);
-       g_checksum_free(checksum);
-
-       _D("new_name(%s)", new_name);
-
-       return new_name;
-}
index 4cfea99..1628df3 100644 (file)
  *
  */
 
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-#include <glib.h>
 #include <gio/gio.h>
 
+#include "app2sd_internals.h"
+
 GMainLoop *app2sd_mainloop = NULL;
 
 gboolean __exit_app2sd_server(void *data)
index 156fd41..d2c914e 100644 (file)
@@ -19,7 +19,6 @@
  *
  */
 
-#include <app2ext_interface.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <stdio.h>
 #include <dirent.h>
 
-#define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
+#include "app2ext_interface.h"
+#include "app2ext_utils.h"
 
-int _is_global(uid_t uid)
-{
-       if (uid == OWNER_ROOT || uid == GLOBAL_USER)
-               return 1;
-       else
-               return 0;
-}
+#define APP2EXT_SD_PLUGIN_PATH LIBPREFIX "/libapp2sd.so"
 
 app2ext_handle *app2ext_init(int storage_type)
 {
@@ -99,7 +93,7 @@ int app2ext_deinit(app2ext_handle *handle)
        /* validate the function parameter recieved */
        if (handle == NULL || handle->plugin_handle == NULL){
                _E("invalid function arguments");
-               return APP2EXT_ERROR_INVALID_ARGUMENTS;
+               return -1;
        }
 
        /* close the plugin handle*/
@@ -108,7 +102,7 @@ int app2ext_deinit(app2ext_handle *handle)
        /* free allocated memory during installtion*/
        free(handle);
 
-       return APP2EXT_SUCCESS;
+       return 0;
 }
 
 int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
@@ -117,11 +111,12 @@ int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
        char loopback_device[FILENAME_MAX] = { 0, };
        char application_path[FILENAME_MAX] = { 0, };
        char application_mmc_path[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
 
        /* validate the function parameter received */
        if (pkgid == NULL) {
                _E("invalid func parameters");
-               return APP2EXT_ERROR_INVALID_ARGUMENTS;
+               return -1;
        }
 
        if (_is_global(uid)) {
@@ -129,23 +124,23 @@ int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
                snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
                        tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
        } else {
                tzplatform_set_user(uid);
                snprintf(application_path, FILENAME_MAX - 1, "%s/%s",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
                snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
                        tzplatform_getenv(TZ_USER_APP), pkgid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
                tzplatform_reset_user();
        }
-       _D("application_path = (%s)", application_path);
-       _D("application_mmc_path = (%s)", application_mmc_path);
-       _D("loopback_device = (%s)", loopback_device);
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return -1;
+       }
+       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+               APP2SD_PATH, encoded_id);
+       free(encoded_id);
 
-       /*check whether application is in external memory or not */
+       /* check whether application is in external memory or not */
        fp = fopen(loopback_device, "r");
        if (fp != NULL) {
                fclose(fp);
@@ -154,7 +149,7 @@ int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
                return APP2EXT_SD_CARD;
        }
 
-       /*check whether application is in internal or not */
+       /* check whether application is in internal or not */
        fp = fopen(application_path, "r");
        if (fp == NULL) {
                _D("app_dir_path open failed, " \
@@ -173,10 +168,11 @@ int app2ext_usr_get_app_location(const char *pkgid, uid_t uid)
                        fclose(fp);
                        _E("app_mmc_internal_path exists, " \
                                "error mmc status");
-                       return APP2EXT_ERROR_MMC_STATUS;
+                       return -1;
                }
        }
 }
+
 int app2ext_get_app_location(const char *pkgid)
 {
        int ret = 0;
@@ -191,6 +187,7 @@ int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
        FILE *fp = NULL;
        app2ext_handle *app2_handle = NULL;
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
 
        /* validate the function parameter received */
        if (pkgid == NULL) {
@@ -198,17 +195,13 @@ int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
                return -1;
        }
 
-       if (_is_global(uid)) {
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
-       } else {
-               tzplatform_set_user(uid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
-               tzplatform_reset_user();
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return -1;
        }
-
-       _D("loopback_device = (%s)", loopback_device);
+       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+               APP2SD_PATH, encoded_id);
+       free(encoded_id);
 
        /* check whether application is in external memory or not */
        fp = fopen(loopback_device, "r");
@@ -219,14 +212,16 @@ int app2ext_usr_enable_external_pkg(const char *pkgid, uid_t uid)
                app2_handle = app2ext_init(APP2EXT_SD_CARD);
                if (app2_handle == NULL) {
                        _E("app2ext init failed");
-                       return -2;
+                       return -1;
                }
 
                app2_handle->interface.client_usr_enable(pkgid, uid);
                app2ext_deinit(app2_handle);
        }
+
        return 0;
 }
+
 int app2ext_enable_external_pkg(const char *pkgid)
 {
        int ret = 0;
@@ -241,24 +236,21 @@ int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
        FILE *fp = NULL;
        app2ext_handle *app2_handle = NULL;
        char loopback_device[FILENAME_MAX] = { 0, };
+       char *encoded_id = NULL;
 
        /* validate the function parameter received */
-       if (pkgid == NULL) {
+       if (pkgid == NULL || uid < 0) {
                _E("invalid func parameters");
                return -1;
        }
 
-       if (_is_global(uid)) {
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
-                       APP2SD_PATH, pkgid);
-       } else {
-               tzplatform_set_user(uid);
-               snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s/%s",
-                       APP2SD_PATH, tzplatform_getenv(TZ_USER_NAME), pkgid);
-               tzplatform_reset_user();
+       encoded_id = _app2sd_get_encoded_name(pkgid, uid);
+       if (encoded_id == NULL) {
+               return -1;
        }
-
-       _D("loopback_device = (%s)", loopback_device);
+       snprintf(loopback_device, FILENAME_MAX - 1, "%s/%s",
+               APP2SD_PATH, encoded_id);
+       free(encoded_id);
 
        /* check whether application is in external memory or not */
        fp = fopen(loopback_device, "r");
@@ -268,8 +260,8 @@ int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
 
                app2_handle = app2ext_init(APP2EXT_SD_CARD);
                if (app2_handle == NULL) {
-                       _E("app2_handle : app2ext init failed");
-                       return -2;
+                       _E("app2ext init failed");
+                       return -1;
                }
 
                app2_handle->interface.client_usr_disable(pkgid, uid);
@@ -278,6 +270,7 @@ int app2ext_usr_disable_external_pkg(const char *pkgid, uid_t uid)
 
        return 0;
 }
+
 int app2ext_disable_external_pkg(const char *pkgid)
 {
        int ret = 0;
@@ -291,36 +284,17 @@ int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid)
 {
        FILE *fp = NULL;
        app2ext_handle *app2_handle = NULL;
-       char application_mmc_path[FILENAME_MAX] = { 0, };
 
        /* validate the function parameter received */
-       if (pkgid == NULL) {
+       if (pkgid == NULL || uid < 0) {
                _E("invalid func parameters");
-               return 0;
-       }
-
-       if (_is_global(uid)) {
-               snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
-                       tzplatform_getenv(TZ_SYS_RW_APP), pkgid);
-       } else {
-               tzplatform_set_user(uid);
-               snprintf(application_mmc_path, FILENAME_MAX - 1, "%s/%s/.mmc",
-                       tzplatform_getenv(TZ_USER_APP), pkgid);
-               tzplatform_reset_user();
-       }
-       _D("application_mmc_path = (%s)", application_mmc_path);
-
-       fp = fopen(application_mmc_path, "r");
-       if (fp == NULL) {
-               return 0;
-       } else {
-               fclose(fp);
+               return -1;
        }
 
        app2_handle = app2ext_init(APP2EXT_SD_CARD);
        if (app2_handle == NULL) {
                _E("app2ext init failed");
-               return 0;
+               return -1;
        }
 
        app2_handle->interface.client_usr_force_clean(pkgid, uid);
@@ -328,6 +302,7 @@ int app2ext_usr_force_clean_pkg(const char *pkgid, uid_t uid)
 
        return 0;
 }
+
 int app2ext_force_clean_pkg(const char *pkgid)
 {
        int ret = 0;
index e20bcf8..3c1c6f5 100644 (file)
@@ -29,8 +29,9 @@
 #include <sys/types.h>
 #include <getopt.h>
 #include <unzip.h>
-#include <tzplatform_config.h>
-#include <app2ext_interface.h>
+
+#include "app2ext_interface.h"
+#include "app2ext_utils.h"
 
 #define SUCCESS 0
 #define FAIL 1