Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

acsmx2.h

Go to the documentation of this file.
00001 /*
00002 **   ACSMX2.H 
00003 **
00004 **   Version 2.0
00005 **
00006 **   Copyright (C) 2002,2003,2004 Marc Norton
00007 **   Copyright (C) 2003,2004 Sourcefire,Inc.
00008 */
00009 
00010 #include <stdio.h>
00011 #include <stdlib.h>
00012 #include <string.h>
00013 
00014 #ifndef ACSMX2S_H
00015 #define ACSMX2S_H
00016 
00017 #ifdef WIN32
00018 
00019 #ifdef inline
00020 #undef inline
00021 #endif
00022 
00023 #define inline __inline
00024 
00025 #endif
00026 
00027 /*
00028 *   DEFINES and Typedef's
00029 */
00030 #define MAX_ALPHABET_SIZE 256     
00031 
00032 /*
00033    FAIL STATE for 1,2,or 4 bytes for state transitions
00034 
00035    Uncomment this define to use 32 bit state values
00036    #define AC32
00037 */
00038 
00039 /* #define AC32 */
00040 
00041 #ifdef AC32
00042 
00043 typedef  unsigned int   acstate_t;
00044 #define ACSM_FAIL_STATE2  0xffffffff
00045 
00046 #else
00047 
00048 typedef    unsigned short acstate_t;
00049 #define ACSM_FAIL_STATE2 0xffff
00050 
00051 #endif
00052 
00053 /*
00054 *
00055 */
00056 typedef 
00057 struct _acsm_pattern2
00058 {      
00059     struct  _acsm_pattern2 *next;
00060 
00061     unsigned char         *patrn;
00062     unsigned char         *casepatrn;
00063     int      n;
00064     int      nocase;
00065     int      offset;
00066     int      depth;
00067     void *   id;
00068     int      iid;
00069 
00070 } ACSM_PATTERN2;
00071 
00072 /*
00073 *    transition nodes  - either 8 or 12 bytes
00074 */
00075 typedef 
00076 struct trans_node_s {
00077 
00078   acstate_t    key;           /* The character that got us here - sized to keep structure aligned on 4 bytes */
00079                               /* to better the caching opportunities. A value that crosses the cache line */
00080                               /* forces an expensive reconstruction, typing this as acstate_t stops that. */
00081   acstate_t    next_state;    /*  */
00082   struct trans_node_s * next; /* next transition for this state */
00083 
00084 } trans_node_t;
00085 
00086 
00087 /*
00088 *  User specified final storage type for the state transitions
00089 */
00090 enum {
00091   ACF_FULL,
00092   ACF_SPARSE,
00093   ACF_BANDED,
00094   ACF_SPARSEBANDS,
00095 };
00096 
00097 /*
00098 *   User specified machine types
00099 *
00100 *   TRIE : Keyword trie
00101 *   NFA  : 
00102 *   DFA  : 
00103 */
00104 enum {
00105   FSA_TRIE,
00106   FSA_NFA,
00107   FSA_DFA,
00108 };
00109 
00110 /*
00111 *   Aho-Corasick State Machine Struct - one per group of pattterns
00112 */
00113 typedef struct {
00114   
00115         int acsmMaxStates;  
00116         int acsmNumStates;  
00117 
00118         ACSM_PATTERN2    * acsmPatterns;
00119         acstate_t        * acsmFailState;
00120         ACSM_PATTERN2   ** acsmMatchList;
00121 
00122         /* list of transitions in each state, this is used to build the nfa & dfa */
00123         /* after construction we convert to sparse or full format matrix and free */
00124         /* the transition lists */
00125         trans_node_t ** acsmTransTable;
00126 
00127         acstate_t ** acsmNextState;
00128         int          acsmFormat;
00129         int          acsmSparseMaxRowNodes;
00130         int          acsmSparseMaxZcnt;
00131         
00132         int          acsmNumTrans;
00133         int          acsmAlphabetSize;
00134         int          acsmFSA;
00135 
00136 }ACSM_STRUCT2;
00137 
00138 /*
00139 *   Prototypes
00140 */
00141 ACSM_STRUCT2 * acsmNew2 ();
00142 int acsmAddPattern2( ACSM_STRUCT2 * p, unsigned char * pat, int n,
00143                     int nocase, int offset, int depth, void *  id, int iid );
00144 int acsmCompile2 ( ACSM_STRUCT2 * acsm );
00145 int acsmSearch2 ( ACSM_STRUCT2 * acsm,unsigned char * T, int n, 
00146                   int (*Match)( void * id, int index, void * data ),
00147                   void * data );
00148 void acsmFree2 ( ACSM_STRUCT2 * acsm );
00149 
00150 
00151 int  acsmSelectFormat2( ACSM_STRUCT2 * acsm, int format );
00152 int  acsmSelectFSA2( ACSM_STRUCT2 * acsm, int fsa );
00153 
00154 void acsmSetMaxSparseBandZeros2( ACSM_STRUCT2 * acsm, int n );
00155 void acsmSetMaxSparseElements2( ACSM_STRUCT2 * acsm, int n );
00156 int  acsmSetAlphabetSize2( ACSM_STRUCT2 * acsm, int n );
00157 void acsmSetVerbose2(int n);
00158 
00159 void acsmPrintInfo2( ACSM_STRUCT2 * p);
00160 
00161 int acsmPrintDetailInfo2(ACSM_STRUCT2*);
00162 int acsmPrintSummaryInfo2();
00163 
00164 #endif

Generated on Sun May 14 14:51:18 2006 by  doxygen 1.4.2