From 74ffa2b26456f5e01eea45ece9b77cf8443c5160 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Sat, 18 Oct 2014 13:20:52 +0200 Subject: [PATCH] lua: move function to common utils LuaStateNeedProto function can be used for any protocol so let's move it out of the http file. --- src/util-lua-common.c | 20 ++++++++++++++++++++ src/util-lua-common.h | 2 ++ src/util-lua-http.c | 20 -------------------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/util-lua-common.c b/src/util-lua-common.c index d89007738e..54c236de87 100644 --- a/src/util-lua-common.c +++ b/src/util-lua-common.c @@ -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 */ diff --git a/src/util-lua-common.h b/src/util-lua-common.h index fe048fe68e..2e0df28751 100644 --- a/src/util-lua-common.h +++ b/src/util-lua-common.h @@ -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__ */ diff --git a/src/util-lua-http.c b/src/util-lua-http.c index e5957afdd4..3d97b0f640 100644 --- a/src/util-lua-http.c +++ b/src/util-lua-http.c @@ -56,26 +56,6 @@ #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)))