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

UrlMapping.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 #ifndef _URL_MAPPING_H_
00025 #define _URL_MAPPING_H_
00026 
00027 #include "AclFiltering.h"
00028 #include "Main.h"
00029 #include "Error.h"
00030 #include "URL.h"
00031 #include "RemapPluginInfo.h"
00032 
00033 #ifdef HAVE_PCRE_PCRE_H
00034 #include <pcre/pcre.h>
00035 #else
00036 #include <pcre.h>
00037 #endif
00038 
00039 static const unsigned int MAX_REMAP_PLUGIN_CHAIN = 10;
00040 
00041 
00042 /**
00043  * Used to store http referer strings (and/or regexp)
00044 **/
00045 class referer_info
00046 {
00047 public:
00048   referer_info(char *_ref, bool * error_flag = NULL, char *errmsgbuf = NULL, int errmsgbuf_size = 0);
00049    ~referer_info();
00050   referer_info *next;
00051   char *referer;
00052   int referer_size;
00053   bool any;                     /* any flag '*' */
00054   bool negative;                /* negative referer '~' */
00055   bool regx_valid;
00056   pcre* regx;
00057 };
00058 
00059 /**
00060  *
00061 **/
00062 class redirect_tag_str
00063 {
00064 public:
00065    redirect_tag_str()
00066      : next(0), chunk_str(NULL), type(0)
00067     { }
00068 
00069   ~redirect_tag_str()
00070   {
00071     type = 0;
00072     if (chunk_str) {
00073       ats_free(chunk_str);
00074       chunk_str = NULL;
00075     }
00076   }
00077 
00078   redirect_tag_str *next;
00079   char *chunk_str;
00080   char type;                    /* s - string, r - referer, t - url_to, f - url_from, o - origin url */
00081   static redirect_tag_str *parse_format_redirect_url(char *url);
00082 };
00083 
00084 /**
00085  * Used to store the mapping for class UrlRewrite
00086 **/
00087 class url_mapping
00088 {
00089 public:
00090   url_mapping(int rank = 0);
00091   ~url_mapping();
00092 
00093   bool add_plugin(remap_plugin_info *i, void* ih);
00094   remap_plugin_info *get_plugin(unsigned int) const;
00095 
00096   void* get_instance(unsigned int index) const { return _instance_data[index]; };
00097   void delete_instance(unsigned int index);
00098   void Print();
00099 
00100   int from_path_len;
00101   URL fromURL;
00102   URL toUrl; // Default TO-URL (from remap.config)
00103   bool homePageRedirect;
00104   bool unique;                  // INKqa11970 - unique mapping
00105   bool default_redirect_url;
00106   bool optional_referer;
00107   bool negative_referer;
00108   bool wildcard_from_scheme;    // from url is '/foo', only http or https for now
00109   char *tag;                    // tag
00110   char *filter_redirect_url;    // redirect url when referer filtering enabled
00111   unsigned int map_id;
00112   referer_info *referer_list;
00113   redirect_tag_str *redir_chunk_list;
00114   acl_filter_rule *filter;      // acl filtering (list of rules)
00115   unsigned int _plugin_count;
00116   LINK(url_mapping, link); // For use with the main Queue linked list holding all the mapping
00117 
00118   int getRank() const { return _rank; };
00119 
00120 private:
00121   remap_plugin_info* _plugin_list[MAX_REMAP_PLUGIN_CHAIN];
00122   void* _instance_data[MAX_REMAP_PLUGIN_CHAIN];
00123   int _rank;
00124 };
00125 
00126 
00127 /**
00128  * UrlMappingContainer wraps a url_mapping object and allows a caller to rewrite the target URL.
00129  * This is used while evaluating remap rules.
00130 **/
00131 class UrlMappingContainer {
00132 public:
00133  UrlMappingContainer()
00134    : _mapping(NULL), _toURLPtr(NULL), _heap(NULL)
00135     { }
00136 
00137   explicit UrlMappingContainer(HdrHeap *heap)
00138     : _mapping(NULL), _toURLPtr(NULL), _heap(heap)
00139   { }
00140 
00141   ~UrlMappingContainer() { deleteToURL(); }
00142   
00143   URL * getToURL() const { return _toURLPtr; };
00144   URL * getFromURL() const { return _mapping ? &(_mapping->fromURL) : NULL; };
00145 
00146   url_mapping *getMapping() const { return _mapping; };
00147 
00148   void set(url_mapping *m) { 
00149     deleteToURL();
00150     _mapping = m;
00151     _toURLPtr = m ? &(m->toUrl) : NULL;
00152   }
00153 
00154   void set(HdrHeap *heap) {
00155     _heap = heap;
00156   }
00157 
00158   URL *createNewToURL() {
00159     ink_assert(_heap != NULL);
00160     deleteToURL();
00161     _toURL.create(_heap);
00162     _toURLPtr = &_toURL;
00163     return _toURLPtr; 
00164   }
00165 
00166   void deleteToURL() {
00167     if (_toURLPtr == &_toURL) {
00168       _toURL.clear();
00169     }
00170   }
00171 
00172   void clear() {
00173     deleteToURL();
00174     _mapping = NULL;
00175     _toURLPtr = NULL;
00176     _heap = NULL;
00177   }
00178 
00179 private:
00180   url_mapping *_mapping;
00181   URL *_toURLPtr;
00182   URL _toURL;
00183   HdrHeap *_heap;
00184   
00185   // non-copyable, non-assignable
00186   UrlMappingContainer(const UrlMappingContainer &orig);
00187   UrlMappingContainer &operator =(const UrlMappingContainer &rhs);
00188 };
00189 
00190 #endif

Generated by  doxygen 1.7.1