• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

HostLookup.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /*****************************************************************************
00025  *
00026  *  HostLookup.h - Interface to genernal purpose matcher
00027  *
00028  *
00029  ****************************************************************************/
00030 
00031 #ifndef _HOST_LOOKUP_H_
00032 #define _HOST_LOOKUP_H_
00033 // HostLookup  constantss
00034 const int HOST_TABLE_DEPTH = 3; // Controls the max number of levels in the logical tree
00035 const int HOST_ARRAY_MAX = 8;   // Sets the fixed array size
00036 
00037 //
00038 //  Begin Host Lookup Helper types
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 // The data in the HostMatcher tree is pointers to HostBranches.
00048 //   No duplicates keys permitted in the tree.  To handle multiple
00049 //   data items bound the same key, the HostBranch has the lead_indexs
00050 //   array which stores pointers (in the form of array indexes) to
00051 //   HostLeaf structs
00052 //
00053 // There is HostLeaf struct for each data item put into the
00054 //   table
00055 //
00056 struct HostLeaf
00057 {
00058   LeafType type;
00059   char *match;                  // Contains a copy of the match data
00060   int len;                      // length of the data
00061   bool isNot;                   // used by any fasssst path ...
00062   void *opaque_data;            // Data associated with this leaf
00063 };
00064 
00065 struct HostBranch
00066 {
00067   HostBranch();
00068   ~HostBranch();
00069   int level;                    // what level in the tree.  the root is level 0
00070   HostNodeType type;            // tells what kind of data structure is next_level is
00071   void *next_level;             // opaque pointer to lookup structure
00072     DynArray<int>leaf_indexs;        // pointers HostLeaf(s)
00073 };
00074 
00075 typedef void (*HostLookupPrintFunc) (void *opaque_data);
00076 //
00077 //  End Host Lookup Helper types
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;              // request lower-cased host name copy
00095   char *host_copy_next;         // ptr to part of host_copy for next use
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;             // The top of the search tree
00123   HostLeaf *leaf_array;         // array of all leaves in tree
00124   int array_len;                // the length of the arrays
00125   int num_el;                   // the numbe of itmems in the tree
00126   const char *matcher_name;     // Used for Debug/Warning/Error messages
00127 };
00128 
00129 
00130 #endif

Generated by  doxygen 1.7.1