From 0a1841f4c40413a00fd3e6baa2c0ccc12696a661 Mon Sep 17 00:00:00 2001 From: leerang song Date: Tue, 26 Feb 2013 20:56:52 +0900 Subject: [PATCH] Implement certificate confirm popup [Issue#] N/A [Problem] Can't storage certificate info [Cause] Not exist certificate db [Solution] Add certificate db [SCMRequest] N/A Change-Id: I698485f3945deeade8de82d21b88061767275c67 --- .gitignore | 2 +- CMakeLists.txt | 1 + build/CMakeLists.txt | 1 + build/certificate_dao/CMakeLists.txt | 21 ++ .../wrt-commons-certificate-dao.pc.in | 12 + modules/CMakeLists.txt | 1 + modules/certificate_dao/CMakeLists.txt | 57 ++++ .../certificate_dao/dao/certificate_dao.cpp | 270 ++++++++++++++++++ .../dao/certificate_dao_types.cpp | 30 ++ .../dao/certificate_database.cpp | 19 ++ .../certificate-dao/certificate_dao.h | 59 ++++ .../certificate-dao/certificate_dao_types.h | 65 +++++ .../certificate-dao/certificate_database.h | 50 ++++ modules/certificate_dao/orm/certificate_db | 9 + .../orm/certificate_db_definitions | 5 + .../orm/certificate_db_sql_generator.h | 27 ++ .../orm/orm_generator_certificate.h | 24 ++ 17 files changed, 652 insertions(+), 1 deletion(-) create mode 100755 build/certificate_dao/CMakeLists.txt create mode 100644 build/certificate_dao/wrt-commons-certificate-dao.pc.in create mode 100755 modules/certificate_dao/CMakeLists.txt create mode 100755 modules/certificate_dao/dao/certificate_dao.cpp create mode 100755 modules/certificate_dao/dao/certificate_dao_types.cpp create mode 100755 modules/certificate_dao/dao/certificate_database.cpp create mode 100755 modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao.h create mode 100755 modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao_types.h create mode 100755 modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_database.h create mode 100755 modules/certificate_dao/orm/certificate_db create mode 100644 modules/certificate_dao/orm/certificate_db_definitions create mode 100755 modules/certificate_dao/orm/certificate_db_sql_generator.h create mode 100755 modules/certificate_dao/orm/orm_generator_certificate.h diff --git a/.gitignore b/.gitignore index fb11196..fd5511d 100755 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ modules/auto_save_dao/database_checksum_autosave.h modules/widget_dao/database_checksum.h modules/security_origin_dao/database_checksum_security_origin.h modules/custom_handler_dao/database_checksum_custom_handler.h - +modules/certificate_dao/database_checksum_certificage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 64704d2..45cc829 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,6 +190,7 @@ SET(TARGET_AUTO_SAVE_DAO_RO_LIB "wrt-commons-auto-save-dao-ro") SET(TARGET_CUSTOM_HANDLER_DAO_RW_LIB "wrt-commons-custom-handler-dao-rw") SET(TARGET_CUSTOM_HANDLER_DAO_RO_LIB "wrt-commons-custom-handler-dao-ro") SET(TARGET_SECURITY_ORIGIN_DAO_LIB "wrt-commons-security-origin-dao") +SET(TARGET_CERTIFICATE_DAO_LIB "wrt-commons-certificate-dao") SET(TARGET_DPL_UTILS_EFL "lib${PROJECT_NAME}-utils-efl") SET(TARGET_DPL_ENCRYPTION "lib${PROJECT_NAME}-encryption") diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index b27d01f..10e05ce 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -33,3 +33,4 @@ ADD_SUBDIRECTORY(custom_handler_dao) ADD_SUBDIRECTORY(utils) ADD_SUBDIRECTORY(support) ADD_SUBDIRECTORY(encryption) +ADD_SUBDIRECTORY(certificate_dao) diff --git a/build/certificate_dao/CMakeLists.txt b/build/certificate_dao/CMakeLists.txt new file mode 100755 index 0000000..037a7c2 --- /dev/null +++ b/build/certificate_dao/CMakeLists.txt @@ -0,0 +1,21 @@ +# 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. +# +# @file CMakeLists.txt +# @author Leerang Song (leerang.song@samsung.com) +# @brief +# + +configure_and_install_pkg(wrt-commons-certificate-dao.pc) + diff --git a/build/certificate_dao/wrt-commons-certificate-dao.pc.in b/build/certificate_dao/wrt-commons-certificate-dao.pc.in new file mode 100644 index 0000000..903dc95 --- /dev/null +++ b/build/certificate_dao/wrt-commons-certificate-dao.pc.in @@ -0,0 +1,12 @@ +prefix=/usr +exec_prefix=${prefix} + +libdir=${prefix}/lib +includedir=${prefix}/include +Name: wrt-commons-certificate-dao +Description: wrt-commons-certificate-dao + +Version: @VERSION@ +Requires: dpl-efl +Libs: -lwrt-commons-certificate-dao -L${libdir} +Cflags: -I${includedir}/dpl-efl diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 4d39189..a057a4b 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -31,6 +31,7 @@ ADD_SUBDIRECTORY(widget_dao) ADD_SUBDIRECTORY(auto_save_dao) ADD_SUBDIRECTORY(security_origin_dao) ADD_SUBDIRECTORY(custom_handler_dao) +ADD_SUBDIRECTORY(certificate_dao) include(utils/config.cmake) include(localization/config.cmake) include(support/config.cmake) diff --git a/modules/certificate_dao/CMakeLists.txt b/modules/certificate_dao/CMakeLists.txt new file mode 100755 index 0000000..f55ee45 --- /dev/null +++ b/modules/certificate_dao/CMakeLists.txt @@ -0,0 +1,57 @@ +SET(TARGET_CERTIFICATE_DAO_DB "Sqlite3DbCertificate") + +ADD_CUSTOM_COMMAND( OUTPUT .certificate.db + COMMAND rm -f ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db + COMMAND gcc -Wall -I${PROJECT_SOURCE_DIR}/modules/db/include -I${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm -E ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm/certificate_db_sql_generator.h | grep --invert-match "^#" > ${CMAKE_CURRENT_BINARY_DIR}/certificate_db.sql + COMMAND sqlite3 ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db ".read ${CMAKE_CURRENT_BINARY_DIR}/certificate_db.sql" || rm -f ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db + DEPENDS ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm/certificate_db_sql_generator.h ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm/certificate_db + ) + +ADD_CUSTOM_COMMAND( OUTPUT .certificate.db-journal + COMMAND touch + ARGS ${CMAKE_CURRENT_BINARY_DIR}/.certificate.db-journal + ) + +ADD_CUSTOM_TARGET(${TARGET_CERTIFICATE_DAO_DB} ALL DEPENDS .certificate.db .certificate.db-journal) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/certificate_db.sql DESTINATION share/wrt-engine/) + +############################################################################### + +INCLUDE(FindPkgConfig) + +PKG_CHECK_MODULES(CERTIFICATE_DAO_DEPS + glib-2.0 + REQUIRED) + +SET(CERTIFICATE_DAO_INCLUDE_DIRS + ${PROJECT_SOURCE_DIR}/modules/certificate_dao/include + ${PROJECT_SOURCE_DIR}/modules/certificate_dao/orm + ${PROJECT_SOURCE_DIR}/modules/core/include + ${PROJECT_SOURCE_DIR}/modules/db/include + ${PROJECT_SOURCE_DIR}/modules/log/include + ${PROJECT_SOURCE_DIR}/modules/widget_dao/include +) + +SET(CERTIFICATE_DAO_SOURCES + dao/certificate_dao_types.cpp + dao/certificate_dao.cpp + dao/certificate_database.cpp +) + +INCLUDE_DIRECTORIES(SYSTEM ${CERTIFICATE_DAO_DEPS_INCLUDE_DIRS} ) +INCLUDE_DIRECTORIES(${CERTIFICATE_DAO_INCLUDE_DIRS}) + +ADD_LIBRARY(${TARGET_CERTIFICATE_DAO_LIB} SHARED ${CERTIFICATE_DAO_SOURCES}) +SET_TARGET_PROPERTIES(${TARGET_CERTIFICATE_DAO_LIB} PROPERTIES SOVERSION ${API_VERSION} VERSION ${VERSION}) +TARGET_LINK_LIBRARIES(${TARGET_CERTIFICATE_DAO_LIB} ${TARGET_DPL_EFL} ${TARGET_DPL_DB_EFL} ${TARGET_WRT_DAP_RO_LIB} ${CERTIFICATE_DAO_DEPS_LIBRARIES}) +ADD_DEPENDENCIES(${TARGET_CERTIFICATE_DAO_LIB} ${TARGET_CERTIFICATE_DAO_DB}) + +INSTALL(TARGETS ${TARGET_CERTIFICATE_DAO_LIB} DESTINATION lib) + +INSTALL(FILES + include/wrt-commons/certificate-dao/certificate_dao_types.h + include/wrt-commons/certificate-dao/certificate_database.h + include/wrt-commons/certificate-dao/certificate_dao.h + DESTINATION include/dpl-efl/wrt-commons/certificate-dao +) + diff --git a/modules/certificate_dao/dao/certificate_dao.cpp b/modules/certificate_dao/dao/certificate_dao.cpp new file mode 100755 index 0000000..4f1a719 --- /dev/null +++ b/modules/certificate_dao/dao/certificate_dao.cpp @@ -0,0 +1,270 @@ +/* + * 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. + */ +/* + * @file certificate_dao.cpp + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief This file contains the definition of certificate dao class. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace DPL::DB::ORM; +using namespace DPL::DB::ORM::certificate; + +namespace CertificateDB { +#define SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN Try + +#define SQL_CONNECTION_EXCEPTION_HANDLER_END(message) \ + Catch(DPL::DB::SqlConnection::Exception::Base) { \ + LogError(message); \ + ReThrowMsg(CertificateDAO::Exception::DatabaseError, \ + message); \ + } + +namespace { +DPL::DB::SqlConnection::Flag::Option CERTIFICATE_DB_OPTION = + DPL::DB::SqlConnection::Flag::RW; +DPL::DB::SqlConnection::Flag::Type CERTIFICATE_DB_TYPE = + DPL::DB::SqlConnection::Flag::UseLucene; +const char* const CERTIFICATE_DB_NAME = ".certificate.db"; +const char* const CERTIFICATE_DB_SQL_PATH = + "/usr/share/wrt-engine/certificate_db.sql"; +const char* const CERTIFICATE_DATABASE_JOURNAL_FILENAME = "-journal"; + +const int WEB_APPLICATION_UID = 5000; +const int WEB_APPLICATION_GUID = 5000; + +std::string createDatabasePath(const WrtDB::WidgetPkgName &pkgName) +{ + std::stringstream filename; + + filename << WrtDB::WidgetConfig::GetWidgetPersistentStoragePath(pkgName) + << "/" + << CERTIFICATE_DB_NAME; + return filename.str(); +} + +std::string createDatabasePath(int widgetHandle) +{ + using namespace DPL::DB::ORM; + using namespace WrtDB::WidgetConfig; + using namespace WrtDB::GlobalConfig; + + WrtDB::TizenAppId appid; + + Try + { + appid = WrtDB::WidgetDAOReadOnly::getTzAppId(widgetHandle); + } + Catch(DPL::DB::SqlConnection::Exception::Base) { + LogError("Failed to get database Path"); + } + return createDatabasePath(appid); +} + +void checkDatabase(std::string databasePath) +{ + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + if (databasePath.empty()) { + ThrowMsg(CertificateDAO::Exception::DatabaseError, + "Wrong database Path is passed"); + } + + struct stat buffer; + if (stat(databasePath.c_str(), &buffer) != 0) { + //Create fresh database + LogInfo("Creating database " << databasePath); + + std::fstream file; + file.open(CERTIFICATE_DB_SQL_PATH, std::ios_base::in); + if (!file) { + ThrowMsg(CertificateDAO::Exception::DatabaseError, + "Fail to get database Path"); + } + + std::stringstream ssBuffer; + ssBuffer << file.rdbuf(); + + file.close(); + + DPL::DB::SqlConnection con(databasePath, + CERTIFICATE_DB_TYPE, + CERTIFICATE_DB_OPTION); + con.ExecCommand(ssBuffer.str().c_str()); + } + + if(chown(databasePath.c_str(), + WEB_APPLICATION_UID, + WEB_APPLICATION_GUID) != 0) + { + ThrowMsg(CertificateDAO::Exception::DatabaseError, + "Fail to change uid/guid"); + } + std::string databaseJournal = + databasePath + CERTIFICATE_DATABASE_JOURNAL_FILENAME; + if(chown(databaseJournal.c_str(), + WEB_APPLICATION_UID, + WEB_APPLICATION_GUID) != 0) + { + ThrowMsg(CertificateDAO::Exception::DatabaseError, + "Fail to change uid/guid"); + } + } + SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to get database Path") +} +} + +CertificateDAO::CertificateDAO(const WrtDB::WidgetPkgName &pkgName) : + m_certificateDBPath(createDatabasePath(pkgName)), + m_certificateDBInterface(m_certificateDBPath, CERTIFICATE_DB_TYPE) +{ + checkDatabase(m_certificateDBPath); + m_certificateDBInterface.AttachToThread(CERTIFICATE_DB_OPTION); +} + +CertificateDAO::~CertificateDAO() +{ + m_certificateDBInterface.DetachFromThread(); +} + +CertificateDataList CertificateDAO::getCertificateDataList(void) +{ + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + CertificateDataList list; + CERTIFICATE_DB_SELECT(select, + CertificateInfo, + &m_certificateDBInterface); + typedef std::list RowList; + RowList rowList = select->GetRowList(); + + FOREACH(it, rowList) { + list.push_back( + CertificateDataPtr( + new CertificateData(it->Get_certificate()))); + } + return list; + } + SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed to get data list") +} + +Result CertificateDAO::getResult( + const CertificateData &certificateData) +{ + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + CERTIFICATE_DB_SELECT(select, + CertificateInfo, + &m_certificateDBInterface); + select->Where( + Equals(certificateData.certificate)); + CertificateInfo::Select::RowList rows = select->GetRowList(); + + if (rows.empty()) { + return RESULT_UNKNOWN; + } + CertificateInfo::Row row = rows.front(); + return static_cast(row.Get_result()); + } + SQL_CONNECTION_EXCEPTION_HANDLER_END( + "Failed to get result for security certiInfo") +} + +void CertificateDAO::setCertificateData(const CertificateData &certificateData, + const Result result) +{ + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + ScopedTransaction transaction(&m_certificateDBInterface); + CertificateInfo::Row row; + row.Set_certificate(certificateData.certificate); + row.Set_result(result); + + if (true == hasResult(certificateData)) { + CERTIFICATE_DB_UPDATE(update, + CertificateInfo, + &m_certificateDBInterface); + update->Values(row); + update->Execute(); + } else { + CERTIFICATE_DB_INSERT(insert, + CertificateInfo, + &m_certificateDBInterface); + insert->Values(row); + insert->Execute(); + } + transaction.Commit(); + } + SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set security certiInfo data") +} + +void CertificateDAO::removeCertificateData( + const CertificateData &certificateData) +{ + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + ScopedTransaction transaction(&m_certificateDBInterface); + + if (true == hasResult(certificateData)) { + CERTIFICATE_DB_DELETE(del, + CertificateInfo, + &m_certificateDBInterface) + del->Where( + Equals(certificateData.certificate)); + del->Execute(); + transaction.Commit(); + } + } + SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to set certiInfo data") +} + +void CertificateDAO::removeCertificateData(const Result result) +{ + SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN + { + ScopedTransaction transaction(&m_certificateDBInterface); + CERTIFICATE_DB_DELETE(del, + CertificateInfo, + &m_certificateDBInterface) + del->Where(Equals(result)); + del->Execute(); + transaction.Commit(); + } + SQL_CONNECTION_EXCEPTION_HANDLER_END("Fail to remove data by result") +} + +bool CertificateDAO::hasResult(const CertificateData &certificateData) +{ + Result res = getResult(certificateData); + return (res != RESULT_UNKNOWN); +} + +#undef SQL_CONNECTION_EXCEPTION_HANDLER_BEGIN +#undef SQL_CONNECTION_EXCEPTION_HANDLER_END +} // namespace CertificateDB diff --git a/modules/certificate_dao/dao/certificate_dao_types.cpp b/modules/certificate_dao/dao/certificate_dao_types.cpp new file mode 100755 index 0000000..35e8a58 --- /dev/null +++ b/modules/certificate_dao/dao/certificate_dao_types.cpp @@ -0,0 +1,30 @@ +/* + * 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. + */ +/** + * + * @file certificate_dao_types.cpp + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief This file contains the implementation of + * common data types for certificate.db + */ + +#include +#include + +namespace CertificateDB { + +} // namespace CertificateDB diff --git a/modules/certificate_dao/dao/certificate_database.cpp b/modules/certificate_dao/dao/certificate_database.cpp new file mode 100755 index 0000000..4392e0c --- /dev/null +++ b/modules/certificate_dao/dao/certificate_database.cpp @@ -0,0 +1,19 @@ +/* + * 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. + */ + +#include + +DPL::Mutex g_certificateDBQueriesMutex; diff --git a/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao.h b/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao.h new file mode 100755 index 0000000..9260ab7 --- /dev/null +++ b/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao.h @@ -0,0 +1,59 @@ +/* + * 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. + */ +/** + * @file certificate_dao.h + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief This file contains the declaration of certificate dao + */ +#ifndef _CERTIFICATE_DAO_H_ +#define _CERTIFICATE_DAO_H_ + +#include +#include +#include + +namespace CertificateDB { +class CertificateDAO +{ + public: + class Exception + { + public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, Base) + DECLARE_EXCEPTION_TYPE(Base, DatabaseError) + DECLARE_EXCEPTION_TYPE(Base, DataNotExist) + }; + + explicit CertificateDAO(const WrtDB::WidgetPkgName &pkgName); + virtual ~CertificateDAO(); + CertificateDataList getCertificateDataList(); + Result getResult(const CertificateData &certificateData); + void setCertificateData(const CertificateData &certificateData, + const Result result); + void removeCertificateData(const CertificateData &certificateData); + void removeCertificateData(const Result result); + + private: + std::string m_certificateDBPath; + DPL::DB::ThreadDatabaseSupport m_certificateDBInterface; + bool hasResult(const CertificateData &certificateData); +}; + +typedef std::shared_ptr CertificateDAOPtr; +} // namespace CertificateDB + +#endif // _CERTIFICATE_DAO_H_ \ No newline at end of file diff --git a/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao_types.h b/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao_types.h new file mode 100755 index 0000000..89f5836 --- /dev/null +++ b/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_dao_types.h @@ -0,0 +1,65 @@ +/* + * 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. + */ +/** + * + * @file certificate_dao_types.h + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief This file contains the declaration of + * common data types for certificate database. + */ +#ifndef _CERTIFICATE_DAO_TYPES_H_ +#define _CERTIFICATE_DAO_TYPES_H_ + +#include +#include +#include + +namespace CertificateDB { + +enum Result +{ + RESULT_UNKNOWN = 0, + RESULT_ALLOW_ONCE, + RESULT_DENY_ONCE, + RESULT_ALLOW_ALWAYS, + RESULT_DENY_ALWAYS +}; + +struct CertificateData +{ + DPL::String certificate; + + CertificateData(const DPL::String& certi) : + certificate(certi) + {} + + bool operator== (const CertificateData& other) const + { + return !(certificate == other.certificate); + } + + bool operator!= (const CertificateData& other) const + { + return !(*this == other); + } +}; + +typedef std::shared_ptr CertificateDataPtr; +typedef std::list CertificateDataList; +} // namespace CertificateDB + +#endif // _CERTIFICATE_DAO_TYPES_H_ \ No newline at end of file diff --git a/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_database.h b/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_database.h new file mode 100755 index 0000000..f0ee954 --- /dev/null +++ b/modules/certificate_dao/include/wrt-commons/certificate-dao/certificate_database.h @@ -0,0 +1,50 @@ +/* + * 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. + */ + +#ifndef _CERTIFICATE_DATABASE_H_ +#define _CERTIFICATE_DATABASE_H_ + +#include +#include + +extern DPL::Mutex g_certificateDBQueriesMutex; + +#define CERTIFICATE_DB_INTERNAL(tlsCommand, InternalType, interface) \ + static DPL::ThreadLocalVariable *tlsCommand##Ptr = NULL; \ + { \ + DPL::Mutex::ScopedLock lock(&g_certificateDBQueriesMutex); \ + if (!tlsCommand##Ptr) { \ + static DPL::ThreadLocalVariable tmp; \ + tlsCommand##Ptr = &tmp; \ + } \ + } \ + DPL::ThreadLocalVariable &tlsCommand = *tlsCommand##Ptr; \ + if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); } + +#define CERTIFICATE_DB_SELECT(name, type, interface) \ + CERTIFICATE_DB_INTERNAL(name, type::Select, interface) + +#define CERTIFICATE_DB_INSERT(name, type, interface) \ + CERTIFICATE_DB_INTERNAL(name, type::Insert, interface) + +#define CERTIFICATE_DB_UPDATE(name, type, interface) \ + CERTIFICATE_DB_INTERNAL(name, type::Update, interface) + +#define CERTIFICATE_DB_DELETE(name, type, interface) \ + CERTIFICATE_DB_INTERNAL(name, type::Delete, interface) + +#endif // _CERTIFICATE_DATABASE_H_ + diff --git a/modules/certificate_dao/orm/certificate_db b/modules/certificate_dao/orm/certificate_db new file mode 100755 index 0000000..2dbe366 --- /dev/null +++ b/modules/certificate_dao/orm/certificate_db @@ -0,0 +1,9 @@ +SQL(BEGIN TRANSACTION;) + +CREATE_TABLE(CertificateInfo) + COLUMN_NOT_NULL(certificate, TEXT,DEFAULT '') + COLUMN_NOT_NULL(result, INT, DEFAULT 0) + TABLE_CONSTRAINTS(PRIMARY KEY(certificate)) +CREATE_TABLE_END() + +SQL(COMMIT;) diff --git a/modules/certificate_dao/orm/certificate_db_definitions b/modules/certificate_dao/orm/certificate_db_definitions new file mode 100644 index 0000000..6cfdc11 --- /dev/null +++ b/modules/certificate_dao/orm/certificate_db_definitions @@ -0,0 +1,5 @@ +DATABASE_START(certificate) + +#include "certificate_db" + +DATABASE_END() diff --git a/modules/certificate_dao/orm/certificate_db_sql_generator.h b/modules/certificate_dao/orm/certificate_db_sql_generator.h new file mode 100755 index 0000000..07c1816 --- /dev/null +++ b/modules/certificate_dao/orm/certificate_db_sql_generator.h @@ -0,0 +1,27 @@ +/* + * 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. + */ +/* + * @file certificate_db_sql_generator.h + * @author Leerang Song (leerang.song@samsung.com) + * @version 1.0 + * @brief Macro definitions for generating the SQL + * input file from database definition. + */ + +//Do not include this file directly! It is used only for SQL code generation. +#include + +#include "certificate_db_definitions" diff --git a/modules/certificate_dao/orm/orm_generator_certificate.h b/modules/certificate_dao/orm/orm_generator_certificate.h new file mode 100755 index 0000000..6822708 --- /dev/null +++ b/modules/certificate_dao/orm/orm_generator_certificate.h @@ -0,0 +1,24 @@ +/* + * 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. + */ + +#ifndef _ORM_GENERATOR_CERTIFICATE_H_ +#define _ORM_GENERATOR_CERTIFICATE_H_ + +#define ORM_GENERATOR_DATABASE_NAME certificate_db_definitions +#include +#undef ORM_GENERATOR_DATABASE_NAME + +#endif // _ORM_GENERATOR_CERTIFICATE_H_ \ No newline at end of file -- 2.34.1