diff options
author | Hyunwoo Kim <hwlove.kim@samsung.com> | 2013-06-28 19:22:07 +0900 |
---|---|---|
committer | Hyunwoo Kim <hwlove.kim@samsung.com> | 2013-06-28 19:23:27 +0900 |
commit | 733d34e89fa095db1954c3b108eea36de063ed64 (patch) | |
tree | 99d485f10b92380f9c9d957fea19f6f2542dd912 | |
parent | 37253c36754f1f8ca81c6e729c505251c28b3afb (diff) | |
download | privacy-manager-733d34e89fa095db1954c3b108eea36de063ed64.tar.gz privacy-manager-733d34e89fa095db1954c3b108eea36de063ed64.tar.bz2 privacy-manager-733d34e89fa095db1954c3b108eea36de063ed64.zip |
modify logs
Change-Id: Iebc4b089e81ad14015afa75b583fca43e1638298
Signed-off-by: Hyunwoo Kim <hwlove.kim@samsung.com>
41 files changed, 3803 insertions, 3934 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b97fd9..6bb3e86 100755..100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,21 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-
-MESSAGE("build privacy-manager")
-
-SET(CMAKE_VERBOSE_MAKEFILE OFF)
-
-IF("${USE_AUTOSTART}" STREQUAL "1")
- ADD_DEFINITIONS("-DUSE_AUTOSTART")
-ENDIF()
-
-ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
-ADD_DEFINITIONS("-DUSE_IPC_EPOLL")
-
-STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}")
-ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"")
-
-ADD_SUBDIRECTORY(server)
-ADD_SUBDIRECTORY(client)
-#ADD_SUBDIRECTORY(test)
-ADD_SUBDIRECTORY(capi)
-ADD_SUBDIRECTORY(pkgmgr_plugin)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +MESSAGE("build privacy-manager") + +SET(CMAKE_VERBOSE_MAKEFILE OFF) + +IF("${USE_AUTOSTART}" STREQUAL "1") + ADD_DEFINITIONS("-DUSE_AUTOSTART") +ENDIF() + +ADD_DEFINITIONS("-DCLIENT_IPC_THREAD") +ADD_DEFINITIONS("-DUSE_IPC_EPOLL") + +STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}") +ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"") + +ADD_SUBDIRECTORY(server) +ADD_SUBDIRECTORY(client) +#ADD_SUBDIRECTORY(test) +ADD_SUBDIRECTORY(capi) +ADD_SUBDIRECTORY(pkgmgr_plugin) diff --git a/capi/include/privacy_info.h b/capi/include/privacy_info.h index 4d9ee85..e515a12 100644 --- a/capi/include/privacy_info.h +++ b/capi/include/privacy_info.h @@ -86,20 +86,20 @@ EXPORT_API int privacy_info_get_privacy_description(privacy_info_h privacy_info, */ EXPORT_API int privacy_info_is_enabled(privacy_info_h privacy_info, bool *enabled); -/**
- * @brief Creates and returns a copy of the given privacy info handle.
- *
- * @remarks A newly created service should be destroyed by calling privacy_info_destroy() if it is no longer needed.
- *
- * @param [out] clone If successful, a newly created privacy info handle will be returned.
- * @param [in] privacy_info The privacy info handle
- * @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
- * @see privacy_info_destroy()
- */
-EXPORT_API int privacy_info_clone(privacy_info_h *clone, privacy_info_h privacy_info);
+/** + * @brief Creates and returns a copy of the given privacy info handle. + * + * @remarks A newly created service should be destroyed by calling privacy_info_destroy() if it is no longer needed. + * + * @param [out] clone If successful, a newly created privacy info handle will be returned. + * @param [in] privacy_info The privacy info handle + * @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 + * @see privacy_info_destroy() + */ +EXPORT_API int privacy_info_clone(privacy_info_h *clone, privacy_info_h privacy_info); #ifdef __cplusplus } diff --git a/capi/src/privacy_manager.c b/capi/src/privacy_manager.c index dadd1ae..8be76fe 100644 --- a/capi/src/privacy_manager.c +++ b/capi/src/privacy_manager.c @@ -1,39 +1,39 @@ -/*
- * 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 <string.h>
-#include <stdlib.h>
-#include <privacy_manager.h>
-#include <privacy_info.h>
-#include <privacy_manager_client_types.h>
-#include <privacy_info_client.h>
-#include <privacy_manager_client.h>
-#include <privacy_manager_types_private.h>
-#include <dlog.h>
-
-
-static int _privacy_manager_convert_error(int error)
-{
- int ret = PRIV_MGR_ERROR_SUCCESS;
-
- LOGD("before error : %d", error);
-
- switch (error)
- {
- case PRIV_MGR_ERROR_SUCCESS:
+/* + * 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 <string.h> +#include <stdlib.h> +#include <privacy_manager.h> +#include <privacy_info.h> +#include <privacy_manager_client_types.h> +#include <privacy_info_client.h> +#include <privacy_manager_client.h> +#include <privacy_manager_types_private.h> +#include <dlog.h> + + +static int _privacy_manager_convert_error(int error) +{ + int ret = PRIV_MGR_ERROR_SUCCESS; + + LOGD("before error : %d", error); + + switch (error) + { + case PRIV_MGR_ERROR_SUCCESS: ret = PRIVACY_MANAGER_ERROR_NONE; break; case PRIV_MGR_ERROR_INVALID_PARAMETER: @@ -51,191 +51,191 @@ static int _privacy_manager_convert_error(int error) case PRIV_MGR_ERROR_DB_ERROR: ret = PRIVACY_MANAGER_ERROR_DB_FAILED; break; - case PRIV_MGR_ERROR_IPC_ERROR:
- ret = PRIVACY_MANAGER_ERROR_IPC_FAILED;
- break;
- }
- LOGD("after error : %d", ret);
- return ret;
-}
-
-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;
-
-typedef struct _foreach_all_privacy_context_
-{
- privacy_manager_all_privacy_info_cb callback;
- void *user_data;
-} foreach_all_privacy_context_s;
-
-typedef struct _foreach_package_by_privacy_context_
-{
- privacy_manager_packages_by_privacy_cb callback;
- void *user_data;
-} foreach_package_by_privacy_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;
-}
-
-bool __privacy_manager_client_all_privacy_info_cb(privacy_info_client_s* privacy_info_client, void* user_data)
-{
- foreach_all_privacy_context_s* context = (foreach_all_privacy_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;
-}
-
-bool __privacy_manager_client_packages_by_privacy_cb(const char *package_id, bool is_enabled, void* user_data)
-{
- foreach_package_by_privacy_context_s* context = (foreach_package_by_privacy_context_s*) user_data;
-
- bool ret = false;
-
- ret = context->callback(package_id, is_enabled, context->user_data);
-
- 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);
-}
-
-int privacy_manager_foreach_all_privacy(privacy_manager_all_privacy_info_cb callback, void* user_data)
-{
- int retval;
-
- foreach_all_privacy_context_s* context = NULL;
-
- context = (foreach_all_privacy_context_s*) calloc(1, sizeof(foreach_all_privacy_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_all_privacy(__privacy_manager_client_all_privacy_info_cb, context);
-
- return _privacy_manager_convert_error(retval);
-}
-
-int privacy_manager_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data)
-{
- int retval;
-
- foreach_package_by_privacy_context_s* context = NULL;
-
- context = (foreach_package_by_privacy_context_s*) calloc(1, sizeof(foreach_package_by_privacy_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_package_list_by_privacy(privacy_id, __privacy_manager_client_packages_by_privacy_cb, context);
-
- return _privacy_manager_convert_error(retval);
+ case PRIV_MGR_ERROR_IPC_ERROR: + ret = PRIVACY_MANAGER_ERROR_IPC_FAILED; + break; + } + LOGD("after error : %d", ret); + return ret; +} + +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; + +typedef struct _foreach_all_privacy_context_ +{ + privacy_manager_all_privacy_info_cb callback; + void *user_data; +} foreach_all_privacy_context_s; + +typedef struct _foreach_package_by_privacy_context_ +{ + privacy_manager_packages_by_privacy_cb callback; + void *user_data; +} foreach_package_by_privacy_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; +} + +bool __privacy_manager_client_all_privacy_info_cb(privacy_info_client_s* privacy_info_client, void* user_data) +{ + foreach_all_privacy_context_s* context = (foreach_all_privacy_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; +} + +bool __privacy_manager_client_packages_by_privacy_cb(const char *package_id, bool is_enabled, void* user_data) +{ + foreach_package_by_privacy_context_s* context = (foreach_package_by_privacy_context_s*) user_data; + + bool ret = false; + + ret = context->callback(package_id, is_enabled, context->user_data); + + 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); +} + +int privacy_manager_foreach_all_privacy(privacy_manager_all_privacy_info_cb callback, void* user_data) +{ + int retval; + + foreach_all_privacy_context_s* context = NULL; + + context = (foreach_all_privacy_context_s*) calloc(1, sizeof(foreach_all_privacy_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_all_privacy(__privacy_manager_client_all_privacy_info_cb, context); + + return _privacy_manager_convert_error(retval); +} + +int privacy_manager_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data) +{ + int retval; + + foreach_package_by_privacy_context_s* context = NULL; + + context = (foreach_package_by_privacy_context_s*) calloc(1, sizeof(foreach_package_by_privacy_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_package_list_by_privacy(privacy_id, __privacy_manager_client_packages_by_privacy_cb, context); + + return _privacy_manager_convert_error(retval); }
\ No newline at end of file diff --git a/client/inc/PrivacyChecker.h b/client/inc/PrivacyChecker.h index 41868d8..a014ebd 100644 --- a/client/inc/PrivacyChecker.h +++ b/client/inc/PrivacyChecker.h @@ -1,73 +1,73 @@ -/*
- * 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 <PrivacyManagerTypes.h>
-#include <dbus/dbus.h>
-#include <glib.h>
-
-struct sqlite3;
-
-class EXTERN_API PrivacyChecker
-{
-private:
- static std::map < std::string, bool > m_privacyCache;
- static std::map < std::string, std::map < std::string, 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;
-
-private:
- static int initializeDbus(void);
- static int finalizeDbus(void);
- static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap);
- static int updateCache(const std::string pkgId, std::map < std::string, 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, bool >& privacyMap);
-
-public:
- // for Checking in App 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 Server 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);
-
- // common
- static int finalize(void);
- static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data);
-};
-
+/* + * 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 <PrivacyManagerTypes.h> +#include <dbus/dbus.h> +#include <glib.h> + +struct sqlite3; + +class EXTERN_API PrivacyChecker +{ +private: + static std::map < std::string, bool > m_privacyCache; + static std::map < std::string, std::map < std::string, 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; + +private: + static int initializeDbus(void); + static int finalizeDbus(void); + static int updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap); + static int updateCache(const std::string pkgId, std::map < std::string, 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, bool >& privacyMap); + +public: + // for Checking in App 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 Server 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); + + // common + static int finalize(void); + static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data); +}; + #endif // _PRIVACY_CHECKER_H_
\ No newline at end of file diff --git a/client/inc/PrivacyManagerClient.h b/client/inc/PrivacyManagerClient.h index dcfca31..509b04a 100644 --- a/client/inc/PrivacyManagerClient.h +++ b/client/inc/PrivacyManagerClient.h @@ -1,66 +1,66 @@ -/*
- * 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 getPrivaycDescription(const std::string privacyId, std::string& description) const;
-};
-
-#endif // _PRIVACY_MANAGER_H_
+/* + * 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 getPrivaycDescription(const std::string privacyId, std::string& description) const; +}; + +#endif // _PRIVACY_MANAGER_H_
\ No newline at end of file diff --git a/client/inc/SocketClient.h b/client/inc/SocketClient.h index a69e8d0..d2713b1 100644 --- a/client/inc/SocketClient.h +++ b/client/inc/SocketClient.h @@ -1,150 +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;
-};
-
+/* + * 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 index e1902f7..3c276e9 100644 --- a/client/inc/privacy_checker_client.h +++ b/client/inc/privacy_checker_client.h @@ -1,40 +1,40 @@ -/*
- * 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
-
-EXTERN_API int privacy_checker_initialize(const char *package_id);
-EXTERN_API int privacy_checker_check_privacy(const char *privacy_id);
-EXTERN_API int privacy_checker_check_by_privilege(const char *privilege_id);
-EXTERN_API int privacy_checker_finalize(void);
-
-EXTERN_API int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id);
-
-EXTERN_API int privacy_checker_finalize(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //_PRIVACY_CHECKER_CLIENT_H
+/* + * 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 + +EXTERN_API int privacy_checker_initialize(const char *package_id); +EXTERN_API int privacy_checker_check_privacy(const char *privacy_id); +EXTERN_API int privacy_checker_check_by_privilege(const char *privilege_id); +EXTERN_API int privacy_checker_finalize(void); + +EXTERN_API int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id); + +EXTERN_API int privacy_checker_finalize(void); + +#ifdef __cplusplus +} +#endif + + +#endif //_PRIVACY_CHECKER_CLIENT_H diff --git a/client/inc/privacy_info_client.h b/client/inc/privacy_info_client.h index 9559956..fb4791f 100644 --- a/client/inc/privacy_info_client.h +++ b/client/inc/privacy_info_client.h @@ -1,43 +1,43 @@ -/*
- * 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_description(privacy_info_client_s* privacy_info, char **description);
-EXTERN_API int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //_PRIVACY_INFO_CLIENT_H
+/* + * 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_description(privacy_info_client_s* privacy_info, char **description); +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 index e2cb73b..eec4837 100644 --- a/client/inc/privacy_manager_client.h +++ b/client/inc/privacy_manager_client.h @@ -1,51 +1,51 @@ -/*
- * 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_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
-
+/* + * 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_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 + diff --git a/client/src/PrivacyChecker.cpp b/client/src/PrivacyChecker.cpp index 0cda415..dac7b16 100644 --- a/client/src/PrivacyChecker.cpp +++ b/client/src/PrivacyChecker.cpp @@ -1,408 +1,364 @@ -/*
- * 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.
- */
-
-#include <PrivacyChecker.h>
-#include <PrivacyIdInfo.h>
-#include <PrivacyManagerClient.h>
-#include <SocketClient.h>
-#include <algorithm>
-#include <memory>
-#include <Utils.h>
-#include <dlog.h>
-#include <sqlite3.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-bool PrivacyChecker::m_isInitialized = false;
-std::map < std::string, bool >PrivacyChecker::m_privacyCache;
-std::map < std::string, std::map < std::string, bool > > PrivacyChecker::m_privacyInfoCache;
-std::mutex PrivacyChecker::m_cacheMutex;
-std::string PrivacyChecker::m_pkgId;
-DBusConnection* PrivacyChecker::m_pDBusConnection;
-GMainLoop* PrivacyChecker::m_pLoop = NULL;
-GMainContext* PrivacyChecker::m_pHandlerGMainContext = NULL;
-const int MAX_LOCAL_BUF_SIZE = 128;
-pthread_t PrivacyChecker::m_signalThread;
-
-int
-PrivacyChecker::initialize(const std::string pkgId)
-{
- LOGI("enter");
-
- if (m_isInitialized) {
- LOGD("Already Initalized");
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- m_pkgId = pkgId;
-
- std::lock_guard < std::mutex > guard(m_cacheMutex);
-
- int res = updateCache(m_pkgId, m_privacyCache);
- TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res);
-
- res = initialize();
- TryReturn(res == 0, res, m_pkgId.clear(), "Failed to initialize() : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyChecker::initialize(void)
-{
- LOGI("enter");
-
- TryReturn(!m_isInitialized, PRIV_MGR_ERROR_SUCCESS, , "Already Initalized");
-
- m_pHandlerGMainContext = g_main_context_new();
- TryReturn(m_pHandlerGMainContext != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pHandlerGMainContext");
-
- m_pLoop = g_main_loop_new(m_pHandlerGMainContext, FALSE);
- TryReturn(m_pLoop != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pLoop");
-
- int res = pthread_create(&m_signalThread, NULL, &runSignalListenerThread, NULL);
- TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));
- LOGD("created thread");
-
- m_isInitialized = true;
-
- LOGI("leave");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-void*
-PrivacyChecker::runSignalListenerThread(void* pData)
-{
- pthread_detach(pthread_self());
- LOGI("Running g main loop for signal");
-
- initializeDbus();
-
- g_main_loop_run(m_pLoop);
-
- finalizeDbus();
-
- pthread_exit(NULL);
-
- return (void*) 0;
-}
-
-int
-PrivacyChecker::initializeDbus(void)
-{
- LOGI("enter");
- DBusError error;
- dbus_error_init(&error);
-
- m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
- TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private [%s] : %d", PRIV_MGR_ERROR_SYSTEM_ERROR);
-
- dbus_connection_setup_with_g_main(m_pDBusConnection, m_pHandlerGMainContext);
- std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);
-
- snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());
- dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);
- TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match[%s] : %d", error.message, PRIV_MGR_ERROR_SYSTEM_ERROR);
-
- dbus_bool_t r = dbus_connection_add_filter(m_pDBusConnection, handleNotification, NULL, NULL);
- TryReturn(r, PRIV_MGR_ERROR_SYSTEM_ERROR, , "dbus_connection_add_filter: %d", PRIV_MGR_ERROR_SYSTEM_ERROR);
-
- LOGI("leave");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyChecker::finalizeDbus(void)
-{
- dbus_connection_remove_filter(m_pDBusConnection, handleNotification, NULL);
- dbus_connection_close(m_pDBusConnection);
- m_pDBusConnection = NULL;
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-
-DBusHandlerResult
-PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data)
-{
- DBusError error;
- dbus_bool_t r;
- dbus_error_init(&error);
-
- char* pPkgId;
- char* pPrivacyId;
-
- LOGI("enter");
-
- if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str()))
- {
- r = dbus_message_get_args(message, &error,
- DBUS_TYPE_STRING, &pPkgId,
- DBUS_TYPE_STRING, &pPrivacyId,
- DBUS_TYPE_INVALID);
- TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message);
-
- std::lock_guard < std::mutex > guard(m_cacheMutex);
-
- if (std::string(pPkgId) == m_pkgId)
- {
- LOGI("Current app pkg privacy information updated");
- updateCache(m_pkgId, pPrivacyId, m_privacyCache);
- printCache();
- }
-
- std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId));
- if (iter != m_privacyInfoCache.end())
- {
- LOGI("Current pkg privacy is in cache");
- updateCache(std::string(pPkgId), pPrivacyId, iter->second);
- }
-
- }
- else if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str()))
- {
- r = dbus_message_get_args(message, &error,
- DBUS_TYPE_STRING, &pPkgId,
- DBUS_TYPE_INVALID);
- TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message);
-
- std::lock_guard < std::mutex > guard(m_cacheMutex);
-
- std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId));
- if (iter != m_privacyInfoCache.end())
- {
- LOGI("cache for pkg : %d is in cache", pPkgId);
- m_privacyInfoCache.erase(iter);
- }
- }
-// else
-// {
-// return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-// }
-
-
- // This event is not only for specific handler. All handlers of daemons should be check it and handle it.
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-int
-PrivacyChecker::check(const std::string privacyId, std::map < std::string, bool >& privacyMap)
-{
- LOGI("enter");
-
- TryReturn(m_isInitialized, PRIV_MGR_ERROR_NOT_INITIALIZED, , "Not initialized");
-
- std::map < std::string, bool >::iterator iter;
-
- iter = privacyMap.find(privacyId);
- if (iter == privacyMap.end() )
- {
- LOGD("NO matcheded");
- return PRIV_MGR_ERROR_USER_NOT_CONSENTED;
- }
- else if (!iter->second)
- {
- LOGD("NOT allowed");
- return PRIV_MGR_ERROR_USER_NOT_CONSENTED;
- }
-
- LOGD("OK");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyChecker::check(const std::string privacyId)
-{
- LOGI("enter");
-
- if (!m_isInitialized)
- return PRIV_MGR_ERROR_NOT_INITIALIZED;
-
- std::lock_guard < std::mutex > guard(m_cacheMutex);
-
- int res = check(privacyId, m_privacyCache);
-
- LOGI("leave");
-
- return res;
-}
-
-int
-PrivacyChecker::check(const std::string pkgId, const std::string privacyId)
-{
- LOGI("enter %s: %s", pkgId.c_str(), privacyId.c_str());
-
- if (!m_isInitialized)
- initialize();
-
- std::lock_guard < std::mutex > guard(m_cacheMutex);
- int res;
-
- std::map < std::string, std::map < std::string, bool > >::iterator iter = m_privacyInfoCache.find(pkgId);
- if (iter == m_privacyInfoCache.end() )
- {
- std::map < std::string, bool > pkgCacheMap;
- res = updateCache(pkgId, pkgCacheMap);
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_DB_ERROR, , "updateCache : %d", res);
-
- m_privacyInfoCache.insert( std::map < std::string, std::map < std::string, bool > >::value_type(std::string(pkgId), pkgCacheMap));
- iter = m_privacyInfoCache.find(pkgId);
- }
-
- if (iter->second.size() == 0)
- {
- LOGD("No privacy contained");
- return PRIV_MGR_ERROR_USER_NOT_CONSENTED;
- }
-
- res = check(privacyId, iter->second);
-
- LOGI("leave");
-
- return res;
-}
-
-int
-PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string privilege)
-{
- LOGI("enter");
-
- std::string privacyId;
- int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
- if (res == PRIV_MGR_ERROR_NO_DATA) {
- LOGD("%s is not privacy privilege", privilege.c_str());
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);
-
- LOGI("leave");
-
- return check(pkgId, privacyId);
-}
-
-int
-PrivacyChecker::checkWithPrivilege(const std::string privilege)
-{
- LOGI("enter");
-
- std::string privacyId;
- int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId);
- if (res == PRIV_MGR_ERROR_NO_DATA) {
- LOGD("%s is not privacy privilege", privilege.c_str());
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res);
-
- LOGI("leave");
-
- return check(privacyId);
-}
-
-int
-PrivacyChecker::finalize(void)
-{
- std::lock_guard <std::mutex> guard (m_cacheMutex);
- m_privacyCache.clear();
- m_privacyInfoCache.clear();
-
- if (m_pLoop != NULL)
- {
- g_main_loop_quit(m_pLoop);
- m_pLoop = NULL;
- }
-
- if (m_pHandlerGMainContext != NULL)
- {
- g_main_context_unref(m_pHandlerGMainContext);
- m_pHandlerGMainContext = NULL;
- }
-
- m_isInitialized = false;
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-void
-PrivacyChecker::printCache(void)
-{
- std::map < std::string, bool >::const_iterator iter = m_privacyCache.begin();
- for (; iter != m_privacyCache.end(); ++iter)
- {
- LOGD(" %s : %d", iter->first.c_str(), iter->second);
- }
-}
-
-int
-PrivacyChecker::updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap)
-{
- LOGI("enter");
- static const std::string PrivacyQuery = "SELECT IS_ENABLED from PrivacyInfo where PKG_ID=? and PRIVACY_ID=?";
-
- openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);
- prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);
- int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);
- TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
-
- res = sqlite3_bind_text(pPrivacyStmt.get(), 2, privacyId.c_str(), -1, SQLITE_TRANSIENT);
- TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
-
- LOGI(" %s -- %s", pkgId.c_str(), privacyId.c_str());
- while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )
- {
- bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 0) > 0 ? true : false;
-
- SECURE_LOGD("Set result : %s : %d", privacyId.c_str(), privacyEnabled );
- pkgCacheMap.erase(privacyId);
- pkgCacheMap.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled));
- }
-
- LOGI("leave");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyChecker::updateCache(std::string pkgId, std::map < std::string, bool >& pkgCacheMap)
-{
- LOGI("enter");
- static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?";
-
- pkgCacheMap.clear();
-
- openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);
- prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);
- int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
-
- while ( (res = sqlite3_step(pPrivacyStmt.get())) == SQLITE_ROW )
- {
- LOGI("start");
- const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0));
- bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false;
-
- pkgCacheMap.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled));
-
- SECURE_LOGD("Privacy found : %s %d", privacyId, privacyEnabled);
- }
- LOGI("leave : %d", res);
- return PRIV_MGR_ERROR_SUCCESS;
-}
\ No newline at end of file +/* + * 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. + */ + +#include <PrivacyChecker.h> +#include <PrivacyIdInfo.h> +#include <PrivacyManagerClient.h> +#include <SocketClient.h> +#include <algorithm> +#include <memory> +#include <Utils.h> +#include <dlog.h> +#include <sqlite3.h> +#include <dbus/dbus-glib-lowlevel.h> +#include <sys/types.h> +#include <unistd.h> + +bool PrivacyChecker::m_isInitialized = false; +std::map < std::string, bool >PrivacyChecker::m_privacyCache; +std::map < std::string, std::map < std::string, bool > > PrivacyChecker::m_privacyInfoCache; +std::mutex PrivacyChecker::m_cacheMutex; +std::string PrivacyChecker::m_pkgId; +DBusConnection* PrivacyChecker::m_pDBusConnection; +GMainLoop* PrivacyChecker::m_pLoop = NULL; +GMainContext* PrivacyChecker::m_pHandlerGMainContext = NULL; +const int MAX_LOCAL_BUF_SIZE = 128; +pthread_t PrivacyChecker::m_signalThread; + +int +PrivacyChecker::initialize(const std::string pkgId) +{ + if (m_isInitialized) { + return PRIV_MGR_ERROR_SUCCESS; + } + + m_pkgId = pkgId; + + std::lock_guard < std::mutex > guard(m_cacheMutex); + + int res = updateCache(m_pkgId, m_privacyCache); + TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res); + + res = initialize(); + TryReturn(res == 0, res, m_pkgId.clear(), "Failed to initialize() : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyChecker::initialize(void) +{ + TryReturn(!m_isInitialized, PRIV_MGR_ERROR_SUCCESS, , "Already Initalized"); + + m_pHandlerGMainContext = g_main_context_new(); + TryReturn(m_pHandlerGMainContext != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pHandlerGMainContext"); + + m_pLoop = g_main_loop_new(m_pHandlerGMainContext, FALSE); + TryReturn(m_pLoop != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, m_pkgId.clear(), "cannot create m_pLoop"); + + int res = pthread_create(&m_signalThread, NULL, &runSignalListenerThread, NULL); + TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res)); + + m_isInitialized = true; + + return PRIV_MGR_ERROR_SUCCESS; +} + +void* +PrivacyChecker::runSignalListenerThread(void* pData) +{ + pthread_detach(pthread_self()); + LOGI("Running g main loop for signal"); + + initializeDbus(); + + g_main_loop_run(m_pLoop); + + finalizeDbus(); + + pthread_exit(NULL); + + return (void*) 0; +} + +int +PrivacyChecker::initializeDbus(void) +{ + DBusError error; + dbus_error_init(&error); + + m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private [%s] : %d", PRIV_MGR_ERROR_SYSTEM_ERROR); + + dbus_connection_setup_with_g_main(m_pDBusConnection, m_pHandlerGMainContext); + std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]); + + snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str()); + dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error); + TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match[%s] : %d", error.message, PRIV_MGR_ERROR_SYSTEM_ERROR); + + dbus_bool_t r = dbus_connection_add_filter(m_pDBusConnection, handleNotification, NULL, NULL); + TryReturn(r, PRIV_MGR_ERROR_SYSTEM_ERROR, , "dbus_connection_add_filter: %d", PRIV_MGR_ERROR_SYSTEM_ERROR); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyChecker::finalizeDbus(void) +{ + dbus_connection_remove_filter(m_pDBusConnection, handleNotification, NULL); + dbus_connection_close(m_pDBusConnection); + m_pDBusConnection = NULL; + + return PRIV_MGR_ERROR_SUCCESS; +} + + +DBusHandlerResult +PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data) +{ + DBusError error; + dbus_bool_t r; + dbus_error_init(&error); + + char* pPkgId; + char* pPrivacyId; + + if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str())) + { + r = dbus_message_get_args(message, &error, + DBUS_TYPE_STRING, &pPkgId, + DBUS_TYPE_STRING, &pPrivacyId, + DBUS_TYPE_INVALID); + TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message); + + std::lock_guard < std::mutex > guard(m_cacheMutex); + + if (std::string(pPkgId) == m_pkgId) + { + LOGI("Current app pkg privacy information updated"); + updateCache(m_pkgId, pPrivacyId, m_privacyCache); + //printCache(); + } + + std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId)); + if (iter != m_privacyInfoCache.end()) + { + LOGI("Current pkg privacy is in cache"); + updateCache(std::string(pPkgId), pPrivacyId, iter->second); + } + + } + else if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str())) + { + r = dbus_message_get_args(message, &error, + DBUS_TYPE_STRING, &pPkgId, + DBUS_TYPE_INVALID); + TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message); + + std::lock_guard < std::mutex > guard(m_cacheMutex); + + std::map < std::string, std::map < std::string, bool > > :: iterator iter = m_privacyInfoCache.find(std::string(pPkgId)); + if (iter != m_privacyInfoCache.end()) + { + m_privacyInfoCache.erase(iter); + } + } +// else +// { +// return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +// } + + + // This event is not only for specific handler. All handlers of daemons should be check it and handle it. + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +int +PrivacyChecker::check(const std::string privacyId, std::map < std::string, bool >& privacyMap) +{ + TryReturn(m_isInitialized, PRIV_MGR_ERROR_NOT_INITIALIZED, , "Not initialized"); + + std::map < std::string, bool >::iterator iter; + + iter = privacyMap.find(privacyId); + if (iter == privacyMap.end() ) + { + LOGD("The application cannot access the privacy inforamtion."); + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + } + else if (!iter->second) + { + LOGD("User does not consented to access the privacy information"); + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyChecker::check(const std::string privacyId) +{ + if (!m_isInitialized) + return PRIV_MGR_ERROR_NOT_INITIALIZED; + + std::lock_guard < std::mutex > guard(m_cacheMutex); + + int res = check(privacyId, m_privacyCache); + + return res; +} + +int +PrivacyChecker::check(const std::string pkgId, const std::string privacyId) +{ + if (!m_isInitialized) + initialize(); + + std::lock_guard < std::mutex > guard(m_cacheMutex); + int res; + + std::map < std::string, std::map < std::string, bool > >::iterator iter = m_privacyInfoCache.find(pkgId); + if (iter == m_privacyInfoCache.end() ) + { + std::map < std::string, bool > pkgCacheMap; + res = updateCache(pkgId, pkgCacheMap); + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, PRIV_MGR_ERROR_DB_ERROR, , "Failed to update cache : %d", res); + + m_privacyInfoCache.insert( std::map < std::string, std::map < std::string, bool > >::value_type(std::string(pkgId), pkgCacheMap)); + iter = m_privacyInfoCache.find(pkgId); + } + + if (iter->second.size() == 0) + { + return PRIV_MGR_ERROR_USER_NOT_CONSENTED; + } + + res = check(privacyId, iter->second); + + return res; +} + +int +PrivacyChecker::checkWithPrivilege(const std::string pkgId, const std::string privilege) +{ + std::string privacyId; + int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId); + if (res == PRIV_MGR_ERROR_NO_DATA) { + return PRIV_MGR_ERROR_SUCCESS; + } + + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); + + return check(pkgId, privacyId); +} + +int +PrivacyChecker::checkWithPrivilege(const std::string privilege) +{ + std::string privacyId; + int res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilege, privacyId); + if (res == PRIV_MGR_ERROR_NO_DATA) { + return PRIV_MGR_ERROR_SUCCESS; + } + + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege : %d", res); + + return check(privacyId); +} + +int +PrivacyChecker::finalize(void) +{ + std::lock_guard <std::mutex> guard (m_cacheMutex); + m_privacyCache.clear(); + m_privacyInfoCache.clear(); + + if (m_pLoop != NULL) + { + g_main_loop_quit(m_pLoop); + m_pLoop = NULL; + } + + if (m_pHandlerGMainContext != NULL) + { + g_main_context_unref(m_pHandlerGMainContext); + m_pHandlerGMainContext = NULL; + } + + m_isInitialized = false; + + return PRIV_MGR_ERROR_SUCCESS; +} + +void +PrivacyChecker::printCache(void) +{ + std::map < std::string, bool >::const_iterator iter = m_privacyCache.begin(); + for (; iter != m_privacyCache.end(); ++iter) + { + LOGD(" %s : %d", iter->first.c_str(), iter->second); + } +} + +int +PrivacyChecker::updateCache(const std::string pkgId, std::string privacyId, std::map < std::string, bool >& pkgCacheMap) +{ + static const std::string PrivacyQuery = "SELECT IS_ENABLED from PrivacyInfo where PKG_ID=? and PRIVACY_ID=?"; + + openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); + prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt); + int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + res = sqlite3_bind_text(pPrivacyStmt.get(), 2, privacyId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == 0, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW ) + { + bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 0) > 0 ? true : false; + + SECURE_LOGD("Set result : %s : %d", privacyId.c_str(), privacyEnabled ); + pkgCacheMap.erase(privacyId); + pkgCacheMap.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled)); + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyChecker::updateCache(std::string pkgId, std::map < std::string, bool >& pkgCacheMap) +{ + static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?"; + + pkgCacheMap.clear(); + + openDb(PRIVACY_DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY); + prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt); + int res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + while ( (res = sqlite3_step(pPrivacyStmt.get())) == SQLITE_ROW ) + { + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0)); + bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false; + + pkgCacheMap.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled)); + + SECURE_LOGD("Privacy found : %s %d", privacyId, privacyEnabled); + } + return PRIV_MGR_ERROR_SUCCESS; +} diff --git a/client/src/PrivacyManagerClient.cpp b/client/src/PrivacyManagerClient.cpp index fba5fc4..b189ca5 100644 --- a/client/src/PrivacyManagerClient.cpp +++ b/client/src/PrivacyManagerClient.cpp @@ -1,213 +1,205 @@ -/*
- * 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.
- */
-
-#include <PrivacyManagerClient.h>
-#include <PrivacyDb.h>
-#include <SocketClient.h>
-#include <PrivacyIdInfo.h>
-#include <algorithm>
-#include <memory>
-#include <Utils.h>
-
-#undef __READ_DB_IPC__
-
-
-std::mutex PrivacyManagerClient::m_singletonMutex;
-PrivacyManagerClient* PrivacyManagerClient::m_pInstance = NULL;
-const std::string PrivacyManagerClient::INTERFACE_NAME("PrivacyInfoService");
-
-PrivacyManagerClient::PrivacyManagerClient(void)
-{
- std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));
- m_pSocketClient = std::move(pSocketClient);
-}
-
-PrivacyManagerClient*
-PrivacyManagerClient::getInstance(void)
-{
- std::lock_guard<std::mutex> guard(m_singletonMutex);
- if (m_pInstance == NULL)
- m_pInstance = new PrivacyManagerClient();
- return m_pInstance;
-}
-
-int
-PrivacyManagerClient::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list, bool privacyPopupRequired, bool isServerOperation)
-{
-
- std::list < std::string > privacyList;
-
- int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(list, privacyList);
- if (res != PRIV_MGR_ERROR_SUCCESS )
- return res;
-
- if (privacyList.size() == 0)
- return PRIV_MGR_ERROR_SUCCESS;
-
- if (isServerOperation == true)
- {
- int result = PRIV_MGR_ERROR_SUCCESS;
- res = m_pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- res = m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, privacyPopupRequired, &result);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- res = m_pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
-
- return result;
- }
- else
- {
- return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privacyList, privacyPopupRequired);
- }
-}
-
-int
-PrivacyManagerClient::removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation)
-{
- if (isServerOperation == true)
- {
- int result = PRIV_MGR_ERROR_SUCCESS;
- int res = m_pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- result = m_pSocketClient->call("removePrivacyInfo", pkgId, &result);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- result = m_pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
-
- return result;
- }
- else
- return PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId);
-}
-
-int
-PrivacyManagerClient::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)
-{
- int result = PRIV_MGR_ERROR_SUCCESS;
- int res = m_pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- res = m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- res = m_pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
-
- return result;
-}
-
-int
-PrivacyManagerClient::getPrivacyAppPackages(std::list < std::string >& list) const
-{
-#ifdef __READ_DB_IPC__
-
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
-
- int result = PRIV_MGR_ERROR_SUCCESS
- int size = 0;
-
- int res = pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- res = pSocketClient->call("getPrivacyAppPackages", &result, &size, &list);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- res = pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
-
- return result;
-#endif
-
- return PrivacyDb::getInstance()->getPrivacyAppPackages(list);
-}
-
-int
-PrivacyManagerClient::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const
-{
-#ifdef __READ_DB_IPC__
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
-
- int result = PRIV_MGR_ERROR_SUCCESS;
- int res = pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
-
- return result;
-#endif
-
- return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, list);
-}
-
-int
-PrivacyManagerClient::isUserPrompted(const std::string pkgId, bool& isPrompted) const
-{
-#ifdef __READ_DB_IPC__
- LOGI("enter");
-
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
-
- int result = PRIV_MGR_ERROR_SUCCESS;
- int res = pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- res = pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- res = pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
-
- LOGI("leave");
-
- return result;
-#endif
- return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted);
-}
-
-int
-PrivacyManagerClient::setUserPrompted(const std::string pkgId, bool prompted)
-{
- LOGI("enter");
-
- std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));
-
- int result = PRIV_MGR_ERROR_SUCCESS;
- int res = pSocketClient->connect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res);
- res = pSocketClient->call("setUserPrompted", pkgId, prompted, &result);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res);
- res = pSocketClient->disconnect();
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res);
-
- LOGI("leave");
-
- return result;
-}
-
-int
-PrivacyManagerClient::getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const
-{
- return PrivacyDb::getInstance()->getAppPackagesbyPrivacyId(privacyId, list);
-}
-
-int
-PrivacyManagerClient::getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const
-{
- return PrivacyIdInfo::getPrivaycDisplayName(privacyId, displayName);
-}
-
-int
-PrivacyManagerClient::getPrivaycDescription(const std::string privacyId, std::string& description) const
-{
- return PrivacyIdInfo::getPrivaycDescription(privacyId, description);
-}
+/* + * 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. + */ + +#include <PrivacyManagerClient.h> +#include <PrivacyDb.h> +#include <SocketClient.h> +#include <PrivacyIdInfo.h> +#include <algorithm> +#include <memory> +#include <Utils.h> + +#undef __READ_DB_IPC__ + + +std::mutex PrivacyManagerClient::m_singletonMutex; +PrivacyManagerClient* PrivacyManagerClient::m_pInstance = NULL; +const std::string PrivacyManagerClient::INTERFACE_NAME("PrivacyInfoService"); + +PrivacyManagerClient::PrivacyManagerClient(void) +{ + std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME)); + m_pSocketClient = std::move(pSocketClient); +} + +PrivacyManagerClient* +PrivacyManagerClient::getInstance(void) +{ + std::lock_guard<std::mutex> guard(m_singletonMutex); + if (m_pInstance == NULL) + m_pInstance = new PrivacyManagerClient(); + return m_pInstance; +} + +int +PrivacyManagerClient::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list, bool privacyPopupRequired, bool isServerOperation) +{ + + std::list < std::string > privacyList; + + int res = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(list, privacyList); + if (res != PRIV_MGR_ERROR_SUCCESS ) + return res; + + if (privacyList.size() == 0) + return PRIV_MGR_ERROR_SUCCESS; + + if (isServerOperation == true) + { + int result = PRIV_MGR_ERROR_SUCCESS; + res = m_pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + res = m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, privacyPopupRequired, &result); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + res = m_pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res); + + return result; + } + else + { + return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privacyList, privacyPopupRequired); + } +} + +int +PrivacyManagerClient::removeAppPackagePrivacyInfo(const std::string pkgId, bool isServerOperation) +{ + if (isServerOperation == true) + { + int result = PRIV_MGR_ERROR_SUCCESS; + int res = m_pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + result = m_pSocketClient->call("removePrivacyInfo", pkgId, &result); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + result = m_pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res); + + return result; + } + else + return PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId); +} + +int +PrivacyManagerClient::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled) +{ + int result = PRIV_MGR_ERROR_SUCCESS; + int res = m_pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + res = m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + res = m_pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + + return result; +} + +int +PrivacyManagerClient::getPrivacyAppPackages(std::list < std::string >& list) const +{ +#ifdef __READ_DB_IPC__ + + std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result = PRIV_MGR_ERROR_SUCCESS + int size = 0; + + int res = pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + res = pSocketClient->call("getPrivacyAppPackages", &result, &size, &list); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + res = pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + + return result; +#endif + + return PrivacyDb::getInstance()->getPrivacyAppPackages(list); +} + +int +PrivacyManagerClient::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list) const +{ +#ifdef __READ_DB_IPC__ + std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result = PRIV_MGR_ERROR_SUCCESS; + int res = pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res); + + return result; +#endif + + return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, list); +} + +int +PrivacyManagerClient::isUserPrompted(const std::string pkgId, bool& isPrompted) const +{ +#ifdef __READ_DB_IPC__ + std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result = PRIV_MGR_ERROR_SUCCESS; + int res = pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + res = pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + res = pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res); + + return result; +#endif + return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted); +} + +int +PrivacyManagerClient::setUserPrompted(const std::string pkgId, bool prompted) +{ + std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME)); + + int result = PRIV_MGR_ERROR_SUCCESS; + int res = pSocketClient->connect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "connect : %d", res); + res = pSocketClient->call("setUserPrompted", pkgId, prompted, &result); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, m_pSocketClient->disconnect(), "call : %d", res); + res = pSocketClient->disconnect(); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "disconnect : %d", res); + + return result; +} + +int +PrivacyManagerClient::getAppPackagesbyPrivacyId(const std::string privacyId, std::list < std::pair < std::string, bool > >& list) const +{ + return PrivacyDb::getInstance()->getAppPackagesbyPrivacyId(privacyId, list); +} + +int +PrivacyManagerClient::getPrivaycDisplayName(const std::string privacyId, std::string& displayName) const +{ + return PrivacyIdInfo::getPrivaycDisplayName(privacyId, displayName); +} + +int +PrivacyManagerClient::getPrivaycDescription(const std::string privacyId, std::string& description) const +{ + return PrivacyIdInfo::getPrivaycDescription(privacyId, description); +} diff --git a/client/src/SocketClient.cpp b/client/src/SocketClient.cpp index 20ecb3d..a144628 100644 --- a/client/src/SocketClient.cpp +++ b/client/src/SocketClient.cpp @@ -1,75 +1,75 @@ -/*
- * 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.
- */
-
-#include <sys/socket.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/un.h>
-#include <errno.h>
-#include <unistd.h>
-#include <PrivacyManagerTypes.h>
-#include "SocketClient.h"
-#include <Utils.h>
-
-#define throwWithErrnoMessage(specificInfo) do {\
- LOGE("%s : %s", specificInfo, strerror(errno)); \
- return -1; \
- } while(0)
-
-SocketClient::SocketClient(const std::string& interfaceName)
-{
- m_interfaceName = interfaceName;
- m_serverAddress = SERVER_ADDRESS;
- LOGI("Client created");
-}
-
-int SocketClient::connect()
-{
- struct sockaddr_un remote;
- m_socketFd = socket(AF_UNIX, SOCK_STREAM,0);
- TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "socket : %s", strerror(errno));
-
- int res;
- //socket needs to be nonblocking, because read can block after select
- int flags;
- if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 )
- flags = 0;
- res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);
- TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "fcntl : %s", strerror(errno));
-
- bzero(&remote, sizeof(remote));
- remote.sun_family = AF_UNIX;
- strcpy(remote.sun_path, m_serverAddress.c_str());
- res = ::connect(m_socketFd, (struct sockaddr *)&remote, SUN_LEN(&remote));
- TryReturn( res != -1, PRIV_MGR_ERROR_IPC_ERROR, , "connect : %s", strerror(errno));
-
- m_socketConnector.reset(new SocketConnection(m_socketFd));
-
- LOGI("Client connected");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int SocketClient::disconnect()
-{
- //Socket should be already closed by server side,
- //even though we should close it in case of any errors
- close(m_socketFd);
- LOGI("Client disconnected");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
+/* + * 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. + */ + +#include <sys/socket.h> +#include <string.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/un.h> +#include <errno.h> +#include <unistd.h> +#include <PrivacyManagerTypes.h> +#include "SocketClient.h" +#include <Utils.h> + +#define throwWithErrnoMessage(specificInfo) do {\ + LOGE("%s : %s", specificInfo, strerror(errno)); \ + return -1; \ + } while(0) + +SocketClient::SocketClient(const std::string& interfaceName) +{ + m_interfaceName = interfaceName; + m_serverAddress = SERVER_ADDRESS; + LOGI("Client created"); +} + +int SocketClient::connect() +{ + struct sockaddr_un remote; + m_socketFd = socket(AF_UNIX, SOCK_STREAM,0); + TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "socket : %s", strerror(errno)); + + int res; + //socket needs to be nonblocking, because read can block after select + int flags; + if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 ) + flags = 0; + res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK); + TryReturn( m_socketFd != -1, PRIV_MGR_ERROR_IPC_ERROR, , "fcntl : %s", strerror(errno)); + + bzero(&remote, sizeof(remote)); + remote.sun_family = AF_UNIX; + strcpy(remote.sun_path, m_serverAddress.c_str()); + res = ::connect(m_socketFd, (struct sockaddr *)&remote, SUN_LEN(&remote)); + TryReturn( res != -1, PRIV_MGR_ERROR_IPC_ERROR, , "connect : %s", strerror(errno)); + + m_socketConnector.reset(new SocketConnection(m_socketFd)); + + LOGI("Client connected"); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int SocketClient::disconnect() +{ + //Socket should be already closed by server side, + //even though we should close it in case of any errors + close(m_socketFd); + LOGI("Client disconnected"); + + return PRIV_MGR_ERROR_SUCCESS; +} diff --git a/client/src/privacy_checker_client.cpp b/client/src/privacy_checker_client.cpp index 011de07..fa0cdca 100644 --- a/client/src/privacy_checker_client.cpp +++ b/client/src/privacy_checker_client.cpp @@ -1,52 +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.
- */
-
-#include <string.h>
-#include <string>
-#include <memory>
-#include <PrivacyManagerClient.h>
-#include <privacy_manager_client.h>
-#include <privacy_manager_client_types.h>
-#include "privacy_manager_client_internal_types.h"
-#include <PrivacyChecker.h>
-#include <privacy_checker_client.h>
-#include <privacy_info_client.h>
-#include <PrivacyIdInfo.h>
-
-int privacy_checker_initialize(const char *package_id)
-{
- return PrivacyChecker::initialize(std::string(package_id));
-}
-
-int privacy_checker_check_privacy(const char *privacy_id)
-{
- return PrivacyChecker::check(std::string(privacy_id));
-}
-
-int privacy_checker_check_by_privilege(const char *privilege_id)
-{
- return PrivacyChecker::checkWithPrivilege(privilege_id);
-}
-
-int privacy_checker_finalize(void)
-{
- return PrivacyChecker::finalize();
-}
-
-int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id)
-{
- return PrivacyChecker::checkWithPrivilege(package_id,privilege_id);
+/* + * 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 <string.h> +#include <string> +#include <memory> +#include <PrivacyManagerClient.h> +#include <privacy_manager_client.h> +#include <privacy_manager_client_types.h> +#include "privacy_manager_client_internal_types.h" +#include <PrivacyChecker.h> +#include <privacy_checker_client.h> +#include <privacy_info_client.h> +#include <PrivacyIdInfo.h> + +int privacy_checker_initialize(const char *package_id) +{ + return PrivacyChecker::initialize(std::string(package_id)); +} + +int privacy_checker_check_privacy(const char *privacy_id) +{ + return PrivacyChecker::check(std::string(privacy_id)); +} + +int privacy_checker_check_by_privilege(const char *privilege_id) +{ + return PrivacyChecker::checkWithPrivilege(privilege_id); +} + +int privacy_checker_finalize(void) +{ + return PrivacyChecker::finalize(); +} + +int privacy_checker_check_package_by_privilege(const char* package_id, const char *privilege_id) +{ + return PrivacyChecker::checkWithPrivilege(package_id,privilege_id); }
\ No newline at end of file diff --git a/client/src/privacy_info_client.cpp b/client/src/privacy_info_client.cpp index ac379e3..9260cc7 100644 --- a/client/src/privacy_info_client.cpp +++ b/client/src/privacy_info_client.cpp @@ -1,79 +1,79 @@ -/*
- * 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 <string.h>
-#include <string>
-#include <memory>
-#include <PrivacyManagerClient.h>
-#include <privacy_manager_client.h>
-#include <privacy_manager_client_types.h>
-#include "privacy_manager_client_internal_types.h"
-
-int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info)
-{
- if (privacy_info != NULL)
- {
- if (privacy_info->privacy_id)
- free(privacy_info->privacy_id);
- free (privacy_info);
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id)
-{
- int size = strlen(privacy_info->privacy_id);
- *privacy_id = (char*) calloc(1, size + 1);
-
- memcpy (*privacy_id, privacy_info->privacy_id, size);
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name)
-{
- std::string displayName;
- int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), displayName);
- if (res != PRIV_MGR_ERROR_SUCCESS)
- return res;
-
- int size = strlen(displayName.c_str());
- *name = (char*) calloc(1, size + 1);
- memcpy (*name, displayName.c_str(), size);
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description)
-{
- std::string desc;
- int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), desc);
- if (res != PRIV_MGR_ERROR_SUCCESS)
- return res;
-
- int size = strlen(desc.c_str());
- *description = (char*) calloc(1, size + 1);
- memcpy (*description, desc.c_str(), size);
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled)
-{
- *enabled = privacy_info->is_enabled;
- return PRIV_MGR_ERROR_SUCCESS;
-}
+/* + * 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 <string.h> +#include <string> +#include <memory> +#include <PrivacyManagerClient.h> +#include <privacy_manager_client.h> +#include <privacy_manager_client_types.h> +#include "privacy_manager_client_internal_types.h" + +int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info) +{ + if (privacy_info != NULL) + { + if (privacy_info->privacy_id) + free(privacy_info->privacy_id); + free (privacy_info); + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **privacy_id) +{ + int size = strlen(privacy_info->privacy_id); + *privacy_id = (char*) calloc(1, size + 1); + + memcpy (*privacy_id, privacy_info->privacy_id, size); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name) +{ + std::string displayName; + int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), displayName); + if (res != PRIV_MGR_ERROR_SUCCESS) + return res; + + int size = strlen(displayName.c_str()); + *name = (char*) calloc(1, size + 1); + memcpy (*name, displayName.c_str(), size); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description) +{ + std::string desc; + int res = PrivacyManagerClient::getInstance()->getPrivaycDisplayName(std::string(privacy_info->privacy_id), desc); + if (res != PRIV_MGR_ERROR_SUCCESS) + return res; + + int size = strlen(desc.c_str()); + *description = (char*) calloc(1, size + 1); + memcpy (*description, desc.c_str(), size); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled) +{ + *enabled = privacy_info->is_enabled; + return PRIV_MGR_ERROR_SUCCESS; +} diff --git a/client/src/privacy_manager_client.cpp b/client/src/privacy_manager_client.cpp index 2703e19..74a9ff1 100644 --- a/client/src/privacy_manager_client.cpp +++ b/client/src/privacy_manager_client.cpp @@ -1,189 +1,189 @@ -/*
- * 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 <string.h>
-#include <string>
-#include <memory>
-#include <dlog.h>
-#include <PrivacyManagerClient.h>
-#include <PrivacyIdInfo.h>
-#include <privacy_manager_client.h>
-#include "privacy_manager_client_internal_types.h"
-
-int create_privacy_info_client_s(const char* privacy_id, bool enabled, privacy_info_client_s **privacy_info)
-{
- privacy_info_client_s* temp = (privacy_info_client_s*) calloc(1, sizeof(privacy_info_client_s));
- if (temp == NULL)
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;
-
- int size = strlen(privacy_id);
- temp->privacy_id = (char*) calloc(1, size + 1);
- if (temp->privacy_id == NULL)
- {
- free(temp);
- return PRIV_MGR_ERROR_OUT_OF_MEMORY;
- }
- memcpy(temp->privacy_id, privacy_id, size + 1);
-
- temp->is_enabled = enabled;
-
- *privacy_info = temp;
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list, bool privacy_popup_required)
-{
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
- std::list < std::string > privacyList;
-
- while (*privacy_list[0] != '\0')
- privacyList.push_back(std::string(*privacy_list++));
-
- int retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList, privacy_popup_required, false);
-
- return retval;
-}
-
-int privacy_manager_client_uninstall_privacy(const char *package_id)
-{
- if (package_id == NULL)
- return PRIV_MGR_ERROR_INVALID_PARAMETER;
- return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), false);
-}
-
-int privacy_manager_client_uninstall_privacy_by_server(const char *package_id)
-{
- if (package_id == NULL)
- return PRIV_MGR_ERROR_INVALID_PARAMETER;
- return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), true);
-}
-
-int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data)
-{
- int retval;
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
-
- std::list < std::string > list;
- retval = pInst->getPrivacyAppPackages(list);
- if (retval != PRIV_MGR_ERROR_SUCCESS)
- return retval;
- if (list.size() == 0)
- return PRIV_MGR_ERROR_NO_DATA;
-
- for (std::list < std::string >::iterator iter = list.begin(); iter != list.end(); ++iter)
- {
- if ( ! callback(iter->c_str(), user_data) )
- break;
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data)
-{
- int retval;
- bool res;
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
-
- std::list < std::pair <std::string, bool > > list;
-
- retval = pInst->getAppPackagePrivacyInfo(std::string(package_id), list);
- if (retval != PRIV_MGR_ERROR_SUCCESS)
- return retval;
- if (list.size() == 0)
- return PRIV_MGR_ERROR_NO_DATA;
-
- for (std::list < std::pair <std::string, bool > >::iterator iter = list.begin(); iter != list.end(); ++iter)
- {
- privacy_info_client_s *privacy_info_client_s = NULL;
- retval = create_privacy_info_client_s(iter->first.c_str(), iter->second, &privacy_info_client_s);
- res = callback(privacy_info_client_s, user_data);
- privacy_info_client_s_destroy(privacy_info_client_s);
- if (!res)
- break;
- }
- return PRIV_MGR_ERROR_SUCCESS;
-
-}
-int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable)
-{
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
-
- return pInst->setPrivacySetting(package_id, privacy_id, enable);
-}
-
-int privacy_manager_client_check_user_consented(const char *package_id, bool *consented)
-{
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
-
- return pInst->isUserPrompted(std::string(package_id), *consented);
-}
-
-int privacy_manager_client_set_user_consented(const char *package_id, bool consented)
-{
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
-
- return pInst->setUserPrompted(std::string(package_id), consented);
-}
-
-int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data)
-{
- int retval;
- bool res;
-
- std::list < std::string > privacyList;
- retval = PrivacyIdInfo::getAllPrivacyId(privacyList);
- if (retval != PRIV_MGR_ERROR_SUCCESS)
- return retval;
- if (privacyList.size() == 0)
- return PRIV_MGR_ERROR_NO_DATA;
-
- for (std::list < std::string >::iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter)
- {
- privacy_info_client_s *privacy_info_client_s = NULL;
- retval = create_privacy_info_client_s(iter->c_str(), false, &privacy_info_client_s);
- res = callback(privacy_info_client_s, user_data);
- privacy_info_client_s_destroy(privacy_info_client_s);
- if (!res)
- break;
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data)
-{
- int retval;
- bool res;
- PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance();
-
- std::list < std::pair < std::string, bool > > packageList;
- retval = pInst->getAppPackagesbyPrivacyId(std::string(privacy_id), packageList);
-
- if (retval != PRIV_MGR_ERROR_SUCCESS)
- return retval;
- if (packageList.size() == 0)
- return PRIV_MGR_ERROR_NO_DATA;
-
- for (std::list < std::pair < std::string, bool > >::iterator iter = packageList.begin(); iter != packageList.end(); ++iter)
- {
- res = callback(iter->first.c_str(), iter->second, user_data);
- if (!res)
- break;
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
+/* + * 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 <string.h> +#include <string> +#include <memory> +#include <dlog.h> +#include <PrivacyManagerClient.h> +#include <PrivacyIdInfo.h> +#include <privacy_manager_client.h> +#include "privacy_manager_client_internal_types.h" + +int create_privacy_info_client_s(const char* privacy_id, bool enabled, privacy_info_client_s **privacy_info) +{ + privacy_info_client_s* temp = (privacy_info_client_s*) calloc(1, sizeof(privacy_info_client_s)); + if (temp == NULL) + return PRIV_MGR_ERROR_OUT_OF_MEMORY; + + int size = strlen(privacy_id); + temp->privacy_id = (char*) calloc(1, size + 1); + if (temp->privacy_id == NULL) + { + free(temp); + return PRIV_MGR_ERROR_OUT_OF_MEMORY; + } + memcpy(temp->privacy_id, privacy_id, size + 1); + + temp->is_enabled = enabled; + + *privacy_info = temp; + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list, bool privacy_popup_required) +{ + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + std::list < std::string > privacyList; + + while (*privacy_list[0] != '\0') + privacyList.push_back(std::string(*privacy_list++)); + + int retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList, privacy_popup_required, false); + + return retval; +} + +int privacy_manager_client_uninstall_privacy(const char *package_id) +{ + if (package_id == NULL) + return PRIV_MGR_ERROR_INVALID_PARAMETER; + return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), false); +} + +int privacy_manager_client_uninstall_privacy_by_server(const char *package_id) +{ + if (package_id == NULL) + return PRIV_MGR_ERROR_INVALID_PARAMETER; + return PrivacyManagerClient::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id), true); +} + +int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data) +{ + int retval; + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + std::list < std::string > list; + retval = pInst->getPrivacyAppPackages(list); + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + if (list.size() == 0) + return PRIV_MGR_ERROR_NO_DATA; + + for (std::list < std::string >::iterator iter = list.begin(); iter != list.end(); ++iter) + { + if ( ! callback(iter->c_str(), user_data) ) + break; + } + + return PRIV_MGR_ERROR_SUCCESS; +} +int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data) +{ + int retval; + bool res; + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + std::list < std::pair <std::string, bool > > list; + + retval = pInst->getAppPackagePrivacyInfo(std::string(package_id), list); + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + if (list.size() == 0) + return PRIV_MGR_ERROR_NO_DATA; + + for (std::list < std::pair <std::string, bool > >::iterator iter = list.begin(); iter != list.end(); ++iter) + { + privacy_info_client_s *privacy_info_client_s = NULL; + retval = create_privacy_info_client_s(iter->first.c_str(), iter->second, &privacy_info_client_s); + res = callback(privacy_info_client_s, user_data); + privacy_info_client_s_destroy(privacy_info_client_s); + if (!res) + break; + } + return PRIV_MGR_ERROR_SUCCESS; + +} +int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable) +{ + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + return pInst->setPrivacySetting(package_id, privacy_id, enable); +} + +int privacy_manager_client_check_user_consented(const char *package_id, bool *consented) +{ + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + return pInst->isUserPrompted(std::string(package_id), *consented); +} + +int privacy_manager_client_set_user_consented(const char *package_id, bool consented) +{ + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + return pInst->setUserPrompted(std::string(package_id), consented); +} + +int privacy_manager_client_foreach_all_privacy(privacy_manager_client_all_privacy_info_cb callback, void* user_data) +{ + int retval; + bool res; + + std::list < std::string > privacyList; + retval = PrivacyIdInfo::getAllPrivacyId(privacyList); + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + if (privacyList.size() == 0) + return PRIV_MGR_ERROR_NO_DATA; + + for (std::list < std::string >::iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter) + { + privacy_info_client_s *privacy_info_client_s = NULL; + retval = create_privacy_info_client_s(iter->c_str(), false, &privacy_info_client_s); + res = callback(privacy_info_client_s, user_data); + privacy_info_client_s_destroy(privacy_info_client_s); + if (!res) + break; + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int privacy_manager_client_foreach_package_list_by_privacy(const char *privacy_id, privacy_manager_client_packages_by_privacy_cb callback, void* user_data) +{ + int retval; + bool res; + PrivacyManagerClient* pInst = PrivacyManagerClient::getInstance(); + + std::list < std::pair < std::string, bool > > packageList; + retval = pInst->getAppPackagesbyPrivacyId(std::string(privacy_id), packageList); + + if (retval != PRIV_MGR_ERROR_SUCCESS) + return retval; + if (packageList.size() == 0) + return PRIV_MGR_ERROR_NO_DATA; + + for (std::list < std::pair < std::string, bool > >::iterator iter = packageList.begin(); iter != packageList.end(); ++iter) + { + res = callback(iter->first.c_str(), iter->second, user_data); + if (!res) + break; + } + + return PRIV_MGR_ERROR_SUCCESS; }
\ No newline at end of file diff --git a/client/src/privacy_manager_client_internal_types.h b/client/src/privacy_manager_client_internal_types.h index 638288e..ca9f907 100644 --- a/client/src/privacy_manager_client_internal_types.h +++ b/client/src/privacy_manager_client_internal_types.h @@ -1,32 +1,32 @@ -/*
- * 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 __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
-#define __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
-
-#include <tizen.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
+/* + * 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 __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H +#define __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H + +#include <tizen.h> + +#ifdef __cplusplus +extern "C" { +#endif + + +#ifdef __cplusplus +} +#endif + + #endif //__TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
\ No newline at end of file diff --git a/common/inc/IPrivacyManager.h b/common/inc/IPrivacyManager.h index 26beb33..055bbbf 100644 --- a/common/inc/IPrivacyManager.h +++ b/common/inc/IPrivacyManager.h @@ -1,43 +1,43 @@ -/*
- * 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 _IPRIVACY_MANAGER_H_
-#define _IPRIVACY_MANAGER_H_
-
-#include <string>
-#include <mutex>
-#include <list>
-#include <vector>
-#include <memory>
-#include <PrivacyManagerTypes.h>
-
-class SocketClient;
-
-class EXTERN_API IPrivacyManager
-{
-public:
- int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList, bool privacyPopupRequired);
-
- int removeAppPackagePrivacyInfo(const std::string pkgId);
-
- int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);
-
- int getPrivacyAppPackages(std::list < std::string >& pList);
-
- int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & pList);
-};
-
+/* + * 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 _IPRIVACY_MANAGER_H_ +#define _IPRIVACY_MANAGER_H_ + +#include <string> +#include <mutex> +#include <list> +#include <vector> +#include <memory> +#include <PrivacyManagerTypes.h> + +class SocketClient; + +class EXTERN_API IPrivacyManager +{ +public: + int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList, bool privacyPopupRequired); + + int removeAppPackagePrivacyInfo(const std::string pkgId); + + int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled); + + int getPrivacyAppPackages(std::list < std::string >& pList); + + int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & pList); +}; + #endif // _IPRIVACY_MANAGER_H_
\ No newline at end of file diff --git a/common/inc/PrivacyIdInfo.h b/common/inc/PrivacyIdInfo.h index 0d82d11..dfd0d3b 100644 --- a/common/inc/PrivacyIdInfo.h +++ b/common/inc/PrivacyIdInfo.h @@ -1,40 +1,40 @@ -/*
- * 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_ID_INFO_H_
-#define _PRIVACY_ID_INFO_H_
-
-#include <string>
-#include <map>
-#include <list>
-
-class PrivacyIdInfo
-{
-private:
- static std::map <std::string, std::string> m_privilegeToPrivacyMap;
- static bool m_isInitialized;
-
-public:
- static int initialize(void);
- static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId);
- static int getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList);
- static int getAllPrivacyId(std::list < std::string >& privacyIdList);
-
- static int getPrivaycDisplayName(const std::string privacyId, std::string& displayName);
- static int getPrivaycDescription(const std::string privacyId, std::string& description);
-};
-
+/* + * 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_ID_INFO_H_ +#define _PRIVACY_ID_INFO_H_ + +#include <string> +#include <map> +#include <list> + +class PrivacyIdInfo +{ +private: + static std::map <std::string, std::string> m_privilegeToPrivacyMap; + static bool m_isInitialized; + +public: + static int initialize(void); + static int getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId); + static int getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList); + static int getAllPrivacyId(std::list < std::string >& privacyIdList); + + static int getPrivaycDisplayName(const std::string privacyId, std::string& displayName); + static int getPrivaycDescription(const std::string privacyId, std::string& description); +}; + #endif //_PRIVACY_ID_INFO_H_
\ No newline at end of file diff --git a/common/inc/PrivacyManagerTypes.h b/common/inc/PrivacyManagerTypes.h index 437d810..becb451 100644 --- a/common/inc/PrivacyManagerTypes.h +++ b/common/inc/PrivacyManagerTypes.h @@ -1,31 +1,31 @@ -/*
- * 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_TYPES_H_
-#define _PRIVACY_MANAGER_TYPES_H_
-
-#include <string>
-#include <privacy_manager_client_types.h>
-
-static const std::string PRIVACY_DB_PATH("/opt/dbspace/.privacy.db");
-static const std::string PRIVACY_INFO_DB_PATH("/opt/dbspace/.privacylist.db");
-static const std::string SERVER_ADDRESS ("/tmp/privacy_manager_server");
-static const std::string DBUS_PATH("/privacy_manager/dbus_notification");
-static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_manager.signal");
-static const std::string DBUS_SIGNAL_SETTING_CHANGED("privacy_setting_changed");
-static const std::string DBUS_SIGNAL_PKG_REMOVED("privacy_pkg_removed");
-
-#endif
+/* + * 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_TYPES_H_ +#define _PRIVACY_MANAGER_TYPES_H_ + +#include <string> +#include <privacy_manager_client_types.h> + +static const std::string PRIVACY_DB_PATH("/opt/dbspace/.privacy.db"); +static const std::string PRIVACY_INFO_DB_PATH("/opt/dbspace/.privacylist.db"); +static const std::string SERVER_ADDRESS ("/tmp/privacy_manager_server"); +static const std::string DBUS_PATH("/privacy_manager/dbus_notification"); +static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_manager.signal"); +static const std::string DBUS_SIGNAL_SETTING_CHANGED("privacy_setting_changed"); +static const std::string DBUS_SIGNAL_PKG_REMOVED("privacy_pkg_removed"); + +#endif diff --git a/common/inc/SocketConnection.h b/common/inc/SocketConnection.h index 14a50c2..d6bd88c 100644 --- a/common/inc/SocketConnection.h +++ b/common/inc/SocketConnection.h @@ -1,327 +1,327 @@ -/*
- * 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 _SOCKET_CONNECTION_H_
-#define _SOCKET_CONNECTION_H_
-
-#include <dlog.h>
-#include <new>
-#include <list>
-#include <utility>
-#include <SocketStream.h>
-#include <PrivacyManagerTypes.h>
-#include <iostream>
-#include <Utils.h>
-/*
- * This class implements interface for generic read and write from given socket.
- * It does not maintain socket descriptor, so any connecting and disconnecting should be
- */
-
-/*
- * Throws SocketConnectionException when read/write will not succeed or if any bad allocation
- * exception occurs during read.
- */
-
-class EXTERN_API SocketConnection
-{
-
-public:
-
- explicit SocketConnection(int socket_fd) : m_socketStream(socket_fd){
- LOGI("Created");
- }
-
- template<typename T, typename ...Args>
- int read(T* out, const Args&... args )
- {
- int res = read(out);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
- res = read(args...);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template<typename T>
- int read(T* out)
- {
- int length = 0;
- int res = m_socketStream.readStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
- char* pBuf = new (std::nothrow) char[length + 1];
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
-
- res = m_socketStream.readStream(length, pBuf);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
-
- pBuf[length] = 0;
-
- out = T(pBuf);
-
- delete[] pBuf;
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int read(bool* pB)
- {
- int length = 0;
- int res = m_socketStream.readStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
-
- char* pBuf = new (std::nothrow) char[length + 1];
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
-
- res = m_socketStream.readStream(length, pBuf);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
-
- pBuf[length] = 0;
-
- *pB = * reinterpret_cast <bool* > (pBuf);
-
- delete[] pBuf;
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int read(bool& b)
- {
- return read(&b);
- }
-
- int read(int& i)
- {
- return read(&i);
- }
-
- int read(int* pI)
- {
- int length = 0;
- int res = m_socketStream.readStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
-
- char* pBuf = new (std::nothrow) char[length + 1];
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
-
- res = m_socketStream.readStream(length, pBuf);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
-
- pBuf[length] = 0;
-
- *pI = * reinterpret_cast <int* > (pBuf);
-
- delete[] pBuf;
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int read(std::string* pStr)
- {
- int length = 0;
- int res = m_socketStream.readStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res);
-
- char* pBuf = new (std::nothrow) char[length + 1];
- TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY);
-
- m_socketStream.readStream(length, pBuf);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res);
-
- pBuf[length] = 0;
-
- *pStr = std::string(pBuf);
- delete[] pBuf;
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int read(std::string& str)
- {
- return read(&str);
- }
-
- template < typename T >
- int read (std::list<T>& list)
- {
- int length;
- int res = read(length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
-
- for (int i = 0; i < length; ++i)
- {
- T obj;
- res = read (obj);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
- list.push_back(obj);
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template < typename T >
- int read (std::list<T>* pList)
- {
- return read(*pList);
- }
-
- template < typename K, typename P >
- void read (std::pair<K, P>& pair)
- {
- int res = read( pair.first);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
- res = read( pair.second);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template < typename K, typename P >
- int read (std::pair<K, P>* pPair)
- {
- return read( *pPair);
- }
-
- template<typename T, typename ...Args>
- int write(const T& in, const Args&... args)
- {
- int res = write(in);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
- res = write(args...);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int write(const std::string& in)
- {
- int length = in.size();
- int res = m_socketStream.writeStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
- res = m_socketStream.writeStream(length, in.c_str());
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int write(const unsigned int& in)
- {
- int length = sizeof(in);
- int res = m_socketStream.writeStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
- res = m_socketStream.writeStream(length, &in);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int write(const int& in)
- {
- int length = sizeof(in);
- int res = m_socketStream.writeStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
- res = m_socketStream.writeStream(length, &in);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int write(const bool& in)
- {
- int length = sizeof(in);
- int res = m_socketStream.writeStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
- res = m_socketStream.writeStream(length, &in);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- int write(const char*& in)
- {
- int length = strlen(in);
- int res = m_socketStream.writeStream(sizeof(length), &length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
- res = m_socketStream.writeStream(length, in);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template<typename T, typename ...Args>
- int write(const T* in, const Args&... args)
- {
- int res = write(in);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
- res = write(args...);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template<typename K, typename T>
- int write(const std::pair<K, T> p)
- {
- int res = write(p.first);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
- res = write(p.second);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template<typename K, typename T>
- int write(const std::pair<K, T&> p)
- {
- int res = write(p.first);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
- res = write(p.second);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template<typename K, typename T>
- int write(const std::pair<K, T&>* pPair)
- {
- return write(*pPair);
- }
-
- template<typename T>
- int write(const std::list <T> list)
- {
- int length = list.size();
- int res = write(length);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
- for (typename std::list <T>::const_iterator iter = list.begin(); iter != list.end(); iter++) {
- res = write(*iter);
- TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res);
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- template<typename T>
- int write(const std::list <T>* pList)
- {
- return write(*pList);
- }
-
-
-private:
- SocketStream m_socketStream;
-};
-
-#endif // _SOCKET_CONNECTION_H_
+/* + * 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 _SOCKET_CONNECTION_H_ +#define _SOCKET_CONNECTION_H_ + +#include <dlog.h> +#include <new> +#include <list> +#include <utility> +#include <SocketStream.h> +#include <PrivacyManagerTypes.h> +#include <iostream> +#include <Utils.h> +/* + * This class implements interface for generic read and write from given socket. + * It does not maintain socket descriptor, so any connecting and disconnecting should be + */ + +/* + * Throws SocketConnectionException when read/write will not succeed or if any bad allocation + * exception occurs during read. + */ + +class EXTERN_API SocketConnection +{ + +public: + + explicit SocketConnection(int socket_fd) : m_socketStream(socket_fd){ + LOGI("Created"); + } + + template<typename T, typename ...Args> + int read(T* out, const Args&... args ) + { + int res = read(out); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res); + res = read(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T> + int read(T* out) + { + int length = 0; + int res = m_socketStream.readStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res); + char* pBuf = new (std::nothrow) char[length + 1]; + TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY); + + res = m_socketStream.readStream(length, pBuf); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res); + + pBuf[length] = 0; + + out = T(pBuf); + + delete[] pBuf; + + return PRIV_MGR_ERROR_SUCCESS; + } + + int read(bool* pB) + { + int length = 0; + int res = m_socketStream.readStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res); + + char* pBuf = new (std::nothrow) char[length + 1]; + TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY); + + res = m_socketStream.readStream(length, pBuf); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res); + + pBuf[length] = 0; + + *pB = * reinterpret_cast <bool* > (pBuf); + + delete[] pBuf; + + return PRIV_MGR_ERROR_SUCCESS; + } + + int read(bool& b) + { + return read(&b); + } + + int read(int& i) + { + return read(&i); + } + + int read(int* pI) + { + int length = 0; + int res = m_socketStream.readStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res); + + char* pBuf = new (std::nothrow) char[length + 1]; + TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY); + + res = m_socketStream.readStream(length, pBuf); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res); + + pBuf[length] = 0; + + *pI = * reinterpret_cast <int* > (pBuf); + + delete[] pBuf; + + return PRIV_MGR_ERROR_SUCCESS; + } + + int read(std::string* pStr) + { + int length = 0; + int res = m_socketStream.readStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "readStream : %d", res); + + char* pBuf = new (std::nothrow) char[length + 1]; + TryReturn(pBuf != NULL, PRIV_MGR_ERROR_OUT_OF_MEMORY, , "new : %d", PRIV_MGR_ERROR_OUT_OF_MEMORY); + + m_socketStream.readStream(length, pBuf); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, delete[] pBuf, "readStream : %d", res); + + pBuf[length] = 0; + + *pStr = std::string(pBuf); + delete[] pBuf; + + return PRIV_MGR_ERROR_SUCCESS; + } + + int read(std::string& str) + { + return read(&str); + } + + template < typename T > + int read (std::list<T>& list) + { + int length; + int res = read(length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res); + + for (int i = 0; i < length; ++i) + { + T obj; + res = read (obj); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res); + list.push_back(obj); + } + + return PRIV_MGR_ERROR_SUCCESS; + } + + template < typename T > + int read (std::list<T>* pList) + { + return read(*pList); + } + + template < typename K, typename P > + void read (std::pair<K, P>& pair) + { + int res = read( pair.first); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res); + res = read( pair.second); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "read : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template < typename K, typename P > + int read (std::pair<K, P>* pPair) + { + return read( *pPair); + } + + template<typename T, typename ...Args> + int write(const T& in, const Args&... args) + { + int res = write(in); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + res = write(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + int write(const std::string& in) + { + int length = in.size(); + int res = m_socketStream.writeStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + res = m_socketStream.writeStream(length, in.c_str()); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + int write(const unsigned int& in) + { + int length = sizeof(in); + int res = m_socketStream.writeStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + res = m_socketStream.writeStream(length, &in); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + int write(const int& in) + { + int length = sizeof(in); + int res = m_socketStream.writeStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + res = m_socketStream.writeStream(length, &in); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + int write(const bool& in) + { + int length = sizeof(in); + int res = m_socketStream.writeStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + res = m_socketStream.writeStream(length, &in); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + int write(const char*& in) + { + int length = strlen(in); + int res = m_socketStream.writeStream(sizeof(length), &length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + res = m_socketStream.writeStream(length, in); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "writeStream : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T, typename ...Args> + int write(const T* in, const Args&... args) + { + int res = write(in); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + res = write(args...); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename K, typename T> + int write(const std::pair<K, T> p) + { + int res = write(p.first); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + res = write(p.second); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename K, typename T> + int write(const std::pair<K, T&> p) + { + int res = write(p.first); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + res = write(p.second); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename K, typename T> + int write(const std::pair<K, T&>* pPair) + { + return write(*pPair); + } + + template<typename T> + int write(const std::list <T> list) + { + int length = list.size(); + int res = write(length); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + for (typename std::list <T>::const_iterator iter = list.begin(); iter != list.end(); iter++) { + res = write(*iter); + TryReturn(res == PRIV_MGR_ERROR_SUCCESS, res, , "write : %d", res); + } + + return PRIV_MGR_ERROR_SUCCESS; + } + + template<typename T> + int write(const std::list <T>* pList) + { + return write(*pList); + } + + +private: + SocketStream m_socketStream; +}; + +#endif // _SOCKET_CONNECTION_H_ diff --git a/common/inc/SocketStream.h b/common/inc/SocketStream.h index c99aafd..0788a9d 100644 --- a/common/inc/SocketStream.h +++ b/common/inc/SocketStream.h @@ -1,43 +1,43 @@ -/*
- * 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 _SOCKET_STREAM_H_
-#define _SOCKET_STREAM_H_
-
-#include <string>
-#include <PrivacyManagerTypes.h>
-
-class EXTERN_API SocketStream
-{
-public:
- explicit SocketStream(int socket_fd)
- : m_socketFd(socket_fd)
- , m_bytesRead(0)
- ,m_bytesWrote(0)
- {
- LOGI("Created");
- }
-
- int readStream(size_t num, void * bytes);
- int writeStream(size_t num, const void * bytes);
-private:
- int throwWithErrnoMessage(std::string specificInfo);
- int m_socketFd;
- int m_bytesRead;
- int m_bytesWrote;
-};
-
+/* + * 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 _SOCKET_STREAM_H_ +#define _SOCKET_STREAM_H_ + +#include <string> +#include <PrivacyManagerTypes.h> + +class EXTERN_API SocketStream +{ +public: + explicit SocketStream(int socket_fd) + : m_socketFd(socket_fd) + , m_bytesRead(0) + ,m_bytesWrote(0) + { + LOGI("Created"); + } + + int readStream(size_t num, void * bytes); + int writeStream(size_t num, const void * bytes); +private: + int throwWithErrnoMessage(std::string specificInfo); + int m_socketFd; + int m_bytesRead; + int m_bytesWrote; +}; + #endif //_SOCKET_STREAM_H_
\ No newline at end of file diff --git a/common/inc/privacy_manager_client_types.h b/common/inc/privacy_manager_client_types.h index e3da8ab..9555cc8 100644 --- a/common/inc/privacy_manager_client_types.h +++ b/common/inc/privacy_manager_client_types.h @@ -1,50 +1,50 @@ -/*
- * 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 __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H
-#define __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifndef EXTERN_API
-#define EXTERN_API __attribute__((visibility("default")))
-#endif
-
-enum {
- PRIV_MGR_ERROR_SUCCESS = 0,
-
- PRIV_MGR_ERROR_NOT_INITIALIZED = -10,
- PRIV_MGR_ERROR_INVALID_PARAMETER = -11,
- PRIV_MGR_ERROR_OUT_OF_MEMORY = -12,
- PRIV_MGR_ERROR_IO_ERROR = -13,
- PRIV_MGR_ERROR_NO_DATA = -14,
- PRIV_MGR_ERROR_DB_ERROR = -15,
- PRIV_MGR_ERROR_IPC_ERROR = -16,
- PRIV_MGR_ERROR_INVALID_STATE = -17,
- PRIV_MGR_ERROR_SYSTEM_ERROR = -18,
- PRIV_MGR_ERROR_USER_NOT_CONSENTED = -19,
-
- PRIV_MGR_ERROR_UNKNOWN = -(0x99),
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H
+/* + * 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 __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H +#define __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef EXTERN_API +#define EXTERN_API __attribute__((visibility("default"))) +#endif + +enum { + PRIV_MGR_ERROR_SUCCESS = 0, + + PRIV_MGR_ERROR_NOT_INITIALIZED = -10, + PRIV_MGR_ERROR_INVALID_PARAMETER = -11, + PRIV_MGR_ERROR_OUT_OF_MEMORY = -12, + PRIV_MGR_ERROR_IO_ERROR = -13, + PRIV_MGR_ERROR_NO_DATA = -14, + PRIV_MGR_ERROR_DB_ERROR = -15, + PRIV_MGR_ERROR_IPC_ERROR = -16, + PRIV_MGR_ERROR_INVALID_STATE = -17, + PRIV_MGR_ERROR_SYSTEM_ERROR = -18, + PRIV_MGR_ERROR_USER_NOT_CONSENTED = -19, + + PRIV_MGR_ERROR_UNKNOWN = -(0x99), +}; + + +#ifdef __cplusplus +} +#endif + +#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H diff --git a/common/src/PrivacyDb.cpp b/common/src/PrivacyDb.cpp index f1a9bc6..acd91a7 100644 --- a/common/src/PrivacyDb.cpp +++ b/common/src/PrivacyDb.cpp @@ -60,7 +60,7 @@ bool PrivacyDb::isFilteredPackage(const std::string pkgId) const if ( (it = m_filteredPkgList.find(pkgId)) != m_filteredPkgList.end()) return true; - return false; + return false; #else return false; #endif @@ -69,8 +69,6 @@ bool PrivacyDb::isFilteredPackage(const std::string pkgId) const int PrivacyDb::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled) { - LOGI("enter"); - static const std::string query = std::string("UPDATE PrivacyInfo set IS_ENABLED =? where PKG_ID=? and PRIVACY_ID=?"); openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); @@ -88,16 +86,12 @@ PrivacyDb::setPrivacySetting(const std::string pkgId, const std::string privacyI res = sqlite3_step(pStmt.get()); TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); - LOGI("leave"); - return 0; } int PrivacyDb::getPrivacyAppPackages(std::list <std::string>& list) const { - LOGI("enter"); - std::string query = "SELECT PKG_ID from PackageInfo"; openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); @@ -118,16 +112,12 @@ PrivacyDb::getPrivacyAppPackages(std::list <std::string>& list) const list.push_back(std::string(pValue)); } - LOGI("leave"); - return 0; } int PrivacyDb::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList) const { - LOGI("enter"); - static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from PrivacyInfo where PKG_ID=?"; openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); @@ -146,8 +136,6 @@ PrivacyDb::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pa SECURE_LOGD("Privacy found : %s %d", privacyId, privacyEnabled); } - LOGI("leave"); - return 0; } @@ -155,8 +143,6 @@ PrivacyDb::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pa int PrivacyDb::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList, bool privacyPopupRequired) { - LOGI("enter"); - static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)"); static const std::string privacyQuery("INSERT INTO PrivacyInfo(PKG_ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)"); @@ -174,7 +160,7 @@ PrivacyDb::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < s for ( std::list <std::string>::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter) { - SECURE_LOGD(" install privacy: %s", iter->c_str()); + SECURE_LOGD("install privacy: %s", iter->c_str()); prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt); res = sqlite3_bind_text(pPrivacyStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT); @@ -199,8 +185,6 @@ PrivacyDb::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < s int PrivacyDb::removeAppPackagePrivacyInfo(const std::string pkgId) { - LOGI("enter"); - static const std::string pkgInfoQuery("DELETE FROM PackageInfo WHERE PKG_ID=?"); static const std::string privacyQuery("DELETE FROM PrivacyInfo WHERE PKG_ID=?"); @@ -229,8 +213,6 @@ PrivacyDb::removeAppPackagePrivacyInfo(const std::string pkgId) int PrivacyDb::isUserPrompted(const std::string pkgId, bool& isPrompted) const { - LOGI("enter"); - static const std::string query = "SELECT IS_SET from PackageInfo where PKG_ID=?"; isPrompted = true; @@ -265,8 +247,6 @@ PrivacyDb::isUserPrompted(const std::string pkgId, bool& isPrompted) const int PrivacyDb::setUserPrompted(const std::string pkgId, bool prompted) { - LOGI("enter"); - std::string query = std::string("UPDATE PackageInfo set IS_SET =? where PKG_ID=?"); int res; @@ -283,16 +263,12 @@ PrivacyDb::setUserPrompted(const std::string pkgId, bool prompted) res = sqlite3_step(pStmt.get()); TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res); - LOGI("leave"); - return 0; } int PrivacyDb::getAppPackagesbyPrivacyId(std::string privacyId, std::list < std::pair < std::string, bool > >& list) const { - LOGI("enter"); - std::string sql = std::string("SELECT PKG_ID, IS_ENABLED from PrivacyInfo where PRIVACY_ID=?"); openDb(PRIVACY_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE); @@ -317,8 +293,6 @@ PrivacyDb::getAppPackagesbyPrivacyId(std::string privacyId, std::list < std::pai list.push_back( std::pair <std::string, bool >(pkgId, isEnabled) ); } - LOGI("leave"); - return PRIV_MGR_ERROR_SUCCESS; } @@ -358,7 +332,6 @@ PrivacyDb::~PrivacyDb(void) PrivacyDb* PrivacyDb::getInstance(void) { - LOGI("enter"); std::lock_guard < std::mutex > guard(m_singletonMutex); if (m_pInstance == NULL) @@ -366,7 +339,5 @@ PrivacyDb::getInstance(void) m_pInstance = new PrivacyDb(); } - LOGI("leave"); - return m_pInstance; } diff --git a/common/src/PrivacyIdInfo.cpp b/common/src/PrivacyIdInfo.cpp index 64d28fb..5663a76 100644 --- a/common/src/PrivacyIdInfo.cpp +++ b/common/src/PrivacyIdInfo.cpp @@ -1,190 +1,171 @@ -/*
- * 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 <PrivacyIdInfo.h>
-#include <privacy_manager_client_types.h>
-#include <PrivacyManagerTypes.h>
-#include <dlog.h>
-#include <set>
-#include <Utils.h>
-#include <libintl.h>
-
-std::map <std::string, std::string> PrivacyIdInfo::m_privilegeToPrivacyMap;
-bool PrivacyIdInfo:: m_isInitialized;
-
-int
-PrivacyIdInfo::initialize(void)
-{
- static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable");
-
- LOGI("enter");
-
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
- prepareDb(pDbHandler, sqlPrivilege.c_str(), pStmtPrivilege);
-
- int res;
- while ( (res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW )
- {
- const char* privilegeId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 0));
- const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 1));
- m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId)));
- }
-
- m_isInitialized = true;
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyIdInfo::getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId)
-{
- if (!m_isInitialized)
- initialize();
- std::map < std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege);
- if (iter == m_privilegeToPrivacyMap.end())
- return PRIV_MGR_ERROR_NO_DATA;
- privacyId = iter->second;
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList)
-{
- if (!m_isInitialized)
- initialize();
-
- privacyIdList.clear();
-
- std::set <std::string> privacyIdSet;
-
- for (std::list < std::string > ::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter)
- {
- std::string privacyId;
- int res = getPrivacyIdFromPrivilege(*iter, privacyId);
- if (res == PRIV_MGR_ERROR_SUCCESS)
- privacyIdSet.insert(privacyId);
- }
-
- for (std::set < std::string >::iterator iter = privacyIdSet.begin(); iter != privacyIdSet.end(); ++iter)
- {
- privacyIdList.push_back(*iter);
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyIdInfo::getAllPrivacyId(std::list < std::string >& privacyIdList)
-{
- static const std::string sql("SELECT PRIVACY_ID from PrivacyInfo");
-
- if (!m_isInitialized)
- initialize();
-
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
- prepareDb(pDbHandler, sql.c_str(), pStmt);
-
- int res;
- while ( (res = sqlite3_step(pStmt.get())) == SQLITE_ROW )
- {
- const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
- privacyIdList.push_back(std::string(privacyId));
- SECURE_LOGD(" privacy Id : %s", privacyId);
- }
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyIdInfo::getPrivaycDisplayName(const std::string privacyId, std::string& displayName)
-{
- LOGI("enter");
-
- if (!m_isInitialized)
- initialize();
- //bindtextdomain("privacy-manager", "/usr/share/locale");
- //setlocale(LC_ALL, "");
-
- std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?");
-
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
- prepareDb(pDbHandler, sql.c_str(), pStmt);
-
- int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT);
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
-
- if ( sqlite3_step(pStmt.get()) == SQLITE_ROW )
- {
- const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
- const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1));
-
- LOGD("result : [%s] [%s]", pModuleId, pNameId);
-
- if (pNameId == NULL)
- displayName = privacyId;
- else
- displayName = std::string(dgettext(pModuleId, pNameId));
- }
- else
- {
- LOGI("Cannot find privacy string %s ", privacyId.c_str());
-
- // Todo : return no_data.
- displayName = privacyId;
- return PRIV_MGR_ERROR_SUCCESS;
- }
-
- LOGI("leave %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& displayName)
-{
- LOGI("enter");
-
- if (!m_isInitialized)
- initialize();
-
- std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?");
-
- openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY);
- prepareDb(pDbHandler, sql.c_str(), pStmt);
-
- int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT);
- TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);
-
- if ( sqlite3_step(pStmt.get()) == SQLITE_ROW )
- {
- const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
- const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));
-
- LOGD("result : %s %s", pModuleId, pNameId);
-
- displayName = std::string(dgettext(pModuleId, pNameId));
- }
- else
- {
- LOGI("Cannot find privacy string %s ", privacyId.c_str());
- return PRIV_MGR_ERROR_NO_DATA;
- }
-
- LOGI("leave %d", res);
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
+/* + * 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 <PrivacyIdInfo.h> +#include <privacy_manager_client_types.h> +#include <PrivacyManagerTypes.h> +#include <dlog.h> +#include <set> +#include <Utils.h> +#include <libintl.h> + +std::map <std::string, std::string> PrivacyIdInfo::m_privilegeToPrivacyMap; +bool PrivacyIdInfo:: m_isInitialized; + +int +PrivacyIdInfo::initialize(void) +{ + static const std::string sqlPrivilege("SELECT PRIVILEGE_ID, PRIVACY_ID from PrivilegeToPrivacyTable"); + + openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); + prepareDb(pDbHandler, sqlPrivilege.c_str(), pStmtPrivilege); + + int res; + while ( (res = sqlite3_step(pStmtPrivilege.get())) == SQLITE_ROW ) + { + const char* privilegeId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 0)); + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmtPrivilege.get(), 1)); + m_privilegeToPrivacyMap.insert(std::map < std::string, std::string >::value_type(std::string(privilegeId), std::string(privacyId))); + } + + m_isInitialized = true; + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyIdInfo::getPrivacyIdFromPrivilege(const std::string privilege, std::string& privacyId) +{ + if (!m_isInitialized) + initialize(); + std::map < std::string, std::string >::iterator iter = m_privilegeToPrivacyMap.find(privilege); + if (iter == m_privilegeToPrivacyMap.end()) + return PRIV_MGR_ERROR_NO_DATA; + privacyId = iter->second; + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(const std::list < std::string> privilegeList, std::list < std::string> & privacyIdList) +{ + if (!m_isInitialized) + initialize(); + + privacyIdList.clear(); + + std::set <std::string> privacyIdSet; + + for (std::list < std::string > ::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter) + { + std::string privacyId; + int res = getPrivacyIdFromPrivilege(*iter, privacyId); + if (res == PRIV_MGR_ERROR_SUCCESS) + privacyIdSet.insert(privacyId); + } + + for (std::set < std::string >::iterator iter = privacyIdSet.begin(); iter != privacyIdSet.end(); ++iter) + { + privacyIdList.push_back(*iter); + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyIdInfo::getAllPrivacyId(std::list < std::string >& privacyIdList) +{ + static const std::string sql("SELECT PRIVACY_ID from PrivacyInfo"); + + if (!m_isInitialized) + initialize(); + + openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); + prepareDb(pDbHandler, sql.c_str(), pStmt); + + int res; + while ( (res = sqlite3_step(pStmt.get())) == SQLITE_ROW ) + { + const char* privacyId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + privacyIdList.push_back(std::string(privacyId)); + SECURE_LOGD(" privacy Id : %s", privacyId); + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyIdInfo::getPrivaycDisplayName(const std::string privacyId, std::string& displayName) +{ + if (!m_isInitialized) + initialize(); + + std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?"); + + openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); + prepareDb(pDbHandler, sql.c_str(), pStmt); + + int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + if ( sqlite3_step(pStmt.get()) == SQLITE_ROW ) + { + const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 1)); + + if (pNameId == NULL) + displayName = privacyId; + else + displayName = std::string(dgettext(pModuleId, pNameId)); + } + else + { + LOGI("Cannot find privacy string %s ", privacyId.c_str()); + return PRIV_MGR_ERROR_NO_DATA; + } + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +PrivacyIdInfo::getPrivaycDescription(const std::string privacyId, std::string& displayName) +{ + if (!m_isInitialized) + initialize(); + + std::string sql = std::string("SELECT STR_MODULE_ID, STR_NAME_ID from PrivacyInfo where PRIVACY_ID=?"); + + openDb(PRIVACY_INFO_DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READONLY); + prepareDb(pDbHandler, sql.c_str(), pStmt); + + int res = sqlite3_bind_text(pStmt.get(), 1, privacyId.c_str(), -1, SQLITE_TRANSIENT); + TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res); + + if ( sqlite3_step(pStmt.get()) == SQLITE_ROW ) + { + const char* pModuleId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + const char* pNameId = reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0)); + + displayName = std::string(dgettext(pModuleId, pNameId)); + } + else + { + LOGI("Cannot find privacy string %s ", privacyId.c_str()); + return PRIV_MGR_ERROR_NO_DATA; + } + + return PRIV_MGR_ERROR_SUCCESS; +} diff --git a/common/src/SocketConnection.cpp b/common/src/SocketConnection.cpp index 45f51fc..bb9101c 100644 --- a/common/src/SocketConnection.cpp +++ b/common/src/SocketConnection.cpp @@ -1,25 +1,25 @@ -/*
- * 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 "SocketConnection.h"
-
-//
-// Note:
-//
-// The file here is left blank to enable precompilation
-// of templates in corresponding header file.
-// Do not remove this file.
-//
+/* + * 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 "SocketConnection.h" + +// +// Note: +// +// The file here is left blank to enable precompilation +// of templates in corresponding header file. +// Do not remove this file. +// diff --git a/common/src/SocketStream.cpp b/common/src/SocketStream.cpp index 834f132..4337c3e 100644 --- a/common/src/SocketStream.cpp +++ b/common/src/SocketStream.cpp @@ -1,173 +1,173 @@ -/*
- * 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 <sys/socket.h>
-#include <sys/select.h>
-#include <errno.h>
-#include <cstring>
-#include <unistd.h>
-#include <dlog.h>
-#include <Utils.h>
-#include "SocketStream.h"
-
-#define READ_TIEMOUT_SEC 1
-#define READ_TIMEUOT_NSEC 0
-#define WRITE_TIMEOUT_SEC 0
-#define WRITE_TIMEOUT_NSEC 100000000
-#define MAX_BUFFER 10240
-
-int
-SocketStream::throwWithErrnoMessage(std::string function_name)
-{
- LOGE("%s : %s", function_name.c_str(), strerror(errno));
- return errno;
-}
-
-int
-SocketStream::readStream(size_t num, void* pBytes)
-{
- TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");
-
- m_bytesRead += num;
-
- TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");
-
- char partBuffer[MAX_BUFFER];
- std::string wholeBuffer;
-
- fd_set rset, allset;
- int maxFd;
- ssize_t bytesRead = 0;
- ssize_t bytesToRead = (ssize_t) num;
-
- timespec timeout;
-
- maxFd = m_socketFd;
- ++maxFd;
-
- FD_ZERO(&allset);
- FD_SET(m_socketFd, &allset);
-
- int ret = -1;
-
- while(bytesToRead != 0)
- {
- timeout.tv_sec = READ_TIEMOUT_SEC;
- timeout.tv_nsec = READ_TIMEUOT_NSEC;
- rset = allset;
-
- if ( (ret = pselect(maxFd, &rset, NULL, NULL, &timeout, NULL)) == -1 )
- {
- if (errno == EINTR)
- continue;
- LOGD("pselect : %s", strerror(errno));
- return -1;
- }
- //This means pselect got timedout
- //This is not a proper behavior in reading data from UDS
- //And could mean we got corrupted connection
- TryReturn(ret != 0, -1, , "Couldn't read whole data");
-
- if ( FD_ISSET(m_socketFd, &rset) )
- {
- bytesRead = read(m_socketFd, partBuffer, num);
- if ( bytesRead <= 0 )
- {
- if(errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT)
- {
- LOGI("Connection closed : %s", strerror(errno));
- return -1;
- }
- else if (errno != EAGAIN && errno != EWOULDBLOCK){
- LOGI("read()");
- return -1;
- }
- }
-
- wholeBuffer.append(partBuffer, bytesRead);
- bytesToRead -= bytesRead;
- bytesRead = 0;
- continue;
- }
-
- }
- memcpy(pBytes, wholeBuffer.c_str(), num);
-
- return 0;
-}
-
-int
-SocketStream::writeStream(size_t num, const void* pBytes)
-{
- TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");
-
- m_bytesWrote += num;
-
- TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");
-
- fd_set wset, allset;
- int maxFd;
-
- timespec timeout;
-
- maxFd = m_socketFd;
- ++maxFd;
-
- FD_ZERO(&allset);
- FD_SET(m_socketFd, &allset);
-
- int res;
- int writeRes;
- int bytesToWrite = num;
- unsigned int currentOffset = 0;
-
- while(currentOffset != num)
- {
- timeout.tv_sec = WRITE_TIMEOUT_SEC;
- timeout.tv_nsec = WRITE_TIMEOUT_NSEC;
- wset = allset;
-
- if ( (res = pselect(maxFd, NULL, &wset, NULL, &timeout, NULL)) == -1 )
- {
- if(errno == EINTR)
- continue;
- LOGD("pselect : %s", strerror(errno));
- return -1;
- }
-
- if(FD_ISSET(m_socketFd, &wset))
- {
- if ( (writeRes = write(m_socketFd, reinterpret_cast<const char *>(pBytes) + currentOffset, bytesToWrite)) == -1)
- {
- if(errno == ECONNRESET || errno == EPIPE)
- {
- LOGI("Connection closed : %s", strerror(errno));
- return -1;
-
- }
- else if(errno != EAGAIN && errno != EWOULDBLOCK)
- {
- LOGE("write()");
- return -1;
- }
- }
- currentOffset += writeRes;
- bytesToWrite -= writeRes;
- }
- }
- return 0;
+/* + * 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 <sys/socket.h> +#include <sys/select.h> +#include <errno.h> +#include <cstring> +#include <unistd.h> +#include <dlog.h> +#include <Utils.h> +#include "SocketStream.h" + +#define READ_TIEMOUT_SEC 1 +#define READ_TIMEUOT_NSEC 0 +#define WRITE_TIMEOUT_SEC 0 +#define WRITE_TIMEOUT_NSEC 100000000 +#define MAX_BUFFER 10240 + +int +SocketStream::throwWithErrnoMessage(std::string function_name) +{ + LOGE("%s : %s", function_name.c_str(), strerror(errno)); + return errno; +} + +int +SocketStream::readStream(size_t num, void* pBytes) +{ + TryReturn(pBytes != NULL, -1, , "Null pointer to buffer"); + + m_bytesRead += num; + + TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!"); + + char partBuffer[MAX_BUFFER]; + std::string wholeBuffer; + + fd_set rset, allset; + int maxFd; + ssize_t bytesRead = 0; + ssize_t bytesToRead = (ssize_t) num; + + timespec timeout; + + maxFd = m_socketFd; + ++maxFd; + + FD_ZERO(&allset); + FD_SET(m_socketFd, &allset); + + int ret = -1; + + while(bytesToRead != 0) + { + timeout.tv_sec = READ_TIEMOUT_SEC; + timeout.tv_nsec = READ_TIMEUOT_NSEC; + rset = allset; + + if ( (ret = pselect(maxFd, &rset, NULL, NULL, &timeout, NULL)) == -1 ) + { + if (errno == EINTR) + continue; + LOGD("pselect : %s", strerror(errno)); + return -1; + } + //This means pselect got timedout + //This is not a proper behavior in reading data from UDS + //And could mean we got corrupted connection + TryReturn(ret != 0, -1, , "Couldn't read whole data"); + + if ( FD_ISSET(m_socketFd, &rset) ) + { + bytesRead = read(m_socketFd, partBuffer, num); + if ( bytesRead <= 0 ) + { + if(errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT) + { + LOGI("Connection closed : %s", strerror(errno)); + return -1; + } + else if (errno != EAGAIN && errno != EWOULDBLOCK){ + LOGI("read()"); + return -1; + } + } + + wholeBuffer.append(partBuffer, bytesRead); + bytesToRead -= bytesRead; + bytesRead = 0; + continue; + } + + } + memcpy(pBytes, wholeBuffer.c_str(), num); + + return 0; +} + +int +SocketStream::writeStream(size_t num, const void* pBytes) +{ + TryReturn(pBytes != NULL, -1, , "Null pointer to buffer"); + + m_bytesWrote += num; + + TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!"); + + fd_set wset, allset; + int maxFd; + + timespec timeout; + + maxFd = m_socketFd; + ++maxFd; + + FD_ZERO(&allset); + FD_SET(m_socketFd, &allset); + + int res; + int writeRes; + int bytesToWrite = num; + unsigned int currentOffset = 0; + + while(currentOffset != num) + { + timeout.tv_sec = WRITE_TIMEOUT_SEC; + timeout.tv_nsec = WRITE_TIMEOUT_NSEC; + wset = allset; + + if ( (res = pselect(maxFd, NULL, &wset, NULL, &timeout, NULL)) == -1 ) + { + if(errno == EINTR) + continue; + LOGD("pselect : %s", strerror(errno)); + return -1; + } + + if(FD_ISSET(m_socketFd, &wset)) + { + if ( (writeRes = write(m_socketFd, reinterpret_cast<const char *>(pBytes) + currentOffset, bytesToWrite)) == -1) + { + if(errno == ECONNRESET || errno == EPIPE) + { + LOGI("Connection closed : %s", strerror(errno)); + return -1; + + } + else if(errno != EAGAIN && errno != EWOULDBLOCK) + { + LOGE("write()"); + return -1; + } + } + currentOffset += writeRes; + bytesToWrite -= writeRes; + } + } + return 0; }
\ No newline at end of file diff --git a/common/src/Utils.cpp b/common/src/Utils.cpp index b94e4af..d7aa293 100644 --- a/common/src/Utils.cpp +++ b/common/src/Utils.cpp @@ -1,22 +1,22 @@ -/*
- * 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 <Utils.h>
-
-std::string Utils::toHash(std::string src)
-{
- return src;
+/* + * 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 <Utils.h> + +std::string Utils::toHash(std::string src) +{ + return src; }
\ No newline at end of file diff --git a/pkgmgr_plugin/privileges.cpp b/pkgmgr_plugin/privileges.cpp index 21b217f..831bf42 100644 --- a/pkgmgr_plugin/privileges.cpp +++ b/pkgmgr_plugin/privileges.cpp @@ -44,11 +44,9 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId) { int ret; bool privacyPopupRequired = true; - LOGI("enter"); // Node: <privileges> xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr)); - LOGD("Node: %s", curPtr->name); curPtr = curPtr->xmlChildrenNode; if (curPtr == NULL) @@ -60,12 +58,10 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId) std::list <std::string> privilegeList; while (curPtr != NULL) { - LOGD("Node: %s", curPtr->name); - if (xmlStrcmp(curPtr->name, _NODE_PRIVILEGE) == 0) { xmlChar* pPrivilege = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1); - SECURE_LOGD(" value= %s", reinterpret_cast<char*>(pPrivilege));
+ if (pPrivilege == NULL) { LOGE("Failed to get value"); @@ -109,8 +105,6 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId) return -EINVAL; } - LOGI("leave"); - return 0; } @@ -118,8 +112,6 @@ extern "C" __attribute__ ((visibility("default"))) int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId) { - LOGI("enter"); - int res = privacy_manager_client_uninstall_privacy_by_server(packageId); if (res != PRIV_MGR_ERROR_SUCCESS) { @@ -133,7 +125,6 @@ int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr docPtr, const char* packageId) } } - LOGI("leave"); return 0; } @@ -142,6 +133,8 @@ __attribute__ ((visibility("default"))) int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char* packageId) { int res = 0; + + LOGD("Update privacy Info"); res = PKGMGR_PARSER_PLUGIN_UNINSTALL(docPtr, packageId); if (res != 0) @@ -155,4 +148,4 @@ int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr docPtr, const char* packageId) LOGD("Failed to install privacy Info: %d", res); } return res; -}
\ No newline at end of file +} diff --git a/server/inc/NotificationServer.h b/server/inc/NotificationServer.h index 81117ae..6e6d590 100644 --- a/server/inc/NotificationServer.h +++ b/server/inc/NotificationServer.h @@ -1,42 +1,42 @@ -/*
- * 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 _NOTIFICATION_SERVER_H_
-#define _NOTIFICATION_SERVER_H_
-
-#include <string>
-#include <memory>
-#include <list>
-#include <sqlite3.h>
-#include <mutex>
-#include <dbus/dbus.h>
-
-class NotificationServer
-{
-private:
- bool m_initialized;
- DBusConnection* m_pDBusConnection;
-public:
-
- NotificationServer(void);
- ~NotificationServer(void);
- int initialize(void);
- int notifySettingChanged(const std::string pkgId, const std::string privacyId);
- int notifyPkgRemoved(const std::string pkgId);
-};
-
-
+/* + * 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 _NOTIFICATION_SERVER_H_ +#define _NOTIFICATION_SERVER_H_ + +#include <string> +#include <memory> +#include <list> +#include <sqlite3.h> +#include <mutex> +#include <dbus/dbus.h> + +class NotificationServer +{ +private: + bool m_initialized; + DBusConnection* m_pDBusConnection; +public: + + NotificationServer(void); + ~NotificationServer(void); + int initialize(void); + int notifySettingChanged(const std::string pkgId, const std::string privacyId); + int notifyPkgRemoved(const std::string pkgId); +}; + + #endif // _NOTIFICATION_SERVER_H_
\ No newline at end of file diff --git a/server/inc/PrivacyInfoService.h b/server/inc/PrivacyInfoService.h index 5a9c8f8..26a3bcb 100644 --- a/server/inc/PrivacyInfoService.h +++ b/server/inc/PrivacyInfoService.h @@ -1,61 +1,61 @@ -/*
- * 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_SERVICE_H_
-#define _PRIVACY_INFO_SERVICE_H_
-
-#include <SocketConnection.h>
-#include <SocketService.h>
-
-class PrivacyInfoService {
-private:
- inline static std::string getInterfaceName(void)
- {
- return "PrivacyInfoService";
- }
-
-public:
- static void registerCallbacks(SocketService* pSocketService)
- {
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("addPrivacyInfo"), addPrivacyInfo);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("removePrivacyInfo"), removePrivacyInfo);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("setPrivacySetting"), setPrivacySetting);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("getPrivacyAppPackages"), getPrivacyAppPackages);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("getAppPackagePrivacyInfo"), getAppPackagePrivacyInfo);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("isUserPrompted"), isUserPrompted);
- pSocketService->registerServiceCallback(getInterfaceName(), std::string("setUserPrompted"), setUserPrompted);
- }
-
- static void addPrivacyInfo(SocketConnection* pConnector);
-
- static void removePrivacyInfo(SocketConnection* pConnector);
-
- static void setPrivacySetting(SocketConnection* pConnector);
-
- // input message format
- // interface_name(str) | method_name(str)
- // output message format
- // result (int) | list size (int) | serialized package list (using delimeter)
- static void getPrivacyAppPackages(SocketConnection* pConnector);
-
- static void getAppPackagePrivacyInfo(SocketConnection* pConnector);
-
- static void isUserPrompted(SocketConnection* pConnector);
-
- static void setUserPrompted(SocketConnection* pConnector);
-
-};
+/* + * 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_SERVICE_H_ +#define _PRIVACY_INFO_SERVICE_H_ + +#include <SocketConnection.h> +#include <SocketService.h> + +class PrivacyInfoService { +private: + inline static std::string getInterfaceName(void) + { + return "PrivacyInfoService"; + } + +public: + static void registerCallbacks(SocketService* pSocketService) + { + pSocketService->registerServiceCallback(getInterfaceName(), std::string("addPrivacyInfo"), addPrivacyInfo); + pSocketService->registerServiceCallback(getInterfaceName(), std::string("removePrivacyInfo"), removePrivacyInfo); + pSocketService->registerServiceCallback(getInterfaceName(), std::string("setPrivacySetting"), setPrivacySetting); + pSocketService->registerServiceCallback(getInterfaceName(), std::string("getPrivacyAppPackages"), getPrivacyAppPackages); + pSocketService->registerServiceCallback(getInterfaceName(), std::string("getAppPackagePrivacyInfo"), getAppPackagePrivacyInfo); + pSocketService->registerServiceCallback(getInterfaceName(), std::string("isUserPrompted"), isUserPrompted); + pSocketService->registerServiceCallback(getInterfaceName(), std::string("setUserPrompted"), setUserPrompted); + } + + static void addPrivacyInfo(SocketConnection* pConnector); + + static void removePrivacyInfo(SocketConnection* pConnector); + + static void setPrivacySetting(SocketConnection* pConnector); + + // input message format + // interface_name(str) | method_name(str) + // output message format + // result (int) | list size (int) | serialized package list (using delimeter) + static void getPrivacyAppPackages(SocketConnection* pConnector); + + static void getAppPackagePrivacyInfo(SocketConnection* pConnector); + + static void isUserPrompted(SocketConnection* pConnector); + + static void setUserPrompted(SocketConnection* pConnector); + +}; #endif // _PRIVACY_INFO_SERVICE_H_
\ No newline at end of file diff --git a/server/inc/PrivacyManagerDaemon.h b/server/inc/PrivacyManagerDaemon.h index 0659abb..a646c8b 100644 --- a/server/inc/PrivacyManagerDaemon.h +++ b/server/inc/PrivacyManagerDaemon.h @@ -1,43 +1,43 @@ -/*
- * 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_DAEMON_H_
-#define _PRIVACY_MANAGER_DAEMON_H_
-
-#include <privacy_manager_client_types.h>
-
-class SocketService;
-
-class EXTERN_API PrivacyManagerDaemon
-{
-private:
- static PrivacyManagerDaemon* pInstance;
- SocketService* pSocketService;
-
-private:
- PrivacyManagerDaemon(void);
- ~PrivacyManagerDaemon(void);
-
-
-public:
- static PrivacyManagerDaemon* getInstance(void);
- int initialize(void);
- int start(void);
- int stop(void);
- int shutdown(void);
-};
-
-#endif // _PRIVACY_MANAGER_DAEMON_H_
\ No newline at end of file +/* + * 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_DAEMON_H_ +#define _PRIVACY_MANAGER_DAEMON_H_ + +#include <privacy_manager_client_types.h> + +class SocketService; + +class EXTERN_API PrivacyManagerDaemon +{ +private: + static PrivacyManagerDaemon* pInstance; + SocketService* pSocketService; + +private: + PrivacyManagerDaemon(void); + ~PrivacyManagerDaemon(void); + + +public: + static PrivacyManagerDaemon* getInstance(void); + int initialize(void); + int start(void); + int stop(void); + int shutdown(void); +}; + +#endif // _PRIVACY_MANAGER_DAEMON_H_ diff --git a/server/inc/PrivacyManagerServer.h b/server/inc/PrivacyManagerServer.h index 26c8b4d..3425834 100644 --- a/server/inc/PrivacyManagerServer.h +++ b/server/inc/PrivacyManagerServer.h @@ -1,61 +1,61 @@ -/*
- * 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_SERVER_H_
-#define _PRIVACY_MANAGER_SERVER_H_
-
-#include <string>
-#include <memory>
-#include <list>
-#include <mutex>
-#include <NotificationServer.h>
-
-class NotificationServer;
-
-class PrivacyManagerServer
-{
-private:
- static std::mutex m_singletonMutex;
- static PrivacyManagerServer* m_pInstance;
- NotificationServer m_notificationServer;
-
-private:
- void createDB(void);
-
-public:
-
- explicit PrivacyManagerServer(void);
-
- static PrivacyManagerServer* getInstance(void);
-
- int getPrivacyAppPackages(std::list <std::string>& list);
-
- int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list);
-
- int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled);
-
- int addAppPackagePrivacyInfo(const std::string pkgcId, const std::list < std::string > privilegeList, bool privacyPopupRequired);
-
- int removeAppPackagePrivacyInfo(const std::string pkgId);
-
- int isUserPrompted(const std::string pkgId, bool& isPrompted);
-
- int setUserPrompted(const std::string pkgId, bool prompted);
-
-};
-
-
+/* + * 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_SERVER_H_ +#define _PRIVACY_MANAGER_SERVER_H_ + +#include <string> +#include <memory> +#include <list> +#include <mutex> +#include <NotificationServer.h> + +class NotificationServer; + +class PrivacyManagerServer +{ +private: + static std::mutex m_singletonMutex; + static PrivacyManagerServer* m_pInstance; + NotificationServer m_notificationServer; + +private: + void createDB(void); + +public: + + explicit PrivacyManagerServer(void); + + static PrivacyManagerServer* getInstance(void); + + int getPrivacyAppPackages(std::list <std::string>& list); + + int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > & list); + + int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled); + + int addAppPackagePrivacyInfo(const std::string pkgcId, const std::list < std::string > privilegeList, bool privacyPopupRequired); + + int removeAppPackagePrivacyInfo(const std::string pkgId); + + int isUserPrompted(const std::string pkgId, bool& isPrompted); + + int setUserPrompted(const std::string pkgId, bool prompted); + +}; + + #endif // _PRIVACY_MANAGER_SERVER_H_
\ No newline at end of file diff --git a/server/inc/SocketService.h b/server/inc/SocketService.h index 1615ccd..50fc0e6 100644 --- a/server/inc/SocketService.h +++ b/server/inc/SocketService.h @@ -1,84 +1,84 @@ -/*
- * 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 _SOCKET_SERVICE_H_
-#define _SOCKET_SERVICE_H_
-
-#include <string>
-#include <mutex>
-#include <list>
-#include <map>
-#include <memory>
-#include <pthread.h>
-#include <SocketConnection.h>
-
-typedef void(*socketServiceCallback)(SocketConnection* pConnector);
-
-class SocketService
-{
- struct ConnectionInfo{
- ConnectionInfo(int fd, void* pData) : connFd(fd), pData(pData) {}
- int connFd;
- void* pData;
- };
- class ServiceCallback
- {
- public:
- ServiceCallback(socketServiceCallback callback)
- : serviceCallback(callback)
- {}
- socketServiceCallback serviceCallback;
- };
-
-private:
- static const int MAX_LISTEN;
- static const int TIMEOUT_SEC;
- static const int TIMEOUT_NSEC;
- int m_listenFd;
- int m_signalToClose;
- pthread_t m_mainThread;
-
- typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr;
- //Map for callback methods, key is a method name and value is a callback to method
- typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap;
- //Map for interface methods, key is an interface name and value is a map of available methods with callbacks
- std::map <std::string, ServiceMethodCallbackMap > m_callbackMap;
-
- std::list < int > m_clientSocketList;
- std::mutex m_clientSocketListMutex;
-
-private:
- static void* serverThread(void* );
- static void* connectionThread(void* pData);
- int connectionService(int fd);
- int mainloop(void);
- void closeConnections(void);
-
- void addClientSocket(int clientSocket);
- void removeClientSocket(int clientSocket);
- bool popClientSocket(int* pClientSocket);
-
-public:
- SocketService(void);
- ~SocketService(void);
- int initialize(void);
- int registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod);
- int start(void);
- int stop(void);
- int shutdown(void);
-};
-
+/* + * 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 _SOCKET_SERVICE_H_ +#define _SOCKET_SERVICE_H_ + +#include <string> +#include <mutex> +#include <list> +#include <map> +#include <memory> +#include <pthread.h> +#include <SocketConnection.h> + +typedef void(*socketServiceCallback)(SocketConnection* pConnector); + +class SocketService +{ + struct ConnectionInfo{ + ConnectionInfo(int fd, void* pData) : connFd(fd), pData(pData) {} + int connFd; + void* pData; + }; + class ServiceCallback + { + public: + ServiceCallback(socketServiceCallback callback) + : serviceCallback(callback) + {} + socketServiceCallback serviceCallback; + }; + +private: + static const int MAX_LISTEN; + static const int TIMEOUT_SEC; + static const int TIMEOUT_NSEC; + int m_listenFd; + int m_signalToClose; + pthread_t m_mainThread; + + typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr; + //Map for callback methods, key is a method name and value is a callback to method + typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap; + //Map for interface methods, key is an interface name and value is a map of available methods with callbacks + std::map <std::string, ServiceMethodCallbackMap > m_callbackMap; + + std::list < int > m_clientSocketList; + std::mutex m_clientSocketListMutex; + +private: + static void* serverThread(void* ); + static void* connectionThread(void* pData); + int connectionService(int fd); + int mainloop(void); + void closeConnections(void); + + void addClientSocket(int clientSocket); + void removeClientSocket(int clientSocket); + bool popClientSocket(int* pClientSocket); + +public: + SocketService(void); + ~SocketService(void); + int initialize(void); + int registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod); + int start(void); + int stop(void); + int shutdown(void); +}; + #endif //_SOCKET_SERVICE_H_
\ No newline at end of file diff --git a/server/inc/privacy_manager_daemon.h b/server/inc/privacy_manager_daemon.h index fd52b10..70e39da 100644 --- a/server/inc/privacy_manager_daemon.h +++ b/server/inc/privacy_manager_daemon.h @@ -1,37 +1,37 @@ -/*
- * 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_DAEMON_H__
-#define __PRIVACY_MANAGER_DAEMON_H__
-
-#include <privacy_manager_client_types.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int EXTERN_API privacy_manager_daemon_initialize(void);
-int EXTERN_API privacy_manager_daemon_start(void);
-int EXTERN_API privacy_manager_daemon_stop(void);
-int EXTERN_API privacy_manager_daemon_shutdown(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //__PRIVACY_MANAGER_DAEMON_H__
-
+/* + * 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_DAEMON_H__ +#define __PRIVACY_MANAGER_DAEMON_H__ + +#include <privacy_manager_client_types.h> + +#ifdef __cplusplus +extern "C" { +#endif + +int EXTERN_API privacy_manager_daemon_initialize(void); +int EXTERN_API privacy_manager_daemon_start(void); +int EXTERN_API privacy_manager_daemon_stop(void); +int EXTERN_API privacy_manager_daemon_shutdown(void); + +#ifdef __cplusplus +} +#endif + + +#endif //__PRIVACY_MANAGER_DAEMON_H__ + diff --git a/server/src/NotificationServer.cpp b/server/src/NotificationServer.cpp index c9b5b6d..22e5ee6 100644 --- a/server/src/NotificationServer.cpp +++ b/server/src/NotificationServer.cpp @@ -1,127 +1,119 @@ -/*
- * 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.
- */
-
-
-#include <NotificationServer.h>
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <PrivacyManagerTypes.h>
-#include <Utils.h>
-
-auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;};
-const int MAX_LOCAL_BUF_SIZE = 128;
-
-NotificationServer::NotificationServer(void)
- : m_initialized(false)
- , m_pDBusConnection(NULL)
-{
-
-}
-
-NotificationServer::~NotificationServer(void)
-{
- if (m_pDBusConnection)
- {
- dbus_connection_close(m_pDBusConnection);
- m_pDBusConnection = NULL;
- }
-}
-
-int
-NotificationServer::initialize(void)
-{
- if (m_initialized)
- return PRIV_MGR_ERROR_SUCCESS;
-
- DBusError error;
- dbus_error_init(&error);
-
- m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
- TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message);
-
- dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);
- std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);
-
- snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());
-
- dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);
- TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message);
-
- m_initialized = true;
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId)
-{
- LOGI("enter");
-
- if (!m_initialized)
- return PRIV_MGR_ERROR_INVALID_STATE;
-
- char* pPkgId = const_cast <char*> (pkgId.c_str());
- char* pPrivacyId = const_cast <char*> (privacyId.c_str());
-
- DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str());
- TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");
-
- dbus_bool_t r;
- r = dbus_message_append_args(pMessage,
- DBUS_TYPE_STRING, &pPkgId,
- DBUS_TYPE_STRING, &pPrivacyId,
- DBUS_TYPE_INVALID);
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");
-
- r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
-
- dbus_connection_flush(m_pDBusConnection);
- dbus_message_unref(pMessage);
-
- LOGI("leave");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-NotificationServer::notifyPkgRemoved(const std::string pkgId)
-{
- LOGI("enter");
-
- if (!m_initialized)
- return PRIV_MGR_ERROR_INVALID_STATE;
-
- char* pPkgId = const_cast <char*> (pkgId.c_str());
-
- DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str());
- TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");
-
- dbus_bool_t r;
- r = dbus_message_append_args(pMessage,
- DBUS_TYPE_STRING, &pPkgId,
- DBUS_TYPE_INVALID);
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");
-
- r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);
- TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");
-
- dbus_connection_flush(m_pDBusConnection);
- dbus_message_unref(pMessage);
-
- LOGI("leave");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
\ No newline at end of file +/* + * 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. + */ + + +#include <NotificationServer.h> +#include <dbus/dbus.h> +#include <dbus/dbus-glib-lowlevel.h> +#include <PrivacyManagerTypes.h> +#include <Utils.h> + +auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;}; +const int MAX_LOCAL_BUF_SIZE = 128; + +NotificationServer::NotificationServer(void) + : m_initialized(false) + , m_pDBusConnection(NULL) +{ + +} + +NotificationServer::~NotificationServer(void) +{ + if (m_pDBusConnection) + { + dbus_connection_close(m_pDBusConnection); + m_pDBusConnection = NULL; + } +} + +int +NotificationServer::initialize(void) +{ + if (m_initialized) + return PRIV_MGR_ERROR_SUCCESS; + + DBusError error; + dbus_error_init(&error); + + m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error); + TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message); + + dbus_connection_setup_with_g_main(m_pDBusConnection, NULL); + std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]); + + snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str()); + + dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error); + TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message); + + m_initialized = true; + return PRIV_MGR_ERROR_SUCCESS; +} + +int +NotificationServer::notifySettingChanged(const std::string pkgId, const std::string privacyId) +{ + if (!m_initialized) + return PRIV_MGR_ERROR_INVALID_STATE; + + char* pPkgId = const_cast <char*> (pkgId.c_str()); + char* pPrivacyId = const_cast <char*> (privacyId.c_str()); + + DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_SETTING_CHANGED.c_str()); + TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal"); + + dbus_bool_t r; + r = dbus_message_append_args(pMessage, + DBUS_TYPE_STRING, &pPkgId, + DBUS_TYPE_STRING, &pPrivacyId, + DBUS_TYPE_INVALID); + TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args"); + + r = dbus_connection_send(m_pDBusConnection, pMessage, NULL); + TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send"); + + dbus_connection_flush(m_pDBusConnection); + dbus_message_unref(pMessage); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +NotificationServer::notifyPkgRemoved(const std::string pkgId) +{ + if (!m_initialized) + return PRIV_MGR_ERROR_INVALID_STATE; + + char* pPkgId = const_cast <char*> (pkgId.c_str()); + + DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_PKG_REMOVED.c_str()); + TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal"); + + dbus_bool_t r; + r = dbus_message_append_args(pMessage, + DBUS_TYPE_STRING, &pPkgId, + DBUS_TYPE_INVALID); + TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args"); + + r = dbus_connection_send(m_pDBusConnection, pMessage, NULL); + TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send"); + + dbus_connection_flush(m_pDBusConnection); + dbus_message_unref(pMessage); + + return PRIV_MGR_ERROR_SUCCESS; +} diff --git a/server/src/PrivacyManagerDaemon.cpp b/server/src/PrivacyManagerDaemon.cpp index 61c2df4..bf84448 100644 --- a/server/src/PrivacyManagerDaemon.cpp +++ b/server/src/PrivacyManagerDaemon.cpp @@ -1,80 +1,80 @@ -/*
- * 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 <string>
-#include <PrivacyManagerDaemon.h>
-#include <PrivacyInfoService.h>
-#include <PrivacyManagerServer.h>
-#include <SocketService.h>
-
-PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL;
-
-PrivacyManagerDaemon::PrivacyManagerDaemon(void)
- : pSocketService(NULL)
-{
-
-}
-
-PrivacyManagerDaemon::~PrivacyManagerDaemon(void)
-{
-
-}
-
-PrivacyManagerDaemon*
-PrivacyManagerDaemon::getInstance(void)
-{
- if (pInstance == NULL)
- pInstance = new PrivacyManagerDaemon();
- PrivacyManagerServer::getInstance();
- return pInstance;
-}
-
-int
-PrivacyManagerDaemon::initialize(void)
-{
- if (pSocketService == NULL)
- pSocketService = new SocketService();
-
- pSocketService->initialize();
-
- PrivacyInfoService::registerCallbacks(pSocketService);
-
- return 0;
-}
-
-int
-PrivacyManagerDaemon::start(void)
-{
- if (pSocketService == NULL)
- return -1;
- return pSocketService->start();
-
- return 0;
-}
-
-int
-PrivacyManagerDaemon::stop(void)
-{
- pSocketService->stop();
- return 0;
-}
-
-int
-PrivacyManagerDaemon::shutdown(void)
-{
- pSocketService->shutdown();
- return 0;
-}
+/* + * 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 <string> +#include <PrivacyManagerDaemon.h> +#include <PrivacyInfoService.h> +#include <PrivacyManagerServer.h> +#include <SocketService.h> + +PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL; + +PrivacyManagerDaemon::PrivacyManagerDaemon(void) + : pSocketService(NULL) +{ + +} + +PrivacyManagerDaemon::~PrivacyManagerDaemon(void) +{ + +} + +PrivacyManagerDaemon* +PrivacyManagerDaemon::getInstance(void) +{ + if (pInstance == NULL) + pInstance = new PrivacyManagerDaemon(); + PrivacyManagerServer::getInstance(); + return pInstance; +} + +int +PrivacyManagerDaemon::initialize(void) +{ + if (pSocketService == NULL) + pSocketService = new SocketService(); + + pSocketService->initialize(); + + PrivacyInfoService::registerCallbacks(pSocketService); + + return 0; +} + +int +PrivacyManagerDaemon::start(void) +{ + if (pSocketService == NULL) + return -1; + return pSocketService->start(); + + return 0; +} + +int +PrivacyManagerDaemon::stop(void) +{ + pSocketService->stop(); + return 0; +} + +int +PrivacyManagerDaemon::shutdown(void) +{ + pSocketService->shutdown(); + return 0; +} diff --git a/server/src/PrivacyManagerServer.cpp b/server/src/PrivacyManagerServer.cpp index 3887f88..b1b50f2 100644 --- a/server/src/PrivacyManagerServer.cpp +++ b/server/src/PrivacyManagerServer.cpp @@ -1,107 +1,106 @@ -/*
- * 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 <sstream>
-#include <dlog.h>
-#include <Utils.h>
-#include <PrivacyManagerServer.h>
-#include <PrivacyManagerTypes.h>
-#include <PrivacyDb.h>
-
-std::mutex PrivacyManagerServer::m_singletonMutex;
-PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL;
-
-void
-PrivacyManagerServer::createDB(void)
-{
-
-}
-
-int
-PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled)
-{
- int res = PrivacyDb::getInstance()->setPrivacySetting(pkgId, privacyId, enabled);
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::setPrivacySetting : %d", res);
-
- res = m_notificationServer.notifySettingChanged(pkgId, privacyId);
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifySettingChanged : %d", res);
-
- return res;
-}
-
-int
-PrivacyManagerServer::getPrivacyAppPackages(std::list <std::string>& list)
-{
- return PrivacyDb::getInstance()->getPrivacyAppPackages(list);
-}
-
-int
-PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList)
-{
- return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, privacyInfoList);
-}
-
-
-int
-PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList, bool privacyPopupRequired)
-{
- return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privilegeList, privacyPopupRequired);
-}
-
-int
-PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId)
-{
- int res = PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId);
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::removeAppPackagePrivacyInfo : %d", res);
-
- res = m_notificationServer.notifyPkgRemoved(pkgId);
- TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifyPkgRemoved : %d", res);
-
- return res;
-}
-
-int
-PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted)
-{
- return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted);
-}
-
-int
-PrivacyManagerServer::setUserPrompted(const std::string pkgId, bool prompted)
-{
- return PrivacyDb::getInstance()->setUserPrompted(pkgId, prompted);
-}
-
-PrivacyManagerServer::PrivacyManagerServer(void)
-{
-
-}
-
-PrivacyManagerServer*
-PrivacyManagerServer::getInstance(void)
-{
- LOGI("enter");
- std::lock_guard < std::mutex > guard(m_singletonMutex);
-
- if (m_pInstance == NULL)
- {
- m_pInstance = new PrivacyManagerServer();
-
- m_pInstance->m_notificationServer.initialize();
- }
- LOGI("leave");
- return m_pInstance;
-}
\ No newline at end of file +/* + * 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 <sstream> +#include <dlog.h> +#include <Utils.h> +#include <PrivacyManagerServer.h> +#include <PrivacyManagerTypes.h> +#include <PrivacyDb.h> + +std::mutex PrivacyManagerServer::m_singletonMutex; +PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL; + +void +PrivacyManagerServer::createDB(void) +{ + +} + +int +PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled) +{ + int res = PrivacyDb::getInstance()->setPrivacySetting(pkgId, privacyId, enabled); + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::setPrivacySetting : %d", res); + + res = m_notificationServer.notifySettingChanged(pkgId, privacyId); + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifySettingChanged : %d", res); + + return res; +} + +int +PrivacyManagerServer::getPrivacyAppPackages(std::list <std::string>& list) +{ + return PrivacyDb::getInstance()->getPrivacyAppPackages(list); +} + +int +PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >& privacyInfoList) +{ + return PrivacyDb::getInstance()->getAppPackagePrivacyInfo(pkgId, privacyInfoList); +} + + +int +PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList, bool privacyPopupRequired) +{ + return PrivacyDb::getInstance()->addAppPackagePrivacyInfo(pkgId, privilegeList, privacyPopupRequired); +} + +int +PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId) +{ + int res = PrivacyDb::getInstance()->removeAppPackagePrivacyInfo(pkgId); + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "privacyDb::removeAppPackagePrivacyInfo : %d", res); + + res = m_notificationServer.notifyPkgRemoved(pkgId); + TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "NotificationServer::notifyPkgRemoved : %d", res); + + return res; +} + +int +PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted) +{ + return PrivacyDb::getInstance()->isUserPrompted(pkgId, isPrompted); +} + +int +PrivacyManagerServer::setUserPrompted(const std::string pkgId, bool prompted) +{ + return PrivacyDb::getInstance()->setUserPrompted(pkgId, prompted); +} + +PrivacyManagerServer::PrivacyManagerServer(void) +{ + +} + +PrivacyManagerServer* +PrivacyManagerServer::getInstance(void) +{ + std::lock_guard < std::mutex > guard(m_singletonMutex); + + if (m_pInstance == NULL) + { + m_pInstance = new PrivacyManagerServer(); + + m_pInstance->m_notificationServer.initialize(); + } + + return m_pInstance; +} diff --git a/server/src/SocketService.cpp b/server/src/SocketService.cpp index 3019da0..296525e 100644 --- a/server/src/SocketService.cpp +++ b/server/src/SocketService.cpp @@ -1,374 +1,374 @@ -/*
- * 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 <errno.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/un.h>
-#include <sys/signalfd.h>
-#include <sys/select.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <memory>
-#include <dlog.h>
-#include <PrivacyManagerTypes.h>
-#include <Utils.h>
-#include "SocketService.h"
-#include "SocketConnection.h"
-
-const int SocketService::MAX_LISTEN = 5;
-
-SocketService::SocketService(void)
- : m_listenFd(-1)
- , m_signalToClose(-1)
- , m_mainThread(-1)
-{
-
-}
-
-SocketService::~SocketService(void)
-{
-
-}
-
-int
-SocketService::initialize(void)
-{
- LOGI("SocketService initializing");
-
- m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
- TryReturn( m_listenFd != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "socket : %s", strerror(errno));
-
- int flags = -1;
- int res;
- if ( (flags = fcntl(m_listenFd, F_GETFL, 0)) == -1)
- flags = 0;
- res = fcntl(m_listenFd, F_SETFL, flags | O_NONBLOCK);
- TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror(errno));
-
- sockaddr_un server_address;
- bzero(&server_address, sizeof(server_address));
- server_address.sun_family = AF_UNIX;
- strcpy(server_address.sun_path, SERVER_ADDRESS.c_str());
- unlink(server_address.sun_path);
-
- mode_t socket_umask, original_umask;
- socket_umask = 0;
- original_umask = umask(socket_umask);
-
- res = bind(m_listenFd, (struct sockaddr*)&server_address, SUN_LEN(&server_address));
- TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "bind : %s", strerror(errno));
-
- umask(original_umask);
-
- LOGI("SocketService initialized");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-SocketService::start(void)
-{
- LOGI("SocketService starting");
-
- sigset_t sigset;
- sigemptyset(&sigset);
-// if ( sigaddset(&sigset, m_signalToClose) == -1 )
-// {
-// LOGE("Failed to sigaddset : %s", strerror(errno));
-// return -1;
-// }
-
- int res = 0;
- res = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
- TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno));
-
- pthread_t mainThread;
- res = pthread_create(&mainThread, NULL, &serverThread, this);
- TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res));
-
- m_mainThread = mainThread;
-
- LOGI("SocketService started");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-void*
-SocketService::serverThread(void* pData)
-{
- pthread_detach(pthread_self());
- SocketService &t = *static_cast< SocketService* > (pData);
- LOGI("Running main thread");
- int ret = t.mainloop();
- if (ret < 0)
- {
- return (void*) 1;
- }
- return (void*) 0;
-}
-
-int
-SocketService::mainloop(void)
-{
- if( listen(m_listenFd, MAX_LISTEN) == -1 ){
- LOGE("listen : %s", strerror(errno));
- return PRIV_MGR_ERROR_IPC_ERROR;
- }
-
- //Settings to catch closing signal in select
- int signal_fd;
- sigset_t sigset;
- int res;
- res = sigemptyset(&sigset);
- TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror(errno));
-
-// if( sigaddset(&sigset, m_signalToClose) == -1) {
-// LOGE("sigaddset : %s", strerror(errno));
-// return -1;
-// }
- signal_fd = signalfd(-1, &sigset, 0);
- TryReturn( signal_fd >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror(errno));
-
- //Setting descriptors for pselect
- fd_set allset, rset;
- int maxfd;
- FD_ZERO(&allset);
- FD_SET(m_listenFd, &allset);
- FD_SET(signal_fd, &allset);
- maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd);
- ++maxfd;
- //this will block SIGPIPE for this thread and every thread created in it
- //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket
- //instead of signal we want to receive error from write - hence blocking SIGPIPE
- sigset_t set;
- sigemptyset(&set);
- sigaddset(&set, SIGPIPE);
- pthread_sigmask(SIG_BLOCK, &set, NULL);
-
- while(1)
- {
- rset = allset;
- if(pselect(maxfd, &rset, NULL, NULL, NULL, NULL) == -1)
- {
- closeConnections();
- LOGE("pselect()");
- return PRIV_MGR_ERROR_SYSTEM_ERROR;
- }
-
- if(FD_ISSET(signal_fd, &rset))
- {
- LOGI("Got signal to close");
- signalfd_siginfo siginfo;
- ssize_t res;
- res = read(signal_fd, &siginfo, sizeof(siginfo));
- TryReturn( res > 0, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror(errno));
- TryReturn( (size_t)res == sizeof(siginfo), PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "couldn't read whole siginfo");
-
- if((int)siginfo.ssi_signo == m_signalToClose)
- {
- LOGI("Server thread got signal to close");
- closeConnections();
- return PRIV_MGR_ERROR_SUCCESS;
- }
- else
- {
- LOGI("Got not handled signal");
- }
- }
- if(FD_ISSET(m_listenFd, &rset))
- {
- int clientFd;
- clientFd = accept(m_listenFd, NULL, NULL);
- TryReturn( clientFd != -1, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror(errno));
-
- LOGI("Got incoming connection");
- ConnectionInfo * connection = new ConnectionInfo(clientFd, (void *)this);
- int res;
- pthread_t client_thread;
- if((res = pthread_create(&client_thread, NULL, &connectionThread, connection)) < 0)
- {
- delete connection;
- errno = res;
- closeConnections();
- LOGE("pthread_create()");
- return PRIV_MGR_ERROR_SYSTEM_ERROR;
- }
- addClientSocket(clientFd);
- }
- }
-}
-
-void*
-SocketService::connectionThread(void* pData)
-{
- pthread_detach(pthread_self());
- std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData));
- SocketService &t = *static_cast<SocketService *>(connectionInfo->pData);
- LOGI("Starting connection thread");
- int ret = t.connectionService(connectionInfo->connFd);
- if (ret < 0)
- {
- LOGE("Connection thread error");
- t.removeClientSocket(connectionInfo->connFd);
- close(connectionInfo->connFd);
- return (void*)1;
- }
- LOGI("Client serviced");
- return (void*)0;
-}
-
-int
-SocketService::connectionService(int fd)
-{
-
- SocketConnection connector = SocketConnection(fd);
- std::string interfaceName, methodName;
-
- int res = connector.read(&interfaceName, &methodName);
- if (res != PRIV_MGR_ERROR_SUCCESS)
- {
- LOGE("read : %d", res);
- return res;
- }
-
- LOGD("Got interface : %s", interfaceName.c_str());
- LOGD("Got method : %s", methodName.c_str());
-
- if( m_callbackMap.find(interfaceName) == m_callbackMap.end())
- {
- LOGE("Unknown interface : %s", interfaceName.c_str());
- return PRIV_MGR_ERROR_NO_DATA;
- }
-
- if(m_callbackMap[interfaceName].find(methodName) == m_callbackMap[interfaceName].end())
- {
- LOGE("Unknown method : %s", methodName.c_str());
- return PRIV_MGR_ERROR_NO_DATA;
- }
-
-// if(m_callbackMap[interfaceName][methodName]->securityCallback != NULL){
-// if(!m_callbackMap[interfaceName][methodName]->securityCallback(fd)){
-// LOGE("Security check returned false");
-// return -1;
-// }
-// }
-
- LOGI("Calling service");
- m_callbackMap[interfaceName][methodName]->serviceCallback(&connector);
-
- LOGI("Removing client");
- removeClientSocket(fd);
- close(fd);
-
- LOGI("Call served");
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-SocketService::stop(void)
-{
- LOGI("Stopping");
- if(close(m_listenFd) == -1)
- if(errno != ENOTCONN)
- {
- LOGE("close() : %s", strerror(errno));
- return PRIV_MGR_ERROR_IPC_ERROR;
- }
-
- int returned_value;
- if((returned_value = pthread_kill(m_mainThread, m_signalToClose)) < 0)
- {
- errno = returned_value;
- LOGE("pthread_kill() : %s", strerror(errno));
- return PRIV_MGR_ERROR_IPC_ERROR;
- }
- pthread_join(m_mainThread, NULL);
-
- LOGI("Stopped");
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-SocketService::shutdown(void)
-{
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-int
-SocketService::registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod)
-{
- if(NULL == callbackMethod)
- {
- LOGE("Null callback");
- return PRIV_MGR_ERROR_INVALID_PARAMETER;
- }
- if(interfaceName.empty() || methodName.empty())
- {
- LOGE("Interface and method name cannot be empty");
- return PRIV_MGR_ERROR_INVALID_PARAMETER;
- }
-
- auto serviceCallbackPtr = std::make_shared<ServiceCallback>(ServiceCallback(callbackMethod));
- m_callbackMap[interfaceName][methodName] = serviceCallbackPtr;
-
- return PRIV_MGR_ERROR_SUCCESS;
-}
-
-void
-SocketService::addClientSocket(int clientSocket)
-{
- std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
- m_clientSocketList.push_back(clientSocket);
-}
-
-void
-SocketService::removeClientSocket(int clientSocket)
-{
- std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
- m_clientSocketList.remove(clientSocket);
-}
-
-bool
-SocketService::popClientSocket(int * pClientSocket)
-{
- std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
- if(m_clientSocketList.empty())
- return false;
- *pClientSocket = m_clientSocketList.front();
- m_clientSocketList.pop_front();
- return true;
-}
-
-
-void
-SocketService::closeConnections(void)
-{
- int clientSocket;
- LOGI("Closing client sockets");
- while(popClientSocket(&clientSocket))
- {
- if(close(clientSocket) == -1)
- {
- LOGE("close() : %s", strerror(errno));
- }
- }
-
- LOGI("Connections closed");
-}
+/* + * 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 <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/signalfd.h> +#include <sys/select.h> +#include <sys/stat.h> +#include <signal.h> +#include <unistd.h> +#include <fcntl.h> +#include <memory> +#include <dlog.h> +#include <PrivacyManagerTypes.h> +#include <Utils.h> +#include "SocketService.h" +#include "SocketConnection.h" + +const int SocketService::MAX_LISTEN = 5; + +SocketService::SocketService(void) + : m_listenFd(-1) + , m_signalToClose(-1) + , m_mainThread(-1) +{ + +} + +SocketService::~SocketService(void) +{ + +} + +int +SocketService::initialize(void) +{ + LOGI("SocketService initializing"); + + m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0); + TryReturn( m_listenFd != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "socket : %s", strerror(errno)); + + int flags = -1; + int res; + if ( (flags = fcntl(m_listenFd, F_GETFL, 0)) == -1) + flags = 0; + res = fcntl(m_listenFd, F_SETFL, flags | O_NONBLOCK); + TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror(errno)); + + sockaddr_un server_address; + bzero(&server_address, sizeof(server_address)); + server_address.sun_family = AF_UNIX; + strcpy(server_address.sun_path, SERVER_ADDRESS.c_str()); + unlink(server_address.sun_path); + + mode_t socket_umask, original_umask; + socket_umask = 0; + original_umask = umask(socket_umask); + + res = bind(m_listenFd, (struct sockaddr*)&server_address, SUN_LEN(&server_address)); + TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "bind : %s", strerror(errno)); + + umask(original_umask); + + LOGI("SocketService initialized"); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +SocketService::start(void) +{ + LOGI("SocketService starting"); + + sigset_t sigset; + sigemptyset(&sigset); +// if ( sigaddset(&sigset, m_signalToClose) == -1 ) +// { +// LOGE("Failed to sigaddset : %s", strerror(errno)); +// return -1; +// } + + int res = 0; + res = pthread_sigmask(SIG_BLOCK, &sigset, NULL); + TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno)); + + pthread_t mainThread; + res = pthread_create(&mainThread, NULL, &serverThread, this); + TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res)); + + m_mainThread = mainThread; + + LOGI("SocketService started"); + + return PRIV_MGR_ERROR_SUCCESS; +} + +void* +SocketService::serverThread(void* pData) +{ + pthread_detach(pthread_self()); + SocketService &t = *static_cast< SocketService* > (pData); + LOGI("Running main thread"); + int ret = t.mainloop(); + if (ret < 0) + { + return (void*) 1; + } + return (void*) 0; +} + +int +SocketService::mainloop(void) +{ + if( listen(m_listenFd, MAX_LISTEN) == -1 ){ + LOGE("listen : %s", strerror(errno)); + return PRIV_MGR_ERROR_IPC_ERROR; + } + + //Settings to catch closing signal in select + int signal_fd; + sigset_t sigset; + int res; + res = sigemptyset(&sigset); + TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror(errno)); + +// if( sigaddset(&sigset, m_signalToClose) == -1) { +// LOGE("sigaddset : %s", strerror(errno)); +// return -1; +// } + signal_fd = signalfd(-1, &sigset, 0); + TryReturn( signal_fd >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror(errno)); + + //Setting descriptors for pselect + fd_set allset, rset; + int maxfd; + FD_ZERO(&allset); + FD_SET(m_listenFd, &allset); + FD_SET(signal_fd, &allset); + maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd); + ++maxfd; + //this will block SIGPIPE for this thread and every thread created in it + //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket + //instead of signal we want to receive error from write - hence blocking SIGPIPE + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGPIPE); + pthread_sigmask(SIG_BLOCK, &set, NULL); + + while(1) + { + rset = allset; + if(pselect(maxfd, &rset, NULL, NULL, NULL, NULL) == -1) + { + closeConnections(); + LOGE("pselect()"); + return PRIV_MGR_ERROR_SYSTEM_ERROR; + } + + if(FD_ISSET(signal_fd, &rset)) + { + LOGI("Got signal to close"); + signalfd_siginfo siginfo; + ssize_t res; + res = read(signal_fd, &siginfo, sizeof(siginfo)); + TryReturn( res > 0, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror(errno)); + TryReturn( (size_t)res == sizeof(siginfo), PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "couldn't read whole siginfo"); + + if((int)siginfo.ssi_signo == m_signalToClose) + { + LOGI("Server thread got signal to close"); + closeConnections(); + return PRIV_MGR_ERROR_SUCCESS; + } + else + { + LOGI("Got not handled signal"); + } + } + if(FD_ISSET(m_listenFd, &rset)) + { + int clientFd; + clientFd = accept(m_listenFd, NULL, NULL); + TryReturn( clientFd != -1, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror(errno)); + + LOGI("Got incoming connection"); + ConnectionInfo * connection = new ConnectionInfo(clientFd, (void *)this); + int res; + pthread_t client_thread; + if((res = pthread_create(&client_thread, NULL, &connectionThread, connection)) < 0) + { + delete connection; + errno = res; + closeConnections(); + LOGE("pthread_create()"); + return PRIV_MGR_ERROR_SYSTEM_ERROR; + } + addClientSocket(clientFd); + } + } +} + +void* +SocketService::connectionThread(void* pData) +{ + pthread_detach(pthread_self()); + std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData)); + SocketService &t = *static_cast<SocketService *>(connectionInfo->pData); + LOGI("Starting connection thread"); + int ret = t.connectionService(connectionInfo->connFd); + if (ret < 0) + { + LOGE("Connection thread error"); + t.removeClientSocket(connectionInfo->connFd); + close(connectionInfo->connFd); + return (void*)1; + } + LOGI("Client serviced"); + return (void*)0; +} + +int +SocketService::connectionService(int fd) +{ + + SocketConnection connector = SocketConnection(fd); + std::string interfaceName, methodName; + + int res = connector.read(&interfaceName, &methodName); + if (res != PRIV_MGR_ERROR_SUCCESS) + { + LOGE("read : %d", res); + return res; + } + + LOGD("Got interface : %s", interfaceName.c_str()); + LOGD("Got method : %s", methodName.c_str()); + + if( m_callbackMap.find(interfaceName) == m_callbackMap.end()) + { + LOGE("Unknown interface : %s", interfaceName.c_str()); + return PRIV_MGR_ERROR_NO_DATA; + } + + if(m_callbackMap[interfaceName].find(methodName) == m_callbackMap[interfaceName].end()) + { + LOGE("Unknown method : %s", methodName.c_str()); + return PRIV_MGR_ERROR_NO_DATA; + } + +// if(m_callbackMap[interfaceName][methodName]->securityCallback != NULL){ +// if(!m_callbackMap[interfaceName][methodName]->securityCallback(fd)){ +// LOGE("Security check returned false"); +// return -1; +// } +// } + + LOGI("Calling service"); + m_callbackMap[interfaceName][methodName]->serviceCallback(&connector); + + LOGI("Removing client"); + removeClientSocket(fd); + close(fd); + + LOGI("Call served"); + + return PRIV_MGR_ERROR_SUCCESS; +} + +int +SocketService::stop(void) +{ + LOGI("Stopping"); + if(close(m_listenFd) == -1) + if(errno != ENOTCONN) + { + LOGE("close() : %s", strerror(errno)); + return PRIV_MGR_ERROR_IPC_ERROR; + } + + int returned_value; + if((returned_value = pthread_kill(m_mainThread, m_signalToClose)) < 0) + { + errno = returned_value; + LOGE("pthread_kill() : %s", strerror(errno)); + return PRIV_MGR_ERROR_IPC_ERROR; + } + pthread_join(m_mainThread, NULL); + + LOGI("Stopped"); + return PRIV_MGR_ERROR_SUCCESS; +} + +int +SocketService::shutdown(void) +{ + return PRIV_MGR_ERROR_SUCCESS; +} + +int +SocketService::registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod) +{ + if(NULL == callbackMethod) + { + LOGE("Null callback"); + return PRIV_MGR_ERROR_INVALID_PARAMETER; + } + if(interfaceName.empty() || methodName.empty()) + { + LOGE("Interface and method name cannot be empty"); + return PRIV_MGR_ERROR_INVALID_PARAMETER; + } + + auto serviceCallbackPtr = std::make_shared<ServiceCallback>(ServiceCallback(callbackMethod)); + m_callbackMap[interfaceName][methodName] = serviceCallbackPtr; + + return PRIV_MGR_ERROR_SUCCESS; +} + +void +SocketService::addClientSocket(int clientSocket) +{ + std::lock_guard<std::mutex> guard(m_clientSocketListMutex); + m_clientSocketList.push_back(clientSocket); +} + +void +SocketService::removeClientSocket(int clientSocket) +{ + std::lock_guard<std::mutex> guard(m_clientSocketListMutex); + m_clientSocketList.remove(clientSocket); +} + +bool +SocketService::popClientSocket(int * pClientSocket) +{ + std::lock_guard<std::mutex> guard(m_clientSocketListMutex); + if(m_clientSocketList.empty()) + return false; + *pClientSocket = m_clientSocketList.front(); + m_clientSocketList.pop_front(); + return true; +} + + +void +SocketService::closeConnections(void) +{ + int clientSocket; + LOGI("Closing client sockets"); + while(popClientSocket(&clientSocket)) + { + if(close(clientSocket) == -1) + { + LOGE("close() : %s", strerror(errno)); + } + } + + LOGI("Connections closed"); +} diff --git a/server/src/main.cpp b/server/src/main.cpp index f2fee09..2ae8169 100644 --- a/server/src/main.cpp +++ b/server/src/main.cpp @@ -1,37 +1,37 @@ -/*
- * 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 <PrivacyManagerDaemon.h>
-#include <glib.h>
-
-int
-main(int argc, char* argv[])
-{
- PrivacyManagerDaemon* pDaemon = PrivacyManagerDaemon::getInstance();
-
- pDaemon->inialize();
- pDaemon->start();
-
- GMainLoop* pLoop;
- pLoop = g_main_new(TRUE);
-
- g_main_loop_run(pLoop);
-
- pDaemon->stop();
- pDaemon->shutdown();
-
- return 0;
+/* + * 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 <PrivacyManagerDaemon.h> +#include <glib.h> + +int +main(int argc, char* argv[]) +{ + PrivacyManagerDaemon* pDaemon = PrivacyManagerDaemon::getInstance(); + + pDaemon->inialize(); + pDaemon->start(); + + GMainLoop* pLoop; + pLoop = g_main_new(TRUE); + + g_main_loop_run(pLoop); + + pDaemon->stop(); + pDaemon->shutdown(); + + return 0; }
\ No newline at end of file diff --git a/server/src/privacy_manager_daemon.cpp b/server/src/privacy_manager_daemon.cpp index 1cfb874..098f414 100644 --- a/server/src/privacy_manager_daemon.cpp +++ b/server/src/privacy_manager_daemon.cpp @@ -1,46 +1,46 @@ -/*
- * 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 <privacy_manager_daemon.h>
-#include <PrivacyManagerDaemon.h>
-
-int privacy_manager_daemon_initialize(void)
-{
- PrivacyManagerDaemon* pPrivacyDaemon = PrivacyManagerDaemon::getInstance();
-
- return pPrivacyDaemon->initialize();
-}
-
-int privacy_manager_daemon_start(void)
-{
- PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();
-
- return pInstance->start();
-}
-
-int privacy_manager_daemon_stop(void)
-{
- PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();
-
- return pInstance->stop();
-}
-
-int privacy_manager_daemon_shutdown(void)
-{
- PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance();
-
- return pInstance->shutdown();
-}
+/* + * 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 <privacy_manager_daemon.h> +#include <PrivacyManagerDaemon.h> + +int privacy_manager_daemon_initialize(void) +{ + PrivacyManagerDaemon* pPrivacyDaemon = PrivacyManagerDaemon::getInstance(); + + return pPrivacyDaemon->initialize(); +} + +int privacy_manager_daemon_start(void) +{ + PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance(); + + return pInstance->start(); +} + +int privacy_manager_daemon_stop(void) +{ + PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance(); + + return pInstance->stop(); +} + +int privacy_manager_daemon_shutdown(void) +{ + PrivacyManagerDaemon* pInstance = PrivacyManagerDaemon::getInstance(); + + return pInstance->shutdown(); +} diff --git a/server/src/service/PrivacyInfoService.cpp b/server/src/service/PrivacyInfoService.cpp index a8bbbe6..bffda01 100644 --- a/server/src/service/PrivacyInfoService.cpp +++ b/server/src/service/PrivacyInfoService.cpp @@ -1,135 +1,120 @@ -/*
- * 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.
- */
-
-#include <PrivacyInfoService.h>
-#include <PrivacyManagerServer.h>
-#include <dlog.h>
-#include <Utils.h>
-
-void
-PrivacyInfoService::addPrivacyInfo(SocketConnection* pConnector)
-{
- LOGI("enter");
-
- std::string pkgId;
- std::list < std::string > list;
- bool privacyPopupRequired = true;
- pConnector->read(&pkgId, &list, &privacyPopupRequired);
-
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
- int result = pPrivacyManagerServer->addAppPackagePrivacyInfo(pkgId, list, privacyPopupRequired);
-
- pConnector->write(result);
-}
-
-void
-PrivacyInfoService::removePrivacyInfo(SocketConnection* pConnector)
-{
- LOGI("enter");
-
- std::string pkgId;
- pConnector->read(&pkgId);
-
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
- int res = pPrivacyManagerServer->removeAppPackagePrivacyInfo(pkgId);
-
- pConnector->write(res);
-}
-
-void
-PrivacyInfoService::setPrivacySetting(SocketConnection* pConnector)
-{
- LOGI("enter");
-
- std::string pkgId;
- std::string privacyId;
- bool enabled = false;
- pConnector->read(&pkgId, &privacyId, &enabled);
-
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
- int result = pPrivacyManagerServer->setPrivacySetting(pkgId, privacyId, enabled);
-
- pConnector->write(result);
-}
-
-void
-PrivacyInfoService::getPrivacyAppPackages(SocketConnection* pConnector)
-{
- LOGI("enter");
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
- std::list <std::string> list;
- int result = pPrivacyManagerServer->getPrivacyAppPackages(list);
-
- pConnector->write( (unsigned int) result);
- pConnector->write( (unsigned int) list.size());
- pConnector->write(list);
-}
-
-void
-PrivacyInfoService::getAppPackagePrivacyInfo(SocketConnection* pConnector)
-{
- LOGI("enter");
-
- std::string pkgId;
-
- pConnector->read(&pkgId);
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
-
-
- std::list < std::pair < std::string, bool > > infoList;
-
- int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, infoList);
-
- pConnector->write( res );
- pConnector->write( infoList );
-}
-
-void
-PrivacyInfoService::isUserPrompted(SocketConnection* pConnector)
-{
- LOGI("enter");
-
- std::string pkgId;
-
- pConnector->read(&pkgId);
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
-
- bool isPrompted;
- int res = pPrivacyManagerServer->isUserPrompted(pkgId, isPrompted);
-
- pConnector->write( res );
- pConnector->write( isPrompted );
-
- LOGI("leave");
-}
-
-void
-PrivacyInfoService::setUserPrompted(SocketConnection* pConnector)
-{
- LOGI("enter");
-
- std::string pkgId;
- bool prompted = false;
-
- pConnector->read(&pkgId, &prompted);
- PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();
-
- int res = pPrivacyManagerServer->setUserPrompted(pkgId, prompted);
- LOGI("write");
- pConnector->write( res );
-
- LOGI("leave");
-}
\ No newline at end of file +/* + * 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. + */ + +#include <PrivacyInfoService.h> +#include <PrivacyManagerServer.h> +#include <dlog.h> +#include <Utils.h> + +void +PrivacyInfoService::addPrivacyInfo(SocketConnection* pConnector) +{ + std::string pkgId; + std::list < std::string > list; + bool privacyPopupRequired = true; + pConnector->read(&pkgId, &list, &privacyPopupRequired); + + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + int result = pPrivacyManagerServer->addAppPackagePrivacyInfo(pkgId, list, privacyPopupRequired); + + pConnector->write(result); +} + +void +PrivacyInfoService::removePrivacyInfo(SocketConnection* pConnector) +{ + std::string pkgId; + pConnector->read(&pkgId); + + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + int res = pPrivacyManagerServer->removeAppPackagePrivacyInfo(pkgId); + + pConnector->write(res); +} + +void +PrivacyInfoService::setPrivacySetting(SocketConnection* pConnector) +{ + std::string pkgId; + std::string privacyId; + bool enabled = false; + pConnector->read(&pkgId, &privacyId, &enabled); + + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + int result = pPrivacyManagerServer->setPrivacySetting(pkgId, privacyId, enabled); + + pConnector->write(result); +} + +void +PrivacyInfoService::getPrivacyAppPackages(SocketConnection* pConnector) +{ + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + std::list <std::string> list; + int result = pPrivacyManagerServer->getPrivacyAppPackages(list); + + pConnector->write( (unsigned int) result); + pConnector->write( (unsigned int) list.size()); + pConnector->write(list); +} + +void +PrivacyInfoService::getAppPackagePrivacyInfo(SocketConnection* pConnector) +{ + std::string pkgId; + + pConnector->read(&pkgId); + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + + + std::list < std::pair < std::string, bool > > infoList; + + int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, infoList); + + pConnector->write( res ); + pConnector->write( infoList ); +} + +void +PrivacyInfoService::isUserPrompted(SocketConnection* pConnector) +{ + std::string pkgId; + + pConnector->read(&pkgId); + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + + bool isPrompted; + int res = pPrivacyManagerServer->isUserPrompted(pkgId, isPrompted); + + pConnector->write( res ); + pConnector->write( isPrompted ); + +} + +void +PrivacyInfoService::setUserPrompted(SocketConnection* pConnector) +{ + std::string pkgId; + bool prompted = false; + + pConnector->read(&pkgId, &prompted); + PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance(); + + int res = pPrivacyManagerServer->setUserPrompted(pkgId, prompted); + LOGI("write"); + pConnector->write( res ); + +} |