lua: move function to common utils

LuaStateNeedProto function can be used for any protocol so let's
move it out of the http file.
pull/1183/head
Eric Leblond 11 years ago committed by Victor Julien
parent 4d66775a56
commit 74ffa2b264

@ -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 */

@ -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__ */

@ -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)))

Loading…
Cancel
Save