You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ki...@apache.org on 2017/11/14 23:28:44 UTC

[trafficserver] branch master updated (8a53cf1 -> d77aa3f)

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

kichan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.


    from 8a53cf1  TsLuaConfig: Fix virtual destructor issue.
     new 98a2d2d  Add support for TSIpAddrParse as a conveninent function to parse IP address
     new 5f4271b  fix text width for documentation
     new d07b79c  Change function name
     new 79c31f3  fix typo
     new d77aa3f  use string_view

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ...xnServerPush.en.rst => TSIpStringToAddr.en.rst} | 28 ++++++++-------
 plugins/experimental/ts_lua/ts_lua_fetch.c         | 40 ++++++----------------
 proxy/InkAPI.cc                                    | 13 +++++++
 proxy/api/ts/experimental.h                        |  3 ++
 4 files changed, 42 insertions(+), 42 deletions(-)
 copy doc/developer-guide/api/functions/{TSHttpTxnServerPush.en.rst => TSIpStringToAddr.en.rst} (59%)

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>'].

[trafficserver] 01/05: Add support for TSIpAddrParse as a conveninent function to parse IP address

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 98a2d2d21d62e9413186aa475248dc47d12e7c54
Author: Kit Chan <ki...@apache.org>
AuthorDate: Thu Sep 14 17:24:23 2017 -0700

    Add support for TSIpAddrParse as a conveninent function to parse IP address
---
 .../api/functions/TSIpAddrParse.en.rst             | 51 ++++++++++++++++++++++
 plugins/experimental/ts_lua/ts_lua_fetch.c         | 40 +++++------------
 proxy/InkAPI.cc                                    | 13 ++++++
 proxy/api/ts/experimental.h                        |  3 ++
 4 files changed, 77 insertions(+), 30 deletions(-)

diff --git a/doc/developer-guide/api/functions/TSIpAddrParse.en.rst b/doc/developer-guide/api/functions/TSIpAddrParse.en.rst
new file mode 100644
index 0000000..0f7234c
--- /dev/null
+++ b/doc/developer-guide/api/functions/TSIpAddrParse.en.rst
@@ -0,0 +1,51 @@
+.. 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
+
+TSIpAddrParse
+*************
+
+Synopsis
+========
+
+`#include <ts/experimental.h>`
+
+.. function:: TSReturnCode TSIpAddrParse(const char * str, int str_len, sockaddr* addr)
+
+Description
+===========
+
+:arg:`str` is expected to be an explicit address, not a hostname.  No hostname resolution is done. This attempts to recognize and process a port value if present. It is set appropriately, or to zero if no port was found or it was malformed.
+
+It is intended to deal with the brackets that can optionally surround an IP address (usually IPv6) which in turn are used to differentiate between an address and an attached port. E.g.
+
+.. code-block:: none
+
+[FE80:9312::192:168:1:1]:80
+
+Return values
+=============
+
+It returns :data:`TS_SUCCESS` on success, or :data:`TS_ERROR` on failure. 
+
+Notes
+=====
+
+This API may be changed in the future version since it is experimental.
+
diff --git a/plugins/experimental/ts_lua/ts_lua_fetch.c b/plugins/experimental/ts_lua/ts_lua_fetch.c
index cf5d5e9..7b2d6a4 100644
--- a/plugins/experimental/ts_lua/ts_lua_fetch.c
+++ b/plugins/experimental/ts_lua/ts_lua_fetch.c
@@ -16,17 +16,13 @@
   limitations under the License.
 */
 
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
 #include "ts_lua_util.h"
 #include "ts_lua_io.h"
 #include "ts_lua_fetch.h"
 
 #define TS_LUA_EVENT_FETCH_OVER 20010
-#define TS_LUA_FETCH_CLIENT_ADDRESS "127.0.0.1"
-#define TS_LUA_FETCH_CLIENT_PORT 33333
+#define TS_LUA_FETCH_CLIENT_ADDRPORT "127.0.0.1:33333"
+#define TS_LUA_FETCH_CLIENT_ADDRPORT_LEN 15
 #define TS_LUA_FETCH_USER_AGENT "TS Fetcher/1.0"
 
 static int ts_lua_fetch(lua_State *L);
@@ -203,15 +199,14 @@ static int
 ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetch_info *fi)
 {
   TSCont contp;
-  int tb, flags, host_len, port, n;
+  int tb, flags, host_len, n;
   int cl, ht, ua;
   const char *method, *key, *value, *body, *opt;
   const char *addr, *ptr, *host;
   size_t method_len, key_len, value_len, body_len;
   size_t addr_len, opt_len, i, left;
   char c;
-  struct sockaddr_in clientaddr;
-  char ipstr[32];
+  struct sockaddr clientaddr;
   char buf[32];
 
   tb = lua_istable(L, -1);
@@ -252,8 +247,6 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
 
   /* cliaddr */
   memset(&clientaddr, 0, sizeof(clientaddr));
-  clientaddr.sin_family = AF_INET;
-  const char *p         = NULL;
 
   if (tb) {
     lua_pushlstring(L, "cliaddr", sizeof("cliaddr") - 1);
@@ -261,32 +254,19 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
 
     if (lua_isstring(L, -1)) {
       addr = luaL_checklstring(L, -1, &addr_len);
-      p    = strstr(addr, ":");
-      if (p && p - addr < 32) {
-        port = atoi(p + 1);
-        strncpy(ipstr, addr, p - addr);
-        ipstr[p - addr]     = 0;
-        clientaddr.sin_port = htons(port);
-        if (!inet_aton(ipstr, (struct in_addr *)&clientaddr.sin_addr.s_addr)) {
-          p = NULL;
-          TSError("[%s] Client ip parse failed! Using default. [ip: %s]", TS_LUA_DEBUG_TAG, ipstr);
+
+      if (TS_ERROR == TSIpAddrParse(addr, addr_len, &clientaddr)) {
+        TSError("[%s] Client ip parse failed! Using default.", TS_LUA_DEBUG_TAG);
+        if (TS_ERROR == TSIpAddrParse(TS_LUA_FETCH_CLIENT_ADDRPORT, TS_LUA_FETCH_CLIENT_ADDRPORT_LEN, &clientaddr)) {
+          TSError("[%s] Default client ip parse failed!", TS_LUA_DEBUG_TAG);
+          return 0;
         }
-      } else {
-        p = NULL;
-        TSError("[%s] Client ip parse failed! Using default. [addrstr: %s]", TS_LUA_DEBUG_TAG, addr);
       }
     }
 
     lua_pop(L, 1);
   }
 
-  if (!p) {
-    clientaddr.sin_port = htons(TS_LUA_FETCH_CLIENT_PORT);
-    if (!inet_aton(TS_LUA_FETCH_CLIENT_ADDRESS, (struct in_addr *)&clientaddr.sin_addr.s_addr)) {
-      TSError("[%s] Error using default for client ip in fetch API. [ip: %s]", TS_LUA_DEBUG_TAG, TS_LUA_FETCH_CLIENT_ADDRESS);
-    }
-  }
-
   /* option */
   flags = TS_FETCH_FLAGS_DECHUNK; // dechunk the body default
 
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index ead3577..b4b911c 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -2428,6 +2428,19 @@ TSUrlPercentEncode(TSMBuffer bufp, TSMLoc obj, char *dst, size_t dst_size, size_
   return ret;
 }
 
+// pton
+TSReturnCode
+TSIpAddrParse(const char *str, size_t str_len, sockaddr *addr)
+{
+  sdk_assert(sdk_sanity_check_null_ptr((void *)str) == TS_SUCCESS);
+
+  if (0 != ats_ip_pton(ts::ConstBuffer(str, str_len), addr)) {
+    return TS_ERROR;
+  }
+
+  return TS_SUCCESS;
+}
+
 ////////////////////////////////////////////////////////////////////
 //
 // MIME Headers
diff --git a/proxy/api/ts/experimental.h b/proxy/api/ts/experimental.h
index 5181d88..dd19cbf 100644
--- a/proxy/api/ts/experimental.h
+++ b/proxy/api/ts/experimental.h
@@ -231,6 +231,9 @@ tsapi int TSHttpTxnLookingUpTypeGet(TSHttpTxn txnp);
 
 tsapi void TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len);
 
+/* ip addr parsing */
+tsapi TSReturnCode TSIpAddrParse(const char *str, size_t str_len, struct sockaddr *addr);
+
 /**
    Attempt to attach the contp continuation to sockets that have already been
    opened by the traffic manager and defined as belonging to plugins (based on

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 02/05: fix text width for documentation

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 5f4271bd03680f3aabeb5522e0bbf32d6eeb3f5d
Author: Kit Chan <ki...@apache.org>
AuthorDate: Thu Sep 14 17:56:30 2017 -0700

    fix text width for documentation
---
 doc/developer-guide/api/functions/TSIpAddrParse.en.rst | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/developer-guide/api/functions/TSIpAddrParse.en.rst b/doc/developer-guide/api/functions/TSIpAddrParse.en.rst
index 0f7234c..204375f 100644
--- a/doc/developer-guide/api/functions/TSIpAddrParse.en.rst
+++ b/doc/developer-guide/api/functions/TSIpAddrParse.en.rst
@@ -31,9 +31,12 @@ Synopsis
 Description
 ===========
 
-:arg:`str` is expected to be an explicit address, not a hostname.  No hostname resolution is done. This attempts to recognize and process a port value if present. It is set appropriately, or to zero if no port was found or it was malformed.
+:arg:`str` is expected to be an explicit address, not a hostname.  No hostname resolution is done. This attempts to
+recognize and process a port value if present. It is set appropriately, or to zero if no port was found or it was
+malformed. 
 
-It is intended to deal with the brackets that can optionally surround an IP address (usually IPv6) which in turn are used to differentiate between an address and an attached port. E.g.
+It is intended to deal with the brackets that can optionally surround an IP address (usually IPv6) which in turn are
+used to differentiate between an address and an attached port. E.g. 
 
 .. code-block:: none
 

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 04/05: fix typo

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 79c31f33dea5bf776e2822410b0639f6c9ffdca2
Author: Kit Chan <ki...@apache.org>
AuthorDate: Wed Sep 20 10:27:57 2017 -0700

    fix typo
---
 proxy/api/ts/experimental.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxy/api/ts/experimental.h b/proxy/api/ts/experimental.h
index 4949064..1acc179 100644
--- a/proxy/api/ts/experimental.h
+++ b/proxy/api/ts/experimental.h
@@ -232,7 +232,7 @@ tsapi int TSHttpTxnLookingUpTypeGet(TSHttpTxn txnp);
 tsapi void TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len);
 
 /* ip addr parsing */
-tsapi TSReturnCode TSIpStringtoAddr(const char *str, size_t str_len, struct sockaddr *addr);
+tsapi TSReturnCode TSIpStringToAddr(const char *str, size_t str_len, struct sockaddr *addr);
 
 /**
    Attempt to attach the contp continuation to sockets that have already been

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 05/05: use string_view

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit d77aa3f381ffdc530109429eaa00b0f2ceb46354
Author: Kit Chan <ki...@apache.org>
AuthorDate: Tue Oct 24 08:15:28 2017 -0700

    use string_view
---
 proxy/InkAPI.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 4d5057c..4a17cfe 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -2434,7 +2434,7 @@ TSIpStringToAddr(const char *str, size_t str_len, sockaddr *addr)
 {
   sdk_assert(sdk_sanity_check_null_ptr((void *)str) == TS_SUCCESS);
 
-  if (0 != ats_ip_pton(ts::ConstBuffer(str, str_len), addr)) {
+  if (0 != ats_ip_pton(ts::string_view(str, str_len), addr)) {
     return TS_ERROR;
   }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.

[trafficserver] 03/05: Change function name

Posted by ki...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kichan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit d07b79ce49c86eaa03928455e04fc29bc27bc3dc
Author: Kit Chan <ki...@apache.org>
AuthorDate: Tue Sep 19 23:16:00 2017 -0700

    Change function name
---
 .../api/functions/{TSIpAddrParse.en.rst => TSIpStringToAddr.en.rst} | 6 +++---
 plugins/experimental/ts_lua/ts_lua_fetch.c                          | 4 ++--
 proxy/InkAPI.cc                                                     | 2 +-
 proxy/api/ts/experimental.h                                         | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/doc/developer-guide/api/functions/TSIpAddrParse.en.rst b/doc/developer-guide/api/functions/TSIpStringToAddr.en.rst
similarity index 92%
rename from doc/developer-guide/api/functions/TSIpAddrParse.en.rst
rename to doc/developer-guide/api/functions/TSIpStringToAddr.en.rst
index 204375f..8251a29 100644
--- a/doc/developer-guide/api/functions/TSIpAddrParse.en.rst
+++ b/doc/developer-guide/api/functions/TSIpStringToAddr.en.rst
@@ -18,15 +18,15 @@
 
 .. default-domain:: c
 
-TSIpAddrParse
-*************
+TSIpStringToAddr
+****************
 
 Synopsis
 ========
 
 `#include <ts/experimental.h>`
 
-.. function:: TSReturnCode TSIpAddrParse(const char * str, int str_len, sockaddr* addr)
+.. function:: TSReturnCode TSIpStringToAddr(const char * str, int str_len, sockaddr* addr)
 
 Description
 ===========
diff --git a/plugins/experimental/ts_lua/ts_lua_fetch.c b/plugins/experimental/ts_lua/ts_lua_fetch.c
index 7b2d6a4..337a451 100644
--- a/plugins/experimental/ts_lua/ts_lua_fetch.c
+++ b/plugins/experimental/ts_lua/ts_lua_fetch.c
@@ -255,9 +255,9 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
     if (lua_isstring(L, -1)) {
       addr = luaL_checklstring(L, -1, &addr_len);
 
-      if (TS_ERROR == TSIpAddrParse(addr, addr_len, &clientaddr)) {
+      if (TS_ERROR == TSIpStringToAddr(addr, addr_len, &clientaddr)) {
         TSError("[%s] Client ip parse failed! Using default.", TS_LUA_DEBUG_TAG);
-        if (TS_ERROR == TSIpAddrParse(TS_LUA_FETCH_CLIENT_ADDRPORT, TS_LUA_FETCH_CLIENT_ADDRPORT_LEN, &clientaddr)) {
+        if (TS_ERROR == TSIpStringToAddr(TS_LUA_FETCH_CLIENT_ADDRPORT, TS_LUA_FETCH_CLIENT_ADDRPORT_LEN, &clientaddr)) {
           TSError("[%s] Default client ip parse failed!", TS_LUA_DEBUG_TAG);
           return 0;
         }
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index b4b911c..4d5057c 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -2430,7 +2430,7 @@ TSUrlPercentEncode(TSMBuffer bufp, TSMLoc obj, char *dst, size_t dst_size, size_
 
 // pton
 TSReturnCode
-TSIpAddrParse(const char *str, size_t str_len, sockaddr *addr)
+TSIpStringToAddr(const char *str, size_t str_len, sockaddr *addr)
 {
   sdk_assert(sdk_sanity_check_null_ptr((void *)str) == TS_SUCCESS);
 
diff --git a/proxy/api/ts/experimental.h b/proxy/api/ts/experimental.h
index dd19cbf..4949064 100644
--- a/proxy/api/ts/experimental.h
+++ b/proxy/api/ts/experimental.h
@@ -232,7 +232,7 @@ tsapi int TSHttpTxnLookingUpTypeGet(TSHttpTxn txnp);
 tsapi void TSHttpTxnServerPush(TSHttpTxn txnp, const char *url, int url_len);
 
 /* ip addr parsing */
-tsapi TSReturnCode TSIpAddrParse(const char *str, size_t str_len, struct sockaddr *addr);
+tsapi TSReturnCode TSIpStringtoAddr(const char *str, size_t str_len, struct sockaddr *addr);
 
 /**
    Attempt to attach the contp continuation to sockets that have already been

-- 
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.