This is an automated email from the ASF dual-hosted git repository.

amc 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 09fdc21  Add TSAPI functions TSRemapFrom/ToUrlGet().  Allow TSMBuffer 
pointer passed to TSUrlStringGet() to be null.
09fdc21 is described below

commit 09fdc21fda98eda0be44dbe36569c6d97faf6583
Author: Walt Karas <wka...@yahoo-inc.com>
AuthorDate: Wed Jan 31 17:33:07 2018 +0000

    Add TSAPI functions TSRemapFrom/ToUrlGet().  Allow TSMBuffer pointer passed 
to TSUrlStringGet() to be null.
---
 .../api/functions/TSRemapFromToUrlGet.en.rst       | 40 +++++++++++++++++++
 .../api/functions/TSUrlStringGet.en.rst            |  2 +-
 proxy/InkAPI.cc                                    | 45 +++++++++++++++++++++-
 proxy/api/ts/ts.h                                  | 12 ++++++
 4 files changed, 97 insertions(+), 2 deletions(-)

diff --git a/doc/developer-guide/api/functions/TSRemapFromToUrlGet.en.rst 
b/doc/developer-guide/api/functions/TSRemapFromToUrlGet.en.rst
new file mode 100644
index 0000000..75c23e9
--- /dev/null
+++ b/doc/developer-guide/api/functions/TSRemapFromToUrlGet.en.rst
@@ -0,0 +1,40 @@
+.. Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed
+   with this work for additional information regarding copyright
+   ownership.  The ASF licenses this file to you under the Apache
+   License, Version 2.0 (the "License"); you may not use this file
+   except in compliance with the License.  You may obtain a copy of
+   the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+   implied.  See the License for the specific language governing
+   permissions and limitations under the License.
+
+.. include:: ../../../common.defs
+
+.. default-domain:: c
+
+TSRemapFrom/ToUrlGet
+********************
+
+Synopsis
+========
+
+`#include <ts/ts.h>`
+
+.. function:: TSReturnCode TSRemapFromUrlGet(TSHttpTxn txnp, TSMLoc * urlLocp)
+.. function:: TSReturnCode TSRemapToUrlGet(TSHttpTxn txnp, TSMLoc * urlLocp)
+
+Description
+===========
+
+These functions are useful for transactions where the URL is remapped, due to 
matching a line in :file:`remap.config`.
+:func:`TSRemapFromUrlGet` returns the *from* URL in the matching line in 
:file:`remap.config`.
+:func:`TSRemapToUrlGet` returns the *to* URL in the matching line in 
:file:`remap.config`.
+This info is available at or after the :c:data:`TS_HTTP_POST_REMAP_HOOK` hook. 
 If the function returns
+:data:`TS_SUCCESS`, the location of the URL is put into the variable pointed 
to by :arg:`urlLocp`.  On error, the function
+returns :data:`TS_ERROR`.
diff --git a/doc/developer-guide/api/functions/TSUrlStringGet.en.rst 
b/doc/developer-guide/api/functions/TSUrlStringGet.en.rst
index a472e40..6da5d0b 100644
--- a/doc/developer-guide/api/functions/TSUrlStringGet.en.rst
+++ b/doc/developer-guide/api/functions/TSUrlStringGet.en.rst
@@ -44,7 +44,7 @@ and retrieve or modify parts of URLs, such as their host, 
port or scheme
 information.
 
 :func:`TSUrlStringGet` constructs a string representation of the URL located
-at :arg:`offset` within the marshal buffer :arg:`bufp`.
+at :arg:`offset` within the marshal buffer :arg:`bufp`.  (However :arg:`bufp` 
is actually superfluous and may be null.)
 :func:`TSUrlStringGet` stores the length of the allocated string in the
 parameter :arg:`length`. This is the same length that :func:`TSUrlLengthGet`
 returns. The returned string is allocated by a call to :func:`TSmalloc` and
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 076edfa..176c6e6 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -2137,7 +2137,10 @@ TSUrlLengthGet(TSMBuffer bufp, TSMLoc obj)
 char *
 TSUrlStringGet(TSMBuffer bufp, TSMLoc obj, int *length)
 {
-  sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS);
+  // bufp is not actually used anymore, so it can be null.
+  if (bufp) {
+    sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS);
+  }
   sdk_assert(sdk_sanity_check_url_handle(obj) == TS_SUCCESS);
   sdk_assert(sdk_sanity_check_null_ptr((void *)length) == TS_SUCCESS);
 
@@ -9586,3 +9589,43 @@ TSRegisterProtocolTag(const char *tag)
 {
   return nullptr;
 }
+
+namespace
+{
+// Function that contains the common logic for TSRemapFrom/ToUrlGet().
+//
+TSReturnCode
+remapUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp, URL 
*(UrlMappingContainer::*mfp)() const)
+{
+  sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+  sdk_assert(sdk_sanity_check_null_ptr(urlLocp) == TS_SUCCESS);
+  HttpSM *sm = reinterpret_cast<HttpSM *>(txnp);
+
+  URL *url = (sm->t_state.url_map.*mfp)();
+  if (url == nullptr) {
+    return TS_ERROR;
+  }
+
+  auto urlImpl = url->m_url_impl;
+  if (urlImpl == nullptr) {
+    return TS_ERROR;
+  }
+
+  *urlLocp = reinterpret_cast<TSMLoc>(urlImpl);
+
+  return TS_SUCCESS;
+}
+
+} // end anonymous namespace
+
+tsapi TSReturnCode
+TSRemapFromUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp)
+{
+  return remapUrlGet(txnp, urlLocp, &UrlMappingContainer::getFromURL);
+}
+
+tsapi TSReturnCode
+TSRemapToUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp)
+{
+  return remapUrlGet(txnp, urlLocp, &UrlMappingContainer::getToURL);
+}
diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h
index 4598582..7b1b752 100644
--- a/proxy/api/ts/ts.h
+++ b/proxy/api/ts/ts.h
@@ -2448,6 +2448,18 @@ tsapi const char 
*TSHttpSsnClientProtocolStackContains(TSHttpSsn ssnp, char cons
 tsapi const char *TSNormalizedProtocolTag(char const *tag);
 tsapi const char *TSRegisterProtocolTag(char const *tag);
 
+// If, for the given transaction, the URL has been remapped, this function 
puts the memory location of the "from" URL object in the
+// variable pointed to by urlLocp, and returns TS_SUCCESS.  (The URL object 
will be within memory allocated to the transaction
+// object.)  Otherwise, the function returns TS_ERROR.
+//
+tsapi TSReturnCode TSRemapFromUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp);
+
+// If, for the given transaction, the URL has been remapped, this function 
puts the memory location of the "to" URL object in the
+// variable pointed to by urlLocp, and returns TS_SUCCESS.  (The URL object 
will be within memory allocated to the transaction
+// object.)  Otherwise, the function returns TS_ERROR.
+//
+tsapi TSReturnCode TSRemapToUrlGet(TSHttpTxn txnp, TSMLoc *urlLocp);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

-- 
To stop receiving notification emails like this one, please contact
a...@apache.org.

Reply via email to