suricata
util-lua.h
Go to the documentation of this file.
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 #ifndef HAVE_LUA
28 
29 /* If we don't have Lua, create a typedef for lua_State so the
30  * exported Lua functions don't fail the build. */
31 typedef void lua_State;
32 
33 #else
34 
35 #include <lua.h>
36 #include <lualib.h>
37 #include <lauxlib.h>
38 
39 #include "util-luajit.h"
40 
41 typedef struct LuaStreamingBuffer_ {
42  const uint8_t *data;
43  uint32_t data_len;
44  uint8_t flags;
45 } LuaStreamingBuffer;
46 
47 lua_State *LuaGetState(void);
48 void LuaReturnState(lua_State *s);
49 
50 /* gets */
51 
52 /** \brief get tv pointer from the lua state */
53 ThreadVars *LuaStateGetThreadVars(lua_State *luastate);
54 
55 Packet *LuaStateGetPacket(lua_State *luastate);
56 void *LuaStateGetTX(lua_State *luastate);
57 
58 /** \brief get flow pointer from lua state
59  *
60  * \retval f flow poiner or NULL if it was not set
61  */
62 Flow *LuaStateGetFlow(lua_State *luastate);
63 
64 PacketAlert *LuaStateGetPacketAlert(lua_State *luastate);
65 
66 Signature *LuaStateGetSignature(lua_State *luastate);
67 
68 /** \brief get file pointer from the lua state */
69 File *LuaStateGetFile(lua_State *luastate);
70 
71 LuaStreamingBuffer *LuaStateGetStreamingBuffer(lua_State *luastate);
72 
73 int LuaStateGetDirection(lua_State *luastate);
74 
75 /* sets */
76 
77 void LuaStateSetPacket(lua_State *luastate, Packet *p);
78 void LuaStateSetTX(lua_State *luastate, void *tx);
79 
80 /** \brief set a flow pointer in the lua state
81  *
82  * \param f flow pointer
83  */
84 void LuaStateSetFlow(lua_State *luastate, Flow *f);
85 
86 void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa);
87 
88 void LuaStateSetSignature(lua_State *luastate, const Signature *s);
89 
90 void LuaStateSetFile(lua_State *luastate, File *file);
91 
92 void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv);
93 
94 void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b);
95 
96 void LuaStateSetDirection(lua_State *luastate, int direction);
97 
98 void LuaPrintStack(lua_State *state);
99 
100 int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
101 
102 int LuaPushInteger(lua_State *luastate, lua_Integer n);
103 
104 #endif /* HAVE_LUA */
105 
106 #endif /* __UTIL_LUA_H__ */
lua_State
void lua_State
Definition: util-lua.h:31
Flow_
Flow data structure.
Definition: flow.h:353
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
Packet_
Definition: decode.h:427
File_
Definition: util-file.h:75
flags
uint8_t flags
Definition: decode-gre.h:0
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
Signature_
Signature container.
Definition: detect.h:548
PacketAlert_
Definition: decode.h:280
util-luajit.h