Class: Clamrb
- Inherits:
-
Object
- Object
- Clamrb
- Defined in:
- lib/clamrb/result.rb,
lib/clamrb/version.rb,
ext/clamrb/clamrb.c
Defined Under Namespace
Classes: Result
Constant Summary collapse
- VERSION =
"0.0.4"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.new ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'ext/clamrb/clamrb.c', line 8
VALUE constructor(VALUE self)
{
if (cl_init(CL_INIT_DEFAULT) == CL_SUCCESS) {
struct cl_engine *engine = cl_engine_new();
VALUE t_data = Data_Wrap_Struct(self, 0, clamav_free, engine);
const char *dbDir = cl_retdbdir();
printf("Initializing clamav engine from database located at %s\n", dbDir);
unsigned int signature = 0;
if (cl_load(dbDir, engine, &signature, CL_DB_STDOPT) == CL_SUCCESS
&& cl_engine_compile(engine) == CL_SUCCESS) {
return t_data;
} else {
rb_raise(rb_eRuntimeError, "Error loading clamav database\n");
return Qnil;
}
} else {
rb_raise(rb_eRuntimeError, "Unable to initialize clamav\n");
return Qnil;
}
}
|
Instance Method Details
#scan(filename) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'ext/clamrb/clamrb.c', line 29
VALUE scan(VALUE self, VALUE filename)
{
struct cl_engine *engine;
Data_Get_Struct(self, struct cl_engine, engine);
const char *name = NULL;
long unsigned int scanned = 0;
struct cl_scan_options scanoptions;
memset(&scanoptions, 0, sizeof(struct cl_scan_options));
scanoptions.parse |= -0;
scanoptions.general |= CL_SCAN_GENERAL_ALLMATCHES;
int ret = cl_scanfile(StringValueCStr(filename), &name, &scanned, engine, &scanoptions);
VALUE clamrb = rb_const_get(rb_cObject, rb_intern("Clamrb"));
VALUE clamrb_result = rb_const_get(clamrb, rb_intern("Result"));
switch (ret) {
case CL_VIRUS:
return rb_funcall(clamrb_result, rb_intern("new"), 2,
ID2SYM(rb_intern("infected")),
rb_str_new_cstr(name));
case CL_CLEAN:
return rb_funcall(clamrb_result, rb_intern("new"), 1,
ID2SYM(rb_intern("clean")));
default:
return rb_funcall(clamrb_result, rb_intern("new"), 1,
ID2SYM(rb_intern("unknown")));
}
}
|