Class: ClamAV
- Inherits:
-
Object
- Object
- ClamAV
- Defined in:
- ext/clamav/clamav.c
Class Method Summary collapse
Instance Method Summary collapse
- #countsigs(*args) ⇒ Object
- #getlimit(v_limit) ⇒ Object
- #getstring(v_param) ⇒ Object
- #initialize ⇒ Object constructor
- #loaddb(*args) ⇒ Object
- #reload ⇒ Object
- #scanfile(*args) ⇒ Object
- #setlimit(v_limit, v_value) ⇒ Object
- #setstring(v_param, v_value) ⇒ Object
- #signo ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize ⇒ Object
25 26 27 |
# File 'ext/clamav/clamav.c', line 25 static VALUE clamavr_initialize(VALUE self) { return self; } |
Class Method Details
.new ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'ext/clamav/clamav.c', line 29
static VALUE clamavr_new(VALUE klass) {
VALUE v_options;
v_options = INT2FIX(CL_SCAN_STDOPT); /* default value */
int ret;
ret = cl_init(FIX2INT(v_options));
if(ret != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_init() error: %s\n", cl_strerror(ret));
}
struct ClamAV_R *ptr = ALLOC(struct ClamAV_R);
/* save options */
ptr->options = v_options;
ptr->root = NULL;
return Data_Wrap_Struct(klass, 0, clamavr_free, ptr);
}
|
Instance Method Details
#countsigs(*args) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'ext/clamav/clamav.c', line 185
static VALUE clamavr_countsigs(int argc, VALUE *argv, VALUE self) {
VALUE v_options;
rb_scan_args(argc, argv, "01", &v_options);
if(NIL_P(v_options)){
v_options = CL_COUNTSIGS_ALL; /* all signatures count */
}
const char *dbdir;
dbdir = cl_retdbdir();
int ret;
int signo = 0;
ret = cl_countsigs(dbdir, FIX2INT(v_options), &signo);
if(ret != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_countsigs() error: %s\n", cl_strerror(ret));
}
return INT2NUM(signo);
}
|
#getlimit(v_limit) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'ext/clamav/clamav.c', line 132
static VALUE clamavr_getlimit(VALUE self, VALUE v_limit) {
Check_Type(v_limit, T_FIXNUM);
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
int ret;
int err;
ret = cl_engine_get_num(ptr->root, FIX2INT(v_limit), &err);
if(err != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_engine_get_num() error: %s\n", cl_strerror(err));
}
return INT2NUM(ret);
}
|
#getstring(v_param) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'ext/clamav/clamav.c', line 162
static VALUE clamavr_getstring(VALUE self, VALUE v_param) {
Check_Type(v_param, T_FIXNUM);
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
const char *result;
int err;
result = cl_engine_get_str(ptr->root, FIX2INT(v_param), &err);
if(err != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_engine_get_str() error: %s\n", cl_strerror(err));
}
if(result == NULL){
return Qnil;
}
return rb_str_new2(result);
}
|
#loaddb(*args) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'ext/clamav/clamav.c', line 78
static VALUE clamavr_loaddb(int argc, VALUE *argv, VALUE self) {
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
VALUE v_db_options;
rb_scan_args(argc, argv, "01", &v_db_options);
if(NIL_P(v_db_options)){
v_db_options = INT2FIX(CL_DB_STDOPT); /* default value */
}
if(ptr->root != NULL) {
cl_engine_free(ptr->root);
}
clamavr_build(v_db_options, ptr);
return CL_SUCCESS;
}
|
#reload ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'ext/clamav/clamav.c', line 97
static VALUE clamavr_reload(VALUE self) {
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
int state;
state = cl_statchkdir(&ptr->dbstat);
if(state == 1) {
const char *dbdir;
dbdir = cl_retdbdir();
int ret;
ret = cl_load(dbdir, ptr->root, &ptr->signo, FIX2INT(ptr->db_options));
if(ret != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_load() error: %s\n", cl_strerror(ret));
}
cl_statfree(&ptr->dbstat);
cl_statinidir(dbdir, &ptr->dbstat);
}
return INT2FIX(state);
}
|
#scanfile(*args) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'ext/clamav/clamav.c', line 205
static VALUE clamavr_scanfile(int argc, VALUE *argv, VALUE klass) {
struct ClamAV_R *ptr;
Data_Get_Struct(klass, struct ClamAV_R, ptr);
const char *v_fname;
VALUE v_options;
rb_scan_args(argc, argv, "11", &v_fname, &v_options);
if(ptr->root == NULL) {
rb_raise(rb_eRuntimeError, "ClamAV error: you should call loaddb() before scanning\n");
}
if(NIL_P(v_options)){
v_options = ptr->options; /* stored value */
}
Check_Type(v_fname, T_STRING);
Check_Type(v_options, T_FIXNUM);
int ret;
const char *virname;
ret = cl_scanfile(RSTRING_PTR(v_fname), &virname, NULL, ptr->root, FIX2INT(v_options));
if (ret == CL_VIRUS) {
return rb_str_new2(virname);
} else {
return INT2FIX(ret);
}
}
|
#setlimit(v_limit, v_value) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'ext/clamav/clamav.c', line 117
static VALUE clamavr_setlimit(VALUE self, VALUE v_limit, VALUE v_value) {
Check_Type(v_limit, T_FIXNUM);
Check_Type(v_value, T_FIXNUM);
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
int ret;
ret = cl_engine_set_num(ptr->root, FIX2INT(v_limit), FIX2INT(v_value));
if(ret != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_engine_set_num() error: %s\n", cl_strerror(ret));
}
return INT2FIX(ret);
}
|
#setstring(v_param, v_value) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/clamav/clamav.c', line 147
static VALUE clamavr_setstring(VALUE self, VALUE v_param, VALUE v_value) {
Check_Type(v_param, T_FIXNUM);
Check_Type(v_value, T_STRING);
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
int ret;
ret = cl_engine_set_str(ptr->root, FIX2INT(v_param), RSTRING_PTR(v_value));
if(ret != CL_SUCCESS) {
rb_raise(rb_eRuntimeError, "cl_engine_set_str() error: %s\n", cl_strerror(ret));
}
return INT2FIX(ret);
}
|
#signo ⇒ Object
178 179 180 181 182 |
# File 'ext/clamav/clamav.c', line 178
static VALUE clamavr_signo(VALUE self) {
struct ClamAV_R *ptr;
Data_Get_Struct(self, struct ClamAV_R, ptr);
return UINT2NUM(ptr->signo);
}
|
#version ⇒ Object
235 236 237 238 239 |
# File 'ext/clamav/clamav.c', line 235 static VALUE clamavr_retver(VALUE self) { const char *res; res = cl_retver(); return rb_str_new2(res); } |