1 /* Copyright (C) 2014 Open Information Security Foundation 2 * 3 * You can copy, redistribute or modify this Program under the terms of 4 * the GNU General Public License version 2 as published by the Free 5 * Software Foundation. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * version 2 along with this program; if not, write to the Free Software 14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 15 * 02110-1301, USA. 16 */ 17 18 /** 19 * \file 20 * 21 * \author Victor Julien <victor@inliniac.net> 22 */ 23 24 #ifndef __UTIL_LUA_H__ 25 #define __UTIL_LUA_H__ 26 27 #ifdef HAVE_LUA 28 29 #include "util-luajit.h" 30 31 typedef struct LuaStreamingBuffer_ { 32 const uint8_t *data; 33 uint32_t data_len; 34 uint8_t flags; 35 } LuaStreamingBuffer; 36 37 lua_State *LuaGetState(void); 38 void LuaReturnState(lua_State *s); 39 40 /* gets */ 41 42 /** \brief get tv pointer from the lua state */ 43 ThreadVars *LuaStateGetThreadVars(lua_State *luastate); 44 45 Packet *LuaStateGetPacket(lua_State *luastate); 46 void *LuaStateGetTX(lua_State *luastate); 47 48 /** \brief get flow pointer from lua state 49 * 50 * \retval f flow poiner or NULL if it was not set 51 */ 52 Flow *LuaStateGetFlow(lua_State *luastate); 53 54 PacketAlert *LuaStateGetPacketAlert(lua_State *luastate); 55 56 /** \brief get file pointer from the lua state */ 57 File *LuaStateGetFile(lua_State *luastate); 58 59 LuaStreamingBuffer *LuaStateGetStreamingBuffer(lua_State *luastate); 60 61 int LuaStateGetDirection(lua_State *luastate); 62 63 /* sets */ 64 65 void LuaStateSetPacket(lua_State *luastate, Packet *p); 66 void LuaStateSetTX(lua_State *luastate, void *tx); 67 68 /** \brief set a flow pointer in the lua state 69 * 70 * \param f flow pointer 71 */ 72 void LuaStateSetFlow(lua_State *luastate, Flow *f); 73 74 void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa); 75 76 void LuaStateSetFile(lua_State *luastate, File *file); 77 78 void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv); 79 80 void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b); 81 82 void LuaStateSetDirection(lua_State *luastate, int direction); 83 84 void LuaPrintStack(lua_State *state); 85 86 int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len); 87 88 int LuaPushInteger(lua_State *luastate, lua_Integer n); 89 90 #endif /* HAVE_LUA */ 91 92 #endif /* __UTIL_LUA_H__ */ 93