From dd16d45947fc0f864f48198276d6255e6d74db64 Mon Sep 17 00:00:00 2001 From: Jihoon Chung Date: Thu, 13 Dec 2012 11:48:03 +0900 Subject: [PATCH] [Release] wrt-commons_0.2.79 Change-Id: I6c63f9baf6f89676f7d30a9489a06b9157b74856 --- debian/changelog | 14 +++ .../dao/CustomHandlerDatabase.cpp | 13 +- .../dao/custom_handler_dao.cpp | 92 +++++++++++++++ .../dao/custom_handler_dao_read_only.cpp | 111 +++++++++++++++++- .../CustomHandlerDatabase.h | 57 ++++----- .../custom-handler-dao-ro/common_dao_types.h | 20 ++++ .../custom_handler_dao_read_only.h | 26 +++- .../custom_handler_dao.h | 21 +++- modules/socket/src/unix_socket.cpp | 6 +- modules/widget_dao/dao/widget_dao.cpp | 5 +- .../widget_dao/dao/widget_dao_read_only.cpp | 3 - packaging/wrt-commons.spec | 4 +- 12 files changed, 327 insertions(+), 45 deletions(-) diff --git a/debian/changelog b/debian/changelog index 68a753b..215553f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,17 @@ +wrt-commons (0.2.79) unstable; urgency=low + + * Replacing DbWidgetHandle with WidgetPkgName in SecurityOriginDAO + * Handle remove() return value + * Delete unreachable code + * Handle chmod return value + * CustomHandlerDAO implementation + * Unhandled isWidgetInstalled return value + + * Git : framework/web/wrt-commons + * Tag : wrt-commons_0.2.79 + + -- Jihoon Chung Thu, 13 Dec 2012 11:15:24 +0900 + wrt-commons (0.2.78) unstable; urgency=low * Removing copy&paste code, part 2 diff --git a/modules/custom_handler_dao/dao/CustomHandlerDatabase.cpp b/modules/custom_handler_dao/dao/CustomHandlerDatabase.cpp index c11f2a0..d0b26c5 100644 --- a/modules/custom_handler_dao/dao/CustomHandlerDatabase.cpp +++ b/modules/custom_handler_dao/dao/CustomHandlerDatabase.cpp @@ -24,24 +24,23 @@ DPL::DB::SqlConnection::Flag::Type CustomHandler_DB_FLAGS = DPL::DB::SqlConnection::Flag::UseLucene; } -DPL::Mutex g_CustomHandlerDbQueriesMutex; -DPL::DB::ThreadDatabaseSupport m_customHandlerdbInterface( - CustomHandler_DB_DATABASE, CustomHandler_DB_FLAGS); - +DPL::Mutex g_dbQueriesMutex; +DPL::DB::ThreadDatabaseSupport g_dbInterface(CustomHandler_DB_DATABASE, + CustomHandler_DB_FLAGS); void attachDatabaseRO() { - m_customHandlerdbInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RO); + g_dbInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RO); } void attachDatabaseRW() { - m_customHandlerdbInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW); + g_dbInterface.AttachToThread(DPL::DB::SqlConnection::Flag::RW); } void detachDatabase() { - m_customHandlerdbInterface.DetachFromThread(); + g_dbInterface.DetachFromThread(); } } //namespace Interface diff --git a/modules/custom_handler_dao/dao/custom_handler_dao.cpp b/modules/custom_handler_dao/dao/custom_handler_dao.cpp index ee3d52f..cbab366 100644 --- a/modules/custom_handler_dao/dao/custom_handler_dao.cpp +++ b/modules/custom_handler_dao/dao/custom_handler_dao.cpp @@ -22,9 +22,28 @@ #include #include +#include + +using namespace DPL::DB::ORM; +using namespace DPL::DB::ORM::custom_handler; namespace CustomHandlerDB { +namespace { + +template +void fillRow(T& row, const CustomHandler& handler, const DPL::String& pkgName) +{ + row.Set_app_id(pkgName); + row.Set_target(handler.target); + row.Set_base_url(handler.base_url); + row.Set_url(handler.url); + row.Set_title(handler.title); + row.Set_user_allowed(handler.user_allowed); +} + +} // namespace + CustomHandlerDAO::CustomHandlerDAO(const DPL::String& pkgName) : CustomHandlerDAOReadOnly(pkgName) { @@ -34,4 +53,77 @@ CustomHandlerDAO::~CustomHandlerDAO() { } +void CustomHandlerDAO::registerContentHandler(const CustomHandler& handler) +{ + LogDebug("Registering content handler " << handler.target << " " << + handler.base_url); + Try { + ContentHandlers::Row row; + fillRow(row, handler, m_pkgName); + + // TODO remove previous if necessary + CUSTOM_HANDLER_DB_INSERT(insert, ContentHandlers); + insert->Values(row); + insert->Execute(); + } + Catch(DPL::DB::SqlConnection::Exception::Base){ + ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError, + "Failed to register custom handler"); + } +} + +void CustomHandlerDAO::registerProtocolHandler(const CustomHandler& handler) +{ + LogDebug("Registering protocol handler " << handler.target << " " << + handler.base_url); + Try { + ProtocolHandlers::Row row; + fillRow(row, handler, m_pkgName); + + // TODO remove previous if necessary + CUSTOM_HANDLER_DB_INSERT(insert, ProtocolHandlers); + insert->Values(row); + insert->Execute(); + } + Catch(DPL::DB::SqlConnection::Exception::Base){ + ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError, + "Failed to register custom handler"); + } +} + +void CustomHandlerDAO::unregisterContentHandler(const DPL::String& target, + const DPL::String& url) +{ + LogDebug("Removing content handler " << target << " " << url); + Try { + CUSTOM_HANDLER_DB_DELETE(deleteFrom, ContentHandlers); + deleteFrom->Where(And(Equals(m_pkgName), + And(Equals(target), + Equals(url)))); + deleteFrom->Execute(); + } + Catch(DPL::DB::SqlConnection::Exception::Base) { + ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError, + "Failed to remove content handler"); + } +} + +void CustomHandlerDAO::unregisterProtocolHandler(const DPL::String& target, + const DPL::String& url) +{ + LogDebug("Removing protocol handler " << target << " " << url); + Try { + CUSTOM_HANDLER_DB_DELETE(deleteFrom, ProtocolHandlers); + deleteFrom->Where(And(Equals(m_pkgName), + And(Equals(target), + Equals(url)))); + deleteFrom->Execute(); + } + Catch(DPL::DB::SqlConnection::Exception::Base) { + ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError, + "Failed to remove content handler"); + } + +} + } // namespace CustomHandlerDB diff --git a/modules/custom_handler_dao/dao/custom_handler_dao_read_only.cpp b/modules/custom_handler_dao/dao/custom_handler_dao_read_only.cpp index 2cd5e19..ef8e3ef 100644 --- a/modules/custom_handler_dao/dao/custom_handler_dao_read_only.cpp +++ b/modules/custom_handler_dao/dao/custom_handler_dao_read_only.cpp @@ -25,9 +25,40 @@ #include #include +#include + +using namespace DPL::DB::ORM; +using namespace DPL::DB::ORM::custom_handler; + namespace CustomHandlerDB { -CustomHandlerDAOReadOnly::CustomHandlerDAOReadOnly(const DPL::String& pkgName) +namespace { + +template +CustomHandlerPtr getSingleHandler(std::list row) +{ + CustomHandlerPtr handler; + if (!row.empty()) { + // There should be only one + if (row.size() > 1) { + ThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError, + "More than one handler registered"); + } + + handler.reset(new CustomHandler()); + handler->target = row.front().Get_target(); + handler->base_url = row.front().Get_base_url(); + handler->url = row.front().Get_url(); + handler->title = row.front().Get_title(); + handler->user_allowed = row.front().Get_user_allowed(); + } + return handler; +} + +} // namespace + +CustomHandlerDAOReadOnly::CustomHandlerDAOReadOnly(const DPL::String& pkgName) : + m_pkgName(pkgName) { } @@ -35,4 +66,82 @@ CustomHandlerDAOReadOnly::~CustomHandlerDAOReadOnly() { } +CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler( + const DPL::String& protocol, + const DPL::String& url) +{ + LogDebug("Getting protocol handler"); + Try{ + CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers); + + select->Where(And(Equals(m_pkgName), + And(Equals(protocol), + Equals(url)))); + + std::list list = select->GetRowList(); + return getSingleHandler(list); + } Catch(DPL::DB::SqlConnection::Exception::Base) { + ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError, + "Failed to get protocol handler"); + } +} + +CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler( + const DPL::String& content, + const DPL::String& url) +{ + LogDebug("Getting content handler"); + Try{ + CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers); + + select->Where(And(Equals(m_pkgName), + And(Equals(content), + Equals(url)))); + + std::list list = select->GetRowList(); + return getSingleHandler(list); + } Catch(DPL::DB::SqlConnection::Exception::Base) { + ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError, + "Failed to get content handler"); + } +} + +CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedProtocolHandler( + const DPL::String& protocol) +{ + LogDebug("Getting allowed protocol handler"); + Try{ + CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers); + + select->Where(And(Equals(m_pkgName), + And(Equals(protocol), + Equals(true)))); + + std::list list = select->GetRowList(); + return getSingleHandler(list); + } Catch(DPL::DB::SqlConnection::Exception::Base) { + ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError, + "Failed to get content handler"); + } +} + +CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedContentHandler( + const DPL::String& protocol) +{ + LogDebug("Getting allowed content handler"); + Try{ + CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers) + + select->Where(And(Equals(m_pkgName), + And(Equals(protocol), + Equals(true)))); + + std::list list = select->GetRowList(); + return getSingleHandler(list); + } Catch(DPL::DB::SqlConnection::Exception::Base) { + ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError, + "Failed to get content handler"); + } +} + } // namespace CustomHandlerDB diff --git a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h index 9b6bd71..fea6309 100644 --- a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h +++ b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h @@ -21,32 +21,6 @@ #include #include -extern DPL::Mutex g_CustomHandlerDbQueriesMutex; - -#define CUSTOM_HANDLER_DB_INTERNAL(tlsCommand, InternalType, interface) \ - static DPL::ThreadLocalVariable *tlsCommand ## Ptr = NULL; \ - { \ - DPL::Mutex::ScopedLock lock(&customHandlerDbQueriesMutex); \ - if (!tlsCommand ## Ptr) { \ - static DPL::ThreadLocalVariable tmp; \ - tlsCommand ## Ptr = &tmp; \ - } \ - } \ - DPL::ThreadLocalVariable &tlsCommand = *tlsCommand ## Ptr; \ - if (tlsCommand.IsNull()) { tlsCommand = InternalType(interface); } - -#define CUSTOM_HANDLER_DB_SELECT(name, type, interface) \ - CUSTOM_HANDLER_DB_INTERNAL(name, type::Select, interface) - -#define CUSTOM_HANDLER_DB_INSERT(name, type, interface) \ - CUSTOM_HANDLER_DB_INTERNAL(name, type::Insert, interface) - -#define CUSTOM_HANDLER_DB_UPDATE(name, type, interface) \ - CUSTOM_HANDLER_DB_INTERNAL(name, type::Update, interface) - -#define CUSTOM_HANDLER_DB_DELETE(name, type, interface) \ - CUSTOM_HANDLER_DB_INTERNAL(name, type::Delete, interface) - namespace CustomHandlerDB { namespace Interface { @@ -54,10 +28,39 @@ void attachDatabaseRO(); void attachDatabaseRW(); void detachDatabase(); -extern DPL::DB::ThreadDatabaseSupport m_customHandlerdbInterface; +extern DPL::Mutex g_dbQueriesMutex; +extern DPL::DB::ThreadDatabaseSupport g_dbInterface; } // namespace Interface } // namespace CustomHandlerDB +#define CUSTOM_HANDLER_DB_INTERNAL(tlsCommand, InternalType) \ + static DPL::ThreadLocalVariable *tlsCommand ## Ptr = NULL; \ + { \ + DPL::Mutex::ScopedLock lock( \ + &CustomHandlerDB::Interface::g_dbQueriesMutex); \ + if (!tlsCommand ## Ptr) { \ + static DPL::ThreadLocalVariable tmp; \ + tlsCommand ## Ptr = &tmp; \ + } \ + } \ + DPL::ThreadLocalVariable &tlsCommand = *tlsCommand ## Ptr; \ + if (tlsCommand.IsNull()) \ + { \ + tlsCommand = InternalType(&CustomHandlerDB::Interface::g_dbInterface); \ + } + +#define CUSTOM_HANDLER_DB_SELECT(name, type) \ + CUSTOM_HANDLER_DB_INTERNAL(name, type::Select) + +#define CUSTOM_HANDLER_DB_INSERT(name, type) \ + CUSTOM_HANDLER_DB_INTERNAL(name, type::Insert) + +#define CUSTOM_HANDLER_DB_UPDATE(name, type) \ + CUSTOM_HANDLER_DB_INTERNAL(name, type::Update) + +#define CUSTOM_HANDLER_DB_DELETE(name, type) \ + CUSTOM_HANDLER_DB_INTERNAL(name, type::Delete) + #endif /* _CUSTOM_HANDLER_DATABASE_H_ */ diff --git a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/common_dao_types.h b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/common_dao_types.h index ad55dc1..6be001c 100644 --- a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/common_dao_types.h +++ b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/common_dao_types.h @@ -24,8 +24,28 @@ #ifndef SHARE_COMMON_DAO_TYPES_H_ #define SHARE_COMMON_DAO_TYPES_H_ +#include +#include +#include + namespace CustomHandlerDB { +/** + * @brief Custom Handler struct + * + * Describes custom handler for protocol and content. + */ +struct CustomHandler +{ + DPL::String target; // protocol/content ("mailto"/"application/x-soup") + DPL::String base_url; // base url of registered page + DPL::String url; // url used for protocol/content handling + DPL::String title; // user friendly handler name + bool user_allowed; // true if user has allowed the handler +}; + +typedef std::shared_ptr CustomHandlerPtr; + } // namespace CustomHandlerDB #endif /* SHARE_COMMON_DAO_TYPES_H_ */ diff --git a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h index 941057b..021d6a8 100644 --- a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h +++ b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h @@ -27,6 +27,7 @@ #include #include +#include "common_dao_types.h" namespace CustomHandlerDB { @@ -47,7 +48,30 @@ class CustomHandlerDAOReadOnly explicit CustomHandlerDAOReadOnly(const DPL::String& pkgName); virtual ~CustomHandlerDAOReadOnly(); - // TODO + /** + * Returns protocol handler + */ + CustomHandlerPtr getProtocolHandler(const DPL::String& protocol, + const DPL::String& url); + + /** + * Returns content handler + */ + CustomHandlerPtr getContentHandler(const DPL::String& content, + const DPL::String& url); + + /** + * Returns allowed handler for given protocol + */ + CustomHandlerPtr getAllowedProtocolHandler(const DPL::String& protocol); + + /** + * Returns allowed handler for given content + */ + CustomHandlerPtr getAllowedContentHandler(const DPL::String& protocol); + + protected: + DPL::String m_pkgName; }; } // namespace CustomHandlerDB diff --git a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-rw/custom_handler_dao.h b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-rw/custom_handler_dao.h index e192ed7..d1307fe 100644 --- a/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-rw/custom_handler_dao.h +++ b/modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-rw/custom_handler_dao.h @@ -34,7 +34,26 @@ class CustomHandlerDAO : public CustomHandlerDAOReadOnly explicit CustomHandlerDAO(const DPL::String& pkgName); virtual ~CustomHandlerDAO(); - // TODO + /** + * Registers custom content handler + */ + void registerContentHandler(const CustomHandler& handler); + + /** + * Registers custom protocol handler + */ + void registerProtocolHandler(const CustomHandler& handler); + + /** + * Unregisters custom content handler + */ + void unregisterContentHandler(const DPL::String& target, + const DPL::String& burl); + /** + * Unregisters custom protocol handler + */ + void unregisterProtocolHandler(const DPL::String& target, + const DPL::String& url); }; } // namespace CustomHandlerDB diff --git a/modules/socket/src/unix_socket.cpp b/modules/socket/src/unix_socket.cpp index 29fae2b..3dd905c 100644 --- a/modules/socket/src/unix_socket.cpp +++ b/modules/socket/src/unix_socket.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace DPL { @@ -102,8 +103,9 @@ void UnixSocket::Bind(const Address &address) GenericSocket::Bind(address); // Always set proper permissions to the socket file - chmod(address.GetAddress().c_str(), 0777); + if(chmod(address.GetAddress().c_str(), 0777)<0){ + LogError("Error setting permissions to the socket file. Errno " << strerror(errno)); + } } - } } // namespace DPL diff --git a/modules/widget_dao/dao/widget_dao.cpp b/modules/widget_dao/dao/widget_dao.cpp index 44389c7..db2e682 100644 --- a/modules/widget_dao/dao/widget_dao.cpp +++ b/modules/widget_dao/dao/widget_dao.cpp @@ -111,7 +111,10 @@ void WidgetDAO::setPkgName_TEMPORARY_API(const WidgetPkgName& pkgName) using namespace DPL::DB::ORM; wrt::ScopedTransaction transaction(&WrtDatabase::interface()); - isWidgetInstalled(getHandle()); + if (!isWidgetInstalled(getHandle())) { + ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, + "Cannot find widget. Handle: " << getHandle()); + } wrt::WidgetInfo::Row row; row.Set_pkgname(pkgName); diff --git a/modules/widget_dao/dao/widget_dao_read_only.cpp b/modules/widget_dao/dao/widget_dao_read_only.cpp index 4e4a50c..5b13abe 100644 --- a/modules/widget_dao/dao/widget_dao_read_only.cpp +++ b/modules/widget_dao/dao/widget_dao_read_only.cpp @@ -136,9 +136,6 @@ WidgetPkgName getPkgNameByHandle(const DbWidgetHandle handle) } SQL_CONNECTION_EXCEPTION_HANDLER_END("Failed in getHandle") - - ThrowMsg(WidgetDAOReadOnly::Exception::WidgetNotExist, - "Failed to get widget by handle"); } } // namespace diff --git a/packaging/wrt-commons.spec b/packaging/wrt-commons.spec index 3da29d4..5bd9057 100644 --- a/packaging/wrt-commons.spec +++ b/packaging/wrt-commons.spec @@ -1,7 +1,7 @@ -#git:framework/web/wrt-commons wrt-commons 0.2.78 +#git:framework/web/wrt-commons wrt-commons 0.2.79 Name: wrt-commons Summary: Wrt common library -Version: 0.2.78 +Version: 0.2.79 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 -- 2.34.1