]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua: move function to common utils
authorEric Leblond <eric@regit.org>
Sat, 18 Oct 2014 11:20:52 +0000 (13:20 +0200)
committerVictor Julien <victor@inliniac.net>
Sat, 25 Oct 2014 17:28:40 +0000 (19:28 +0200)
LuaStateNeedProto function can be used for any protocol so let's
move it out of the http file.

src/util-lua-common.c
src/util-lua-common.h
src/util-lua-http.c

index d89007738e366bedd9975d032b2f617c76dc9d4c..54c236de87d363e0c6a774d7d3ffe351c8cffa88 100644 (file)
@@ -747,4 +747,24 @@ int LuaRegisterFunctions(lua_State *luastate)
     return 0;
 }
 
+int LuaStateNeedProto(lua_State *luastate, AppProto alproto)
+{
+    AppProto flow_alproto = 0;
+    int locked = 0;
+    Flow *flow = LuaStateGetFlow(luastate, &locked);
+    if (flow == NULL)
+        return LuaCallbackError(luastate, "internal error: no flow");
+
+    if (locked == LUA_FLOW_NOT_LOCKED_BY_PARENT) {
+        FLOWLOCK_RDLOCK(flow);
+        flow_alproto = flow->alproto;
+        FLOWLOCK_UNLOCK(flow);
+    } else {
+        flow_alproto = flow->alproto;
+    }
+
+    return (alproto == flow_alproto);
+
+}
+
 #endif /* HAVE_LUA */
index fe048fe68e0df935ff464300f8ac8b3291204c2a..2e0df28751a1143d94dd42a010c8173378a335c5 100644 (file)
@@ -35,6 +35,8 @@ void LuaPushTableKeyValueArray(lua_State *luastate, const char *key, const uint8
 
 int LuaRegisterFunctions(lua_State *luastate);
 
+int LuaStateNeedProto(lua_State *luastate, AppProto alproto);
+
 #endif /* HAVE_LUA */
 
 #endif /* __UTIL_LUA_COMMON_H__ */
index e5957afdd47eb66e1e7a644f8ab5503a50784f5b..3d97b0f640acd365c0289a590e2c5b42fb27752c 100644 (file)
 #include "util-lua.h"
 #include "util-lua-common.h"
 
-int LuaStateNeedProto(lua_State *luastate, AppProto alproto)
-{
-    AppProto flow_alproto = 0;
-    int locked = 0;
-    Flow *flow = LuaStateGetFlow(luastate, &locked);
-    if (flow == NULL)
-        return LuaCallbackError(luastate, "internal error: no flow");
-
-    if (locked == LUA_FLOW_NOT_LOCKED_BY_PARENT) {
-        FLOWLOCK_RDLOCK(flow);
-        flow_alproto = flow->alproto;
-        FLOWLOCK_UNLOCK(flow);
-    } else {
-        flow_alproto = flow->alproto;
-    }
-
-    return (alproto == flow_alproto);
-
-}
-
 static int HttpGetRequestHost(lua_State *luastate)
 {
     if (!(LuaStateNeedProto(luastate, ALPROTO_HTTP)))