trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kic...@apache.org
Subject trafficserver git commit: TS-3674: bug fix for ts_lua plugin for adding package path
Date Tue, 09 Jun 2015 06:05:09 GMT
Repository: trafficserver
Updated Branches:
  refs/heads/master 3bcdd5022 -> 3b097aff4


TS-3674: bug fix for ts_lua plugin for adding package path


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

Branch: refs/heads/master
Commit: 3b097aff412db20c2ccd46db9f891a41a3396a72
Parents: 3bcdd50
Author: Kit Chan <kichan@apache.org>
Authored: Mon Jun 8 23:04:56 2015 -0700
Committer: Kit Chan <kichan@apache.org>
Committed: Mon Jun 8 23:04:56 2015 -0700

----------------------------------------------------------------------
 CHANGES                                      |   2 +
 plugins/experimental/ts_lua/ts_lua.c         |   2 +
 plugins/experimental/ts_lua/ts_lua_common.h  |   2 +
 plugins/experimental/ts_lua/ts_lua_package.c | 110 +++++++++++++++++-----
 4 files changed, 90 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3b097aff/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 1e07599..5512e15 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 6.0.0
 
+  *) [TS-3674] bug fix on ts_lua plugin for adding package path.
+
   *) [TS-2325] Support .include directories in remap.config.
    Author: Masakazu Kitajo <m4sk17@gmail.com>
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3b097aff/plugins/experimental/ts_lua/ts_lua.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua.c b/plugins/experimental/ts_lua/ts_lua.c
index 44870a2..d0e6345 100644
--- a/plugins/experimental/ts_lua/ts_lua.c
+++ b/plugins/experimental/ts_lua/ts_lua.c
@@ -88,6 +88,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int
errbuf_s
   }
 
   memset(conf, 0, sizeof(ts_lua_instance_conf));
+  conf->remap = 1;
 
   if (fn) {
     snprintf(conf->script, TS_LUA_MAX_SCRIPT_FNAME_LENGTH, "%s", argv[2]);
@@ -383,6 +384,7 @@ TSPluginInit(int argc, const char *argv[])
     return;
   }
   memset(conf, 0, sizeof(ts_lua_instance_conf));
+  conf->remap = 0;
 
   snprintf(conf->script, TS_LUA_MAX_SCRIPT_FNAME_LENGTH, "%s", argv[1]);
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3b097aff/plugins/experimental/ts_lua/ts_lua_common.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_common.h b/plugins/experimental/ts_lua/ts_lua_common.h
index 3f9ce4e..3a26472 100644
--- a/plugins/experimental/ts_lua/ts_lua_common.h
+++ b/plugins/experimental/ts_lua/ts_lua_common.h
@@ -97,6 +97,8 @@ typedef struct {
 
   int _first : 1; // create current instance for 1st ts_lua_main_ctx
   int _last : 1;  // create current instance for the last ts_lua_main_ctx
+
+  int remap;
 } ts_lua_instance_conf;
 
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/3b097aff/plugins/experimental/ts_lua/ts_lua_package.c
----------------------------------------------------------------------
diff --git a/plugins/experimental/ts_lua/ts_lua_package.c b/plugins/experimental/ts_lua/ts_lua_package.c
index 898fac7..04cf4ba 100644
--- a/plugins/experimental/ts_lua/ts_lua_package.c
+++ b/plugins/experimental/ts_lua/ts_lua_package.c
@@ -29,6 +29,12 @@ typedef struct {
 } ts_lua_package_path;
 
 
+static int path_cnt = 0;
+static ts_lua_package_path path[TS_LUA_MAX_PACKAGE_NUM];
+
+static int cpath_cnt = 0;
+static ts_lua_package_path cpath[TS_LUA_MAX_PACKAGE_NUM];
+
 static int g_path_cnt = 0;
 static ts_lua_package_path g_path[TS_LUA_MAX_PACKAGE_NUM];
 
@@ -88,20 +94,38 @@ ts_lua_add_package_path(lua_State *L)
     }
 
     if (item_len > 0) {
-      for (i = 0; i < g_path_cnt; i++) {
-        if (g_path[i].len == item_len && memcmp(g_path[i].name, ptr, item_len) ==
0) // exist
-        {
-          break;
+      if (!conf->remap) {
+        for (i = 0; i < g_path_cnt; i++) {
+          if (g_path[i].len == item_len && memcmp(g_path[i].name, ptr, item_len)
== 0) // exist
+          {
+            break;
+          }
         }
-      }
 
-      if (i >= g_path_cnt) {
-        if (n + i >= TS_LUA_MAX_PACKAGE_NUM)
-          return luaL_error(L, "extended package path number exceeds %d.", TS_LUA_MAX_PACKAGE_NUM);
+        if (i >= g_path_cnt) {
+          if (n + i >= TS_LUA_MAX_PACKAGE_NUM)
+            return luaL_error(L, "extended package path number exceeds %d.", TS_LUA_MAX_PACKAGE_NUM);
 
-        pp[n].name = (char *)ptr;
-        pp[n].len = item_len;
-        n++;
+          pp[n].name = (char *)ptr;
+          pp[n].len = item_len;
+          n++;
+        }
+      } else {
+        for (i = 0; i < path_cnt; i++) {
+          if (path[i].len == item_len && memcmp(path[i].name, ptr, item_len) == 0)
// exist
+          {
+            break;
+          }
+        }
+
+        if (i >= path_cnt) {
+          if (n + i >= TS_LUA_MAX_PACKAGE_NUM)
+            return luaL_error(L, "extended package path number exceeds %d.", TS_LUA_MAX_PACKAGE_NUM);
+
+          pp[n].name = (char *)ptr;
+          pp[n].len = item_len;
+          n++;
+        }
       }
     }
 
@@ -112,7 +136,11 @@ ts_lua_add_package_path(lua_State *L)
     ts_lua_add_package_path_items(L, pp, n);
 
     if (conf->_last) {
-      elt = &g_path[g_path_cnt];
+      if (!conf->remap) {
+        elt = &g_path[g_path_cnt];
+      } else {
+        elt = &path[path_cnt];
+      }
 
       for (i = 0; i < n; i++) {
         elt->len = pp[i].len;
@@ -121,7 +149,11 @@ ts_lua_add_package_path(lua_State *L)
         elt++;
       }
 
-      g_path_cnt += n;
+      if (!conf->remap) {
+        g_path_cnt += n;
+      } else {
+        path_cnt += n;
+      }
     }
   }
 
@@ -208,20 +240,38 @@ ts_lua_add_package_cpath(lua_State *L)
     }
 
     if (item_len > 0) {
-      for (i = 0; i < g_cpath_cnt; i++) {
-        if (g_cpath[i].len == item_len && memcmp(g_cpath[i].name, ptr, item_len)
== 0) // exist
-        {
-          break;
+      if (!conf->remap) {
+        for (i = 0; i < g_cpath_cnt; i++) {
+          if (g_cpath[i].len == item_len && memcmp(g_cpath[i].name, ptr, item_len)
== 0) // exist
+          {
+            break;
+          }
         }
-      }
 
-      if (i >= g_cpath_cnt) {
-        if (n + i >= TS_LUA_MAX_PACKAGE_NUM)
-          return luaL_error(L, "extended package cpath number exceeds %d.", TS_LUA_MAX_PACKAGE_NUM);
+        if (i >= g_cpath_cnt) {
+          if (n + i >= TS_LUA_MAX_PACKAGE_NUM)
+            return luaL_error(L, "extended package cpath number exceeds %d.", TS_LUA_MAX_PACKAGE_NUM);
+
+          pp[n].name = (char *)ptr;
+          pp[n].len = item_len;
+          n++;
+        }
+      } else {
+        for (i = 0; i < cpath_cnt; i++) {
+          if (cpath[i].len == item_len && memcmp(cpath[i].name, ptr, item_len) ==
0) // exist
+          {
+            break;
+          }
+        }
 
-        pp[n].name = (char *)ptr;
-        pp[n].len = item_len;
-        n++;
+        if (i >= cpath_cnt) {
+          if (n + i >= TS_LUA_MAX_PACKAGE_NUM)
+            return luaL_error(L, "extended package cpath number exceeds %d.", TS_LUA_MAX_PACKAGE_NUM);
+
+          pp[n].name = (char *)ptr;
+          pp[n].len = item_len;
+          n++;
+        }
       }
     }
 
@@ -232,7 +282,11 @@ ts_lua_add_package_cpath(lua_State *L)
     ts_lua_add_package_cpath_items(L, pp, n);
 
     if (conf->_last) {
-      elt = &g_cpath[g_cpath_cnt];
+      if (!conf->remap) {
+        elt = &g_cpath[g_cpath_cnt];
+      } else {
+        elt = &cpath[cpath_cnt];
+      }
 
       for (i = 0; i < n; i++) {
         elt->len = pp[i].len;
@@ -241,7 +295,11 @@ ts_lua_add_package_cpath(lua_State *L)
         elt++;
       }
 
-      g_cpath_cnt += n;
+      if (!conf->remap) {
+        g_cpath_cnt += n;
+      } else {
+        cpath_cnt += n;
+      }
     }
   }
 


Mime
View raw message