diff options
Diffstat (limited to 'client/inc')
-rw-r--r-- | client/inc/PrivacyChecker.h | 88 | ||||
-rw-r--r-- | client/inc/PrivacyManagerClient.h | 72 | ||||
-rw-r--r-- | client/inc/SocketClient.h | 150 | ||||
-rw-r--r-- | client/inc/privacy_checker_client.h | 98 | ||||
-rw-r--r-- | client/inc/privacy_info_client.h | 45 | ||||
-rw-r--r-- | client/inc/privacy_manager_client.h | 52 |
6 files changed, 505 insertions, 0 deletions
diff --git a/client/inc/PrivacyChecker.h b/client/inc/PrivacyChecker.h new file mode 100644 index 0000000..96ab93d --- /dev/null +++ b/client/inc/PrivacyChecker.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2012 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 _PRIVACY_CHECKER_H_ +#define _PRIVACY_CHECKER_H_ + +#include <string> +#include <mutex> +#include <list> +#include <vector> +#include <memory> +#include <map> +#include <condition_variable> +#include <PrivacyManagerTypes.h> +#include <dbus/dbus.h> +#include <glib.h> + +struct sqlite3; + +class EXTERN_API PrivacyChecker +{ +private: + static std::map < std::string, std::pair<bool,bool> > m_privacyCache; + static std::map < std::string, std::map < std::string, std::pair<bool,bool> > > m_privacyInfoCache; + static std::string m_pkgId; + static bool m_isInitialized; + static std::mutex m_cacheMutex; + static DBusConnection* m_pDBusConnection; + static GMainLoop* m_pLoop; + static GMainContext* m_pHandlerGMainContext; + static pthread_t m_signalThread; + static std::mutex m_dbusMutex; + static std::condition_variable m_condition; + static std::mutex m_initializeMutex; + static bool m_isPreloaded; + static bool m_isServiceProcess; + +private: + static int initializeDbus(void); + static int finalizeDbus(void); + static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, std::pair<bool,bool> >& pkgCacheMap); + static int updateCache(const std::string pkgId, std::map < std::string, std::pair<bool,bool> >& pkgCacheMap); + static void printCache(void); + static void* runSignalListenerThread(void* pData); + static int getCurrentPkgId(std::string& pkgId); + static int check(const std::string privacyId, std::map < std::string, std::pair<bool,bool> >& privacyMap); + static void notify(const std::string& pkgId, const std::string privacyId); + static void removeWhiteSpace(std::string& packageNameString); + static bool isExceptionalCase(const std::string&); + +public: + // for Checking in Server Process + static int initialize(const std::string pkgId); + static int check(const std::string pkgId, const std::string privacyId); + static int checkWithPrivilege(const std::string pkgId, const std::string privilegeId); + static int checkWithDeviceCap(const std::string pkgId, const std::string deviceCap); + + // for Checking in App Process + static int initialize(void); + static int check(const std::string privacyId); + static int checkWithPrivilege(const std::string privilegeId); + static int checkWithDeviceCap(const std::string deviceCap); + static int checkExceptionalCase(std::string& pkgId, const std::string &privacyId); + + // common + static int finalize(void); + static int finalizeWihtoutCache(void); + static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data); + + // utility + static int getPackageId(std::string& pkgId); + static int isPreloadedPackage(const std::string& pkdId); +}; + +#endif // _PRIVACY_CHECKER_H_ diff --git a/client/inc/PrivacyManagerClient.h b/client/inc/PrivacyManagerClient.h new file mode 100644 index 0000000..cfd34ca --- /dev/null +++ b/client/inc/PrivacyManagerClient.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2012 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 _PRIVACY_MANAGER_H_ +#define _PRIVACY_MANAGER_H_ + +#include <string> +#include <mutex> +#include <list> +#include <vector> +#include <memory> +#include <PrivacyManagerTypes.h> + +class SocketClient; + +class EXTERN_API PrivacyManagerClient +{ +private: + static PrivacyManagerClient* m_pInstance; + static const std::string INTERFACE_NAME; + + std::unique_ptr< SocketClient > m_pSocketClient; + + static std::mutex m_singletonMutex; + + PrivacyManagerClient(); + ~PrivacyManagerClient(); + +public: + static PrivacyManagerClient* getInstance(void); + + int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list, bool privacyPopupRequired, bool isServerOperation = true); + + int removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation = true); + + int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled); + + int getPrivacyAppPackages(std::list < std::string >& list) const; + + int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const; + + int isUserPrompted(const std::string pkgId, bool& isPrompted) const; + + int setUserPrompted(const std::string pkgId, bool prompted); + + int getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const; + + int getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const; + + int getPrivaycDisplayNameStringId(const std::string privacyId, std::string& displayNameStringId) const; + + int getPrivaycDescription(const std::string privacyId, std::string& description) const; + + int getPrivaycDescriptionStringId(const std::string privacyId, std::string& descriptionStringId) const; + + int notifyUserNotConsented(const std::string pkgId, const std::string privacyId) const; +}; + +#endif // _PRIVACY_MANAGER_H_ diff --git a/client/inc/SocketClient.h b/client/inc/SocketClient.h new file mode 100644 index 0000000..d2713b1 --- /dev/null +++ b/client/inc/SocketClient.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2012 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 SECURITYSOCKETCLIENT_H_ +#define SECURITYSOCKETCLIENT_H_ + +#include <memory> +#include <string> +#include <dlog.h> +#include "SocketConnection.h" + +/* IMPORTANT: + * Methods connect(), call() and disconnected() should be called one by one. + * Between connect() and disconnect() you can use call() only once. + * It is because of timeout on call, e.g. to avoid waiting for corrupted data. + */ + +/* USAGE: + * Class should be used according to this scheme: + * SocketClient client("Interface Name"); + * (...) + * client.connect(); + * client.call("Method name", in_arg1, in_arg2, ..., in_argN, + * out_arg1, out_arg2, ..., out_argM); + * client.disconnect(); + * (...) + * + * input parameters of the call are passed with reference, + * output ones are passed as pointers - parameters MUST be passed this way. + * + * Currently client supports serialization and deserialization of simple types + * (int, char, float, unsigned), strings (std::string and char*) and + * some STL containers (std::vector, std::list, std::map, std::pair). + * Structures and classes are not (yet) supported. + */ + +#include <string> +#include <PrivacyManagerTypes.h> + +class EXTERN_API SocketClient +{ +public: + + SocketClient(const std::string &interfaceName); + int connect(); + int disconnect(); + + int call(std::string methodName) + { + int res = make_call(m_interfaceName); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + + res = make_call(methodName); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename ...Args> + int call(std::string methodName, const Args&... args) + { + int res = make_call(m_interfaceName); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + res = make_call(methodName); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + res = make_call(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T> + int read(T* outvalue) + { + return m_socketConnector->read(outvalue); + } +private: + template<typename T, typename ...Args> + int make_call(const T& invalue, const Args&... args) + { + int res = make_call(invalue); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + res = make_call(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T> + int make_call(const T& invalue) + { + return m_socketConnector->write(invalue); + } + + template<typename T, typename ...Args> + int make_call(const T* invalue, const Args&... args) + { + int res = make_call(invalue); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + res = make_call(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T> + int make_call(const T* invalue) + { + return m_socketConnector->write(invalue); + } + + template<typename T, typename ...Args> + int make_call(T * outvalue, const Args&... args) + { + int res = make_call(outvalue); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + res = make_call(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "make_call : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T> + int make_call(T* outvalue) + { + return m_socketConnector->read(outvalue); + } + + +private: + std::string m_serverAddress; + std::string m_interfaceName; + std::unique_ptr<SocketConnection> m_socketConnector; + int m_socketFd; +}; + +#endif /* SECURITYSOCKETCLIENT_H_ */
\ No newline at end of file diff --git a/client/inc/privacy_checker_client.h b/client/inc/privacy_checker_client.h new file mode 100644 index 0000000..63fff77 --- /dev/null +++ b/client/inc/privacy_checker_client.h @@ -0,0 +1,98 @@ +/* + * 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. + */ + +#ifndef _PRIVACY_CHECKER_CLIENT_H +#define _PRIVACY_CHECKER_CLIENT_H + +#include <privacy_manager_client_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_PRIVACY_MANAGER_MODULE + * @{ + */ + +/** + * @brief Initialize privacy checker + * @param [in] package_id The ID of the pacakge to check + * @return PRIV_MGR_ERROR_SUCCESS on success, otherwise a negative error value + * @retval #PRIV_MGR_ERROR_SUCCESS Successful + * @retval #PRIV_MGR_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #PRIV_MGR_ERROR_SYSTEM_ERROR Failed to initialize + * @post privacy_checker_finalize must be called to finalize + */ +EXTERN_API int privacy_checker_initialize(const char *package_id); + +/** + * @brief Checks privacy is enabled or not by privacy id + * @param [in] privacy_ud The ID of privacy + * @return PRIV_MGR_ERROR_SUCCESS if the privacy is enabled else PRIV_MGR_ERROR_USER_NOT_CONSENTED, otherwise a negative error value + * @retval #PRIV_MGR_ERROR_SUCCESS Successful + * @retval #PRIV_MGR_ERROR_NOT_INITIALIZED Privacy chcker is not initialized + * @retval #PRIV_MGR_ERROR_DB_ERROR DB operation failed + * @retval #PRIV_MGR_ERROR_USER_NOT_CONSENTED The privacy of the package disabled + * @pre privacy_checker_initialize must be called to initialize + * @post privacy_checker_finalize must be called to finalize + * @see privacy_checker_initialize + * @see privacy_checker_finalize + */ +EXTERN_API int privacy_checker_check_by_privacy(const char *privacy_id); + +/** + * @brief Checks privacy is enabled or not by privilege id + * @param [in] privilege_id The ID of the privilege + * @return PRIV_MGR_ERROR_SUCCESS if the privacy is enabled else PRIV_MGR_ERROR_USER_NOT_CONSENTED, otherwise a negative error value + * @retval #PRIV_MGR_ERROR_SUCCESS Successful + * @retval #PRIV_MGR_ERROR_NOT_INITIALIZED Privacy chcker is not initialized + * @retval #PRIV_MGR_ERROR_DB_FAILED DB operation failed + * @retval #PRIV_MGR_ERROR_INVALID_PARAMETER invalid parameter + * @retval #PRIV_MGR_ERROR_USER_NOT_CONSENTED The privacy of the package disabled + * @remark Caller can free resource by calling privacy_checker_finalize() after calling this API otherwise, finalize while library unloading\n + * This API initialize privacy checker for the first time + * @see privacy_checker_finalize + */ +EXTERN_API int privacy_checker_check_by_privilege(const char *privilege_id); + +/** + * @brief Finalize privacy checker + * @return 0 on success. + * @retval #PRIV_MGR_ERROR_SUCCESS Successful + */ +EXTERN_API int privacy_checker_finalize(void); + +/** + * @brief Check privacy is enabled or not by privilege id of the package + * @param [in] package_id The ID of the pacakge + * @param [in] privacy_id The ID of the privacy + * @return PRIV_MGR_ERROR_SUCCESS if the privacy is enabled else PRIV_MGR_ERROR_USER_NOT_CONSENTED, otherwise a negative error value + * @retval #PRIV_MGR_ERROR_SUCCESS Successful + * @retval #PRIV_MGR_ERROR_DB_FAILED DB operation failed + * @retval #PRIV_MGR_ERROR_INVALID_PARAMETER invalid parameter + * @retval #PRIV_MGR_ERROR_USER_NOT_CONSENTED The privacy of the package disabled + * @post privacy_checker_finalize must be called to finalize + * @see privacy_checker_finalize + */ +EXTERN_API int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id); + +#ifdef __cplusplus +} +#endif + + +#endif //_PRIVACY_CHECKER_CLIENT_H diff --git a/client/inc/privacy_info_client.h b/client/inc/privacy_info_client.h new file mode 100644 index 0000000..afb9c1c --- /dev/null +++ b/client/inc/privacy_info_client.h @@ -0,0 +1,45 @@ +/* + * 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. + */ + +#ifndef _PRIVACY_INFO_CLIENT_H +#define _PRIVACY_INFO_CLIENT_H + +#include <privacy_manager_client_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct _privacy_info_client_s { + char *privacy_id; + bool is_enabled; +} privacy_info_client_s; + +EXTERN_API int create_privacy_info_client_s(const char* package_id, bool enabled, privacy_info_client_s **privacy_info); +EXTERN_API int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info); +EXTERN_API int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id); +EXTERN_API int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name); +EXTERN_API int privacy_info_client_get_privacy_display_name_string_id(privacy_info_client_s* privacy_info, char **name_string_id); +EXTERN_API int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description); +EXTERN_API int privacy_info_client_get_privacy_description_string_id(privacy_info_client_s* privacy_info, char **description_string_id); +EXTERN_API int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled); + +#ifdef __cplusplus +} +#endif + + +#endif //_PRIVACY_INFO_CLIENT_H diff --git a/client/inc/privacy_manager_client.h b/client/inc/privacy_manager_client.h new file mode 100644 index 0000000..eabdd22 --- /dev/null +++ b/client/inc/privacy_manager_client.h @@ -0,0 +1,52 @@ +/* + * 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. + */ + +#ifndef _PRIVACY_MANAGER_CLIENT_H +#define _PRIVACY_MANAGER_CLIENT_H + +#include <privacy_info_client.h> +#include <privacy_manager_client_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +typedef bool (*privacy_manager_client_privacy_packages_cb) (const char *package_id, void* user_data); +typedef bool (*privacy_manager_client_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data); +typedef bool (*privacy_manager_client_all_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data); +typedef bool (*privacy_manager_client_packages_by_privacy_cb) (const char *package_id, bool is_enabled, void* user_data); + +EXTERN_API int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list, bool privacy_popup_required); +EXTERN_API int privacy_manager_client_install_privacy_by_client(const char *package_id, const char** privacy_list, bool privacy_popup_required); +EXTERN_API int privacy_manager_client_uninstall_privacy(const char *package_id); +EXTERN_API int privacy_manager_client_uninstall_privacy_by_server(const char *package_id); +EXTERN_API int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data); +EXTERN_API int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data); +EXTERN_API int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable); + +EXTERN_API int privacy_manager_client_check_user_consented(const char *package_id, bool *consented); +EXTERN_API int privacy_manager_client_set_user_consented(const char *package_id, bool consented); + +EXTERN_API int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data); +EXTERN_API int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data); + +#ifdef __cplusplus +} +#endif + + +#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_H + |