Updated Branches:
  refs/heads/master 5b73f528d -> 7429793dc

TS-2335: add features for ts_lua

1) inject remap vars
2) free memory which is allocated by TSUrlStringGet
3) add ts.client_request.get_pristine_url()

Signed-off-by: Quehan <[email protected]>
Signed-off-by: Yunkai Zhang <[email protected]>


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

Branch: refs/heads/master
Commit: 7429793dcc1e2715452723bd5d401cb6c114bec3
Parents: 5b73f52
Author: Quehan <[email protected]>
Authored: Sun Dec 15 00:48:21 2013 +0800
Committer: Yunkai Zhang <[email protected]>
Committed: Mon Dec 16 15:10:01 2013 +0800

----------------------------------------------------------------------
 plugins/experimental/ts_lua/Makefile.am         |  2 +-
 .../experimental/ts_lua/ts_lua_client_request.c | 45 ++++++++++++-
 plugins/experimental/ts_lua/ts_lua_remap.c      | 67 ++++++++++++++++++++
 plugins/experimental/ts_lua/ts_lua_remap.h      | 28 ++++++++
 plugins/experimental/ts_lua/ts_lua_util.c       |  3 +
 5 files changed, 142 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7429793d/plugins/experimental/ts_lua/Makefile.am
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/Makefile.am 
b/plugins/experimental/ts_lua/Makefile.am
index f1c1b27..a519578 100644
--- a/plugins/experimental/ts_lua/Makefile.am
+++ b/plugins/experimental/ts_lua/Makefile.am
@@ -29,7 +29,7 @@ tslua_la_CPPFLAGS = \
 pkglib_LTLIBRARIES = tslua.la
 
 tslua_la_LIBADD = $(LUA_LIBS)
-tslua_la_SOURCES = ts_lua.c ts_lua_cached_response.c ts_lua_client_request.c 
ts_lua_client_response.c ts_lua_context.c ts_lua_hook.c ts_lua_http.c 
ts_lua_http_intercept.c ts_lua_log.c ts_lua_misc.c ts_lua_server_request.c 
ts_lua_server_response.c ts_lua_transform.c ts_lua_util.c
+tslua_la_SOURCES = ts_lua.c ts_lua_cached_response.c ts_lua_client_request.c 
ts_lua_client_response.c ts_lua_context.c ts_lua_hook.c ts_lua_http.c 
ts_lua_http_intercept.c ts_lua_log.c ts_lua_misc.c ts_lua_server_request.c 
ts_lua_server_response.c ts_lua_transform.c ts_lua_util.c ts_lua_remap.c
 tslua_la_LDFLAGS = $(TS_PLUGIN_LDFLAGS)
 
 endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7429793d/plugins/experimental/ts_lua/ts_lua_client_request.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_client_request.c 
b/plugins/experimental/ts_lua/ts_lua_client_request.c
index 2dffed8..9512486 100644
--- a/plugins/experimental/ts_lua/ts_lua_client_request.c
+++ b/plugins/experimental/ts_lua/ts_lua_client_request.c
@@ -26,6 +26,7 @@ static void 
ts_lua_inject_client_request_server_addr_api(lua_State *L);
 static int ts_lua_client_request_header_get(lua_State *L);
 static int ts_lua_client_request_header_set(lua_State *L);
 static int ts_lua_client_request_get_url(lua_State *L);
+static int ts_lua_client_request_get_pristine_url(lua_State *L);
 static int ts_lua_client_request_get_uri(lua_State *L);
 static int ts_lua_client_request_set_uri(lua_State *L);
 static int ts_lua_client_request_set_uri_args(lua_State *L);
@@ -206,6 +207,9 @@ ts_lua_inject_client_request_url_api(lua_State *L)
 {
     lua_pushcfunction(L, ts_lua_client_request_get_url);
     lua_setfield(L, -2, "get_url");
+
+    lua_pushcfunction(L, ts_lua_client_request_get_pristine_url);
+    lua_setfield(L, -2, "get_pristine_url");
 }
 
 static void
@@ -221,7 +225,7 @@ ts_lua_inject_client_request_uri_api(lua_State *L)
 static int
 ts_lua_client_request_get_url(lua_State *L)
 {
-    const char  *url;
+    char        *url;
     int         url_len;
 
     ts_lua_http_ctx  *http_ctx;
@@ -230,7 +234,44 @@ ts_lua_client_request_get_url(lua_State *L)
 
     url = TSUrlStringGet(http_ctx->client_request_bufp, 
http_ctx->client_request_url, &url_len);
 
-    lua_pushlstring(L, url, url_len);
+    if (url) {
+        lua_pushlstring(L, url, url_len);
+        TSfree(url);
+
+    } else {
+        lua_pushnil(L);
+    }
+
+    return 1;
+}
+
+static int
+ts_lua_client_request_get_pristine_url(lua_State *L)
+{
+    char        *url;
+    int         url_len;
+
+    TSMBuffer   bufp;
+    TSMLoc      url_loc;
+
+    ts_lua_http_ctx  *http_ctx;
+
+    http_ctx = ts_lua_get_http_ctx(L);
+
+    if (TSHttpTxnPristineUrlGet(http_ctx->txnp, &bufp, &url_loc) != TS_SUCCESS)
+        return 0;
+
+    url = TSUrlStringGet(bufp, url_loc, &url_len);
+
+    if (url) {
+        lua_pushlstring(L, url, url_len);
+        TSfree(url);
+
+    } else {
+        lua_pushnil(L);
+    }
+
+    TSHandleMLocRelease(bufp, NULL, url_loc);
 
     return 1;
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7429793d/plugins/experimental/ts_lua/ts_lua_remap.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_remap.c 
b/plugins/experimental/ts_lua/ts_lua_remap.c
new file mode 100644
index 0000000..d6efaaf
--- /dev/null
+++ b/plugins/experimental/ts_lua/ts_lua_remap.c
@@ -0,0 +1,67 @@
+/*
+  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 "ts_lua_remap.h"
+
+
+typedef enum {
+    TS_LUA_REMAP_NO_REMAP = 0,
+    TS_LUA_REMAP_DID_REMAP,
+    TS_LUA_REMAP_NO_REMAP_STOP,
+    TS_LUA_REMAP_DID_REMAP_STOP,
+    TS_LUA_REMAP_ERROR = -1,
+} TSLuaRemapStatus;
+
+int ts_lua_remap_status_id[] = {
+    TS_LUA_REMAP_NO_REMAP,
+    TS_LUA_REMAP_DID_REMAP,
+    TS_LUA_REMAP_NO_REMAP_STOP,
+    TS_LUA_REMAP_DID_REMAP_STOP,
+    TS_LUA_REMAP_ERROR,
+};
+
+char * ts_lua_remap_status_string[] = {
+    "TS_LUA_REMAP_NO_REMAP",
+    "TS_LUA_REMAP_DID_REMAP",
+    "TS_LUA_REMAP_NO_REMAP_STOP",
+    "TS_LUA_REMAP_DID_REMAP_STOP",
+    "TS_LUA_REMAP_ERROR",
+};
+
+
+static void ts_lua_inject_remap_variables(lua_State *L);
+
+
+void
+ts_lua_inject_remap_api(lua_State *L)
+{
+    ts_lua_inject_remap_variables(L);
+}
+
+static void
+ts_lua_inject_remap_variables(lua_State *L)
+{
+    int     i;
+
+    for (i = 0; i < sizeof(ts_lua_remap_status_string)/sizeof(char*); i++) {
+        lua_pushinteger(L, ts_lua_remap_status_id[i]);
+        lua_setglobal(L, ts_lua_remap_status_string[i]);
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7429793d/plugins/experimental/ts_lua/ts_lua_remap.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_remap.h 
b/plugins/experimental/ts_lua/ts_lua_remap.h
new file mode 100644
index 0000000..1dc84ed
--- /dev/null
+++ b/plugins/experimental/ts_lua/ts_lua_remap.h
@@ -0,0 +1,28 @@
+/*
+  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.
+*/
+
+
+#ifndef _TS_LUA_REMAP_H
+#define _TS_LUA_REMAP_H
+
+#include "ts_lua_common.h"
+
+void ts_lua_inject_remap_api(lua_State *L);
+
+#endif
+

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7429793d/plugins/experimental/ts_lua/ts_lua_util.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_util.c 
b/plugins/experimental/ts_lua/ts_lua_util.c
index b79b7da..ea20fa9 100644
--- a/plugins/experimental/ts_lua/ts_lua_util.c
+++ b/plugins/experimental/ts_lua/ts_lua_util.c
@@ -18,6 +18,7 @@
 
 
 #include "ts_lua_util.h"
+#include "ts_lua_remap.h"
 #include "ts_lua_client_request.h"
 #include "ts_lua_server_request.h"
 #include "ts_lua_server_response.h"
@@ -186,6 +187,8 @@ ts_lua_inject_ts_api(lua_State *L)
 {
     lua_newtable(L);
 
+    ts_lua_inject_remap_api(L);
+
     ts_lua_inject_client_request_api(L);
     ts_lua_inject_server_request_api(L);
     ts_lua_inject_server_response_api(L);

Reply via email to