Exemple #1
0
func (e *Engine) Addref() error {
	err := ErrorCode(C.cl_engine_compile((*C.struct_cl_engine)(e)))
	if err != Success {
		return fmt.Errorf("%v", StrError(err))
	}
	return nil
}
Exemple #2
0
func (e *clEngine) Compile(cvdDir string) error {
	e.mtx.Lock()
	defer e.mtx.Unlock()

	if e.IsCompiled() {
		return ErrAlreadyCompiled
	}

	// Create new engine
	e.engine = C.cl_engine_new()
	if e.engine == nil {
		return errors.New("failed to create new clamav engine")
	}

	// Load signatures
	var ret C.int
	var sigs C.uint = 0
	ret = C.cl_load(C.CString(cvdDir), e.engine, &sigs, C.CL_DB_STDOPT)
	if ret != C.CL_SUCCESS {
		return fmt.Errorf("could not load vcds: %s", C.GoString(C.cl_strerror(ret)))
	}

	// Compile engine
	ret = C.cl_engine_compile(e.engine)
	if ret != C.CL_SUCCESS {
		return fmt.Errorf("could not compile engine: %s", C.GoString(C.cl_strerror(ret)))
	}

	atomic.StoreInt32(&e.compiled, 1)

	return nil
}