TS-2707 Migrate TSRedirectUrlSet/Get to TSHttpTxnRedirectUrlSet/Get

1. We leave TSRedirectUrlSet() / Get() as is (as far as functionality
goes). This makes this proposal both API and binary compatible with v4.2.x.

2. We mark them as Deprecated, removing the old API in 6.0.0.

3. We add TSHttpTxnRedirectSet() / Get() , with the new string ownership as
described above. This naming convention is much better aligned with the rest
of our APIs.

I left the URL string lengths as int type for now, we’ll discuss at the Summit
about TS-2514, changing our usage of “int” to more appropriate size_t etc.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/a7b7d5f9
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/a7b7d5f9
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/a7b7d5f9

Branch: refs/heads/5.0.x
Commit: a7b7d5f98cfc94ba95ea572cadc5d14f8ecdf153
Parents: 98c5819
Author: Leif Hedstrom <[email protected]>
Authored: Tue Apr 8 21:11:48 2014 -0600
Committer: Leif Hedstrom <[email protected]>
Committed: Thu Apr 10 06:50:21 2014 -0600

----------------------------------------------------------------------
 .../custom_redirect/custom_redirect.cc          |  2 +-
 plugins/experimental/escalate/escalate.cc       |  4 +-
 proxy/InkAPI.cc                                 | 40 ++++++++++++++++++--
 proxy/api/ts/ts.h                               | 11 ++++--
 4 files changed, 48 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a7b7d5f9/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 075f712..5af9a83 100644
--- a/plugins/experimental/custom_redirect/custom_redirect.cc
+++ b/plugins/experimental/custom_redirect/custom_redirect.cc
@@ -74,7 +74,7 @@ handle_response (TSHttpTxn txnp, TSCont /* contp ATS_UNUSED 
*/)
                               char* url = 
(char*)TSmalloc(redirect_url_length+1);
 
                               TSstrlcpy(url, redirect_url_str, 
redirect_url_length + 1);
-                              TSRedirectUrlSet(txnp, url, redirect_url_length);
+                              TSHttpTxnRedirectUrlSet(txnp, url, 
redirect_url_length);
                             }
                         }
                         TSHandleMLocRelease (resp_bufp, resp_loc, 
redirect_url_loc);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a7b7d5f9/plugins/experimental/escalate/escalate.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/escalate/escalate.cc 
b/plugins/experimental/escalate/escalate.cc
index 05a8234..2f71041 100644
--- a/plugins/experimental/escalate/escalate.cc
+++ b/plugins/experimental/escalate/escalate.cc
@@ -70,7 +70,7 @@ EscalateResponse(TSCont cont, TSEvent event, void* edata)
 
   // First, we need the server response ...
   if (TS_SUCCESS == TSHttpTxnServerRespGet(txn, &response, &resp_hdr)) {
-    int tries = TSRedirectRetriesGet(txn);
+    int tries = TSHttpTxnRedirectRetries(txn);
 
     TSDebug(PLUGIN_NAME, "This is try %d", tries);
     if (0 == tries) { // ToDo: Future support for more than one retry-URL
@@ -98,7 +98,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); // Transfers ownership
+            TSHttpTxnRedirectUrlSet(txn, url_str, url_len); // Transfers 
ownership
           }
           // Release the request MLoc
         TSHandleMLocRelease(request, TS_NULL_MLOC, req_hdr);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a7b7d5f9/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 92c37fc..cc4c4dd 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -7121,7 +7121,7 @@ TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on)
 
 // this function should be called at TS_EVENT_HTTP_READ_RESPONSE_HDR
 void
-TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len)
+TSHttpTxnRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len)
 {
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
   sdk_assert(sdk_sanity_check_null_ptr((void*)url) == TS_SUCCESS);
@@ -7139,8 +7139,35 @@ TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const 
int url_len)
   sm->enable_redirection = true;
 }
 
+// Deprecated, remove for v6.0.0
+void
+TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len)
+{
+  sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+  sdk_assert(sdk_sanity_check_null_ptr((void*)url) == TS_SUCCESS);
+
+  HttpSM *sm = (HttpSM*) txnp;
+
+  if (sm->redirect_url != NULL) {
+    ats_free(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, url, url_len + 1);
+  sm->redirect_url_len = url_len;
+  // have to turn redirection on for this transaction if user wants to 
redirect to another URL
+  if (sm->enable_redirection == false) {
+    sm->enable_redirection = true;
+    // max-out "redirection_tries" to avoid the regular redirection being 
turned on in
+    // this transaction improperly. This variable doesn't affect the 
custom-redirection
+    sm->redirection_tries = HttpConfig::m_master.number_of_redirections;
+  }
+}
+
 const char*
-TSRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr)
+TSHttpTxnRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr)
 {
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
 
@@ -7150,8 +7177,15 @@ TSRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr)
   return sm->redirect_url;
 }
 
+// Deprecated, remove for v6.0.0
+const char*
+TSRedirectUrlGet(TSHttpTxn txnp, int *url_len_ptr)
+{
+  return TSHttpTxnRedirectUrlGet(txnp, url_len_ptr);
+}
+
 int
-TSRedirectRetriesGet(TSHttpTxn txnp)
+TSHttpTxnRedirectRetries(TSHttpTxn txnp)
 {
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/a7b7d5f9/proxy/api/ts/ts.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h
index eaafda1..8279155 100644
--- a/proxy/api/ts/ts.h
+++ b/proxy/api/ts/ts.h
@@ -2237,6 +2237,7 @@ extern "C"
      @return @c TS_SUCCESS if it succeeded
   */
   tsapi TSReturnCode TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on);
+
   /**
      This is a generalization of the TSHttpTxnFollowRedirect(), but gives finer
      control over the behavior. Instead of using the Location: header for the 
new
@@ -2251,7 +2252,9 @@ extern "C"
      @param url  a heap allocated string with the URL
      @param url_len the length of the URL
   */
-  tsapi void TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int 
url_len);
+  tsapi void TSHttpTxnRedirectUrlSet(TSHttpTxn txnp, const char* url, const 
int url_len);
+  tsapi TS_DEPRECATED void TSRedirectUrlSet(TSHttpTxn txnp, const char* url, 
const int url_len);
+
   /**
      Return the current (if set) redirection URL string. This is still owned 
by the
      core, and must not be free'd.
@@ -2261,7 +2264,9 @@ extern "C"
 
      @return the url string
   */
-  tsapi const char* TSRedirectUrlGet(TSHttpTxn txnp, int* url_len_ptr);
+  tsapi const char* TSHttpTxnRedirectUrlGet(TSHttpTxn txnp, int* url_len_ptr);
+  tsapi TS_DEPRECATED const char* TSRedirectUrlGet(TSHttpTxn txnp, int* 
url_len_ptr);
+
   /**
      Return the number of redirection retries we have done. This starts off
      at zero, and can be used to select different URLs based on which attempt 
this
@@ -2272,7 +2277,7 @@ extern "C"
 
      @return the redirect try count
   */
-  tsapi int TSRedirectRetriesGet(TSHttpTxn txnp);
+  tsapi int TSHttpTxnRedirectRetries(TSHttpTxn txnp);
 
   /* Get current HTTP connection stats */
   tsapi int TSHttpCurrentClientConnectionsGet(void);

Reply via email to