Implement security origin dao for setting menu
authorJihoon Chung <jihoon.chung@samsung.com>
Mon, 19 Nov 2012 04:22:41 +0000 (13:22 +0900)
committerJihoon Chung <jihoon.chung@samsung.com>
Wed, 21 Nov 2012 01:03:33 +0000 (10:03 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] For supporting setting menu, security origin dao is
needed to change API and additional type define
[SCMRequest] N/A

Change-Id: I615c3c56fa1d3bc4a4a564687bddb84afc861774

modules/security_origin_dao/dao/security_origin_dao.cpp
modules/security_origin_dao/include/wrt-commons/security-origin-dao/security_origin_dao.h
modules/security_origin_dao/include/wrt-commons/security-origin-dao/security_origin_dao_types.h

index 34ed369..c3b24c6 100644 (file)
@@ -126,6 +126,27 @@ SecurityOriginDAO::~SecurityOriginDAO()
     m_securityOriginDBInterface.DetachFromThread();
 }
 
+SecurityOriginDataList SecurityOriginDAO::getSecurityOriginDataList(void)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        SecurityOriginDataList list;
+        SECURITY_ORIGIN_DB_SELECT(select, SecurityOriginInfo, &m_securityOriginDBInterface);
+        typedef std::list<SecurityOriginInfo::Row> RowList;
+        RowList rowList = select->GetRowList();
+
+        FOREACH(it, rowList) {
+            Origin origin(it->Get_scheme(), it->Get_host(), it->Get_port());
+            list.push_back(
+                SecurityOriginDataPtr(
+                    new SecurityOriginData(
+                        static_cast<Feature>(it->Get_feature()), origin)));
+        }
+        return list;
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get data  list")
+}
+
 Result SecurityOriginDAO::getResult(const SecurityOriginData &securityOriginData)
 {
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
@@ -179,6 +200,27 @@ void SecurityOriginDAO::setSecurityOriginData(const SecurityOriginData &security
     SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set security origin data")
 }
 
+void SecurityOriginDAO::removeSecurityOriginData(
+    const SecurityOriginData &securityOriginData)
+{
+    SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
+    {
+        ScopedTransaction transaction(&m_securityOriginDBInterface);
+
+        if (true == hasResult(securityOriginData)) {
+            SECURITY_ORIGIN_DB_DELETE(del, SecurityOriginInfo, &m_securityOriginDBInterface)
+            del->Where(
+                And(And(And(Equals<SecurityOriginInfo::feature>(securityOriginData.feature),
+                            Equals<SecurityOriginInfo::scheme>(securityOriginData.origin.scheme)),
+                        Equals<SecurityOriginInfo::host>(securityOriginData.origin.host)),
+                    Equals<SecurityOriginInfo::port>(securityOriginData.origin.port)));
+            del->Execute();
+            transaction.Commit();
+        }
+    }
+    SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set security origin data")
+}
+
 bool SecurityOriginDAO::hasResult(const SecurityOriginData &securityOriginData)
 {
     SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
index a1e649e..e27c02e 100644 (file)
@@ -40,15 +40,19 @@ class SecurityOriginDAO
 
     explicit SecurityOriginDAO(int handle);
     virtual ~SecurityOriginDAO();
+    SecurityOriginDataList getSecurityOriginDataList();
     Result getResult(const SecurityOriginData &securityOriginData);
     void setSecurityOriginData(const SecurityOriginData &securityOriginData,
                                const Result result);
+    void removeSecurityOriginData(const SecurityOriginData &securityOriginData);
   private:
     std::string m_securityOriginDBPath;
     DPL::DB::ThreadDatabaseSupport m_securityOriginDBInterface;
     bool hasResult(const SecurityOriginData &securityOriginData);
 };
 
+typedef std::shared_ptr<SecurityOriginDAO> SecurityOriginDAOPtr;
+
 } // namespace SecurityOriginDB
 
 #endif // _SECURITY_ORIGIN_DAO_H_
index 90e355b..35081ca 100644 (file)
 #define _SECURITY_ORIGIN_DAO_TYPES_H_
 
 #include <list>
+#include <memory>
 #include <dpl/string.h>
 
 namespace SecurityOriginDB {
 
 enum Feature
 {
+    FEATURE_START = 0,
     FEATURE_GEOLOCATION = 0,
-    FEATURE_FILESYSTEM,
-    FEATURE_WEB_NOTIFICATION
+    FEATURE_WEB_NOTIFICATION,
+    FEATURE_WEB_DATABASE,
+    FEATURE_FILE_SYSTEM_ACCESS,
+    FEATURE_END = FEATURE_FILE_SYSTEM_ACCESS
 };
 
 enum Result
 {
     RESULT_UNKNOWN = 0,
-    RESULT_USER_ALLOWED,
-    RESULT_USER_DENIED,
-    RESULT_EXCEPTION_ALLOWED,
-    RESULT_EXCEPTION_DENIED
+    RESULT_ALLOW_ONCE,
+    RESULT_DENY_ONCE,
+    RESULT_ALLOW_ALWAYS,
+    RESULT_DENY_ALWAYS
 };
 
 struct Origin
@@ -96,6 +100,9 @@ struct SecurityOriginData
     }
 };
 
+typedef std::shared_ptr<SecurityOriginData> SecurityOriginDataPtr;
+typedef std::list<SecurityOriginDataPtr> SecurityOriginDataList;
+
 } // namespace SecurityOriginDB
 
 #endif // _SECURITY_ORIGIN_DAO_TYPES_H_