From: Hyunwoo Kim Date: Mon, 18 Mar 2013 06:46:37 +0000 (+0900) Subject: Add capi of privacy manager X-Git-Tag: accepted/tizen_2.1/20130425.032956~26^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25a262260b139f81c9a590eb321ef991312a18a5;p=platform%2Fcore%2Fsecurity%2Fprivacy-manager.git Add capi of privacy manager Change-Id: I0822bdceeda45a7ff4e585737b6297d5fbd52574 Signed-off-by: Hyunwoo Kim --- diff --git a/capi-security-privacy-manager.pc.in b/capi-security-privacy-manager.pc.in new file mode 100755 index 0000000..516dca4 --- /dev/null +++ b/capi-security-privacy-manager.pc.in @@ -0,0 +1,15 @@ + +# Package Information for pkg-config + +prefix=@PREFIX@ +exec_prefix=/usr +libdir=/usr/lib +includedir=/usr/include/privacymgr + +Name: @PC_NAME@ +Description: @PACKAGE_DESCRIPTION@ +Version: @VERSION@ +Requires: @PC_REQUIRED@ +Libs: -L${libdir} @PC_LDFLAGS@ +Cflags: -I${includedir} + diff --git a/capi/CMakeLists.txt b/capi/CMakeLists.txt new file mode 100755 index 0000000..162f60b --- /dev/null +++ b/capi/CMakeLists.txt @@ -0,0 +1,98 @@ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-security-privacy-manager") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR} /usr/include/privacy_manager) + +#SET(requires capi-base-common dlog privacy-manager-client glib-2.0) +SET(pc_requires "capi-base-common") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED capi-base-common dlog glib-2.0) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DSLP_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION ../lib) +INSTALL( + DIRECTORY ${INC_DIR}/ DESTINATION ../include/privacymgr + FILES_MATCHING + PATTERN "*_private.h" EXCLUDE + PATTERN "${INC_DIR}/*.h" + ) + +SET(PC_NAME ${fw_name}) +SET(PC_REQUIRED ${pc_requires}) +SET(PC_LDFLAGS -l${fw_name}) +SET(PC_CFLAGS -I\${includedir}/privacymgr) + +#CONFIGURE_FILE( +# ../capi-security-privacy-manager.pc.in +# ${CMAKE_CURRENT_SOURCE_DIR}/../${fw_name}.pc +# @ONLY +#) +CONFIGURE_FILE(../capi-security-privacy-manager.pc.in capi-security-privacy-manager.pc @ONLY) + +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ../lib/pkgconfig) + +IF(UNIX) + +ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) +ADD_CUSTOM_COMMAND( + DEPENDS clean + COMMENT "distribution clean" + COMMAND find + ARGS . + -not -name config.cmake -and \( + -name tester.c -or + -name Testing -or + -name CMakeFiles -or + -name cmake.depends -or + -name cmake.check_depends -or + -name CMakeCache.txt -or + -name cmake.check_cache -or + -name *.cmake -or + -name Makefile -or + -name core -or + -name core.* -or + -name gmon.out -or + -name install_manifest.txt -or + -name *.pc -or + -name *~ \) + | grep -v TC | xargs rm -rf + TARGET distclean + VERBATIM +) + +ENDIF(UNIX) + diff --git a/capi/include/privacy_info.h b/capi/include/privacy_info.h new file mode 100644 index 0000000..f3cee7e --- /dev/null +++ b/capi/include/privacy_info.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2011 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 __TIZEN_SECURITY_PRIVACY_INFO_H +#define __TIZEN_SECURITY_PRIVACY_INFO_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Privacy information handle. + */ +typedef struct privacy_info_s *privacy_info_h; + +/** + * @brief Destroys the privacy information handle and releases all its resources. + * @param [in] privacy_info The application information handle + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @see app_manager_foreach_app_info() + * @see app_manager_get_app_info() + */ +EXPORT_API int privacy_info_destroy(privacy_info_h privacy_info); + +/** + * @brief Gets the privacy ID with the given privacy info. + * @remarks @a package must be released with free() by you. + * @param [in] privacy_info The privacy information + * @param [out] package_id The package ID of the privacy info + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + */ +EXPORT_API int privacy_info_get_privacy_id(privacy_info_h privacy_info, char **privacy_id); + +/** + * @brief Gets the privacy display name with the given privacy info. + * @remarks @a name must be released with free() by you. + * @param [in] privacy_info The privacy information + * @param [out] name The display name of the privacy info + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + */ +EXPORT_API int privacy_info_get_privacy_display_name(privacy_info_h privacy_info, char **name); + +/** + * @brief Gets the description with the given privacy info. + * @remarks @a description must be released with free() by you. + * @param [in] privacy_info The privacy information + * @param [out] description The description of the privacy info + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY Out of memory + */ +EXPORT_API int privacy_info_get_privacy_description(privacy_info_h privacy_info, char **description); + +/** + * @brief Checks whether the privacy setting is enabled. + * @param [in] privacy_info The privacy information + * @param [out] enabled A boolean value indicating whether the privacy setting is enabled. + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + */ +EXPORT_API int privacy_info_is_enabled(privacy_info_h privacy_info, bool *enabled); + + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SECURITY_PRIVACY_INFO_H diff --git a/capi/include/privacy_manager.h b/capi/include/privacy_manager.h new file mode 100644 index 0000000..9900d3b --- /dev/null +++ b/capi/include/privacy_manager.h @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2011 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 __TIZEN_SECURITY_PRIVACY_MANAGER_H +#define __TIZEN_SECURITY_PRIVACY_MANAGER_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_PRIVACY_MANAGER_MODULE + * @{ + */ + +/** + * @brief Enumerations of error code for Privacy Manager. + */ +typedef enum +{ + PRIVACY_MANAGER_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + PRIVACY_MANAGER_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + PRIVACY_MANAGER_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + PRIVACY_MANAGER_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< Internal I/O error */ + PRIVACY_MANAGER_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA, /**< No data found */ + PRIVACY_MANAGER_ERROR_DB_FAILED = TIZEN_ERROR_APPLICATION_CLASS | 0x01, /**< Database error */ + PRIVACY_MANAGER_ERROR_IPC_FAILED = TIZEN_ERROR_APPLICATION_CLASS | 0x02, /**< Failed to communication with server */ +} privacy_manager_error_e; + +//struct privacy_info_h; + +/** + * @brief Called to get a package id once for each privacy package. + * @remarks @a package_id will be automatically destroyed when the callback function returns. (Do not release @a package_id.) + * @param[in] package_id The privacy package id + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. + * @pre privacy_manager_foreach_privacy_packages() will invoke this callback. + * @see privacy_manager_foreach_privacy_packages() + */ +typedef bool (*privacy_manager_privacy_packages_cb) (const char *package_id, void* user_data); + +/** + * @brief Called to get package privacy info once for specific package. + * @remarks @a privacy_info will be automatically destroyed when the callback function returns. (Do not release @a privacy_info.) + * @param[in] privacy_info_h privacy info of the packcage + * @param[in] user_data The user data passed from the foreach function + * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop. + * @pre privacy_manager_foreach_privacy_info() will invoke this callback. + * @see privacy_manager_foreach_privacy_info() + */ +typedef bool (*privacy_manager_privacy_info_cb) (privacy_info_h privacy_info, void* user_data); + +/** + * @brief Retrieves privacy package list. + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_NO_DATA no package founded. + * @retval #PRIVACY_MANAGER_ERROR_IPC_FAILED IPC failed + * @retval #PRIVACY_MANAGER_ERROR_DB_FAILED DB operation failed + * @post This function invokes privacy_manager_privacy_packages_cb() repeatedly for each application context. + * @see privacy_manager_privacy_packages_cb() + */ +EXPORT_API int privacy_manager_foreach_privacy_packages(privacy_manager_privacy_packages_cb callback, void *user_data); + +/** + * @brief Retrieves privacy info of the pacakge. + * @param [in] package_id The ID of the pacakge. + * @param [in] callback The callback function to invoke + * @param [in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_NO_DATA no privacy info founded. + * @retval #PRIVACY_MANAGER_ERROR_IPC_FAILED IPC failed + * @retval #PRIVACY_MANAGER_ERROR_DB_FAILED DB operation failed + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER invalid parameter + * @post This function invokes privacy_manager_privacy_info_cb() repeatedly for each application context. + * @see privacy_manager_privacy_info_cb() + */ +EXPORT_API int privacy_manager_foreach_privacy_info(const char *package_id, privacy_manager_privacy_info_cb callback, void* user_data); + +/** + * @brief Enables or disables privacy of the package. + * @param [in] package_id The ID of the pacakge. + * @param [in] privacy_id The ID of the privacy to be changed. + * @param [in] callback The callback function to invoke + * @param [in] enable A Boolean value indicating whether the privacy setting is enabled + * @return 0 on success, otherwise a negative error value. + * @retval #PRIVACY_MANAGER_ERROR_NONE Successful + * @retval #PRIVACY_MANAGER_ERROR_IPC_FAILED IPC failed + * @retval #PRIVACY_MANAGER_ERROR_DB_FAILED DB operation failed + * @retval #PRIVACY_MANAGER_ERROR_INVALID_PARAMETER invalid parameter + */ +EXPORT_API int privacy_manager_set_package_privacy(const char *package_id, const char *privacy_id, bool enable); + + +#ifdef __cplusplus +} +#endif + +#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_H diff --git a/capi/include/privacy_manager_types_private.h b/capi/include/privacy_manager_types_private.h new file mode 100644 index 0000000..e5ef9d8 --- /dev/null +++ b/capi/include/privacy_manager_types_private.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2011 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 __TIZEN_SECURITY_PRIVACY_INFO_TYPES_H +#define __TIZEN_SECURITY_PRIVACY_INFO_TYPES_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct privacy_info_s{ + privacy_info_client_s* privacy_info_client; +}; + +#ifdef __cplusplus +} +#endif + +#endif // __TIZEN_SECURITY_PRIVACY_INFO_TYPES_H diff --git a/capi/src/privacy-manager.c b/capi/src/privacy-manager.c new file mode 100644 index 0000000..a78bf9d --- /dev/null +++ b/capi/src/privacy-manager.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2013 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 +#include +#include +#include +#include +#include +#include +#include + + +static int _privacy_manager_convert_error(int error) +{ + return PRIVACY_MANAGER_ERROR_NONE; +} + +typedef struct _foreach_privacy_package_context_ +{ + privacy_manager_privacy_packages_cb callback; + void *user_data; +} foreach_privacy_package_context_s; + +typedef struct _foreach_privacy_info_context_ +{ + privacy_manager_privacy_info_cb callback; + void *user_data; +} foreach_privacy_info_context_s; + +//static int _create_privacy_info(const char* package_id, bool enabled, privacy_info_h *privacy_info) +//{ +// privacy_info_h temp = (privacy_info_h) calloc(1, sizeof(privacy_info_h)); +// if (temp == NULL) +// return PRIV_MGR_ERROR_OUT_OF_MEMORY; +// +// int size = strlen(package_id); +// temp->privacy_info_client->privacy_id = (char*) calloc(1, size + 1); +// if (temp->privacy_info_client->privacy_id == NULL) +// { +// free(temp); +// return PRIV_MGR_ERROR_OUT_OF_MEMORY; +// } +// memcpy(temp->privacy_info_client->privacy_id, package_id, size + 1); +// +// temp->privacy_info_client->is_enabled = enabled; +// +// *privacy_info = temp; +// +// return PRIV_MGR_ERROR_SUCCESS; +//} + +bool __privacy_manager_client_privacy_packages_cb(const char *package_id, void* user_data) +{ + foreach_privacy_package_context_s* context = (foreach_privacy_package_context_s*) user_data; + return context->callback(package_id, context->user_data); +} + +bool __privacy_manager_client_privacy_info_cb (privacy_info_client_s* privacy_info_client, void* user_data) +{ + foreach_privacy_info_context_s* context = (foreach_privacy_info_context_s*) user_data; + + struct privacy_info_s* privacy_info = NULL; + + bool ret = false; + + privacy_info = (struct privacy_info_s*) calloc(1, sizeof(struct privacy_info_s)); + + privacy_info->privacy_info_client = privacy_info_client; + + ret = context->callback(privacy_info, context->user_data); + + free(privacy_info); + + return ret; +} + +int privacy_manager_foreach_privacy_packages(privacy_manager_privacy_packages_cb callback, void *user_data) +{ + int retval; + + foreach_privacy_package_context_s* context = NULL; + + context = (foreach_privacy_package_context_s*) calloc(1, sizeof(foreach_privacy_package_context_s)); + if (context == NULL) + return PRIV_MGR_ERROR_OUT_OF_MEMORY; + + context->callback = callback; + context->user_data = user_data; + + retval = privacy_manager_client_foreach_privacy_packages(__privacy_manager_client_privacy_packages_cb, context); + free(context); + + return _privacy_manager_convert_error(retval); +} + +int privacy_manager_foreach_privacy_info(const char *package_id, privacy_manager_privacy_info_cb callback, void* user_data) +{ + int retval; + + foreach_privacy_info_context_s* context = NULL; + + context = (foreach_privacy_info_context_s*) calloc(1, sizeof(foreach_privacy_info_context_s)); + if (context == NULL) + return PRIV_MGR_ERROR_OUT_OF_MEMORY; + + context->callback = callback; + context->user_data = user_data; + + retval = privacy_manager_client_foreach_get_privacy_info(package_id, __privacy_manager_client_privacy_info_cb, context); + + return _privacy_manager_convert_error(retval); +} +int privacy_manager_set_package_privacy(const char *package_id, const char *privacy_id, bool enable) +{ + int retval = privacy_manager_client_set_package_privacy(package_id, privacy_id, enable); + + return _privacy_manager_convert_error(retval); +} diff --git a/capi/src/privacy_info.c b/capi/src/privacy_info.c new file mode 100644 index 0000000..a41284f --- /dev/null +++ b/capi/src/privacy_info.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013 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 +#include +#include +#include +#include +#include +#include + +static int _privacy_info_convert_error(int error) +{ + + return PRIVACY_MANAGER_ERROR_NONE; +} + +int privacy_info_destroy(privacy_info_h privacy_info) +{ + int retval; + if (privacy_info == NULL) + return PRIV_MGR_ERROR_INVALID_PARAMETER; + + if (privacy_info->privacy_info_client) + { + retval = privacy_info_client_s_destroy(privacy_info->privacy_info_client); + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + } + + free (privacy_info); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_info_get_privacy_id(privacy_info_h privacy_info, char **package) +{ + int retval = privacy_info_client_get_privacy_id(privacy_info->privacy_info_client, package); + + return _privacy_info_convert_error(retval); +} + +int privacy_info_get_privacy_display_name(struct privacy_info_s* privacy_info, char **name) +{ + int retval = privacy_info_client_get_privacy_display_name(privacy_info->privacy_info_client, name); + + return _privacy_info_convert_error(retval); +} + +int privacy_info_get_privacy_description(struct privacy_info_s* privacy_info, char **description) +{ + int retval = privacy_info_client_get_privacy_description(privacy_info->privacy_info_client, description); + + return _privacy_info_convert_error(retval); +} + +int privacy_info_is_enabled(struct privacy_info_s* privacy_info, bool *enable) +{ + int retval = privacy_info_client_is_enabled(privacy_info->privacy_info_client, enable); + + return _privacy_info_convert_error(retval); +}