Shared functions for all lua parts of the engine.
util-ip.h util-ip.c \
util-logopenfile.h util-logopenfile.c \
util-logopenfile-tile.h util-logopenfile-tile.c \
+util-lua.c util-lua.h \
util-magic.c util-magic.h \
util-memcmp.c util-memcmp.h \
util-memcpy.h \
#include <lualib.h>
#include <lauxlib.h>
-/** \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;
-extern const char lualog_ext_key_p;
-
-Packet *LuaStateGetPacket(lua_State *luastate)
-{
- lua_pushlightuserdata(luastate, (void *)&lualog_ext_key_p);
- lua_gettable(luastate, LUA_REGISTRYINDEX);
- void *p = lua_touserdata(luastate, -1);
- return (Packet *)p;
-}
-
-void *LuaStateGetTX(lua_State *luastate)
-{
- lua_pushlightuserdata(luastate, (void *)&lualog_ext_key_tx);
- lua_gettable(luastate, LUA_REGISTRYINDEX);
- void *tx = lua_touserdata(luastate, -1);
- return tx;
-}
+#include "util-lua.h"
int LuaCallbackError(lua_State *luastate, const char *msg)
{
#ifdef HAVE_LUA
-void LuaPrintStack(lua_State *state);
-
-Packet *LuaStateGetPacket(lua_State *luastate);
-void *LuaStateGetTX(lua_State *luastate);
-
int LuaCallbackError(lua_State *luastate, const char *msg);
int LuaReturnStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
const char *LuaGetStringArgument(lua_State *luastate, int argc);
#include <lualib.h>
#include <lauxlib.h>
+#include "util-lua.h"
#include "output-lua-common.h"
static int HttpGetRequestUriRaw(lua_State *luastate)
#include <lualib.h>
#include <lauxlib.h>
+#include "util-lua.h"
#include "output-lua-common.h"
#include "output-lua-http.h"
LogLuaCtx *lua_ctx;
} LogLuaThreadCtx;
-/* key for tx pointer */
-const char lualog_ext_key_tx[] = "suricata:lualog:tx:ptr";
-/* key for p (packet) pointer */
-const char lualog_ext_key_p[] = "suricata:lualog:pkt:ptr";
-
/** \internal
* \brief TX logger for lua scripts
*
SCMutexLock(&td->lua_ctx->m);
- /* we need the p in our callbacks */
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)&lualog_ext_key_p);
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)p);
- lua_settable(td->lua_ctx->luastate, LUA_REGISTRYINDEX);
- /* we need the tx in our callbacks */
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)&lualog_ext_key_tx);
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)txptr);
- lua_settable(td->lua_ctx->luastate, LUA_REGISTRYINDEX);
+ LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p);
+ LuaStateSetTX(td->lua_ctx->luastate, txptr);
/* prepare data to pass to script */
lua_getglobal(td->lua_ctx->luastate, "log");
lua_getglobal(td->lua_ctx->luastate, "log");
- /* we need the p in our callbacks */
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)&lualog_ext_key_p);
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)p);
- lua_settable(td->lua_ctx->luastate, LUA_REGISTRYINDEX);
+ LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p);
/* prepare data to pass to script */
lua_newtable(td->lua_ctx->luastate);
SCMutexLock(&td->lua_ctx->m);
lua_getglobal(td->lua_ctx->luastate, "log");
- /* we need the p in our callbacks */
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)&lualog_ext_key_p);
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)p);
- lua_settable(td->lua_ctx->luastate, LUA_REGISTRYINDEX);
+ LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p);
/* prepare data to pass to script */
lua_newtable(td->lua_ctx->luastate);
SCMutexLock(&td->lua_ctx->m);
- /* we need the p in our callbacks */
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)&lualog_ext_key_p);
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)p);
- lua_settable(td->lua_ctx->luastate, LUA_REGISTRYINDEX);
- /* we need the tx in our callbacks */
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)&lualog_ext_key_tx);
- lua_pushlightuserdata(td->lua_ctx->luastate, (void *)txptr);
- lua_settable(td->lua_ctx->luastate, LUA_REGISTRYINDEX);
+ LuaStateSetPacket(td->lua_ctx->luastate, (Packet *)p);
+ LuaStateSetTX(td->lua_ctx->luastate, txptr);
/* get the lua function to call */
lua_getglobal(td->lua_ctx->luastate, "log");
--- /dev/null
+/* Copyright (C) 2014 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/**
+ * \file
+ *
+ * \author Victor Julien <victor@inliniac.net>
+ *
+ * Common function for Lua
+ */
+
+#include "suricata-common.h"
+#include "debug.h"
+#include "detect.h"
+#include "pkt-var.h"
+#include "conf.h"
+
+#include "threads.h"
+#include "threadvars.h"
+#include "tm-threads.h"
+
+#include "util-print.h"
+#include "util-unittest.h"
+
+#include "util-debug.h"
+
+#include "output.h"
+#include "app-layer-htp.h"
+#include "app-layer.h"
+#include "app-layer-parser.h"
+#include "util-privs.h"
+#include "util-buffer.h"
+#include "util-proto-name.h"
+#include "util-logopenfile.h"
+#include "util-time.h"
+
+#ifdef HAVE_LUA
+
+#include <lua.h>
+#include <lualib.h>
+#include <lauxlib.h>
+
+/* key for tx pointer */
+const char lua_ext_key_tx[] = "suricata:lua:tx:ptr";
+/* key for p (packet) pointer */
+const char lua_ext_key_p[] = "suricata:lua:pkt:ptr";
+
+/** \brief get packet pointer from the lua state */
+Packet *LuaStateGetPacket(lua_State *luastate)
+{
+ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_p);
+ lua_gettable(luastate, LUA_REGISTRYINDEX);
+ void *p = lua_touserdata(luastate, -1);
+ return (Packet *)p;
+}
+
+void LuaStateSetPacket(lua_State *luastate, Packet *p)
+{
+ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_p);
+ lua_pushlightuserdata(luastate, (void *)p);
+ lua_settable(luastate, LUA_REGISTRYINDEX);
+}
+
+/** \brief get tx pointer from the lua state */
+void *LuaStateGetTX(lua_State *luastate)
+{
+ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tx);
+ lua_gettable(luastate, LUA_REGISTRYINDEX);
+ void *tx = lua_touserdata(luastate, -1);
+ return tx;
+}
+
+void LuaStateSetTX(lua_State *luastate, void *txptr)
+{
+ lua_pushlightuserdata(luastate, (void *)&lua_ext_key_tx);
+ lua_pushlightuserdata(luastate, (void *)txptr);
+ lua_settable(luastate, LUA_REGISTRYINDEX);
+}
+
+/** \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");
+ }
+}
+
+
+
+
+#endif /* HAVE_LUA */
--- /dev/null
+/* Copyright (C) 2014 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+/**
+ * \file
+ *
+ * \author Victor Julien <victor@inliniac.net>
+ */
+
+#ifndef __UTIL_LUA_H__
+#define __UTIL_LUA_H__
+
+#ifdef HAVE_LUA
+
+Packet *LuaStateGetPacket(lua_State *luastate);
+void *LuaStateGetTX(lua_State *luastate);
+
+void LuaStateSetPacket(lua_State *luastate, Packet *p);
+void LuaStateSetTX(lua_State *luastate, void *tx);
+
+void LuaPrintStack(lua_State *state);
+
+#endif /* HAVE_LUA */
+
+#endif /* __UTIL_LUA_H__ */