From a25960bb3c0736bfdf752ec95e88ad845958a856 Mon Sep 17 00:00:00 2001 From: Yunjin Lee Date: Mon, 8 Aug 2016 17:06:18 +0900 Subject: [PATCH] Add API for getting privacy ID by privilege Change-Id: I090af0d4b6043cfd7cadfbb50d9cf57105626ba1 Signed-off-by: Yunjin Lee --- capi/include/privilege_db_manager.h | 1 + capi/include/privilege_info.h | 12 ++++++++++++ capi/src/privilege_db_manager.c | 25 +++++++++++++++++++++++++ capi/src/privilege_info.c | 11 +++++++++++ test/tc-privilege-info.c | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+) diff --git a/capi/include/privilege_db_manager.h b/capi/include/privilege_db_manager.h index 5017067..4d5695f 100755 --- a/capi/include/privilege_db_manager.h +++ b/capi/include/privilege_db_manager.h @@ -78,6 +78,7 @@ int privilege_db_manager_get_privacy_display(const char *privacy, char **privacy int privilege_db_manager_is(char type, const char* privilege); int __privilege_db_manager_get_privacy_list(GList** privacy_list); int __privilege_db_manager_get_privilege_list_by_privacy(const char* privacy, GList **privilege_list); +int privilege_db_manager_get_privacy_by_privilege(const char* privilege, char** privacy); int privilege_db_manager_get_black_list(int uid, privilege_db_manager_package_type_e package_type, GList** privilege_list); int privilege_db_manager_set_black_list(int uid, privilege_db_manager_package_type_e pacakge_type, GList *privilege_list); diff --git a/capi/include/privilege_info.h b/capi/include/privilege_info.h index cfc47a3..33005dc 100644 --- a/capi/include/privilege_info.h +++ b/capi/include/privilege_info.h @@ -165,6 +165,18 @@ EXPORT_API int privilege_info_get_privacy_display(const char* privacy, char** pr EXPORT_API int privilege_info_get_privilege_list_by_privacy(const char *privacy, GList **privilege_list); /** + * @brief Gets privacy id of the given privilege. + * @remarks @a privacy must be released with g_list_free() by you. + * @param [in] privilege The privilege + * @param [out] privacy The privacy id of the given privilege + * @return 0 on success, otherwise a nonzero error value. + * @retval #PRVMGR_ERR_NONE Successful + * @retval #PRVMGR_ERR_INTERNAL_ERROR Internal error + * @retval #PRVMGR_ERR_INVALID_PARAMETER Invalid parameter + */ +EXPORT_API int privilege_info_get_privacy_by_privilege(const char *privilege, char** privacy); + +/** * @brief Gets the list of privilges marked as black list. * @remarks @a privilege_list must be released with g_list_free() by you. * @param [in] uid The UID diff --git a/capi/src/privilege_db_manager.c b/capi/src/privilege_db_manager.c index d81d773..9a880c3 100755 --- a/capi/src/privilege_db_manager.c +++ b/capi/src/privilege_db_manager.c @@ -568,6 +568,31 @@ int __privilege_db_manager_get_privilege_list_by_privacy(const char* privacy, GL } +int privilege_db_manager_get_privacy_by_privilege(const char* privilege, char** privacy) +{ + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + int ret = __initialize_db('i', &db, PRIVILEGE_DB_MANAGER_PACKAGE_TYPE_CORE); + if (ret != PRIVILEGE_DB_MANAGER_ERR_NONE) + return ret; + + char *sql = sqlite3_mprintf("select privacy_group from privilege_info where privilege_name=%Q", privilege); + TryReturn(sql != NULL, __finalize_db(db, stmt, sql), PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY, "[DB_FAIL] sqlite3_mprintf failed"); + ret = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL); + if (ret != SQLITE_OK) { + _LOGE("[DB_FAIL] fail to prepare database : %s", sqlite3_errmsg(db)); + __finalize_db(db, stmt, sql); + return PRIVILEGE_DB_MANAGER_ERR_INVALID_QUERY; + } + ret = sqlite3_step(stmt); + if (ret == SQLITE_ROW) + *privacy = strdup((char*)sqlite3_column_text(stmt, 0)); + + __finalize_db(db, stmt, sql); + + return PRIVILEGE_DB_MANAGER_ERR_NONE; +} + int privilege_db_manager_get_black_list(int uid, privilege_db_manager_package_type_e package_type, GList **privilege_list) { sqlite3 *db = NULL; diff --git a/capi/src/privilege_info.c b/capi/src/privilege_info.c index 7642dec..bfda875 100755 --- a/capi/src/privilege_info.c +++ b/capi/src/privilege_info.c @@ -605,6 +605,17 @@ int privilege_info_get_privilege_list_by_privacy(const char* privacy, GList **pr return ret; } +int privilege_info_get_privacy_by_privilege(const char* privilege, char** privacy) +{ + TryReturn(privilege != NULL, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] privilege is NULL"); + TryReturn(privilege_db_manager_is('p', privilege) == 1, , PRVMGR_ERR_INVALID_PARAMETER, "[PRVMGR_ERR_INVALID_PARAMETER] given privilege is NOT a privacy related"); + int ret = privilege_db_manager_get_privacy_by_privilege(privilege, privacy); + if (ret == PRIVILEGE_DB_MANAGER_ERR_NONE) + ret = PRVMGR_ERR_NONE; + else + ret = PRVMGR_ERR_INTERNAL_ERROR; + return ret; +} int privilege_info_get_black_list(int uid, privilege_manager_package_type_e package_type, GList **privilege_list) { diff --git a/test/tc-privilege-info.c b/test/tc-privilege-info.c index 98a7e1e..75b88dc 100755 --- a/test/tc-privilege-info.c +++ b/test/tc-privilege-info.c @@ -106,6 +106,7 @@ static void __check_get_privilege_group_display_name_result(privilege_manager_er } __color_to_origin(); } + static void __test_privilege_info_is_valid() { int ret; @@ -286,6 +287,37 @@ static void __test_privilege_info_get_privilege_list_by_privacy() __print_line(); } +static void __test_privilege_info_get_privacy_by_privilege() +{ + printf("privilege : http://tizen.org/privilege/apphistory.read\n"); + char* privacy = NULL; + int ret = privilege_info_get_privacy_by_privilege("http://tizen.org/privilege/apphistory.read", &privacy); + if (ret == PRVMGR_ERR_NONE) { + success_cnt++; + printf("privacy id: %s\n", privacy); + } else { + fail_cnt++; + printf("Test FAILED\n"); + } + + free(privacy); + privacy = NULL; + + __print_line(); + + printf("privilege : http://tizen.org/privilege/internet\n"); + ret = privilege_info_get_privacy_by_privilege("http://tizen.org/privilege/internet", &privacy); + if (ret == PRVMGR_ERR_INVALID_PARAMETER) { + success_cnt++; + printf("privilege: http://tizen.org/privilege/internet is not a privacy related.\n"); + } else { + fail_cnt++; + printf("Test FAILED\n"); + } + free(privacy); + __print_line(); +} + static void __test_privilege_info_get_privilege_display_name() { int ret; @@ -409,6 +441,9 @@ int main() __tcinfo(function, "privilege_info_get_privilege_list_by_privacy"); __test_privilege_info_get_privilege_list_by_privacy(); + __tcinfo(function, "privilege_info_get_privacy_by_privilege"); + __test_privilege_info_get_privacy_by_privilege(); + __color_to_green(); printf("Test Complete\n"); printf("success : %d, ", success_cnt); -- 2.7.4