From: Eric Leblond Date: Sat, 18 Oct 2014 11:20:52 +0000 (+0200) Subject: lua: move function to common utils X-Git-Tag: suricata-2.1beta2~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74ffa2b26456f5e01eea45ece9b77cf8443c5160;p=thirdparty%2Fsuricata.git lua: move function to common utils LuaStateNeedProto function can be used for any protocol so let's move it out of the http file. --- 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)))