[Release] wrt-commons_0.2.79 submit/tizen_2.0/20121213.024927
authorJihoon Chung <jihoon.chung@samsung.com>
Thu, 13 Dec 2012 02:48:03 +0000 (11:48 +0900)
committerJihoon Chung <jihoon.chung@samsung.com>
Thu, 13 Dec 2012 02:48:15 +0000 (11:48 +0900)
Change-Id: I6c63f9baf6f89676f7d30a9489a06b9157b74856

12 files changed:
debian/changelog
modules/custom_handler_dao/dao/CustomHandlerDatabase.cpp
modules/custom_handler_dao/dao/custom_handler_dao.cpp
modules/custom_handler_dao/dao/custom_handler_dao_read_only.cpp
modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h
modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/common_dao_types.h
modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h
modules/custom_handler_dao/include/wrt-commons/custom-handler-dao-rw/custom_handler_dao.h
modules/socket/src/unix_socket.cpp
modules/widget_dao/dao/widget_dao.cpp
modules/widget_dao/dao/widget_dao_read_only.cpp
packaging/wrt-commons.spec

index 68a753bde016b09fbf0488ea5664f7477bbfc49d..215553f2af5bfbe8d12113fe43c2eb44cbd9d88d 100644 (file)
@@ -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 <jihoon.chung@samsung.com>  Thu, 13 Dec 2012 11:15:24 +0900
+
 wrt-commons (0.2.78) unstable; urgency=low
 
   * Removing copy&paste code, part 2
index c11f2a076fbd7a931643456b5a4e4c08759c5f7a..d0b26c50274f83d222a9295086651a0aad7f13b7 100644 (file)
@@ -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
index ee3d52f00e2630c03ac76967e58637a250e41a41..cbab36690ecca2a2651cd880c3cdde0c4155554c 100644 (file)
 
 #include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
 #include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
+#include <orm_generator_custom_handler.h>
+
+using namespace DPL::DB::ORM;
+using namespace DPL::DB::ORM::custom_handler;
 
 namespace CustomHandlerDB {
 
+namespace {
+
+template <typename T>
+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<ContentHandlers::app_id>(m_pkgName),
+                         And(Equals<ContentHandlers::target>(target),
+                             Equals<ContentHandlers::url>(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<ProtocolHandlers::app_id>(m_pkgName),
+                         And(Equals<ProtocolHandlers::target>(target),
+                             Equals<ProtocolHandlers::url>(url))));
+       deleteFrom->Execute();
+    }
+    Catch(DPL::DB::SqlConnection::Exception::Base) {
+       ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
+                  "Failed to remove content handler");
+    }
+
+}
+
 } // namespace CustomHandlerDB
index 2cd5e1993bb0816032e73eccb51851dccef46bc8..ef8e3efb1b6dc6819935dea197e50526c229f36e 100644 (file)
 #include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
 #include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
 
+#include <orm_generator_custom_handler.h>
+
+using namespace DPL::DB::ORM;
+using namespace DPL::DB::ORM::custom_handler;
+
 namespace CustomHandlerDB {
 
-CustomHandlerDAOReadOnly::CustomHandlerDAOReadOnly(const DPL::String& pkgName)
+namespace {
+
+template <typename T>
+CustomHandlerPtr getSingleHandler(std::list<T> 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<ProtocolHandlers::app_id>(m_pkgName),
+                      And(Equals<ProtocolHandlers::target>(protocol),
+                          Equals<ProtocolHandlers::url>(url))));
+
+        std::list<ProtocolHandlers::Row> 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<ContentHandlers::app_id>(m_pkgName),
+                      And(Equals<ContentHandlers::target>(content),
+                          Equals<ContentHandlers::url>(url))));
+
+        std::list<ContentHandlers::Row> 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<ProtocolHandlers::app_id>(m_pkgName),
+                      And(Equals<ProtocolHandlers::target>(protocol),
+                          Equals<ProtocolHandlers::user_allowed>(true))));
+
+        std::list<ProtocolHandlers::Row> 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<ContentHandlers::app_id>(m_pkgName),
+                      And(Equals<ContentHandlers::target>(protocol),
+                          Equals<ContentHandlers::user_allowed>(true))));
+
+        std::list<ContentHandlers::Row> list = select->GetRowList();
+        return getSingleHandler(list);
+    } Catch(DPL::DB::SqlConnection::Exception::Base) {
+        ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
+                   "Failed to get content handler");
+    }
+}
+
 } // namespace CustomHandlerDB
index 9b6bd7147b25052f4196a0d0573185a4810a540d..fea6309d895b6e774a6100eb156343e9c6b152ec 100644 (file)
 #include <dpl/mutex.h>
 #include <dpl/db/thread_database_support.h>
 
-extern DPL::Mutex g_CustomHandlerDbQueriesMutex;
-
-#define CUSTOM_HANDLER_DB_INTERNAL(tlsCommand, InternalType, interface)      \
-    static DPL::ThreadLocalVariable<InternalType> *tlsCommand ## Ptr = NULL; \
-    {                                                                        \
-        DPL::Mutex::ScopedLock lock(&customHandlerDbQueriesMutex);           \
-        if (!tlsCommand ## Ptr) {                                            \
-            static DPL::ThreadLocalVariable<InternalType> tmp;               \
-            tlsCommand ## Ptr = &tmp;                                        \
-        }                                                                    \
-    }                                                                        \
-    DPL::ThreadLocalVariable<InternalType> &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<InternalType> *tlsCommand ## Ptr = NULL;   \
+    {                                                                          \
+        DPL::Mutex::ScopedLock lock(                                           \
+                &CustomHandlerDB::Interface::g_dbQueriesMutex);                \
+        if (!tlsCommand ## Ptr) {                                              \
+            static DPL::ThreadLocalVariable<InternalType> tmp;                 \
+            tlsCommand ## Ptr = &tmp;                                          \
+        }                                                                      \
+    }                                                                          \
+    DPL::ThreadLocalVariable<InternalType> &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_ */
 
index ad55dc1445535f10b8daed513170fdd96829771b..6be001c2b174427e3770ad10fd42ff37dbebd368 100644 (file)
 #ifndef SHARE_COMMON_DAO_TYPES_H_
 #define SHARE_COMMON_DAO_TYPES_H_
 
+#include <list>
+#include <memory>
+#include <dpl/string.h>
+
 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<CustomHandler> CustomHandlerPtr;
+
 } // namespace CustomHandlerDB
 
 #endif /* SHARE_COMMON_DAO_TYPES_H_ */
index 941057b646bca0dda47b35ad526a978147203132..021d6a81ef6454ebac148b05b2ec3f67204b940d 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <dpl/string.h>
 #include <dpl/exception.h>
+#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
index e192ed7cc82229549e531e07336c23d8fd88e762..d1307fe88b12028c74a69d68cb2ca7aba8505200 100644 (file)
@@ -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
index 29fae2bee6b9c42c9957508eb4641f3729d0a7dc..3dd905c8d13c6d4bcfff159c40e9761709817b9a 100644 (file)
@@ -30,6 +30,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <string.h>
 
 namespace DPL
 {
@@ -102,8 +103,9 @@ void UnixSocket::Bind(const Address &address)
     GenericSocket<UnixSocket>::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
index 44389c72a427f2d000b3cad0ecf4538a1f880fc9..db2e6821d3c9bc43ea9dc53e85df935ed671dcc9 100644 (file)
@@ -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);
index 4e4a50c84ae324634d8a501aa3385793f8b748d5..5b13abe5d36c5dc5f7a03a4e7a2dd37c8d19175b 100644 (file)
@@ -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
 
index 3da29d45ee4bba6fae7c2850aeda6344c57503f1..5bd9057b09769525ca9a0df286f2808b2b3d2c8f 100644 (file)
@@ -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