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 #ifndef _MATCHER_UTILS_H_
00033 #define _MATCHER_UTILS_H_
00034
00035 #include "ParseRules.h"
00036
00037 char *readIntoBuffer(const char *file_path, const char *module_name, int *read_size_ptr);
00038
00039 int unescapifyStr(char *buffer);
00040
00041
00042
00043
00044
00045 char const* ExtractIpRange(
00046 char *match_str,
00047 sockaddr* min,
00048 sockaddr* max
00049 );
00050
00051
00052 char const* ExtractIpRange(
00053 char *match_str,
00054 in_addr_t * addr1,
00055 in_addr_t * addr2
00056 );
00057
00058
00059 inline char const* ExtractIpRange(
00060 char *match_str,
00061 sockaddr_in6* addr1,
00062 sockaddr_in6* addr2
00063 ) {
00064 return ExtractIpRange(match_str, ats_ip_sa_cast(addr1), ats_ip_sa_cast(addr2));
00065 }
00066
00067 char *tokLine(char *buf, char **last, char cont = '\0');
00068
00069 const char *processDurationString(char *str, int *seconds);
00070
00071
00072 enum matcher_type
00073 { MATCH_NONE, MATCH_HOST, MATCH_DOMAIN,
00074 MATCH_IP, MATCH_REGEX, MATCH_URL, MATCH_HOST_REGEX
00075 };
00076 extern const char *matcher_type_str[];
00077
00078
00079 const int MATCHER_MAX_TOKENS = 40;
00080 struct matcher_line
00081 {
00082 matcher_type type;
00083 int dest_entry;
00084 int num_el;
00085 char *line[2][MATCHER_MAX_TOKENS];
00086 int line_num;
00087 matcher_line *next;
00088 };
00089
00090
00091 struct matcher_tags
00092 {
00093 const char *match_host;
00094 const char *match_domain;
00095 const char *match_ip;
00096 const char *match_regex;
00097 const char *match_url;
00098 const char *match_host_regex;
00099 bool dest_error_msg;
00100
00101 bool empty() const {
00102 return this->match_host == NULL &&
00103 this->match_domain == NULL &&
00104 this->match_ip == NULL &&
00105 this->match_regex == NULL &&
00106 this->match_url == NULL &&
00107 this->match_host_regex == NULL;
00108 }
00109
00110 };
00111
00112 extern const matcher_tags http_dest_tags;
00113 extern const matcher_tags ip_allow_tags;
00114 extern const matcher_tags socks_server_tags;
00115
00116 const char *parseConfigLine(char *line, matcher_line * p_line, const matcher_tags * tags);
00117
00118
00119
00120
00121
00122
00123 static inline void
00124 LowerCaseStr(char *str)
00125 {
00126 if (!str)
00127 return;
00128 while (*str != '\0') {
00129 *str = ParseRules::ink_tolower(*str);
00130 str++;
00131 }
00132 }
00133
00134 #endif