[Engine API Changed] engine handles are removed 45/72745/4
authorKyungwook Tak <k.tak@samsung.com>
Thu, 2 Jun 2016 09:12:59 +0000 (18:12 +0900)
committerkyungwook tak <k.tak@samsung.com>
Fri, 3 Jun 2016 01:36:03 +0000 (18:36 -0700)
engine handles are replaced with context handles.

Change-Id: I8a088ecf1427b69d9f6cee3f5c88a79c6cd49648
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
16 files changed:
src/framework/service/cs-loader.cpp
src/framework/service/cs-loader.h
src/framework/service/cs-logic.cpp
src/framework/service/em-logic.cpp
src/framework/service/wp-loader.cpp
src/framework/service/wp-loader.h
src/framework/service/wp-logic.cpp
src/include/csre/csre-content-screening-engine-info.h
src/include/csre/csre-web-protection-engine-info.h
test/engine/content-screening/sample-engine.cpp
test/engine/web-protection/sample-engine.cpp
test/internals/test-api-engine-content-screening.cpp
test/internals/test-api-engine-web-protection.cpp
test/internals/test-cs-loader.cpp
test/internals/test-wp-loader.cpp
test/test-common.h

index 50cd496..ee5e77c 100644 (file)
@@ -122,92 +122,82 @@ int CsLoader::getErrorString(int ec, std::string &value)
        });
 }
 
-int CsLoader::getEngineInfo(csre_cs_engine_h &e)
+int CsLoader::getEngineApiVersion(csre_cs_context_h c, std::string &value)
 {
-       return this->m_pc.fpGetEngineInfo(&e);
-}
-
-int CsLoader::destroyEngine(csre_cs_engine_h e)
-{
-       return this->m_pc.fpDestroyEngine(e);
-}
-
-int CsLoader::getEngineApiVersion(csre_cs_engine_h e, std::string &value)
-{
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("cs loader get error string");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineApiVersion(e, cvalue);
+               return this->m_pc.fpGetEngineApiVersion(c, cvalue);
        });
 }
 
-int CsLoader::getEngineVendor(csre_cs_engine_h e, std::string &value)
+int CsLoader::getEngineVendor(csre_cs_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("cs loader get engine vendor");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineVendor(e, cvalue);
+               return this->m_pc.fpGetEngineVendor(c, cvalue);
        });
 }
 
-int CsLoader::getEngineName(csre_cs_engine_h e, std::string &value)
+int CsLoader::getEngineName(csre_cs_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("cs loader get engine name");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineName(e, cvalue);
+               return this->m_pc.fpGetEngineName(c, cvalue);
        });
 }
 
-int CsLoader::getEngineVersion(csre_cs_engine_h e, std::string &value)
+int CsLoader::getEngineVersion(csre_cs_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("cs loader get engine version");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineVersion(e, cvalue);
+               return this->m_pc.fpGetEngineVersion(c, cvalue);
        });
 }
 
-int CsLoader::getEngineDataVersion(csre_cs_engine_h e, std::string &value)
+int CsLoader::getEngineDataVersion(csre_cs_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("cs loader get engine version");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineDataVersion(e, cvalue);
+               return this->m_pc.fpGetEngineDataVersion(c, cvalue);
        });
 }
 
-int CsLoader::getEngineLatestUpdateTime(csre_cs_engine_h e, time_t *ptime)
+int CsLoader::getEngineLatestUpdateTime(csre_cs_context_h c, time_t *ptime)
 {
-       if (e == nullptr || ptime == nullptr)
+       if (c == nullptr || ptime == nullptr)
                throw std::invalid_argument("cs loader get latest update time");
 
-       return this->m_pc.fpGetEngineLatestUpdateTime(e, ptime);
+       return this->m_pc.fpGetEngineLatestUpdateTime(c, ptime);
 }
 
-int CsLoader::getEngineActivated(csre_cs_engine_h e,
+int CsLoader::getEngineActivated(csre_cs_context_h c,
                                                                 csre_cs_activated_e *pactivated)
 {
-       if (e == nullptr || pactivated == nullptr)
+       if (c == nullptr || pactivated == nullptr)
                throw std::invalid_argument("cs loader get engine activated");
 
-       return this->m_pc.fpGetEngineActivated(e, pactivated);
+       return this->m_pc.fpGetEngineActivated(c, pactivated);
 }
 
-int CsLoader::getEngineVendorLogo(csre_cs_engine_h e,
+int CsLoader::getEngineVendorLogo(csre_cs_context_h c,
                                                                  std::vector<unsigned char> &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("cs loader get engine vendor logo");
 
        unsigned char *cvalue = nullptr;
        unsigned int size = 0;
-       auto retval = this->m_pc.fpGetEngineVendorLogo(e, &cvalue, &size);
+       auto retval = this->m_pc.fpGetEngineVendorLogo(c, &cvalue, &size);
 
        if (retval == CSRE_ERROR_NONE && cvalue != nullptr && size != 0)
                value.assign(cvalue, cvalue + size);
@@ -253,10 +243,6 @@ void CsLoader::init(const std::string &enginePath, const std::string &roResDir,
                                                                  "csre_cs_detected_get_detailed_url"));
        this->m_pc.fpGetErrorString = reinterpret_cast <FpGetErrorString>(dlsym(handle,
                                                                  "csre_cs_get_error_string"));
-       this->m_pc.fpGetEngineInfo = reinterpret_cast<FpGetEngineInfo>(dlsym(handle,
-                                                                "csre_cs_engine_get_info"));
-       this->m_pc.fpDestroyEngine = reinterpret_cast<FpDestroyEngine>(dlsym(handle,
-                                                                "csre_cs_engine_destroy"));
        this->m_pc.fpGetEngineApiVersion = reinterpret_cast<FpGetEngineApiVersion>(dlsym(
                                                                           handle, "csre_cs_engine_get_api_version"));
        this->m_pc.fpGetEngineVendor = reinterpret_cast<FpGetEngineVendor>(dlsym(handle,
@@ -284,7 +270,6 @@ void CsLoader::init(const std::string &enginePath, const std::string &roResDir,
                        this->m_pc.fpGetMalwareName == nullptr ||
                        this->m_pc.fpGetDetailedUrl == nullptr ||
                        this->m_pc.fpGetErrorString == nullptr ||
-                       this->m_pc.fpGetEngineInfo == nullptr ||
                        this->m_pc.fpGetEngineApiVersion == nullptr ||
                        this->m_pc.fpGetEngineVendor == nullptr ||
                        this->m_pc.fpGetEngineName == nullptr ||
@@ -350,24 +335,4 @@ csre_cs_context_h &CsEngineContext::get(void)
        return this->m_context;
 }
 
-
-CsEngineInfo::CsEngineInfo(const std::shared_ptr<CsLoader> &loader) :
-       m_loader(loader), m_info(nullptr)
-{
-       if (!this->m_loader)
-               ThrowExc(EngineNotExist, "null loader means engine not exist!");
-
-       toException(this->m_loader->getEngineInfo(this->m_info));
-}
-
-CsEngineInfo::~CsEngineInfo()
-{
-       toException(this->m_loader->destroyEngine(this->m_info));
-}
-
-csre_cs_engine_h &CsEngineInfo::get(void)
-{
-       return this->m_info;
-}
-
 }
index abba72b..829acce 100644 (file)
@@ -52,16 +52,14 @@ public:
 
        int getErrorString(int, std::string &);
 
-       int getEngineInfo(csre_cs_engine_h &);
-       int destroyEngine(csre_cs_engine_h);
-       int getEngineApiVersion(csre_cs_engine_h, std::string &);
-       int getEngineVendor(csre_cs_engine_h, std::string &);
-       int getEngineName(csre_cs_engine_h, std::string &);
-       int getEngineVersion(csre_cs_engine_h, std::string &);
-       int getEngineDataVersion(csre_cs_engine_h, std::string &);
-       int getEngineLatestUpdateTime(csre_cs_engine_h, time_t *);
-       int getEngineActivated(csre_cs_engine_h, csre_cs_activated_e *);
-       int getEngineVendorLogo(csre_cs_engine_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> &);
 
 private:
        using FpGlobalInit = int(*)(const char *, const char *);
@@ -77,16 +75,14 @@ private:
        using FpGetMalwareName = int(*)(csre_cs_detected_h, const char **);
        using FpGetDetailedUrl = int(*)(csre_cs_detected_h, const char **);
        using FpGetErrorString = int(*)(int, const char **);
-       using FpGetEngineInfo = int(*)(csre_cs_engine_h *);
-       using FpDestroyEngine = int(*)(csre_cs_engine_h);
-       using FpGetEngineApiVersion = int(*)(csre_cs_engine_h, const char **);
-       using FpGetEngineVendor = int(*)(csre_cs_engine_h, const char **);
-       using FpGetEngineName = int(*)(csre_cs_engine_h, const char **);
-       using FpGetEngineVersion = int(*)(csre_cs_engine_h, const char **);
-       using FpGetEngineDataVersion = int(*)(csre_cs_engine_h, const char **);
-       using FpGetEngineLatestUpdateTime = int(*)(csre_cs_engine_h, time_t *);
-       using FpGetEngineActivated = int(*)(csre_cs_engine_h, csre_cs_activated_e *);
-       using FpGetEngineVendorLogo = int(*)(csre_cs_engine_h, unsigned char **,
+       using FpGetEngineApiVersion = int(*)(csre_cs_context_h, const char **);
+       using FpGetEngineVendor = int(*)(csre_cs_context_h, const char **);
+       using FpGetEngineName = int(*)(csre_cs_context_h, const char **);
+       using FpGetEngineVersion = int(*)(csre_cs_context_h, const char **);
+       using FpGetEngineDataVersion = int(*)(csre_cs_context_h, const char **);
+       using FpGetEngineLatestUpdateTime = int(*)(csre_cs_context_h, time_t *);
+       using FpGetEngineActivated = int(*)(csre_cs_context_h, csre_cs_activated_e *);
+       using FpGetEngineVendorLogo = int(*)(csre_cs_context_h, unsigned char **,
                                                                                 unsigned int *);
 
        struct PluginContext {
@@ -103,8 +99,6 @@ private:
                FpGetMalwareName fpGetMalwareName;
                FpGetDetailedUrl fpGetDetailedUrl;
                FpGetErrorString fpGetErrorString;
-               FpGetEngineInfo fpGetEngineInfo;
-               FpDestroyEngine fpDestroyEngine;
                FpGetEngineApiVersion fpGetEngineApiVersion;
                FpGetEngineVendor fpGetEngineVendor;
                FpGetEngineName fpGetEngineName;
@@ -132,15 +126,4 @@ private:
        csre_cs_context_h m_context;
 };
 
-class CsEngineInfo {
-public:
-       CsEngineInfo(const std::shared_ptr<CsLoader> &);
-       ~CsEngineInfo();
-       csre_cs_engine_h &get(void);
-
-private:
-       std::shared_ptr<CsLoader> m_loader;
-       csre_cs_engine_h m_info;
-};
-
 }
index 13a5d27..6e9c5a1 100644 (file)
@@ -62,8 +62,8 @@ CsLogic::CsLogic(const std::shared_ptr<CsLoader> &loader,
                ThrowExc(DbFailed, "Failed to init db");
 
        if (this->m_loader) {
-               CsEngineInfo csEngineInfo(this->m_loader);
-               toException(this->m_loader->getEngineDataVersion(csEngineInfo.get(),
+               CsEngineContext csEngineContext(this->m_loader);
+               toException(this->m_loader->getEngineDataVersion(csEngineContext.get(),
                                        this->m_dataVersion));
        }
 }
index 5561e11..3d1e7a7 100644 (file)
@@ -72,16 +72,16 @@ RawBuffer EmLogic::getEngineName(const EmContext &context)
        EXCEPTION_GUARD_START
 
        if (context.engineId == CSR_ENGINE_CS) {
-               CsEngineInfo engineInfo(this->m_cs);
-               auto &c = engineInfo.get();
+               CsEngineContext engineContext(this->m_cs);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_cs->getEngineName(c, value));
 
                return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
        } else {
-               WpEngineInfo engineInfo(this->m_wp);
-               auto &c = engineInfo.get();
+               WpEngineContext engineContext(this->m_wp);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_wp->getEngineName(c, value));
@@ -97,16 +97,16 @@ RawBuffer EmLogic::getEngineVendor(const EmContext &context)
        EXCEPTION_GUARD_START
 
        if (context.engineId == CSR_ENGINE_CS) {
-               CsEngineInfo engineInfo(this->m_cs);
-               auto &c = engineInfo.get();
+               CsEngineContext engineContext(this->m_cs);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_cs->getEngineVendor(c, value));
 
                return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
        } else {
-               WpEngineInfo engineInfo(this->m_wp);
-               auto &c = engineInfo.get();
+               WpEngineContext engineContext(this->m_wp);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_wp->getEngineVendor(c, value));
@@ -122,16 +122,16 @@ RawBuffer EmLogic::getEngineVersion(const EmContext &context)
        EXCEPTION_GUARD_START
 
        if (context.engineId == CSR_ENGINE_CS) {
-               CsEngineInfo engineInfo(this->m_cs);
-               auto &c = engineInfo.get();
+               CsEngineContext engineContext(this->m_cs);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_cs->getEngineVersion(c, value));
 
                return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
        } else {
-               WpEngineInfo engineInfo(this->m_wp);
-               auto &c = engineInfo.get();
+               WpEngineContext engineContext(this->m_wp);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_wp->getEngineVersion(c, value));
@@ -147,16 +147,16 @@ RawBuffer EmLogic::getEngineDataVersion(const EmContext &context)
        EXCEPTION_GUARD_START
 
        if (context.engineId == CSR_ENGINE_CS) {
-               CsEngineInfo engineInfo(this->m_cs);
-               auto &c = engineInfo.get();
+               CsEngineContext engineContext(this->m_cs);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_cs->getEngineDataVersion(c, value));
 
                return BinaryQueue::Serialize(CSR_ERROR_NONE, value).pop();
        } else {
-               WpEngineInfo engineInfo(this->m_wp);
-               auto &c = engineInfo.get();
+               WpEngineContext engineContext(this->m_wp);
+               auto &c = engineContext.get();
 
                std::string value;
                toException(this->m_wp->getEngineDataVersion(c, value));
@@ -172,8 +172,8 @@ RawBuffer EmLogic::getEngineUpdatedTime(const EmContext &context)
        EXCEPTION_GUARD_START
 
        if (context.engineId == CSR_ENGINE_CS) {
-               CsEngineInfo engineInfo(this->m_cs);
-               auto &c = engineInfo.get();
+               CsEngineContext engineContext(this->m_cs);
+               auto &c = engineContext.get();
 
                time_t value;
                toException(this->m_cs->getEngineLatestUpdateTime(c, &value));
@@ -182,8 +182,8 @@ RawBuffer EmLogic::getEngineUpdatedTime(const EmContext &context)
 
                return BinaryQueue::Serialize(CSR_ERROR_NONE, ts64).pop();
        } else {
-               WpEngineInfo engineInfo(this->m_wp);
-               auto &c = engineInfo.get();
+               WpEngineContext engineContext(this->m_wp);
+               auto &c = engineContext.get();
 
                time_t value;
                toException(this->m_wp->getEngineLatestUpdateTime(c, &value));
@@ -203,8 +203,8 @@ RawBuffer EmLogic::getEngineActivated(const EmContext &context)
        csr_activated_e activated = CSR_NOT_ACTIVATED;
 
        if (context.engineId == CSR_ENGINE_CS) {
-               CsEngineInfo engineInfo(this->m_cs);
-               auto &c = engineInfo.get();
+               CsEngineContext engineContext(this->m_cs);
+               auto &c = engineContext.get();
 
                csre_cs_activated_e value;
                toException(this->m_cs->getEngineActivated(c, &value));
@@ -217,8 +217,8 @@ RawBuffer EmLogic::getEngineActivated(const EmContext &context)
                        ThrowExc(EngineError, "Invalid returned activated val: " <<
                                         static_cast<int>(value));
        } else {
-               WpEngineInfo engineInfo(this->m_wp);
-               auto &c = engineInfo.get();
+               WpEngineContext engineContext(this->m_wp);
+               auto &c = engineContext.get();
 
                csre_wp_activated_e value;
                toException(this->m_wp->getEngineActivated(c, &value));
index a0eac40..573491d 100644 (file)
@@ -94,93 +94,82 @@ int WpLoader::getErrorString(int ec, std::string &value)
        });
 }
 
-
-int WpLoader::getEngineInfo(csre_wp_engine_h &e)
-{
-       return this->m_pc.fpGetEngineInfo(&e);
-}
-
-int WpLoader::destroyEngine(csre_wp_engine_h e)
-{
-       return this->m_pc.fpDestroyEngine(e);
-}
-
-int WpLoader::getEngineApiVersion(csre_wp_engine_h e, std::string &value)
+int WpLoader::getEngineApiVersion(csre_wp_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("wp loader get error string");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineApiVersion(e, cvalue);
+               return this->m_pc.fpGetEngineApiVersion(c, cvalue);
        });
 }
 
-int WpLoader::getEngineVendor(csre_wp_engine_h e, std::string &value)
+int WpLoader::getEngineVendor(csre_wp_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("wp loader get engine vendor");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineVendor(e, cvalue);
+               return this->m_pc.fpGetEngineVendor(c, cvalue);
        });
 }
 
-int WpLoader::getEngineName(csre_wp_engine_h e, std::string &value)
+int WpLoader::getEngineName(csre_wp_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("wp loader get engine name");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineName(e, cvalue);
+               return this->m_pc.fpGetEngineName(c, cvalue);
        });
 }
 
-int WpLoader::getEngineVersion(csre_wp_engine_h e, std::string &value)
+int WpLoader::getEngineVersion(csre_wp_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("wp loader get engine version");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineVersion(e, cvalue);
+               return this->m_pc.fpGetEngineVersion(c, cvalue);
        });
 }
 
-int WpLoader::getEngineDataVersion(csre_wp_engine_h e, std::string &value)
+int WpLoader::getEngineDataVersion(csre_wp_context_h c, std::string &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("wp loader get engine version");
 
        return getValueCstr(value, [&](const char **cvalue) {
-               return this->m_pc.fpGetEngineDataVersion(e, cvalue);
+               return this->m_pc.fpGetEngineDataVersion(c, cvalue);
        });
 }
 
-int WpLoader::getEngineLatestUpdateTime(csre_wp_engine_h e, time_t *ptime)
+int WpLoader::getEngineLatestUpdateTime(csre_wp_context_h c, time_t *ptime)
 {
-       if (e == nullptr || ptime == nullptr)
+       if (c == nullptr || ptime == nullptr)
                throw std::invalid_argument("wp loader get latest update time");
 
-       return this->m_pc.fpGetEngineLatestUpdateTime(e, ptime);
+       return this->m_pc.fpGetEngineLatestUpdateTime(c, ptime);
 }
 
-int WpLoader::getEngineActivated(csre_wp_engine_h e,
+int WpLoader::getEngineActivated(csre_wp_context_h c,
                                                                 csre_wp_activated_e *pactivated)
 {
-       if (e == nullptr || pactivated == nullptr)
+       if (c == nullptr || pactivated == nullptr)
                throw std::invalid_argument("wp loader get engine activated");
 
-       return this->m_pc.fpGetEngineActivated(e, pactivated);
+       return this->m_pc.fpGetEngineActivated(c, pactivated);
 }
 
-int WpLoader::getEngineVendorLogo(csre_wp_engine_h e,
+int WpLoader::getEngineVendorLogo(csre_wp_context_h c,
                                                                  std::vector<unsigned char> &value)
 {
-       if (e == nullptr)
+       if (c == nullptr)
                throw std::invalid_argument("wp loader get engine vendor logo");
 
        unsigned char *cvalue = nullptr;
        unsigned int size = 0;
-       auto retval = this->m_pc.fpGetEngineVendorLogo(e, &cvalue, &size);
+       auto retval = this->m_pc.fpGetEngineVendorLogo(c, &cvalue, &size);
 
        if (retval == CSRE_ERROR_NONE && cvalue != nullptr && size != 0)
                value.assign(cvalue, cvalue + size);
@@ -220,10 +209,6 @@ void WpLoader::init(const std::string &enginePath, const std::string &roResDir,
                                                                  "csre_wp_result_get_detailed_url"));
        this->m_pc.fpGetErrorString = reinterpret_cast <FpGetErrorString>(dlsym(handle,
                                                                  "csre_wp_get_error_string"));
-       this->m_pc.fpGetEngineInfo = reinterpret_cast<FpGetEngineInfo>(dlsym(handle,
-                                                                "csre_wp_engine_get_info"));
-       this->m_pc.fpDestroyEngine = reinterpret_cast<FpDestroyEngine>(dlsym(handle,
-                                                                "csre_wp_engine_destroy"));
        this->m_pc.fpGetEngineApiVersion = reinterpret_cast<FpGetEngineApiVersion>(dlsym(
                                                                           handle, "csre_wp_engine_get_api_version"));
        this->m_pc.fpGetEngineVendor = reinterpret_cast<FpGetEngineVendor>(dlsym(handle,
@@ -248,8 +233,6 @@ void WpLoader::init(const std::string &enginePath, const std::string &roResDir,
                        this->m_pc.fpCheckUrl == nullptr || this->m_pc.fpGetRiskLevel == nullptr ||
                        this->m_pc.fpGetDetailedUrl == nullptr ||
                        this->m_pc.fpGetErrorString == nullptr ||
-                       this->m_pc.fpGetEngineInfo == nullptr ||
-                       this->m_pc.fpDestroyEngine == nullptr ||
                        this->m_pc.fpGetEngineApiVersion == nullptr ||
                        this->m_pc.fpGetEngineVendor == nullptr ||
                        this->m_pc.fpGetEngineName == nullptr ||
@@ -315,24 +298,4 @@ csre_wp_context_h &WpEngineContext::get(void)
        return this->m_context;
 }
 
-
-WpEngineInfo::WpEngineInfo(const std::shared_ptr<WpLoader> &loader) :
-       m_loader(loader), m_info(nullptr)
-{
-       if (!this->m_loader)
-               ThrowExc(EngineNotExist, "null loader means engine not exist!");
-
-       toException(this->m_loader->getEngineInfo(this->m_info));
-}
-
-WpEngineInfo::~WpEngineInfo()
-{
-       toException(this->m_loader->destroyEngine(this->m_info));
-}
-
-csre_wp_engine_h &WpEngineInfo::get(void)
-{
-       return this->m_info;
-}
-
 }
index c722214..94ef88f 100644 (file)
@@ -46,16 +46,14 @@ public:
        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 getEngineInfo(csre_wp_engine_h &);
-       int destroyEngine(csre_wp_engine_h);
-       int getEngineApiVersion(csre_wp_engine_h, std::string &);
-       int getEngineVendor(csre_wp_engine_h, std::string &);
-       int getEngineName(csre_wp_engine_h, std::string &);
-       int getEngineVersion(csre_wp_engine_h, std::string &);
-       int getEngineDataVersion(csre_wp_engine_h, std::string &);
-       int getEngineLatestUpdateTime(csre_wp_engine_h, time_t *);
-       int getEngineActivated(csre_wp_engine_h, csre_wp_activated_e *);
-       int getEngineVendorLogo(csre_wp_engine_h, std::vector<unsigned char> &);
+       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> &);
 
 private:
        using FpGlobalInit = int(*)(const char *, const char *);
@@ -67,16 +65,14 @@ private:
        using FpGetRiskLevel = int(*)(csre_wp_check_result_h, csre_wp_risk_level_e *);
        using FPGetDetailedUrl = int(*)(csre_wp_check_result_h, const char **);
        using FpGetErrorString = int(*)(int, const char **);
-       using FpGetEngineInfo = int(*)(csre_wp_engine_h *);
-       using FpDestroyEngine = int(*)(csre_wp_engine_h);
-       using FpGetEngineApiVersion = int(*)(csre_wp_engine_h, const char **);
-       using FpGetEngineVendor = int(*)(csre_wp_engine_h, const char **);
-       using FpGetEngineName = int(*)(csre_wp_engine_h, const char **);
-       using FpGetEngineVersion = int(*)(csre_wp_engine_h, const char **);
-       using FpGetEngineDataVersion = int(*)(csre_wp_engine_h, const char **);
-       using FpGetEngineLatestUpdateTime = int(*)(csre_wp_engine_h, time_t *);
-       using FpGetEngineActivated = int(*)(csre_wp_engine_h, csre_wp_activated_e *);
-       using FpGetEngineVendorLogo = int(*)(csre_wp_engine_h, unsigned char **,
+       using FpGetEngineApiVersion = int(*)(csre_wp_context_h, const char **);
+       using FpGetEngineVendor = int(*)(csre_wp_context_h, const char **);
+       using FpGetEngineName = int(*)(csre_wp_context_h, const char **);
+       using FpGetEngineVersion = int(*)(csre_wp_context_h, const char **);
+       using FpGetEngineDataVersion = int(*)(csre_wp_context_h, const char **);
+       using FpGetEngineLatestUpdateTime = int(*)(csre_wp_context_h, time_t *);
+       using FpGetEngineActivated = int(*)(csre_wp_context_h, csre_wp_activated_e *);
+       using FpGetEngineVendorLogo = int(*)(csre_wp_context_h, unsigned char **,
                                                                                 unsigned int *);
 
        struct PluginContext {
@@ -90,8 +86,6 @@ private:
                FpGetRiskLevel fpGetRiskLevel;
                FPGetDetailedUrl fpGetDetailedUrl;
                FpGetErrorString fpGetErrorString;
-               FpGetEngineInfo fpGetEngineInfo;
-               FpDestroyEngine fpDestroyEngine;
                FpGetEngineApiVersion fpGetEngineApiVersion;
                FpGetEngineVendor fpGetEngineVendor;
                FpGetEngineName fpGetEngineName;
@@ -119,15 +113,4 @@ private:
        csre_wp_context_h m_context;
 };
 
-class WpEngineInfo {
-public:
-       WpEngineInfo(const std::shared_ptr<WpLoader> &);
-       ~WpEngineInfo();
-       csre_wp_engine_h &get(void);
-
-private:
-       std::shared_ptr<WpLoader> m_loader;
-       csre_wp_engine_h m_info;
-};
-
 }
index f94b093..5374c55 100644 (file)
@@ -40,8 +40,8 @@ WpLogic::WpLogic(const std::shared_ptr<WpLoader> &loader,
                ThrowExc(DbFailed, "DB init failed.");
 
        if (this->m_loader) {
-               WpEngineInfo wpEngineInfo(this->m_loader);
-               toException(this->m_loader->getEngineDataVersion(wpEngineInfo.get(),
+               WpEngineContext wpEngineContext(this->m_loader);
+               toException(this->m_loader->getEngineDataVersion(wpEngineContext.get(),
                                        this->m_dataVersion));
        }
 }
index 82d152c..f513788 100644 (file)
@@ -29,8 +29,6 @@
 extern "C" {
 #endif
 
-typedef struct __csre_cs_engine_h *csre_cs_engine_h;
-
 /**
  * @brief State of engine activation
  */
@@ -40,179 +38,127 @@ typedef enum {
 } csre_cs_activated_e;
 
 /**
- * @brief Gets the handle of a selected engine information.
- *
- * @param[in]  id       Engine identifier to get handle.
- * @param[out] pengine  A pointer of the engine information handle.
- *
- * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
- *
- * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    pengine is invalid
- * @retval #CSRE_ERROR_ENGINE_NOT_SELECTED  No engine selected
- * @retval #CSRE_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
- * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
- * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- */
-int csre_cs_engine_get_info(csre_cs_engine_h *engine);
-
-/**
- * @brief Releases all system resources associated with a engine information handle.
- *
- * @param[in]  engine      The engine information handle.
- *
- * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
- *
- * @retval #CSRE_ERROR_NONE                  Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE        Invalid handle
- * @retval #CSRE_ERROR_SOCKET                Socket error between client and server
- * @retval #CSRE_ERROR_SERVER                Server has been failed for some reason
- * @retval #CSRE_ERROR_ENGINE_INTERNAL       Engine Internal error
- * @retval #CSRE_ERROR_UNKNOWN               Error with unknown reason
- */
-int csre_cs_engine_destroy(csre_cs_engine_h engine);
-
-/**
  * @brief returns the engine API version.
  *
- * @param[in]  engine   The engine information handle.
+ * @param[in]  context  CSR CS context handle.
  * @param[out] version  A pointer of the API version string. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    api_ver is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval -0x0100~-0xFF00                  Engine defined error
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_api_version(csre_cs_engine_h engine,
-                                                                  const char **version);
+int csre_cs_engine_get_api_version(csre_cs_context_h context, const char **version);
 
 /**
- * @brief Extracts an vendor name from the engine information handle.
+ * @brief Extracts an vendor name from CSR CS context handle.
  *
- * @param[in]  engine  The engine information handle.
+ * @param[in]  context CSR CS context handle.
  * @param[out] vendor  A pointer of the engine's vendor name. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_vendor is invalid
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER    @a vendor is invalid
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_vendor(csre_cs_engine_h engine, const char **vendor);
+int csre_cs_engine_get_vendor(csre_cs_context_h context, const char **vendor);
 
 /**
- * @brief Extracts an engine name from the engine information handle.
+ * @brief Extracts an engine name from CSR CS context handle.
  *
- * @param[in]  engine  The engine information handle.
+ * @param[in]  context CSR CS context handle.
  * @param[out] name    A pointer of the engine's name. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_name is invalid
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER    @a name is invalid
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_name(csre_cs_engine_h engine, const char **name);
+int csre_cs_engine_get_name(csre_cs_context_h context, const char **name);
 
 /**
- * @brief Extracts an engine version from the engine information handle.
+ * @brief Extracts an engine version from CSR CS context handle.
  *
- * @param[in]  engine   An engine information handle.
+ * @param[in]  context  CSR CS context handle.
  * @param[out] version  A pointer of the engine's version. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_version is invalid
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER    @a version is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_version(csre_cs_engine_h engine, const char **version);
+int csre_cs_engine_get_version(csre_cs_context_h context, const char **version);
 
 /**
- * @brief Extracts an engine's data version from the engine information handle.
+ * @brief Extracts an engine's data version from CSR CS context handle.
  *
- * @param[in]  engine   The engine information handle.
+ * @param[in]  context  CSR CS context handle.
  * @param[out] version  A pointer of the data version. It can be null. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_version is invalid
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER    @a version is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_data_version(csre_cs_engine_h engine,
-                                                                       const char **version);
+int csre_cs_engine_get_data_version(csre_cs_context_h context, const char **version);
 
 /**
- * @brief Extracts the latest update time of an engine from the engine information handle.
+ * @brief Extracts the latest update time of an engine from CSR CS context handle.
  *
- * @param[in]  engine   The engine information handle.
+ * @param[in]  context  CSR CS context handle.
  * @param[out] time     A pointer of lasted update time.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    time is invalid
- * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_latest_update_time(csre_cs_engine_h engine,
-               time_t *time);
+int csre_cs_engine_get_latest_update_time(csre_cs_context_h context, time_t *time);
 
 /**
- * @brief Extracts the state of engine activation from the engine information handle.
+ * @brief Extracts the state of engine activation from CSR CS context handle.
  *
- * @param[in]  engine      The engine information handle.
+ * @param[in]  context     CSR CS context handle.
  * @param[out] pactivated  A pointer of the engine state.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    pactivated is invalid
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER    @a pactivated is invalid
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_activated(csre_cs_engine_h engine,
+int csre_cs_engine_get_activated(csre_cs_context_h context,
                                                                 csre_cs_activated_e *pactivated);
 
 /**
- * @brief Extracts an vendor logo image from the engine information handle.
+ * @brief Extracts an vendor logo image from CSR CS context handle.
  *
  * @details If log image is provided, the vendor logo is shown in a popup. The format
  *          of the logo image should be jpeg, gif, bmp or png.
  *
- * @param[in]  engine             The engine information handle.
+ * @param[in]  context            CSR CS context handle.
  * @param[out] vendor_logo_image  A pointer of the vendor logo image. A caller should not
  *                                free it.
  * @param[out] image_size         Size of log image.
@@ -220,16 +166,15 @@ int csre_cs_engine_get_activated(csre_cs_engine_h engine,
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    vendor_logo_imgage or image_size is invalid
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER    @a vendor_logo_imgage or @a image_size is invalid
  * @retval #CSRE_ERROR_NO_DATA              No vendor logo image
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval -0x0100~-0xFF00                  Engine defined error
- *
- * @see csre_cs_get_engine_info()
  */
-int csre_cs_engine_get_vendor_logo(csre_cs_engine_h engine,
-                                                                  unsigned char **vendor_logo_image, unsigned int *image_size);
+int csre_cs_engine_get_vendor_logo(csre_cs_context_h context,
+                                                                  unsigned char **vendor_logo_image,
+                                                                  unsigned int *image_size);
 
 #ifdef __cplusplus
 }
index 4ca3383..5fb64d9 100644 (file)
@@ -29,8 +29,6 @@
 extern "C" {
 #endif
 
-typedef struct csre_wp_engine_s *csre_wp_engine_h;
-
 /**
  * @brief State of engine activation
  */
@@ -40,179 +38,128 @@ typedef enum {
 } csre_wp_activated_e;
 
 /**
- * @brief Gets the handle of a selected engine information.
- *
- * @param[in]  id       Engine identifier to get handle.
- * @param[out] pengine  A pointer of the engine information handle.
- *
- * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
- *
- * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid handle
- * @retval #CSRE_ERROR_INVALID_PARAMETER    pengine is invalid
- * @retval #CSRE_ERROR_ENGINE_NOT_SELECTED  No engine selected
- * @retval #CSRE_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
- * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
- * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- */
-int csre_wp_engine_get_info(csre_wp_engine_h *engine);
-
-/**
- * @brief Releases all system resources associated with a engine information handle.
- *
- * @param[in]  engine      The engine information handle.
- *
- * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
- *
- * @retval #CSRE_ERROR_NONE                  Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE        Invalid handle
- * @retval #CSRE_ERROR_SOCKET                Socket error between client and server
- * @retval #CSRE_ERROR_SERVER                Server has been failed for some reason
- * @retval #CSRE_ERROR_ENGINE_INTERNAL       Engine Internal error
- * @retval #CSRE_ERROR_UNKNOWN               Error with unknown reason
- */
-int csre_wp_engine_destroy(csre_wp_engine_h engine);
-
-/**
  * @brief returns the engine API version.
  *
- * @param[in]  engine   The engine information handle.
+ * @param[in]  context  CSR WP context handle.
  * @param[out] version  A pointer of the API version string. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    api_ver is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval -0x0100~-0xFF00                  Engine defined error
- *
- * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_api_version(csre_wp_engine_h engine,
-                                                                  const char **version);
+int csre_wp_engine_get_api_version(csre_wp_context_h context, const char **version);
 
 /**
- * @brief Extracts an vendor name from the engine information handle.
+ * @brief Extracts an vendor name from the CSR WP context handle.
  *
- * @param[in]  engine  The engine information handle.
- * @param[out] vendor  A pointer of the engine's vendor name. A caller should not free it.
+ * @param[in]  context  CSR WP context handle.
+ * @param[out] vendor   A pointer of the engine's vendor name. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_vendor is invalid
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_vendor(csre_wp_engine_h engine, const char **vendor);
+int csre_wp_engine_get_vendor(csre_wp_context_h context, const char **vendor);
 
 /**
- * @brief Extracts an engine name from the engine information handle.
+ * @brief Extracts an engine name from the CSR WP context handle.
  *
- * @param[in]  engine  The engine information handle.
- * @param[out] name    A pointer of the engine's name. A caller should not free it.
+ * @param[in]  context  CSR WP context handle.
+ * @param[out] name     A pointer of the engine's name. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_name is invalid
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_name(csre_wp_engine_h engine, const char **name);
+int csre_wp_engine_get_name(csre_wp_context_h context, const char **name);
 
 /**
- * @brief Extracts an engine version from the engine information handle.
+ * @brief Extracts an engine version from the CSR WP context handle.
  *
- * @param[in]  engine   An engine information handle.
+ * @param[in]  context   CSR WP context handle.
  * @param[out] version  A pointer of the engine's version. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_version is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_version(csre_wp_engine_h engine, const char **version);
+int csre_wp_engine_get_version(csre_wp_context_h context, const char **version);
 
 /**
- * @brief Extracts an engine's data version from the engine information handle.
+ * @brief Extracts an engine's data version from the CSR WP context handle.
  *
- * @param[in]  engine   The engine information handle.
+ * @param[in]  context  CSR WP context handle.
  * @param[out] version  A pointer of the data version. It can be null. A caller should not free it.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    engine_version is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_data_version(csre_wp_engine_h engine,
-                                                                       const char **version);
+int csre_wp_engine_get_data_version(csre_wp_context_h context, const char **version);
 
 /**
- * @brief Extracts the latest update time of an engine from the engine information handle.
+ * @brief Extracts the latest update time of an engine from the CSR WP context handle.
  *
- * @param[in]  engine   The engine information handle.
+ * @param[in]  context  CSR WP context handle.
  * @param[out] time     A pointer of lasted update time.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    time is invalid
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_wp_get_engine_info()
  */
-int csre_wp_engine_get_latest_update_time(csre_wp_engine_h engine,
-               time_t *time);
+int csre_wp_engine_get_latest_update_time(csre_wp_context_h context, time_t *time);
 
 /**
- * @brief Extracts the state of engine activation from the engine information handle.
+ * @brief Extracts the state of engine activation from the CSR WP context handle.
  *
- * @param[in]  engine      The engine information handle.
+ * @param[in]  context     CSR WP context handle.
  * @param[out] pactivated  A pointer of the engine state.
  *
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    pactivated is invalid
  * @retval #CSRE_ERROR_ENGINE_INTERNAL      Engine Internal error
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
- *
- * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_activated(csre_wp_engine_h engine,
+int csre_wp_engine_get_activated(csre_wp_context_h context,
                                                                 csre_wp_activated_e *pactivated);
 
 /**
- * @brief Extracts an vendor logo image from the engine information handle.
+ * @brief Extracts an vendor logo image from the CSR WP context handle.
  *
  * @details If log image is provided, the vendor logo is shown in a popup. The format
  *          of the logo image should be jpeg, gif, bmp or png.
  *
- * @param[in]  engine             The engine information handle.
+ * @param[in]  context            CSR WP context handle.
  * @param[out] vendor_logo_image  A pointer of the vendor logo image. A caller should not
  *                                free it.
  * @param[out] image_size         Size of log image.
@@ -220,7 +167,7 @@ int csre_wp_engine_get_activated(csre_wp_engine_h engine,
  * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
  *
  * @retval #CSRE_ERROR_NONE                 Successful
- * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_HANDLE       Invalid context handle
  * @retval #CSRE_ERROR_INVALID_PARAMETER    vendor_logo_imgage or image_size is invalid
  * @retval #CSRE_ERROR_NO_DATA              No vendor logo image
  * @retval #CSRE_ERROR_UNKNOWN              Error with unknown reason
@@ -228,8 +175,9 @@ int csre_wp_engine_get_activated(csre_wp_engine_h engine,
  *
  * @see csre_wp_engine_get_info()
  */
-int csre_wp_engine_get_vendor_logo(csre_wp_engine_h engine,
-                                                                  unsigned char **vendor_logo_image, unsigned int *image_size);
+int csre_wp_engine_get_vendor_logo(csre_wp_context_h context,
+                                                                  unsigned char **vendor_logo_image,
+                                                                  unsigned int *image_size);
 
 #ifdef __cplusplus
 }
index f777938..0322744 100644 (file)
@@ -63,11 +63,6 @@ struct csret_cs_detected_s {
        time_t timestamp;
 };
 
-struct csret_cs_context_s {
-       int scan_on_data;
-       std::list<csret_cs_detected_s> detected_list;
-};
-
 struct csret_cs_engine_s {
        std::string vendorName;
        std::string engineName;
@@ -78,6 +73,12 @@ struct csret_cs_engine_s {
        time_t latestUpdate;
 };
 
+struct csret_cs_context_s {
+       int scan_on_data;
+       std::list<csret_cs_detected_s> detected_list;
+       csret_cs_engine_s *engine;
+};
+
 enum csret_cs_internal_error_e {
        CSRET_CS_ERROR_NO_SIGNATURE_FILE     = -0x0101,
        CSRET_CS_ERROR_SIGNATURE_FILE_FORMAT = -0x0102,
@@ -225,8 +226,11 @@ time_t csret_cs_get_timestamp()
        return tv.tv_sec;
 }
 
-csret_cs_engine_s *csret_cs_init_engine()
+int csret_cs_init_engine(csret_cs_engine_s **pengine)
 {
+       if (pengine == nullptr)
+               return CSRE_ERROR_INVALID_PARAMETER;
+
        auto ptr = new csret_cs_engine_s;
 
        ptr->vendorName = VENDOR_NAME;
@@ -235,12 +239,11 @@ csret_cs_engine_s *csret_cs_init_engine()
        ptr->engineVersion = ENGINE_VERSION;
        ptr->dataVersion = ENGINE_VERSION;
 
-       int ret = csret_cs_read_binary(g_resdir + "/" PRIVATE_LOGO_FILE,
-                                                                  ptr->logoImage);
+       int ret = csret_cs_read_binary(g_resdir + "/" PRIVATE_LOGO_FILE, ptr->logoImage);
 
        if (ret != CSRE_ERROR_NONE) {
                delete ptr;
-               return nullptr;
+               return ret;
        }
 
        struct stat attrib;
@@ -249,7 +252,9 @@ csret_cs_engine_s *csret_cs_init_engine()
 
        ptr->latestUpdate = attrib.st_mtime;
 
-       return ptr;
+       *pengine = ptr;
+
+       return CSRE_ERROR_NONE;
 }
 
 int csret_cs_compare_data(const RawBuffer &data, const std::string &needle)
@@ -309,8 +314,7 @@ int csret_cs_detect_malware(csret_cs_context_s *context, const RawBuffer &data,
 // Main function related
 //==============================================================================
 API
-int csre_cs_global_initialize(const char *ro_res_dir,
-                                                         const char *rw_working_dir)
+int csre_cs_global_initialize(const char *ro_res_dir, const char *rw_working_dir)
 {
        if (ro_res_dir == nullptr || rw_working_dir == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
@@ -338,7 +342,16 @@ int csre_cs_context_create(csre_cs_context_h *phandle)
        if (g_virus_sig.empty())
                return CSRE_ERROR_INVALID_HANDLE; // not yet initialized
 
-       auto context = new csret_cs_context_s;
+       csret_cs_engine_s *engine = nullptr;
+       auto ret = csret_cs_init_engine(&engine);
+       if (ret != CSRE_ERROR_NONE)
+               return ret;
+
+       auto context = new (std::nothrow) csret_cs_context_s;
+       if (context == nullptr)
+               return CSRE_ERROR_OUT_OF_MEMORY;
+
+       context->engine = engine;
 
        *phandle = reinterpret_cast<csre_cs_context_h>(context);
 
@@ -353,6 +366,9 @@ int csre_cs_context_destroy(csre_cs_context_h handle)
        if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
+       if (context->engine != nullptr)
+               delete context->engine;
+
        delete context;
 
        return CSRE_ERROR_NONE;
@@ -542,73 +558,50 @@ int csre_cs_detected_get_detailed_url(csre_cs_detected_h detected,
 // Engine information related
 //==============================================================================
 API
-int csre_cs_engine_get_info(csre_cs_engine_h *pengine)
-{
-       if (pengine == nullptr)
-               return CSRE_ERROR_INVALID_PARAMETER;
-
-       auto ptr = csret_cs_init_engine();
-       *pengine = reinterpret_cast<csre_cs_engine_h>(ptr);
-
-       return CSRE_ERROR_NONE;
-}
-
-API
-int csre_cs_engine_destroy(csre_cs_engine_h engine)
+int csre_cs_engine_get_vendor(csre_cs_context_h context, const char **vendor)
 {
-       if (engine == nullptr)
-               return CSRE_ERROR_INVALID_PARAMETER;
-
-       delete reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       return CSRE_ERROR_NONE;
-}
-
-API
-int csre_cs_engine_get_vendor(csre_cs_engine_h engine, const char **vendor)
-{
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (vendor == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        *vendor = eng->vendorName.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_cs_engine_get_name(csre_cs_engine_h engine, const char **name)
+int csre_cs_engine_get_name(csre_cs_context_h context, const char **name)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (name == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        *name = eng->engineName.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_cs_engine_get_vendor_logo(csre_cs_engine_h engine,
+int csre_cs_engine_get_vendor_logo(csre_cs_context_h context,
                                                                   unsigned char **logo_image,
                                                                   unsigned int *image_size)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (logo_image == nullptr || image_size == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        auto s = eng->logoImage.size();
 
        if (s > UINT_MAX - 1)
@@ -621,62 +614,58 @@ int csre_cs_engine_get_vendor_logo(csre_cs_engine_h engine,
 }
 
 API
-int csre_cs_engine_get_version(csre_cs_engine_h engine, const char **version)
+int csre_cs_engine_get_version(csre_cs_context_h context, const char **version)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (version == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        *version = eng->engineVersion.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_cs_engine_get_data_version(csre_cs_engine_h engine,
-                                                                       const char **version)
+int csre_cs_engine_get_data_version(csre_cs_context_h context, const char **version)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (version == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        *version = eng->dataVersion.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_cs_engine_get_latest_update_time(csre_cs_engine_h engine, time_t *time)
+int csre_cs_engine_get_latest_update_time(csre_cs_context_h context, time_t *time)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (time == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        *time = eng->latestUpdate;
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_cs_engine_get_activated(csre_cs_engine_h engine,
+int csre_cs_engine_get_activated(csre_cs_context_h context,
                                                                 csre_cs_activated_e *pactivated)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
-               return CSRE_ERROR_INVALID_HANDLE;
+       (void) context;
 
        if (pactivated == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
@@ -690,17 +679,16 @@ int csre_cs_engine_get_activated(csre_cs_engine_h engine,
 }
 
 API
-int csre_cs_engine_get_api_version(csre_cs_engine_h engine,
-                                                                  const char **version)
+int csre_cs_engine_get_api_version(csre_cs_context_h context, const char **version)
 {
-       auto eng = reinterpret_cast<csret_cs_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (version == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_cs_context_s *>(context)->engine;
+
        *version = eng->apiVersion.c_str();
 
        return CSRE_ERROR_NONE;
index b44fa3d..eb62909 100644 (file)
@@ -56,10 +56,6 @@ struct csret_wp_risky_url_s {
        csret_wp_risky_url_s() : risk_level(CSRE_WP_RISK_UNVERIFIED) {}
 };
 
-struct csret_wp_context_s {
-       std::list<csret_wp_risky_url_s> detected_list;
-};
-
 struct csret_wp_engine_s {
        std::string vendorName;
        std::string engineName;
@@ -70,6 +66,11 @@ struct csret_wp_engine_s {
        time_t latestUpdate;
 };
 
+struct csret_wp_context_s {
+       std::list<csret_wp_risky_url_s> detected_list;
+       csret_wp_engine_s *engine;
+};
+
 enum csret_wp_internal_error_e {
        CSRET_WP_ERROR_NO_RISKY_URL_FILE     = -0x0101,
        CSRET_WP_ERROR_SIGNATURE_FILE_FORMAT = -0x0102,
@@ -188,8 +189,11 @@ int csret_wp_read_binary(const std::string &path, RawBuffer &buffer)
        return CSRE_ERROR_NONE;
 }
 
-csret_wp_engine_s *csret_wp_init_engine()
+int csret_wp_init_engine(csret_wp_engine_s **pengine)
 {
+       if (pengine == nullptr)
+               return CSRE_ERROR_INVALID_PARAMETER;
+
        auto ptr = new csret_wp_engine_s;
 
        ptr->vendorName = VENDOR_NAME;
@@ -203,7 +207,7 @@ csret_wp_engine_s *csret_wp_init_engine()
 
        if (ret != CSRE_ERROR_NONE) {
                delete ptr;
-               return nullptr;
+               return ret;
        }
 
        struct stat attrib;
@@ -212,7 +216,9 @@ csret_wp_engine_s *csret_wp_init_engine()
 
        ptr->latestUpdate = attrib.st_mtime;
 
-       return ptr;
+       *pengine = ptr;
+
+       return CSRE_ERROR_NONE;
 }
 
 
@@ -255,7 +261,16 @@ int csre_wp_context_create(csre_wp_context_h *phandle)
        if (g_risky_urls.empty())
                return CSRE_ERROR_INVALID_HANDLE; // not yet initialized
 
-       auto context = new csret_wp_context_s;
+       csret_wp_engine_s *engine = nullptr;
+       auto ret = csret_wp_init_engine(&engine);
+       if (ret != CSRE_ERROR_NONE)
+               return ret;
+
+       auto context = new (std::nothrow) csret_wp_context_s;
+       if (context == nullptr)
+               return CSRE_ERROR_OUT_OF_MEMORY;
+
+       context->engine = engine;
 
        *phandle = reinterpret_cast<csre_wp_context_h>(context);
 
@@ -270,6 +285,9 @@ int csre_wp_context_destroy(csre_wp_context_h handle)
        if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
+       if (context->engine != nullptr)
+               delete context->engine;
+
        delete context;
 
        return CSRE_ERROR_NONE;
@@ -352,73 +370,50 @@ int csre_wp_result_get_detailed_url(csre_wp_check_result_h result,
 // Engine information related
 //==============================================================================
 API
-int csre_wp_engine_get_info(csre_wp_engine_h *pengine)
+int csre_wp_engine_get_vendor(csre_wp_context_h context, const char **vendor)
 {
-       if (pengine == nullptr)
-               return CSRE_ERROR_INVALID_PARAMETER;
-
-       auto ptr = csret_wp_init_engine();
-       *pengine = reinterpret_cast<csre_wp_engine_h>(ptr);
-
-       return CSRE_ERROR_NONE;
-}
-
-API
-int csre_wp_engine_destroy(csre_wp_engine_h engine)
-{
-       if (engine == nullptr)
-               return CSRE_ERROR_INVALID_PARAMETER;
-
-       delete reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       return CSRE_ERROR_NONE;
-}
-
-API
-int csre_wp_engine_get_vendor(csre_wp_engine_h engine, const char **vendor)
-{
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (vendor == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        *vendor = eng->vendorName.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_wp_engine_get_name(csre_wp_engine_h engine, const char **name)
+int csre_wp_engine_get_name(csre_wp_context_h context, const char **name)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (name == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        *name = eng->engineName.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_wp_engine_get_vendor_logo(csre_wp_engine_h engine,
+int csre_wp_engine_get_vendor_logo(csre_wp_context_h context,
                                                                   unsigned char **vendor_logo_image,
                                                                   unsigned int *image_size)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (vendor_logo_image == nullptr || image_size == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        auto s = eng->logoImage.size();
 
        if (s > UINT_MAX - 1)
@@ -431,33 +426,32 @@ int csre_wp_engine_get_vendor_logo(csre_wp_engine_h engine,
 }
 
 API
-int csre_wp_engine_get_version(csre_wp_engine_h engine, const char **version)
+int csre_wp_engine_get_version(csre_wp_context_h context, const char **version)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (version == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        *version = eng->engineVersion.c_str();
 
        return CSRE_ERROR_NONE;
 }
 
 API
-int csre_wp_engine_get_data_version(csre_wp_engine_h engine,
-                                                                       const char **version)
+int csre_wp_engine_get_data_version(csre_wp_context_h context, const char **version)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (version == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        *version = eng->dataVersion.c_str();
 
        return CSRE_ERROR_NONE;
@@ -465,29 +459,26 @@ int csre_wp_engine_get_data_version(csre_wp_engine_h engine,
 
 
 API
-int csre_wp_engine_get_latest_update_time(csre_wp_engine_h engine, time_t *time)
+int csre_wp_engine_get_latest_update_time(csre_wp_context_h context, time_t *time)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (time == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        *time = eng->latestUpdate;
        return CSRE_ERROR_NONE;
 }
 
 
 API
-int csre_wp_engine_get_activated(csre_wp_engine_h engine,
+int csre_wp_engine_get_activated(csre_wp_context_h context,
                                                                 csre_wp_activated_e *pactivated)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
-               return CSRE_ERROR_INVALID_HANDLE;
+       (void) context;
 
        if (pactivated == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
@@ -501,17 +492,16 @@ int csre_wp_engine_get_activated(csre_wp_engine_h engine,
 }
 
 API
-int csre_wp_engine_get_api_version(csre_wp_engine_h engine,
-                                                                  const char **version)
+int csre_wp_engine_get_api_version(csre_wp_context_h context, const char **version)
 {
-       auto eng = reinterpret_cast<csret_wp_engine_s *>(engine);
-
-       if (eng == nullptr)
+       if (context == nullptr)
                return CSRE_ERROR_INVALID_HANDLE;
 
        if (version == nullptr)
                return CSRE_ERROR_INVALID_PARAMETER;
 
+       auto eng = reinterpret_cast<csret_wp_context_s *>(context)->engine;
+
        *version = eng->apiVersion.c_str();
 
        return CSRE_ERROR_NONE;
index 4f5e1ac..72b8a4c 100644 (file)
@@ -265,21 +265,11 @@ BOOST_AUTO_TEST_SUITE_END()
 
 BOOST_AUTO_TEST_SUITE(API_ENGINE_CONTENT_SCREENING_ENGINE_INFO)
 
-BOOST_AUTO_TEST_CASE(get_engine_info)
-{
-       EXCEPTION_GUARD_START
-
-       auto c = Test::Context<csre_cs_engine_h>();
-       (void) c;
-
-       EXCEPTION_GUARD_END
-}
-
 BOOST_AUTO_TEST_CASE(get_vendor)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        const char *vendor = nullptr;
@@ -292,7 +282,7 @@ BOOST_AUTO_TEST_CASE(get_vendor_logo)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        unsigned char *vendor_logo_image = nullptr;
@@ -307,7 +297,7 @@ BOOST_AUTO_TEST_CASE(get_version)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        const char *version = nullptr;
@@ -321,7 +311,7 @@ BOOST_AUTO_TEST_CASE(get_data_version)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        const char *version = nullptr;
@@ -335,7 +325,7 @@ BOOST_AUTO_TEST_CASE(get_latest_update_time)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        time_t time = 0;
@@ -349,7 +339,7 @@ BOOST_AUTO_TEST_CASE(get_engine_activated)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        csre_cs_activated_e activated;
@@ -362,7 +352,7 @@ BOOST_AUTO_TEST_CASE(get_api_version)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_cs_engine_h>();
+       auto c = Test::Context<csre_cs_context_h>();
        auto handle = c.get();
 
        const char *version = nullptr;
index 6026a93..5e254b1 100644 (file)
@@ -119,21 +119,11 @@ BOOST_AUTO_TEST_SUITE_END()
 
 BOOST_AUTO_TEST_SUITE(API_ENGINE_WEB_PROTECTION_ENGINE_INFO)
 
-BOOST_AUTO_TEST_CASE(get_engine_info)
-{
-       EXCEPTION_GUARD_START
-
-       auto c = Test::Context<csre_wp_engine_h>();
-       (void) c;
-
-       EXCEPTION_GUARD_END
-}
-
 BOOST_AUTO_TEST_CASE(get_vendor)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        const char *vendor = nullptr;
@@ -146,7 +136,7 @@ BOOST_AUTO_TEST_CASE(get_vendor_logo)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        unsigned char *vendor_logo_image = nullptr;
@@ -161,7 +151,7 @@ BOOST_AUTO_TEST_CASE(get_version)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        const char *version = nullptr;
@@ -175,7 +165,7 @@ BOOST_AUTO_TEST_CASE(get_data_version)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        const char *version = nullptr;
@@ -189,7 +179,7 @@ BOOST_AUTO_TEST_CASE(get_latest_update_time)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        time_t time = 0;
@@ -203,7 +193,7 @@ BOOST_AUTO_TEST_CASE(get_engine_activated)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        csre_wp_activated_e activated;
@@ -216,7 +206,7 @@ BOOST_AUTO_TEST_CASE(get_api_version)
 {
        EXCEPTION_GUARD_START
 
-       auto c = Test::Context<csre_wp_engine_h>();
+       auto c = Test::Context<csre_wp_context_h>();
        auto handle = c.get();
 
        const char *version = nullptr;
index 38696bf..5478a9d 100644 (file)
@@ -69,24 +69,7 @@ inline void checkDetected(Csr::CsLoader &loader,
        EXCEPTION_GUARD_END
 }
 
-template <typename T>
 struct Handle {
-       Handle()
-       {
-               BOOST_REQUIRE_MESSAGE(0, "Not specialized for handle template");
-       }
-
-       ~Handle()
-       {
-               BOOST_REQUIRE_MESSAGE(0, "Not specialized for handle template");
-       }
-
-       Csr::CsLoader loader;
-       T context;
-};
-
-template <>
-struct Handle<csre_cs_context_h> {
        Handle() :
                loader(ENGINE_DIR "/libcsr-cs-engine.so",
                           ENGINE_DIR,
@@ -104,25 +87,6 @@ struct Handle<csre_cs_context_h> {
        csre_cs_context_h context;
 };
 
-template <>
-struct Handle<csre_cs_engine_h> {
-       Handle() :
-               loader(ENGINE_DIR "/libcsr-cs-engine.so",
-                          ENGINE_DIR,
-                          ENGINE_RW_WORKING_DIR)
-       {
-               ASSERT_IF(loader.getEngineInfo(context), CSRE_ERROR_NONE);
-       }
-
-       ~Handle()
-       {
-               ASSERT_IF(loader.destroyEngine(context), CSRE_ERROR_NONE);
-       }
-
-       Csr::CsLoader loader;
-       csre_cs_engine_h context;
-};
-
 } // namespace anonymous
 
 BOOST_AUTO_TEST_SUITE(CS_LOADER)
@@ -131,7 +95,7 @@ BOOST_AUTO_TEST_CASE(context_create_destroy)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
        (void) h;
 
        EXCEPTION_GUARD_END
@@ -141,7 +105,7 @@ BOOST_AUTO_TEST_CASE(scan_data_clear)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        const char *cdata =
                "abcd1234dfdfdf334dfdi8ffndsfdfdsfdasfagdfvdfdfafadfasdfsdfe";
@@ -159,7 +123,7 @@ BOOST_AUTO_TEST_CASE(scan_data_high)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        const char *cdata =
                "aabbccX5O!P%@AP[4\\PZX54(P^)7CC)7}$"
@@ -184,7 +148,7 @@ BOOST_AUTO_TEST_CASE(scan_data_medium)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        const char *cdata = "aabbccRISKY_MALWARE112233";
 
@@ -207,7 +171,7 @@ BOOST_AUTO_TEST_CASE(scan_file_normal)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        csre_cs_detected_h detected;
        ASSERT_IF(h.loader.scanFile(h.context, TEST_FILE_NORMAL, &detected),
@@ -222,7 +186,7 @@ BOOST_AUTO_TEST_CASE(scan_file_malware)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        csre_cs_detected_h detected;
        ASSERT_IF(h.loader.scanFile(h.context, TEST_FILE_MALWARE, &detected),
@@ -243,7 +207,7 @@ BOOST_AUTO_TEST_CASE(scan_file_risky)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        csre_cs_detected_h detected;
        ASSERT_IF(h.loader.scanFile(h.context, TEST_FILE_RISKY, &detected),
@@ -264,7 +228,7 @@ BOOST_AUTO_TEST_CASE(scan_app_on_cloud)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        csre_cs_detected_h detected;
        ASSERT_IF(h.loader.scanAppOnCloud(h.context, TEST_APP_ROOT, &detected),
@@ -285,7 +249,7 @@ BOOST_AUTO_TEST_CASE(error_string_positive)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_context_h> h;
+       Handle h;
 
        std::string str;
 
@@ -295,21 +259,11 @@ BOOST_AUTO_TEST_CASE(error_string_positive)
        EXCEPTION_GUARD_END
 }
 
-BOOST_AUTO_TEST_CASE(get_engine_info)
-{
-       EXCEPTION_GUARD_START
-
-       Handle<csre_cs_engine_h> h;
-       (void) h;
-
-       EXCEPTION_GUARD_END
-}
-
 BOOST_AUTO_TEST_CASE(get_vendor)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineVendor(h.context, str), CSRE_ERROR_NONE);
@@ -322,7 +276,7 @@ BOOST_AUTO_TEST_CASE(get_vendor_logo)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        std::vector<unsigned char> logo;
        ASSERT_IF(h.loader.getEngineVendorLogo(h.context, logo), CSRE_ERROR_NONE);
@@ -334,7 +288,7 @@ BOOST_AUTO_TEST_CASE(get_version)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineVersion(h.context, str), CSRE_ERROR_NONE);
@@ -347,7 +301,7 @@ BOOST_AUTO_TEST_CASE(get_data_version)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineDataVersion(h.context, str), CSRE_ERROR_NONE);
@@ -360,7 +314,7 @@ BOOST_AUTO_TEST_CASE(get_latest_update_time)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        time_t time = 0;
        ASSERT_IF(h.loader.getEngineLatestUpdateTime(h.context, &time),
@@ -373,7 +327,7 @@ BOOST_AUTO_TEST_CASE(get_engine_activated)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        csre_cs_activated_e activated;
        ASSERT_IF(h.loader.getEngineActivated(h.context, &activated), CSRE_ERROR_NONE);
@@ -385,7 +339,7 @@ BOOST_AUTO_TEST_CASE(get_api_version)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_cs_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineApiVersion(h.context, str), CSRE_ERROR_NONE);
index 9eb7bca..8ecb267 100755 (executable)
@@ -71,24 +71,7 @@ inline void checkResult(Csr::WpLoader &loader,
        EXCEPTION_GUARD_END
 }
 
-template <typename T>
 struct Handle {
-       Handle()
-       {
-               BOOST_REQUIRE_MESSAGE(0, "Not specialized for handle template");
-       }
-
-       ~Handle()
-       {
-               BOOST_REQUIRE_MESSAGE(0, "Not specialized for handle template");
-       }
-
-       Csr::WpLoader loader;
-       T context;
-};
-
-template <>
-struct Handle<csre_wp_context_h> {
        Handle() :
                loader(ENGINE_DIR "/libcsr-wp-engine.so",
                           ENGINE_DIR,
@@ -106,25 +89,6 @@ struct Handle<csre_wp_context_h> {
        csre_wp_context_h context;
 };
 
-template <>
-struct Handle<csre_wp_engine_h> {
-       Handle() :
-               loader(ENGINE_DIR "/libcsr-wp-engine.so",
-                          ENGINE_DIR,
-                          ENGINE_RW_WORKING_DIR)
-       {
-               ASSERT_IF(loader.getEngineInfo(context), CSRE_ERROR_NONE);
-       }
-
-       ~Handle()
-       {
-               ASSERT_IF(loader.destroyEngine(context), CSRE_ERROR_NONE);
-       }
-
-       Csr::WpLoader loader;
-       csre_wp_engine_h context;
-};
-
 } // namespace anonymous
 
 
@@ -134,7 +98,7 @@ BOOST_AUTO_TEST_CASE(context_create_destroy)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_context_h> h;
+       Handle h;
        (void) h;
 
        EXCEPTION_GUARD_END
@@ -144,7 +108,7 @@ BOOST_AUTO_TEST_CASE(check_url)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_context_h> h;
+       Handle h;
 
        for (const auto &expected : ExpectedResult) {
                csre_wp_check_result_h result;
@@ -161,7 +125,7 @@ BOOST_AUTO_TEST_CASE(error_string)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        std::string str;
 
@@ -171,22 +135,11 @@ BOOST_AUTO_TEST_CASE(error_string)
        EXCEPTION_GUARD_END
 }
 
-
-BOOST_AUTO_TEST_CASE(get_engine_info)
-{
-       EXCEPTION_GUARD_START
-
-       Handle<csre_wp_engine_h> h;
-       (void) h;
-
-       EXCEPTION_GUARD_END
-}
-
 BOOST_AUTO_TEST_CASE(get_vendor)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineVendor(h.context, str), CSRE_ERROR_NONE);
@@ -199,7 +152,7 @@ BOOST_AUTO_TEST_CASE(get_vendor_logo)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        std::vector<unsigned char> logo;
        ASSERT_IF(h.loader.getEngineVendorLogo(h.context, logo), CSRE_ERROR_NONE);
@@ -211,7 +164,7 @@ BOOST_AUTO_TEST_CASE(get_version)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineVersion(h.context, str), CSRE_ERROR_NONE);
@@ -224,7 +177,7 @@ BOOST_AUTO_TEST_CASE(get_data_version)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineDataVersion(h.context, str), CSRE_ERROR_NONE);
@@ -237,7 +190,7 @@ BOOST_AUTO_TEST_CASE(get_latest_update_time)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        time_t time = 0;
        ASSERT_IF(h.loader.getEngineLatestUpdateTime(h.context, &time),
@@ -250,7 +203,7 @@ BOOST_AUTO_TEST_CASE(get_engine_activated)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        csre_wp_activated_e activated;
        ASSERT_IF(h.loader.getEngineActivated(h.context, &activated), CSRE_ERROR_NONE);
@@ -262,7 +215,7 @@ BOOST_AUTO_TEST_CASE(get_api_version)
 {
        EXCEPTION_GUARD_START
 
-       Handle<csre_wp_engine_h> h;
+       Handle h;
 
        std::string str;
        ASSERT_IF(h.loader.getEngineApiVersion(h.context, str), CSRE_ERROR_NONE);
index b70f853..66c919f 100644 (file)
@@ -40,9 +40,6 @@
 #include <csre-content-screening.h>
 #include <csre-web-protection.h>
 
-#include <csre-content-screening-engine-info.h>
-#include <csre-web-protection-engine-info.h>
-
 #ifndef __FILENAME__
 #define __FILENAME__ (::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__)
 #endif
@@ -322,50 +319,4 @@ private:
        csre_wp_context_h m_context;
 };
 
-template <>
-class Context<csre_cs_engine_h> {
-public:
-       Context() : m_context(nullptr)
-       {
-               ASSERT_IF(csre_cs_engine_get_info(&m_context), CSRE_ERROR_NONE);
-               BOOST_REQUIRE(m_context != nullptr);
-       }
-
-       virtual ~Context()
-       {
-               ASSERT_IF(csre_cs_engine_destroy(m_context), CSRE_ERROR_NONE);
-       }
-
-       csre_cs_engine_h get(void) const
-       {
-               return m_context;
-       }
-
-private:
-       csre_cs_engine_h m_context;
-};
-
-template <>
-class Context<csre_wp_engine_h> {
-public:
-       Context() : m_context(nullptr)
-       {
-               ASSERT_IF(csre_wp_engine_get_info(&m_context), CSRE_ERROR_NONE);
-               BOOST_REQUIRE(m_context != nullptr);
-       }
-
-       virtual ~Context()
-       {
-               ASSERT_IF(csre_wp_engine_destroy(m_context), CSRE_ERROR_NONE);
-       }
-
-       csre_wp_engine_h get(void) const
-       {
-               return m_context;
-       }
-
-private:
-       csre_wp_engine_h m_context;
-};
-
 } // namespace Test