suricata
util-lua.h
Go to the documentation of this file.
1 /* Copyright (C) 2014-2022 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 
40 typedef struct LuaStreamingBuffer_ {
41  const uint8_t *data;
42  uint32_t data_len;
43  uint8_t flags;
44 } LuaStreamingBuffer;
45 
46 lua_State *LuaGetState(void);
47 void LuaReturnState(lua_State *s);
48 
49 /* gets */
50 
51 /** \brief get tv pointer from the lua state */
52 ThreadVars *LuaStateGetThreadVars(lua_State *luastate);
53 
54 Packet *LuaStateGetPacket(lua_State *luastate);
55 void *LuaStateGetTX(lua_State *luastate);
56 
57 /** \brief get flow pointer from lua state
58  *
59  * \retval f flow poiner or NULL if it was not set
60  */
61 Flow *LuaStateGetFlow(lua_State *luastate);
62 
63 PacketAlert *LuaStateGetPacketAlert(lua_State *luastate);
64 
65 Signature *LuaStateGetSignature(lua_State *luastate);
66 
67 /** \brief get file pointer from the lua state */
68 File *LuaStateGetFile(lua_State *luastate);
69 
70 /** \brief get detect engine thread context pointer from the lua state */
71 DetectEngineThreadCtx *LuaStateGetDetCtx(lua_State *luastate);
72 
73 LuaStreamingBuffer *LuaStateGetStreamingBuffer(lua_State *luastate);
74 
75 int LuaStateGetDirection(lua_State *luastate);
76 
77 /* sets */
78 
79 void LuaStateSetPacket(lua_State *luastate, Packet *p);
80 void LuaStateSetTX(lua_State *luastate, void *tx);
81 
82 /** \brief set a flow pointer in the lua state
83  *
84  * \param f flow pointer
85  */
86 void LuaStateSetFlow(lua_State *luastate, Flow *f);
87 
88 void LuaStateSetPacketAlert(lua_State *luastate, PacketAlert *pa);
89 
90 void LuaStateSetSignature(lua_State *luastate, const Signature *s);
91 
92 void LuaStateSetFile(lua_State *luastate, File *file);
93 
94 void LuaStateSetDetCtx(lua_State *luastate, DetectEngineThreadCtx *det_ctx);
95 
96 void LuaStateSetThreadVars(lua_State *luastate, ThreadVars *tv);
97 
98 void LuaStateSetStreamingBuffer(lua_State *luastate, LuaStreamingBuffer *b);
99 
100 void LuaStateSetDirection(lua_State *luastate, int direction);
101 
102 void LuaPrintStack(lua_State *state);
103 
104 int LuaPushStringBuffer(lua_State *luastate, const uint8_t *input, size_t input_len);
105 
106 int LuaPushInteger(lua_State *luastate, lua_Integer n);
107 
108 #endif /* HAVE_LUA */
109 
110 #endif /* __UTIL_LUA_H__ */
lua_State
void lua_State
Definition: util-lua.h:31
Flow_
Flow data structure.
Definition: flow.h:353
DetectEngineThreadCtx_
Definition: detect.h:1034
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:56
Packet_
Definition: decode.h:434
File_
Definition: util-file.h:75
flags
uint8_t flags
Definition: decode-gre.h:0
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:31
Signature_
Signature container.
Definition: detect.h:540
PacketAlert_
Definition: decode.h:271