From 2336f6b3bba94198526c7018378a013e9eaeec01 Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 5 Oct 2015 14:07:37 +0900 Subject: [PATCH] migrate appsvc to aul Change-Id: I438fc30e06d3f2d404914d11c4a91712420f33f7 Signed-off-by: Jiwoong Im --- CMakeLists.txt | 10 +- data/appsvc_db.sql | 11 - include/appsvc.h | 263 +++++++---- include/appsvc_db.h | 49 -- include/internal.h | 61 --- include/priv_key.h | 50 --- packaging/app-svc.manifest | 3 - packaging/app-svc.spec | 31 +- src/appsvc.c | 1063 +++----------------------------------------- src/appsvc_db.c | 553 ----------------------- 10 files changed, 227 insertions(+), 1867 deletions(-) delete mode 100755 data/appsvc_db.sql delete mode 100755 include/appsvc_db.h delete mode 100755 include/internal.h delete mode 100755 include/priv_key.h delete mode 100755 src/appsvc_db.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2926a10..ded6517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,11 +18,10 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "") ENDIF() MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") - # Set required packages INCLUDE(FindPkgConfig) -SET(APPSVC_LIBPKGS_CHECK_MODULES "dlog bundle dbus-glib-1 xdgmime aul glib-2.0 ecore libsoup-2.4 iniparser pkgmgr-info libtzplatform-config sqlite3") +SET(APPSVC_LIBPKGS_CHECK_MODULES "dlog bundle aul ecore") IF (with_x) pkg_check_modules(libpkgs REQUIRED ${APPSVC_LIBPKGS_CHECK_MODULES} ecore-x) @@ -49,7 +48,6 @@ SET(CMAKE_C_FLAGS_RELEASE "-O2") SET(CMAKE_SKIP_BUILD_RPATH true) # Get uname value to set 'TARGET' definition -# TODO: Is this needed? FIND_PROGRAM(UNAME NAMES uname) EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") IF("${ARCH}" STREQUAL "arm") @@ -63,16 +61,12 @@ ADD_DEFINITIONS("-DRW_DATA_PREFIX=\"/opt/share\"") # Linker flags SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") - ### Build ### - - # aul add_library(appsvc SHARED src/appsvc.c - src/appsvc_db.c ) -target_link_libraries(appsvc ${libpkgs_LDFLAGS}) +TARGET_LINK_LIBRARIES(appsvc ${libpkgs_LDFLAGS}) SET_TARGET_PROPERTIES(appsvc PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(appsvc PROPERTIES VERSION ${VERSION}) diff --git a/data/appsvc_db.sql b/data/appsvc_db.sql deleted file mode 100755 index 290feee..0000000 --- a/data/appsvc_db.sql +++ /dev/null @@ -1,11 +0,0 @@ -PRAGMA journal_mode = PERSIST; - -CREATE TABLE IF NOT EXISTS appsvc ( - operation TEXT, - mime_type TEXT DEFAULT 'NULL', - uri TEXT DEFAULT 'NULL', - pkg_name TEXT, - PRIMARY KEY (operation,mime_type,uri) -); - - diff --git a/include/appsvc.h b/include/appsvc.h index 766126f..4c5c561 100755 --- a/include/appsvc.h +++ b/include/appsvc.h @@ -47,7 +47,6 @@ #include -#include #ifdef __cplusplus extern "C" { @@ -81,16 +80,14 @@ extern "C" { /** APP_SVC OPERATION TYPE*/ #define APPSVC_OPERATION_MULTI_SHARE "http://tizen.org/appcontrol/operation/multi_share" /** APP_SVC OPERATION TYPE*/ -#define APPSVC_OPERATION_COMPOSE "http://tizen.org/appcontrol/opeation/compose" +#define APPSVC_OPERATION_COMPOSE "http://tizen.org/appcontrol/operation/compose" /** APP_SVC OPERATION TYPE*/ #define APPSVC_OPERATION_LOCATION "http://tizen.org/appcontrol/operation/configure/location" /** APP_SVC OPERATION TYPE*/ #define APPSVC_OPERATION_FONT_TYPE "http://tizen.org/appcontrol/operation/configure/font/type" /** APP_SVC OPERATION TYPE*/ #define APPSVC_OPERATION_FONT_SIZE "http://tizen.org/appcontrol/operation/configure/font/size" -/** APP_SVC OPERATION TYPE*/ -#define APPSVC_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event" - +#define APPSVC_OPERATION_LAUNCH_ON_EVENT "http://tizen.org/appcontrol/operation/launch_on_event" @@ -121,14 +118,27 @@ extern "C" { /** APP SVC internal private key */ #define APP_SVC_K_URI_R_INFO "__APP_SVC_URI_R_INFO__" +#define APP_SVC_K_SELECTOR_EXTRA_LIST "http://tizen.org/appcontrol/data/selector_extra_list" + +#ifdef _APPFW_FEATURE_MULTI_INSTANCE +#define APP_SVC_K_MULTI_INSTANCE "multi_instance" +#endif + #define APP_SELECTOR "org.tizen.app-selector" -#define APPSVC_K_LAUNCH_RESULT_APP_STARTED "__K_LAUNCH_RESULT_APP_STARTED__" +/** Internal operation for launching application which is other zone */ +#define APP_SVC_OPERATION_JUMP "http://tizen.org/appcontrol/operation/jump" +#define APP_SVC_K_JUMP_ZONE_NAME "__K_JUMP_DOMAIN_NAME__" +#define APP_SVC_K_JUMP_ORIGIN_OPERATION "__K_JUMP_ORIGIN_OPERATION__" +#define APP_SVC_K_FOCUS_ZONE "__K_FOCUS_ZONE__" + /** - * @brief Return values in appsvc. + * @brief Return values in appsvc. */ typedef enum _appsvc_return_val { + APPSVC_RET_EREJECTED = -7, /**< application launch rejected */ + APPSVC_RET_ETERMINATING = -6, /**< application terminating */ APPSVC_RET_EILLACC = -5, /**< Illegal Access */ APPSVC_RET_ELAUNCH = -4, /**< Failure on launching the app */ APPSVC_RET_ENOMATCH = -3, /**< No matching result Error */ @@ -139,7 +149,7 @@ typedef enum _appsvc_return_val { /** - * @brief result values in appsvc. + * @brief result values in appsvc. */ typedef enum _appsvc_result_val { APPSVC_RES_CANCEL = -2, /**< Cancel by system */ @@ -148,20 +158,20 @@ typedef enum _appsvc_result_val { }appsvc_result_val; -/** +/** * @brief appsvc_res_fn is appsvc result function - * @param[out] b result bundle + * @param[out] b result bundle * @param[out] request_code request code * @param[out] result result value - * @param[out] data user-supplied data + * @param[out] data user-supplied data */ typedef void (*appsvc_res_fn)(bundle *b, int request_code, appsvc_result_val result, void *data); -/** - * @brief iterator function running with appsvc_get_list - * @param[out] pkg_name package name retreived by appsvc_get_list - * @param[out] data user-supplied data +/** + * @brief iterator function running with appsvc_get_list + * @param[out] appid appid retreived by appsvc_get_list + * @param[out] data user-supplied data */ typedef int (*appsvc_info_iter_fn)(const char *appid, void *data); @@ -171,18 +181,18 @@ typedef int (*appsvc_host_res_fn)(void *data); * @par Description: * This function sets an operation to launch application based on appsvc. * - * @param[in] b bundle object - * @param[in] operation operation + * @param[in] b bundle object + * @param[in] operation operation * * @return 0 if success, negative value(<0) if fail * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre None. * @post None. * @see None. - * @remarks An application must call this function before using appsvc_run_service API. + * @remarks An application must call this function before using appsvc_run_service API. * * @par Sample code: * @code @@ -193,7 +203,7 @@ typedef int (*appsvc_host_res_fn)(void *data); bundle *b = NULL; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_VIEW); } * @endcode @@ -205,18 +215,18 @@ int appsvc_set_operation(bundle *b, const char *operation); * @par Description: * This function sets an uri to launch application based on appsvc. * - * @param[in] b bundle object - * @param[in] uri uri + * @param[in] b bundle object + * @param[in] uri uri * * @return 0 if success, negative value(<0) if fail * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -227,7 +237,7 @@ int appsvc_set_operation(bundle *b, const char *operation); bundle *b = NULL; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_VIEW); appsvc_set_uri(b,"http://www.samsung.com"); } @@ -240,18 +250,18 @@ int appsvc_set_uri(bundle *b, const char *uri); * @par Description: * This function sets a mime-type to launch application based on appsvc. * - * @param[in] b bundle object - * @param[in] mime mime-type + * @param[in] b bundle object + * @param[in] mime mime-type * * @return 0 if success, negative value(<0) if fail * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -262,7 +272,7 @@ int appsvc_set_uri(bundle *b, const char *uri); bundle *b = NULL; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_PICK); appsvc_set_mime(b,"image/jpg"); } @@ -275,16 +285,16 @@ int appsvc_set_mime(bundle *b, const char *mime); * @par Description: * This function sets an extra data to launch application based on appsvc. * - * @param[in] b bundle object - * @param[in] key key of extra data - * @param[in] val data + * @param[in] b bundle object + * @param[in] key key of extra data + * @param[in] val data * * @return 0 if success, negative value(<0) if fail * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -295,7 +305,7 @@ int appsvc_set_mime(bundle *b, const char *mime); bundle *b = NULL; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_SEND); appsvc_set_uri(b,"mailto:xxx1@xxx"); appsvc_add_data(b,APPSVC_DATA_CC,"xxx2@xxx"); @@ -309,9 +319,9 @@ int appsvc_add_data(bundle *b, const char *key, const char *val); * @par Description: * This function sets an extra array data to launch application based on appsvc. * - * @param[in] b bundle object - * @param[in] key key of extra data - * @param[in] val_array data + * @param[in] b bundle object + * @param[in] key key of extra data + * @param[in] val_array data * @param[in] len Length of array * * @return 0 if success, negative value(<0) if fail @@ -319,7 +329,7 @@ int appsvc_add_data(bundle *b, const char *key, const char *val); * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -344,18 +354,18 @@ int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, in * @par Description: * This function sets a package name to launch application based on appsvc. * - * @param[in] b bundle object + * @param[in] b bundle object * @param[in] pkg_name package name for explict launch * * @return 0 if success, negative value(<0) if fail * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -366,7 +376,7 @@ int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, in bundle *b = NULL; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_PICK); appsvc_set_mime(b,"image/jpg"); appsvc_set_pkgname(b, "org.tizen.mygallery"); @@ -461,15 +471,15 @@ int appsvc_set_category(bundle *b, const char *category); * * @return callee's pid if success, negative value(<0) if fail * @retval callee's pid - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) - * @retval APPSVC_RET_ENOMATCH - no matching result Error + * @retval APPSVC_RET_ENOMATCH - no matching result Error * @retval APPSVC_RET_ELAUNCH - failure on launching the app * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -481,7 +491,7 @@ int appsvc_set_category(bundle *b, const char *category); static int num = 0; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_PICK); appsvc_set_mime(b,"image/jpg"); @@ -504,21 +514,21 @@ int appsvc_usr_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, vo * @return 0 if success, negative value(<0) if fail * @retval APPSVC_RET_OK - success * @retval APPSVC_RET_EINVAL - invalid argument(content) - * @retval APPSVC_RET_ENOMATCH - no matching result Error + * @retval APPSVC_RET_ENOMATCH - no matching result Error * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code #include -static int iter_fn(const char* pkg_name, void *data) +static int iter_fn(const char* appid, void *data) { printf("\t==========================\n"); - printf("\t pkg_name: %s\n", pkg_name); + printf("\t appid: %s\n", appid); printf("\t==========================\n"); return 0; } @@ -529,7 +539,7 @@ static int iter_fn(const char* pkg_name, void *data) static int num = 0; b = bundle_create(); - + appsvc_set_operation(b, APPSVC_OPERATION_PICK); appsvc_set_mime(b,"image/jpg"); @@ -543,16 +553,54 @@ int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_ /** * @par Description: + * This API use to get default applications + * + * @param[in] iter_fn iterator function + * @param[in] data user-supplied data for iter_fn + * + * @return 0 if success, negative value(<0) if fail + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_EINVAL - invalid argument(content) + * @retval APPSVC_RET_ENOMATCH - no matching result Error + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +static int iter_fn(const char* appid, void *data) +{ + printf("\t==========================\n"); + printf("\t appid : %s\n", appid); + printf("\t==========================\n"); + return 0; +} + +... +{ + return appsvc_get_all_defapps(iter_fn, (void*)NULL); +} + * @endcode + * + */ +int appsvc_get_all_defapps(appsvc_info_iter_fn iter_fn, void *data); + +/** + * @par Description: * This function gets a operation from bundle. * - * @param[in] b bundle object + * @param[in] b bundle object * * @return Pointer for operation string if success, NULL if fail * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -560,7 +608,7 @@ int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_ ... { - char *val; + char *val; val = appsvc_get_operation(b); } * @endcode @@ -572,14 +620,14 @@ const char *appsvc_get_operation(bundle *b); * @par Description: * This function gets a uri from bundle. * - * @param[in] b bundle object + * @param[in] b bundle object * * @return Pointer for uri string if success, NULL if fail * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -587,7 +635,7 @@ const char *appsvc_get_operation(bundle *b); ... { - char *val; + char *val; val = appsvc_get_uri(b); } * @endcode @@ -599,14 +647,14 @@ const char *appsvc_get_uri(bundle *b); * @par Description: * This function gets a mime-type from bundle. * - * @param[in] b bundle object + * @param[in] b bundle object * * @return Pointer for mime-type string if success, NULL if fail * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -614,7 +662,7 @@ const char *appsvc_get_uri(bundle *b); ... { - char *val; + char *val; val = appsvc_get_mime(b); } * @endcode @@ -626,14 +674,14 @@ const char *appsvc_get_mime(bundle *b); * @par Description: * This function gets a package name from bundle. * - * @param[in] b bundle object + * @param[in] b bundle object * * @return Pointer for package name string if success, NULL if fail * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -641,7 +689,7 @@ const char *appsvc_get_mime(bundle *b); ... { - char *val; + char *val; val = appsvc_get_pkgname(b); } * @endcode @@ -708,7 +756,7 @@ const char *appsvc_get_category(bundle *b); * @par Description: * This function gets value from key. * - * @param[in] b bundle object + * @param[in] b bundle object * @param[in] key key * * @return Pointer for value string if success, NULL if fail @@ -716,7 +764,7 @@ const char *appsvc_get_category(bundle *b); * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -724,7 +772,7 @@ const char *appsvc_get_category(bundle *b); ... { - char *val; + char *val; val = appsvc_get_data(b, APPSVC_DATA_CC); } * @endcode @@ -736,7 +784,7 @@ const char *appsvc_get_data(bundle *b, const char *key); * @par Description: * This function gets value from key. * - * @param[in] b bundle object + * @param[in] b bundle object * @param[in] key key * @param[out] len length of array * @@ -745,7 +793,7 @@ const char *appsvc_get_data(bundle *b, const char *key); * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -753,13 +801,13 @@ const char *appsvc_get_data(bundle *b, const char *key); ... { - char **val_array; + char **val_array; int len; char *val; if(appsvc_data_is_array(b, APPSVC_DATA_SELECTED)) val_array = appsvc_get_data_array(b, APPSVC_DATA_SELECTED, &len); - else + else val = appsvc_get_data(b, APPSVC_DATA_SELECTED); } * @endcode @@ -771,17 +819,17 @@ const char **appsvc_get_data_array(bundle *b, const char *key, int *len); * @par Description: * This API create appsvc result bundle based on bundle received in reset event. * - * @param[in] inb bundle received in reset event - * @param[in] outb bundle to use for returning result + * @param[in] inb bundle received in reset event + * @param[in] outb bundle to use for returning result * * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre None. * @post None. * @see appsvc_send_result. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -791,7 +839,7 @@ const char **appsvc_get_data_array(bundle *b, const char *key, int *len); { struct appdata *ad = data; bundle* res_bundle; - + appsvc_create_result_bundle(ad->b,&res_bundle); bundle_add(res_bundle, "result", "1"); appsvc_send_result(res_bundle, 0); @@ -809,13 +857,13 @@ int appsvc_create_result_bundle(bundle *inb, bundle **outb); * @param[in] result result value * * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre appsvc_create_result_bundle. * @post None. * @see appsvc_send_result. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -825,7 +873,7 @@ int appsvc_create_result_bundle(bundle *inb, bundle **outb); { struct appdata *ad = data; bundle* res_bundle; - + appsvc_create_result_bundle(ad->b,&res_bundle); bundle_add(res_bundle, "result", "1"); appsvc_send_result(res_bundle, 0); @@ -845,13 +893,13 @@ int appsvc_send_result(bundle *b, appsvc_result_val result); * @param[in] defapp default application * * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * @retval APPSVC_RET_EINVAL - invalid argument(content) * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -874,12 +922,12 @@ int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri, * @param[in] defapp default application * * @retval APPSVC_RET_OK - success - * @retval APPSVC_RET_ERROR - general error + * @retval APPSVC_RET_ERROR - general error * * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code @@ -896,9 +944,35 @@ int appsvc_unset_defapp(const char *defapp, uid_t uid); /** * @par Description: + * This API unset all of default applications associated with op, uri and mime-type. + * + * + * @retval APPSVC_RET_OK - success + * @retval APPSVC_RET_ERROR - general error + * + * @pre None. + * @post None. + * @see None. + * @remarks None. + * + * @par Sample code: + * @code +#include + +... +{ + appsvc_unset_all_defapps(); +} + * @endcode + * + */ +int appsvc_unset_all_defapps(); + +/** + * @par Description: * This API ask a application is default application or not. * - * @param[in] pkg_name application package name + * @param[in] appid application appid * @return true / false * @retval 1 app_name is default application in appsvc. * @retval 0 app_name is NOT default application in appsvc. @@ -906,32 +980,33 @@ int appsvc_unset_defapp(const char *defapp, uid_t uid); * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code #include - + ... * int is_defapp_browser_app() - * { + * { * return appsvc_is_defapp("org.tizen.browser"); * } * * @endcode * @remark * None -* +* */ int appsvc_is_defapp(const char *appid, uid_t uid); + /** * @par Description: * This API ask a extra data is array or not. * - * @param[in] b bundle object - * @param[in] key key of extra data + * @param[in] b bundle object + * @param[in] key key of extra data * @return true / false * @retval 1 a extra data is array. * @retval 0 a extra data is not array. @@ -939,12 +1014,12 @@ int appsvc_is_defapp(const char *appid, uid_t uid); * @pre None. * @post None. * @see None. - * @remarks None. + * @remarks None. * * @par Sample code: * @code #include - + ... * int appsvc_data_is_array(bundle *b, char *key) @@ -955,7 +1030,7 @@ int appsvc_is_defapp(const char *appid, uid_t uid); * @endcode * @remark * None -* +* */ int appsvc_data_is_array(bundle *b, const char *key); @@ -1016,8 +1091,6 @@ int appsvc_set_launch_mode(bundle *b, const char *mode); * */ const char *appsvc_get_launch_mode(bundle *b); - -int aul_svc_subscribe_launch_result(bundle *b, const char *event); #ifdef __cplusplus } #endif diff --git a/include/appsvc_db.h b/include/appsvc_db.h deleted file mode 100755 index b471fa2..0000000 --- a/include/appsvc_db.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * app-svc - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee - * - * 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 __APP_SVC_DB_H__ -#define __APP_SVC_DB_H__ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name, uid_t uid); -int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid); -char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, uid_t uid); -int _svc_db_is_defapp(const char *pkg_name, uid_t uid); -int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, GSList **pkg_list, uid_t uid); - - - -#ifdef __cplusplus -} -#endif - -#endif /* __APP_SVC_DB_H__ */ - diff --git a/include/internal.h b/include/internal.h deleted file mode 100755 index b255ea3..0000000 --- a/include/internal.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * app-svc - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee - * - * 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 __INTERNAL_H__ -#define __INTERNAL_H__ - -#include -#include -#include - -#undef LOG_TAG -#define LOG_TAG "APP_SVC" - -#define MAX_FILTER_STR_SIZE 1024 -#define MAX_PACKAGE_STR_SIZE 512 -#define MAX_URI_STR_SIZE 256 -#define MAX_MIME_STR_SIZE 256 -#define MAX_SCHEME_STR_SIZE 256 -#define MAX_HOST_STR_SIZE 256 -#define MAX_OP_STR_SIZE 128 -#define MAX_LOCAL_BUFSZ 128 - -#define _E(fmt, arg...) LOGE(fmt,##arg) -#define _D(fmt, arg...) LOGD(fmt,##arg) - -#define retvm_if(expr, val, fmt, arg...) do { \ - if(expr) { \ - _E(fmt, ##arg); \ - _E("(%s) -> %s() return", #expr, __FUNCTION__); \ - return (val); \ - } \ -} while (0) - -#define retv_if(expr, val) do { \ - if(expr) { \ - _E("(%s) -> %s() return", #expr, __FUNCTION__); \ - return (val); \ - } \ -} while (0) - -#endif /* __INTERNAL_H__ */ - diff --git a/include/priv_key.h b/include/priv_key.h deleted file mode 100755 index a21abe4..0000000 --- a/include/priv_key.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * app-svc - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee - * - * 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 __PRIV_KEY_H__ -#define __PRIV_KEY_H__ - - -/** APP SVC internal private key */ -#define APP_SVC_K_OPERATION "__APP_SVC_OP_TYPE__" -/** APP SVC internal private key */ -#define APP_SVC_K_URI "__APP_SVC_URI__" -/** APP SVC internal private key */ -#define APP_SVC_K_MIME "__APP_SVC_MIME_TYPE__" -/** APP SVC internal private key */ -#define APP_SVC_K_DATA "__APP_SVC_DATA__" -/** APP SVC internal private key */ -#define APP_SVC_K_PKG_NAME "__APP_SVC_PKG_NAME__" -/** APP SVC internal private key */ -#define APP_SVC_K_CATEGORY "__APP_SVC_CATEGORY__" -/** APP SVC internal private key */ -#define APP_SVC_K_RES_VAL "__APP_SVC_K_RES_VAL__" - -/** APP SVC internal private key */ -#define APP_SVC_K_WIN_ID "__APP_SVC_K_WIN_ID__" - -/** APP SVC internal private key */ -#define APP_SVC_K_LAUNCH_MODE "__APP_SVC_LAUNCH_MODE__" - -#endif /* __PRIV_KEY_H__ */ - -/* vi: set ts=8 sts=8 sw=8: */ diff --git a/packaging/app-svc.manifest b/packaging/app-svc.manifest index 2d25aaf..017d22d 100644 --- a/packaging/app-svc.manifest +++ b/packaging/app-svc.manifest @@ -2,7 +2,4 @@ - - - diff --git a/packaging/app-svc.spec b/packaging/app-svc.spec index b8b533d..3724c0d 100644 --- a/packaging/app-svc.spec +++ b/packaging/app-svc.spec @@ -12,26 +12,16 @@ Source1001: app-svc.manifest Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig -BuildRequires: cmake -BuildRequires: sqlite3 -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(ecore) + +BuildRequires: cmake + +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(bundle) +BuildRequires: pkgconfig(aul) +BuildRequires: pkgconfig(ecore) %if %{with x} -BuildRequires: pkgconfig(x11) BuildRequires: pkgconfig(ecore-x) %endif -BuildRequires: pkgconfig(libprivilege-control) -BuildRequires: pkgconfig(bundle) -BuildRequires: pkgconfig(dbus-glib-1) -BuildRequires: pkgconfig(xdgmime) -BuildRequires: pkgconfig(aul) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(libsoup-2.4) -BuildRequires: pkgconfig(iniparser) -BuildRequires: pkgconfig(pkgmgr-info) -BuildRequires: pkgconfig(libtzplatform-config) -BuildRequires: pkgconfig(sqlite3) - %description Application Service @@ -45,7 +35,6 @@ Requires: %{name} = %{version}-%{release} %prep %setup -q -sed -i %{SOURCE1001} -e "s|TZ_SYS_DB|%TZ_SYS_DB|g" cp %{SOURCE1001} . %build @@ -61,10 +50,6 @@ cp %{SOURCE1001} . %install %make_install -# Create database -mkdir -p %{buildroot}%{TZ_SYS_DB} -sqlite3 %{buildroot}%{TZ_SYS_DB}/.appsvc.db < data/appsvc_db.sql - %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -73,8 +58,6 @@ sqlite3 %{buildroot}%{TZ_SYS_DB}/.appsvc.db < data/appsvc_db.sql %defattr(-,root,root,-) %manifest %{name}.manifest %license LICENSE -%config(noreplace) %verify(not md5 mtime size) %attr(664,root,%{TZ_SYS_USER_GROUP}) %{TZ_SYS_DB}/.appsvc.db -%config(noreplace) %verify(not md5 mtime size) %attr(664,root,%{TZ_SYS_USER_GROUP}) %{TZ_SYS_DB}/.appsvc.db-journal %{_bindir}/appsvc_test %{_libdir}/libappsvc.so.0 %{_libdir}/libappsvc.so.0.1.0 diff --git a/src/appsvc.c b/src/appsvc.c index 8722b96..0794e7f 100644 --- a/src/appsvc.c +++ b/src/appsvc.c @@ -1,1175 +1,212 @@ /* - * app-svc + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee - * - * Licensed under the Apache License, Version 2.0 (the "License"); + * 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, + * 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 #ifndef WAYLAND #include #endif -#include -#include -#include -#include - #include "appsvc.h" -#include "appsvc_db.h" -#include "internal.h" -#include "priv_key.h" - - #ifndef SLPAPI #define SLPAPI __attribute__ ((visibility("default"))) #endif - -/* callback handling */ -typedef struct _appsvc_cb_info_t{ - appsvc_res_fn cb_func; - int request_code; - void *data; -}appsvc_cb_info_t; - -typedef struct _appsvc_resolve_info_t{ - char *pkgname; - char *op; - char *uri; - char *scheme; - char *host; - char *uri_r_info; - char *origin_mime; - char *mime; - char *m_type; - char *s_type; - char *category; - char *win_id; - int mime_set; -}appsvc_resolve_info_t; - -extern int aul_launch_app_with_result(const char *pkgname, bundle *kb, - void (*cbfunc) (bundle *, int, void *), - void *data); - -static appsvc_cb_info_t *__create_rescb(int request_code, appsvc_res_fn cbfunc, - void *data); -static void __remove_rescb(appsvc_cb_info_t *info); -static int __set_bundle(bundle *b, const char *key, const char *value); -static void __aul_cb(bundle *b, int is_cancel, void *data); -static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, - appsvc_res_fn cbfunc, void *data); -static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info); -static int __free_resolve_info_data(appsvc_resolve_info_t *info); -static int __get_list_with_condition(char *op, char *uri, - char *mime, GSList **pkg_list, uid_t uid); - - -static appsvc_cb_info_t *__create_rescb(int request_code, appsvc_res_fn cbfunc, void *data) -{ - appsvc_cb_info_t* info; - - info = (appsvc_cb_info_t*)calloc(1, sizeof(appsvc_cb_info_t)); - if(info == NULL) - return NULL; - - info->request_code = request_code; - info->cb_func = cbfunc; - info->data = data; - - return info; -} - -static void __remove_rescb(appsvc_cb_info_t *info) -{ - if(info) free(info); -} - -static int __set_bundle(bundle *b, const char *key, const char *value) -{ - const char *val = NULL; - - val = bundle_get_val(b, key); - if(val){ - if( bundle_del(b, key) != 0 ){ - return APPSVC_RET_ERROR; - } - } - - if(!value) - return APPSVC_RET_EINVAL; - - if( bundle_add(b, key, value) != 0 ){ - return APPSVC_RET_ERROR; - } - - _D("__set_bundle"); -// bundle_iterate(b, __bundle_iterate, NULL); - - return APPSVC_RET_OK; -} - -static int __set_bundle_array(bundle *b, const char *key, const char **value, int len) -{ - - int type; - type = appsvc_data_is_array(b, key); - - if(type == 1) { - if( bundle_del(b, key) != 0 ){ - return APPSVC_RET_ERROR; - } - } - - if(!value) - return APPSVC_RET_EINVAL; - - if( bundle_add_str_array(b, key, value, len) != 0 ){ - return APPSVC_RET_ERROR; - } - - _D("__set_bundle_array"); -// bundle_iterate(b, __bundle_iterate, NULL); - - return APPSVC_RET_OK; -} - - -static void __aul_cb(bundle *b, int is_cancel, void *data) -{ - const char *val = NULL; - appsvc_cb_info_t* cb_info; - int res; - - if(is_cancel) - res = APPSVC_RES_CANCEL; - else{ - /* get result_code from bundle */ - val = bundle_get_val(b, APP_SVC_K_RES_VAL); - res = (val==NULL)? APPSVC_RES_NOT_OK : atoi(val); - } - - /* remove result_code from bundle */ - bundle_del(b, APP_SVC_K_RES_VAL); - - /* find corresponding callback */ - cb_info = (appsvc_cb_info_t*)data; - - cb_info->cb_func(b, cb_info->request_code, (appsvc_result_val)res, cb_info->data); - __remove_rescb(cb_info); - - - return; -} - -static int __run_svc_with_pkgname(char *pkgname, bundle *b, int request_code, appsvc_res_fn cbfunc, void *data) -{ - appsvc_cb_info_t *cb_info = NULL; - int ret = -1; - - if (cbfunc) { - _D("pkg_name : %s - with result", pkgname); - - cb_info = __create_rescb(request_code, cbfunc, data); - ret = aul_launch_app_with_result(pkgname, b, __aul_cb, cb_info); - } else { - _D("pkg_name : %s - no result", pkgname); - ret = aul_launch_app(pkgname, b); - } - - if(ret < 0) { - switch (ret) { - case AUL_R_EILLACC: - ret = APPSVC_RET_EILLACC; - break; - case AUL_R_EINVAL: - ret = APPSVC_RET_EINVAL; - break; - case AUL_R_ENOAPP: - ret = APPSVC_RET_ENOMATCH; - break; - default: - ret = APPSVC_RET_ELAUNCH; - } - } - - return ret; -} - -static int __get_resolve_info(bundle *b, appsvc_resolve_info_t *info) -{ - char *tmp = NULL; - char *strtok_buf = NULL; - SoupURI *s_uri; - - info->op = (char *)appsvc_get_operation(b); - info->uri = (char *)appsvc_get_uri(b); - info->origin_mime = info->mime = (char *)appsvc_get_mime(b); - info->pkgname = (char *)appsvc_get_pkgname(b); - info->category = (char *)appsvc_get_category(b); - info->win_id = (char *)bundle_get_val(b, APP_SVC_K_WIN_ID); - - if(info->uri) { - if(strncmp(info->uri,"/",1) == 0){ - if(!info->mime) { - info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE); - aul_get_mime_from_file(info->uri, info->mime, MAX_MIME_STR_SIZE); - info->mime_set = 1; - } - info->uri = NULL; - } else if(strncmp(info->uri,"file:/",6)==0){ - if(!info->mime) { - info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE); - aul_get_mime_from_file(&info->uri[5], info->mime, MAX_MIME_STR_SIZE); - info->mime_set = 1; - } - info->uri = NULL; - } else if(strncmp(info->uri,"file:///",8) == 0){ - if(!info->mime) { - info->origin_mime = info->mime = malloc(MAX_MIME_STR_SIZE); - aul_get_mime_from_file(&info->uri[7], info->mime, MAX_MIME_STR_SIZE); - info->mime_set = 1; - } - info->uri = NULL; - } - } - - if(info->uri) { - s_uri = soup_uri_new(info->uri); - - if(!s_uri) - return APPSVC_RET_EINVAL; - - if(s_uri->scheme) { - info->scheme = malloc(MAX_SCHEME_STR_SIZE); - strncpy(info->scheme, s_uri->scheme, MAX_SCHEME_STR_SIZE-1); - } - if(s_uri->host) { - info->host = malloc(MAX_HOST_STR_SIZE); - strncpy(info->host, s_uri->host, MAX_HOST_STR_SIZE-1); - } - if(info->scheme && info->host) { - info->uri_r_info = malloc(MAX_SCHEME_STR_SIZE+MAX_HOST_STR_SIZE+2); - snprintf(info->uri_r_info, MAX_SCHEME_STR_SIZE+MAX_HOST_STR_SIZE+1, - "%s://%s", info->scheme, info->host); - } - - soup_uri_free(s_uri); - } else { - info->scheme = strdup("NULL"); - } - - if(!info->mime) - info->mime = strdup("NULL"); - else { - info->m_type = malloc(MAX_LOCAL_BUFSZ); - info->s_type = malloc(MAX_LOCAL_BUFSZ); - tmp = strdup(info->mime); - strtok_buf = strtok(tmp,"/"); - if(strtok_buf) - strncpy(info->m_type, strtok_buf, MAX_LOCAL_BUFSZ-1); - strtok_buf = strtok(NULL,"/"); - if(strtok_buf) - strncpy(info->s_type, strtok_buf, MAX_LOCAL_BUFSZ-1); - free(tmp); - - if(strncmp(info->m_type, "*", 1) == 0) { - strncpy(info->m_type, "%", MAX_LOCAL_BUFSZ-1); - } - if(strncmp(info->s_type, "*", 1) == 0) { - strncpy(info->s_type, "%", MAX_LOCAL_BUFSZ-1); - } - - info->mime = malloc(MAX_MIME_STR_SIZE); - snprintf(info->mime, MAX_MIME_STR_SIZE-1, "%s/%s", info->m_type, info->s_type); - } - - return 0; -} - -static int __free_resolve_info_data(appsvc_resolve_info_t *info) -{ - if (info->mime) - free(info->mime); - if (info->scheme) - free(info->scheme); - if (info->host) - free(info->host); - if (info->m_type) - free(info->m_type); - if (info->s_type) - free(info->s_type); - if (info->uri_r_info) - free(info->uri_r_info); - if (info->mime_set) - free(info->origin_mime); - - return 0; -} - SLPAPI int appsvc_set_operation(bundle *b, const char *operation) -{ - if(b == NULL){ - _E("bundle for appsvc_set_operation is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_OPERATION, operation); +{ + return aul_svc_set_operation(b, operation); } SLPAPI int appsvc_set_uri(bundle *b, const char *uri) -{ - if(b == NULL){ - _E("bundle for appsvc_set_uri is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_URI, uri); +{ + return aul_svc_set_uri(b, uri); } SLPAPI int appsvc_set_mime(bundle *b, const char *mime) -{ - if(b == NULL){ - _E("bundle for appsvc_set_mime is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_MIME, mime); +{ + return aul_svc_set_mime(b, mime); } SLPAPI int appsvc_add_data(bundle *b, const char *key, const char *val) { - if(b == NULL || key == NULL) { - return APPSVC_RET_EINVAL; - } - - /* check key for data */ - /******************/ - - return __set_bundle(b, key, val); + return aul_svc_add_data(b, key, val); } SLPAPI int appsvc_add_data_array(bundle *b, const char *key, const char **val_array, int len) { - if(b == NULL || key == NULL) { - return APPSVC_RET_EINVAL; - } - - /* check key for data */ - /******************/ - - return __set_bundle_array(b, key, val_array, len); + return aul_svc_add_data_array(b, key, val_array, len); } - SLPAPI int appsvc_set_pkgname(bundle *b, const char *pkg_name) -{ - if(b == NULL){ - _E("bundle for appsvc_set_pkgname is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_PKG_NAME, pkg_name); -} - -static char* __get_alias_appid(char *appid) { - char *alias_id = NULL; - char *val = NULL; - char key_string[MAX_PACKAGE_STR_SIZE+5]; - dictionary *dic; - - dic = iniparser_load("/usr/share/appsvc/alias.ini"); - - if(dic == NULL) - return NULL; - - sprintf(key_string, "Alias:%s", appid); - val = iniparser_getstring(dic, key_string, NULL); - - _D("alias_id : %s", val); - - if(val != NULL) { - alias_id = malloc(MAX_PACKAGE_STR_SIZE); - strncpy(alias_id, val, MAX_PACKAGE_STR_SIZE-1); - } - - iniparser_freedict(dic); - - return alias_id; + return aul_svc_set_pkgname(b, pkg_name); } SLPAPI int appsvc_set_appid(bundle *b, const char *appid) { - char *alias_id = NULL; - int ret; - - if(b == NULL || appid == NULL){ - _E("bundle for appsvc_set_appid is NULL"); - return APPSVC_RET_EINVAL; - } - - alias_id = __get_alias_appid(appid); - if(alias_id == NULL) { - ret = __set_bundle(b, APP_SVC_K_PKG_NAME, appid); - } else { - ret = __set_bundle(b, APP_SVC_K_PKG_NAME, alias_id); - free(alias_id); - } - - return ret; + return aul_svc_set_appid(b, appid); } SLPAPI int appsvc_set_category(bundle *b, const char *category) { - if(b == NULL){ - _E("bundle for appsvc_set_category is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_CATEGORY, category); + return aul_svc_set_category(b, category); } SLPAPI int appsvc_set_launch_mode(bundle *b, const char *mode) { - if (b == NULL) { - _E("bundle for appsvc_set_launch_mode is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_LAUNCH_MODE, mode); -} -static int __get_list_with_condition_mime_extened(char *op, char *uri, char *mime, - char *m_type, char *s_type, GSList **pkg_list, uid_t uid) -{ - char *tmp; - - tmp = malloc(MAX_MIME_STR_SIZE); - - _svc_db_get_list_with_condition(op, uri, mime, pkg_list, uid); - if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) { - snprintf(tmp, MAX_MIME_STR_SIZE-1, "%s/*", m_type); - _svc_db_get_list_with_condition(op, uri, tmp, pkg_list, uid); - } - if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) { - snprintf(tmp, MAX_MIME_STR_SIZE-1, "*/*"); - _svc_db_get_list_with_condition(op, uri, tmp, pkg_list, uid); - } - free(tmp); - - return 0; -} - -static int __get_list_with_condition_mime_extened_with_collation(char *op, char *uri, char *mime, - char *m_type, char *s_type, GSList **pkg_list, uid_t uid) -{ - char *tmp; - - tmp = malloc(MAX_MIME_STR_SIZE); - - _svc_db_get_list_with_collation(op, uri, mime, pkg_list, uid); - if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(s_type, "%", 1) != 0)) { - snprintf(tmp, MAX_MIME_STR_SIZE-1, "%s/*", m_type); - _svc_db_get_list_with_collation(op, uri, tmp, pkg_list, uid); - } - if ((strncmp(mime, "NULL", 4) != 0) && (strncmp(m_type, "%", 1) != 0)) { - snprintf(tmp, MAX_MIME_STR_SIZE-1, "*/*"); - _svc_db_get_list_with_collation(op, uri, tmp, pkg_list, uid); - } - free(tmp); - - return 0; -} - -GSList *tmp_list; -static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data) -{ - char *appid = NULL; - GSList **app_list = (GSList **)user_data; - char *str = NULL; - GSList *iter = NULL; - - pkgmgrinfo_appinfo_get_appid(handle, &str); - _D("Matching application is %s",str); - - for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) { - if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE-1) == 0) { - appid = strdup(str); - *app_list = g_slist_append(*app_list, (void *)appid); - _D("%s is added",appid); - } - } - - return 0; -} - -static int __get_list_with_category(char *category, GSList **pkg_list, uid_t uid) -{ - int ret; - pkgmgrinfo_appinfo_filter_h handle; - GSList *app_list = NULL; - GSList *iter = NULL; - char *list_item = NULL; - - ret = pkgmgrinfo_appinfo_filter_create(&handle); - ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_CATEGORY, category); - - tmp_list = *pkg_list; - ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle, __app_list_cb, &app_list, uid); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_appinfo_filter_destroy(handle); - return -1; - } - pkgmgrinfo_appinfo_filter_destroy(handle); - - for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) { - list_item = (char *)iter->data; - g_free(list_item); - } - g_slist_free(*pkg_list); - - *pkg_list = app_list; - - return 0; -} - -static int __appid_compare(gconstpointer data1, gconstpointer data2) -{ - char *a = (char *)data1; - char *b = (char *)data2; - return strcmp(a,b); -} - -static int __get_list_with_submode(char *win_id, GSList **pkg_list, uid_t uid) -{ - int ret; - GSList *iter = NULL; - char *appid = NULL; - GSList *find_item = NULL; - char *find_appid = NULL; - pkgmgrinfo_appinfo_h handle = NULL; - char *submode_mainid = NULL; - -#ifndef WAYLAND - for (iter = *pkg_list; iter != NULL; ) { - find_item = NULL; - submode_mainid = NULL; - appid = (char *)iter->data; - ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle); - SECURE_LOGD("ret %d, %s, %x", ret, appid, handle); - ret = pkgmgrinfo_appinfo_get_submode_mainid(handle, &submode_mainid); - SECURE_LOGD("appid(%s) submode_mainid(%s) win_id(%s)", appid, submode_mainid, win_id); - if(submode_mainid) { - if(win_id) { - find_item = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare); - if(find_item) { - find_appid = find_item->data; - if(find_item == g_slist_next(iter)) { - iter = g_slist_next(find_item); - *pkg_list = g_slist_remove(*pkg_list, find_appid); - free(find_appid); - } else { - iter = g_slist_next(iter); - *pkg_list = g_slist_remove(*pkg_list, find_appid); - free(find_appid); - } - } - } else { - find_item = g_slist_find_custom(*pkg_list, submode_mainid, __appid_compare); - if(find_item) { - iter = g_slist_next(iter); - *pkg_list = g_slist_remove(*pkg_list, appid); - free(appid); - } - } - } - pkgmgrinfo_appinfo_destroy_appinfo(handle); - if(!find_item) { - iter = g_slist_next(iter); - } - } -#endif - - for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) { - appid = (char *)iter->data; - SECURE_LOGD("appid(%s)", appid); - } - - return 0; + return aul_svc_set_launch_mode(b, mode); } SLPAPI int appsvc_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data) { - //using default user to allow app-svc API usage for deamon. - //App-svc run service leads to app launch that could require a graphical session. - //Indeed bluetooth_agent uses this API and is launched as bluetooth user (that not regular user). - return appsvc_usr_run_service(b, request_code, cbfunc, data, tzplatform_getuid(TZ_SYS_DEFAULT_USER)); + return aul_svc_run_service(b, request_code, (aul_svc_res_fn)cbfunc, data); } SLPAPI int appsvc_usr_run_service(bundle *b, int request_code, appsvc_res_fn cbfunc, void *data, uid_t uid) { - appsvc_resolve_info_t info; - char *pkgname; - int pkg_count = 0; - int ret = -1; - - GSList *pkg_list = NULL; - GSList *iter = NULL; - char *list_item; - - if(b == NULL){ - _E("bundle for appsvc_set_appid is NULL"); - return APPSVC_RET_EINVAL; - } - - pkgname = (char *)appsvc_get_pkgname(b); - - /* explict*/ - if(pkgname) { - if(appsvc_get_operation(b) == NULL) - appsvc_set_operation(b,APPSVC_OPERATION_DEFAULT); - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - return ret; - } - - memset(&info, 0, sizeof(appsvc_resolve_info_t)); - ret = __get_resolve_info(b, &info); - if(ret < 0) - return ret; - - _D("op - %s / mime - %s / scheme - %s\n", info.op, info.origin_mime, info.scheme); - - /*uri*/ - pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri, uid); - if(pkgname==NULL){ - __get_list_with_condition_mime_extened_with_collation(info.op, info.uri, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - pkg_count = g_slist_length(pkg_list); - if(pkg_count > 0) { - - if(info.uri_r_info) { - __get_list_with_condition_mime_extened(info.op, info.uri_r_info, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - } - - __get_list_with_condition_mime_extened(info.op, info.scheme, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - __get_list_with_condition_mime_extened(info.op, "*", - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - if(info.category) { - __get_list_with_category(info.category, &pkg_list, uid); - } - - __get_list_with_submode(info.win_id, &pkg_list, uid); - - pkg_count = g_slist_length(pkg_list); - _D("pkg_count : %d", pkg_count); - - if(pkg_count == 1){ - pkgname = (char *)pkg_list->data; - if(pkgname != NULL){ - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - goto end; - } - } else { - bundle_add(b, APP_SVC_K_URI_R_INFO, info.uri); - ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); - goto end; - } - for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { - list_item = (char *)iter->data; - g_free(list_item); - } - g_slist_free(pkg_list); - pkg_list = NULL; - } - } else { - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - free(pkgname); - goto end; - } - - /*scheme & host*/ - if(info.uri_r_info) { - pkgname = _svc_db_get_app(info.op, info.origin_mime, info.uri_r_info, uid); - - if(pkgname==NULL){ - __get_list_with_condition_mime_extened(info.op, info.uri_r_info, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - pkg_count = g_slist_length(pkg_list); - if(pkg_count > 0) { - __get_list_with_condition_mime_extened(info.op, info.scheme, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - __get_list_with_condition_mime_extened(info.op, "*", - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - if(info.category) { - __get_list_with_category(info.category, &pkg_list, uid); - } - - __get_list_with_submode(info.win_id, &pkg_list, uid); - - pkg_count = g_slist_length(pkg_list); - _D("pkg_count : %d", pkg_count); - - if(pkg_count == 1){ - pkgname = (char *)pkg_list->data; - if(pkgname != NULL){ - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - goto end; - } - } else { - bundle_add(b, APP_SVC_K_URI_R_INFO, info.uri_r_info); - ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); - goto end; - } - } - for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { - list_item = (char *)iter->data; - g_free(list_item); - } - g_slist_free(pkg_list); - pkg_list = NULL; - } else { - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - free(pkgname); - goto end; - } - } - - /*scheme*/ - pkgname = _svc_db_get_app(info.op, info.origin_mime, info.scheme, uid); - - if(pkgname==NULL){ - __get_list_with_condition_mime_extened(info.op, info.scheme, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - __get_list_with_condition_mime_extened(info.op, "*", - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - if(info.category) { - __get_list_with_category(info.category, &pkg_list, uid); - } - - __get_list_with_submode(info.win_id, &pkg_list, uid); - - pkg_count = g_slist_length(pkg_list); - _D("pkg_count : %d", pkg_count); - - if(pkg_count == 1){ - pkgname = (char *)pkg_list->data; - if(pkgname != NULL){ - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - } - } else if(pkg_count < 1) { - __free_resolve_info_data(&info); - return APPSVC_RET_ENOMATCH; - } else { - bundle_add(b, APP_SVC_K_URI_R_INFO, info.scheme); - ret = __run_svc_with_pkgname(APP_SELECTOR, b, request_code, cbfunc, data); - } - - for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { - list_item = (char *)iter->data; - g_free(list_item); - } - g_slist_free(pkg_list); - } else { - ret = __run_svc_with_pkgname(pkgname, b, request_code, cbfunc, data); - free(pkgname); - } - -end: - __free_resolve_info_data(&info); - - return ret; + return aul_svc_run_service_with_uid(b, request_code, (aul_svc_res_fn)cbfunc, data, uid); } - SLPAPI int appsvc_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data) { - //using default user to allow app-svc API usage for deamon. - //App-svc run get list leads to app launch that could require a graphical session. - return appsvc_usr_get_list(b, iter_fn, data, tzplatform_getuid(TZ_SYS_DEFAULT_USER)); + return aul_svc_get_list(b, (aul_svc_info_iter_fn)iter_fn, data); } SLPAPI int appsvc_usr_get_list(bundle *b, appsvc_info_iter_fn iter_fn, void *data, uid_t uid) { - appsvc_resolve_info_t info; - char *pkgname = NULL; - int pkg_count; - int ret = -1; - - GSList *pkg_list = NULL; - GSList *iter = NULL; - - if(b == NULL){ - _E("bundle for appsvc_run_service is NULL"); - return APPSVC_RET_EINVAL; - } - - if (iter_fn == NULL){ - _E("iter_fn for appsvc_run_service is NULL"); - return APPSVC_RET_EINVAL; - } - - /* parse bundle */ - memset(&info, 0, sizeof(appsvc_resolve_info_t)); - ret = __get_resolve_info(b,&info); - if(ret < 0) - return ret; - - _D("operation - %s / scheme - %s / mime - %s\n", info.op, info.scheme, info.mime); - - __get_list_with_condition_mime_extened_with_collation(info.op, info.uri, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - if(info.uri_r_info) { - __get_list_with_condition_mime_extened(info.op, info.uri_r_info, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - } - - __get_list_with_condition_mime_extened(info.op, info.scheme, - info.mime, info.m_type, info.s_type, &pkg_list, uid); - - if(info.category) { - __get_list_with_category(info.category, &pkg_list, uid); - } - - __get_list_with_submode(info.win_id, &pkg_list, uid); - - pkg_count = g_slist_length(pkg_list); - if (pkg_count == 0) { - _E("Cannot find associated application"); - return APPSVC_RET_ENOMATCH; - } - - for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) { - pkgname = iter->data; - _D("PKGNAME : %s\n", pkgname); - if( iter_fn(pkgname,data) != 0) - break; - g_free(pkgname); - } - - g_slist_free(pkg_list); - __free_resolve_info_data(&info); + return aul_svc_get_list_with_uid(b, (aul_svc_info_iter_fn)iter_fn, data, uid); +} - return APPSVC_RET_OK; +SLPAPI int appsvc_get_all_defapps(appsvc_info_iter_fn iter_fn, void *data) +{ + return aul_svc_get_all_defapps((aul_svc_info_iter_fn)iter_fn, data); } SLPAPI const char *appsvc_get_operation(bundle *b) { - return bundle_get_val(b, APP_SVC_K_OPERATION); + return aul_svc_get_operation(b); } SLPAPI const char *appsvc_get_uri(bundle *b) { - return bundle_get_val(b, APP_SVC_K_URI); + return aul_svc_get_uri(b); } SLPAPI const char *appsvc_get_mime(bundle *b) { - return bundle_get_val(b, APP_SVC_K_MIME); + return aul_svc_get_mime(b); } SLPAPI const char *appsvc_get_data(bundle *b, const char *key) { - return bundle_get_val(b, key); + return aul_svc_get_data(b, key); } SLPAPI const char **appsvc_get_data_array(bundle *b, const char *key, int *len) { - return bundle_get_str_array(b, key, len); + return aul_svc_get_data_array(b, key, len); } SLPAPI const char *appsvc_get_pkgname(bundle *b) { - return bundle_get_val(b, APP_SVC_K_PKG_NAME); + return aul_svc_get_pkgname(b); } SLPAPI const char *appsvc_get_appid(bundle *b) { - return bundle_get_val(b, APP_SVC_K_PKG_NAME); + return aul_svc_get_appid(b); } SLPAPI const char *appsvc_get_category(bundle *b) { - return bundle_get_val(b, APP_SVC_K_CATEGORY); + return aul_svc_get_category(b); } SLPAPI const char *appsvc_get_launch_mode(bundle *b) { - return bundle_get_val(b, APP_SVC_K_LAUNCH_MODE); + return aul_svc_get_launch_mode(b); } SLPAPI int appsvc_create_result_bundle(bundle *inb, bundle **outb) { - int ret = -1; - - if(inb == NULL || outb == NULL) { - _E("bundle is NULL"); - return APPSVC_RET_EINVAL; - } - - ret = aul_create_result_bundle(inb, outb); - - /* add additional bundle */ - /* bundle_add(outb, " ", " "); */ - - if(ret == AUL_R_OK) - ret = APPSVC_RET_OK; - else if(ret == AUL_R_EINVAL) - ret = APPSVC_RET_EINVAL; - else - ret = APPSVC_RET_ERROR; - - return ret; + return aul_svc_create_result_bundle(inb, outb); } SLPAPI int appsvc_send_result(bundle *b, appsvc_result_val result) { - int ret; - char tmp[MAX_LOCAL_BUFSZ]; - - if(b == NULL){ - _E("appsvc_send_result is NULL"); - return APPSVC_RET_EINVAL; - } - - if(result != APPSVC_RES_OK && result != APPSVC_RES_NOT_OK){ - _E("invalid result %d", (int)result); - return APPSVC_RET_EINVAL; - } - - /* add result_code to bundle */ - snprintf(tmp,MAX_LOCAL_BUFSZ,"%d", (int)result); - ret = __set_bundle(b, APP_SVC_K_RES_VAL, tmp); - if(ret < 0) - return APPSVC_RET_ERROR; - - ret = aul_send_service_result(b); - - /* remove result_code from bundle */ - bundle_del(b, APP_SVC_K_RES_VAL); - - return ret; -} + return aul_svc_send_result(b, (aul_svc_result_val)result); +} SLPAPI int appsvc_set_defapp(const char *op, const char *mime_type, const char *uri, const char *defapp, uid_t uid) { - int ret; - - if(op == NULL || defapp == NULL) - return APPSVC_RET_EINVAL; - - ret = _svc_db_add_app(op, mime_type, uri, defapp, uid); - - if(ret < 0) - return APPSVC_RET_ERROR; - - return APPSVC_RET_OK; + return aul_svc_set_defapp_with_uid(op, mime_type, uri, defapp, uid); } SLPAPI int appsvc_unset_defapp(const char *defapp, uid_t uid) { - int ret; - - if(defapp == NULL) - return APPSVC_RET_EINVAL; - - ret = _svc_db_delete_with_pkgname(defapp, uid); - - if(ret < 0) - return APPSVC_RET_ERROR; - - return APPSVC_RET_OK; + return aul_svc_unset_defapp_with_uid(defapp, uid); } -SLPAPI int appsvc_is_defapp(const char *pkg_name, uid_t uid) +SLPAPI int appsvc_unset_all_defapps() { - return _svc_db_is_defapp(pkg_name, uid); -} - -SLPAPI int appsvc_data_is_array(bundle *b, const char *key) -{ - int type; - type = bundle_get_type(b, key); - - if(type <= 0) - return 0; - - if(type & BUNDLE_TYPE_ARRAY) - return 1; - return 0; + return aul_svc_unset_all_defapps(); } -typedef struct _appsvc_transient_cb_info_t{ - appsvc_host_res_fn cb_func; - -#ifndef WAYLAND - Ecore_X_Window win_id; -#endif - - void *data; -}appsvc_transient_cb_info_t; - -static Eina_Bool __transient_cb(void *data, int type, void *event) +SLPAPI int appsvc_is_defapp(const char *pkg_name, uid_t uid) { -#ifndef WAYLAND - Ecore_X_Event_Window_Hide *ev; - appsvc_transient_cb_info_t* cb_info; - - ev = event; - cb_info = (appsvc_transient_cb_info_t*) data; - - if(ev->win == cb_info->win_id) { - cb_info->cb_func(cb_info->data); - ecore_main_loop_quit(); - } -#endif - return ECORE_CALLBACK_RENEW; + return aul_svc_is_defapp_with_uid(pkg_name, uid); } -int __aul_subapp_cb(void *data) +SLPAPI int appsvc_data_is_array(bundle *b, const char *key) { - appsvc_transient_cb_info_t* cb_info; - - cb_info = (appsvc_transient_cb_info_t*) data; - - cb_info->cb_func(cb_info->data); - ecore_main_loop_quit(); - - return 0; + return aul_svc_data_is_array(b, key); } #ifndef WAYLAND SLPAPI int appsvc_allow_transient_app(bundle *b, Ecore_X_Window id) { - char win_id[MAX_LOCAL_BUFSZ]; - - snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", id); - - if(b == NULL){ - _E("bundle for appsvc_allow_transient_app is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, APP_SVC_K_WIN_ID, win_id); + return aul_svc_allow_transient_app(b, id); } #else SLPAPI int appsvc_allow_transient_app(bundle *b, unsigned int id) { - return 0; + return aul_svc_allow_transient_app(b, id); } #endif #ifndef WAYLAND SLPAPI int appsvc_request_transient_app(bundle *b, Ecore_X_Window callee_id, appsvc_host_res_fn cbfunc, void *data) { - char *caller = NULL; - Ecore_X_Window caller_id; - - caller = bundle_get_val(b, APP_SVC_K_WIN_ID); - if(caller == NULL) - return APPSVC_RET_ERROR; - - caller_id = atoi(caller); - - ecore_x_icccm_transient_for_set(callee_id, caller_id); - - ecore_x_window_client_manage(caller_id); - - appsvc_transient_cb_info_t* info; - - info = (appsvc_transient_cb_info_t*)calloc(1, sizeof(appsvc_transient_cb_info_t)); - if(info == NULL) - return APPSVC_RET_ERROR; - - info->win_id = caller_id; - info->cb_func = cbfunc; - info->data = data; - - ecore_event_handler_add(ECORE_X_EVENT_WINDOW_DESTROY, __transient_cb, info); - aul_set_subapp(__aul_subapp_cb, info); - - return 0; + return aul_svc_request_transient_app(b, callee_id, (aul_svc_host_res_fn)cbfunc, data); } #else SLPAPI int appsvc_request_transient_app(bundle *b, unsigned int callee_id, appsvc_host_res_fn cbfunc, void *data) { - return 0; + return aul_svc_request_transient_app(b, callee_id, (aul_svc_host_res_fn)cbfunc, data); } #endif SLPAPI int appsvc_subapp_terminate_request_pid(int pid) { - int cpid = getpid(); - int lcnt; - int *lpids = NULL; - int i; - - aul_app_group_get_leader_pids(&lcnt, &lpids); - for (i = 0; i < lcnt; i++) { - if (lpids[i] == cpid) { - int cnt; - int *pids = NULL; - - aul_app_group_get_group_pids(cpid, &cnt, &pids); - - if (cnt == 0) { - free(lpids); - return aul_subapp_terminate_request_pid(pid); - } - - if (pids != NULL) - free(pids); - break; - } - } - - if (lpids != NULL) - free(lpids); - - return aul_app_group_clear_top(); -} - -SLPAPI int aul_svc_subscribe_launch_result(bundle *b, const char *result) -{ - if (b == NULL) { - _E("bundle for aul_svc_subscribe_launch_result is NULL"); - return APPSVC_RET_EINVAL; - } - - return __set_bundle(b, result, "1"); + return aul_svc_subapp_terminate_request_pid(pid); } diff --git a/src/appsvc_db.c b/src/appsvc_db.c deleted file mode 100755 index 3781581..0000000 --- a/src/appsvc_db.c +++ /dev/null @@ -1,553 +0,0 @@ -/* - * app-svc - * - * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. - * - * Contact: Jayoun Lee , Sewook Park , Jaeho Lee - * - * 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 "appsvc_db.h" -#include "internal.h" - -#define SVC_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".appsvc.db") -#define APP_INFO_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db") - -#define QUERY_MAX_LEN 8192 -#define URI_MAX_LEN 4096 -#define BUF_MAX_LEN 1024 -#define BUFSIZE 4096 -#define ROOT_UID 0 - -#define APPSVC_COLLATION "appsvc_collation" - -#define QUERY_CREATE_TABLE_APPSVC "create table if not exists appsvc " \ - "(operation text, " \ - "mime_type text, " \ - "uri text, " \ - "pkg_name text, " \ - "PRIMARY KEY(pkg_name)) " - -static sqlite3 *svc_db = NULL; -static sqlite3 *app_info_db = NULL; - -static int _mkdir(const char *dir, mode_t mode) -{ - char tmp[PATH_MAX]; - char *p = NULL; - size_t len; - int ret; - - snprintf(tmp, sizeof(tmp), "%s", dir); - len = strlen(tmp); - if(tmp[len - 1] == '/') - tmp[len - 1] = 0; - for(p = tmp + 1; *p; p++) { - if(*p == '/') { - *p = 0; - ret = mkdir(tmp, mode); - if (ret && errno != EEXIST) - return ret; - *p = '/'; - } - } - return mkdir(tmp, mode); -} - -static void _mkdir_for_user(const char* dir, uid_t uid, gid_t gid) { - int ret = 0; - - ret = _mkdir(dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH); - if (ret == -1 && errno != EEXIST) { - _E("FAIL : to create directory %s %d", dir, errno); - } else if (getuid() == ROOT_UID) { - ret = chown(dir, uid, gid); - if (ret == -1) - _E("FAIL : chown %s %d.%d, because %s", dir, uid, gid, strerror(errno)); - } -} - -static char* getUserSvcDB(uid_t uid) -{ - const char *appsvc_db = NULL; - const char *db_path = NULL; - uid_t uid_caller = getuid(); - gid_t gid = ROOT_UID; - - if (uid == ROOT_UID) { - _E("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - - if (uid != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) { - tzplatform_set_user(uid); - appsvc_db = tzplatform_mkpath(TZ_USER_DB, ".appsvc.db"); - db_path = tzplatform_getenv(TZ_USER_DB); - gid = tzplatform_getgid(TZ_USER_NAME); - tzplatform_reset_user(); - } else { - appsvc_db = tzplatform_mkpath(TZ_SYS_DB, ".appsvc.db"); - db_path = tzplatform_getenv(TZ_SYS_DB); - } - - // just allow certain users to create missing directory. - if (uid_caller == ROOT_UID || uid_caller == uid) - _mkdir_for_user (db_path, uid, gid); - - return appsvc_db; -} - - -static char* getUserAppDB(uid_t uid) -{ - const char *app_info_db = NULL; - const char *db_path = NULL; - uid_t uid_caller = getuid(); - gid_t gid = ROOT_UID; - - if (uid == ROOT_UID) { - _E("FAIL : Root is not allowed user! please fix it replacing with DEFAULT_USER"); - return NULL; - } - - if (uid != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) { - tzplatform_set_user(uid); - app_info_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db"); - db_path = tzplatform_getenv(TZ_USER_DB); - gid = tzplatform_getgid(TZ_USER_NAME); - tzplatform_reset_user(); - } else { - app_info_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db"); - db_path = tzplatform_getenv(TZ_SYS_DB); - } - - // just allow certain users to create the missing directory. - if (uid_caller == ROOT_UID || uid_caller == uid) - _mkdir_for_user (db_path, uid, gid); - - return app_info_db; -} -/** - * db initialize - */ -static int __init(uid_t uid) -{ - int rc; - - if (svc_db) { - _D("Already initialized\n"); - return 0; - } - - rc = sqlite3_open_v2(getUserSvcDB(uid), &svc_db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); - if(rc) { - _E("Can't open database: %s", sqlite3_errmsg(svc_db)); - goto err; - } - - // Enable persist journal mode - rc = sqlite3_exec(svc_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL); - if(SQLITE_OK!=rc){ - _D("Fail to change journal mode\n"); - goto err; - } - rc = sqlite3_exec(svc_db, QUERY_CREATE_TABLE_APPSVC, NULL, NULL, NULL); - if(SQLITE_OK!=rc){ - _D("Fail to create tables\n"); - goto err; - } - - return 0; -err: - sqlite3_close(svc_db); - return -1; -} - -static int __collate_appsvc(void *ucol, int str1_len, const void *str1, int str2_len, const void *str2) -{ - char *saveptr1 = NULL; - char *saveptr2 = NULL; - char *dup_str1; - char *dup_str2; - char *token; - char *in_op; - char *in_uri; - char *in_mime; - char *op; - char *uri; - char *mime; - int i; - - if(str1 == NULL || str2 == NULL) - return -1; - - dup_str1 = strdup(str1); - dup_str2 = strdup(str2); - - in_op = strtok_r(dup_str2, "|", &saveptr1); - in_uri = strtok_r(NULL, "|", &saveptr1); - in_mime = strtok_r(NULL, "|", &saveptr1); - - token = strtok_r(dup_str1, ";", &saveptr1); - - if(token == NULL) { - free(dup_str1); - free(dup_str2); - return -1; - } - - do { - //_D("token : %s", token); - op = strtok_r(token, "|", &saveptr2); - uri = strtok_r(NULL, "|", &saveptr2); - mime = strtok_r(NULL, "|", &saveptr2); - - if( (strcmp(op, in_op) == 0) && (strcmp(mime, in_mime) == 0) ) { - _D("%s %s %s %s %s %s", op, in_op, mime, in_mime, uri, in_uri); - if(strcmp(uri, in_uri) == 0) { - free(dup_str1); - free(dup_str2); - return 0; - } else { - for(i=0; uri[i]!=0; i++) { - if(uri[i] == '*') { - uri[i] = 0; - if(strstr(in_uri, uri)) { - _D("in_uri : %s | uri : %s", in_uri, uri); - free(dup_str1); - free(dup_str2); - return 0; - } - } - } - } - } - } while(token = strtok_r(NULL, ";", &saveptr1)); - - free(dup_str1); - free(dup_str2); - - return -1; -} - -static int __init_app_info_db(uid_t uid) -{ - int rc; - - if (app_info_db) { - _D("Already initialized\n"); - return 0; - } - - rc = sqlite3_open_v2(getUserAppDB(uid), &app_info_db, SQLITE_OPEN_READONLY, NULL); - if(rc) { - _E("Can't open database: %s", sqlite3_errmsg(app_info_db)); - goto err; - } - - // Enable persist journal mode - rc = sqlite3_exec(app_info_db, "PRAGMA journal_mode = PERSIST", NULL, NULL, NULL); - if(SQLITE_OK!=rc){ - _D("Fail to change journal mode\n"); - goto err; - } - - sqlite3_create_collation(app_info_db, APPSVC_COLLATION, SQLITE_UTF8, NULL, - __collate_appsvc); - - return 0; -err: - sqlite3_close(app_info_db); - return -1; -} - - -static int __fini(void) -{ - if (svc_db) { - sqlite3_close(svc_db); - svc_db = NULL; - } - return 0; -} - - -int _svc_db_add_app(const char *op, const char *mime_type, const char *uri, const char *pkg_name, uid_t uid) -{ - char m[BUF_MAX_LEN]; - char u[URI_MAX_LEN]; - char query[QUERY_MAX_LEN]; - char* error_message = NULL; - - if(__init(uid)<0) - return -1; - - if(op == NULL ) - return -1; - - if(mime_type==NULL) - strncpy(m,"NULL",BUF_MAX_LEN-1); - else - strncpy(m,mime_type,BUF_MAX_LEN-1); - - if(uri==NULL) - strncpy(u,"NULL",URI_MAX_LEN-1); - else - strncpy(u,uri,URI_MAX_LEN-1); - - snprintf(query, QUERY_MAX_LEN, "insert into appsvc( operation, mime_type, uri, pkg_name) \ - values('%s','%s','%s','%s')",op,m,u,pkg_name); - - if (SQLITE_OK != sqlite3_exec(svc_db, query, NULL, NULL, &error_message)) - { - _E("Don't execute query = %s, error message = %s\n", query, error_message); - return -1; - } - - __fini(); - return 0; -} - -int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid) -{ - char query[QUERY_MAX_LEN]; - char* error_message = NULL; - - if(pkg_name == NULL) { - _E("Invalid argument: data to delete is NULL\n"); - return -1; - } - - if(__init(uid)<0) - return -1; - - snprintf(query, QUERY_MAX_LEN, "delete from appsvc where pkg_name = '%s';", pkg_name); - - if (SQLITE_OK != sqlite3_exec(svc_db, query, NULL, NULL, &error_message)) - { - _E("Don't execute query = %s, error message = %s\n", query, error_message); - return -1; - } - - __fini(); - - return 0; -} - -int _svc_db_is_defapp(const char *pkg_name, uid_t uid) -{ - char query[QUERY_MAX_LEN]; - sqlite3_stmt *stmt; - int cnt = 0; - int ret = -1; - - if(pkg_name == NULL) { - _E("Invalid argument: data to delete is NULL\n"); - return 0; - } - - if(__init(uid)<0) - return 0; - - snprintf(query, QUERY_MAX_LEN, - "select count(*) from appsvc where pkg_name = '%s';", pkg_name); - - ret = sqlite3_prepare_v2(svc_db, query, sizeof(query), &stmt, NULL); - if (ret != SQLITE_OK) { - return -1; - } - - ret = sqlite3_step(stmt); - if (ret == SQLITE_ROW) { - cnt = sqlite3_column_int(stmt, 0); - } - sqlite3_finalize(stmt); - - __fini(); - - if(cnt < 1) return 0; - - return 1; -} - -char* _svc_db_get_app(const char *op, const char *mime_type, const char *uri, uid_t uid) -{ - char m[BUF_MAX_LEN]; - char u[URI_MAX_LEN]; - char query[QUERY_MAX_LEN]; - sqlite3_stmt* stmt; - int ret; - char* pkgname; - char* ret_val = NULL; - - if(op == NULL ) - return NULL; - - if(mime_type==NULL) - strncpy(m,"NULL",BUF_MAX_LEN-1); - else - strncpy(m,mime_type,BUF_MAX_LEN-1); - - if(uri==NULL) - strncpy(u,"NULL",URI_MAX_LEN-1); - else - strncpy(u,uri,URI_MAX_LEN-1); - -// if(doubt_sql_injection(mime_type)) -// return NULL; - - if(__init(uid) < 0) - return NULL; - - - snprintf(query, QUERY_MAX_LEN, "select pkg_name from appsvc where operation='%s' and mime_type='%s' and uri='%s'",\ - op,m,u); - - _D("query : %s\n",query); - - ret = sqlite3_prepare_v2(svc_db, query, strlen(query), &stmt, NULL); - - if ( ret != SQLITE_OK) { - _E("prepare error(%d)\n", ret); - goto db_fini; - } - - ret = sqlite3_step(stmt); - if (ret != SQLITE_ROW) { - _D("no result"); - goto stmt_finialize; - } - - pkgname = (char*) sqlite3_column_text(stmt, 0); - if(pkgname) { - ret_val = malloc(BUF_MAX_LEN); - strncpy(ret_val, (const char *)sqlite3_column_text(stmt, 0),BUF_MAX_LEN-1); - } - - _D("pkgname : %s\n",pkgname); - -stmt_finialize : - ret = sqlite3_finalize(stmt); - if ( ret != SQLITE_OK) { - _D("finalize error(%d)", ret); - } - -db_fini : - __fini(); - - return ret_val; -} - -int _svc_db_get_list_with_condition(char *op, char *uri, char *mime, GSList **pkg_list, uid_t uid) -{ - char query[QUERY_MAX_LEN]; - sqlite3_stmt* stmt; - int ret; - GSList *iter = NULL; - char *str = NULL; - char *pkgname = NULL; - int found; - - if(__init_app_info_db(uid)<0) - return 0; - - snprintf(query, QUERY_MAX_LEN, "select ac.app_id from package_app_app_control as ac where ac.app_control like '%%%s|%s|%s%%'", op,uri,mime); - SECURE_LOGD("query : %s\n",query); - - ret = sqlite3_prepare_v2(app_info_db, query, strlen(query), &stmt, NULL); - if ( ret != SQLITE_OK) { - _E("prepare error, ret = %d, extended = %d %s\n", ret, - sqlite3_extended_errcode(app_info_db), sqlite3_errmsg(app_info_db)); - return -1; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - str = (char *)sqlite3_column_text(stmt, 0); - found = 0; - for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) { - pkgname = (char *)iter->data; - if (strncmp(str,pkgname, MAX_PACKAGE_STR_SIZE-1) == 0) { - found = 1; - break; - } - } - if(found == 0) { - pkgname = strdup(str); - *pkg_list = g_slist_append(*pkg_list, (void *)pkgname); - _D("%s is added",pkgname); - } - } - - ret = sqlite3_finalize(stmt); - - return 0; -} - -int _svc_db_get_list_with_collation(char *op, char *uri, char *mime, GSList **pkg_list, uid_t uid) -{ - char query[QUERY_MAX_LEN]; - sqlite3_stmt* stmt; - int ret; - GSList *iter = NULL; - char *str = NULL; - char *pkgname = NULL; - int found; - - if(__init_app_info_db(uid)<0) - return 0; - - snprintf(query, QUERY_MAX_LEN, "select ac.app_id from package_app_app_control as ac where ac.app_control='%s|%s|%s' collate appsvc_collation", op,uri,mime); - SECURE_LOGD("query : %s\n",query); - - ret = sqlite3_prepare_v2(app_info_db, query, strlen(query), &stmt, NULL); - - if ( ret != SQLITE_OK) { - _E("prepare error, ret = %d, extended = %d %s\n", ret, - sqlite3_extended_errcode(app_info_db), sqlite3_errmsg(app_info_db)); - return -1; - } - - while (sqlite3_step(stmt) == SQLITE_ROW) { - str = sqlite3_column_text(stmt, 0); - found = 0; - for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) { - pkgname = (char *)iter->data; - if (strncmp(str,pkgname, MAX_PACKAGE_STR_SIZE-1) == 0) { - found = 1; - break; - } - } - if(found == 0) { - pkgname = strdup(str); - *pkg_list = g_slist_append(*pkg_list, (void *)pkgname); - _D("%s is added",pkgname); - } - } - - ret = sqlite3_finalize(stmt); - - return 0; -} - - -- 2.7.4