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

ControlBase.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  *  ControlBase.h - Base class to process generic modifiers to
00027  *                         ControlMatcher Directives
00028  *
00029  *
00030  ****************************************************************************/
00031 
00032 
00033 #ifndef _CONTROL_BASE_H_
00034 #define _CONTROL_BASE_H_
00035 
00036 #include "libts.h"
00037 
00038 class HttpRequestData;
00039 class Tokenizer;
00040 struct matcher_line;
00041 
00042 class ControlBase {
00043 public:
00044   struct Modifier {
00045     enum Type {
00046       MOD_INVALID,
00047       MOD_PORT,
00048       MOD_SCHEME,
00049       MOD_PREFIX,
00050       MOD_SUFFIX,
00051       MOD_METHOD,
00052       MOD_TIME,
00053       MOD_SRC_IP,
00054       MOD_IPORT,
00055       MOD_TAG
00056     };
00057     /// Destructor - force virtual.
00058     virtual ~Modifier();
00059     /// Return the modifier type.
00060     virtual Type type() const;
00061     /// Return the name for the modifier type.
00062     virtual char const* name() const = 0;
00063     /** Test if the modifier matches the request.
00064         @return @c true if the request is matched, @c false if not.
00065     */
00066     virtual bool check(
00067       HttpRequestData* req ///< Request to check.
00068     ) const = 0;
00069     /// Print the mod information.
00070     virtual void print(
00071       FILE* f ///< Output stream.
00072     ) const = 0;
00073   };
00074 
00075   ControlBase();
00076   ~ControlBase();
00077   const char *ProcessModifiers(matcher_line * line_info);
00078   bool CheckModifiers(HttpRequestData * request_data);
00079   bool CheckForMatch(HttpRequestData * request_data, int last_number);
00080   void Print();
00081   int line_num;
00082   Modifier* findModOfType(Modifier::Type t) const;
00083 protected:
00084   /// Get the text for the Scheme modifier, if any.
00085   /// @return The text if present, 0 otherwise.
00086   /// @internal Ugly but it's the only place external access is needed.
00087   char const* getSchemeModText() const;
00088 private:
00089   typedef Vec<Modifier*> Array;
00090   Array _mods;
00091   const char *ProcessSrcIp(char *val, void **opaque_ptr);
00092   const char *ProcessTimeOfDay(char *val, void **opaque_ptr);
00093   const char *ProcessPort(char *val, void **opaque_ptr);
00094 
00095   // Reset to default constructed state, free all allocations.
00096   void clear();
00097 };
00098 
00099 inline
00100 ControlBase::ControlBase()
00101   : line_num(0) {
00102 }
00103 
00104 inline bool
00105 ControlBase::CheckForMatch(HttpRequestData * request_data, int last_number) {
00106   return (last_number<0 || last_number> this->line_num)
00107     && this->CheckModifiers(request_data)
00108     ;
00109 }
00110 
00111 #endif

Generated by  doxygen 1.7.1