]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect-lua: convert extensions to use flow wrappers
authorVictor Julien <victor@inliniac.net>
Mon, 3 Mar 2014 13:11:00 +0000 (14:11 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 15 Aug 2014 11:58:26 +0000 (13:58 +0200)
Use the new flow wrapper functions in the lua flowvar and flowint
extensions.

src/detect-luajit-extensions.c

index 1ea14978133d1789f21f8009e219813ca5f74082..5fb9b0362c34334a36d144b885ba520170ee1f54 100644 (file)
 
 #ifdef HAVE_LUA
 
+#include "util-lua.h"
+
 static const char luaext_key_ld[] = "suricata:luajitdata";
 static const char luaext_key_det_ctx[] = "suricata:det_ctx";
-static const char luaext_key_flow[] = "suricata:flow";
-static const char luaext_key_need_flow_lock[] = "suricata:need_flow_lock";
 
 static int LuajitGetFlowvar(lua_State *luastate)
 {
@@ -85,22 +85,14 @@ static int LuajitGetFlowvar(lua_State *luastate)
         return 2;
     }
 
-    /* need flow */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_flow);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    f = lua_touserdata(luastate, -1);
-    SCLogDebug("f %p", f);
+    /* need flow and lock hint */
+    f = LuaStateGetFlow(luastate, &need_flow_lock);
     if (f == NULL) {
         lua_pushnil(luastate);
         lua_pushstring(luastate, "no flow");
         return 2;
     }
 
-    /* need flow lock hint */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    need_flow_lock = lua_toboolean(luastate, -1);
-
     /* need flowvar idx */
     if (!lua_isnumber(luastate, 1)) {
         lua_pushnil(luastate);
@@ -192,22 +184,14 @@ int LuajitSetFlowvar(lua_State *luastate)
         return 2;
     }
 
-    /* need flow */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_flow);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    f = lua_touserdata(luastate, -1);
-    SCLogDebug("f %p", f);
+    /* need flow and lock hint */
+    f = LuaStateGetFlow(luastate, &need_flow_lock);
     if (f == NULL) {
         lua_pushnil(luastate);
         lua_pushstring(luastate, "no flow");
         return 2;
     }
 
-    /* need flow lock hint */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    need_flow_lock = lua_toboolean(luastate, -1);
-
     /* need flowvar idx */
     if (!lua_isnumber(luastate, 1)) {
         lua_pushnil(luastate);
@@ -292,22 +276,14 @@ static int LuajitGetFlowint(lua_State *luastate)
         return 2;
     }
 
-    /* need flow */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_flow);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    f = lua_touserdata(luastate, -1);
-    SCLogDebug("f %p", f);
+    /* need flow and lock hint */
+    f = LuaStateGetFlow(luastate, &need_flow_lock);
     if (f == NULL) {
         lua_pushnil(luastate);
         lua_pushstring(luastate, "no flow");
         return 2;
     }
 
-    /* need flow lock hint */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    need_flow_lock = lua_toboolean(luastate, -1);
-
     /* need flowint idx */
     if (!lua_isnumber(luastate, 1)) {
         SCLogDebug("1st arg not a number");
@@ -390,20 +366,13 @@ int LuajitSetFlowint(lua_State *luastate)
         return 2;
     }
 
-    /* need flow */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_flow);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    f = lua_touserdata(luastate, -1);
-    SCLogDebug("f %p", f);
+    /* need flow and lock hint */
+    f = LuaStateGetFlow(luastate, &need_flow_lock);
     if (f == NULL) {
         lua_pushnil(luastate);
         lua_pushstring(luastate, "no flow");
         return 2;
     }
-    /* need flow lock hint */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    need_flow_lock = lua_toboolean(luastate, -1);
 
     /* need flowint idx */
     if (!lua_isnumber(luastate, 1)) {
@@ -468,22 +437,14 @@ static int LuajitIncrFlowint(lua_State *luastate)
         return 2;
     }
 
-    /* need flow */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_flow);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    f = lua_touserdata(luastate, -1);
-    SCLogDebug("f %p", f);
+    /* need flow and lock hint */
+    f = LuaStateGetFlow(luastate, &need_flow_lock);
     if (f == NULL) {
         lua_pushnil(luastate);
         lua_pushstring(luastate, "no flow");
         return 2;
     }
 
-    /* need flow lock hint */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    need_flow_lock = lua_toboolean(luastate, -1);
-
     /* need flowint idx */
     if (!lua_isnumber(luastate, 1)) {
         SCLogDebug("1st arg not a number");
@@ -552,22 +513,14 @@ static int LuajitDecrFlowint(lua_State *luastate)
         return 2;
     }
 
-    /* need flow */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_flow);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    f = lua_touserdata(luastate, -1);
-    SCLogDebug("f %p", f);
+    /* need flow and lock hint */
+    f = LuaStateGetFlow(luastate, &need_flow_lock);
     if (f == NULL) {
         lua_pushnil(luastate);
         lua_pushstring(luastate, "no flow");
         return 2;
     }
 
-    /* need flow lock hint */
-    lua_pushlightuserdata(luastate, (void *)&luaext_key_need_flow_lock);
-    lua_gettable(luastate, LUA_REGISTRYINDEX);
-    need_flow_lock = lua_toboolean(luastate, -1);
-
     /* need flowint idx */
     if (!lua_isnumber(luastate, 1)) {
         SCLogDebug("1st arg not a number");
@@ -629,15 +582,7 @@ void LuajitExtensionsMatchSetup(lua_State *lua_state, DetectLuajitData *ld, Dete
     lua_pushlightuserdata(lua_state, (void *)det_ctx);
     lua_settable(lua_state, LUA_REGISTRYINDEX);
 
-    /* flow */
-    lua_pushlightuserdata(lua_state, (void *)&luaext_key_flow);
-    lua_pushlightuserdata(lua_state, (void *)f);
-    lua_settable(lua_state, LUA_REGISTRYINDEX);
-
-    /* flow lock status hint */
-    lua_pushlightuserdata(lua_state, (void *)&luaext_key_need_flow_lock);
-    lua_pushboolean(lua_state, need_flow_lock);
-    lua_settable(lua_state, LUA_REGISTRYINDEX);
+    LuaStateSetFlow(lua_state, f, need_flow_lock);
 }
 
 /**