Created
October 25, 2011 16:09
-
-
Save rchatsiri/1313284 to your computer and use it in GitHub Desktop.
Clamav init engines for scanning virus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef INIT_SERVICES_HPP_ | |
#define INIT_SERVICES_HPP_ | |
#include <iostream> | |
#include "clamav.h" | |
#include "optparser.h" | |
#include "clamav_logger.hpp" | |
#define CL_INIT_DEFAULT 0x0 | |
extern int cl_init(unsigned int initoptions); | |
extern int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int dboptions); | |
extern int cl_engine_compile(struct cl_engine *engine); | |
extern int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs); | |
extern "C" | |
{ | |
int cl_init(unsigned int options); | |
int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, unsigned int dboptions); | |
int cl_engine_compile(struct cl_engine *engine); | |
int cl_countsigs(const char *path, unsigned int countoptions, unsigned int *sigs); | |
} | |
namespace clamav_services | |
{ | |
class init_engine | |
{ | |
public: | |
init_engine(int cl_init_default) : | |
cl_init_default_(cl_init_default) | |
{ | |
} | |
~init_engine() | |
{ | |
} | |
bool engine() | |
{ | |
if ((result_ = cl_init(cl_init_default_)) != CL_SUCCESS) | |
{ | |
CLLOG_TRACE("Cannot init engine"); | |
return false; | |
} | |
return true; | |
} | |
bool engine_new() | |
{ | |
if (!(engine_ = cl_engine_new())) | |
{ | |
CLLOG_TRACE("Cannot new engine"); | |
return false; | |
} | |
result_ = cl_load(dbsign_path_.c_str(), engine_, &signs_, CL_DB_PHISHING); | |
if(result_ != CL_SUCCESS) | |
{ | |
cl_engine_free(engine_); | |
return false; | |
} | |
debug_init_engine("cl_load init "); | |
return true; | |
} | |
bool engine_detected() | |
{ | |
if((result_ = cl_engine_compile(engine_)) != CL_SUCCESS) | |
{ | |
debug_init_engine("Cannot detected engine = "); | |
cl_engine_free(engine_); | |
return false; | |
} | |
return true; | |
} | |
void database_signature_path() | |
{ | |
dbsign_path_ = std::string("/home/chatsiri/clamav/clamav-devel/database/main.cvd"); | |
CLLOG_TRACE(dbsign_path_); | |
} | |
void eninge_db_check() | |
{ | |
memset(&dbstat_, 0, sizeof(struct cl_stat)); | |
dbsign_path_ = std::string("/home/chatsiri/clamav/clamav-devel/database/"); | |
cl_statinidir(dbsign_path_.c_str(), &dbstat_); | |
if(cl_statchkdir(&dbstat_) == 1) | |
{ | |
CLLOG_TRACE("### Databases changed."); | |
} | |
else | |
{ | |
CLLOG_TRACE("### Databases not changing."); | |
} | |
} | |
struct cl_engine* get_engine() | |
{ | |
return engine_; | |
} | |
std::string debug_init_engine(std::string str_detail) | |
{ | |
CLLOG_TRACE("### "<<str_detail<<", "<<cl_strerror(result_)); | |
} | |
private: | |
int cl_init_default_; | |
struct cl_engine *engine_; | |
int result_; | |
unsigned int signs_; | |
std::string dbsign_path_; | |
struct cl_stat dbstat_; | |
struct optstruct *opts_; | |
const char *virname_; | |
}; | |
} | |
#endif /* INIT_SERVICES_HPP_ */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment