+1 Can we get the API exposed for plugins also?
----- Original Message ----- > TS-2323: use the Layout API to find remap.config > > > Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo > Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/238e3396 > Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/238e3396 > Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/238e3396 > > Branch: refs/heads/master > Commit: 238e3396b591be810728ed316c53354560e14be2 > Parents: 90f923e > Author: James Peach <jpe...@apache.org> > Authored: Fri Nov 1 10:45:52 2013 -0700 > Committer: James Peach <jpe...@apache.org> > Committed: Tue Nov 5 16:46:39 2013 -0800 > > ---------------------------------------------------------------------- > proxy/ReverseProxy.cc | 4 ++-- > proxy/http/remap/UrlRewrite.cc | 30 +++++++++++++----------------- > proxy/http/remap/UrlRewrite.h | 7 +++---- > 3 files changed, 18 insertions(+), 23 deletions(-) > ---------------------------------------------------------------------- > > > http://git-wip-us.apache.org/repos/asf/trafficserver/blob/238e3396/proxy/ReverseProxy.cc > ---------------------------------------------------------------------- > diff --git a/proxy/ReverseProxy.cc b/proxy/ReverseProxy.cc > index 4b4b578..51c3664 100644 > --- a/proxy/ReverseProxy.cc > +++ b/proxy/ReverseProxy.cc > @@ -74,7 +74,7 @@ init_reverse_proxy() > { > ink_assert(rewrite_table == NULL); > reconfig_mutex = new_ProxyMutex(); > - rewrite_table = NEW(new UrlRewrite("proxy.config.url_remap.filename")); > + rewrite_table = NEW(new UrlRewrite()); > > if (!rewrite_table->is_valid()) { > Warning("Can not load the remap table, exiting out!"); > @@ -178,7 +178,7 @@ reloadUrlRewrite() > UrlRewrite *newTable; > > Debug("url_rewrite", "remap.config updated, reloading..."); > - newTable = new UrlRewrite("proxy.config.url_remap.filename"); > + newTable = NEW(new UrlRewrite()); > if (newTable->is_valid()) { > eventProcessor.schedule_in(new UR_FreerContinuation(rewrite_table), > URL_REWRITE_TIMEOUT, ET_TASK); > Debug("url_rewrite", "remap.config done reloading!"); > > http://git-wip-us.apache.org/repos/asf/trafficserver/blob/238e3396/proxy/http/remap/UrlRewrite.cc > ---------------------------------------------------------------------- > diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc > index 32c6de6..a6f1c23 100644 > --- a/proxy/http/remap/UrlRewrite.cc > +++ b/proxy/http/remap/UrlRewrite.cc > @@ -33,6 +33,7 @@ > #include "api/ts/remap.h" > #include "UrlMappingPathIndex.h" > #include "RemapConfig.h" > +#include "I_Layout.h" > > #include "ink_string.h" > > @@ -60,9 +61,9 @@ SetHomePageRedirectFlag(url_mapping *new_mapping, URL > &new_to_url) > // > // CTOR / DTOR for the UrlRewrite class. > // > -UrlRewrite::UrlRewrite(const char *file_var_in) > +UrlRewrite::UrlRewrite() > : nohost_rules(0), reverse_proxy(0), backdoor_enabled(0), > - mgmt_autoconf_port(0), default_to_pac(0), default_to_pac_port(0), > file_var(NULL), ts_name(NULL), > + mgmt_autoconf_port(0), default_to_pac(0), default_to_pac_port(0), > ts_name(NULL), > http_default_redirect_url(NULL), num_rules_forward(0), > num_rules_reverse(0), num_rules_redirect_permanent(0), > num_rules_redirect_temporary(0), num_rules_forward_with_recv_port(0), > _valid(false) > { > @@ -71,14 +72,10 @@ UrlRewrite::UrlRewrite(const char *file_var_in) > permanent_redirects.hash_lookup = temporary_redirects.hash_lookup = > forward_mappings_with_recv_port.hash_lookup = NULL; > > - char *config_file = NULL; > - > - ink_assert(file_var_in != NULL); > - this->file_var = ats_strdup(file_var_in); > - config_file_path[0] = '\0'; > - > - REC_ReadConfigStringAlloc(config_file, file_var_in); > + char * config_file = NULL; > + char * config_file_path = NULL; > > + REC_ReadConfigStringAlloc(config_file, "proxy.config.url_remap.filename"); > if (config_file == NULL) { > pmgmt->signalManager(MGMT_SIGNAL_CONFIG_ERROR, "Unable to find > proxy.config.url_remap.filename"); > Warning("%s Unable to locate remap.config. No remappings in effect", > modulePrefix); > @@ -108,12 +105,9 @@ UrlRewrite::UrlRewrite(const char *file_var_in) > REC_ReadConfigInteger(url_remap_mode, > "proxy.config.url_remap.url_remap_mode"); > REC_ReadConfigInteger(backdoor_enabled, > "proxy.config.url_remap.handle_backdoor_urls"); > > - ink_strlcpy(config_file_path, system_config_directory, > sizeof(config_file_path)); > - ink_strlcat(config_file_path, "/", sizeof(config_file_path)); > - ink_strlcat(config_file_path, config_file, sizeof(config_file_path)); > - ats_free(config_file); > + config_file_path = Layout::relative_to(Layout::get()->sysconfdir, > config_file); > > - if (0 == this->BuildTable()) { > + if (0 == this->BuildTable(config_file_path)) { > _valid = true; > if (is_debug_tag_set("url_rewrite")) { > Print(); > @@ -121,11 +115,13 @@ UrlRewrite::UrlRewrite(const char *file_var_in) > } else { > Warning("something failed during BuildTable() -- check your remap > plugins!"); > } > + > + ats_free(config_file_path); > + ats_free(config_file); > } > > UrlRewrite::~UrlRewrite() > { > - ats_free(this->file_var); > ats_free(this->ts_name); > ats_free(this->http_default_redirect_url); > > @@ -676,7 +672,7 @@ UrlRewrite::InsertForwardMapping(mapping_type maptype, > url_mapping * mapping, co > > */ > int > -UrlRewrite::BuildTable() > +UrlRewrite::BuildTable(const char * path) > { > BUILD_TABLE_INFO bti; > url_mapping * new_mapping = NULL; > @@ -699,7 +695,7 @@ UrlRewrite::BuildTable() > temporary_redirects.hash_lookup = > ink_hash_table_create(InkHashTableKeyType_String); > forward_mappings_with_recv_port.hash_lookup = > ink_hash_table_create(InkHashTableKeyType_String); > > - if (!remap_parse_config(config_file_path, this)) { > + if (!remap_parse_config(path, this)) { > // XXX handle file reload error > return 3; > } > > http://git-wip-us.apache.org/repos/asf/trafficserver/blob/238e3396/proxy/http/remap/UrlRewrite.h > ---------------------------------------------------------------------- > diff --git a/proxy/http/remap/UrlRewrite.h b/proxy/http/remap/UrlRewrite.h > index 35788f9..8785a1a 100644 > --- a/proxy/http/remap/UrlRewrite.h > +++ b/proxy/http/remap/UrlRewrite.h > @@ -52,9 +52,10 @@ enum mapping_type > class UrlRewrite > { > public: > - UrlRewrite(const char *file_var_in); > + UrlRewrite(); > ~UrlRewrite(); > - int BuildTable(); > + > + int BuildTable(const char * path); > mapping_type Remap_redirect(HTTPHdr * request_header, URL *redirect_url); > bool ReverseMap(HTTPHdr *response_header); > void SetReverseFlag(int flag); > @@ -160,8 +161,6 @@ public: > int default_to_pac; > int default_to_pac_port; > > - char config_file_path[PATH_NAME_MAX]; > - char *file_var; > char *ts_name; // Used to send redirects when no host info > > char *http_default_redirect_url; // Used if redirect in "referer" > filtering was not defined properly > > -- Igor Galić Tel: +43 (0) 664 886 22 883 Mail: i.ga...@brainsware.org URL: http://brainsware.org/ GPG: 8716 7A9F 989B ABD5 100F 4008 F266 55D6 2998 1641