From 00cedb17451f8216454a5c46ea23cf0b68f7f68d Mon Sep 17 00:00:00 2001 From: Jihoon Chung Date: Fri, 8 Mar 2013 17:52:55 +0900 Subject: [PATCH] [Release] wrt-commons_0.2.103 Change-Id: Ibad78464f559142cb211a89e2c21a708b7858b07 --- .gitignore | 2 +- CMakeLists.txt | 2 + build/CMakeLists.txt | 1 + build/certificate_dao/CMakeLists.txt | 21 + .../wrt-commons-certificate-dao.pc.in | 12 + build/encryption/CMakeLists.txt | 2 + debian/changelog | 10 + 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 + .../dpl/encryption/resource_decryption.h | 10 +- .../dpl/encryption/resource_encryption.h | 10 +- .../encryption/src/resource_decryption.cpp | 42 +- .../encryption/src/resource_encryption.cpp | 43 +- modules/utils/config.cmake | 2 + modules/utils/include/dpl/utils/path.h | 177 ++++++ modules/utils/src/path.cpp | 353 +++++++++++ modules/widget_dao/dao/widget_dao.cpp | 5 +- .../include/dpl/wrt-dao-ro/global_config.h | 2 +- modules/widget_dao/orm/wrt_db | 58 +- packaging/wrt-commons.spec | 7 +- tests/utils/CMakeLists.txt | 1 + tests/utils/path_tests.cpp | 571 ++++++++++++++++++ 32 files changed, 1904 insertions(+), 43 deletions(-) create mode 100644 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 create mode 100644 modules/utils/include/dpl/utils/path.h create mode 100644 modules/utils/src/path.cpp create mode 100644 tests/utils/path_tests.cpp 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..d36d0dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ ELSE(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling") ENDIF(DPL_LOG AND NOT CMAKE_BUILD_TYPE MATCHES "profiling") OPTION(WITH_TESTS "Build tests" OFF) + ADD_DEFINITIONS("-DDPL_LOGS_ENABLED") #@@@@@@@@@@@@@ # Compiler flags SET(CMAKE_C_FLAGS_PROFILING "-O2") @@ -190,6 +191,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 100644 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/build/encryption/CMakeLists.txt b/build/encryption/CMakeLists.txt index 7949864..e96b3dd 100644 --- a/build/encryption/CMakeLists.txt +++ b/build/encryption/CMakeLists.txt @@ -23,6 +23,7 @@ INCLUDE(FindPkgConfig) PKG_CHECK_MODULES(SYS_ENCRYPTION dlog openssl + osp-appfw REQUIRED ) @@ -56,6 +57,7 @@ TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} "-ldukgenerator" ) TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} "-lcryptsvc" ) +TARGET_LINK_LIBRARIES(${TARGET_DPL_ENCRYPTION} -L/usr/lib/osp -losp-appfw ) # Target library properties SET_TARGET_PROPERTIES(${TARGET_DPL_ENCRYPTION} PROPERTIES diff --git a/debian/changelog b/debian/changelog index 8cff814..a0a429e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,13 @@ +wrt-commons (0.2.103) unstable; urgency=low + + * Update tizen version to 2.1 + * Replaced VARCHAR with TEXT in databases + * Path class for DPL + tests + * Implement certificate confirm popup + * Add encrypt/decrypt API from trust zone + + -- Jihoon Chung Fri, 08 Mar 2013 17:17:26 +0900 + wrt-commons (0.2.102) unstable; urgency=low * DPL path join for class Path to be introduced 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 diff --git a/modules/encryption/include/dpl/encryption/resource_decryption.h b/modules/encryption/include/dpl/encryption/resource_decryption.h index a6d7af0..1f10fdb 100644 --- a/modules/encryption/include/dpl/encryption/resource_decryption.h +++ b/modules/encryption/include/dpl/encryption/resource_decryption.h @@ -28,8 +28,6 @@ #include #include -extern char** calculate(char*pappId, int idLen, int keyLen); - namespace WRTDecryptor { class ResourceDecryptor { @@ -51,9 +49,17 @@ class ResourceDecryptor unsigned char* decBuf, size_t chunkSize); + /* TrustZone */ + int DecryptChunkByTrustZone( + std::string pkgid, + const unsigned char *inBuffer, + int inBufSize); + void getDecryptStringByTrustZone(unsigned char *decBuffer); + private: AES_KEY* GetDecryptionKey(); AES_KEY m_decKey; + void *m_getBuffer; }; } //namespace WRTDecryptor diff --git a/modules/encryption/include/dpl/encryption/resource_encryption.h b/modules/encryption/include/dpl/encryption/resource_encryption.h index f2e4988..32d7132 100644 --- a/modules/encryption/include/dpl/encryption/resource_encryption.h +++ b/modules/encryption/include/dpl/encryption/resource_encryption.h @@ -28,8 +28,6 @@ #include #include -extern char** calculate(char*pappId, int idLen, int keyLen); - namespace WRTEncryptor { class ResourceEncryptor { @@ -53,9 +51,17 @@ class ResourceEncryptor void EncryptChunk(unsigned char* inputBuf, unsigned char* encBuf, size_t chunkSize); + /* TrustZone */ + int EncryptChunkByTrustZone( + std::string pkgid, + const unsigned char *plainBuffer, + int pBufSize); + void getEncStringByTrustZone(unsigned char *encBuffer); + private: AES_KEY GetEncryptionkey(); AES_KEY m_encKey; + void *m_getBuffer; }; } //namespace WRTEncryptor diff --git a/modules/encryption/src/resource_decryption.cpp b/modules/encryption/src/resource_decryption.cpp index c599e64..d51adfb 100644 --- a/modules/encryption/src/resource_decryption.cpp +++ b/modules/encryption/src/resource_decryption.cpp @@ -27,13 +27,16 @@ #include #include #include +#include +#include namespace { #define BITS_SIZE 128 #define KEY_SIZE 16 } namespace WRTDecryptor { -ResourceDecryptor::ResourceDecryptor() +ResourceDecryptor::ResourceDecryptor() : + m_getBuffer(NULL) { LogDebug("Started Decryption"); } @@ -84,4 +87,41 @@ void ResourceDecryptor::GetDecryptedChunk(unsigned char* AES_cbc_encrypt(inBuf, decBuf, inBufSize, &m_decKey, ivec, AES_DECRYPT); LogDebug("Success decryption"); } + +int ResourceDecryptor::DecryptChunkByTrustZone( + std::string pkgid, const unsigned char* inBuffer, + int inBufSize) +{ + using namespace Tizen::Base; + + const byte *b_pkgid = reinterpret_cast(pkgid.c_str()); + ByteBuffer appInfo; + appInfo.Construct(pkgid.length()); + appInfo.SetArray(b_pkgid, 0, pkgid.length()); + appInfo.Flip(); + + Tizen::Security::Crypto::_TrustZoneService* pInstance; + pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance(); + + ByteBuffer pBuf; + pBuf.Construct(inBufSize); + const byte *pByte = reinterpret_cast(inBuffer); + pBuf.SetArray(pByte, 0, inBufSize); + pBuf.Flip(); + + ByteBuffer *getBuffer = pInstance->_TrustZoneService::DecryptN(appInfo, pBuf); + + m_getBuffer = reinterpret_cast(getBuffer); + return getBuffer->GetRemaining(); +} + +void ResourceDecryptor::getDecryptStringByTrustZone(unsigned char *decBuffer) +{ + using namespace Tizen::Base; + LogDebug("Get decrypted string"); + ByteBuffer *buffer = reinterpret_cast(m_getBuffer); + memcpy(decBuffer, buffer->GetPointer(), buffer->GetRemaining()); + buffer->Reset(); +} + } //namespace WRTDecryptor diff --git a/modules/encryption/src/resource_encryption.cpp b/modules/encryption/src/resource_encryption.cpp index 8dc5284..67f9061 100644 --- a/modules/encryption/src/resource_encryption.cpp +++ b/modules/encryption/src/resource_encryption.cpp @@ -25,13 +25,16 @@ #include #include #include +#include +#include namespace { #define BITS_SIZE 128 #define KEY_SIZE 16 } namespace WRTEncryptor { -ResourceEncryptor::ResourceEncryptor() +ResourceEncryptor::ResourceEncryptor() : + m_getBuffer(NULL) { LogDebug("Started Encrytion"); } @@ -83,4 +86,42 @@ void ResourceEncryptor::EncryptChunk(unsigned char* AES_cbc_encrypt(inputBuf, encBuf, chunkSize, &m_encKey, ivec, AES_ENCRYPT); } + +int ResourceEncryptor::EncryptChunkByTrustZone( + std::string pkgid, + const unsigned char *plainBuffer, + int pBufSize) +{ + using namespace Tizen::Base; + + const byte *b_pkgid = reinterpret_cast(pkgid.c_str()); + ByteBuffer appInfo; + appInfo.Construct(pkgid.length()); + appInfo.SetArray(b_pkgid, 0, pkgid.length()); + appInfo.Flip(); + + Tizen::Security::Crypto::_TrustZoneService* pInstance; + pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance(); + + ByteBuffer pBuf; + pBuf.Construct(pBufSize); + const byte *pByte = reinterpret_cast(plainBuffer); + pBuf.SetArray(pByte, 0, pBufSize); + pBuf.Flip(); + + ByteBuffer *getBuffer = + pInstance->_TrustZoneService::EncryptN(appInfo, pBuf); + m_getBuffer = reinterpret_cast(getBuffer); + + return getBuffer->GetRemaining(); +} + +void ResourceEncryptor::getEncStringByTrustZone(unsigned char *encBuffer) +{ + using namespace Tizen::Base; + LogDebug("Get encrypted String"); + ByteBuffer *buffer = reinterpret_cast(m_getBuffer); + memcpy(encBuffer, buffer->GetPointer(), buffer->GetRemaining()); + buffer->Reset(); +} } //namespace ResourceEnc diff --git a/modules/utils/config.cmake b/modules/utils/config.cmake index aac2fce..828ca6c 100644 --- a/modules/utils/config.cmake +++ b/modules/utils/config.cmake @@ -27,6 +27,7 @@ SET(DPL_UTILS_SOURCES ${PROJECT_SOURCE_DIR}/modules/utils/src/widget_version.cpp ${PROJECT_SOURCE_DIR}/modules/utils/src/wrt_global_settings.cpp ${PROJECT_SOURCE_DIR}/modules/utils/src/wrt_utility.cpp + ${PROJECT_SOURCE_DIR}/modules/utils/src/path.cpp PARENT_SCOPE ) @@ -38,6 +39,7 @@ SET(DPL_UTILS_HEADERS ${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/widget_version.h ${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/wrt_global_settings.h ${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/wrt_utility.h + ${PROJECT_SOURCE_DIR}/modules/utils/include/dpl/utils/path.h PARENT_SCOPE ) diff --git a/modules/utils/include/dpl/utils/path.h b/modules/utils/include/dpl/utils/path.h new file mode 100644 index 0000000..6e025db --- /dev/null +++ b/modules/utils/include/dpl/utils/path.h @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file path.h + * @author Tomasz Iwanek (t.iwanek@samsung.com) + * @version 1.0 + */ +#ifndef PATH_H +#define PATH_H + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +namespace DPL { +namespace Utils { +class Path; +} +} + +std::ostream & operator<<(std::ostream & str, const DPL::Utils::Path & path); + +namespace DPL { +namespace Utils { +/** + * @brief The Path class path abstraction + * + * Class for expressing paths not limited not existing ones. + * It's possible to check if path exists, remove it or iterate it if it's directory + */ +class Path +{ +public: + DECLARE_EXCEPTION_TYPE(DPL::Exception, BaseException) + DECLARE_EXCEPTION_TYPE(BaseException, AlreadyExists) + DECLARE_EXCEPTION_TYPE(BaseException, NotExists) + DECLARE_EXCEPTION_TYPE(BaseException, NotDirectory) + DECLARE_EXCEPTION_TYPE(BaseException, OperationFailed) + DECLARE_EXCEPTION_TYPE(BaseException, EmptyPath) + DECLARE_EXCEPTION_TYPE(BaseException, InternalError) + + class Iterator : public std::iterator + { + public: + Iterator(); + Iterator(const char *); + Iterator& operator++(); + Iterator operator++(int); + bool operator==(const Iterator& rhs) const; + bool operator!=(const Iterator& rhs) const; + const Path & operator*(); + const Path * operator->(); + private: + void ReadNext(); + + std::shared_ptr m_dir; + std::shared_ptr m_path; + std::shared_ptr m_root; + }; + + explicit Path(const DPL::String & str); + explicit Path(const std::string & str); + explicit Path(const char * str); + + /** + * @brief DirectoryName shell's dirname equivalent + * @return directory name of given path + */ + std::string DirectoryName() const; + /** + * @brief Basename shell's basename equivalent + * @return base name of given path + */ + std::string Basename() const; + /** + * @brief Fullpath fullpath based on current working diretory + * @return full path + */ + std::string Fullpath() const; + + bool Exists() const; + bool IsDir() const; + bool IsFile() const; + bool IsSymlink() const; + + bool operator==(const Path & other) const; + bool operator!=(const Path & other) const; + + //appending to path + Path operator/(const DPL::String& part) const; + Path operator/(const std::string& part) const; + Path operator/(const char * part) const; + + Path & operator/=(const DPL::String& part); + Path & operator/=(const std::string& part); + Path & operator/=(const char * part); + + //foreach + Iterator begin() const; + Iterator end() const; + +private: + Path(); + + void Append(const std::string& part); + void Construct(const std::string & src); + + std::vector m_parts; + + friend std::ostream & ::operator<<(std::ostream & str, const DPL::Utils::Path & path); +}; + +/** + * @brief MkDir creates 'current path' as directory + * @param path path + * @param mode mode + */ +void MakeDir(const Path & path, mode_t mode = 0755); + +/** + * @brief MkFile creates 'current path' as empty file + * @param path path + */ +void MakeEmptyFile(const Path & path); + +/** + * @brief Remove removes 'current path' + * @param path path to remove + */ +void Remove(const Path & path); + +/** + * @brief Rename renames(moves) current path + * + * If you uses this method string to path is internally change + * and this object will store new path not only anymore + * @param from source path + * @param to target path + */ +void Rename(const Path & from, const Path & to); + +/** + * @brief Exists Checks if given path exists + * @param path path + * @return true if path exists + */ +bool Exists(const Path & path); + +} + +} + +//TODO: uncomment when user defiend literals are supported +///Path operator"" p(const char * str); + +#endif // PATH_H diff --git a/modules/utils/src/path.cpp b/modules/utils/src/path.cpp new file mode 100644 index 0000000..5ce44a1 --- /dev/null +++ b/modules/utils/src/path.cpp @@ -0,0 +1,353 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file path.h + * @author Tomasz Iwanek (t.iwanek@samsung.com) + * @version 1.0 + */ + +#include "dpl/utils/path.h" + +#include + +#include +#include +#include +#include +#include + +#include + +namespace DPL { + +namespace Utils { + +Path::Iterator::Iterator() //end iterator by default +{ +} + +Path::Iterator::Iterator(const char * str) +{ + m_root = std::shared_ptr(new Path(str)); + m_dir = std::shared_ptr(opendir(str), [](DIR * d){ if(d)closedir(d); }); //custom delete + if(m_dir.get() == NULL) + { + ThrowMsg(NotDirectory, "Not directory"); + } + ReadNext(); +} + +Path::Iterator& Path::Iterator::operator++() +{ + ReadNext(); + return *this; +} + +Path::Iterator Path::Iterator::operator++(int) +{ + Path::Iterator copy(*this); + ReadNext(); + return copy; +} + +void Path::Iterator::ReadNext() +{ + struct dirent * entry = readdir(m_dir.get()); + while(entry && (strcmp(entry->d_name, ".") == 0 || + strcmp(entry->d_name, "..") == 0)) + { + entry = readdir(m_dir.get()); + } + if(entry) + { + m_path = std::shared_ptr(new Path(*m_root)); + m_path->Append(entry->d_name); + } + else //transform into end iterator + { + m_path.reset(); + m_dir.reset(); + } +} + +bool Path::Iterator::operator==(const Path::Iterator& rhs) const +{ + if(m_dir.get() == NULL) + { + if(rhs.m_dir.get() == NULL) return true; + else return false; + } + else + { + if(rhs.m_dir.get() == NULL) return false; + } + return *m_path == *rhs.m_path; +} + +bool Path::Iterator::operator!=(const Path::Iterator& rhs) const +{ + return !this->operator==(rhs); +} + +const Path & Path::Iterator::operator*() +{ + return *m_path; +} + +const Path * Path::Iterator::operator->() +{ + return m_path.get(); +} + +Path::Path(const DPL::String & str) +{ + Construct(ToUTF8String(str)); +} + +Path::Path(const std::string & str) +{ + Construct(str); +} + +Path::Path(const char * str) +{ + Construct(std::string(str)); +} + +void Path::Construct(const std::string & src) +{ + if(src.empty()) ThrowMsg(EmptyPath, "Path cannot be empty"); + if(src[0] != '/') + { + DPL::ScopedFree root(getcwd(NULL,0)); + Tokenize(std::string(root.Get()), "\\/", std::inserter(m_parts, m_parts.begin()), true); + } + Tokenize(src, "\\/", std::inserter(m_parts, m_parts.end()), true); +} + +Path::Path() //for private usage +{ +} + +std::string Path::DirectoryName() const +{ + if(m_parts.empty()) ThrowMsg(InternalError, "Asking DirectoryName for root directory"); + std::string ret = Join(m_parts.begin(), --m_parts.end(), "/"); + return std::string("/") + ret; +} + +std::string Path::Basename() const +{ + if(m_parts.empty()) return ""; + else return m_parts.back(); +} + +std::string Path::Fullpath() const +{ + std::string ret = Join(m_parts.begin(), m_parts.end(), "/"); + return std::string ("/") + ret; +} + +//foreach +Path::Iterator Path::begin() const +{ + if(IsDir()) + { + return Iterator(Fullpath().c_str()); + } + else + { + ThrowMsg(NotDirectory, "Cannot iterate not a directory"); + } +} + +Path::Iterator Path::end() const +{ + return Iterator(); +} + + +bool Path::Exists() const +{ + struct stat tmp; + return (0 == lstat(Fullpath().c_str(), &tmp)); +} + +bool Path::IsDir() const +{ + struct stat tmp; + if (-1 == lstat(Fullpath().c_str(), &tmp)) + { + ThrowMsg(NotExists, DPL::GetErrnoString()); + } + return S_ISDIR(tmp.st_mode); +} + +bool Path::IsFile() const +{ + struct stat tmp; + if (-1 == lstat(Fullpath().c_str(), &tmp)) + { + ThrowMsg(NotExists, DPL::GetErrnoString()); + } + return S_ISREG(tmp.st_mode); +} + +bool Path::IsSymlink() const +{ + struct stat tmp; + if (-1 == lstat(Fullpath().c_str(), &tmp)) + { + ThrowMsg(NotExists, DPL::GetErrnoString()); + } + return S_ISLNK(tmp.st_mode); +} + +bool Path::operator==(const Path & other) const +{ + return m_parts == other.m_parts; +} + +bool Path::operator!=(const Path & other) const +{ + return m_parts != other.m_parts; +} + +Path Path::operator/(const DPL::String& part) const +{ + Path newOne; + newOne.Append(ToUTF8String(part)); + return newOne; +} + +Path Path::operator/(const std::string& part) const +{ + Path newOne; + newOne.Append(part); + return newOne; +} + +Path Path::operator/(const char * part) const +{ + Path newOne(*this); + newOne.Append(std::string(part)); + return newOne; +} + +Path & Path::operator/=(const DPL::String& part) +{ + Append(ToUTF8String(part)); +} + +Path & Path::operator/=(const std::string& part) +{ + Append(part); +} + +Path & Path::operator/=(const char * part) +{ + Append(std::string(part)); +} + +void Path::Append(const std::string& part) +{ + std::vector tokens; + Tokenize(part, "\\/", std::inserter(tokens, tokens.end()), true); + std::copy(tokens.begin(), tokens.end(), std::inserter(m_parts, m_parts.end())); +} + +void MakeDir(const Path & path, mode_t mode) +{ + if(!WrtUtilMakeDir(path.Fullpath(), mode)) ThrowMsg(Path::OperationFailed, "Cannot make directory"); +} + +void MakeEmptyFile(const Path & path) +{ + std::string fp = path.Fullpath(); + FILE* fd = fopen(fp.c_str(), "wx"); + if(!fd) + { + struct stat st; + if(lstat(fp.c_str(), &st) == 0) + { + ThrowMsg(Path::AlreadyExists, "File already exists"); + } + else + { + ThrowMsg(Path::OperationFailed, "Operation failed"); + } + } + fclose(fd); +} + +void Remove(const Path & path) +{ + if(!WrtUtilRemove(path.Fullpath())) ThrowMsg(Path::OperationFailed, "Cannot remove path"); +} + +void Rename(const Path & from, const Path & to) +{ + if(from == to) + { + return; + } + int code = 0; + if( (code = rename(from.Fullpath().c_str(), to.Fullpath().c_str())) ) + { + if(code == EXDEV) + { + Try + { + DPL::FileInput in(from.Fullpath()); + DPL::FileOutput out(to.Fullpath()); + DPL::Copy(&in, &out); + } + Catch(DPL::FileInput::Exception::Base) + { + ThrowMsg(Path::OperationFailed, "Cannot open input file " << from.Fullpath()); + } + Catch(DPL::FileOutput::Exception::Base) + { + ThrowMsg(Path::OperationFailed, "Cannot open output file " << to.Fullpath()); + } + } + else + { + ThrowMsg(Path::OperationFailed, DPL::GetErrnoString()); + } + } +} + +bool Exists(const Path & path) +{ + return path.Exists(); +} + +} + +} + +std::ostream & operator<<(std::ostream & str, const DPL::Utils::Path & path) +{ + str << path.Fullpath(); + return str; +} + +//TODO: uncomment when used defiend literals are supported +///DPL::Utils::Path operator""p(const char * str, size_t) +//{ +// return DPL::Utils::Path(str); +//} diff --git a/modules/widget_dao/dao/widget_dao.cpp b/modules/widget_dao/dao/widget_dao.cpp index 51c4627..8f65336 100644 --- a/modules/widget_dao/dao/widget_dao.cpp +++ b/modules/widget_dao/dao/widget_dao.cpp @@ -36,10 +36,6 @@ #include #include -namespace { - unsigned int seed = time(NULL); -} - namespace WrtDB { //TODO in current solution in each getter there exists a check //"IsWidgetInstalled". Maybe it should be verified, if it could be done @@ -249,6 +245,7 @@ DbWidgetHandle WidgetDAO::registerWidget( struct timeval tv; gettimeofday(&tv, NULL); DbWidgetHandle widgetHandle; + unsigned int seed = time(NULL); do { widgetHandle = rand_r(&seed); } while (isWidgetInstalled(widgetHandle)); diff --git a/modules/widget_dao/include/dpl/wrt-dao-ro/global_config.h b/modules/widget_dao/include/dpl/wrt-dao-ro/global_config.h index 67dcca6..a2fa66a 100644 --- a/modules/widget_dao/include/dpl/wrt-dao-ro/global_config.h +++ b/modules/widget_dao/include/dpl/wrt-dao-ro/global_config.h @@ -272,7 +272,7 @@ inline const char* GetWACVersion() inline const char* GetTizenVersion() { - return "1.0"; + return "2.1"; } inline const char* GetShareDirectoryPath() diff --git a/modules/widget_dao/orm/wrt_db b/modules/widget_dao/orm/wrt_db index 4f5f136..a10f230 100755 --- a/modules/widget_dao/orm/wrt_db +++ b/modules/widget_dao/orm/wrt_db @@ -20,15 +20,15 @@ SQL( CREATE_TABLE(WidgetInfo) COLUMN_NOT_NULL(app_id, INTEGER, PRIMARY KEY AUTOINCREMENT) - COLUMN(widget_type, INT, DEFAULT 1) - COLUMN(widget_id, VARCHAR(256), DEFAULT '') - COLUMN(widget_version, VARCHAR(256), DEFAULT '') + COLUMN(widget_type, INT, DEFAULT 1) + COLUMN(widget_id, TEXT, DEFAULT '') + COLUMN(widget_version, TEXT, DEFAULT '') COLUMN(widget_width, INT, DEFAULT 0) COLUMN(widget_height, INT, DEFAULT 0) - COLUMN(author_name, VARCHAR(256), DEFAULT '') - COLUMN(author_email, VARCHAR(256), DEFAULT '') - COLUMN(author_href, VARCHAR(256), DEFAULT '') - COLUMN(base_folder, VARCHAR(256), DEFAULT '') + COLUMN(author_name, TEXT, DEFAULT '') + COLUMN(author_email, TEXT, DEFAULT '') + COLUMN(author_href, TEXT, DEFAULT '') + COLUMN(base_folder, TEXT, DEFAULT '') COLUMN(webkit_plugins_required, TINYINT, DEFAULT 0) COLUMN(security_domain, INT, DEFAULT 0) COLUMN(csp_policy, TEXT, DEFAULT '') @@ -36,12 +36,12 @@ CREATE_TABLE(WidgetInfo) COLUMN(recognized, INT, DEFAULT 0) COLUMN(wac_signed, INT, DEFAULT 0) COLUMN(distributor_signed, INT, DEFAULT 0) - COLUMN(min_version, VARCHAR(16), DEFAULT '1.0') + COLUMN(min_version, TEXT, DEFAULT '1.0') COLUMN_NOT_NULL(back_supported, TINYINT, DEFAULT 0) COLUMN(access_network, TINYINT, DEFAULT 0) - COLUMN(defaultlocale, VARCHAR(256), DEFAULT 0) - COLUMN_NOT_NULL(tizen_pkgid, VARCHAR(256), DEFAULT '') - COLUMN_NOT_NULL(tizen_appid, VARCHAR(256), DEFAULT 0 UNIQUE) + COLUMN(defaultlocale, TEXT, DEFAULT 0) + COLUMN_NOT_NULL(tizen_pkgid, TEXT, DEFAULT '') + COLUMN_NOT_NULL(tizen_appid, TEXT, DEFAULT 0 UNIQUE) COLUMN(pkg_type, INT, DEFAULT 0) CREATE_TABLE_END() @@ -87,24 +87,24 @@ CREATE_TABLE(WidgetExtendedInfo) COLUMN(last_update_time, BIGINT, DEFAULT 0) COLUMN(install_time, BIGINT, DEFAULT 0) COLUMN(option_state, INT, DEFAULT 0) - COLUMN(share_href, VARCHAR(256), DEFAULT '') + COLUMN(share_href, TEXT, DEFAULT '') COLUMN(signature_type, INT, DEFAULT 0) COLUMN(updated, INT, DEFAULT 0) COLUMN(update_policy, INT, DEFAULT 0) COLUMN_NOT_NULL(test_widget, INT, CHECK(test_widget between 0 and 1) DEFAULT 0) - COLUMN(splash_img_src, VARCHAR(256), DEFAULT '') - COLUMN(background_page, VARCHAR(256), DEFAULT '') - COLUMN(installed_path, VARCHAR(512), DEFAULT '') + COLUMN(splash_img_src, TEXT, DEFAULT '') + COLUMN(background_page, TEXT, DEFAULT '') + COLUMN(installed_path, TEXT, DEFAULT '') TABLE_CONSTRAINTS( FOREIGN KEY(app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE ) CREATE_TABLE_END() CREATE_TABLE(WidgetPreference) - COLUMN_NOT_NULL(tizen_appid, VARCHAR(256), DEFAULT 0) - COLUMN_NOT_NULL(key_name, VARCHAR(256),) - COLUMN(key_value, VARCHAR(8000), DEFAULT '') - COLUMN(readonly, INT, DEFAULT 0) + COLUMN_NOT_NULL(tizen_appid, TEXT, DEFAULT 0) + COLUMN_NOT_NULL(key_name, TEXT,) + COLUMN(key_value, TEXT, DEFAULT '') + COLUMN(readonly, INT, DEFAULT 0) TABLE_CONSTRAINTS( PRIMARY KEY(tizen_appid, key_name), @@ -115,7 +115,7 @@ CREATE_TABLE_END() CREATE_TABLE(WidgetFeature) COLUMN_NOT_NULL(widget_feature_id, INTEGER, primary key autoincrement) COLUMN_NOT_NULL(app_id, INT,) - COLUMN_NOT_NULL(name, VARCHAR(256),) + COLUMN_NOT_NULL(name, TEXT,) COLUMN_NOT_NULL(required, INT,) COLUMN_NOT_NULL(rejected, INT,) TABLE_CONSTRAINTS( @@ -135,7 +135,7 @@ CREATE_TABLE_END() CREATE_TABLE(WidgetPrivilege) COLUMN_NOT_NULL(widget_privilege_id, INTEGER, primary key autoincrement) COLUMN_NOT_NULL(app_id, INT,) - COLUMN_NOT_NULL(name, VARCHAR(256),) + COLUMN_NOT_NULL(name, TEXT,) TABLE_CONSTRAINTS( FOREIGN KEY (app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE ) @@ -144,7 +144,7 @@ CREATE_TABLE_END() CREATE_TABLE(WidgetIcon) COLUMN_NOT_NULL(icon_id, INTEGER, primary key autoincrement) COLUMN_NOT_NULL(app_id, INT,) - COLUMN_NOT_NULL(icon_src, VARCHAR(256),) + COLUMN_NOT_NULL(icon_src, TEXT,) COLUMN(icon_width, INT, DEFAULT 0) COLUMN(icon_height, INT, DEFAULT 0) TABLE_CONSTRAINTS( @@ -165,7 +165,7 @@ CREATE_TABLE_END() CREATE_TABLE(WidgetStartFile) COLUMN_NOT_NULL(start_file_id, INTEGER, primary key autoincrement) COLUMN_NOT_NULL(app_id, INT,) - COLUMN_NOT_NULL(src, VARCHAR(256),) + COLUMN_NOT_NULL(src, TEXT,) TABLE_CONSTRAINTS( FOREIGN KEY(app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE ) @@ -194,7 +194,7 @@ CREATE_TABLE_END() CREATE_TABLE(WidgetAccessHost) COLUMN_NOT_NULL(app_id, INT,) - COLUMN_NOT_NULL(host, VARCHAR(256),) + COLUMN_NOT_NULL(host, TEXT,) TABLE_CONSTRAINTS( PRIMARY KEY(app_id, host) @@ -206,8 +206,8 @@ CREATE_TABLE(WidgetCertificateFingerprint) COLUMN_NOT_NULL(owner, INT,) COLUMN_NOT_NULL(chainid, INT,) COLUMN_NOT_NULL(type, INT,) - COLUMN(md5_fingerprint, VARCHAR(64),) - COLUMN(sha1_fingerprint, VARCHAR(64),) + COLUMN(md5_fingerprint, TEXT,) + COLUMN(sha1_fingerprint, TEXT,) COLUMN(common_name, VARCHAR(64),) TABLE_CONSTRAINTS( @@ -218,7 +218,7 @@ CREATE_TABLE_END() CREATE_TABLE(WidgetWARPInfo) COLUMN_NOT_NULL(app_id, INT,) - COLUMN_NOT_NULL(iri, VARCHAR(65536),) + COLUMN_NOT_NULL(iri, TEXT,) COLUMN(subdomain_access, INT, CHECK(subdomain_access between 0 and 1)) TABLE_CONSTRAINTS( @@ -359,8 +359,8 @@ SQL( /*TODO: It will be removed when user agent is fixed. User agent MUST be configurable in development...*/ CREATE_TABLE(UserAgents) - COLUMN_NOT_NULL(key_name, VARCHAR(256),) - COLUMN(key_value, VARCHAR(8000), DEFAULT '') + COLUMN_NOT_NULL(key_name, TEXT,) + COLUMN(key_value, TEXT, DEFAULT '') TABLE_CONSTRAINTS(PRIMARY KEY(key_name)) CREATE_TABLE_END() diff --git a/packaging/wrt-commons.spec b/packaging/wrt-commons.spec index b072049..77f4d1e 100644 --- a/packaging/wrt-commons.spec +++ b/packaging/wrt-commons.spec @@ -1,7 +1,7 @@ -#git:framework/web/wrt-commons wrt-commons 0.2.102 +#git:framework/web/wrt-commons wrt-commons 0.2.103 Name: wrt-commons Summary: Wrt common library -Version: 0.2.102 +Version: 0.2.103 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 @@ -23,9 +23,12 @@ BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(openssl) BuildRequires: pkgconfig(libiri) BuildRequires: pkgconfig(libidn) +BuildRequires: pkgconfig(osp-appfw) BuildRequires: libcryptsvc-devel BuildRequires: dukgenerator-devel +BuildRequires: osp-appfw-internal-devel Requires: libcryptsvc +Requires: osp-appfw %description Wrt common library diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt index 9898084..f17421b 100644 --- a/tests/utils/CMakeLists.txt +++ b/tests/utils/CMakeLists.txt @@ -26,6 +26,7 @@ SET(DPL_TESTS_UTIL_SOURCES ${TESTS_DIR}/utils/widget_version.cpp ${TESTS_DIR}/utils/bash_utils.cpp ${TESTS_DIR}/utils/wrt_utility.cpp + ${TESTS_DIR}/utils/path_tests.cpp ) #WRT_TEST_ADD_INTERNAL_DEPENDENCIES(${TARGET_NAME} ${TARGET_DPL_UTILS_EFL}) diff --git a/tests/utils/path_tests.cpp b/tests/utils/path_tests.cpp new file mode 100644 index 0000000..1a86a21 --- /dev/null +++ b/tests/utils/path_tests.cpp @@ -0,0 +1,571 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @file path.h + * @author Tomasz Iwanek (t.iwanek@samsung.com) + * @version 1.0 + */ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +using namespace DPL::Utils; + +namespace { +//do not used path here we test it +std::string rootTest = "/tmp/wrttest/"; +} + +RUNNER_TEST_GROUP_INIT(DPL_Path) + +/* +Name: path_touch +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_mkfile) +{ + DPL::ScopedDir sd(rootTest); + + struct stat st; + Path path = Path(rootTest) / "touch.txt"; + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created"); + RUNNER_ASSERT(!path.Exists()); + MakeEmptyFile(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created"); + RUNNER_ASSERT(path.Exists()); + RUNNER_ASSERT(path.IsFile()); + RUNNER_ASSERT(!path.IsDir()); + RUNNER_ASSERT(!path.IsSymlink()); +} + +/* +Name: path_touch +Description: tries to craete file when it exists +Expected: failure +*/ +RUNNER_TEST(path_mkfile_exists) +{ + DPL::ScopedDir sd(rootTest); + + Path path = Path(rootTest) / "touch.txt"; + MakeEmptyFile(path); + RUNNER_ASSERT(path.Exists()); + bool cannotCreate2ndTime = false; + Try + { + MakeEmptyFile(path); + } + Catch(Path::AlreadyExists) + { + cannotCreate2ndTime = true; + } + RUNNER_ASSERT_MSG(cannotCreate2ndTime, "File created should not be able to be created second time"); +} + +/* +Name: path_mkfile_invalid_path +Description: tries to create file in not exisitng directory +Expected: failure at creation +*/ +RUNNER_TEST(path_mkfile_invalid_path) +{ + DPL::ScopedDir sd(rootTest); + + Path path = Path(rootTest) / "not_existing" / "touch.txt"; + bool cannotCreate = false; + Try + { + MakeEmptyFile(path); + } + Catch(Path::OperationFailed) + { + cannotCreate = true; + } + RUNNER_ASSERT_MSG(cannotCreate, "File created should not be able to be created"); +} + +/* +Name: path_mkdir +Description: creates valid directory +Expected: success direcotry creation +*/ +RUNNER_TEST(path_mkdir) +{ + DPL::ScopedDir sd(rootTest); + + struct stat st; + Path path = Path(rootTest) / "touchDir"; + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created"); + RUNNER_ASSERT(!path.Exists()); + MakeDir(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created"); + RUNNER_ASSERT(path.Exists()); + RUNNER_ASSERT(!path.IsFile()); + RUNNER_ASSERT(path.IsDir()); + RUNNER_ASSERT(!path.IsSymlink()); +} + +/* +Name: path_symlink +Description: chekc if symlink is correctly recognized +Expected: method isSymlink returns true +*/ +RUNNER_TEST(path_symlink) +{ + DPL::ScopedDir sd(rootTest); + + struct stat st; + Path path = Path(rootTest) / "symlink"; + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Symlink should not be created"); + RUNNER_ASSERT(!path.Exists()); + (void)symlink("/nonexistisfile/file/file/file ", path.Fullpath().c_str()); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Symlink should be created"); + RUNNER_ASSERT(path.Exists()); + RUNNER_ASSERT(!path.IsFile()); + RUNNER_ASSERT(!path.IsDir()); + RUNNER_ASSERT(path.IsSymlink()); +} + +/* +Name: path_construction_empty +Description: tries to construct empty path +Expected: failure +*/ +RUNNER_TEST(path_construction_empty) +{ + bool passed = false; + Try + { + Path path1(std::string("")); + } + Catch(Path::EmptyPath) + { + passed = true; + } + RUNNER_ASSERT_MSG(passed, "Construction with empty path do not fails"); +} + +/* +Name: path_construction_root +Description: tries to construct root path +Expected: success +*/ +RUNNER_TEST(path_construction_root) +{ + Path path1(std::string("/")); + RUNNER_ASSERT(path1.Fullpath() == "/"); + RUNNER_ASSERT(path1.Basename() == ""); + bool passed = false; + Try + { + RUNNER_ASSERT(path1.DirectoryName() == "/"); + } + Catch(Path::InternalError) + { + passed = true; + } + RUNNER_ASSERT_MSG(passed, "Directory name for root should be an error"); +} + +/* +Name: path_construction_1 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_1) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + + Path path1(std::string("/test/bin/file")); + RUNNER_ASSERT(path1.Fullpath() == "/test/bin/file"); + RUNNER_ASSERT(path1.Basename() == "file"); + RUNNER_ASSERT(path1.DirectoryName() == "/test/bin"); +} + +/* +Name: path_construction_2 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_2) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + std::string cwd(sf.Get()); + + Path path2(std::string("test/bin/file.eas")); + RUNNER_ASSERT(path2.Fullpath() == cwd + "/test/bin/file.eas"); + RUNNER_ASSERT(path2.Basename() == "file.eas"); + RUNNER_ASSERT(path2.DirectoryName() == cwd + "/test/bin"); +} + +/* +Name: path_construction_3 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_3) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + std::string cwd(sf.Get()); + + Path path3("test/23/abc"); + RUNNER_ASSERT(path3.Fullpath() == cwd + "/test/23/abc"); + RUNNER_ASSERT(path3.Basename() == "abc"); + RUNNER_ASSERT(path3.DirectoryName() == cwd + "/test/23"); +} + +/* +Name: path_construction_4 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_4) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + + Path path4("/test/bin/abc"); + RUNNER_ASSERT(path4.Fullpath() == "/test/bin/abc"); + RUNNER_ASSERT(path4.Basename() == "abc"); + RUNNER_ASSERT(path4.DirectoryName() == "/test/bin"); +} + +/* +Name: path_construction_5 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_5) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + std::string cwd(sf.Get()); + + Path path5(DPL::String(L"test/bin/file.st.exe")); + RUNNER_ASSERT(path5.Fullpath() == cwd + "/test/bin/file.st.exe"); + RUNNER_ASSERT(path5.Basename() == "file.st.exe"); + RUNNER_ASSERT(path5.DirectoryName() == cwd + "/test/bin"); +} + +/* +Name: path_construction_6 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_6) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + + Path path6(DPL::String(L"/test/bin/file")); + RUNNER_ASSERT(path6.Fullpath() == "/test/bin/file"); + RUNNER_ASSERT(path6.Basename() == "file"); + RUNNER_ASSERT(path6.DirectoryName() == "/test/bin"); +} + +/* +Name: path_construction_7 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_7) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + std::string cwd(sf.Get()); + + Path path7 = Path("test") / "a///23/lol"; + RUNNER_ASSERT(path7.Fullpath() == cwd + "/test/a/23/lol"); + RUNNER_ASSERT(path7.Basename() == "lol"); + RUNNER_ASSERT(path7.DirectoryName() == cwd + "/test/a/23"); +} + +/* +Name: path_construction_8 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_8) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + + Path path8 = Path("/test/bin/") / "123" / "dir1.dll"; + RUNNER_ASSERT(path8.Fullpath() == "/test/bin/123/dir1.dll"); + RUNNER_ASSERT(path8.Basename() == "dir1.dll"); + RUNNER_ASSERT(path8.DirectoryName() == "/test/bin/123"); +} + +/* +Name: path_construction_9 +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_9) +{ + DPL::ScopedFree sf(getcwd(NULL, 0)); + + Path path9 = Path("/test/bin/file.txt//"); + RUNNER_ASSERT(path9.Fullpath() == "/test/bin/file.txt"); + RUNNER_ASSERT(path9.Basename() == "file.txt"); + RUNNER_ASSERT(path9.DirectoryName() == "/test/bin"); +} + +/* +Name: path_construction_10 +Description: constructs paths by appending +Expected: success full constrution +*/ +RUNNER_TEST(path_construction_10) +{ + Path path10 = Path("/test/"); + path10 /= "one"; + path10 /= std::string("two"); + path10 /= DPL::String(L"three"); + RUNNER_ASSERT(path10.Fullpath() == "/test/one/two/three"); + RUNNER_ASSERT(path10.Basename() == "three"); + RUNNER_ASSERT(path10.DirectoryName() == "/test/one/two"); +} + +/* +Name: path_remove +Description: tests removing paths +Expected: successfull path remove +*/ +RUNNER_TEST(path_remove_valid) +{ + DPL::ScopedDir sd(rootTest); + + struct stat st; + Path path = Path(rootTest) / "touchDir"; + RUNNER_ASSERT(!path.Exists()); + + MakeDir(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "Directory should be created"); + RUNNER_ASSERT(path.Exists()); + + Remove(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "Directory should not be created"); + RUNNER_ASSERT(!path.Exists()); + + MakeEmptyFile(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created"); + RUNNER_ASSERT(path.Exists()); + + Remove(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) != 0, "File should not be created"); + RUNNER_ASSERT(!path.Exists()); +} + +/* +Name: path_remove_invalid +Description: tests removing invalid paths +Expected: failure at path remove +*/ +RUNNER_TEST(path_remove_invalid) +{ + DPL::ScopedDir sd(rootTest); + + Path path = Path(rootTest) / "touchDir"; + + bool removedNotExisting = true; + Try + { + Remove(path); + } + Catch(Path::OperationFailed) + { + removedNotExisting = false; + } + RUNNER_ASSERT_MSG(!removedNotExisting, "Removing not existing file"); +} + +/* +Name: path_rename +Description: tests path renaming +Expected: path is successfully renamed +*/ +RUNNER_TEST(path_rename) +{ + DPL::ScopedDir sd(rootTest); + + struct stat st; + Path path = Path(rootTest) / "touchDir"; + Path dirpath = Path(rootTest) / "directory"; + Path path2 = dirpath / "touchDir2"; + + MakeDir(dirpath); + + MakeEmptyFile(path); + RUNNER_ASSERT_MSG(lstat(path.Fullpath().c_str(), &st) == 0, "File should be created"); + RUNNER_ASSERT(path.Exists()); + RUNNER_ASSERT(!path2.Exists()); + + Rename(path, path2); + RUNNER_ASSERT(!path.Exists()); + RUNNER_ASSERT(path2.Exists()); + + Rename(path2, path); + RUNNER_ASSERT(path.Exists()); + RUNNER_ASSERT(!path2.Exists()); + + //TODO: test for different devices +} + +/* +Name: path_rename_same +Description: tests if renam does not brokens file if target location is equal to source location +Expected: path is avaliable +*/ +RUNNER_TEST(path_rename_same) +{ + DPL::ScopedDir sd(rootTest); + + struct stat st; + Path path = Path(rootTest) / "touchDir"; + + MakeDir(path); + Rename(path, path); + RUNNER_ASSERT(path.Exists()); +} + +/* +Name: path_iterate_not_directory +Description: iterates not a directory +Expected: success full constrution +*/ +RUNNER_TEST(path_iterate_not_directory) +{ + DPL::ScopedDir sd(rootTest); + + Path fileTest = Path(rootTest) / "file.txt"; + MakeEmptyFile(fileTest); + + bool passed = false; + Try + { + FOREACH(file, fileTest) + { + + } + } + Catch(Path::NotDirectory) + { + passed = true; + } + RUNNER_ASSERT(passed); +} + +/* +Name: path_construction +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_iterate_empty_directory) +{ + DPL::ScopedDir sd(rootTest); + + Path dirTest = Path(rootTest) / "directory"; + MakeDir(dirTest); + + bool passed = true; + Try + { + FOREACH(file, dirTest) + { + passed = false; + LogError("Directory should be empty"); + } + } + Catch(Path::NotDirectory) + { + passed = false; + LogError("Directory should exists"); + } + RUNNER_ASSERT(passed); +} + +/* +Name: path_construction +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_iterate_notempty_directory) +{ + DPL::ScopedDir sd(rootTest); + + Path dirTest = Path(rootTest) / "directory"; + + Path path1 = Path(rootTest) / "directory" / "file1"; + Path path2 = Path(rootTest) / "directory" / "file2"; + Path path3 = Path(rootTest) / "directory" / "file3"; + + std::set resultSet; + std::set testSet; + testSet.insert(path1.Fullpath()); + testSet.insert(path2.Fullpath()); + testSet.insert(path3.Fullpath()); + + MakeDir(dirTest); + MakeEmptyFile(path1); + MakeEmptyFile(path2); + MakeEmptyFile(path3); + + FOREACH(file, dirTest) + { + resultSet.insert(file->Fullpath()); + } + + RUNNER_ASSERT_MSG(testSet == resultSet, "Testing"); +} + +/* +Name: path_construction +Description: constructs paths in many ways +Expected: success full constrution +*/ +RUNNER_TEST(path_iterator_copy_constructor) +{ + DPL::ScopedDir sd(rootTest); + + Path dirTest = Path(rootTest) / "directory"; + + Path path1 = Path(rootTest) / "directory" / "file1"; + Path path2 = Path(rootTest) / "directory" / "file2"; + Path path3 = Path(rootTest) / "directory" / "file3"; + + MakeDir(dirTest); + MakeEmptyFile(path1); + MakeEmptyFile(path2); + MakeEmptyFile(path3); + + std::shared_ptr iter1(new Path::Iterator((Path(rootTest) / "directory").Fullpath().c_str())); + + //as it's input iterator it's guaranteed for one element to be iterate only once + (*iter1)++; + std::shared_ptr iter2(new Path::Iterator( (*iter1))); + iter1.reset(); + (*iter2)++; + ++(*iter2); + RUNNER_ASSERT_MSG(*iter2 == dirTest.end(), "Iterator is in broken state"); + iter2.reset(); +} -- 2.34.1