From: Victor Julien Date: Thu, 20 Feb 2014 14:45:33 +0000 (+0100) Subject: output-lua: move LuaPrintStack to common X-Git-Tag: suricata-2.1beta2~157 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=15052e58a24b572a312df3cdc93f10ad6e5f3dcb;p=thirdparty%2Fsuricata.git output-lua: move LuaPrintStack to common It's a utility function that will be used in several other places as well. --- diff --git a/src/output-lua-common.c b/src/output-lua-common.c index 027d4ef802..ae4384ed9f 100644 --- a/src/output-lua-common.c +++ b/src/output-lua-common.c @@ -54,6 +54,40 @@ #include #include +/** \brief dump stack from lua state to screen */ +void LuaPrintStack(lua_State *state) { + int size = lua_gettop(state); + int i; + + for (i = 1; i <= size; i++) { + int type = lua_type(state, i); + printf("Stack size=%d, level=%d, type=%d, ", size, i, type); + + switch (type) { + case LUA_TFUNCTION: + printf("function %s", lua_tostring(state, i) ? "true" : "false"); + break; + case LUA_TBOOLEAN: + printf("bool %s", lua_toboolean(state, i) ? "true" : "false"); + break; + case LUA_TNUMBER: + printf("number %g", lua_tonumber(state, i)); + break; + case LUA_TSTRING: + printf("string `%s'", lua_tostring(state, i)); + break; + case LUA_TTABLE: + printf("table `%s'", lua_tostring(state, i)); + break; + default: + printf("other %s", lua_typename(state, type)); + break; + + } + printf("\n"); + } +} + extern const char lualog_ext_key_tx; void *LuaStateGetTX(lua_State *luastate) diff --git a/src/output-lua.c b/src/output-lua.c index fc579991ed..8ed2a1062d 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -53,6 +53,7 @@ #include #include +#include "output-lua-common.h" #include "output-lua-http.h" #define MODULE_NAME "LuaLog" @@ -69,40 +70,6 @@ typedef struct LogLuaThreadCtx_ { const char lualog_ext_key_tx[] = "suricata:lualog:tx:ptr"; -/** \brief dump stack from lua state to screen */ -void LuaPrintStack(lua_State *state) { - int size = lua_gettop(state); - int i; - - for (i = 1; i <= size; i++) { - int type = lua_type(state, i); - printf("Stack size=%d, level=%d, type=%d, ", size, i, type); - - switch (type) { - case LUA_TFUNCTION: - printf("function %s", lua_tostring(state, i) ? "true" : "false"); - break; - case LUA_TBOOLEAN: - printf("bool %s", lua_toboolean(state, i) ? "true" : "false"); - break; - case LUA_TNUMBER: - printf("number %g", lua_tonumber(state, i)); - break; - case LUA_TSTRING: - printf("string `%s'", lua_tostring(state, i)); - break; - case LUA_TTABLE: - printf("table `%s'", lua_tostring(state, i)); - break; - default: - printf("other %s", lua_typename(state, type)); - break; - - } - printf("\n"); - } -} - static int LuaTxLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f, void *alstate, void *txptr, uint64_t tx_id) { SCEnter();