Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 #ifndef _HOST_LOOKUP_H_
00032 #define _HOST_LOOKUP_H_
00033 
00034 const int HOST_TABLE_DEPTH = 3; 
00035 const int HOST_ARRAY_MAX = 8;   
00036 
00037 
00038 
00039 
00040 enum HostNodeType
00041 { HOST_TERMINAL, HOST_HASH, HOST_INDEX, HOST_ARRAY };
00042 enum LeafType
00043 { LEAF_INVALID, HOST_PARTIAL, HOST_COMPLETE,
00044   DOMAIN_COMPLETE, DOMAIN_PARTIAL
00045 };
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 struct HostLeaf
00057 {
00058   LeafType type;
00059   char *match;                  
00060   int len;                      
00061   bool isNot;                   
00062   void *opaque_data;            
00063 };
00064 
00065 struct HostBranch
00066 {
00067   HostBranch();
00068   ~HostBranch();
00069   int level;                    
00070   HostNodeType type;            
00071   void *next_level;             
00072     DynArray<int>leaf_indexs;        
00073 };
00074 
00075 typedef void (*HostLookupPrintFunc) (void *opaque_data);
00076 
00077 
00078 
00079 
00080 struct HostLookupState
00081 {
00082   HostLookupState()
00083     : cur(NULL), table_level(0), array_index(0), hostname(NULL), host_copy(NULL), host_copy_next(NULL)
00084   { }
00085 
00086   ~HostLookupState() {
00087     ats_free(host_copy);
00088   }
00089 
00090   HostBranch *cur;
00091   int table_level;
00092   int array_index;
00093   const char *hostname;
00094   char *host_copy;              
00095   char *host_copy_next;         
00096 };
00097 
00098 class HostLookup
00099 {
00100 public:
00101   HostLookup(const char *name);
00102    ~HostLookup();
00103   void NewEntry(const char *match_data, bool domain_record, void *opaque_data_in);
00104   void AllocateSpace(int num_entries);
00105   bool Match(const char *host);
00106   bool Match(const char *host, void **opaque_ptr);
00107   bool MatchFirst(const char *host, HostLookupState * s, void **opaque_ptr);
00108   bool MatchNext(HostLookupState * s, void **opaque_ptr);
00109   void Print(HostLookupPrintFunc f);
00110   void Print();
00111   HostLeaf *getLArray()
00112   {
00113     return leaf_array;
00114   };
00115 private:
00116   void TableInsert(const char *match_data, int index, bool domain_record);
00117   HostBranch *TableNewLevel(HostBranch * from, const char *level_data);
00118   HostBranch *InsertBranch(HostBranch * insert_in, const char *level_data);
00119   HostBranch *FindNextLevel(HostBranch * from, const char *level_data, bool bNotProcess = false);
00120   bool MatchArray(HostLookupState * s, void **opaque_ptr, DynArray<int>&array, bool host_done);
00121   void PrintHostBranch(HostBranch * hb, HostLookupPrintFunc f);
00122   HostBranch *root;             
00123   HostLeaf *leaf_array;         
00124   int array_len;                
00125   int num_el;                   
00126   const char *matcher_name;     
00127 };
00128 
00129 
00130 #endif