blob: f21f4e1b7c66a66ac8d45a309c4424e5993439fd [file] [log] [blame]
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +01001#ifndef _TYPES_HLUA_H
2#define _TYPES_HLUA_H
3
4#include <lua.h>
5
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +01006#define CLASS_CORE "Core"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +01007#define CLASS_TXN "TXN"
8
9struct session;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010010
Thierry FOURNIER380d0932015-01-23 14:27:52 +010011enum hlua_state {
12 HLUA_STOP = 0,
13 HLUA_RUN,
14};
15
16enum hlua_exec {
17 HLUA_E_OK = 0,
18 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
19 the associatedtask is waked. */
20 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
21 in the top of stack. */
22 HLUA_E_ERR, /* LUA stack execution failed without error message. */
23};
24
25struct hlua {
26 lua_State *T; /* The LUA stack. */
27 int Tref; /* The reference of the stack in coroutine case.
28 -1 for the main lua stack. */
29 int Mref; /* The reference of the memory context in coroutine case.
30 -1 if the memory context is not used. */
31 int nargs; /* The number of arguments in the stack at the start of execution. */
32 enum hlua_state state; /* The current execution state. */
33 struct task *task; /* The task associated with the lua stack execution.
34 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010035 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010036 struct ebpt_node node;
37};
38
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010039struct hlua_com {
40 struct list purge_me; /* Part of the list of signals to be purged in the
41 case of the LUA execution stack crash. */
42 struct list wake_me; /* Part of list of signals to be targeted if an
43 event occurs. */
44 struct task *task; /* The task to be wake if an event occurs. */
45};
46
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010047/* This is a part of the list containing references to functions
48 * called at the initialisation time.
49 */
50struct hlua_init_function {
51 struct list l;
52 int function_ref;
53};
54
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010055/* This struct contains the lua data used to bind
56 * Lua function on HAProxy hook like sample-fetches
57 * or actions.
58 */
59struct hlua_function {
60 char *name;
61 int function_ref;
62};
63
Thierry FOURNIER258d8aa2015-02-16 20:23:40 +010064/* This struct is used with the structs:
65 * - http_req_rule
66 * - http_res_rule
67 * - tcp_rule
68 * It contains the lua execution configuration.
69 */
70struct hlua_rule {
71 struct hlua_function fcn;
72 char **args;
73};
74
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010075/* This struct contains the pointer provided on the most
76 * of internal HAProxy calls during the processing of
77 * rules, converters and sample-fetches. This struct is
78 * associated with the lua object called "TXN".
79 */
80struct hlua_txn {
81 struct session *s;
82 struct proxy *p;
83 void *l7;
84};
85
Thierry FOURNIERd0fa5382015-02-16 20:14:51 +010086/* This struct is used as a closure argument associated
87 * with dynamic sample-fetch created fucntions. This contains
88 * a pointer to the original sample_fetch struct. It is used
89 * to identify the function to execute with the sample fetch
90 * wrapper.
91 */
92struct hlua_sample_fetch {
93 struct sample_fetch *f;
94};
95
Thierry FOURNIER5b8608f2015-02-16 19:43:25 +010096/* This struct contains data used with sleep functions. */
97struct hlua_sleep {
98 struct task *task; /* task associated with sleep. */
99 struct list com; /* list of signal to wake at the end of sleep. */
100 unsigned int wakeup_ms; /* hour to wakeup. */
101};
102
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100103#endif /* _TYPES_HLUA_H */