Select logic command in service level 84/68184/3
authorKyungwook Tak <k.tak@samsung.com>
Tue, 3 May 2016 02:13:03 +0000 (11:13 +0900)
committerkyungwook tak <k.tak@samsung.com>
Tue, 3 May 2016 03:03:54 +0000 (20:03 -0700)
Preparation of credential check mechanism.
Credential check (for privilege & remove file permission) is
essential and can be gotten from connection and we can retrieve
it in service level smoothly

Change-Id: Ib577e6e39bf52a868c2d52156a02f906b94ae46e
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/service/logic.cpp
src/framework/service/logic.h
src/framework/service/server-service.cpp
src/framework/service/server-service.h
src/framework/ui/popup/logic.cpp
src/framework/ui/popup/logic.h
src/framework/ui/popup/popup-service.cpp
src/framework/ui/popup/popup-service.h

index c9b9fd8..bd66427 100644 (file)
@@ -80,92 +80,6 @@ Logic::~Logic()
                ThrowExc(EngineError, "global deinit wp engine. ret: " << ret);
 }
 
-RawBuffer Logic::dispatch(const RawBuffer &in)
-{
-       auto info = getRequestInfo(in);
-
-       INFO("Request dispatch! CommandId: " << static_cast<int>(info.first));
-
-       switch (info.first) {
-       // Content scanning
-       case CommandId::SCAN_DATA: {
-               CsContextShPtr cptr;
-               RawBuffer data;
-               info.second.Deserialize(cptr, data);
-
-               return scanData(*cptr, data);
-       }
-
-       case CommandId::SCAN_FILE: {
-               CsContextShPtr cptr;
-               std::string filepath;
-               info.second.Deserialize(cptr, filepath);
-               return scanFile(*cptr, filepath);
-       }
-
-       case CommandId::GET_SCANNABLE_FILES: {
-               std::string dir;
-               info.second.Deserialize(dir);
-               return getScannableFiles(dir);
-       }
-
-       case CommandId::JUDGE_STATUS: {
-               std::string filepath;
-               int intAction;
-               info.second.Deserialize(filepath, intAction);
-               return judgeStatus(filepath, static_cast<csr_cs_action_e>(intAction));
-       }
-
-       case CommandId::GET_DETECTED: {
-               std::string filepath;
-               info.second.Deserialize(filepath);
-               return getDetected(filepath);
-       }
-
-       case CommandId::GET_DETECTED_LIST: {
-               StrSet dirSet;
-               info.second.Deserialize(dirSet);
-               return getDetectedList(dirSet);
-       }
-
-       case CommandId::GET_IGNORED: {
-               std::string filepath;
-               info.second.Deserialize(filepath);
-               return getIgnored(filepath);
-       }
-
-       case CommandId::GET_IGNORED_LIST: {
-               StrSet dirSet;
-               info.second.Deserialize(dirSet);
-               return getIgnoredList(dirSet);
-       }
-
-       // Web protection
-       /* TODO: should we separate command->logic mapping of CS and WP ? */
-       case CommandId::CHECK_URL: {
-               WpContextShPtr cptr;
-               std::string url;
-               info.second.Deserialize(cptr, url);
-               return checkUrl(*cptr, url);
-       }
-
-       default:
-               ThrowExc(InternalError, "Command id[" << static_cast<int>(info.first) <<
-                                "] isn't in range.");
-       }
-}
-
-std::pair<CommandId, BinaryQueue> Logic::getRequestInfo(const RawBuffer &data)
-{
-       CommandId id;
-
-       BinaryQueue q;
-       q.push(data);
-       q.Deserialize(id);
-
-       return std::make_pair(id, std::move(q));
-}
-
 RawBuffer Logic::scanData(const CsContext &context, const RawBuffer &data)
 {
        CsEngineContext engineContext(m_cs);
@@ -210,8 +124,7 @@ RawBuffer Logic::scanData(const CsContext &context, const RawBuffer &data)
        return BinaryQueue::Serialize(ret, d).pop();
 }
 
-RawBuffer Logic::scanFileHelper(const CsContext &context,
-                                                               const std::string &filepath)
+RawBuffer Logic::scanFileHelper(const CsContext &context, const std::string &filepath)
 {
        CsEngineContext engineContext(m_cs);
        auto &c = engineContext.get();
@@ -316,8 +229,7 @@ RawBuffer Logic::scanFile(const CsContext &context, const std::string &filepath)
 RawBuffer Logic::getScannableFiles(const std::string &dir)
 {
        auto lastScanTime = m_db->getLastScanTime(dir, m_csDataVersion);
-       auto visitor = (lastScanTime == -1) ?
-                       FsVisitor::create(dir) : FsVisitor::create(dir, lastScanTime);
+       auto visitor = FsVisitor::create(dir, lastScanTime);
 
        StrSet fileset;
        while (auto file = visitor->next()) {
@@ -334,8 +246,7 @@ RawBuffer Logic::getScannableFiles(const std::string &dir)
        return BinaryQueue::Serialize(CSR_ERROR_NONE, fileset).pop();
 }
 
-RawBuffer Logic::judgeStatus(const std::string &filepath,
-                                                        csr_cs_action_e action)
+RawBuffer Logic::judgeStatus(const std::string &filepath, csr_cs_action_e action)
 {
        auto history = m_db->getDetectedMalware(filepath);
 
@@ -471,8 +382,7 @@ RawBuffer Logic::checkUrl(const WpContext &context, const std::string &url)
        return BinaryQueue::Serialize(ret, wr).pop();
 }
 
-csr_cs_user_response_e Logic::getUserResponse(const CsContext &c,
-               const CsDetected &d)
+csr_cs_user_response_e Logic::getUserResponse(const CsContext &c, const CsDetected &d)
 {
        if (c.askUser == CSR_CS_NOT_ASK_USER)
                return CSR_CS_NO_ASK_USER;
@@ -499,8 +409,8 @@ csr_cs_user_response_e Logic::getUserResponse(const CsContext &c,
        return askUser.cs(cid, c.popupMessage, d);
 }
 
-csr_wp_user_response_e Logic::getUserResponse(const WpContext &c,
-               const std::string &url, const WpResult &wr)
+csr_wp_user_response_e Logic::getUserResponse(const WpContext &c, const std::string &url,
+                                                                                         const WpResult &wr)
 {
        if (c.askUser == CSR_WP_NOT_ASK_USER)
                return CSR_WP_NO_ASK_USER;
index 0986ed1..54159c5 100644 (file)
@@ -30,8 +30,6 @@
 #include "common/wp-context.h"
 #include "common/cs-detected.h"
 #include "common/wp-result.h"
-#include "common/command-id.h"
-#include "common/binary-queue.h"
 #include "db/manager.h"
 #include "service/cs-loader.h"
 #include "service/wp-loader.h"
@@ -45,14 +43,8 @@ public:
        Logic();
        virtual ~Logic();
 
-       RawBuffer dispatch(const RawBuffer &);
-
-private:
-       std::pair<CommandId, BinaryQueue> getRequestInfo(const RawBuffer &);
-
        RawBuffer scanData(const CsContext &context, const RawBuffer &data);
        RawBuffer scanFile(const CsContext &context, const std::string &filepath);
-       RawBuffer scanFileHelper(const CsContext &context, const std::string &filepath);
        RawBuffer getScannableFiles(const std::string &dir);
        RawBuffer judgeStatus(const std::string &filepath, csr_cs_action_e action);
        RawBuffer getDetected(const std::string &filepath);
@@ -62,6 +54,8 @@ private:
 
        RawBuffer checkUrl(const WpContext &context, const std::string &url);
 
+private:
+       RawBuffer scanFileHelper(const CsContext &context, const std::string &filepath);
        CsDetected convert(csre_cs_detected_h &);
        WpResult convert(csre_wp_check_result_h &);
 
index 3af1a1b..ef89551 100644 (file)
  */
 #include "service/server-service.h"
 
+#include <string>
+#include <vector>
+
+#include "common/command-id.h"
 #include "common/audit/logger.h"
+#include "common/exception.h"
+#include "common/cs-context.h"
+#include "common/wp-context.h"
+
+#include "csr/content-screening-types.h"
 
 namespace Csr {
 
@@ -35,12 +44,95 @@ ServerService::~ServerService()
 {
 }
 
+RawBuffer ServerService::process(const ConnShPtr &, RawBuffer &data)
+{
+       CommandId id;
+
+       BinaryQueue q;
+       q.push(data);
+       q.Deserialize(id);
+
+       switch (id) {
+       case CommandId::SCAN_DATA: {
+               CsContextShPtr cptr;
+               RawBuffer data;
+               q.Deserialize(cptr, data);
+
+               return m_logic.scanData(*cptr, data);
+       }
+
+       case CommandId::SCAN_FILE: {
+               CsContextShPtr cptr;
+               std::string filepath;
+               q.Deserialize(cptr, filepath);
+
+               return m_logic.scanFile(*cptr, filepath);
+       }
+
+       case CommandId::GET_SCANNABLE_FILES: {
+               std::string dir;
+               q.Deserialize(dir);
+
+               return m_logic.getScannableFiles(dir);
+       }
+
+       case CommandId::JUDGE_STATUS: {
+               std::string filepath;
+               int intAction;
+               q.Deserialize(filepath, intAction);
+
+               return m_logic.judgeStatus(filepath, static_cast<csr_cs_action_e>(intAction));
+       }
+
+       case CommandId::GET_DETECTED: {
+               std::string filepath;
+               q.Deserialize(filepath);
+
+               return m_logic.getDetected(filepath);
+       }
+
+       case CommandId::GET_DETECTED_LIST: {
+               StrSet dirSet;
+               q.Deserialize(dirSet);
+
+               return m_logic.getDetectedList(dirSet);
+       }
+
+       case CommandId::GET_IGNORED: {
+               std::string filepath;
+               q.Deserialize(filepath);
+
+               return m_logic.getIgnored(filepath);
+       }
+
+       case CommandId::GET_IGNORED_LIST: {
+               StrSet dirSet;
+               q.Deserialize(dirSet);
+
+               return m_logic.getIgnoredList(dirSet);
+       }
+
+       // Web protection
+       /* TODO: should we separate command->logic mapping of CS and WP ? */
+       case CommandId::CHECK_URL: {
+               WpContextShPtr cptr;
+               std::string url;
+               q.Deserialize(cptr, url);
+
+               return m_logic.checkUrl(*cptr, url);
+       }
+
+       default:
+               ThrowExc(InternalError, "Command isn't in range: " << static_cast<int>(id));
+       }
+}
+
 void ServerService::onMessageProcess(const ConnShPtr &connection)
 {
        DEBUG("let's dispatch it to worker threads.");
 
        auto process = [&](RawBuffer & buffer) {
-               connection->send(m_logic.dispatch(buffer));
+               connection->send(this->process(connection, buffer));
        };
 
        m_workqueue.submit(std::bind(process, connection->receive()));
index 6eb6ae0..8a99928 100644 (file)
@@ -22,6 +22,7 @@
 #pragma once
 
 #include "common/service.h"
+#include "common/types.h"
 #include "service/logic.h"
 #include "service/thread-pool.h"
 
@@ -35,6 +36,8 @@ public:
 private:
        virtual void onMessageProcess(const ConnShPtr &) override;
 
+       RawBuffer process(const ConnShPtr &, RawBuffer &);
+
        Logic m_logic;
        ThreadPool m_workqueue;
 };
index 6df3ab2..ea805f1 100644 (file)
@@ -29,6 +29,7 @@
 #include "common/audit/logger.h"
 #include "common/exception.h"
 #include "ui/common.h"
+#include "popup.h"
 
 #include "csr/content-screening-types.h"
 #include "csr/web-protection-types.h"
@@ -53,26 +54,6 @@ void registerCb(Evas_Object *button, int *rp, std::function<void()> &&func)
        g_callbackRegistry[*rp] = std::move(func);
 }
 
-bool isCsCommand(const CommandId &cid)
-{
-       switch (cid) {
-       case CommandId::CS_PROMPT_DATA:
-       case CommandId::CS_PROMPT_APP:
-       case CommandId::CS_PROMPT_FILE:
-       case CommandId::CS_NOTIFY_DATA:
-       case CommandId::CS_NOTIFY_APP:
-       case CommandId::CS_NOTIFY_FILE:
-               return true;
-
-       case CommandId::WP_PROMPT:
-       case CommandId::WP_NOTIFY:
-               return false;
-
-       default:
-               ThrowExc(InternalError, "Protocol error. unknown popup-service command id.");
-       }
-}
-
 void addButton(int *rp, const std::string &buttonPart,
                           const std::string &buttonText,
                           Popup &popup, RawBuffer &result)
@@ -97,68 +78,6 @@ Logic::~Logic()
 {
 }
 
-RawBuffer Logic::dispatch(const RawBuffer &in)
-{
-       auto info = getRequestInfo(in);
-       INFO("Request dispatch on popup-service. CommandId: " << static_cast<int>
-                (info.first));
-
-       if (isCsCommand(info.first)) {
-               std::string message;
-               CsDetected d;
-               info.second.Deserialize(message, d);
-
-               switch (info.first) {
-               case CommandId::CS_PROMPT_DATA:
-                       return csPromptData(message, d);
-
-               case CommandId::CS_PROMPT_APP:
-                       return csPromptApp(message, d);
-
-               case CommandId::CS_PROMPT_FILE:
-                       return csPromptFile(message, d);
-
-               case CommandId::CS_NOTIFY_DATA:
-                       return csNotifyData(message, d);
-
-               case CommandId::CS_NOTIFY_APP:
-                       return csNotifyApp(message, d);
-
-               case CommandId::CS_NOTIFY_FILE:
-                       return csNotifyFile(message, d);
-
-               default:
-                       ThrowExc(InternalError, "protocol error. invalid ui command id.");
-               }
-       } else {
-               std::string message;
-               UrlItem item;
-               info.second.Deserialize(message, item);
-
-               switch (info.first) {
-               case CommandId::WP_PROMPT:
-                       return wpPrompt(message, item);
-
-               case CommandId::WP_NOTIFY:
-                       return wpNotify(message, item);
-
-               default:
-                       ThrowExc(InternalError, "protocol error. invalid ui command id.");
-               }
-       }
-}
-
-std::pair<CommandId, BinaryQueue> Logic::getRequestInfo(const RawBuffer &data)
-{
-       BinaryQueue q;
-       q.push(data);
-
-       int int_id;
-       q.Deserialize(int_id);
-
-       return std::make_pair(static_cast<CommandId>(int_id), std::move(q));
-}
-
 RawBuffer Logic::csPromptData(const std::string &message,
                                                          const CsDetected &d) const
 {
index 4baf77c..6b9c231 100644 (file)
 #pragma once
 
 #include <string>
-#include <functional>
-#include <utility>
 
 #include "common/types.h"
 #include "common/cs-detected.h"
-#include "common/binary-queue.h"
 #include "ui/common.h"
-#include "popup.h"
 
 namespace Csr {
 namespace Ui {
@@ -39,11 +35,6 @@ public:
        Logic();
        virtual ~Logic();
 
-       RawBuffer dispatch(const RawBuffer &);
-
-private:
-       std::pair<CommandId, BinaryQueue> getRequestInfo(const RawBuffer &);
-
        RawBuffer csPromptData(const std::string &, const CsDetected &) const;
        RawBuffer csPromptApp(const std::string &, const CsDetected &) const;
        RawBuffer csPromptFile(const std::string &, const CsDetected &) const;
index fc999f9..95ce9b4 100644 (file)
  */
 #include "popup-service.h"
 
+#include "common/binary-queue.h"
 #include "common/audit/logger.h"
+#include "common/exception.h"
+#include "common/cs-detected.h"
 
 namespace Csr {
 namespace Ui {
 
+namespace {
+
+bool isCsCommand(const CommandId &cid)
+{
+       switch (cid) {
+       case CommandId::CS_PROMPT_DATA:
+       case CommandId::CS_PROMPT_APP:
+       case CommandId::CS_PROMPT_FILE:
+       case CommandId::CS_NOTIFY_DATA:
+       case CommandId::CS_NOTIFY_APP:
+       case CommandId::CS_NOTIFY_FILE:
+               return true;
+
+       case CommandId::WP_PROMPT:
+       case CommandId::WP_NOTIFY:
+               return false;
+
+       default:
+               ThrowExc(InternalError, "Protocol error. unknown popup-service command id.");
+       }
+}
+
+} // namespace nonymous
+
 PopupService::PopupService(const std::string &address) : Service(address)
 {
 }
@@ -34,11 +61,67 @@ PopupService::~PopupService()
 {
 }
 
+RawBuffer PopupService::process(const ConnShPtr &, RawBuffer &data)
+{
+       BinaryQueue q;
+       q.push(data);
+
+       int intCid;
+       q.Deserialize(intCid);
+
+       INFO("Request dispatch on popup-service. CommandId: " << static_cast<int>(intCid));
+
+       if (isCsCommand(static_cast<Ui::CommandId>(intCid))) {
+               std::string message;
+               CsDetected d;
+               q.Deserialize(message, d);
+
+               switch (static_cast<Ui::CommandId>(intCid)) {
+               case CommandId::CS_PROMPT_DATA:
+                       return m_logic.csPromptData(message, d);
+
+               case CommandId::CS_PROMPT_APP:
+                       return m_logic.csPromptApp(message, d);
+
+               case CommandId::CS_PROMPT_FILE:
+                       return m_logic.csPromptFile(message, d);
+
+               case CommandId::CS_NOTIFY_DATA:
+                       return m_logic.csNotifyData(message, d);
+
+               case CommandId::CS_NOTIFY_APP:
+                       return m_logic.csNotifyApp(message, d);
+
+               case CommandId::CS_NOTIFY_FILE:
+                       return m_logic.csNotifyFile(message, d);
+
+               default:
+                       ThrowExc(InternalError, "protocol error. invalid ui command id.");
+               }
+       } else {
+               std::string message;
+               UrlItem item;
+               q.Deserialize(message, item);
+
+               switch (static_cast<Ui::CommandId>(intCid)) {
+               case CommandId::WP_PROMPT:
+                       return m_logic.wpPrompt(message, item);
+
+               case CommandId::WP_NOTIFY:
+                       return m_logic.wpNotify(message, item);
+
+               default:
+                       ThrowExc(InternalError, "protocol error. invalid ui command id.");
+               }
+       }
+}
+
 void PopupService::onMessageProcess(const ConnShPtr &connection)
 {
        DEBUG("process message on popup service");
 
-       connection->send(m_logic.dispatch(connection->receive()));
+       auto in = connection->receive();
+       connection->send(this->process(connection, in));
 
        DEBUG("process done on popup service");
 }
index 4b506d3..c487621 100644 (file)
@@ -24,6 +24,7 @@
 #include <string>
 
 #include "common/service.h"
+#include "common/types.h"
 #include "logic.h"
 
 namespace Csr {
@@ -36,6 +37,9 @@ public:
 
 private:
        virtual void onMessageProcess(const ConnShPtr &) override;
+
+       RawBuffer process(const ConnShPtr &, RawBuffer &);
+
        Logic m_logic;
 };