#include <dpl/wrt-dao-ro/WrtDatabase.h>
#include <dpl/wrt-dao-ro/widget_config.h>
#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
#include <sys/stat.h>
#include <fstream>
const char* const SECURITY_ORIGIN_DB_SQL_PATH =
"/usr/share/wrt-engine/security_origin_db.sql";
+std::string createDatabasePath(const WrtDB::WidgetPkgName &pkgName)
+{
+ std::stringstream filename;
+
+ filename << WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(pkgName)
+ << "/"
+ << SECURITY_ORIGIN_DB_NAME;
+ return filename.str();
+}
+
std::string createDatabasePath(int widgetHandle)
{
using namespace DPL::DB::ORM;
using namespace WrtDB::WidgetConfig;
using namespace WrtDB::GlobalConfig;
- SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
- {
- std::stringstream filename;
- WrtDB::WidgetDAOReadOnly widgetDAO(widgetHandle);
- DPL::Optional<DPL::String> pkgname = widgetDAO.getPkgname();
+ WrtDB::TizenAppId appid;
- filename << GetWidgetPersistentStoragePath(*pkgname)
- << "/"
- << SECURITY_ORIGIN_DB_NAME;
- return filename.str();
+ Try
+ {
+ appid = WrtDB::WidgetDAOReadOnly::getTzAppId(widgetHandle);
}
- SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to get database Path")
-
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ LogError("Failed to get database Path");
+ }
+ return createDatabasePath(appid);
}
void checkDatabase(std::string databasePath)
m_securityOriginDBInterface.AttachToThread(SECURITY_ORIGIN_DB_OPTION);
}
+SecurityOriginDAO::SecurityOriginDAO(const WrtDB::WidgetPkgName &pkgName) :
+ m_securityOriginDBPath(createDatabasePath(pkgName)),
+ m_securityOriginDBInterface(m_securityOriginDBPath, SECURITY_ORIGIN_DB_TYPE)
+{
+ checkDatabase(m_securityOriginDBPath);
+ m_securityOriginDBInterface.AttachToThread(SECURITY_ORIGIN_DB_OPTION);
+}
+
SecurityOriginDAO::~SecurityOriginDAO()
{
m_securityOriginDBInterface.DetachFromThread();
SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set security origin data")
}
-bool SecurityOriginDAO::hasResult(const SecurityOriginData &securityOriginData)
+void SecurityOriginDAO::removeSecurityOriginData(const Result result)
{
SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN
{
- SECURITY_ORIGIN_DB_SELECT(select, SecurityOriginInfo, &m_securityOriginDBInterface);
- select->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)));
-
- SecurityOriginInfo::Select::RowList rows = select->GetRowList();
-
- return !rows.empty();
+ ScopedTransaction transaction(&m_securityOriginDBInterface);
+ SECURITY_ORIGIN_DB_DELETE(del, SecurityOriginInfo, &m_securityOriginDBInterface)
+ del->Where(Equals<SecurityOriginInfo::result>(result));
+ del->Execute();
+ transaction.Commit();
}
- SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get result for security origin")
+ SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to remove data by result")
+}
+
+bool SecurityOriginDAO::hasResult(const SecurityOriginData &securityOriginData)
+{
+ Result res=getResult(securityOriginData);
+ return (res != RESULT_UNKNOWN);
}
#undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN