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

MatcherUtils.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  *  MatcherUtils.h - Various helper routines used in ControlMatcher
00027  *                    and ReverseProxy
00028  *
00029  *
00030  ****************************************************************************/
00031 
00032 #ifndef _MATCHER_UTILS_H_
00033 #define _MATCHER_UTILS_H_
00034 
00035 #include "ParseRules.h"
00036 // Look in MatcherUtils.cc for comments on function usage
00037 char *readIntoBuffer(const char *file_path, const char *module_name, int *read_size_ptr);
00038 
00039 int unescapifyStr(char *buffer);
00040 
00041 /** Extract an IP range.
00042     @a min and @a max should be at least the size of @c sockaddr_in6 to hold
00043     an IP address.
00044 */
00045 char const* ExtractIpRange(
00046   char *match_str,
00047   sockaddr* min,
00048   sockaddr* max
00049 );
00050 
00051 /// Convenience overload for IPv4.
00052 char const* ExtractIpRange(
00053   char *match_str,
00054   in_addr_t * addr1, ///< [in,out] Returned address in host order.
00055   in_addr_t * addr2 ///< [in,out] Returned address in host order.
00056 );
00057 
00058 /// Convenience overload for IPv6.
00059 inline char const* ExtractIpRange(
00060   char *match_str,
00061   sockaddr_in6* addr1, ///< [in,out] Returned address in network order.
00062   sockaddr_in6* addr2 ///< [in,out] Returned address in network order.
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 // The first class types we support matching on
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 // A parsed config file line
00079 const int MATCHER_MAX_TOKENS = 40;
00080 struct matcher_line
00081 {
00082   matcher_type type;            // dest type
00083   int dest_entry;               // entry which specifies the destination
00084   int num_el;                   // Number of elements
00085   char *line[2][MATCHER_MAX_TOKENS];    // label, value pairs
00086   int line_num;                 // config file line number
00087   matcher_line *next;           // use for linked list
00088 };
00089 
00090 // Tag set to use to determining primary selector type
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;          // whether to use src or destination in any error messages
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 // inline void LowerCaseStr(char* str)
00119 //
00120 //   Modifies str so all characters are lower
00121 //     case
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

Generated by  doxygen 1.7.1