You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2018/10/19 16:18:21 UTC
[trafficserver] branch master updated: TCL: Rmove TCL dependency
from UrlRewrite
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 08bbf91 TCL: Rmove TCL dependency from UrlRewrite
08bbf91 is described below
commit 08bbf911cb155d3dd635fb60578bb31da7bf2b8d
Author: Xavier Chi <ch...@gmail.com>
AuthorDate: Thu Oct 18 11:39:40 2018 -0500
TCL: Rmove TCL dependency from UrlRewrite
---
proxy/ReverseProxy.h | 1 -
proxy/http/remap/UrlRewrite.cc | 83 +++++++++++++++++++-----------------------
proxy/http/remap/UrlRewrite.h | 13 +++++--
3 files changed, 47 insertions(+), 50 deletions(-)
diff --git a/proxy/ReverseProxy.h b/proxy/ReverseProxy.h
index 8839627..0ba5bc3 100644
--- a/proxy/ReverseProxy.h
+++ b/proxy/ReverseProxy.h
@@ -34,7 +34,6 @@
#include "records/P_RecProcess.h"
-#include "tscore/ink_hash_table.h"
#include "tscore/ink_defs.h"
#include "HttpTransact.h"
#include "RemapPluginInfo.h"
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index 8f2577b..3f3d0ed 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -24,7 +24,6 @@
#include "UrlRewrite.h"
#include "ProxyConfig.h"
#include "ReverseProxy.h"
-#include "UrlMappingPathIndex.h"
#include "RemapConfig.h"
#include "tscore/I_Layout.h"
#include "HttpSM.h"
@@ -67,9 +66,6 @@ UrlRewrite::UrlRewrite()
{
ats_scoped_str config_file_path;
- forward_mappings.hash_lookup = reverse_mappings.hash_lookup = permanent_redirects.hash_lookup = temporary_redirects.hash_lookup =
- forward_mappings_with_recv_port.hash_lookup = nullptr;
-
config_file_path = RecConfigReadConfigPath("proxy.config.url_remap.filename", "remap.config");
if (!config_file_path) {
pmgmt->signalManager(MGMT_SIGNAL_CONFIG_ERROR, "Unable to find proxy.config.url_remap.filename");
@@ -156,20 +152,12 @@ UrlRewrite::SetupBackdoorMapping()
/** Deallocated a hash table and all the url_mappings in it. */
void
-UrlRewrite::_destroyTable(InkHashTable *h_table)
+UrlRewrite::_destroyTable(std::unique_ptr<URLTable> &h_table)
{
- InkHashTableEntry *ht_entry;
- InkHashTableIteratorState ht_iter;
- UrlMappingPathIndex *item;
-
- if (h_table != nullptr) { // Iterate over the hash tabel freeing up the all the url_mappings
- // contained with in
- for (ht_entry = ink_hash_table_iterator_first(h_table, &ht_iter); ht_entry != nullptr;) {
- item = (UrlMappingPathIndex *)ink_hash_table_entry_value(h_table, ht_entry);
- delete item;
- ht_entry = ink_hash_table_iterator_next(h_table, &ht_iter);
+ if (h_table) {
+ for (auto it = h_table->begin(); it != h_table->end(); ++it) {
+ delete it->second;
}
- ink_hash_table_destroy(h_table);
}
}
@@ -205,15 +193,9 @@ UrlRewrite::Print()
void
UrlRewrite::PrintStore(MappingsStore &store)
{
- if (store.hash_lookup != nullptr) {
- InkHashTableEntry *ht_entry;
- InkHashTableIteratorState ht_iter;
- UrlMappingPathIndex *value;
-
- for (ht_entry = ink_hash_table_iterator_first(store.hash_lookup, &ht_iter); ht_entry != nullptr;) {
- value = (UrlMappingPathIndex *)ink_hash_table_entry_value(store.hash_lookup, ht_entry);
- value->Print();
- ht_entry = ink_hash_table_iterator_next(store.hash_lookup, &ht_iter);
+ if (store.hash_lookup) {
+ for (auto it = store.hash_lookup->begin(); it != store.hash_lookup->end(); ++it) {
+ it->second->Print();
}
}
@@ -229,13 +211,20 @@ UrlRewrite::PrintStore(MappingsStore &store)
*/
url_mapping *
-UrlRewrite::_tableLookup(InkHashTable *h_table, URL *request_url, int request_port, char *request_host, int request_host_len)
+UrlRewrite::_tableLookup(std::unique_ptr<URLTable> &h_table, URL *request_url, int request_port, char *request_host,
+ int request_host_len)
{
- UrlMappingPathIndex *ht_entry;
- url_mapping *um = nullptr;
- int ht_result;
+ if (!h_table) {
+ h_table.reset(new URLTable);
+ }
+ UrlMappingPathIndex *ht_entry = nullptr;
+ url_mapping *um = nullptr;
+ int ht_result = 0;
- ht_result = ink_hash_table_lookup(h_table, request_host, (void **)&ht_entry);
+ if (auto it = h_table->find(request_host); it != h_table->end()) {
+ ht_result = 1;
+ ht_entry = it->second;
+ }
if (likely(ht_result && ht_entry)) {
// for empty host don't do a normal search, get a mapping arbitrarily
@@ -686,11 +675,11 @@ UrlRewrite::BuildTable(const char *path)
ink_assert(num_rules_redirect_temporary == 0);
ink_assert(num_rules_forward_with_recv_port == 0);
- forward_mappings.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
- reverse_mappings.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
- permanent_redirects.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
- temporary_redirects.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
- forward_mappings_with_recv_port.hash_lookup = ink_hash_table_create(InkHashTableKeyType_String);
+ forward_mappings.hash_lookup.reset(new URLTable);
+ reverse_mappings.hash_lookup.reset(new URLTable);
+ permanent_redirects.hash_lookup.reset(new URLTable);
+ temporary_redirects.hash_lookup.reset(new URLTable);
+ forward_mappings_with_recv_port.hash_lookup.reset(new URLTable);
if (!remap_parse_config(path, this)) {
// XXX handle file reload error
@@ -699,27 +688,27 @@ UrlRewrite::BuildTable(const char *path)
// Destroy unused tables
if (num_rules_forward == 0) {
- forward_mappings.hash_lookup = ink_hash_table_destroy(forward_mappings.hash_lookup);
+ forward_mappings.hash_lookup.reset(nullptr);
} else {
- if (ink_hash_table_isbound(forward_mappings.hash_lookup, "")) {
+ if (forward_mappings.hash_lookup->find("") != forward_mappings.hash_lookup->end()) {
nohost_rules = 1;
}
}
if (num_rules_reverse == 0) {
- reverse_mappings.hash_lookup = ink_hash_table_destroy(reverse_mappings.hash_lookup);
+ reverse_mappings.hash_lookup.reset(nullptr);
}
if (num_rules_redirect_permanent == 0) {
- permanent_redirects.hash_lookup = ink_hash_table_destroy(permanent_redirects.hash_lookup);
+ permanent_redirects.hash_lookup.reset(nullptr);
}
if (num_rules_redirect_temporary == 0) {
- temporary_redirects.hash_lookup = ink_hash_table_destroy(temporary_redirects.hash_lookup);
+ temporary_redirects.hash_lookup.reset(nullptr);
}
if (num_rules_forward_with_recv_port == 0) {
- forward_mappings_with_recv_port.hash_lookup = ink_hash_table_destroy(forward_mappings_with_recv_port.hash_lookup);
+ forward_mappings_with_recv_port.hash_lookup.reset(nullptr);
}
return 0;
@@ -731,8 +720,11 @@ UrlRewrite::BuildTable(const char *path)
*/
bool
-UrlRewrite::TableInsert(InkHashTable *h_table, url_mapping *mapping, const char *src_host)
+UrlRewrite::TableInsert(std::unique_ptr<URLTable> &h_table, url_mapping *mapping, const char *src_host)
{
+ if (!h_table) {
+ h_table.reset(new URLTable);
+ }
char src_host_tmp_buf[1];
UrlMappingPathIndex *ht_contents;
@@ -741,16 +733,17 @@ UrlRewrite::TableInsert(InkHashTable *h_table, url_mapping *mapping, const char
src_host_tmp_buf[0] = 0;
}
// Insert the new_mapping into hash table
- if (ink_hash_table_lookup(h_table, src_host, (void **)&ht_contents)) {
+ if (auto it = h_table->find(src_host); it != h_table->end()) {
+ ht_contents = it->second;
// There is already a path index for this host
- if (ht_contents == nullptr) {
+ if (it->second == nullptr) {
// why should this happen?
Warning("Found entry cannot be null!");
return false;
}
} else {
ht_contents = new UrlMappingPathIndex();
- ink_hash_table_insert(h_table, src_host, ht_contents);
+ h_table->emplace(src_host, ht_contents);
}
if (!ht_contents->Insert(mapping)) {
Warning("Could not insert new mapping");
diff --git a/proxy/http/remap/UrlRewrite.h b/proxy/http/remap/UrlRewrite.h
index 016ecde..dafb1d3 100644
--- a/proxy/http/remap/UrlRewrite.h
+++ b/proxy/http/remap/UrlRewrite.h
@@ -25,9 +25,12 @@
#include "tscore/ink_config.h"
#include "UrlMapping.h"
+#include "UrlMappingPathIndex.h"
#include "HttpTransact.h"
#include "tscore/Regex.h"
+#include <memory>
+
#define URL_REMAP_FILTER_NONE 0x00000000
#define URL_REMAP_FILTER_REFERER 0x00000001 /* enable "referer" header validation */
#define URL_REMAP_FILTER_REDIRECT_FMT 0x00010000 /* enable redirect URL formatting */
@@ -53,6 +56,7 @@ enum mapping_type {
class UrlRewrite : public RefCountObj
{
public:
+ using URLTable = std::unordered_map<std::string, UrlMappingPathIndex *>;
UrlRewrite();
~UrlRewrite() override;
@@ -114,7 +118,7 @@ public:
typedef Queue<RegexMapping> RegexMappingList;
struct MappingsStore {
- InkHashTable *hash_lookup;
+ std::unique_ptr<URLTable> hash_lookup;
RegexMappingList regex_list;
bool
empty()
@@ -138,7 +142,7 @@ public:
bool InsertMapping(mapping_type maptype, url_mapping *new_mapping, RegexMapping *reg_map, const char *src_host,
bool is_cur_mapping_regex);
- bool TableInsert(InkHashTable *h_table, url_mapping *mapping, const char *src_host);
+ bool TableInsert(std::unique_ptr<URLTable> &h_table, url_mapping *mapping, const char *src_host);
MappingsStore forward_mappings;
MappingsStore reverse_mappings;
@@ -195,12 +199,13 @@ private:
bool _mappingLookup(MappingsStore &mappings, URL *request_url, int request_port, const char *request_host, int request_host_len,
UrlMappingContainer &mapping_container);
- url_mapping *_tableLookup(InkHashTable *h_table, URL *request_url, int request_port, char *request_host, int request_host_len);
+ url_mapping *_tableLookup(std::unique_ptr<URLTable> &h_table, URL *request_url, int request_port, char *request_host,
+ int request_host_len);
bool _regexMappingLookup(RegexMappingList ®ex_mappings, URL *request_url, int request_port, const char *request_host,
int request_host_len, int rank_ceiling, UrlMappingContainer &mapping_container);
int _expandSubstitutions(int *matches_info, const RegexMapping *reg_map, const char *matched_string, char *dest_buf,
int dest_buf_size);
- void _destroyTable(InkHashTable *h_table);
+ void _destroyTable(std::unique_ptr<URLTable> &h_table);
void _destroyList(RegexMappingList ®exes);
inline bool _addToStore(MappingsStore &store, url_mapping *new_mapping, RegexMapping *reg_map, const char *src_host,
bool is_cur_mapping_regex, int &count);