framework/service/fs-utils.cpp
framework/service/file-system.cpp
framework/service/app-deleter.cpp
+ framework/service/iloader.cpp
framework/service/cs-loader.cpp
framework/service/wp-loader.cpp
- framework/service/engine-error-converter.cpp
framework/service/dir-blacklist.cpp
framework/ui/askuser.cpp
#include <stdexcept>
#include <dlfcn.h>
+#include <csre-error.h>
+
#include "common/audit/logger.h"
#include "common/exception.h"
-#include "service/engine-error-converter.h"
namespace Csr {
{
csre_cs_activated_e a = CSRE_CS_NOT_ACTIVATED;
- int ret = this->getEngineActivated(c, &a);
-
- if (ret != CSRE_ERROR_NONE)
- toException(ret);
+ this->getEngineActivated(c, &a);
if (a == CSRE_CS_NOT_ACTIVATED)
ThrowExc(CSR_ERROR_ENGINE_NOT_ACTIVATED, "engine is not activated yet");
}
-int CsLoader::contextCreate(csre_cs_context_h &c)
+void CsLoader::contextCreate(csre_cs_context_h &c)
{
- return this->m_pc.fpContextCreate(&c);
+ this->toException(this->m_pc.fpContextCreate(&c));
}
-int CsLoader::contextDestroy(csre_cs_context_h c)
+void CsLoader::contextDestroy(csre_cs_context_h c)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader context destroy");
- return this->m_pc.fpContextDestroy(c);
+ this->toException(this->m_pc.fpContextDestroy(c));
}
-int CsLoader::scanData(csre_cs_context_h c,
- const std::vector<unsigned char> &data,
- csre_cs_detected_h *pdetected)
+void CsLoader::scanData(csre_cs_context_h c,
+ const std::vector<unsigned char> &data,
+ csre_cs_detected_h *pdetected)
{
if (c == nullptr || data.empty() || pdetected == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader scan data");
this->checkEngineActivated(c);
- return this->m_pc.fpScanData(c, data.data(), data.size(), pdetected);
+ this->toException(this->m_pc.fpScanData(c, data.data(), data.size(), pdetected));
}
-int CsLoader::scanFile(csre_cs_context_h c, const std::string &filepath,
- csre_cs_detected_h *pdetected)
+void CsLoader::scanFile(csre_cs_context_h c, const std::string &filepath,
+ csre_cs_detected_h *pdetected)
{
if (c == nullptr || filepath.empty() || pdetected == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader scan file");
this->checkEngineActivated(c);
- return this->m_pc.fpScanFile(c, filepath.c_str(), pdetected);
+ this->toException(this->m_pc.fpScanFile(c, filepath.c_str(), pdetected));
}
-int CsLoader::scanAppOnCloud(csre_cs_context_h c, const std::string &appdir,
- csre_cs_detected_h *pdetected)
+void CsLoader::scanAppOnCloud(csre_cs_context_h c, const std::string &appdir,
+ csre_cs_detected_h *pdetected)
{
if (c == nullptr || appdir.empty() || pdetected == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader scan app on cloud");
this->checkEngineActivated(c);
- return this->m_pc.fpScanAppOnCloud(c, appdir.c_str(), pdetected);
+ this->toException(this->m_pc.fpScanAppOnCloud(c, appdir.c_str(), pdetected));
}
bool CsLoader::scanAppOnCloudSupported(void)
return this->m_pc.fpScanAppOnCloudSupported() == CSRE_CS_SUPPORTED;
}
-int CsLoader::getSeverity(csre_cs_detected_h d,
- csre_cs_severity_level_e *pseverity)
+void CsLoader::getSeverity(csre_cs_detected_h d,
+ csre_cs_severity_level_e *pseverity)
{
if (d == nullptr || pseverity == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get severity");
- return this->m_pc.fpGetSeverity(d, pseverity);
+ this->toException(this->m_pc.fpGetSeverity(d, pseverity));
}
-int CsLoader::getMalwareName(csre_cs_detected_h d, std::string &value)
+void CsLoader::getMalwareName(csre_cs_detected_h d, std::string &value)
{
if (d == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get malware name");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetMalwareName(d, cvalue);
- });
+ }));
}
-int CsLoader::getDetailedUrl(csre_cs_detected_h d, std::string &value)
+void CsLoader::getDetailedUrl(csre_cs_detected_h d, std::string &value)
{
if (d == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get detailed url");
#ifdef DETAILED_URL_BASE
DEBUG("get deatiled url with base!");
std::string name;
- auto ret = this->getMalwareName(d, name);
-
- if (ret == CSRE_ERROR_NONE)
- value = std::string(DETAILED_URL_BASE) + name;
+ this->getMalwareName(d, name);
- return ret;
+ value = std::string(DETAILED_URL_BASE) + name;
#else
DEBUG("get detailed url with engine getter API!");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetDetailedUrl(d, cvalue);
- });
+ }));
#endif
}
-int CsLoader::getErrorString(int ec, std::string &value)
+std::string CsLoader::getErrorString(int ec)
{
- return getValueCstr(value, [&](const char **cvalue) {
+ std::string value;
+
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetErrorString(ec, cvalue);
- });
+ }));
+
+ return value;
}
-int CsLoader::getEngineApiVersion(csre_cs_context_h c, std::string &value)
+void CsLoader::getEngineApiVersion(csre_cs_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get error string");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineApiVersion(c, cvalue);
- });
+ }));
}
-int CsLoader::getEngineVendor(csre_cs_context_h c, std::string &value)
+void CsLoader::getEngineVendor(csre_cs_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get engine vendor");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineVendor(c, cvalue);
- });
+ }));
}
-int CsLoader::getEngineName(csre_cs_context_h c, std::string &value)
+void CsLoader::getEngineName(csre_cs_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get engine name");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineName(c, cvalue);
- });
+ }));
}
-int CsLoader::getEngineVersion(csre_cs_context_h c, std::string &value)
+void CsLoader::getEngineVersion(csre_cs_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get engine version");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineVersion(c, cvalue);
- });
+ }));
}
-int CsLoader::getEngineDataVersion(csre_cs_context_h c, std::string &value)
+void CsLoader::getEngineDataVersion(csre_cs_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get engine version");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineDataVersion(c, cvalue);
- });
+ }));
}
-int CsLoader::getEngineLatestUpdateTime(csre_cs_context_h c, time_t *ptime)
+void CsLoader::getEngineLatestUpdateTime(csre_cs_context_h c, time_t *ptime)
{
if (c == nullptr || ptime == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get latest update time");
- return this->m_pc.fpGetEngineLatestUpdateTime(c, ptime);
+ this->toException(this->m_pc.fpGetEngineLatestUpdateTime(c, ptime));
}
-int CsLoader::getEngineActivated(csre_cs_context_h c, csre_cs_activated_e *pactivated)
+void CsLoader::getEngineActivated(csre_cs_context_h c, csre_cs_activated_e *pactivated)
{
if (c == nullptr || pactivated == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get engine activated");
auto ret = this->m_pc.fpGetEngineActivated(c, pactivated);
- if (ret == CSRE_ERROR_ENGINE_NOT_ACTIVATED) {
+ if (ret == CSRE_ERROR_ENGINE_NOT_ACTIVATED)
*pactivated = CSRE_CS_NOT_ACTIVATED;
- return CSRE_ERROR_NONE;
- } else {
- return ret;
- }
+ else if (ret != CSRE_ERROR_NONE)
+ this->toException(ret);
}
-int CsLoader::getEngineVendorLogo(csre_cs_context_h c, std::vector<unsigned char> &value)
+void CsLoader::getEngineVendorLogo(csre_cs_context_h c, std::vector<unsigned char> &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "cs loader get engine vendor logo");
if (retval == CSRE_ERROR_NONE && cvalue != nullptr && size != 0)
value.assign(cvalue, cvalue + size);
- return retval;
+ this->toException(retval);
}
void CsLoader::init(const std::string &enginePath, const std::string &roResDir,
"engine path: " << enginePath << " errno: " << errno);
}
+ try {
#ifndef DETAILED_URL_BASE
- this->m_pc.fpGetDetailedUrl = reinterpret_cast<FpGetDetailedUrl>(dlsym(handle,
- "csre_cs_detected_get_detailed_url"));
- if (this->m_pc.fpGetDetailedUrl == nullptr) {
- dlclose(this->m_pc.dlhandle);
- this->m_pc.dlhandle = nullptr;
- ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "Failed to load detailed_url getter from "
- "engine lib. engine path: " << enginePath << " errno: " << errno);
- }
+ this->m_pc.fpGetDetailedUrl = reinterpret_cast<FpGetDetailedUrl>(dlsym(handle,
+ "csre_cs_detected_get_detailed_url"));
+ if (this->m_pc.fpGetDetailedUrl == nullptr)
+ ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "Failed to load detailed_url getter from "
+ "engine lib. engine path: " << enginePath << " errno: " << errno);
#endif
- auto ret = this->m_pc.fpGlobalInit(roResDir.c_str(), rwWorkingDir.c_str());
+ auto ret = this->m_pc.fpGlobalInit(roResDir.c_str(), rwWorkingDir.c_str());
- if (ret != CSRE_ERROR_NONE) {
+ if (ret != CSRE_ERROR_NONE)
+ this->toException(ret);
+ } catch (...) {
dlclose(this->m_pc.dlhandle);
this->m_pc.dlhandle = nullptr;
- toException(ret);
+ throw;
}
}
if (!this->m_loader)
ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "null loader means engine not exist!");
- toException(this->m_loader->contextCreate(this->m_context));
+ this->m_loader->contextCreate(this->m_context);
}
CsEngineContext::~CsEngineContext()
{
- toException(this->m_loader->contextDestroy(this->m_context));
+ try {
+ this->m_loader->contextDestroy(this->m_context);
+ } catch (...) {
+ ERROR("exception in contextDestroy of cs loader");
+ }
}
csre_cs_context_h &CsEngineContext::get(void)
const std::string &rwWorkingDir);
virtual ~CsLoader();
- int contextCreate(csre_cs_context_h &);
- int contextDestroy(csre_cs_context_h);
- int scanData(csre_cs_context_h, const std::vector<unsigned char> &,
- csre_cs_detected_h *);
- int scanFile(csre_cs_context_h, const std::string &, csre_cs_detected_h *);
- int scanAppOnCloud(csre_cs_context_h, const std::string &, csre_cs_detected_h *);
+ void contextCreate(csre_cs_context_h &);
+ void contextDestroy(csre_cs_context_h);
+ void scanData(csre_cs_context_h, const std::vector<unsigned char> &,
+ csre_cs_detected_h *);
+ void scanFile(csre_cs_context_h, const std::string &, csre_cs_detected_h *);
+ void scanAppOnCloud(csre_cs_context_h, const std::string &, csre_cs_detected_h *);
bool scanAppOnCloudSupported(void);
- int getSeverity(csre_cs_detected_h, csre_cs_severity_level_e *);
- int getMalwareName(csre_cs_detected_h, std::string &);
- int getDetailedUrl(csre_cs_detected_h, std::string &);
+ void getSeverity(csre_cs_detected_h, csre_cs_severity_level_e *);
+ void getMalwareName(csre_cs_detected_h, std::string &);
+ void getDetailedUrl(csre_cs_detected_h, std::string &);
- int getErrorString(int, std::string &);
+ void getEngineApiVersion(csre_cs_context_h, std::string &);
+ void getEngineVendor(csre_cs_context_h, std::string &);
+ void getEngineName(csre_cs_context_h, std::string &);
+ void getEngineVersion(csre_cs_context_h, std::string &);
+ void getEngineDataVersion(csre_cs_context_h, std::string &);
+ void getEngineLatestUpdateTime(csre_cs_context_h, time_t *);
+ void getEngineActivated(csre_cs_context_h, csre_cs_activated_e *);
+ void getEngineVendorLogo(csre_cs_context_h, std::vector<unsigned char> &);
- int getEngineApiVersion(csre_cs_context_h, std::string &);
- int getEngineVendor(csre_cs_context_h, std::string &);
- int getEngineName(csre_cs_context_h, std::string &);
- int getEngineVersion(csre_cs_context_h, std::string &);
- int getEngineDataVersion(csre_cs_context_h, std::string &);
- int getEngineLatestUpdateTime(csre_cs_context_h, time_t *);
- int getEngineActivated(csre_cs_context_h, csre_cs_activated_e *);
- int getEngineVendorLogo(csre_cs_context_h, std::vector<unsigned char> &);
+ virtual std::string getErrorString(int) override;
private:
using FpGlobalInit = int(*)(const char *, const char *);
#include "common/audit/logger.h"
#include "common/exception.h"
#include "service/type-converter.h"
-#include "service/engine-error-converter.h"
#include "service/core-usage.h"
#include "service/dir-blacklist.h"
#include "ui/askuser.h"
if (this->m_loader) {
CsEngineContext csEngineContext(this->m_loader);
- toException(this->m_loader->getEngineDataVersion(csEngineContext.get(),
- this->m_dataVersion));
+ this->m_loader->getEngineDataVersion(csEngineContext.get(), this->m_dataVersion);
}
}
auto timestamp = ::time(nullptr);
- toException(this->m_loader->scanData(c, data, &result));
+ this->m_loader->scanData(c, data, &result);
// detected handle is null if it's safe
if (result == nullptr)
auto timestamp = ::time(nullptr);
csre_cs_detected_h result = nullptr;
- toException(this->m_loader->scanAppOnCloud(c, pkgPath, &result));
+ this->m_loader->scanAppOnCloud(c, pkgPath, &result);
if (!result)
return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
auto timestamp = ::time(nullptr);
csre_cs_detected_h result = nullptr;
- toException(this->m_loader->scanFile(c, file->getPath(), &result));
+ this->m_loader->scanFile(c, file->getPath(), &result);
if (!result) {
if (lastScanTime != -1)
auto timestamp = ::time(nullptr);
csre_cs_detected_h result = nullptr;
- toException(this->m_loader->scanFile(c, filepath, &result));
+ this->m_loader->scanFile(c, filepath, &result);
// detected handle is null if it's safe
if (result == nullptr)
csre_cs_severity_level_e eseverity = CSRE_CS_SEVERITY_LOW;
- toException(this->m_loader->getSeverity(result, &eseverity));
- toException(this->m_loader->getMalwareName(result, d.malwareName));
- toException(this->m_loader->getDetailedUrl(result, d.detailedUrl));
+ this->m_loader->getSeverity(result, &eseverity);
+ this->m_loader->getMalwareName(result, d.malwareName);
+ this->m_loader->getDetailedUrl(result, d.detailedUrl);
d.ts = timestamp;
d.severity = Csr::convert(eseverity);
#include <utility>
#include <cstdint>
+#include <csr-error.h>
+
#include "common/audit/logger.h"
#include "common/exception.h"
-#include "service/engine-error-converter.h"
-#include <csr-error.h>
namespace Csr {
auto &c = engineContext.get();
std::string value;
- toException(this->m_cs->getEngineName(c, value));
+ this->m_cs->getEngineName(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
} else {
auto &c = engineContext.get();
std::string value;
- toException(this->m_wp->getEngineName(c, value));
+ this->m_wp->getEngineName(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
}
auto &c = engineContext.get();
std::string value;
- toException(this->m_cs->getEngineVendor(c, value));
+ this->m_cs->getEngineVendor(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
} else {
auto &c = engineContext.get();
std::string value;
- toException(this->m_wp->getEngineVendor(c, value));
+ this->m_wp->getEngineVendor(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
}
auto &c = engineContext.get();
std::string value;
- toException(this->m_cs->getEngineVersion(c, value));
+ this->m_cs->getEngineVersion(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
} else {
auto &c = engineContext.get();
std::string value;
- toException(this->m_wp->getEngineVersion(c, value));
+ this->m_wp->getEngineVersion(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
}
auto &c = engineContext.get();
std::string value;
- toException(this->m_cs->getEngineDataVersion(c, value));
+ this->m_cs->getEngineDataVersion(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
} else {
auto &c = engineContext.get();
std::string value;
- toException(this->m_wp->getEngineDataVersion(c, value));
+ this->m_wp->getEngineDataVersion(c, value);
return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
}
auto &c = engineContext.get();
time_t value;
- toException(this->m_cs->getEngineLatestUpdateTime(c, &value));
+ this->m_cs->getEngineLatestUpdateTime(c, &value);
int64_t ts64 = static_cast<int64_t>(value);
auto &c = engineContext.get();
time_t value;
- toException(this->m_wp->getEngineLatestUpdateTime(c, &value));
+ this->m_wp->getEngineLatestUpdateTime(c, &value);
int64_t ts64 = static_cast<int64_t>(value);
auto &c = engineContext.get();
csre_cs_activated_e value;
- toException(this->m_cs->getEngineActivated(c, &value));
+ this->m_cs->getEngineActivated(c, &value);
if (value == CSRE_CS_ACTIVATED)
activated = CSR_ACTIVATED;
auto &c = engineContext.get();
csre_wp_activated_e value;
- toException(this->m_wp->getEngineActivated(c, &value));
+ this->m_wp->getEngineActivated(c, &value);
if (value == CSRE_WP_ACTIVATED)
activated = CSR_ACTIVATED;
+++ /dev/null
-/*
- * 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 engine-error-converter.h
- * @author Kyungwook Tak (k.tak@samsung.com)
- * @version 1.0
- * @brief convert engine error to custom exception
- */
-#pragma once
-
-namespace Csr {
-
-// throw converted common exception if it have to.
-void toException(int ee);
-
-}
* limitations under the License
*/
/*
- * @file engine-error-converter.cpp
- * @author Kyungwook Tak (k.tak@samsung.com)
- * @version 1.0
- * @brief convert engine error to custom exception
+ * @file iloader.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief engine loader abstract class
*/
-#include "service/engine-error-converter.h"
+#include "service/iloader.h"
-#include "common/exception.h"
+#include <stdexcept>
#include <csre-error.h>
+#include "common/exception.h"
+
namespace Csr {
-void toException(int ee)
+void ILoader::toException(int ee, bool internalErrorToString)
{
switch (ee) {
case CSRE_ERROR_NONE:
ThrowExc(CSR_ERROR_ENGINE_NOT_ACTIVATED, "engine is not activated yet");
default:
- ThrowExc(CSR_ERROR_ENGINE_INTERNAL, "engine internal error. ec: " << ee);
+ if (internalErrorToString) {
+ std::string errstr;
+ try {
+ errstr = this->getErrorString(ee);
+ } catch (...) {
+ ERROR("exception from engine loader's getErrorString.");
+ ThrowExc(CSR_ERROR_ENGINE_INTERNAL, "engine internal error. Failed to "
+ "get errno string... engine error code: " << ee);
+ }
+
+ ThrowExc(CSR_ERROR_ENGINE_INTERNAL, "engine internal error: " << errstr);
+ } else {
+ ThrowExc(CSR_ERROR_ENGINE_INTERNAL, "engine internal error. ec: " << ee);
+ }
}
}
*/
#pragma once
+#include <string>
+
namespace Csr {
class ILoader {
this->init(enginePath, roResDir, rwWorkingDir);
}
+ virtual std::string getErrorString(int) = 0;
+
protected:
virtual ~ILoader() = default;
virtual void deinit() = 0;
virtual void init(const std::string &enginePath, const std::string &roResDir,
const std::string &rwWorkingDir) = 0;
+
+ virtual void toException(int ee, bool internalErrorToString = true);
};
}
#include "common/audit/logger.h"
#include "common/exception.h"
-#include "service/engine-error-converter.h"
namespace Csr {
{
csre_wp_activated_e a = CSRE_WP_NOT_ACTIVATED;
- int ret = this->getEngineActivated(c, &a);
-
- if (ret != CSRE_ERROR_NONE)
- toException(ret);
+ this->getEngineActivated(c, &a);
if (a == CSRE_WP_NOT_ACTIVATED)
ThrowExc(CSR_ERROR_ENGINE_NOT_ACTIVATED, "engine is not activated yet");
}
-int WpLoader::contextCreate(csre_wp_context_h &c)
+void WpLoader::contextCreate(csre_wp_context_h &c)
{
- return this->m_pc.fpContextCreate(&c);
+ this->toException(this->m_pc.fpContextCreate(&c));
}
-int WpLoader::contextDestroy(csre_wp_context_h c)
+void WpLoader::contextDestroy(csre_wp_context_h c)
{
if (c == nullptr)
throw std::invalid_argument("wp loader context destroy");
- return this->m_pc.fpContextDestroy(c);
+ this->toException(this->m_pc.fpContextDestroy(c));
}
-int WpLoader::checkUrl(csre_wp_context_h c, const std::string &url,
+void WpLoader::checkUrl(csre_wp_context_h c, const std::string &url,
csre_wp_check_result_h *presult)
{
if (c == nullptr || url.empty() || presult == nullptr)
this->checkEngineActivated(c);
- return this->m_pc.fpCheckUrl(c, (const char *)url.c_str(), presult);
+ this->toException(this->m_pc.fpCheckUrl(c, (const char *)url.c_str(), presult));
}
-int WpLoader::getRiskLevel(csre_wp_check_result_h r,
- csre_wp_risk_level_e *plevel)
+void WpLoader::getRiskLevel(csre_wp_check_result_h r, csre_wp_risk_level_e *plevel)
{
if (r == nullptr || plevel == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader Get Risk Level error");
- return this->m_pc.fpGetRiskLevel(r, plevel);
+ this->toException(this->m_pc.fpGetRiskLevel(r, plevel));
}
-int WpLoader::getDetailedUrl(csre_wp_check_result_h r, std::string &value)
+void WpLoader::getDetailedUrl(csre_wp_check_result_h r, std::string &value)
{
if (r == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get detailed url error");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetDetailedUrl(r, cvalue);
- });
+ }));
}
-int WpLoader::getErrorString(int ec, std::string &value)
+std::string WpLoader::getErrorString(int ec)
{
- return getValueCstr(value, [&](const char **cvalue) {
+ std::string value;
+
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetErrorString(ec, cvalue);
- });
+ }));
+
+ return value;
}
-int WpLoader::getEngineApiVersion(csre_wp_context_h c, std::string &value)
+void WpLoader::getEngineApiVersion(csre_wp_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get error string");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineApiVersion(c, cvalue);
- });
+ }));
}
-int WpLoader::getEngineVendor(csre_wp_context_h c, std::string &value)
+void WpLoader::getEngineVendor(csre_wp_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get engine vendor");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineVendor(c, cvalue);
- });
+ }));
}
-int WpLoader::getEngineName(csre_wp_context_h c, std::string &value)
+void WpLoader::getEngineName(csre_wp_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get engine name");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineName(c, cvalue);
- });
+ }));
}
-int WpLoader::getEngineVersion(csre_wp_context_h c, std::string &value)
+void WpLoader::getEngineVersion(csre_wp_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get engine version");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineVersion(c, cvalue);
- });
+ }));
}
-int WpLoader::getEngineDataVersion(csre_wp_context_h c, std::string &value)
+void WpLoader::getEngineDataVersion(csre_wp_context_h c, std::string &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get engine version");
- return getValueCstr(value, [&](const char **cvalue) {
+ this->toException(getValueCstr(value, [&](const char **cvalue) {
return this->m_pc.fpGetEngineDataVersion(c, cvalue);
- });
+ }));
}
-int WpLoader::getEngineLatestUpdateTime(csre_wp_context_h c, time_t *ptime)
+void WpLoader::getEngineLatestUpdateTime(csre_wp_context_h c, time_t *ptime)
{
if (c == nullptr || ptime == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get latest update time");
- return this->m_pc.fpGetEngineLatestUpdateTime(c, ptime);
+ this->toException(this->m_pc.fpGetEngineLatestUpdateTime(c, ptime));
}
-int WpLoader::getEngineActivated(csre_wp_context_h c,
- csre_wp_activated_e *pactivated)
+void WpLoader::getEngineActivated(csre_wp_context_h c, csre_wp_activated_e *pactivated)
{
if (c == nullptr || pactivated == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get engine activated");
auto ret = this->m_pc.fpGetEngineActivated(c, pactivated);
- if (ret == CSRE_ERROR_ENGINE_NOT_ACTIVATED) {
+ if (ret == CSRE_ERROR_ENGINE_NOT_ACTIVATED)
*pactivated = CSRE_WP_NOT_ACTIVATED;
- return CSRE_ERROR_NONE;
- } else {
- return ret;
- }
+ else if (ret != CSRE_ERROR_NONE)
+ this->toException(ret);
}
-int WpLoader::getEngineVendorLogo(csre_wp_context_h c, std::vector<unsigned char> &value)
+void WpLoader::getEngineVendorLogo(csre_wp_context_h c, std::vector<unsigned char> &value)
{
if (c == nullptr)
ThrowExc(CSR_ERROR_INVALID_PARAMETER, "wp loader get engine vendor logo");
if (retval == CSRE_ERROR_NONE && cvalue != nullptr && size != 0)
value.assign(cvalue, cvalue + size);
- return retval;
+ this->toException(retval);
}
void WpLoader::init(const std::string &enginePath, const std::string &roResDir,
if (ret != CSRE_ERROR_NONE) {
dlclose(this->m_pc.dlhandle);
this->m_pc.dlhandle = nullptr;
- toException(ret);
+ this->toException(ret, false);
}
}
if (!this->m_loader)
ThrowExc(CSR_ERROR_ENGINE_NOT_EXIST, "null loader means engine not exist!");
- toException(this->m_loader->contextCreate(this->m_context));
+ this->m_loader->contextCreate(this->m_context);
}
WpEngineContext::~WpEngineContext()
{
- toException(this->m_loader->contextDestroy(this->m_context));
+ try {
+ this->m_loader->contextDestroy(this->m_context);
+ } catch (...) {
+ ERROR("exception in contextDestroy of wp loader");
+ }
}
csre_wp_context_h &WpEngineContext::get(void)
const std::string &rwWorkingDir);
virtual ~WpLoader();
- int contextCreate(csre_wp_context_h &);
- int contextDestroy(csre_wp_context_h);
- int checkUrl(csre_wp_context_h handle, const std::string &,
+ void contextCreate(csre_wp_context_h &);
+ void contextDestroy(csre_wp_context_h);
+ void checkUrl(csre_wp_context_h handle, const std::string &,
csre_wp_check_result_h *);
- int getRiskLevel(csre_wp_check_result_h, csre_wp_risk_level_e *);
- int getDetailedUrl(csre_wp_check_result_h, std::string &);
- int getErrorString(int, std::string &);
- int getEngineApiVersion(csre_wp_context_h, std::string &);
- int getEngineVendor(csre_wp_context_h, std::string &);
- int getEngineName(csre_wp_context_h, std::string &);
- int getEngineVersion(csre_wp_context_h, std::string &);
- int getEngineDataVersion(csre_wp_context_h, std::string &);
- int getEngineLatestUpdateTime(csre_wp_context_h, time_t *);
- int getEngineActivated(csre_wp_context_h, csre_wp_activated_e *);
- int getEngineVendorLogo(csre_wp_context_h, std::vector<unsigned char> &);
+ void getRiskLevel(csre_wp_check_result_h, csre_wp_risk_level_e *);
+ void getDetailedUrl(csre_wp_check_result_h, std::string &);
+ void getEngineApiVersion(csre_wp_context_h, std::string &);
+ void getEngineVendor(csre_wp_context_h, std::string &);
+ void getEngineName(csre_wp_context_h, std::string &);
+ void getEngineVersion(csre_wp_context_h, std::string &);
+ void getEngineDataVersion(csre_wp_context_h, std::string &);
+ void getEngineLatestUpdateTime(csre_wp_context_h, time_t *);
+ void getEngineActivated(csre_wp_context_h, csre_wp_activated_e *);
+ void getEngineVendorLogo(csre_wp_context_h, std::vector<unsigned char> &);
+
+ virtual std::string getErrorString(int) override;
private:
using FpGlobalInit = int(*)(const char *, const char *);
#include "common/audit/logger.h"
#include "common/exception.h"
#include "service/type-converter.h"
-#include "service/engine-error-converter.h"
#include "ui/askuser.h"
#include <csr-error.h>
if (this->m_loader) {
WpEngineContext wpEngineContext(this->m_loader);
- toException(this->m_loader->getEngineDataVersion(wpEngineContext.get(),
- this->m_dataVersion));
+ this->m_loader->getEngineDataVersion(wpEngineContext.get(), this->m_dataVersion);
}
}
auto &c = engineContext.get();
csre_wp_check_result_h result;
- toException(this->m_loader->checkUrl(c, url.c_str(), &result));
+ this->m_loader->checkUrl(c, url.c_str(), &result);
auto wr = convert(result);
WpResult wr;
csre_wp_risk_level_e elevel;
- toException(this->m_loader->getDetailedUrl(r, wr.detailedUrl));
- toException(this->m_loader->getRiskLevel(r, &elevel));
+ this->m_loader->getDetailedUrl(r, wr.detailedUrl);
+ this->m_loader->getRiskLevel(r, &elevel);
wr.riskLevel = Csr::convert(elevel);
return wr;
${CSR_FW_SRC_PATH}/service/fs-utils.cpp
${CSR_FW_SRC_PATH}/service/file-system.cpp
${CSR_FW_SRC_PATH}/service/app-deleter.cpp
+ ${CSR_FW_SRC_PATH}/service/iloader.cpp
${CSR_FW_SRC_PATH}/service/cs-loader.cpp
${CSR_FW_SRC_PATH}/service/wp-loader.cpp
- ${CSR_FW_SRC_PATH}/service/engine-error-converter.cpp
${CSR_FW_SRC_PATH}/service/dir-blacklist.cpp
${CSR_FW_SRC_PATH}/ui/popup/package-info.cpp
CHECK_IS_NOT_NULL(detected);
csre_cs_severity_level_e severity;
- ASSERT_IF(loader.getSeverity(detected, &severity), CSRE_ERROR_NONE);
+ loader.getSeverity(detected, &severity);
ASSERT_IF(severity, expected_severity);
std::string malware_name;
- ASSERT_IF(loader.getMalwareName(detected, malware_name), CSRE_ERROR_NONE);
+ loader.getMalwareName(detected, malware_name);
if (expected_malware_name != nullptr)
ASSERT_IF(malware_name, expected_malware_name);
std::string detailed_url;
- ASSERT_IF(loader.getDetailedUrl(detected, detailed_url), CSRE_ERROR_NONE);
+ loader.getDetailedUrl(detected, detailed_url);
if (expected_detailed_url != nullptr)
ASSERT_IF(detailed_url, expected_detailed_url);
ENGINE_DIR,
ENGINE_RW_WORKING_DIR)
{
- ASSERT_IF(loader.contextCreate(context), CSRE_ERROR_NONE);
+ loader.contextCreate(context);
}
~Handle()
{
- ASSERT_IF(loader.contextDestroy(context), CSRE_ERROR_NONE);
+ loader.contextDestroy(context);
}
Csr::CsLoader loader;
csre_cs_detected_h detected;
std::vector<unsigned char> data(cdata, cdata + strlen(cdata));
- ASSERT_IF(h.loader.scanData(h.context, data, &detected), CSRE_ERROR_NONE);
+ h.loader.scanData(h.context, data, &detected);
CHECK_IS_NULL(detected);
csre_cs_detected_h detected;
std::vector<unsigned char> data(cdata, cdata + strlen(cdata));
- ASSERT_IF(h.loader.scanData(h.context, data, &detected), CSRE_ERROR_NONE);
+ h.loader.scanData(h.context, data, &detected);
CHECK_IS_NOT_NULL(detected);
csre_cs_detected_h detected;
std::vector<unsigned char> data(cdata, cdata + strlen(cdata));
- ASSERT_IF(h.loader.scanData(h.context, data, &detected), CSRE_ERROR_NONE);
+ h.loader.scanData(h.context, data, &detected);
CHECK_IS_NOT_NULL(detected);
Handle h;
csre_cs_detected_h detected;
- ASSERT_IF(h.loader.scanFile(h.context, TEST_FILE_NORMAL, &detected),
- CSRE_ERROR_NONE);
+ h.loader.scanFile(h.context, TEST_FILE_NORMAL, &detected);
CHECK_IS_NULL(detected);
Handle h;
csre_cs_detected_h detected;
- ASSERT_IF(h.loader.scanFile(h.context, TEST_FILE_MALWARE, &detected),
- CSRE_ERROR_NONE);
+ h.loader.scanFile(h.context, TEST_FILE_MALWARE, &detected);
CHECK_IS_NOT_NULL(detected);
Handle h;
csre_cs_detected_h detected;
- ASSERT_IF(h.loader.scanFile(h.context, TEST_FILE_RISKY, &detected),
- CSRE_ERROR_NONE);
+ h.loader.scanFile(h.context, TEST_FILE_RISKY, &detected);
CHECK_IS_NOT_NULL(detected);
Handle h;
csre_cs_detected_h detected;
- ASSERT_IF(h.loader.scanAppOnCloud(h.context, TEST_APP_ROOT, &detected),
- CSRE_ERROR_NONE);
+ h.loader.scanAppOnCloud(h.context, TEST_APP_ROOT, &detected);
CHECK_IS_NOT_NULL(detected);
Handle h;
- std::string str;
-
- ASSERT_IF(h.loader.getErrorString(CSRE_ERROR_UNKNOWN, str), CSRE_ERROR_NONE);
+ std::string str = h.loader.getErrorString(CSRE_ERROR_UNKNOWN);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineVendor(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineVendor(h.context, str);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
std::vector<unsigned char> logo;
- ASSERT_IF(h.loader.getEngineVendorLogo(h.context, logo), CSRE_ERROR_NONE);
+ h.loader.getEngineVendorLogo(h.context, logo);
EXCEPTION_GUARD_END
}
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineVersion(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineVersion(h.context, str);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineDataVersion(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineDataVersion(h.context, str);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
time_t time = 0;
- ASSERT_IF(h.loader.getEngineLatestUpdateTime(h.context, &time),
- CSRE_ERROR_NONE);
+ h.loader.getEngineLatestUpdateTime(h.context, &time);
EXCEPTION_GUARD_END
}
Handle h;
csre_cs_activated_e activated;
- ASSERT_IF(h.loader.getEngineActivated(h.context, &activated), CSRE_ERROR_NONE);
+ h.loader.getEngineActivated(h.context, &activated);;
EXCEPTION_GUARD_END
}
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineApiVersion(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineApiVersion(h.context, str);
ASSERT_IF(str == CSRE_CS_API_VERSION, true);
EXCEPTION_GUARD_END
CHECK_IS_NOT_NULL(result);
csre_wp_risk_level_e risk_level;
- ASSERT_IF(loader.getRiskLevel(result, &risk_level), CSRE_ERROR_NONE);
+ loader.getRiskLevel(result, &risk_level);
ASSERT_IF(risk_level, expected.second.risk_level);
std::string detailed_url;
- ASSERT_IF(loader.getDetailedUrl(result, detailed_url), CSRE_ERROR_NONE);
+ loader.getDetailedUrl(result, detailed_url);
ASSERT_IF(detailed_url, expected.second.detailed_url);
EXCEPTION_GUARD_END
ENGINE_DIR,
ENGINE_RW_WORKING_DIR)
{
- ASSERT_IF(loader.contextCreate(context), CSRE_ERROR_NONE);
+ loader.contextCreate(context);
}
~Handle()
{
- ASSERT_IF(loader.contextDestroy(context), CSRE_ERROR_NONE);
+ loader.contextDestroy(context);
}
Csr::WpLoader loader;
for (const auto &expected : ExpectedResult) {
csre_wp_check_result_h result;
- ASSERT_IF(h.loader.checkUrl(h.context, expected.first.c_str(), &result),
- CSRE_ERROR_NONE);
+ h.loader.checkUrl(h.context, expected.first.c_str(), &result);
checkResult(h.loader, result, expected);
}
Handle h;
- std::string str;
-
- ASSERT_IF(h.loader.getErrorString(CSRE_ERROR_UNKNOWN, str), CSRE_ERROR_NONE);
+ std::string str = h.loader.getErrorString(CSRE_ERROR_UNKNOWN);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineVendor(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineVendor(h.context, str);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
std::vector<unsigned char> logo;
- ASSERT_IF(h.loader.getEngineVendorLogo(h.context, logo), CSRE_ERROR_NONE);
+ h.loader.getEngineVendorLogo(h.context, logo);
EXCEPTION_GUARD_END
}
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineVersion(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineVersion(h.context, str);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineDataVersion(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineDataVersion(h.context, str);
ASSERT_IF(str.empty(), false);
EXCEPTION_GUARD_END
Handle h;
time_t time = 0;
- ASSERT_IF(h.loader.getEngineLatestUpdateTime(h.context, &time),
- CSRE_ERROR_NONE);
+ h.loader.getEngineLatestUpdateTime(h.context, &time);
EXCEPTION_GUARD_END
}
Handle h;
csre_wp_activated_e activated;
- ASSERT_IF(h.loader.getEngineActivated(h.context, &activated), CSRE_ERROR_NONE);
+ h.loader.getEngineActivated(h.context, &activated);
EXCEPTION_GUARD_END
}
Handle h;
std::string str;
- ASSERT_IF(h.loader.getEngineApiVersion(h.context, str), CSRE_ERROR_NONE);
+ h.loader.getEngineApiVersion(h.context, str);
ASSERT_IF(str == CSRE_CS_API_VERSION, true);
EXCEPTION_GUARD_END