From: Victor Julien Date: Wed, 2 Apr 2014 22:09:57 +0000 (+0200) Subject: output-lua: give access to packet payload X-Git-Tag: suricata-2.1beta2~130 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=efb5c29698a4649f007809ef9a448599e4217ecd;p=thirdparty%2Fsuricata.git output-lua: give access to packet payload Add SCPacketPayload() Example: function log(args) p = SCPacketPayload() print(p) end --- diff --git a/src/output-lua-common.c b/src/output-lua-common.c index 42a584115d..2f264386ab 100644 --- a/src/output-lua-common.c +++ b/src/output-lua-common.c @@ -118,6 +118,33 @@ void LogLuaPushTableKeyValueArray(lua_State *luastate, const char *key, const ui lua_settable(luastate, -3); } +/** \internal + * \brief fill lua stack with payload + * \param luastate the lua state + * \param p packet + * \retval cnt number of data items placed on the stack + * + * Places: payload (string) + */ +static int LuaCallbackPacketPayloadPushToStackFromPacket(lua_State *luastate, const Packet *p) +{ + lua_pushlstring (luastate, (const char *)p->payload, p->payload_len); + return 1; +} + +/** \internal + * \brief Wrapper for getting payload into a lua script + * \retval cnt number of items placed on the stack + */ +static int LuaCallbackPacketPayload(lua_State *luastate) +{ + const Packet *p = LuaStateGetPacket(luastate); + if (p == NULL) + return LuaCallbackError(luastate, "internal error: no packet"); + + return LuaCallbackPacketPayloadPushToStackFromPacket(luastate, p); +} + /** \internal * \brief fill lua stack with header info * \param luastate the lua state @@ -619,6 +646,8 @@ static int LuaCallbackThreadInfo(lua_State *luastate) int LogLuaRegisterFunctions(lua_State *luastate) { /* registration of the callbacks */ + lua_pushcfunction(luastate, LuaCallbackPacketPayload); + lua_setglobal(luastate, "SCPacketPayload"); lua_pushcfunction(luastate, LuaCallbackPacketTimeString); lua_setglobal(luastate, "SCPacketTimeString"); lua_pushcfunction(luastate, LuaCallbackTuple);