You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2014/04/17 18:44:06 UTC
[07/50] git commit: TS-2693 Modify string ownership for
TSRedirectUrlSet()
TS-2693 Modify string ownership for TSRedirectUrlSet()
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/6cec1a20
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/6cec1a20
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/6cec1a20
Branch: refs/heads/5.0.x
Commit: 6cec1a2092a40ed5794a7b8a65c1e1d63fc228c2
Parents: d3e2d2c
Author: Leif Hedstrom <zw...@apache.org>
Authored: Fri Apr 4 11:20:34 2014 -0600
Committer: Leif Hedstrom <zw...@apache.org>
Committed: Thu Apr 10 06:50:21 2014 -0600
----------------------------------------------------------------------
plugins/experimental/custom_redirect/custom_redirect.cc | 6 ++++--
plugins/experimental/escalate/escalate.cc | 4 +---
proxy/InkAPI.cc | 7 +++----
proxy/api/ts/ts.h | 5 +----
proxy/http/HttpSM.cc | 4 ++--
proxy/http/HttpSM.h | 6 +++---
proxy/http/HttpTransact.cc | 1 +
7 files changed, 15 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/plugins/experimental/custom_redirect/custom_redirect.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/custom_redirect/custom_redirect.cc b/plugins/experimental/custom_redirect/custom_redirect.cc
index 5ccf8ef..075f712 100644
--- a/plugins/experimental/custom_redirect/custom_redirect.cc
+++ b/plugins/experimental/custom_redirect/custom_redirect.cc
@@ -71,9 +71,11 @@ handle_response (TSHttpTxn txnp, TSCont /* contp ATS_UNUSED */)
redirect_url_str = TSMimeHdrFieldValueStringGet (resp_bufp, resp_loc, redirect_url_loc, -1, &redirect_url_length);
if (redirect_url_str) {
if (redirect_url_length > 0) {
- TSRedirectUrlSet(txnp, redirect_url_str, redirect_url_length);
+ char* url = (char*)TSmalloc(redirect_url_length+1);
+
+ TSstrlcpy(url, redirect_url_str, redirect_url_length + 1);
+ TSRedirectUrlSet(txnp, url, redirect_url_length);
}
- //TSHandleStringRelease(resp_bufp, redirect_url_loc, redirect_url_str);
}
TSHandleMLocRelease (resp_bufp, resp_loc, redirect_url_loc);
}
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/plugins/experimental/escalate/escalate.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/escalate/escalate.cc b/plugins/experimental/escalate/escalate.cc
index d013b27..d57003a 100644
--- a/plugins/experimental/escalate/escalate.cc
+++ b/plugins/experimental/escalate/escalate.cc
@@ -95,9 +95,7 @@ EscalateResponse(TSCont cont, TSEvent event, void* edata)
url_str = TSUrlStringGet(request, url, &url_len);
TSDebug(PLUGIN_NAME, "Setting new URL to %.*s", url_len, url_str);
- TSRedirectUrlSet(txn, url_str, url_len);
-
- TSfree(static_cast<void*>(url_str));
+ TSRedirectUrlSet(txn, url_str, url_len); // Transfers ownership
}
// Release the response MLoc
TSHandleMLocRelease(request, TS_NULL_MLOC, req_hdr);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 68d31d0..e4a0b9c 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -7129,13 +7129,12 @@ TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len)
HttpSM *sm = (HttpSM*) txnp;
if (sm->redirect_url != NULL) {
- ats_free(sm->redirect_url);
+ ats_free((void*)sm->redirect_url);
sm->redirect_url = NULL;
sm->redirect_url_len = 0;
}
- sm->redirect_url = (char*)ats_malloc(url_len + 1);
- ink_strlcpy(sm->redirect_url, (char*)url, url_len + 1);
+ sm->redirect_url = url;
sm->redirect_url_len = url_len;
sm->enable_redirection = true;
}
@@ -7148,7 +7147,7 @@ TSRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr)
HttpSM *sm = (HttpSM*)txnp;
*url_len_ptr = sm->redirect_url_len;
- return (const char*)sm->redirect_url;
+ return sm->redirect_url;
}
char*
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/proxy/api/ts/ts.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h
index 367317b..99098da 100644
--- a/proxy/api/ts/ts.h
+++ b/proxy/api/ts/ts.h
@@ -1456,7 +1456,6 @@ extern "C"
*/
tsapi void TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event);
tsapi TSReturnCode TSHttpCacheReenable(TSCacheTxn txnp, const TSEvent event, const void* data, const uint64_t size);
- tsapi TSReturnCode TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on);
tsapi void TSHttpTxnArgSet(TSHttpTxn txnp, int arg_idx, void* arg);
tsapi void* TSHttpTxnArgGet(TSHttpTxn txnp, int arg_idx);
@@ -2228,9 +2227,7 @@ extern "C"
tsapi TSReturnCode TSHttpTxnConfigFind(const char* name, int length, TSOverridableConfigKey* conf, TSRecordDataType* type);
- /*
- It's unclear if these actually function properly still.
- */
+ tsapi TSReturnCode TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on);
tsapi void TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len);
tsapi const char* TSRedirectUrlGet(TSHttpTxn txnp, int* url_len_ptr);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index fc4f9bc..f1fafff 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -6457,7 +6457,7 @@ HttpSM::kill_this()
HTTP_SM_SET_DEFAULT_HANDLER(NULL);
if (redirect_url != NULL) {
- ats_free(redirect_url);
+ ats_free((void*)redirect_url);
redirect_url = NULL;
redirect_url_len = 0;
}
@@ -7295,7 +7295,7 @@ HttpSM::do_redirect()
if (redirect_url != NULL) {
redirect_request(redirect_url, redirect_url_len);
- ats_free(redirect_url);
+ ats_free((void*)redirect_url);
redirect_url = NULL;
redirect_url_len = 0;
HTTP_INCREMENT_DYN_STAT(http_total_x_redirect_stat);
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/proxy/http/HttpSM.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h
index 0a7b116..a04742d 100644
--- a/proxy/http/HttpSM.h
+++ b/proxy/http/HttpSM.h
@@ -270,12 +270,12 @@ public:
//YTS Team, yamsat Plugin
bool enable_redirection; //To check if redirection is enabled
- char *redirect_url; //url for force redirect (provide users a functionality to redirect to another url when needed)
+ const char *redirect_url; //url for force redirect (provide users a functionality to redirect to another url when needed)
int redirect_url_len;
int redirection_tries; //To monitor number of redirections
- int64_t transfered_bytes; //Added to calculate POST data
+ int64_t transfered_bytes; //Added to calculate POST data
bool post_failed; //Added to identify post failure
- bool debug_on; //Transaction specific debug flag
+ bool debug_on; //Transaction specific debug flag
// Tunneling request to plugin
HttpPluginTunnel_t plugin_tunnel_type;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/6cec1a20/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index c5ee223..aa671fa 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -900,6 +900,7 @@ HttpTransact::EndRemapRequest(State* s)
char *redirect_url = s->http_config_param->reverse_proxy_no_host_redirect;
int redirect_url_len = s->http_config_param->reverse_proxy_no_host_redirect_len;
+
SET_VIA_STRING(VIA_DETAIL_TUNNEL, VIA_DETAIL_TUNNEL_NO_FORWARD);
if (redirect_url) { /* there is a redirect url */
build_error_response(s, HTTP_STATUS_MOVED_TEMPORARILY, "Redirect For Explanation", "request#no_host",