clamav-devel/libclamav/clamav.h
e3aaff8e
 /*
48b7b4a7
  *  Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
e3aaff8e
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
  *  (at your option) any later version.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
48b7b4a7
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  *  MA 02110-1301, USA.
e3aaff8e
  */
 
 #ifndef __CLAMAV_H
 #define __CLAMAV_H
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
  
 #ifdef __cplusplus
 extern "C"
 {
 #endif
 
 
 #define CL_COUNT_PRECISION 4096
 
 /* return codes */
 #define CL_CLEAN	0   /* virus not found */
 #define CL_VIRUS	1   /* virus found */
f51e962f
 #define CL_SUCCESS	CL_CLEAN
414abe87
 
e3aaff8e
 #define CL_EMAXREC	10  /* recursion level limit exceeded */
 #define CL_EMAXSIZE	11  /* size limit exceeded */
 #define CL_EMAXFILES	12  /* files limit exceeded */
 #define CL_ERAR		100 /* rar handler error */
 #define CL_EZIP		101 /* zip handler error */
 #define	CL_EMALFZIP	102 /* malformed zip */
 #define CL_EGZIP	103 /* gzip handler error */
 #define CL_EBZIP	104 /* bzip2 handler error */
47bbbc56
 #define CL_EOLE2	105 /* OLE2 handler error */
341e5433
 #define CL_EMSCOMP	106 /* compress.exe handler error */
414abe87
 #define CL_EMSCAB	107 /* MS CAB module error */
e3aaff8e
 #define CL_EACCES	200 /* access denied */
 #define CL_ENULLARG	300 /* null argument error */
 
6a2532ca
 #define CL_ETMPFILE	-1  /* tmpfile() failed */
 #define CL_EFSYNC	-2  /* fsync() failed */
 #define CL_EMEM		-3  /* memory allocation error */
 #define CL_EOPEN	-4  /* file open error */
 #define CL_EMALFDB	-5  /* malformed database */
 #define CL_EPATSHORT	-6  /* pattern too short */
 #define CL_ETMPDIR	-7  /* mkdir() failed */
 #define CL_ECVD		-8  /* not a CVD file (or broken) */
 #define CL_ECVDEXTR	-9  /* CVD extraction failure */
 #define CL_EMD5		-10 /* MD5 verification error */
 #define CL_EDSIG	-11 /* digital signature verification error */
ac75a532
 #define CL_EIO		-12 /* general I/O error */
bbd221d0
 #define CL_EFORMAT	-13 /* bad format or broken file */
e3aaff8e
 
f51e962f
 #define CL_EHWINIT	-14 /* hardware initialization failed */
 #define	CL_EHWLOAD	-15 /* error loading hardware database */
 #define CL_EHWIO	-16 /* general hardware I/O error */
 
 
f7470773
 /* db options */
 #define CL_DB_HWACCEL		1
15e1a7cd
 #define CL_DB_NOPHISHING	2
83fa5305
 #define CL_DB_ACONLY		4   /* for developers only */
f7470773
 
3805ebcb
 /* scan options */
 #define CL_SCAN_RAW		0
 #define CL_SCAN_ARCHIVE		1
 #define CL_SCAN_MAIL		2
588cf90b
 #define CL_SCAN_OLE2		4
 #define CL_SCAN_BLOCKENCRYPTED	8
 #define CL_SCAN_HTML		16
 #define CL_SCAN_PE		32
 #define CL_SCAN_BLOCKBROKEN	64
 #define CL_SCAN_MAILURL		128
 #define CL_SCAN_BLOCKMAX	256
1b661cef
 #define CL_SCAN_ALGO		512
e3aaff8e
 
64d54968
 /* recommended options */
1b661cef
 #define CL_SCAN_STDOPT		(CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_HTML | CL_SCAN_PE | CL_SCAN_ALGO) 
3805ebcb
 
 /* aliases for backward compatibility */
 #define CL_RAW		CL_SCAN_RAW
 #define CL_ARCHIVE	CL_SCAN_ARCHIVE
 #define CL_MAIL		CL_SCAN_MAIL
 #define CL_OLE2		CL_SCAN_OLE2
d262115a
 #define CL_ENCRYPTED    CL_SCAN_BLOCKENCRYPTED
5612732c
 #define cl_node		cl_engine
3805ebcb
 
8000d078
 
 struct cli_bm_patt {
b68d11d2
     char *pattern, *virname, *offset;
     const char *viralias;
     unsigned int length;
     unsigned short target;
8000d078
     struct cli_bm_patt *next;
 };
 
 struct cli_ac_patt {
e3aaff8e
     short int *pattern;
084ee140
     unsigned int length, mindist, maxdist;
b68d11d2
     char *virname, *offset;
     const char *viralias;
     unsigned short int sigid, parts, partno, alt, *altn;
     unsigned short type, target;
084ee140
     char **altc;
8000d078
     struct cli_ac_patt *next;
e3aaff8e
 };
 
4048c4f6
 struct cli_ac_node {
e3aaff8e
     char islast;
8000d078
     struct cli_ac_patt *list;
     struct cli_ac_node *trans[256], *fail;
4048c4f6
 };
e3aaff8e
 
4048c4f6
 struct cli_md5_node {
058ccefe
     char *virname, *viralias;
     unsigned char *md5;
022a21cf
     unsigned int size;
db65451b
     unsigned short fp;
4048c4f6
     struct cli_md5_node *next;
 };
 
a62ae54f
 struct cli_meta_node {
eedf6131
     int csize, size, method;
     unsigned int crc32, fileno, encrypted, maxdepth;
e5916a51
     char *filename, *virname;
a62ae54f
     struct cli_meta_node *next;
e5916a51
 };
 
5612732c
 struct cli_matcher {
8000d078
     unsigned int maxpatlen; /* maximal length of pattern in db */
83fa5305
     unsigned short ac_only;
8000d078
 
     /* Extended Boyer-Moore */
     int *bm_shift;
     struct cli_bm_patt **bm_suffix;
 
     /* Extended Aho-Corasick */
c6fb0b98
     unsigned int ac_depth;
8000d078
     struct cli_ac_node *ac_root, **ac_nodetable;
     unsigned int ac_partsigs, ac_nodes;
5612732c
 };
 
 struct cl_engine {
     unsigned int refcount; /* reference counter */
f7470773
     unsigned short hwaccel;
555c5390
     unsigned short sdb;
5612732c
 
     /* Roots table */
     struct cli_matcher **root;
4048c4f6
 
     /* MD5 */
8000d078
     struct cli_md5_node **md5_hlist;
e5916a51
 
     /* Zip metadata */
a62ae54f
     struct cli_meta_node *zip_mlist;
 
     /* RAR metadata */
     struct cli_meta_node *rar_mlist;
 
f51e962f
     /* Hardware database handle */
     void *hwdb;
e3aaff8e
 };
 
 struct cl_limits {
33f89aa5
     unsigned int maxreclevel; /* maximal recursion level */
     unsigned int maxfiles; /* maximal number of files to be
 			    * scanned within an archive
 			    */
     unsigned int maxratio; /* maximal compression ratio */
     unsigned short archivememlim; /* limit memory usage for bzip2 (0/1) */
     unsigned long int maxfilesize; /* files in an archive larger than
 				    * this limit will not be scanned
 				    */
e3aaff8e
 };
 
 struct cl_stat {
     char *dir;
     int no;
     struct stat *stattab;
75ccac9f
     char **statdname;
e3aaff8e
 };
 
8139fd99
 struct cl_cvd {
     char *time;	    /* 2 */
     int version;    /* 3 */
     int sigs;	    /* 4 */
     short int fl;   /* 5 */
     char *md5;	    /* 6 */
     char *dsig;	    /* 7 */
     char *builder;  /* 8 */
c48c9d2b
     int stime;	    /* 9 */
8139fd99
 };
 
e3aaff8e
 /* file scanning */
5612732c
 extern int cl_scandesc(int desc, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options);
e3aaff8e
 
5612732c
 extern int cl_scanfile(const char *filename, const char **virname, unsigned long int *scanned, const struct cl_engine *engine, const struct cl_limits *limits, unsigned int options);
e3aaff8e
 
8d78fc78
 /* software versions */
 extern int cl_retflevel(void);
d0b7d0d5
 extern const char *cl_retver(void);
8d78fc78
 
8000d078
 /* database */
5612732c
 extern int cl_loaddb(const char *filename, struct cl_engine **engine, unsigned int *signo);
 extern int cl_loaddbdir(const char *dirname, struct cl_engine **engine, unsigned int *signo);
f7470773
 extern int cl_load(const char *path, struct cl_engine **engine, unsigned int *signo, unsigned int options);
68a6f51f
 extern const char *cl_retdbdir(void);
5612732c
 extern struct cl_engine *cl_dup(struct cl_engine *engine);
e3aaff8e
 
8000d078
 /* CVD */
8139fd99
 extern struct cl_cvd *cl_cvdhead(const char *file);
e4ae7726
 extern struct cl_cvd *cl_cvdparse(const char *head);
 extern int cl_cvdverify(const char *file);
8139fd99
 extern void cl_cvdfree(struct cl_cvd *cvd);
 
d4d14218
 /* data dir stat functions */
e3aaff8e
 extern int cl_statinidir(const char *dirname, struct cl_stat *dbstat);
 extern int cl_statchkdir(const struct cl_stat *dbstat);
 extern int cl_statfree(struct cl_stat *dbstat);
 
d4d14218
 /* enable debug information */
 extern void cl_debug(void);
e3aaff8e
 
590135f9
 extern void cl_settempdir(const char *dir, short leavetemps);
 
5612732c
 extern int cl_build(struct cl_engine *engine);
 extern void cl_free(struct cl_engine *engine);
e3aaff8e
 
68a6f51f
 extern const char *cl_strerror(int clerror);
e3aaff8e
 
 #ifdef __cplusplus
23dc9e0b
 }
e3aaff8e
 #endif
  
 #endif