Type converter for capi <-> engine interface 74/67574/2
authorKyungwook Tak <k.tak@samsung.com>
Tue, 26 Apr 2016 12:14:04 +0000 (21:14 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Wed, 27 Apr 2016 09:07:18 +0000 (18:07 +0900)
Change-Id: I266fbcf1d4ad98db6fc4a054f4e0827f3d823dd1
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/CMakeLists.txt
src/framework/service/logic.cpp
src/framework/service/type-converter.cpp [new file with mode: 0644]
src/framework/service/type-converter.h [new file with mode: 0644]

index 3ac6910..2a73faf 100755 (executable)
@@ -29,6 +29,7 @@ PKG_CHECK_MODULES(${TARGET_CSR_SERVER}_DEP
 SET(${TARGET_CSR_SERVER}_SRCS
        framework/main/csr-main.cpp
        framework/service/logic.cpp
+       framework/service/type-converter.cpp
        framework/service/server-service.cpp
        framework/service/thread-pool.cpp
        framework/service/core-usage.cpp
index 0eddb7b..2d29e11 100644 (file)
@@ -29,6 +29,7 @@
 #include "common/cs-detected.h"
 #include "common/wp-result.h"
 #include "common/audit/logger.h"
+#include "service/type-converter.h"
 #include "ui/askuser.h"
 #include "csr/error.h"
 
@@ -381,50 +382,23 @@ WpResult Logic::convert(csre_wp_check_result_h &r)
 {
        DEBUG("convert engine result handle to WpResult start");
 
+       WpResult wr;
+
+       // getting risk level
        csre_wp_risk_level_e elevel;
        int eret = m_wp->getRiskLevel(r, &elevel);
 
        if (eret != CSRE_ERROR_NONE)
                throw std::runtime_error(FORMAT("Converting wp result. ret: " << eret));
 
-       DEBUG("Get engine risk level: " << static_cast<int>(elevel));
-
-       csr_wp_risk_level_e level;
-
-       switch (elevel) {
-       case CSRE_WP_RISK_LOW:
-               level = CSR_WP_RISK_LOW;
-               break;
-
-       case CSRE_WP_RISK_UNVERIFIED:
-               level = CSR_WP_RISK_UNVERIFIED;
-               break;
-
-       case CSRE_WP_RISK_MEDIUM:
-               level = CSR_WP_RISK_MEDIUM;
-               break;
-
-       case CSRE_WP_RISK_HIGH:
-               level = CSR_WP_RISK_HIGH;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid elevel: " << static_cast<int>(elevel)));
-       }
+       wr.riskLevel = Csr::convert(elevel);
 
-       std::string detailedUrl;
-       eret = m_wp->getDetailedUrl(r, detailedUrl);
+       // getting detailed url
+       eret = m_wp->getDetailedUrl(r, wr.detailedUrl);
 
        if (eret != CSRE_ERROR_NONE)
                throw std::runtime_error(FORMAT("Converting wp result. ret: " << eret));
 
-       DEBUG("Get detailed url from engine: " << detailedUrl);
-
-       WpResult wr;
-
-       wr.detailedUrl = detailedUrl;
-       wr.riskLevel = level;
-
        return wr;
 }
 
diff --git a/src/framework/service/type-converter.cpp b/src/framework/service/type-converter.cpp
new file mode 100644 (file)
index 0000000..a8fcda8
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ *  Copyright (c) 2016 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        type-converter.cpp
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Converts types of engine interface to capi interface
+ */
+#include "service/type-converter.h"
+
+#include <stdexcept>
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+
+csr_cs_severity_level_e convert(const csre_cs_severity_level_e &e)
+{
+       switch (e) {
+       case CSRE_CS_SEVERITY_LOW:
+               return CSR_CS_SEVERITY_LOW;
+
+       case CSRE_CS_SEVERITY_MEDIUM:
+               return CSR_CS_SEVERITY_MEDIUM;
+
+       case CSRE_CS_SEVERITY_HIGH:
+               return CSR_CS_SEVERITY_HIGH;
+
+       default:
+               throw std::logic_error(FORMAT("Invalid eseverity: " << static_cast<int>(e)));
+       }
+}
+
+csr_cs_threat_type_e convert(const csre_cs_threat_type_e &e)
+{
+       switch (e) {
+       case CSRE_CS_THREAT_MALWARE:
+               return CSR_CS_THREAT_MALWARE;
+
+       case CSRE_CS_THREAT_RISKY:
+               return CSR_CS_THREAT_RISKY;
+
+       case CSRE_CS_THREAT_GENERIC:
+               return CSR_CS_THREAT_GENERIC;
+
+       default:
+               throw std::logic_error(FORMAT("Invalid ethreat: " << static_cast<int>(e)));
+       }
+}
+
+csr_wp_risk_level_e convert(const csre_wp_risk_level_e &e)
+{
+       switch (e) {
+       case CSRE_WP_RISK_LOW:
+               return CSR_WP_RISK_LOW;
+
+       case CSRE_WP_RISK_UNVERIFIED:
+               return CSR_WP_RISK_UNVERIFIED;
+
+       case CSRE_WP_RISK_MEDIUM:
+               return CSR_WP_RISK_MEDIUM;
+
+       case CSRE_WP_RISK_HIGH:
+               return CSR_WP_RISK_HIGH;
+
+       default:
+               throw std::logic_error(FORMAT("Invalid elevel: " << static_cast<int>(e)));
+       }
+}
+
+}
diff --git a/src/framework/service/type-converter.h b/src/framework/service/type-converter.h
new file mode 100644 (file)
index 0000000..13e517e
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ *  Copyright (c) 2016 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        type-converter.h
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Converts types of engine interface to capi interface
+ */
+#pragma once
+
+#include "csre/content-screening-types.h"
+#include "csr/content-screening-types.h"
+#include "csre/web-protection-types.h"
+#include "csr/web-protection-types.h"
+
+namespace Csr {
+
+csr_cs_severity_level_e convert(const csre_cs_severity_level_e &);
+csr_cs_threat_type_e convert(const csre_cs_threat_type_e &);
+
+csr_wp_risk_level_e convert(const csre_wp_risk_level_e &);
+
+}