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

UrlMappingPathIndex.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 #ifndef _URL_MAPPING_PATH_INDEX_H
00024 #define _URL_MAPPING_PATH_INDEX_H
00025 
00026 #include "libts.h"
00027 #undef std  // FIXME: remove dependancy on the STL
00028 #include <map>
00029 
00030 #include "URL.h"
00031 #include "UrlMapping.h"
00032 #include "Trie.h"
00033 
00034 class UrlMappingPathIndex
00035 {
00036 public:
00037   UrlMappingPathIndex()
00038   { }
00039 
00040   virtual ~UrlMappingPathIndex();
00041   bool Insert(url_mapping *mapping);
00042   url_mapping* Search(URL *request_url, int request_port, bool normal_search = true) const;
00043   void Print();
00044 
00045 private:
00046   typedef Trie<url_mapping> UrlMappingTrie;
00047 
00048   struct UrlMappingTrieKey {
00049     int scheme_wks_idx;
00050     int port;
00051 
00052     UrlMappingTrieKey(int idx, int p)
00053       : scheme_wks_idx(idx), port(p)
00054     { }
00055     
00056     bool operator <(const UrlMappingTrieKey &rhs) const {
00057       if (scheme_wks_idx == rhs.scheme_wks_idx) {
00058         return (port < rhs.port);
00059       }
00060       return (scheme_wks_idx < rhs.scheme_wks_idx);
00061     }
00062   };
00063 
00064   typedef std::map<UrlMappingTrieKey, UrlMappingTrie *> UrlMappingGroup;
00065   UrlMappingGroup m_tries;
00066 
00067   // make copy-constructor and assignment operator private
00068   // till we properly implement them
00069   UrlMappingPathIndex(const UrlMappingPathIndex & /* rhs ATS_UNUSED */) { };
00070   UrlMappingPathIndex &operator =(const UrlMappingPathIndex & /* rhs ATS_UNUSED */) { return *this; }
00071 
00072   inline UrlMappingTrie *
00073   _GetTrie(URL *url, int &idx, int port, bool search = true) const {
00074     idx = url->scheme_get_wksidx();
00075     // If the scheme is empty (e.g. because of a CONNECT method), guess it
00076     // based on port
00077     if (idx == -1) {
00078         if (port == 80) {
00079             idx = URL_WKSIDX_HTTP;
00080         } else {
00081             idx = URL_WKSIDX_HTTPS;
00082         }
00083     }
00084     UrlMappingGroup::const_iterator group_iter;
00085     if (search) { // normal search
00086       group_iter = m_tries.find(UrlMappingTrieKey(idx, port));
00087     } else { // return the first trie arbitrarily
00088       Debug("UrlMappingPathIndex::_GetTrie", "Not performing search; will return first available trie");
00089       group_iter = m_tries.begin();
00090     }
00091     if (group_iter != m_tries.end()) {
00092       return group_iter->second;
00093     }
00094     return 0;
00095   }
00096 };
00097 
00098 #endif // _URL_MAPPING_PATH_INDEX_H

Generated by  doxygen 1.7.1