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

UrlMappingPathIndex.cc

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 #include "UrlMappingPathIndex.h"
00024 
00025 UrlMappingPathIndex::~UrlMappingPathIndex()
00026 {
00027   for (UrlMappingGroup::iterator group_iter = m_tries.begin(); group_iter != m_tries.end(); ++group_iter)
00028     delete group_iter->second; // Delete the Trie
00029   m_tries.clear();
00030 }
00031 
00032 bool
00033 UrlMappingPathIndex::Insert(url_mapping *mapping)
00034 {
00035   int scheme_idx;
00036   int port = (mapping->fromURL).port_get();
00037   UrlMappingTrie *trie;
00038   int from_path_len;
00039   const char *from_path;
00040 
00041   trie = _GetTrie(&(mapping->fromURL), scheme_idx, port);
00042 
00043   if (!trie) {
00044     trie = new UrlMappingTrie();
00045     m_tries.insert(UrlMappingGroup::value_type(UrlMappingTrieKey(scheme_idx, port), trie));
00046     Debug("UrlMappingPathIndex::Insert", "Created new trie for scheme index, port combo <%d, %d>",
00047           scheme_idx, port);
00048   }
00049 
00050   from_path = mapping->fromURL.path_get(&from_path_len);
00051   if (!trie->Insert(from_path, mapping, mapping->getRank(), from_path_len)) {
00052     Error("Couldn't insert into trie!");
00053     return false;
00054   }
00055   Debug("UrlMappingPathIndex::Insert", "Inserted new element!");
00056   return true;
00057 }
00058 
00059 url_mapping *
00060 UrlMappingPathIndex::Search(URL *request_url, int request_port, bool normal_search /* = true */) const
00061 {
00062   url_mapping *retval = 0;
00063   int scheme_idx;
00064   UrlMappingTrie *trie;
00065   int path_len;
00066   const char *path;
00067 
00068   trie = _GetTrie(request_url, scheme_idx, request_port, normal_search);
00069 
00070   if (!trie) {
00071     Debug("UrlMappingPathIndex::Search", "No mappings exist for scheme index, port combo <%d, %d>",
00072           scheme_idx, request_port);
00073     goto lFail;
00074   }
00075 
00076   path = request_url->path_get(&path_len);
00077   if (!(retval = trie->Search(path, path_len))) {
00078     Debug("UrlMappingPathIndex::Search", "Couldn't find entry for url with path [%.*s]", path_len, path);
00079     goto lFail;
00080   }
00081   return retval;
00082 
00083 lFail:
00084   return 0;
00085 }
00086 
00087 void
00088 UrlMappingPathIndex::Print()
00089 {
00090   for (UrlMappingGroup::iterator group_iter = m_tries.begin(); group_iter != m_tries.end(); ++group_iter)
00091     group_iter->second->Print();
00092 }

Generated by  doxygen 1.7.1