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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 #ifndef _CONTROL_MATCHER_H_
00088 #define _CONTROL_MATCHER_H_
00089
00090 #ifdef HAVE_PCRE_PCRE_H
00091 #include <pcre/pcre.h>
00092 #else
00093 #include <pcre.h>
00094 #endif
00095
00096 #ifdef HAVE_CTYPE_H
00097 #include <ctype.h>
00098 #endif
00099
00100 #include "DynArray.h"
00101 #include <ts/IpMap.h>
00102
00103 #include "ink_defs.h"
00104 #include "HTTP.h"
00105 #include "ink_apidefs.h"
00106
00107 class HostLookup;
00108 struct _HttpApiInfo;
00109 struct matcher_line;
00110 struct matcher_tags;
00111
00112 struct RequestData
00113 {
00114 public:
00115
00116
00117
00118
00119 virtual ~ RequestData()
00120 {
00121 }
00122 virtual char *get_string() = 0;
00123 virtual const char *get_host() = 0;
00124 virtual sockaddr const* get_ip() = 0;
00125
00126 virtual sockaddr const* get_client_ip() = 0;
00127
00128 enum RD_Type
00129 {
00130 RD_NULL,
00131 RD_HTTP,
00132 RD_CONGEST_ENTRY
00133 };
00134
00135 virtual RD_Type data_type(void) { return RD_NULL; }
00136 };
00137
00138 class HttpRequestData:public RequestData
00139 {
00140 public:
00141 inkcoreapi char *get_string();
00142 inkcoreapi const char *get_host();
00143 inkcoreapi sockaddr const* get_ip();
00144 inkcoreapi sockaddr const* get_client_ip();
00145
00146 HttpRequestData()
00147 : hdr(NULL), hostname_str(NULL), api_info(NULL), xact_start(0), incoming_port(0), tag(NULL)
00148 {
00149 ink_zero(src_ip);
00150 ink_zero(dest_ip);
00151 }
00152
00153 HTTPHdr *hdr;
00154 char *hostname_str;
00155 _HttpApiInfo *api_info;
00156 time_t xact_start;
00157 IpEndpoint src_ip;
00158 IpEndpoint dest_ip;
00159 uint16_t incoming_port;
00160 char *tag;
00161 };
00162
00163
00164 template<class Data, class Result> class UrlMatcher {
00165 public:
00166 UrlMatcher(const char *name, const char *filename);
00167 ~UrlMatcher();
00168 void Match(RequestData * rdata, Result * result);
00169 void AllocateSpace(int num_entries);
00170 char *NewEntry(matcher_line * line_info);
00171 void Print();
00172
00173 int getNumElements() { return num_el; }
00174 Data *getDataArray() { return data_array; }
00175
00176 protected:
00177 InkHashTable *url_ht;
00178 char **url_str;
00179 int *url_value;
00180 Data *data_array;
00181 int array_len;
00182 int num_el;
00183 const char *matcher_name;
00184 const char *file_name;
00185 };
00186
00187
00188 template<class Data, class Result> class RegexMatcher {
00189 public:
00190 RegexMatcher(const char *name, const char *filename);
00191 ~RegexMatcher();
00192 void Match(RequestData * rdata, Result * result);
00193 void AllocateSpace(int num_entries);
00194 char *NewEntry(matcher_line * line_info);
00195 void Print();
00196
00197 int getNumElements() { return num_el; }
00198 Data *getDataArray() { return data_array; }
00199
00200 protected:
00201 pcre** re_array;
00202 char **re_str;
00203 Data *data_array;
00204 int array_len;
00205 int num_el;
00206 const char *matcher_name;
00207 const char *file_name;
00208 };
00209
00210 template<class Data, class Result> class HostRegexMatcher:public RegexMatcher<Data, Result> {
00211 public:
00212 HostRegexMatcher(const char *name, const char *filename);
00213 void Match(RequestData * rdata, Result * result);
00214 };
00215
00216 template<class Data, class Result> class HostMatcher {
00217 public:
00218 HostMatcher(const char *name, const char *filename);
00219 ~HostMatcher();
00220 void Match(RequestData * rdata, Result * result);
00221 void AllocateSpace(int num_entries);
00222 char *NewEntry(matcher_line * line_info);
00223 void Print();
00224
00225 int getNumElements() { return num_el; }
00226 Data *getDataArray() { return data_array; }
00227 HostLookup *getHLookup() { return host_lookup; }
00228
00229 private:
00230 static void PrintFunc(void *opaque_data);
00231 HostLookup *host_lookup;
00232 Data *data_array;
00233 int array_len;
00234 int num_el;
00235 const char *matcher_name;
00236 const char *file_name;
00237 };
00238
00239 template<class Data, class Result> class IpMatcher {
00240 public:
00241 IpMatcher(const char *name, const char *filename);
00242 ~IpMatcher();
00243 void Match(sockaddr const* ip_addr, RequestData * rdata, Result * result);
00244 void AllocateSpace(int num_entries);
00245 char *NewEntry(matcher_line * line_info);
00246 void Print();
00247
00248 int getNumElements() { return num_el; }
00249 Data *getDataArray() { return data_array; }
00250
00251 static void PrintFunc(void *opaque_data);
00252 IpMap ip_map;
00253 Data *data_array;
00254 int array_len;
00255 int num_el;
00256 const char *matcher_name;
00257 const char *file_name;
00258 };
00259
00260
00261 #define ALLOW_HOST_TABLE 1 << 0
00262 #define ALLOW_IP_TABLE 1 << 1
00263 #define ALLOW_REGEX_TABLE 1 << 2
00264 #define ALLOW_HOST_REGEX_TABLE 1 << 3
00265 #define ALLOW_URL_TABLE 1 << 4
00266 #define DONT_BUILD_TABLE 1 << 5 // for testing
00267
00268 template<class Data, class Result> class ControlMatcher {
00269 public:
00270
00271
00272 ControlMatcher(const char *file_var, const char *name, const matcher_tags * tags,
00273 int flags_in = (ALLOW_HOST_TABLE | ALLOW_IP_TABLE | ALLOW_REGEX_TABLE |
00274 ALLOW_HOST_REGEX_TABLE | ALLOW_URL_TABLE));
00275 ~ControlMatcher();
00276 int BuildTable();
00277 int BuildTableFromString(char *str);
00278 void Match(RequestData * rdata, Result * result);
00279 void Print();
00280
00281 int getEntryCount() { return m_numEntries; }
00282 HostMatcher<Data, Result> *getHostMatcher() { return hostMatch; }
00283 RegexMatcher<Data, Result> *getReMatcher() { return reMatch; }
00284 UrlMatcher<Data, Result> *getUrlMatcher() { return urlMatch; }
00285 IpMatcher<Data, Result> *getIPMatcher() { return ipMatch; }
00286 HostRegexMatcher<Data, Result> *getHrMatcher() { return hrMatch; }
00287
00288
00289 RegexMatcher<Data, Result> *reMatch;
00290 UrlMatcher<Data, Result> *urlMatch;
00291 HostMatcher<Data, Result> *hostMatch;
00292 IpMatcher<Data, Result> *ipMatch;
00293 HostRegexMatcher<Data, Result> *hrMatch;
00294 const matcher_tags *config_tags;
00295 char config_file_path[PATH_NAME_MAX];
00296 int flags;
00297 int m_numEntries;
00298 const char *matcher_name;
00299 };
00300
00301 #endif