Add privacy manager
authorHyunwoo Kim <hwlove.kim@samsung.com>
Mon, 18 Mar 2013 05:34:57 +0000 (14:34 +0900)
committerHyunwoo Kim <hwlove.kim@samsung.com>
Mon, 18 Mar 2013 05:39:52 +0000 (14:39 +0900)
Change-Id: I838cc5731cb77f009c63b4ac2112c1deeba5e6ee
Signed-off-by: Hyunwoo Kim <hwlove.kim@samsung.com>
52 files changed:
CMakeLists.txt [new file with mode: 0644]
LICENSE.APLv2 [new file with mode: 0644]
client/CMakeLists.txt [new file with mode: 0644]
client/inc/PrivacyChecker.h [new file with mode: 0644]
client/inc/PrivacyManager.h [new file with mode: 0644]
client/inc/SocketClient.h [new file with mode: 0644]
client/inc/privacy_info_client.h [new file with mode: 0644]
client/inc/privacy_manager_client.h [new file with mode: 0644]
client/src/PrivacyChecker.cpp [new file with mode: 0644]
client/src/PrivacyManager.cpp [new file with mode: 0644]
client/src/SocketClient.cpp [new file with mode: 0644]
client/src/privacy_info_client.cpp [new file with mode: 0644]
client/src/privacy_manager_client.cpp [new file with mode: 0644]
client/src/privacy_manager_client_internal_types.h [new file with mode: 0644]
common/CMakeLists.txt [new file with mode: 0644]
common/inc/IPrivacyManager.h [new file with mode: 0644]
common/inc/PrivacyInfo.h [new file with mode: 0644]
common/inc/PrivacyManagerTypes.h [new file with mode: 0644]
common/inc/SocketConnection.h [new file with mode: 0644]
common/inc/SocketStream.h [new file with mode: 0644]
common/inc/Utils.h [new file with mode: 0644]
common/inc/privacy_manager_client_types.h [new file with mode: 0644]
common/src/SocketConnection.cpp [new file with mode: 0644]
common/src/SocketStream.cpp [new file with mode: 0644]
packaging/capi-security-privacy-manager.manifest [new file with mode: 0644]
packaging/libprivacy-manager-client.manifest [new file with mode: 0644]
packaging/priavcy-manager.manifest [new file with mode: 0644]
packaging/privacy-manager-client.manifest [new file with mode: 0644]
packaging/privacy-manager-server.manifest [new file with mode: 0644]
packaging/privacy-manager-server.service [new file with mode: 0644]
packaging/privacy-manager.spec [new file with mode: 0644]
privacy-manager-client.pc.in [new file with mode: 0644]
privacy-manager-server.pc.in [new file with mode: 0644]
privacy-manager-test.pc.in [new file with mode: 0644]
res/etc/rc.d/init.d/privacy-manager-server.sh [new file with mode: 0644]
res/usr/bin/privacy_db.sql [new file with mode: 0644]
res/usr/bin/privacy_manager_create_clean_db.sh [new file with mode: 0755]
server/CMakeLists.txt [new file with mode: 0644]
server/inc/NotificationServer.h [new file with mode: 0644]
server/inc/PrivacyInfoService.h [new file with mode: 0644]
server/inc/PrivacyManagerDaemon.h [new file with mode: 0644]
server/inc/PrivacyManagerServer.h [new file with mode: 0644]
server/inc/SocketService.h [new file with mode: 0644]
server/inc/TestService.h [new file with mode: 0644]
server/src/CMakeLists.txt [new file with mode: 0644]
server/src/NotificationServer.cpp [new file with mode: 0644]
server/src/PrivacyManagerDaemon.cpp [new file with mode: 0644]
server/src/PrivacyManagerServer.cpp [new file with mode: 0644]
server/src/SocketService.cpp [new file with mode: 0644]
server/src/main.cpp [new file with mode: 0644]
server/src/service/PrivacyInfoService.cpp [new file with mode: 0644]
server/src/service/TestService.cpp [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5719ee7
--- /dev/null
@@ -0,0 +1,17 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)\r
+\r
+MESSAGE("build privacy-manager")\r
+\r
+SET(CMAKE_VERBOSE_MAKEFILE OFF)\r
+\r
+IF("${USE_AUTOSTART}" STREQUAL "1")\r
+       ADD_DEFINITIONS("-DUSE_AUTOSTART")\r
+ENDIF()\r
+\r
+ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")\r
+ADD_DEFINITIONS("-DUSE_IPC_EPOLL")\r
+\r
+ADD_SUBDIRECTORY(server)\r
+ADD_SUBDIRECTORY(client)\r
+#ADD_SUBDIRECTORY(test)\r
+#ADD_SUBDIRECTORY(capi)\r
diff --git a/LICENSE.APLv2 b/LICENSE.APLv2
new file mode 100644 (file)
index 0000000..a795f06
--- /dev/null
@@ -0,0 +1,204 @@
+Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved 
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
new file mode 100644 (file)
index 0000000..90c578f
--- /dev/null
@@ -0,0 +1,82 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+#PROJECT(privacy-manager-client)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 0.0)
+
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.0.1")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS_PROFILING    " -g -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING  " -std=c++0x -g -pg")
+SET(CMAKE_C_FLAGS_DEBUG        " -g")
+SET(CMAKE_CXX_FLAGS_DEBUG      " -std=c++0x -g")
+SET(CMAKE_C_FLAGS_RELEASE      " -g")
+SET(CMAKE_CXX_FLAGS_RELEASE    " -std=c++0x -g")
+SET(CMAKE_C_FLAGS_CCOV         " -g --coverage")
+SET(CMAKE_CXX_FLAGS_CCOV       " -std=c++0x -g --coverage")
+
+SET(client_src_dir "${CMAKE_SOURCE_DIR}/client/src")
+SET(client_include_dir "${CMAKE_SOURCE_DIR}/client/inc/")
+SET(common_src_dir "${CMAKE_SOURCE_DIR}/common/src/")
+SET(common_include_dir "${CMAKE_SOURCE_DIR}/common/inc/")
+SET(lib_include_dir 
+       "/usr/include/dbus-1.0"
+       "/usr/include/aul"
+)
+
+## Additional flag
+ADD_DEFINITIONS("-fvisibility=hidden")
+ADD_DEFINITIONS("-Wall -Werror")
+ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
+
+###################################################################################################
+## for libprivacy-manager-client (executable)
+INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS} ${client_include_dir} ${common_include_dir} ${lib_include_dir})
+SET(PRIVACY_MANAGER_CLIENT_SOURCES 
+       ${common_src_dir}/SocketConnection.cpp
+       ${common_src_dir}/SocketStream.cpp
+       ${client_src_dir}/SocketClient.cpp
+       ${client_src_dir}/PrivacyManager.cpp
+       ${client_src_dir}/PrivacyChecker.cpp
+       ${client_src_dir}/privacy_info_client.cpp
+       ${client_src_dir}/privacy_manager_client.cpp
+       )
+SET(PRIVACY_MANAGER_CLIENT_HEADERS
+       ${client_include_dir}/PrivacyManager.h
+       ${client_include_dir}/PrivacyChecker.h
+       ${client_include_dir}/PrivacyChecker.h
+       ${client_include_dir}/privacy_info_client.h
+       ${client_include_dir}/privacy_manager_client.h
+       ${common_include_dir}/privacy_manager_client_types.h
+)
+SET(PRIVACY_MANAGER_CLIENT_LDFLAGS " -module -avoid-version ")
+SET(PRIVACY_MANAGER_CLIENT_CFLAGS  " ${CFLAGS} -fPIC ")
+#SET(PRIVACY_MANAGER_CLIENT_LIBADD " ")
+
+SET(PC_CFLAGS -I\${includedir}/privacy_manager)
+
+ADD_DEFINITIONS("-DLOG_TAG=\"PRIVACY-MANAGER-CLIENT\"")
+ADD_LIBRARY(privacy-manager-client SHARED ${PRIVACY_MANAGER_CLIENT_SOURCES})
+TARGET_LINK_LIBRARIES(privacy-manager-client ${pkgs_LDFLAGS} ${pkgs_LIBRARIES})
+SET_TARGET_PROPERTIES(privacy-manager-client PROPERTIES COMPILE_FLAGS "${PRIVACY_MANAGER_CLIENT_CFLAGS}")
+SET_TARGET_PROPERTIES(privacy-manager-client PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(privacy-manager-client PROPERTIES VERSION ${VERSION})
+###################################################################################################
+
+CONFIGURE_FILE(../privacy-manager-client.pc.in privacy-manager-client.pc @ONLY)
+
+INSTALL(TARGETS privacy-manager-client DESTINATION ../lib COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-manager-client.pc DESTINATION ../lib/pkgconfig)
+INSTALL(FILES ${PRIVACY_MANAGER_CLIENT_HEADERS} DESTINATION ../include/privacy_manager)
diff --git a/client/inc/PrivacyChecker.h b/client/inc/PrivacyChecker.h
new file mode 100644 (file)
index 0000000..96d86b3
--- /dev/null
@@ -0,0 +1,60 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_CHECKER_H_\r
+#define _PRIVACY_CHECKER_H_\r
+\r
+#include <string>\r
+#include <mutex>\r
+#include <list>\r
+#include <vector>\r
+#include <memory>\r
+#include <map>\r
+#include <PrivacyManagerTypes.h>\r
+#include <dbus/dbus.h>\r
+#include <glib.h>\r
+\r
+struct sqlite3;\r
+\r
+class EXTERN_API PrivacyChecker\r
+{\r
+private:\r
+       static const std::string DB_PATH;\r
+       static std::map < std::string, bool > m_privacyCache;\r
+       static std::string m_pkgId;\r
+       static bool m_isInitialized;\r
+       static std::mutex m_cacheMutex;\r
+       static DBusConnection* m_pDBusConnection;\r
+       static GMainLoop* m_pLoop;\r
+\r
+private:\r
+       static int initializeDbus(void);\r
+       static int finalizeDbus(void);\r
+       static int getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId);\r
+       static int updateCache(void);\r
+       static int updateCache(const std::string privacyId);\r
+       static void printCache(void);\r
+       static void* runSignalListenerThread(void* pData);\r
+       static int getCurrentPkgId(std::string& pkgId);\r
+\r
+public:\r
+       static int initialize(const std::string pkgId);\r
+       static int check(const std::string privacyId);\r
+       static int finalize(void);\r
+       static DBusHandlerResult handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data);\r
+};\r
+\r
+#endif // _PRIVACY_CHECKER_H_
\ No newline at end of file
diff --git a/client/inc/PrivacyManager.h b/client/inc/PrivacyManager.h
new file mode 100644 (file)
index 0000000..a9c054d
--- /dev/null
@@ -0,0 +1,60 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_MANAGER_H_\r
+#define _PRIVACY_MANAGER_H_\r
+\r
+#include <string>\r
+#include <mutex>\r
+#include <list>\r
+#include <vector>\r
+#include <memory>\r
+#include <PrivacyManagerTypes.h>\r
+\r
+class SocketClient;\r
+\r
+class EXTERN_API PrivacyManager\r
+{\r
+private:\r
+       static PrivacyManager* m_pInstance;\r
+       static const std::string INTERFACE_NAME;\r
+\r
+       std::unique_ptr< SocketClient > m_pSocketClient;\r
+\r
+       static std::mutex m_singletonMutex;\r
+\r
+       PrivacyManager();\r
+       ~PrivacyManager();\r
+\r
+public:\r
+       static PrivacyManager* getInstance(void);\r
+\r
+       int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& list);\r
+\r
+       int removeAppPackagePrivacyInfo(const std::string pkgId);\r
+\r
+       int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);\r
+       \r
+       int getPrivacyAppPackages(std::list < std::string >& list);\r
+\r
+       int     getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list);\r
+\r
+       int isUserPrompted(const std::string pkgId, bool& isPrompted);\r
+\r
+       int setUserPrompted(const std::string pkgId, bool prompted);\r
+};\r
+\r
+#endif // _PRIVACY_MANAGER_H_
\ No newline at end of file
diff --git a/client/inc/SocketClient.h b/client/inc/SocketClient.h
new file mode 100644 (file)
index 0000000..5445db4
--- /dev/null
@@ -0,0 +1,145 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef SECURITYSOCKETCLIENT_H_\r
+#define SECURITYSOCKETCLIENT_H_\r
+\r
+#include <memory>\r
+#include <string>\r
+#include <dlog.h>\r
+#include "SocketConnection.h"\r
+\r
+/* IMPORTANT:\r
+ * Methods connect(), call() and disconnected() should be called one by one.\r
+ * Between connect() and disconnect() you can use call() only once.\r
+ * It is because of timeout on call, e.g. to avoid waiting for corrupted data.\r
+ */\r
+\r
+/* USAGE:\r
+ * Class should be used according to this scheme:\r
+ * SocketClient client("Interface Name");\r
+ * (...)\r
+ * client.connect();\r
+ * client.call("Method name", in_arg1, in_arg2, ..., in_argN,\r
+ *             out_arg1, out_arg2, ..., out_argM);\r
+ * client.disconnect();\r
+ * (...)\r
+ *\r
+ * input parameters of the call are passed with reference,\r
+ * output ones are passed as pointers - parameters MUST be passed this way.\r
+ *\r
+ * Currently client supports serialization and deserialization of simple types\r
+ * (int, char, float, unsigned), strings (std::string and char*) and\r
+ * some STL containers (std::vector, std::list, std::map, std::pair).\r
+ * Structures and classes are not (yet) supported.\r
+ */\r
+\r
+#include <string>\r
+#include <PrivacyManagerTypes.h>\r
+\r
+class EXTERN_API SocketClient \r
+{\r
+public:\r
+\r
+       SocketClient(const std::string &interfaceName);\r
+       int connect();\r
+       int disconnect();\r
+\r
+       void call(std::string methodName){\r
+               make_call(m_interfaceName);\r
+               make_call(methodName);\r
+       }\r
+\r
+       template<typename ...Args>\r
+       void call(std::string methodName, const Args&... args){\r
+               make_call(m_interfaceName);\r
+               make_call(methodName);\r
+               make_call(args...);\r
+       }\r
+\r
+       template<typename T>\r
+       void read(T* outvalue)\r
+       {\r
+                m_socketConnector->read(outvalue);\r
+       }\r
+private:\r
+       template<typename T, typename ...Args>\r
+       void make_call(const T& invalue, const Args&... args)\r
+       {\r
+               make_call(invalue);\r
+               make_call(args...);\r
+       }\r
+\r
+       template<typename T>\r
+       void make_call(const T& invalue)\r
+       {\r
+//             Try {\r
+                       m_socketConnector->write(invalue);\r
+ //       }\r
+  //     Catch (SocketConnection::Exception::SocketConnectionException){\r
+ //               LogError("Socket connection write error");\r
+  //             ReThrowMsg(Exception::SocketClientException,"Socket connection write error");\r
+ //       }\r
+       }\r
+\r
+       template<typename T, typename ...Args>\r
+       void make_call(const T* invalue, const Args&... args)\r
+       {\r
+               make_call(invalue);\r
+               make_call(args...);\r
+       }\r
+\r
+       template<typename T>\r
+       void make_call(const T* invalue)\r
+       {\r
+//             Try {\r
+                       m_socketConnector->write(invalue);\r
+//             }\r
+//        Catch (SocketConnection::Exception::SocketConnectionException){\r
+//                     LogError("Socket connection write error");\r
+//                ReThrowMsg(Exception::SocketClientException,"Socket connection write error");\r
+//             }\r
+       }\r
+\r
+       template<typename T, typename ...Args>\r
+       void make_call(T * outvalue, const Args&... args)\r
+       {\r
+               make_call(outvalue);\r
+               make_call(args...);\r
+       }\r
+\r
+       template<typename T>\r
+       void make_call(T* outvalue)\r
+       {\r
+//             Try {\r
+                       m_socketConnector->read(outvalue);\r
+//             }\r
+//             Catch (SocketConnection::Exception::SocketConnectionException){\r
+//                     LogError("Socket connection read error");\r
+//                     ReThrowMsg(Exception::SocketClientException,"Socket connection read error");\r
+//             }\r
+   }\r
+\r
+\r
+private:\r
+       //int throwWithErrnoMessage(const std::string& specificInfo);\r
+       std::string m_serverAddress;\r
+       std::string m_interfaceName;\r
+       std::unique_ptr<SocketConnection> m_socketConnector;\r
+       int m_socketFd;\r
+};\r
+\r
+#endif /* SECURITYSOCKETCLIENT_H_ */
\ No newline at end of file
diff --git a/client/inc/privacy_info_client.h b/client/inc/privacy_info_client.h
new file mode 100644 (file)
index 0000000..b348a65
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License. \r
+ */\r
+\r
+#ifndef _PRIVACY_INFO_CLIENT_H\r
+#define _PRIVACY_INFO_CLIENT_H\r
+\r
+#include <privacy_manager_client_types.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef struct _privacy_info_client_s {\r
+       char *privacy_id;\r
+       bool is_enabled;\r
+} privacy_info_client_s;\r
+\r
+EXTERN_API int create_privacy_info_client_s(const char* package_id, bool enabled, privacy_info_client_s **privacy_info);\r
+EXTERN_API int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info);\r
+EXTERN_API int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **package);\r
+EXTERN_API int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name);\r
+EXTERN_API int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description);\r
+EXTERN_API int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif //_PRIVACY_INFO_CLIENT_H\r
diff --git a/client/inc/privacy_manager_client.h b/client/inc/privacy_manager_client.h
new file mode 100644 (file)
index 0000000..5611c79
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License. \r
+ */\r
+\r
+#ifndef __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_H\r
+#define __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_H\r
+\r
+#include <privacy_info_client.h>\r
+#include <privacy_manager_client_types.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+typedef bool (*privacy_manager_client_privacy_packages_cb) (const char *package_id, void* user_data);\r
+typedef bool (*privacy_manager_client_privacy_info_cb) (privacy_info_client_s* privacy_info, void* user_data);\r
+\r
+EXTERN_API int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list);\r
+EXTERN_API int privacy_manager_client_uninstall_privacy(const char *package_id);\r
+EXTERN_API int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data);\r
+EXTERN_API int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data);\r
+EXTERN_API int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable);\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_H\r
+\r
diff --git a/client/src/PrivacyChecker.cpp b/client/src/PrivacyChecker.cpp
new file mode 100644 (file)
index 0000000..8688f7e
--- /dev/null
@@ -0,0 +1,294 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <PrivacyChecker.h>\r
+#include <PrivacyManager.h>\r
+#include <SocketClient.h>\r
+#include <algorithm> \r
+#include <memory>\r
+#include <Utils.h>\r
+#include <dlog.h>\r
+#include <sqlite3.h>\r
+#include <dbus/dbus-glib-lowlevel.h>\r
+#include <sys/types.h>\r
+#include <unistd.h>\r
+\r
+bool PrivacyChecker::m_isInitialized = false;\r
+const std::string PrivacyChecker::DB_PATH("/opt/dbspace/.privacy.db");\r
+std::map < std::string, bool >PrivacyChecker::m_privacyCache;\r
+std::mutex PrivacyChecker::m_cacheMutex;\r
+std::string PrivacyChecker::m_pkgId;\r
+DBusConnection* PrivacyChecker::m_pDBusConnection;\r
+GMainLoop* PrivacyChecker::m_pLoop = NULL;\r
+\r
+const int MAX_LOCAL_BUF_SIZE = 128;\r
+\r
+int\r
+PrivacyChecker::getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId)\r
+{\r
+       LOGI("enter");\r
+       std::string PkgIdQuery = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?");\r
+\r
+       int res;\r
+       openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
+       prepareDb(pDbH, PkgIdQuery.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_IO_ERROR, , "sqlite3_bind_text : %d", res);\r
+\r
+       res = sqlite3_step(pStmt.get());\r
+       TryReturn( res == SQLITE_ROW, PRIV_MGR_ERROR_IO_ERROR, , "sqlite3_step : %d", res);\r
+\r
+       uniqueId = sqlite3_column_int(pStmt.get(), 0);\r
+       LOGI("%s : %d", pkgId.c_str(), uniqueId);\r
+\r
+       LOGI("leave");\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+PrivacyChecker::initialize(const std::string pkgId)\r
+{\r
+       LOGI("enter");\r
+\r
+       if (m_isInitialized)\r
+               return PRIV_MGR_ERROR_SUCCESS;\r
+\r
+       int res;\r
+       pthread_t signalThread;\r
+       res = pthread_create(&signalThread, NULL, &runSignalListenerThread, NULL);\r
+       TryReturn(res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res;, "Failed to create listener thread :%s", strerror(res));\r
+\r
+       m_pkgId = pkgId;\r
+       res = updateCache();\r
+       TryReturn(res == 0, res, m_pkgId.clear(), "Failed to update cache : %d", res);\r
+\r
+       m_isInitialized = true;\r
+\r
+       LOGI("leave");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+void*\r
+PrivacyChecker::runSignalListenerThread(void* pData)\r
+{\r
+       pthread_detach(pthread_self());\r
+       LOGI("Running g main loop for signal");\r
+       \r
+       if (m_pLoop != NULL)\r
+               return (void*) 0;\r
+       \r
+       m_pLoop = g_main_new(TRUE);\r
+\r
+       initializeDbus();\r
+\r
+       g_main_loop_run(m_pLoop);\r
+\r
+       finalizeDbus();\r
+\r
+       pthread_exit(NULL);\r
+\r
+       return (void*) 0;\r
+}\r
+\r
+int\r
+PrivacyChecker::initializeDbus(void)\r
+{\r
+       LOGI("enter");\r
+       DBusError error;\r
+       dbus_error_init(&error);\r
+\r
+       m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);\r
+       TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private [%s] : %d", PRIV_MGR_ERROR_SYSTEM_ERROR);\r
+\r
+       dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);\r
+       std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);\r
+\r
+       snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());\r
+       dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);\r
+       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);\r
+\r
+       dbus_bool_t r = dbus_connection_add_filter(m_pDBusConnection, handleNotification, NULL, NULL);\r
+       TryReturn(r, PRIV_MGR_ERROR_SYSTEM_ERROR, , "dbus_connection_add_filter: %d", PRIV_MGR_ERROR_SYSTEM_ERROR);\r
+\r
+       LOGI("leave");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+PrivacyChecker::finalizeDbus(void)\r
+{\r
+       dbus_connection_remove_filter(m_pDBusConnection, handleNotification, NULL);\r
+       dbus_connection_close(m_pDBusConnection);\r
+       m_pDBusConnection = NULL;\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+\r
+DBusHandlerResult\r
+PrivacyChecker::handleNotification(DBusConnection* connection, DBusMessage* message, void* user_data)\r
+{\r
+       DBusError error;\r
+       dbus_bool_t r;\r
+       dbus_error_init(&error);\r
+\r
+       char* pPkgId;\r
+       char* pPrivacyId;\r
+\r
+       if (dbus_message_is_signal(message, DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_NAME.c_str()))\r
+       {\r
+               r = dbus_message_get_args(message, &error,\r
+                       DBUS_TYPE_STRING, &pPkgId,\r
+                       DBUS_TYPE_STRING, &pPrivacyId,\r
+                       DBUS_TYPE_INVALID);\r
+               TryReturn(r, DBUS_HANDLER_RESULT_NOT_YET_HANDLED, , "Fail to get data : %s", error.message);\r
+               \r
+               if (std::string(pPkgId) == m_pkgId)\r
+               {\r
+                       LOGI("Current app pkg privacy information updated");\r
+                       updateCache(pPrivacyId);\r
+                       printCache();\r
+               }\r
+       }\r
+       else\r
+       {\r
+               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;\r
+       }\r
+       \r
+       return DBUS_HANDLER_RESULT_HANDLED;\r
+}\r
+\r
+int\r
+PrivacyChecker::check(const std::string privacyId)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+\r
+       TryReturn(m_isInitialized, -1, , "Not initialized");\r
+\r
+       std::map < std::string, bool >::const_iterator iter = m_privacyCache.find(privacyId);\r
+       if (iter == m_privacyCache.end() )\r
+       {\r
+               LOGD("NO matcheded");\r
+               return -1;\r
+       }\r
+       else if (!iter->second)\r
+       {\r
+               LOGD("NOT allowed");\r
+               return -1;\r
+       }\r
+       LOGD("OK");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+PrivacyChecker::finalize(void)\r
+{\r
+       std::lock_guard <std::mutex> guard (m_cacheMutex);\r
+       m_privacyCache.clear();\r
+       \r
+       if (m_pLoop != NULL)\r
+       {\r
+               g_main_loop_quit(m_pLoop);\r
+               m_pLoop = NULL;\r
+       }\r
+\r
+       m_isInitialized = false;\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+PrivacyChecker::updateCache(void)\r
+{\r
+       LOGI("enter");\r
+       static const std::string PrivacyQuery = "SELECT PRIVACY_ID, IS_ENABLED from Privacy where ID=?";\r
+       \r
+       std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+\r
+       int res;\r
+       int id;\r
+       res = getUniqueIdFromPackageId(m_pkgId, id);\r
+       TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res);\r
+       LOGD("id : %d" ,id);\r
+       \r
+       openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
+       prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);\r
+       res = sqlite3_bind_int(pPrivacyStmt.get(), 1, id);\r
+       TryReturn( res == 0, -1, , "sqlite3_bind_int : %d", res);\r
+\r
+\r
+       while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )\r
+       {\r
+               LOGI("start");\r
+               const char* privacyId =  reinterpret_cast < const char* > (sqlite3_column_text(pPrivacyStmt.get(), 0));\r
+               bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 1) > 0 ? true : false;\r
+\r
+               m_privacyCache.insert(std::map < std::string, bool >::value_type(std::string(privacyId), privacyEnabled));\r
+\r
+               LOGD("Privacy found : %s %d", privacyId, privacyEnabled);\r
+       }\r
+       LOGI("leave");\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+void\r
+PrivacyChecker::printCache(void)\r
+{\r
+       std::map < std::string, bool >::const_iterator iter = m_privacyCache.begin();\r
+       for (; iter != m_privacyCache.end(); ++iter)\r
+       {\r
+               LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
+       }\r
+}\r
+int\r
+PrivacyChecker::updateCache(const std::string privacyId)\r
+{\r
+       LOGI("enter");\r
+       static const std::string PrivacyQuery = "SELECT IS_ENABLED from Privacy where ID=? and PRIVACY_ID=?";\r
+\r
+       int res;\r
+       int id;\r
+       res = getUniqueIdFromPackageId(m_pkgId, id);\r
+       TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res);\r
+\r
+       LOGD("id : %d" ,id);\r
+       \r
+       openDb(DB_PATH.c_str(), pDbH, SQLITE_OPEN_READONLY);\r
+       prepareDb(pDbH, PrivacyQuery.c_str(), pPrivacyStmt);\r
+       res = sqlite3_bind_int(pPrivacyStmt.get(), 1, id);\r
+       TryReturn( res == 0, -1, , "sqlite3_bind_int : %d", res);\r
+\r
+       res = sqlite3_bind_text(pPrivacyStmt.get(), 2, privacyId.c_str(),  -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == 0, -1, , "sqlite3_bind_text : %d", res);\r
+\r
+       while ( sqlite3_step(pPrivacyStmt.get()) == SQLITE_ROW )\r
+       {\r
+               bool privacyEnabled = sqlite3_column_int(pPrivacyStmt.get(), 0) > 0 ? true : false;\r
+\r
+               std::lock_guard < std::mutex > guard(m_cacheMutex);\r
+               m_privacyCache.erase(privacyId);\r
+               m_privacyCache.insert(std::map < std::string, bool >::value_type(privacyId, privacyEnabled));\r
+       }\r
+       \r
+       LOGI("leave");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}
\ No newline at end of file
diff --git a/client/src/PrivacyManager.cpp b/client/src/PrivacyManager.cpp
new file mode 100644 (file)
index 0000000..fd6115a
--- /dev/null
@@ -0,0 +1,138 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <PrivacyManager.h>\r
+#include <SocketClient.h>\r
+#include <algorithm> \r
+#include <memory>\r
+#include <Utils.h>\r
+\r
+std::mutex PrivacyManager::m_singletonMutex;\r
+PrivacyManager* PrivacyManager::m_pInstance = NULL;\r
+const std::string PrivacyManager::INTERFACE_NAME("PrivacyInfoService");\r
+\r
+PrivacyManager::PrivacyManager(void)\r
+{\r
+       std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));\r
+       m_pSocketClient = std::move(pSocketClient);\r
+}\r
+\r
+PrivacyManager*\r
+PrivacyManager::getInstance(void)\r
+{\r
+       std::lock_guard<std::mutex> guard(m_singletonMutex);\r
+       if (m_pInstance == NULL)\r
+               m_pInstance = new PrivacyManager();\r
+       return m_pInstance;\r
+}\r
+\r
+int\r
+PrivacyManager::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList)\r
+{\r
+       int result;\r
+       m_pSocketClient->connect();\r
+       m_pSocketClient->call("addPrivacyInfo", pkgId, pList, &result);\r
+       m_pSocketClient->disconnect();\r
+\r
+       return result;\r
+}\r
+\r
+int\r
+PrivacyManager::removeAppPackagePrivacyInfo(const std::string pkgId)\r
+{\r
+       int result;\r
+       m_pSocketClient->connect();\r
+       m_pSocketClient->call("removePrivacyInfo", pkgId, pkgId, &result);\r
+       m_pSocketClient->disconnect();\r
+\r
+       return result;\r
+}\r
+\r
+int\r
+PrivacyManager::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)\r
+{\r
+       int result;\r
+       m_pSocketClient->connect();\r
+       m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);\r
+       m_pSocketClient->disconnect();\r
+\r
+       return result;\r
+}\r
+       \r
+int\r
+PrivacyManager::getPrivacyAppPackages(std::list < std::string >& pList)\r
+{\r
+       int result, size;\r
+       std::string temp1;\r
+       SocketClient* p = new SocketClient(INTERFACE_NAME);\r
+       p->connect();\r
+       p->call("getPrivacyAppPackages", &result, &size, &pList);\r
+       p->disconnect();\r
+\r
+       return result;\r
+}\r
+\r
+int\r
+PrivacyManager::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list)\r
+{\r
+\r
+       std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
+\r
+       int result;\r
+       pSocketClient->connect();\r
+       pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);\r
+\r
+       pSocketClient->disconnect();\r
+\r
+       for (std::list < std::pair <std::string, bool > >::const_iterator iter = list.begin(); iter != list.end(); ++iter){\r
+               LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
+       }\r
+\r
+       return result;\r
+}\r
+\r
+int\r
+PrivacyManager::isUserPrompted(const std::string pkgId, bool& isPrompted)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
+\r
+       int result;\r
+       pSocketClient->connect();\r
+       pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);\r
+       pSocketClient->disconnect();\r
+\r
+       LOGI("leave");\r
+\r
+       return result;\r
+}\r
+\r
+int\r
+PrivacyManager::setUserPrompted(const std::string pkgId, bool prompted)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
+\r
+       int result;\r
+       pSocketClient->connect();\r
+       pSocketClient->call("setUserPrompted", pkgId, prompted, &result);\r
+       pSocketClient->disconnect();\r
+       LOGI("leave");\r
+\r
+       return result;\r
+}
\ No newline at end of file
diff --git a/client/src/SocketClient.cpp b/client/src/SocketClient.cpp
new file mode 100644 (file)
index 0000000..991d7b7
--- /dev/null
@@ -0,0 +1,82 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <sys/socket.h>\r
+#include <string.h>\r
+#include <fcntl.h>\r
+#include <sys/types.h>\r
+#include <sys/un.h>\r
+#include <errno.h>\r
+#include <unistd.h>\r
+#include <PrivacyManagerTypes.h>\r
+#include "SocketClient.h"\r
+#include <Utils.h>\r
+\r
+\r
+/*int\r
+SocketClient::throwWithErrnoMessage(const std::string& specificInfo){\r
+       LOGE("%s : %s", specificInfo.c_str(), strerror(errno));\r
+       return -1;\r
+}*/\r
+\r
+#define throwWithErrnoMessage(specificInfo)    do {\\r
+                                                                                               LOGE("%s : %s", specificInfo, strerror(errno)); \\r
+                                                                                               return -1; \\r
+                                                                                       } while(0)\r
+\r
+SocketClient::SocketClient(const std::string& interfaceName) \r
+{\r
+       m_interfaceName = interfaceName;\r
+       m_serverAddress = SERVER_ADDRESS;\r
+       LOGI("Client created");\r
+}\r
+\r
+int SocketClient::connect()\r
+{\r
+       struct sockaddr_un remote;\r
+       m_socketFd = socket(AF_UNIX, SOCK_STREAM,0);\r
+       TryReturn( m_socketFd != -1, -1, , "socket : %s", strerror(errno));\r
+\r
+       int res;\r
+       //socket needs to be nonblocking, because read can block after select\r
+       int flags;\r
+       if ( (flags = fcntl(m_socketFd, F_GETFL, 0)) == -1 )\r
+               flags = 0;\r
+       res = fcntl(m_socketFd, F_SETFL, flags | O_NONBLOCK);\r
+       TryReturn( m_socketFd != -1, -1, , "fcntl : %s", strerror(errno));\r
+\r
+       bzero(&remote, sizeof(remote));\r
+       remote.sun_family = AF_UNIX;\r
+       strcpy(remote.sun_path, m_serverAddress.c_str());\r
+       res = ::connect(m_socketFd, (struct sockaddr *)&remote, SUN_LEN(&remote));\r
+       TryReturn( res != -1, -1, , "connect : %s", strerror(errno));\r
+\r
+       m_socketConnector.reset(new SocketConnection(m_socketFd));\r
+       \r
+       LOGI("Client connected");\r
+\r
+       return 0;\r
+}\r
+\r
+int SocketClient::disconnect()\r
+{\r
+       //Socket should be already closed by server side, \r
+       //even though we should close it in case of any errors\r
+       close(m_socketFd);\r
+       LOGI("Client disconnected");\r
+\r
+       return 0;\r
+}\r
diff --git a/client/src/privacy_info_client.cpp b/client/src/privacy_info_client.cpp
new file mode 100644 (file)
index 0000000..691c69c
--- /dev/null
@@ -0,0 +1,73 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License. \r
+ */\r
+\r
+#include <string.h>\r
+#include <string>\r
+#include <memory>\r
+#include <PrivacyManager.h>\r
+#include <privacy_manager_client.h>\r
+#include <privacy_manager_client_types.h>\r
+#include "privacy_manager_client_internal_types.h"\r
+\r
+int privacy_info_client_s_destroy(privacy_info_client_s* privacy_info)\r
+{\r
+       if (privacy_info != NULL)\r
+       {\r
+               if (privacy_info->privacy_id)\r
+                       free(privacy_info->privacy_id);\r
+               free (privacy_info);\r
+       }\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int privacy_info_client_get_privacy_id(privacy_info_client_s* privacy_info, char **package)\r
+{\r
+       int size = strlen(privacy_info->privacy_id);\r
+       *package = (char*) calloc(1, size);\r
+\r
+       memcpy (*package, privacy_info->privacy_id, size);\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int privacy_info_client_get_privacy_display_name(privacy_info_client_s* privacy_info, char **name)\r
+{\r
+       // TODO: Modify to use STMS\r
+       int size = strlen(privacy_info->privacy_id);\r
+       *name = (char*) calloc(1, size);\r
+\r
+       memcpy (*name, privacy_info->privacy_id, size);\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int privacy_info_client_get_privacy_description(privacy_info_client_s* privacy_info, char **description)\r
+{\r
+       // TODO: Modify to use STMS\r
+       int size = strlen(privacy_info->privacy_id);\r
+       *description = (char*) calloc(1, size);\r
+\r
+       memcpy (*description, privacy_info->privacy_id, size);\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int privacy_info_client_is_enabled(privacy_info_client_s* privacy_info, bool *enabled)\r
+{\r
+       *enabled = privacy_info->is_enabled;\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
diff --git a/client/src/privacy_manager_client.cpp b/client/src/privacy_manager_client.cpp
new file mode 100644 (file)
index 0000000..84fc2a5
--- /dev/null
@@ -0,0 +1,119 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License. \r
+ */\r
+\r
+#include <string.h>\r
+#include <string>\r
+#include <memory>\r
+#include <PrivacyManager.h>\r
+#include <privacy_manager_client.h>\r
+#include "privacy_manager_client_internal_types.h"\r
+\r
+int create_privacy_info_client_s(const char* package_id, bool enabled, privacy_info_client_s **privacy_info)\r
+{\r
+       privacy_info_client_s* temp = (privacy_info_client_s*) calloc(1, sizeof(privacy_info_client_s));\r
+       if (temp == NULL)\r
+               return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
+\r
+       int size = strlen(package_id);\r
+       temp->privacy_id = (char*) calloc(1, size + 1);\r
+       if (temp->privacy_id == NULL)\r
+       {\r
+               free(temp);\r
+               return PRIV_MGR_ERROR_OUT_OF_MEMORY;\r
+       }\r
+       memcpy(temp->privacy_id, package_id, size + 1);\r
+       \r
+       temp->is_enabled = enabled;\r
+\r
+       *privacy_info = temp;\r
+       \r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int privacy_manager_client_install_privacy(const char *package_id, const char** privacy_list)\r
+{\r
+       int retval;\r
+       PrivacyManager* pInst = PrivacyManager::getInstance();\r
+       std::list < std::string > privacyList;\r
+\r
+       while (*privacy_list != NULL)\r
+       {\r
+               privacyList.push_back(std::string(*privacy_list ++));\r
+       }\r
+       retval = pInst->addAppPackagePrivacyInfo(std::string(package_id), privacyList);\r
+\r
+       return retval;\r
+}\r
+\r
+int privacy_manager_client_uninstall_privacy(const char *package_id)\r
+{\r
+       if (package_id == NULL)\r
+               return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
+       return PrivacyManager::getInstance()->removeAppPackagePrivacyInfo(std::string(package_id));\r
+}\r
+\r
+int privacy_manager_client_foreach_privacy_packages(privacy_manager_client_privacy_packages_cb callback, void *user_data)\r
+{\r
+       int retval;\r
+       PrivacyManager* pInst = PrivacyManager::getInstance();\r
+\r
+       std::list < std::string > list;\r
+       retval = pInst->getPrivacyAppPackages(list);\r
+       if (retval != PRIV_MGR_ERROR_SUCCESS)\r
+               return retval;\r
+       if (list.size() == 0)\r
+               return PRIV_MGR_ERROR_NO_DATA;\r
+\r
+       for (std::list < std::string >::iterator iter = list.begin(); iter != list.end(); ++iter)\r
+       {\r
+               if ( ! callback(iter->c_str(), user_data) )\r
+                       break;\r
+       }\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+int privacy_manager_client_foreach_get_privacy_info(const char *package_id, privacy_manager_client_privacy_info_cb callback, void* user_data)\r
+{\r
+       int retval;\r
+       bool res;\r
+       PrivacyManager* pInst = PrivacyManager::getInstance();\r
+\r
+       std::list < std::pair <std::string, bool > > list;\r
+\r
+       retval = pInst->getAppPackagePrivacyInfo(package_id, list);\r
+       if (retval != PRIV_MGR_ERROR_SUCCESS)\r
+               return retval;\r
+       if (list.size() == 0)\r
+               return PRIV_MGR_ERROR_NO_DATA;\r
+\r
+       for (std::list < std::pair <std::string, bool > >::iterator iter = list.begin(); iter != list.end(); ++iter)\r
+       {\r
+               privacy_info_client_s *privacy_info_client_s = NULL;\r
+               retval = create_privacy_info_client_s(iter->first.c_str(), iter->second, &privacy_info_client_s);\r
+               res = callback(privacy_info_client_s, user_data);\r
+               privacy_info_client_s_destroy(privacy_info_client_s);\r
+               if (!res)\r
+                       break;\r
+       }\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+\r
+}\r
+int privacy_manager_client_set_package_privacy(const char *package_id, const char *privacy_id, bool enable)\r
+{\r
+       PrivacyManager* pInst = PrivacyManager::getInstance();\r
+\r
+       return pInst->setPrivacySetting(package_id, privacy_id, enable);\r
+}\r
diff --git a/client/src/privacy_manager_client_internal_types.h b/client/src/privacy_manager_client_internal_types.h
new file mode 100644 (file)
index 0000000..638288e
--- /dev/null
@@ -0,0 +1,32 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License. \r
+ */\r
+\r
+#ifndef __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H\r
+#define __TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H\r
+\r
+#include <tizen.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+\r
+#endif //__TIZEN_PRIVACYMGR_PRIVACY_INFO_CLIENT_INTERNAL_TYPES_H
\ No newline at end of file
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..e9137e4
--- /dev/null
@@ -0,0 +1,14 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+SET(common_src_dir "${CMAKE_SOURCE_DIR}/common/src/")
+SET(common_include_dir "${CMAKE_SOURCE_DIR}/common/inc/")
+
+SET(PRIVACY_MANAGER_COMMON_SOURCES 
+       ${common_src_dir}/SocketConnection.cpp
+       ${common_src_dir}/SocketStream.cpp
+       )
+
+SET(PRIVACY_MANAGER_COMMON_HEADERS
+       ${common_include_dir}/SocketConnection.h
+       ${common_include_dir}/SocketConnection.h
+)
\ No newline at end of file
diff --git a/common/inc/IPrivacyManager.h b/common/inc/IPrivacyManager.h
new file mode 100644 (file)
index 0000000..599e964
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _IPRIVACY_MANAGER_H_\r
+#define _IPRIVACY_MANAGER_H_\r
+\r
+#include <string>\r
+#include <mutex>\r
+#include <list>\r
+#include <vector>\r
+#include <memory>\r
+#include <PrivacyManagerTypes.h>\r
+\r
+class SocketClient;\r
+\r
+class EXTERN_API IPrivacyManager\r
+{\r
+public:\r
+       int addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList);\r
+\r
+       int removeAppPackagePrivacyInfo(const std::string pkgId);\r
+\r
+       int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled);\r
+       \r
+       int getPrivacyAppPackages(std::list < std::string >& pList);\r
+\r
+       int     getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & pList);\r
+};\r
+\r
+#endif // _IPRIVACY_MANAGER_H_
\ No newline at end of file
diff --git a/common/inc/PrivacyInfo.h b/common/inc/PrivacyInfo.h
new file mode 100644 (file)
index 0000000..6ab6629
--- /dev/null
@@ -0,0 +1,50 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_INFO_H_\r
+#define _PRIVACY_INFO_H_\r
+\r
+#include <string>\r
+\r
+struct PrivacyPrivilegePair\r
+{\r
+       char privilege[128];\r
+       char privacy[128];\r
+\r
+};\r
+\r
+struct PrivacyPrivilegePair PrivilegeToPrivacyTable[] =\r
+{\r
+       {"http://tizendev.org/privilege/contact.read", "http://tizendev.org/privilege/contact"},\r
+       {"http://tizendev.org/privilege/contact.write", "http://tizendev.org/privilege/contact"},\r
+       {NULL, NULL}\r
+};\r
+\r
+class PrivacyInfo\r
+{\r
+public:\r
+       static std::string GetPrivacyId(const std::string& privilegeId)\r
+       {\r
+               int i = 0;\r
+               while (PrivilegeToPrivacyTable[i].privilege != NULL)            \r
+               {\r
+                       if ( strncmp(privilegeId.c_str(), PrivilegeToPrivacyTable[i].privilege, privilegeId.size()) == 0)\r
+                               return std::string(PrivilegeToPrivacyTable[i].privacy);\r
+               }\r
+               return std::string("");\r
+       }\r
+}\r
+#endif //_PRIVACY_INFO_H_
\ No newline at end of file
diff --git a/common/inc/PrivacyManagerTypes.h b/common/inc/PrivacyManagerTypes.h
new file mode 100644 (file)
index 0000000..6b42115
--- /dev/null
@@ -0,0 +1,28 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_MANAGER_TYPES_H_\r
+#define _PRIVACY_MANAGER_TYPES_H_\r
+\r
+#include <string>\r
+#include <privacy_manager_client_types.h>\r
+\r
+static const std::string SERVER_ADDRESS ("/tmp/privacy_manager_server");\r
+static const std::string DBUS_PATH("/privacy_manager/dbus_notification");\r
+static const std::string DBUS_SIGNAL_INTERFACE("org.tizen.privacy_manager.signal");\r
+static const std::string DBUS_SIGNAL_NAME("privacy_setting_updated");\r
+\r
+#endif\r
diff --git a/common/inc/SocketConnection.h b/common/inc/SocketConnection.h
new file mode 100644 (file)
index 0000000..dda7082
--- /dev/null
@@ -0,0 +1,247 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _SOCKET_CONNECTION_H_\r
+#define _SOCKET_CONNECTION_H_\r
+\r
+#include <dlog.h>\r
+#include <new>\r
+#include <list>\r
+#include <utility>\r
+#include <SocketStream.h>\r
+#include <PrivacyManagerTypes.h>\r
+#include <iostream>\r
+/*\r
+ * This class implements interface for generic read and write from given socket.\r
+ * It does not maintain socket descriptor, so any connecting and disconnecting should be\r
+ */\r
+\r
+/*\r
+ * Throws SocketConnectionException when read/write will not succeed or if any bad allocation\r
+ * exception occurs during read.\r
+ */\r
+\r
+class EXTERN_API SocketConnection\r
+{\r
+\r
+public:\r
+\r
+       explicit SocketConnection(int socket_fd) : m_socketStream(socket_fd){\r
+               LOGI("Created");\r
+       }\r
+\r
+       template<typename T, typename ...Args>\r
+       void read(T* out, const Args&... args )\r
+       {\r
+               read(out);\r
+               read(args...);\r
+       }\r
+\r
+       template<typename T>\r
+       void read(T* out)\r
+       {\r
+               int length = 0;\r
+               int ret = m_socketStream.readStream(sizeof(length), &length);\r
+               char* pBuf = new char[length + 1];\r
+               m_socketStream.readStream(length, pBuf);\r
+               pBuf[length] = 0;\r
+\r
+               out = T(pBuf);\r
+\r
+               delete[] pBuf;\r
+       }\r
+       \r
+       void read(bool* pB)\r
+       {\r
+               \r
+               int length = 0;\r
+               int ret = m_socketStream.readStream(sizeof(length), &length);\r
+               if (ret < 0)\r
+               {}\r
+               char* pBuf = new char[length + 1];\r
+               m_socketStream.readStream(length, pBuf);\r
+               pBuf[length] = 0;\r
+\r
+               *pB = * reinterpret_cast <bool* > (pBuf);\r
+\r
+               delete[] pBuf;\r
+       }\r
+\r
+       void read(bool& b)\r
+       {\r
+               read(&b);\r
+       }\r
+       \r
+       void read(int& i)\r
+       {\r
+               read(&i);\r
+       }\r
+       void read(int* pI)\r
+       {\r
+               int length = 0;\r
+               int ret = m_socketStream.readStream(sizeof(length), &length);\r
+               if (ret < 0)\r
+               {}\r
+               char* pBuf = new char[length + 1];\r
+               m_socketStream.readStream(length, pBuf);\r
+               pBuf[length] = 0;\r
+\r
+               *pI = * reinterpret_cast <int* > (pBuf);\r
+\r
+               delete[] pBuf;\r
+       }\r
+\r
+       void read(std::string* pStr)\r
+       {\r
+               int length = 0;\r
+               int ret = m_socketStream.readStream(sizeof(length), &length);\r
+               if (ret < 0)\r
+               {}\r
+               char* pBuf = new char[length + 1];\r
+               m_socketStream.readStream(length, pBuf);\r
+               pBuf[length] = 0;\r
+\r
+               *pStr = std::string(pBuf);\r
+               delete[] pBuf;\r
+       }\r
+       \r
+       void read(std::string& str)\r
+       {\r
+               read(&str);\r
+       }\r
+\r
+       template < typename T >\r
+       void read (std::list<T>& list) \r
+       {\r
+               int length;\r
+               read(length);\r
+               for (int i =0; i < length; ++i) \r
+               {\r
+                       T obj;\r
+                       read (obj);\r
+                       list.push_back(obj);\r
+               }\r
+       }\r
+\r
+       template < typename T >\r
+       void read (std::list<T>* pList) \r
+       {\r
+               read(*pList);\r
+       }\r
+\r
+       template < typename K, typename P >\r
+       void read (std::pair<K, P>& pair) \r
+       {\r
+               read( pair.first);\r
+               read( pair.second);\r
+       }\r
+\r
+       template < typename K, typename P >\r
+       void read (std::pair<K, P>* pPair) \r
+       {\r
+               read( *pPair);\r
+       }\r
+\r
+       template<typename T, typename ...Args>\r
+       void write(const T& in, const Args&... args)\r
+       {\r
+               write(in);\r
+               write(args...);\r
+       }\r
+\r
+       void write(const std::string& in)\r
+       {\r
+               int length = in.size();\r
+               m_socketStream.writeStream(sizeof(length), &length);\r
+               m_socketStream.writeStream(length, in.c_str());\r
+       }\r
+       \r
+       void write(const unsigned int& in)\r
+       {\r
+               int length = sizeof(in);\r
+               m_socketStream.writeStream(sizeof(length), &length);\r
+               m_socketStream.writeStream(length, &in);\r
+       }\r
+\r
+       void write(const int& in)\r
+       {\r
+               int length = sizeof(in);\r
+               m_socketStream.writeStream(sizeof(length), &length);\r
+               m_socketStream.writeStream(length, &in);\r
+       }\r
+\r
+       void write(const bool& in)\r
+       {\r
+               int length = sizeof(in);\r
+               m_socketStream.writeStream(sizeof(length), &length);\r
+               m_socketStream.writeStream(length, &in);\r
+       }\r
+\r
+       void write(const char*& in)\r
+       {\r
+               int length = strlen(in);\r
+               m_socketStream.writeStream(sizeof(length), &length);\r
+               m_socketStream.writeStream(length, in);\r
+       }\r
+\r
+       template<typename T, typename ...Args>\r
+       void write(const T* in, const Args&... args)\r
+       {\r
+               write(in);\r
+               write(args...);\r
+       }\r
+\r
+       template<typename K, typename T>\r
+       void write(const std::pair<K, T> p)\r
+       {\r
+               write(p.first);\r
+               write(p.second);\r
+       }\r
+\r
+       template<typename K, typename T>\r
+       void write(const std::pair<K, T&> p) \r
+       {\r
+               write(p.first);\r
+               write(p.second);\r
+       }\r
+\r
+       template<typename K, typename T>\r
+       void write(const std::pair<K, T&>* pPair) \r
+       {\r
+               write(*pPair);\r
+       }\r
+\r
+       template<typename T>\r
+       void write(const std::list <T> list) \r
+       {\r
+               int length = list.size();\r
+               write(length);\r
+               for (typename std::list <T>::const_iterator iter = list.begin(); iter != list.end(); iter++)\r
+                       write(*iter);\r
+       }\r
+\r
+       template<typename T>\r
+       void write(const std::list <T>* pList) \r
+       {\r
+               write(*pList);\r
+       }\r
+\r
+\r
+private:\r
+       SocketStream m_socketStream;\r
+};\r
+\r
+#endif // _SOCKET_CONNECTION_H_\r
diff --git a/common/inc/SocketStream.h b/common/inc/SocketStream.h
new file mode 100644 (file)
index 0000000..c99aafd
--- /dev/null
@@ -0,0 +1,43 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _SOCKET_STREAM_H_\r
+#define _SOCKET_STREAM_H_\r
+\r
+#include <string>\r
+#include <PrivacyManagerTypes.h>\r
+\r
+class EXTERN_API SocketStream\r
+{\r
+public:\r
+       explicit SocketStream(int socket_fd) \r
+               : m_socketFd(socket_fd)\r
+               , m_bytesRead(0)\r
+               ,m_bytesWrote(0)\r
+       {\r
+               LOGI("Created");\r
+       }\r
+\r
+       int readStream(size_t num, void * bytes);\r
+       int writeStream(size_t num, const void * bytes);\r
+private:\r
+       int throwWithErrnoMessage(std::string specificInfo);\r
+       int m_socketFd;\r
+       int m_bytesRead;\r
+       int m_bytesWrote;\r
+};\r
+\r
+#endif //_SOCKET_STREAM_H_
\ No newline at end of file
diff --git a/common/inc/Utils.h b/common/inc/Utils.h
new file mode 100644 (file)
index 0000000..d499231
--- /dev/null
@@ -0,0 +1,69 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _UTILS_H_\r
+#define _UTILS_H_\r
+\r
+#include <vector>\r
+#include <iostream>\r
+#include <algorithm>\r
+#include <dlog.h>\r
+#include <sqlite3.h>\r
+\r
+\r
+#define        TryCatchLogReturn(condition, expr, r, logFormat)        if (!(condition)) { \\r
+               LOGE(logFormat); \\r
+               expr; \\r
+               return r; \\r
+       } else {;}\r
+\r
+#define        TryCatchResLogReturn(condition, expr, r, logFormat, res)        if (!(condition)) { \\r
+               LOGE(logFormat, res); \\r
+               expr; \\r
+               return r; \\r
+       } else {;}\r
+\r
+\r
+#define TryReturn(condition, r, expr, ...) \\r
+       if ( !(condition) ) { \\r
+               LOGE(__VA_ARGS__); \\r
+               expr; \\r
+               return r; \\r
+       } else {;}\r
+\r
+auto StmtDeleter = [&](sqlite3_stmt* pPtr) { LOGI("sqlite3_finalize"); sqlite3_reset (pPtr); sqlite3_finalize(pPtr); };\r
+auto DbDeleter = [&](sqlite3* pPtr) { LOGI("sqlite3_close"); sqlite3_close(pPtr); };\r
+\r
+#define setStmtToUniquePtr(x, y)               std::unique_ptr < sqlite3_stmt, decltype(StmtDeleter) > x (y, StmtDeleter);\r
+#define setDbToUniquePtr(x, y)                 std::unique_ptr < sqlite3, decltype(DbDeleter) > x (y, DbDeleter);\r
+\r
+#define openDb(dbpath, pHandler, mode) sqlite3* pHandler##Temp = NULL;\\r
+       {\\r
+               LOGI("sqlite3_open_v2");\\r
+               int res = sqlite3_open_v2(dbpath, &pHandler##Temp, mode , NULL);\\r
+               TryCatchResLogReturn( res == SQLITE_OK, , PRIV_MGR_ERROR_DB_ERROR, "sqlite3_open : %d", res);\\r
+       }\\r
+       setDbToUniquePtr(pHandler, pHandler##Temp);\\r
+       \r
+#define prepareDb(pHandler, sql, pStmt)        sqlite3_stmt* pStmt##Temp;\\r
+       {\\r
+               LOGI("sqlite3_prepare_v2");\\r
+               int res = sqlite3_prepare_v2(pHandler.get(), sql, -1, & pStmt##Temp, NULL);\\r
+               TryCatchResLogReturn( res == SQLITE_OK, , PRIV_MGR_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);\\r
+       }\\r
+       setStmtToUniquePtr(pStmt, pStmt##Temp);\r
+\r
+#endif //_UTILS_H_\r
diff --git a/common/inc/privacy_manager_client_types.h b/common/inc/privacy_manager_client_types.h
new file mode 100644 (file)
index 0000000..a368742
--- /dev/null
@@ -0,0 +1,49 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the License);\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an AS IS BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License. \r
+ */\r
+\r
+#ifndef __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H\r
+#define __TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#ifndef EXTERN_API\r
+#define EXTERN_API __attribute__((visibility("default")))\r
+#endif\r
+\r
+enum {\r
+       PRIV_MGR_ERROR_SUCCESS = 0,\r
+\r
+       PRIV_MGR_ERROR_NOT_INITIALIZED = -10,\r
+       PRIV_MGR_ERROR_INVALID_PARAMETER = -11,\r
+       PRIV_MGR_ERROR_OUT_OF_MEMORY = -12,\r
+       PRIV_MGR_ERROR_IO_ERROR = -13,\r
+       PRIV_MGR_ERROR_NO_DATA = -14,\r
+       PRIV_MGR_ERROR_DB_ERROR = -15,\r
+       PRIV_MGR_ERROR_IPC_ERROR = -16,\r
+       PRIV_MGR_ERROR_INVALID_STATE = -17,\r
+       PRIV_MGR_ERROR_SYSTEM_ERROR = -18,\r
+\r
+       PRIV_MGR_ERROR_UNKNOWN = -(0x99),\r
+};\r
+\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif //__TIZEN_PRIVACYMGR_PRIVACY_MANAGER_CLIENT_TYPES_H\r
diff --git a/common/src/SocketConnection.cpp b/common/src/SocketConnection.cpp
new file mode 100644 (file)
index 0000000..45f51fc
--- /dev/null
@@ -0,0 +1,25 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include "SocketConnection.h"\r
+\r
+//\r
+// Note:\r
+//\r
+// The file here is left blank to enable precompilation\r
+// of templates in corresponding header file.\r
+// Do not remove this file.\r
+//\r
diff --git a/common/src/SocketStream.cpp b/common/src/SocketStream.cpp
new file mode 100644 (file)
index 0000000..834f132
--- /dev/null
@@ -0,0 +1,173 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+\r
+#include <sys/socket.h>\r
+#include <sys/select.h>\r
+#include <errno.h>\r
+#include <cstring>\r
+#include <unistd.h>\r
+#include <dlog.h>\r
+#include <Utils.h>\r
+#include "SocketStream.h"\r
+\r
+#define READ_TIEMOUT_SEC 1\r
+#define READ_TIMEUOT_NSEC 0\r
+#define WRITE_TIMEOUT_SEC 0\r
+#define WRITE_TIMEOUT_NSEC 100000000\r
+#define MAX_BUFFER 10240\r
+\r
+int\r
+SocketStream::throwWithErrnoMessage(std::string function_name)\r
+{\r
+       LOGE("%s : %s", function_name.c_str(), strerror(errno));\r
+       return errno;\r
+}\r
+\r
+int\r
+SocketStream::readStream(size_t num, void* pBytes)\r
+{\r
+       TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");\r
+\r
+       m_bytesRead += num;\r
+       \r
+       TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");\r
+\r
+       char partBuffer[MAX_BUFFER];\r
+       std::string wholeBuffer;\r
+\r
+       fd_set rset, allset;\r
+       int maxFd;\r
+       ssize_t bytesRead = 0;\r
+       ssize_t bytesToRead = (ssize_t) num;\r
+\r
+       timespec timeout;\r
+\r
+       maxFd = m_socketFd;\r
+       ++maxFd;\r
+\r
+       FD_ZERO(&allset);\r
+       FD_SET(m_socketFd, &allset);\r
+\r
+       int ret = -1;\r
+\r
+       while(bytesToRead != 0)\r
+       {\r
+               timeout.tv_sec = READ_TIEMOUT_SEC;\r
+               timeout.tv_nsec = READ_TIMEUOT_NSEC;\r
+               rset = allset;\r
+\r
+               if ( (ret = pselect(maxFd, &rset, NULL, NULL, &timeout, NULL)) == -1 )\r
+               {\r
+                       if (errno == EINTR)\r
+                               continue;\r
+                       LOGD("pselect : %s", strerror(errno));\r
+                       return -1;\r
+               }       \r
+               //This means pselect got timedout\r
+               //This is not a proper behavior in reading data from UDS\r
+               //And could mean we got corrupted connection\r
+               TryReturn(ret != 0, -1, , "Couldn't read whole data");\r
+\r
+               if ( FD_ISSET(m_socketFd, &rset) )\r
+               {\r
+                       bytesRead = read(m_socketFd, partBuffer, num);\r
+                       if ( bytesRead <= 0 )\r
+                       {\r
+                               if(errno == ECONNRESET || errno == ENOTCONN || errno == ETIMEDOUT)\r
+                               {\r
+                                       LOGI("Connection closed : %s", strerror(errno));\r
+                                       return -1;\r
+                               }\r
+                               else if (errno != EAGAIN && errno != EWOULDBLOCK){\r
+                                       LOGI("read()");\r
+                                       return -1;\r
+                               }\r
+                       }\r
+\r
+                       wholeBuffer.append(partBuffer, bytesRead);\r
+                       bytesToRead -= bytesRead;\r
+                       bytesRead = 0;\r
+                       continue;\r
+               }\r
+\r
+       }\r
+       memcpy(pBytes, wholeBuffer.c_str(), num);\r
+       \r
+       return 0;\r
+}\r
+\r
+int\r
+SocketStream::writeStream(size_t num, const void* pBytes)\r
+{\r
+       TryReturn(pBytes != NULL, -1, , "Null pointer to buffer");\r
+       \r
+       m_bytesWrote += num;\r
+       \r
+       TryReturn(m_bytesRead <= MAX_BUFFER, -1, , "Too big buffer requested!");\r
+\r
+       fd_set wset, allset;\r
+       int maxFd;\r
+\r
+       timespec timeout;\r
+\r
+       maxFd = m_socketFd;\r
+       ++maxFd;\r
+\r
+       FD_ZERO(&allset);\r
+       FD_SET(m_socketFd, &allset);\r
+\r
+       int res;\r
+       int writeRes;\r
+       int bytesToWrite = num;\r
+       unsigned int currentOffset = 0;\r
+\r
+       while(currentOffset != num)\r
+       {\r
+               timeout.tv_sec = WRITE_TIMEOUT_SEC;\r
+               timeout.tv_nsec = WRITE_TIMEOUT_NSEC;\r
+               wset = allset;\r
+\r
+               if ( (res = pselect(maxFd, NULL, &wset, NULL, &timeout, NULL)) == -1 )\r
+               {\r
+                       if(errno == EINTR)\r
+                               continue;\r
+                       LOGD("pselect : %s", strerror(errno));\r
+                       return -1;\r
+               }\r
+\r
+               if(FD_ISSET(m_socketFd, &wset))\r
+               {\r
+                       if ( (writeRes = write(m_socketFd, reinterpret_cast<const char *>(pBytes) + currentOffset, bytesToWrite)) == -1)\r
+                       {\r
+                               if(errno == ECONNRESET || errno == EPIPE)\r
+                               {\r
+                                       LOGI("Connection closed : %s", strerror(errno));\r
+                                       return -1;\r
+\r
+                               }\r
+                               else if(errno != EAGAIN && errno != EWOULDBLOCK)\r
+                               {\r
+                                       LOGE("write()");\r
+                                       return -1;\r
+                               }\r
+                       }\r
+                       currentOffset += writeRes;\r
+                       bytesToWrite -= writeRes;\r
+               }\r
+       }\r
+       return 0;\r
+}
\ No newline at end of file
diff --git a/packaging/capi-security-privacy-manager.manifest b/packaging/capi-security-privacy-manager.manifest
new file mode 100644 (file)
index 0000000..75b0fa5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+    <request>
+        <domain name="_"/>
+    </request>
+</manifest>
diff --git a/packaging/libprivacy-manager-client.manifest b/packaging/libprivacy-manager-client.manifest
new file mode 100644 (file)
index 0000000..c00c25b
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+        <request>
+                <domain name="_" />
+        </request>
+</manifest>
diff --git a/packaging/priavcy-manager.manifest b/packaging/priavcy-manager.manifest
new file mode 100644 (file)
index 0000000..05112a1
--- /dev/null
@@ -0,0 +1,12 @@
+<manifest>
+        <define>
+                <domain name="policy-manager" />
+                <provide>
+                        <label name="policy-manager::daemon" />
+                        <label name="policy-manager::db" />
+                </provide>
+        </define>
+        <request>
+                <domain name="_" />
+        </request>
+</manifest>
diff --git a/packaging/privacy-manager-client.manifest b/packaging/privacy-manager-client.manifest
new file mode 100644 (file)
index 0000000..c00c25b
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+        <request>
+                <domain name="_" />
+        </request>
+</manifest>
diff --git a/packaging/privacy-manager-server.manifest b/packaging/privacy-manager-server.manifest
new file mode 100644 (file)
index 0000000..05112a1
--- /dev/null
@@ -0,0 +1,12 @@
+<manifest>
+        <define>
+                <domain name="policy-manager" />
+                <provide>
+                        <label name="policy-manager::daemon" />
+                        <label name="policy-manager::db" />
+                </provide>
+        </define>
+        <request>
+                <domain name="_" />
+        </request>
+</manifest>
diff --git a/packaging/privacy-manager-server.service b/packaging/privacy-manager-server.service
new file mode 100644 (file)
index 0000000..2e7a99c
--- /dev/null
@@ -0,0 +1,9 @@
+
+[Unit]
+Description=privacy manager server
+
+[Service]
+ExecStart=/usr/bin/privacy-manager-server
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packaging/privacy-manager.spec b/packaging/privacy-manager.spec
new file mode 100644 (file)
index 0000000..f1af038
--- /dev/null
@@ -0,0 +1,168 @@
+Name:    privacy-manager-server
+Summary: Privacy Management
+Version: 0.0.2
+Release: 1
+Group:   System/Libraries
+License: SAMSUNG
+Source0: %{name}-%{version}.tar.gz
+Source1: privacy-manager-server.manifest
+Source2: privacy-manager-client.manifest
+Source3: privacy-manager-server.service
+Source4: capi-security-privacy-manager.manifest
+BuildRequires: cmake
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(dbus-1)
+BuildRequires: pkgconfig(dbus-glib-1)
+
+Requires(post):   /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+provides: privacy-manager-server
+
+%description
+Privacy Management
+
+%package -n privacy-manager-server-devel
+summary: privacy-manager server
+Group: Development/Libraries
+Requires: privacy-manager-server = %{version}-%{release}
+
+%description -n privacy-manager-server-devel
+privacy-manager server devel
+
+%package -n privacy-manager-client
+summary: privacy-manager client
+Group: Development/Libraries
+Requires: privacy-manager-server = %{version}-%{release}
+
+provides: libprivacy-manager-client.so.1
+
+%description -n privacy-manager-client
+privacy-manager client
+
+%package -n privacy-manager-client-devel
+Summary:    privacy-manager client devel
+Group:      Development/Libraries
+Requires:   privacy-manager-client = %{version}-%{release}
+
+%description -n privacy-manager-client-devel
+Privacy Management(development files)
+
+#%package -n capi-security-privacy-manager
+#Summary:    Privacy Manager API
+#Version:    0.0.1
+#Release:    0
+#Group:      TO_BE/FILLED_IN
+#License:    TO BE FILLED IN
+#BuildRequires:  cmake
+#BuildRequires:  pkgconfig(dlog)
+#BuildRequires:  pkgconfig(capi-base-common)
+#BuildRequires:  pkgconfig(glib-2.0)
+#Requires(post): /sbin/ldconfig  
+#Requires(postun): /sbin/ldconfig
+
+#%description -n capi-security-privacy-manager
+#The Privacy Manager API provides functions to get/set information about privacy information of installed packages.
+
+#%package  -n capi-security-privacy-manager-devel
+#Summary:  Privacy Manager API (Development)
+#Group:    TO_BE/FILLED_IN
+#Requires: %{name} = %{version}-%{release}
+
+#%description -n capi-security-privacy-manager-devel
+#The Privacy Manager API provides functions to get/set information about privacy information of installed packages.(DEV)
+
+%prep
+%setup -q
+
+%build
+#%{!?build_type:%define build_type "Release"}
+echo cmake . -DPREFIX=%{_prefix} \
+        -DEXEC_PREFIX=%{_exec_prefix} \
+        -DLIBDIR=%{_libdir} \
+        -DINCLUDEDIR=%{_includedir} \
+        -DCMAKE_BUILD_TYPE=%{build_type}
+cmake . -DPREFIX=%{_prefix} \
+        -DEXEC_PREFIX=%{_exec_prefix} \
+        -DLIBDIR=%{_libdir} \
+        -DINCLUDEDIR=%{_includedir} \
+        -DCMAKE_BUILD_TYPE=%{build_type}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
+mkdir -p %{buildroot}/usr/share/license
+cp LICENSE.APLv2 %{buildroot}/usr/share/license/privacy-manager-client
+mkdir -p %{buildroot}/usr/bin
+cp res/usr/bin/* %{buildroot}/usr/bin/
+#mkdir -p %{buildroot}/etc/rc.d/init.d
+#cp res/etc/rc.d/init.d/* %{buildroot}/etc/rc.d/init.d/
+
+%make_install -n privacy-manager-client
+install -D %{SOURCE2} %{buildroot}%{_datadir}/privacy-manager-client.manifest
+
+%make_install -n privacy-manager-server
+install -D %{SOURCE1} %{buildroot}%{_datadir}/privacy-manager-server.manifest
+
+#%make_install -n capi-security-privacy-manager
+#install -D %{SOURCE4} %{buildroot}%{_datadir}/capi-security-privacy-manager.manifest
+
+#mkdir -p %{buildroot}/etc/rc.d/rc3.d
+#mkdir -p %{buildroot}/etc/rc.d/rc5.d
+#ln -sf /etc/rc.d/init.d/wrt-security-daemon.sh %{buildroot}/etc/rc.d/rc3.d/S10privacy-manager-server.sh
+#ln -sf /etc/rc.d/init.d/wrt-security-daemon.sh %{buildroot}/etc/rc.d/rc5.d/S10privacy-manager-server.sh
+
+mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants
+install -m 0644 %{SOURCE3} %{buildroot}%{_libdir}/systemd/system/privacy-manager-server.service
+ln -sf /usr/lib/systemd/system/privacy-manager-server.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/privacy-manager-server.service
+
+%clean
+rm -rf %{buildroot}
+
+%post
+/sbin/ldconfig
+
+if [ ! -f /opt/dbspace/.ace.db ]
+then
+       /usr/bin/privacy_manager_create_clean_db.sh
+fi
+
+%postun
+/sbin/ldconfig
+
+%files -n privacy-manager-server
+%defattr(-,root,root,-)
+%manifest %{_datadir}/%{name}.manifest
+%{_bindir}/*
+%{_libdir}/systemd/*
+#%{_libdir}/etc/rc.d/init.d/privacy-manager-server.sh
+#%attr(755,root,root) /etc/rc.d/init.d/privacy-manager-server.sh
+#/etc/rc.d/rc3.d/S10privacy-manager-server.sh
+#/etc/rc.d/rc5.d/S10privacy-manager-server.sh
+/usr/share/license/privacy-manager-server
+
+%files -n privacy-manager-client
+%defattr(-,root,root,-)
+%manifest %{_datadir}/privacy-manager-client.manifest
+%{_libdir}/*.so*
+/usr/share/license/privacy-manager-client
+
+%files -n privacy-manager-client-devel
+%defattr(-,root,root,-)
+%{_includedir}/*
+%{_libdir}/pkgconfig/*
+
+#%files -n capi-security-privacy-manager
+#%{_libdir}/libcapi-security-privacy-manager.so.*
+#%manifest %{_datadir}/capi-security-privacy-manager.manifest
+
+#%files -n capi-security-privacy-manager-devel
+#%{_includedir}/privacymgr/*.h
+#%{_libdir}/libcapi-security-privacy-manager.so
+#%{_libdir}/pkgconfig/*.pc
+
diff --git a/privacy-manager-client.pc.in b/privacy-manager-client.pc.in
new file mode 100644 (file)
index 0000000..4c6d5c4
--- /dev/null
@@ -0,0 +1,9 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=/usr/lib/privacy_manager
+
+Name: privacy-manager-client
+Description: Privacy Manager Client
+Version: @VERSION@
+Requires: 
diff --git a/privacy-manager-server.pc.in b/privacy-manager-server.pc.in
new file mode 100644 (file)
index 0000000..0bba87a
--- /dev/null
@@ -0,0 +1,9 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: privacy-manager-server
+Description: Privacy Manager Server
+Version: @VERSION@
+Requires: 
diff --git a/privacy-manager-test.pc.in b/privacy-manager-test.pc.in
new file mode 100644 (file)
index 0000000..0bba87a
--- /dev/null
@@ -0,0 +1,9 @@
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: privacy-manager-server
+Description: Privacy Manager Server
+Version: @VERSION@
+Requires: 
diff --git a/res/etc/rc.d/init.d/privacy-manager-server.sh b/res/etc/rc.d/init.d/privacy-manager-server.sh
new file mode 100644 (file)
index 0000000..89303a1
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+/usr/bin/privacy-manager-server &
+set_pmon -p privacy-manager-server
diff --git a/res/usr/bin/privacy_db.sql b/res/usr/bin/privacy_db.sql
new file mode 100644 (file)
index 0000000..5b16806
--- /dev/null
@@ -0,0 +1,25 @@
+PRAGMA foreign_keys = ON; BEGIN TRANSACTION;
+
+CREATE TABLE PackageInfo(
+    UNIQUE_ID INTEGER PRIMARY KEY AUTOINCREMENT,
+    PKG_ID TEXT not null,
+    IS_SET BOOL not null,
+CHECK(1) );
+
+CREATE TABLE Privacy(
+    ID INTEGER not null,
+    PRIVACY_ID TEXT not null,
+    IS_ENABLED INTEGER not null,
+    FOREIGN KEY(ID) REFERENCES PackageInfo(UNQUE_ID),
+CHECK(1) );
+
+CREATE VIEW PrivacyView as SELECT 
+    PackageInfo.UNIQUE_ID, 
+    PackageInfo.PKG_ID, 
+    Privacy.PRIVACY_ID, 
+    Privacy.IS_ENABLED 
+    FROM PackageInfo, Privacy 
+    WHERE PackageInfo.UNIQUE_ID = Privacy.ID;
+COMMIT;
+BEGIN TRANSACTION; 
+CREATE TABLE DB_VERSION_0_1 (version INT); COMMIT;
diff --git a/res/usr/bin/privacy_manager_create_clean_db.sh b/res/usr/bin/privacy_manager_create_clean_db.sh
new file mode 100755 (executable)
index 0000000..3d0af6e
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+#
+#    Licensed under the Apache License, Version 2.0 (the "License");
+#    you may not use this file except in compliance with the License.
+#    You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS,
+#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#    See the License for the specific language governing permissions and
+#    limitations under the License.
+#
+for name in privacy
+do
+    rm -f /opt/dbspace/.$name.db
+    rm -f /opt/dbspace/.$name.db-journal
+    SQL="PRAGMA journal_mode = PERSIST;"
+    sqlite3 /opt/dbspace/.$name.db "$SQL"
+    SQL=".read /usr/bin/"$name"_db.sql"
+    sqlite3 /opt/dbspace/.$name.db "$SQL"
+    touch /opt/dbspace/.$name.db-journal
+    chown 0:0 /opt/dbspace/.$name.db
+    chown 0:0 /opt/dbspace/.$name.db-journal
+    chmod 660 /opt/dbspace/.$name.db
+    chmod 660 /opt/dbspace/.$name.db-journal
+done
+
+
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a0f2d39
--- /dev/null
@@ -0,0 +1,84 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(privacy-manager)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 0.0)
+
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.0.1")
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dlog sqlite3 dbus-1 dbus-glib-1)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS_PROFILING    " -g -pg")
+SET(CMAKE_CXX_FLAGS_PROFILING  " -std=c++0x -g -pg")
+SET(CMAKE_C_FLAGS_DEBUG        " -g")
+SET(CMAKE_CXX_FLAGS_DEBUG      " -std=c++0x -g")
+SET(CMAKE_C_FLAGS_RELEASE      " -g")
+SET(CMAKE_CXX_FLAGS_RELEASE    " -std=c++0x -g")
+SET(CMAKE_C_FLAGS_CCOV         " -g --coverage")
+SET(CMAKE_CXX_FLAGS_CCOV       " -std=c++0x -g --coverage")
+
+SET(server_src_dir "${CMAKE_SOURCE_DIR}/server/src")
+SET(server_include_dir "${CMAKE_SOURCE_DIR}/server/inc/")
+SET(common_src_dir "${CMAKE_SOURCE_DIR}/common/src/")
+SET(common_include_dir "${CMAKE_SOURCE_DIR}/common/inc/")
+SET(dbus_include_dir "/usr/include/dbus-1.0")
+
+## Additional flag
+ADD_DEFINITIONS("-fvisibility=hidden")
+ADD_DEFINITIONS("-Wall -Werror")
+ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
+
+###################################################################################################
+## for privacy-manager-server (executable)
+INCLUDE_DIRECTORIES(
+       ${pkgs_INCLUDE_DIRS}
+       ${server_include_dir}
+       ${common_include_dir} 
+       ${dbus_include_dir}
+       )
+
+SET(PRIVACY_MANAGER_SERVER_SOURCES 
+       ${common_src_dir}/SocketConnection.cpp
+       ${common_src_dir}/SocketStream.cpp
+       ${server_src_dir}/main.cpp
+       ${server_src_dir}/SocketService.cpp
+       ${server_src_dir}/PrivacyManagerDaemon.cpp
+       ${server_src_dir}/service/PrivacyInfoService.cpp
+       ${server_src_dir}/service/TestService.cpp
+       ${server_src_dir}/PrivacyManagerServer.cpp
+       ${server_src_dir}/NotificationServer.cpp
+
+       )
+SET(PRIVACY_MANAGER_SERVER_HEADERS
+       ${server_include_dir}/SocketService.h
+       ${server_include_dir}/PrivacyManagerDaemon.h
+       ${common_include_dir}/SocketConnection.h
+       ${common_include_dir}/SocketConnection.h
+)
+SET(PRIVACY_MANAGER_SERVER_LDFLAGS " -module -avoid-version ")
+SET(PRIVACY_MANAGER_SERVER_CFLAGS  " ${CFLAGS} -fPIC ")
+#SET(PRIVACY_MANAGER_SERVER_LIBADD " ")
+
+ADD_DEFINITIONS("-DLOG_TAG=\"PRIVACY-MANAGER-SERVER\"")
+ADD_EXECUTABLE(privacy-manager-server ${PRIVACY_MANAGER_SERVER_SOURCES})
+TARGET_LINK_LIBRARIES(privacy-manager-server ${pkgs_LDFLAGS} ${pkgs_LIBRARIES})
+SET_TARGET_PROPERTIES(privacy-manager-server PROPERTIES COMPILE_FLAGS "${PRIVACY_MANAGER_SERVER_CFLAGS}")
+#SET_TARGET_PROPERTIES(privacy-manager-server PROPERTIES SOVERSION ${VERSION_MAJOR})
+#SET_TARGET_PROPERTIES(privacy-manager-server PROPERTIES VERSION ${VERSION})
+###################################################################################################
+
+CONFIGURE_FILE(../privacy-manager-server.pc.in privacy-manager-server.pc @ONLY)
+
+INSTALL(TARGETS privacy-manager-server DESTINATION ../bin COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-manager-server.pc DESTINATION ../lib/pkgconfig)
+INSTALL(FILES ${PRIVACY_MANAGER_SERVER_HEADERS} DESTINATION ../include/privacy_manager/server)
\ No newline at end of file
diff --git a/server/inc/NotificationServer.h b/server/inc/NotificationServer.h
new file mode 100644 (file)
index 0000000..ea18277
--- /dev/null
@@ -0,0 +1,41 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _NOTIFICATION_SERVER_H_\r
+#define _NOTIFICATION_SERVER_H_\r
+\r
+#include <string>\r
+#include <memory>\r
+#include <list>\r
+#include <sqlite3.h>\r
+#include <mutex>\r
+#include <dbus/dbus.h>\r
+\r
+class NotificationServer\r
+{\r
+private:\r
+       bool m_initialized;\r
+       DBusConnection* m_pDBusConnection;\r
+public:\r
+\r
+       NotificationServer(void);\r
+       ~NotificationServer(void);\r
+       int initialize(void);\r
+       int notify(const std::string pkgId, const std::string privacyId);\r
+};\r
+\r
+\r
+#endif // _NOTIFICATION_SERVER_H_
\ No newline at end of file
diff --git a/server/inc/PrivacyInfoService.h b/server/inc/PrivacyInfoService.h
new file mode 100644 (file)
index 0000000..5a9c8f8
--- /dev/null
@@ -0,0 +1,61 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_INFO_SERVICE_H_\r
+#define _PRIVACY_INFO_SERVICE_H_\r
+\r
+#include <SocketConnection.h>\r
+#include <SocketService.h>\r
+\r
+class PrivacyInfoService {\r
+private:\r
+       inline static std::string getInterfaceName(void)\r
+       {\r
+               return "PrivacyInfoService";\r
+       }\r
+\r
+public:\r
+       static void registerCallbacks(SocketService* pSocketService)\r
+       {\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("addPrivacyInfo"), addPrivacyInfo);\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("removePrivacyInfo"), removePrivacyInfo);\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("setPrivacySetting"), setPrivacySetting);\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("getPrivacyAppPackages"), getPrivacyAppPackages);\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("getAppPackagePrivacyInfo"), getAppPackagePrivacyInfo);\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("isUserPrompted"), isUserPrompted);\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("setUserPrompted"), setUserPrompted);\r
+       }\r
+\r
+       static void addPrivacyInfo(SocketConnection* pConnector);\r
+\r
+       static void removePrivacyInfo(SocketConnection* pConnector);\r
+\r
+       static void setPrivacySetting(SocketConnection* pConnector);\r
+       \r
+       // input message format\r
+       // interface_name(str) | method_name(str)\r
+       // output message format\r
+       // result (int) | list size (int) | serialized package list (using delimeter)\r
+       static void getPrivacyAppPackages(SocketConnection* pConnector);\r
+\r
+       static void getAppPackagePrivacyInfo(SocketConnection* pConnector);\r
+\r
+       static void isUserPrompted(SocketConnection* pConnector);\r
+       \r
+       static void setUserPrompted(SocketConnection* pConnector);\r
+\r
+};\r
+#endif // _PRIVACY_INFO_SERVICE_H_
\ No newline at end of file
diff --git a/server/inc/PrivacyManagerDaemon.h b/server/inc/PrivacyManagerDaemon.h
new file mode 100644 (file)
index 0000000..327df52
--- /dev/null
@@ -0,0 +1,41 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_MANAGER_DAEMON_H_\r
+#define _PRIVACY_MANAGER_DAEMON_H_\r
+\r
+#include <SocketService.h>\r
+\r
+class PrivacyManagerDaemon\r
+{\r
+private:\r
+       static PrivacyManagerDaemon* pInstance;\r
+       SocketService* pSocketService;\r
+\r
+private:\r
+       PrivacyManagerDaemon(void);\r
+       ~PrivacyManagerDaemon(void);\r
+\r
+\r
+public:\r
+       static PrivacyManagerDaemon* getInstance(void);\r
+       int inialize(void);\r
+       int start(void);\r
+       int stop(void);\r
+       int shutdown(void);\r
+};\r
+\r
+#endif // _PRIVACY_MANAGER_DAEMON_H_
\ No newline at end of file
diff --git a/server/inc/PrivacyManagerServer.h b/server/inc/PrivacyManagerServer.h
new file mode 100644 (file)
index 0000000..c9a7689
--- /dev/null
@@ -0,0 +1,72 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _PRIVACY_DB_H_\r
+#define _PRIVACY_DB_H_\r
+\r
+#include <string>\r
+#include <memory>\r
+#include <list>\r
+#include <mutex>\r
+#include <sqlite3.h>\r
+#include <NotificationServer.h>\r
+\r
+class NotificationServer;\r
+struct sqlite3;\r
+class a;\r
+class PrivacyManagerServer\r
+{\r
+private:\r
+       static std::mutex m_singletonMutex;\r
+       static const std::string DB_PATH;\r
+       static PrivacyManagerServer* m_pInstance;\r
+       sqlite3* m_pDBHandler;\r
+       NotificationServer m_notificationServer;\r
+\r
+       const static std::string CREATE_PACKAGE_INFO_TABLE;\r
+       const static std::string CREATE_PRIVACY_TABLE;\r
+\r
+private:\r
+       void createDB(void);\r
+       int isPackageIdAreadyExisted(const std::string pkgId, bool& isExisted);\r
+\r
+public:\r
+\r
+       explicit PrivacyManagerServer(void);\r
+\r
+       static PrivacyManagerServer* getInstance(void);\r
+\r
+       sqlite3* getDBHandler(void);\r
+\r
+       int getUniqueIdFromPackageId(const std::string pkgId, int& id);\r
+\r
+       int getPrivacyAppPackages(std::list <std::string>& list);\r
+\r
+       int getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > > *pList);\r
+\r
+       int setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled);\r
+\r
+       int addAppPackagePrivacyInfo(const std::string pkgcId, const std::list < std::string > privilegeList);\r
+\r
+       int removeAppPackagePrivacyInfo(const std::string pkgId);\r
+\r
+       int isUserPrompted(const std::string pkgId, bool& isPrompted);\r
+\r
+       int setUserPrompted(const std::string pkgId, bool prompted);\r
+};\r
+\r
+\r
+#endif // _PRIVACY_DB_H_
\ No newline at end of file
diff --git a/server/inc/SocketService.h b/server/inc/SocketService.h
new file mode 100644 (file)
index 0000000..1615ccd
--- /dev/null
@@ -0,0 +1,84 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _SOCKET_SERVICE_H_\r
+#define _SOCKET_SERVICE_H_\r
+\r
+#include <string>\r
+#include <mutex>\r
+#include <list>\r
+#include <map>\r
+#include <memory>\r
+#include <pthread.h>\r
+#include <SocketConnection.h>\r
+\r
+typedef void(*socketServiceCallback)(SocketConnection* pConnector);\r
+\r
+class SocketService\r
+{\r
+       struct ConnectionInfo{\r
+               ConnectionInfo(int fd, void* pData) : connFd(fd), pData(pData) {}\r
+               int connFd;\r
+               void* pData;\r
+       };\r
+       class ServiceCallback\r
+       {\r
+       public:\r
+               ServiceCallback(socketServiceCallback callback)\r
+                       : serviceCallback(callback)\r
+               {}\r
+               socketServiceCallback serviceCallback;\r
+       };\r
+       \r
+private:\r
+       static const int MAX_LISTEN;\r
+       static const int TIMEOUT_SEC;\r
+       static const int TIMEOUT_NSEC;\r
+       int m_listenFd;\r
+       int m_signalToClose;\r
+       pthread_t m_mainThread;\r
+\r
+       typedef std::shared_ptr<ServiceCallback> ServiceCallbackPtr;\r
+       //Map for callback methods, key is a method name and value is a callback to method\r
+       typedef std::map<std::string, ServiceCallbackPtr> ServiceMethodCallbackMap;\r
+       //Map for interface methods, key is an interface name and value is a map of available methods with callbacks\r
+       std::map <std::string, ServiceMethodCallbackMap > m_callbackMap;\r
+\r
+       std::list < int > m_clientSocketList;\r
+       std::mutex m_clientSocketListMutex;\r
+\r
+private:\r
+       static void* serverThread(void* );\r
+       static void* connectionThread(void* pData);\r
+       int connectionService(int fd);\r
+       int mainloop(void);\r
+       void closeConnections(void);\r
+\r
+       void addClientSocket(int clientSocket);\r
+       void removeClientSocket(int clientSocket);\r
+       bool popClientSocket(int* pClientSocket);\r
+\r
+public:\r
+       SocketService(void);\r
+       ~SocketService(void);\r
+       int initialize(void);\r
+       int registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod);\r
+       int start(void);\r
+       int stop(void);\r
+       int shutdown(void);\r
+};\r
+\r
+#endif //_SOCKET_SERVICE_H_
\ No newline at end of file
diff --git a/server/inc/TestService.h b/server/inc/TestService.h
new file mode 100644 (file)
index 0000000..1498ce5
--- /dev/null
@@ -0,0 +1,39 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#ifndef _TEST_SERVICE_H_\r
+#define _TEST_SERVICE_H_\r
+\r
+#include <SocketConnection.h>\r
+#include <SocketService.h>\r
+\r
+class TestService {\r
+private:\r
+       inline static std::string getInterfaceName(void)\r
+       {\r
+               return "TestService";\r
+       }\r
+\r
+public:\r
+       static void registerCallbacks(SocketService* pSocketService)\r
+       {\r
+               pSocketService->registerServiceCallback(getInterfaceName(), std::string("test"), test);\r
+       }\r
+\r
+       static void test(SocketConnection* pConnector);\r
+\r
+};\r
+#endif // _TEST_SERVICE_H_
\ No newline at end of file
diff --git a/server/src/CMakeLists.txt b/server/src/CMakeLists.txt
new file mode 100644 (file)
index 0000000..3e51c20
--- /dev/null
@@ -0,0 +1,73 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+#PROJECT(privacy-manager-server)
+
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION 0.0)
+
+SET(VERSION_MAJOR 0)
+SET(VERSION "${VERSION_MAJOR}.0.1")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED dlog)
+
+FOREACH(flag ${pkgs_CFLAGS})
+       SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS_PROFILING    " -g -pg")\r
+SET(CMAKE_CXX_FLAGS_PROFILING  " -std=c++0x -g -pg")\r
+SET(CMAKE_C_FLAGS_DEBUG        " -g")\r
+SET(CMAKE_CXX_FLAGS_DEBUG      " -std=c++0x -g")\r
+SET(CMAKE_C_FLAGS_RELEASE      " -g")\r
+SET(CMAKE_CXX_FLAGS_RELEASE    " -std=c++0x -g")\r
+SET(CMAKE_C_FLAGS_CCOV         " -g --coverage")\r
+SET(CMAKE_CXX_FLAGS_CCOV       " -std=c++0x -g --coverage")\r
+
+SET(src_dir "./")
+SET(include_dir "./../inc/")
+SET(common_src_dir "./../../common/src/")
+SET(common_include_dir "./../../common/inc/")
+
+## Additional flag
+ADD_DEFINITIONS("-fvisibility=hidden")
+ADD_DEFINITIONS("-Wall -Werror")
+ADD_DEFINITIONS("-DDLOG_ERROR_ENABLED")
+
+###################################################################################################
+## for libprivacy-manager-server.so (library)
+INCLUDE_DIRECTORIES(${pkgs_INCLUDE_DIRS})
+SET(PRIVACY_MANAGER_SERVER_SOURCES 
+       ${src_dir}/main.cpp
+       ${src_dir}/SocketService.cpp
+       ${src_dir}/PrivacyManagerDaemon.cpp
+       ${common_src_dir}/SocketConnection.cpp
+       ${common_src_dir}/SocketStream.cpp
+       )
+SET(PRIVACY_MANAGER_SERVER_HEADERS
+       ${include_dir}/SocketService.h
+       ${include_dir}/PrivacyManagerDaemon.h
+       ${common_include_dir}/SocketConnection.h
+       ${common_include_dir}/SocketConnection.h
+)
+SET(PRIVACY_MANAGER_SERVER_LDFLAGS " -module -avoid-version ")
+SET(PRIVACY_MANAGER_SERVER_CFLAGS  " ${CFLAGS} -fPIC -I${include_dir}" -I${common_include_dir})
+#SET(PRIVACY_MANAGER_SERVER_LIBADD " ")
+
+ADD_EXECUTABLE(privacy-manager-server ${PRIVACY_MANAGER_SERVER_SOURCES})
+TARGET_LINK_LIBRARIES(privacy-manager-server ${pkgs_LDFLAGS} ${pkgs_LIBRARIES})
+SET_TARGET_PROPERTIES(privacy-manager-server PROPERTIES COMPILE_FLAGS "${PRIVACY_MANAGER_SERVER_CFLAGS}")
+SET_TARGET_PROPERTIES(privacy-manager-server PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(privacy-manager-server PROPERTIES VERSION ${VERSION})
+###################################################################################################
+
+CONFIGURE_FILE(../../privacy-manager-server.pc.in privacy-manager-server.pc @ONLY)
+
+INSTALL(TARGETS privacy-manager-server DESTINATION ../lib COMPONENT RuntimeLibraries)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-manager-server.pc DESTINATION ../lib/pkgconfig)
+INSTALL(FILES ${PRIVACY_MANAGER_SERVER_HEADERS} DESTINATION ../include)
diff --git a/server/src/NotificationServer.cpp b/server/src/NotificationServer.cpp
new file mode 100644 (file)
index 0000000..4f244cc
--- /dev/null
@@ -0,0 +1,97 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+\r
+#include <NotificationServer.h>\r
+#include <dbus/dbus.h>\r
+#include <dbus/dbus-glib-lowlevel.h>\r
+#include <PrivacyManagerTypes.h>\r
+#include <Utils.h>\r
+\r
+auto DBusConnectionDeleter = [&](DBusConnection* pPtr) { dbus_connection_close(pPtr); pPtr = NULL;};\r
+const int MAX_LOCAL_BUF_SIZE = 128;\r
+\r
+NotificationServer::NotificationServer(void)\r
+       : m_initialized(false)\r
+       , m_pDBusConnection(NULL)\r
+{\r
+\r
+}\r
+\r
+NotificationServer::~NotificationServer(void)\r
+{\r
+       if (m_pDBusConnection)\r
+       {\r
+               dbus_connection_close(m_pDBusConnection);\r
+               m_pDBusConnection = NULL;\r
+       }\r
+}\r
+\r
+int\r
+NotificationServer::initialize(void)\r
+{\r
+       if (m_initialized)\r
+               return PRIV_MGR_ERROR_SUCCESS;\r
+       \r
+       DBusError error;\r
+       dbus_error_init(&error);\r
+\r
+       m_pDBusConnection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);\r
+       TryReturn(m_pDBusConnection != NULL, PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_get_private : %s", error.message);\r
+\r
+       dbus_connection_setup_with_g_main(m_pDBusConnection, NULL);\r
+       std::unique_ptr < char[] > pRule(new char[MAX_LOCAL_BUF_SIZE]);\r
+\r
+       snprintf(pRule.get(), MAX_LOCAL_BUF_SIZE, "path='%s',type='signal',interface='%s'", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str());\r
+       LOGD("rule : %s" ,pRule.get());\r
+       dbus_bus_add_match(m_pDBusConnection, pRule.get(), &error);\r
+       TryReturn(!dbus_error_is_set(&error), PRIV_MGR_ERROR_SYSTEM_ERROR, dbus_error_free(&error), "dbus_bus_add_match : %s", error.message);\r
+\r
+       m_initialized = true;\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+NotificationServer::notify(const std::string pkgId, const std::string privacyId)\r
+{\r
+       LOGI("enter");\r
+\r
+       if (!m_initialized)\r
+               return PRIV_MGR_ERROR_INVALID_STATE;\r
+\r
+       char* pPkgId = const_cast <char*> (pkgId.c_str());\r
+       char* pPrivacyId = const_cast <char*> (privacyId.c_str());\r
+       LOGD("path: %s, inter: %s, name: %s", DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_NAME.c_str());\r
+       DBusMessage* pMessage = dbus_message_new_signal(DBUS_PATH.c_str(), DBUS_SIGNAL_INTERFACE.c_str(), DBUS_SIGNAL_NAME.c_str());\r
+       TryReturn(pMessage != NULL, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_new_signal");\r
+\r
+       dbus_bool_t r;\r
+       r = dbus_message_append_args(pMessage,\r
+               DBUS_TYPE_STRING, &pPkgId,\r
+               DBUS_TYPE_STRING, &pPrivacyId,\r
+               DBUS_TYPE_INVALID);\r
+       TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, , "dbus_message_append_args");\r
+\r
+       r = dbus_connection_send(m_pDBusConnection, pMessage, NULL);\r
+       TryReturn(r, PRIV_MGR_ERROR_IPC_ERROR, dbus_message_unref(pMessage);, "dbus_connection_send");\r
+\r
+       dbus_connection_flush(m_pDBusConnection);\r
+       dbus_message_unref(pMessage);\r
+\r
+       LOGI("leave");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}
\ No newline at end of file
diff --git a/server/src/PrivacyManagerDaemon.cpp b/server/src/PrivacyManagerDaemon.cpp
new file mode 100644 (file)
index 0000000..44c9674
--- /dev/null
@@ -0,0 +1,81 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <string>\r
+#include <PrivacyManagerDaemon.h>\r
+#include <PrivacyInfoService.h>\r
+#include <TestService.h>\r
+#include <PrivacyManagerServer.h>\r
+\r
+PrivacyManagerDaemon* PrivacyManagerDaemon::pInstance = NULL;\r
+\r
+PrivacyManagerDaemon::PrivacyManagerDaemon(void)\r
+       : pSocketService(NULL)\r
+{\r
+\r
+}\r
+\r
+PrivacyManagerDaemon::~PrivacyManagerDaemon(void)\r
+{\r
+\r
+}\r
+\r
+PrivacyManagerDaemon*\r
+PrivacyManagerDaemon::getInstance(void)\r
+{\r
+       if (pInstance == NULL)\r
+               pInstance = new PrivacyManagerDaemon();\r
+       PrivacyManagerServer::getInstance();\r
+       return pInstance;\r
+}\r
+\r
+int\r
+PrivacyManagerDaemon::inialize(void)\r
+{\r
+       if (pSocketService == NULL)\r
+               pSocketService = new SocketService();\r
+\r
+       pSocketService->initialize();\r
+\r
+       PrivacyInfoService::registerCallbacks(pSocketService);\r
+       TestService::registerCallbacks(pSocketService);\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerDaemon::start(void)\r
+{\r
+       if (pSocketService == NULL)\r
+               return -1;\r
+       return pSocketService->start();\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerDaemon::stop(void)\r
+{\r
+       pSocketService->stop();\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerDaemon::shutdown(void)\r
+{\r
+       pSocketService->shutdown();\r
+       return 0;\r
+}\r
diff --git a/server/src/PrivacyManagerServer.cpp b/server/src/PrivacyManagerServer.cpp
new file mode 100644 (file)
index 0000000..b95fe31
--- /dev/null
@@ -0,0 +1,352 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <sstream>\r
+#include <PrivacyManagerServer.h>\r
+#include <dlog.h>\r
+#include <Utils.h>\r
+#include <PrivacyManagerTypes.h>\r
+\r
+std::mutex PrivacyManagerServer::m_singletonMutex;\r
+const std::string PrivacyManagerServer::DB_PATH("/opt/dbspace/.privacy.db");\r
+PrivacyManagerServer* PrivacyManagerServer::m_pInstance = NULL;\r
+\r
+void\r
+PrivacyManagerServer::createDB(void)\r
+{\r
+\r
+}\r
+\r
+int\r
+PrivacyManagerServer::isPackageIdAreadyExisted(const std::string pkgId, bool& isExisted)\r
+{\r
+       LOGI("enter");\r
+\r
+       isExisted = false;\r
+\r
+       static const std::string query = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?");\r
+\r
+       int res;\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_prepare_v2 : %d", res);\r
+\r
+       res = sqlite3_step(pStmt.get());\r
+       if (res == SQLITE_DONE)\r
+       {\r
+               isExisted = true;\r
+               return 0;\r
+       }\r
+\r
+       LOGI("leave");\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerServer::getUniqueIdFromPackageId(const std::string pkgId, int& uniqueId)\r
+{\r
+       LOGI("enter");\r
+\r
+       static const std::string query = std::string("SELECT UNIQUE_ID from PackageInfo where PKG_ID=?");\r
+\r
+       int res;\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_prepare_v2 : %d", res);\r
+\r
+       res = sqlite3_step(pStmt.get());\r
+       TryReturn( res == SQLITE_ROW, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+\r
+       int cnt = sqlite3_data_count(pStmt.get());\r
+       TryReturn(cnt != 0, PRIV_MGR_ERROR_NO_DATA, , "Failed to find data");\r
+\r
+       uniqueId = sqlite3_column_int(pStmt.get(), 0);\r
+\r
+       LOGI("%s : %d", pkgId.c_str(), uniqueId);\r
+\r
+       LOGI("leave");\r
+\r
+       return 0;\r
+}\r
+int\r
+PrivacyManagerServer::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool enabled)\r
+{\r
+       LOGI("enter");\r
+\r
+       static const std::string query = std::string("UPDATE Privacy set IS_ENABLED =? where ID=? and PRIVACY_ID=?");\r
+\r
+       int uniqueId;\r
+       int res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
+       TryReturn(res == 0, PRIV_MGR_ERROR_NO_DATA, , "getUniqueIdFromPackageId : %d", res);\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_int(pStmt.get(), 1, enabled);\r
+       TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+       res = sqlite3_bind_int(pStmt.get(), 2, uniqueId);\r
+       TryReturn(res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+       res = sqlite3_bind_text(pStmt.get(), 3, privacyId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+       \r
+       res = sqlite3_step(pStmt.get());\r
+       TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+       res = m_notificationServer.notify(pkgId, privacyId);\r
+       TryReturn( res == 0, res, , "m_notificationServer.notify : %d", res);\r
+\r
+       LOGI("leave");\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerServer::getPrivacyAppPackages(std::list <std::string>& list)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string query = "SELECT pkg_id from PackageInfo";\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       while ( sqlite3_step(pStmt.get()) == SQLITE_ROW )\r
+       {\r
+               const char* pValue =  reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));\r
+\r
+               LOGD("AppId found : %s ", pValue);\r
+               list.push_back(std::string(pValue));\r
+       }\r
+\r
+       LOGI("leave");\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerServer::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair < std::string, bool > >* pPrivacyInfoList)\r
+{\r
+       LOGI("enter");\r
+\r
+       static const std::string query = "SELECT PRIVACY_ID, IS_ENABLED from Privacy where ID=?";\r
+\r
+       int uniqueId;\r
+       int res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
+       TryReturn( res == 0, -1, , "getUniqueIdFromPackageId : %d", res);\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_int(pStmt.get(), 1, uniqueId);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+       std::unique_ptr < std::list < std::pair < std:: string, bool > > > pList ( new std::list < std::pair < std:: string, bool > >);\r
+\r
+       LOGI("start");\r
+       while ((res= sqlite3_step(pStmt.get())) == SQLITE_ROW )\r
+       {\r
+               const char* privacyId =  reinterpret_cast < const char* > (sqlite3_column_text(pStmt.get(), 0));\r
+               bool privacyEnabled = sqlite3_column_int(pStmt.get(), 1) > 0 ? true : false;\r
+\r
+               pList->push_back( std::pair <std::string, bool> (std::string(privacyId), privacyEnabled) );\r
+\r
+               LOGD("Privacy found : %s %d", privacyId, privacyEnabled);\r
+       }\r
+       *pPrivacyInfoList = *pList.release();\r
+\r
+       LOGI("leave");\r
+\r
+       return 0;\r
+}\r
+\r
+\r
+int\r
+PrivacyManagerServer::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string > privilegeList)\r
+{\r
+       LOGI("enter");\r
+\r
+       static const std::string pkgInfoQuery("INSERT INTO PackageInfo(PKG_ID, IS_SET) VALUES(?, ?)");\r
+       static const std::string privacyQuery("INSERT INTO Privacy(ID, PRIVACY_ID, IS_ENABLED) VALUES(?, ?, ?)");\r
+\r
+       int res;\r
+       int uniqueId;\r
+       bool check;\r
+       res = isPackageIdAreadyExisted(pkgId, check);\r
+       TryReturn(check, PRIV_MGR_ERROR_INVALID_STATE, ,"The pkg ID %s is alreay added : %d", pkgId.c_str(), res);\r
+       \r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt);\r
+\r
+       res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+       \r
+       res = sqlite3_bind_int(pPkgInfoStmt.get(), 2, 0);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+       res = sqlite3_step(pPkgInfoStmt.get());\r
+       TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+       \r
+       res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
+       TryReturn( res == PRIV_MGR_ERROR_SUCCESS, res, , "getUniqueIdFromPackageId : %d", res);\r
+       \r
+       for ( std::list <std::string>::const_iterator iter = privilegeList.begin(); iter != privilegeList.end(); ++iter)\r
+       {\r
+               prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt);\r
+               \r
+               res = sqlite3_bind_int(pPrivacyStmt.get(), 1, uniqueId);\r
+               TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+               res = sqlite3_bind_text(pPrivacyStmt.get(), 2, iter->c_str(), -1, SQLITE_TRANSIENT);\r
+               TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+               \r
+               res = sqlite3_bind_int(pPrivacyStmt.get(), 3, 0);\r
+               TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+               res = sqlite3_step(pPrivacyStmt.get());\r
+               TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerServer::removeAppPackagePrivacyInfo(const std::string pkgId)\r
+{\r
+       LOGI("enter");\r
+\r
+       static const std::string pkgInfoQuery("DELETE FROM PackageInfo WHERE PKG_ID=?");\r
+       static const std::string privacyQuery("DELETE FROM Privacy WHERE ID=?");\r
+\r
+       int res;\r
+       int uniqueId;\r
+       res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
+       TryReturn( res == 0, res, , "getUniqueIdFromPackageId : %d", res);\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, pkgInfoQuery.c_str(), pPkgInfoStmt);\r
+\r
+       res = sqlite3_bind_text(pPkgInfoStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+\r
+       res = sqlite3_step(pPkgInfoStmt.get());\r
+       TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+       prepareDb(pDbHandler, privacyQuery.c_str(), pPrivacyStmt);\r
+\r
+       res = sqlite3_bind_int(pPrivacyStmt.get(), 1, uniqueId);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);  \r
+\r
+       res = sqlite3_step(pPrivacyStmt.get());\r
+       TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerServer::isUserPrompted(const std::string pkgId, bool& isPrompted)\r
+{\r
+       LOGI("enter");\r
+\r
+       static const std::string query = "SELECT IS_SET from PackageInfo where PKG_ID=?";\r
+\r
+       int uniqueId;\r
+       int res = getUniqueIdFromPackageId(pkgId, uniqueId);\r
+       TryReturn( res == 0, res, , "getUniqueIdFromPackageId : %d", res);\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_text(pStmt.get(), 1, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+\r
+       std::unique_ptr < std::list < std::pair < std:: string, bool > > > pList ( new std::list < std::pair < std:: string, bool > >);\r
+\r
+       if ((res = sqlite3_step(pStmt.get())) == SQLITE_ROW)\r
+       {\r
+               isPrompted = sqlite3_column_int(pStmt.get(), 0) > 0 ? true : false;\r
+       }\r
+       else\r
+       {\r
+               LOGE("Fail to get data : %d", res);\r
+               return PRIV_MGR_ERROR_DB_ERROR;\r
+       }\r
+\r
+       LOGI("leave");\r
+\r
+       return 0;\r
+}\r
+\r
+int\r
+PrivacyManagerServer::setUserPrompted(const std::string pkgId, bool prompted)\r
+{\r
+       LOGI("enter :%s - %d", pkgId.c_str(), prompted);\r
+\r
+       std::string query = std::string("UPDATE PackageInfo set IS_SET =? where PKG_ID=?");\r
+\r
+       int res;\r
+\r
+       openDb(DB_PATH.c_str(), pDbHandler, SQLITE_OPEN_READWRITE);\r
+       prepareDb(pDbHandler, query.c_str(), pStmt);\r
+\r
+       res = sqlite3_bind_int(pStmt.get(), 1, prompted? 1 : 0);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_int : %d", res);\r
+\r
+       res = sqlite3_bind_text(pStmt.get(), 2, pkgId.c_str(), -1, SQLITE_TRANSIENT);\r
+       TryReturn( res == SQLITE_OK, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_bind_text : %d", res);\r
+\r
+       res = sqlite3_step(pStmt.get());\r
+       TryReturn( res == SQLITE_DONE, PRIV_MGR_ERROR_DB_ERROR, , "sqlite3_step : %d", res);\r
+\r
+       return 0;\r
+}\r
+\r
+PrivacyManagerServer::PrivacyManagerServer(void)\r
+{\r
+\r
+}\r
+\r
+PrivacyManagerServer*\r
+PrivacyManagerServer::getInstance(void)\r
+{\r
+       LOGI("enter");\r
+       std::lock_guard < std::mutex > guard(m_singletonMutex);\r
+\r
+       if (m_pInstance == NULL)\r
+       {       \r
+               m_pInstance = new PrivacyManagerServer();\r
+               \r
+               m_pInstance->m_notificationServer.initialize();\r
+       }\r
+       LOGI("leave");\r
+       return m_pInstance;\r
+}\r
+\r
+sqlite3*\r
+PrivacyManagerServer::getDBHandler(void)\r
+{\r
+       return m_pDBHandler;\r
+}\r
diff --git a/server/src/SocketService.cpp b/server/src/SocketService.cpp
new file mode 100644 (file)
index 0000000..612c3e2
--- /dev/null
@@ -0,0 +1,374 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <errno.h>\r
+#include <sys/types.h>\r
+#include <sys/socket.h>\r
+#include <sys/un.h>\r
+#include <sys/signalfd.h>\r
+#include <sys/select.h>\r
+#include <sys/stat.h>\r
+#include <signal.h>\r
+#include <unistd.h>\r
+#include <fcntl.h>\r
+#include <memory>\r
+#include <dlog.h>\r
+#include <PrivacyManagerTypes.h>\r
+#include <Utils.h>\r
+#include "SocketService.h"\r
+#include "SocketConnection.h"\r
+\r
+const int SocketService::MAX_LISTEN = 5;\r
+const int SocketService::TIMEOUT_SEC = 0;\r
+const int SocketService::TIMEOUT_NSEC = 100000000;\r
+\r
+SocketService::SocketService(void)\r
+       : m_listenFd(-1)\r
+       , m_signalToClose(-1)\r
+       , m_mainThread(-1)\r
+{\r
+\r
+}\r
+\r
+SocketService::~SocketService(void)\r
+{\r
+\r
+}\r
+\r
+int\r
+SocketService::initialize(void)\r
+{\r
+       LOGI("SocketService initializing");\r
+\r
+       m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);\r
+       TryReturn( m_listenFd != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "socket : %s", strerror(errno));\r
+\r
+       int flags = -1;\r
+       int res;\r
+       if ( (flags = fcntl(m_listenFd, F_GETFL, 0)) == -1)\r
+               flags = 0;\r
+       res = fcntl(m_listenFd, F_SETFL, flags | O_NONBLOCK);\r
+       TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "fcntl : %s", strerror(errno));\r
+\r
+       sockaddr_un server_address;\r
+       bzero(&server_address, sizeof(server_address));\r
+       server_address.sun_family = AF_UNIX;\r
+       strcpy(server_address.sun_path, SERVER_ADDRESS.c_str());\r
+       unlink(server_address.sun_path);\r
+\r
+       mode_t socket_umask, original_umask;\r
+       socket_umask = 0;\r
+       original_umask = umask(socket_umask);\r
+\r
+       res = bind(m_listenFd, (struct sockaddr*)&server_address, SUN_LEN(&server_address));\r
+       TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "bind : %s", strerror(errno));\r
+\r
+       umask(original_umask);\r
+\r
+       LOGI("SocketService initialized");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+SocketService::start(void)\r
+{\r
+       LOGI("SocketService starting");\r
+\r
+       sigset_t sigset;\r
+       sigemptyset(&sigset);\r
+//     if ( sigaddset(&sigset, m_signalToClose) == -1 ) \r
+//     {\r
+//             LOGE("Failed to sigaddset : %s", strerror(errno));\r
+//             return -1;\r
+//     }\r
+\r
+       int res = 0;\r
+       res = pthread_sigmask(SIG_BLOCK, &sigset, NULL);\r
+       TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror(errno));\r
+\r
+       pthread_t mainThread;\r
+       res = pthread_create(&mainThread, NULL, &serverThread, this);\r
+       TryReturn( res >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror(res));\r
+\r
+       m_mainThread = mainThread;\r
+\r
+       LOGI("SocketService started");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+void*\r
+SocketService::serverThread(void* pData)\r
+{\r
+       pthread_detach(pthread_self());\r
+       SocketService &t = *static_cast< SocketService* > (pData);\r
+       LOGI("Running main thread");\r
+       int ret = t.mainloop();\r
+       if (ret < 0)\r
+       {\r
+               return (void*) 1;\r
+       }\r
+       return (void*) 0;\r
+}\r
+\r
+int\r
+SocketService::mainloop(void)\r
+{\r
+       if( listen(m_listenFd, MAX_LISTEN) == -1 ){\r
+               LOGE("listen : %s", strerror(errno));\r
+               return PRIV_MGR_ERROR_IPC_ERROR;\r
+       }\r
+\r
+       //Settings to catch closing signal in select\r
+       int signal_fd;\r
+       sigset_t sigset;\r
+       int res;\r
+       res = sigemptyset(&sigset);\r
+       TryReturn( res != -1, PRIV_MGR_ERROR_SYSTEM_ERROR, , "sigemptyset : %s", strerror(errno));\r
+\r
+//     if( sigaddset(&sigset, m_signalToClose) == -1) {\r
+//             LOGE("sigaddset : %s", strerror(errno));\r
+//             return -1;\r
+//     }\r
+       signal_fd = signalfd(-1, &sigset, 0);\r
+       TryReturn( signal_fd >= 0, PRIV_MGR_ERROR_SYSTEM_ERROR, , "signalfd : %s", strerror(errno));\r
+\r
+       //Setting descriptors for pselect\r
+       fd_set allset, rset;\r
+       int maxfd;\r
+       FD_ZERO(&allset);\r
+       FD_SET(m_listenFd, &allset);\r
+       FD_SET(signal_fd, &allset);\r
+       timespec timeout;\r
+       maxfd = (m_listenFd > signal_fd) ? (m_listenFd) : (signal_fd);\r
+       ++maxfd;\r
+       //this will block SIGPIPE for this thread and every thread created in it\r
+       //reason : from here on we don't won't to receive SIGPIPE on writing to closed socket\r
+       //instead of signal we want to receive error from write - hence blocking SIGPIPE\r
+       sigset_t set;\r
+       sigemptyset(&set);\r
+       sigaddset(&set, SIGPIPE);\r
+       pthread_sigmask(SIG_BLOCK, &set, NULL);\r
+\r
+       while(1)\r
+       {\r
+               timeout.tv_sec = TIMEOUT_SEC;\r
+               timeout.tv_nsec = TIMEOUT_NSEC;\r
+               rset = allset;\r
+               if(pselect(maxfd, &rset, NULL, NULL, &timeout, NULL) == -1)\r
+               {\r
+                       closeConnections();\r
+                       LOGE("pselect()");\r
+                       return PRIV_MGR_ERROR_SYSTEM_ERROR;\r
+               }\r
+\r
+               if(FD_ISSET(signal_fd, &rset))\r
+               {\r
+                       LOGI("Got signal to close");\r
+                       signalfd_siginfo siginfo;\r
+                       ssize_t res;\r
+                       res = read(signal_fd, &siginfo, sizeof(siginfo));\r
+                       TryReturn( res > 0, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "read : %s", strerror(errno));\r
+                       TryReturn( (size_t)res == sizeof(siginfo), PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "couldn't read whole siginfo");\r
+\r
+                       if((int)siginfo.ssi_signo == m_signalToClose)\r
+                       {\r
+                               LOGI("Server thread got signal to close");\r
+                               closeConnections();\r
+                               return PRIV_MGR_ERROR_SUCCESS;\r
+                       } \r
+                       else \r
+                       {\r
+                               LOGI("Got not handled signal");\r
+                       }\r
+               }\r
+               if(FD_ISSET(m_listenFd, &rset))\r
+               {\r
+                       int clientFd;\r
+                       clientFd = accept(m_listenFd, NULL, NULL);\r
+                       TryReturn( clientFd != -1, PRIV_MGR_ERROR_IPC_ERROR, closeConnections();, "accept : %s", strerror(errno));\r
+\r
+                       LOGI("Got incoming connection");\r
+                       ConnectionInfo * connection = new ConnectionInfo(clientFd, (void *)this);\r
+                       int res;\r
+                       pthread_t client_thread;\r
+                       if((res = pthread_create(&client_thread, NULL, &connectionThread, connection)) < 0)\r
+                       {\r
+                               delete connection;\r
+                               errno = res;\r
+                               closeConnections();\r
+                               LOGE("pthread_create()");\r
+                               return PRIV_MGR_ERROR_SYSTEM_ERROR;\r
+                       }\r
+                       addClientSocket(clientFd);\r
+               }\r
+       }       \r
+}\r
+\r
+void*\r
+SocketService::connectionThread(void* pData)\r
+{\r
+       pthread_detach(pthread_self());\r
+       std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData));\r
+       SocketService &t = *static_cast<SocketService *>(connectionInfo->pData);\r
+       LOGI("Starting connection thread");\r
+       int ret = t.connectionService(connectionInfo->connFd);\r
+       if (ret < 0)\r
+       {\r
+               LOGE("Connection thread error");\r
+               t.removeClientSocket(connectionInfo->connFd);\r
+               close(connectionInfo->connFd);\r
+               return (void*)1;\r
+       }\r
+       LOGI("Client serviced");\r
+       return (void*)0;\r
+}\r
+\r
+int\r
+SocketService::connectionService(int fd)\r
+{\r
+\r
+       SocketConnection connector = SocketConnection(fd);\r
+       std::string interfaceName, methodName;\r
+\r
+       connector.read(&interfaceName, &methodName);\r
+\r
+       LOGD("Got interface : %s", interfaceName.c_str());\r
+       LOGD("Got method : %s",  methodName.c_str());\r
+\r
+       if( m_callbackMap.find(interfaceName) == m_callbackMap.end())\r
+       {\r
+               LOGE("Unknown interface : %s", interfaceName.c_str());\r
+               return PRIV_MGR_ERROR_NO_DATA;\r
+       }\r
+\r
+       if(m_callbackMap[interfaceName].find(methodName) == m_callbackMap[interfaceName].end())\r
+       {\r
+               LOGE("Unknown method : %s", methodName.c_str());\r
+               return PRIV_MGR_ERROR_NO_DATA;\r
+       }\r
+\r
+//     if(m_callbackMap[interfaceName][methodName]->securityCallback != NULL){\r
+//             if(!m_callbackMap[interfaceName][methodName]->securityCallback(fd)){\r
+//                     LOGE("Security check returned false");\r
+//                     return -1;\r
+//             }\r
+//     }\r
+\r
+       LOGI("Calling service");\r
+       m_callbackMap[interfaceName][methodName]->serviceCallback(&connector);\r
+   \r
+       LOGI("Removing client");\r
+       removeClientSocket(fd);\r
+       close(fd);\r
+\r
+       LOGI("Call served");\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+SocketService::stop(void)\r
+{\r
+       LOGI("Stopping");\r
+       if(close(m_listenFd) == -1)\r
+               if(errno != ENOTCONN)\r
+               {\r
+                       LOGE("close() : %s", strerror(errno));\r
+                       return PRIV_MGR_ERROR_IPC_ERROR;\r
+               }\r
+\r
+       int returned_value;\r
+       if((returned_value = pthread_kill(m_mainThread, m_signalToClose)) < 0)\r
+       {\r
+               errno = returned_value;\r
+               LOGE("pthread_kill() : %s", strerror(errno));\r
+               return PRIV_MGR_ERROR_IPC_ERROR;\r
+       }\r
+       pthread_join(m_mainThread, NULL);\r
+\r
+       LOGI("Stopped");\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+SocketService::shutdown(void)\r
+{\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+int\r
+SocketService::registerServiceCallback(const std::string &interfaceName,  const std::string &methodName, socketServiceCallback callbackMethod)\r
+{\r
+       if(NULL == callbackMethod)\r
+       {\r
+               LOGE("Null callback");\r
+               return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
+       }\r
+       if(interfaceName.empty() || methodName.empty())\r
+       {\r
+               LOGE("Interface and method name cannot be empty");\r
+               return PRIV_MGR_ERROR_INVALID_PARAMETER;\r
+       }\r
+\r
+       auto serviceCallbackPtr = std::make_shared<ServiceCallback>(ServiceCallback(callbackMethod));\r
+       m_callbackMap[interfaceName][methodName] = serviceCallbackPtr;\r
+\r
+       return PRIV_MGR_ERROR_SUCCESS;\r
+}\r
+\r
+void\r
+SocketService::addClientSocket(int clientSocket)\r
+{\r
+       std::lock_guard<std::mutex> guard(m_clientSocketListMutex);\r
+       m_clientSocketList.push_back(clientSocket);\r
+}\r
+\r
+void\r
+SocketService::removeClientSocket(int clientSocket)\r
+{\r
+       std::lock_guard<std::mutex> guard(m_clientSocketListMutex);\r
+       m_clientSocketList.remove(clientSocket);\r
+}\r
+\r
+bool\r
+SocketService::popClientSocket(int * pClientSocket)\r
+{\r
+       std::lock_guard<std::mutex> guard(m_clientSocketListMutex);\r
+       if(m_clientSocketList.empty())\r
+               return false;\r
+       *pClientSocket = m_clientSocketList.front();\r
+       m_clientSocketList.pop_front();\r
+       return true;\r
+}\r
+\r
+\r
+void\r
+SocketService::closeConnections(void)\r
+{\r
+       int clientSocket;\r
+       LOGI("Closing client sockets");\r
+       while(popClientSocket(&clientSocket))\r
+       {\r
+               if(close(clientSocket) == -1)\r
+               {\r
+                       LOGE("close() : %s", strerror(errno));\r
+               }\r
+       }\r
+\r
+       LOGI("Connections closed");\r
+}
\ No newline at end of file
diff --git a/server/src/main.cpp b/server/src/main.cpp
new file mode 100644 (file)
index 0000000..f2fee09
--- /dev/null
@@ -0,0 +1,37 @@
+/*\r
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <PrivacyManagerDaemon.h>\r
+#include <glib.h>\r
+\r
+int\r
+main(int argc, char* argv[])\r
+{\r
+       PrivacyManagerDaemon* pDaemon = PrivacyManagerDaemon::getInstance();\r
+\r
+       pDaemon->inialize();\r
+       pDaemon->start();\r
+\r
+       GMainLoop* pLoop;\r
+       pLoop = g_main_new(TRUE);\r
+\r
+       g_main_loop_run(pLoop);\r
+\r
+       pDaemon->stop();\r
+       pDaemon->shutdown();\r
+\r
+       return 0;\r
+}
\ No newline at end of file
diff --git a/server/src/service/PrivacyInfoService.cpp b/server/src/service/PrivacyInfoService.cpp
new file mode 100644 (file)
index 0000000..664da44
--- /dev/null
@@ -0,0 +1,134 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+#include <PrivacyInfoService.h>\r
+#include <PrivacyManagerServer.h>\r
+#include <dlog.h>\r
+#include <Utils.h>\r
+\r
+void\r
+PrivacyInfoService::addPrivacyInfo(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string pkgId;\r
+       std::list < std::string > list;\r
+       pConnector->read(&pkgId, &list);\r
+\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+       int result = pPrivacyManagerServer->addAppPackagePrivacyInfo(pkgId, list);\r
+\r
+       pConnector->write(result);\r
+}\r
+\r
+void\r
+PrivacyInfoService::removePrivacyInfo(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string pkgId;\r
+       pConnector->read(&pkgId);\r
+\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+       int res = pPrivacyManagerServer->removeAppPackagePrivacyInfo(pkgId);\r
+\r
+       pConnector->write(res);\r
+}\r
+\r
+void\r
+PrivacyInfoService::setPrivacySetting(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string pkgId;\r
+       std::string privacyId;\r
+       bool enabled;\r
+       pConnector->read(&pkgId, &privacyId, &enabled);\r
+\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+       int result = pPrivacyManagerServer->setPrivacySetting(pkgId, privacyId, enabled);\r
+\r
+       pConnector->write(result);\r
+}\r
+\r
+void\r
+PrivacyInfoService::getPrivacyAppPackages(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+       std::list <std::string> list;\r
+       int result = pPrivacyManagerServer->getPrivacyAppPackages(list);\r
+\r
+       pConnector->write( (unsigned int) result);\r
+       pConnector->write( (unsigned int) list.size());\r
+       pConnector->write(list);\r
+}\r
+\r
+void\r
+PrivacyInfoService::getAppPackagePrivacyInfo(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string pkgId;\r
+\r
+       pConnector->read(&pkgId);\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+\r
+       \r
+       std::list < std::pair < std::string, bool > > infoList;\r
+       \r
+       int res = pPrivacyManagerServer->getAppPackagePrivacyInfo(pkgId, &infoList);\r
+\r
+       pConnector->write( res );\r
+       pConnector->write( infoList );\r
+}\r
+\r
+void\r
+PrivacyInfoService::isUserPrompted(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string pkgId;\r
+\r
+       pConnector->read(&pkgId);\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+\r
+       bool isPrompted;\r
+       int res = pPrivacyManagerServer->isUserPrompted(pkgId, isPrompted);\r
+\r
+       pConnector->write( res );\r
+       pConnector->write( isPrompted );\r
+\r
+       LOGI("leave");\r
+}\r
+\r
+void\r
+PrivacyInfoService::setUserPrompted(SocketConnection* pConnector)\r
+{\r
+       LOGI("enter");\r
+\r
+       std::string pkgId;\r
+       bool prompted;\r
+\r
+       pConnector->read(&pkgId, &prompted);\r
+       PrivacyManagerServer* pPrivacyManagerServer = PrivacyManagerServer::getInstance();\r
+\r
+       int res = pPrivacyManagerServer->setUserPrompted(pkgId, prompted);\r
+       LOGI("write");\r
+       pConnector->write( res );\r
+\r
+       LOGI("leave");\r
+}
\ No newline at end of file
diff --git a/server/src/service/TestService.cpp b/server/src/service/TestService.cpp
new file mode 100644 (file)
index 0000000..d9e77cc
--- /dev/null
@@ -0,0 +1,29 @@
+/*\r
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
+ *\r
+ *    Licensed under the Apache License, Version 2.0 (the "License");\r
+ *    you may not use this file except in compliance with the License.\r
+ *    You may obtain a copy of the License at\r
+ *\r
+ *        http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *    Unless required by applicable law or agreed to in writing, software\r
+ *    distributed under the License is distributed on an "AS IS" BASIS,\r
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *    See the License for the specific language governing permissions and\r
+ *    limitations under the License.\r
+ */\r
+\r
+\r
+#include <TestService.h>\r
+\r
+void\r
+TestService::test(SocketConnection* pConnector)\r
+{\r
+       std::string res1, res2;\r
+       pConnector->read(&res1, &res2);\r
+       LOGD("TEST received: %s %s", res1.c_str(),res2.c_str());\r
+\r
+       pConnector->write(std::string("-test OK-"));\r
+       pConnector->write(std::string("-byebye-"));\r
+}\r