blob: 5920e03ef11121782ac5def29e3342c5f5152cf4 [file] [log] [blame]
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +01001#ifndef _TYPES_HLUA_H
2#define _TYPES_HLUA_H
3
Thierry FOURNIERa718b292015-03-04 16:48:34 +01004#ifdef USE_LUA
5
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +01006#include <lua.h>
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +01007#include <lauxlib.h>
8
9#include <types/proxy.h>
10#include <types/server.h>
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +010011
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010012#define CLASS_CORE "Core"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010013#define CLASS_TXN "TXN"
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +010014#define CLASS_SOCKET "Socket"
Thierry FOURNIER5a6d3fd2015-02-09 16:38:34 +010015#define CLASS_CHANNEL "Channel"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010016
17struct session;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010018
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010019#define HLUA_RUN 0x00000001
Thierry FOURNIER380d0932015-01-23 14:27:52 +010020
21enum hlua_exec {
22 HLUA_E_OK = 0,
23 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
24 the associatedtask is waked. */
25 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
26 in the top of stack. */
27 HLUA_E_ERR, /* LUA stack execution failed without error message. */
28};
29
30struct hlua {
31 lua_State *T; /* The LUA stack. */
32 int Tref; /* The reference of the stack in coroutine case.
33 -1 for the main lua stack. */
34 int Mref; /* The reference of the memory context in coroutine case.
35 -1 if the memory context is not used. */
36 int nargs; /* The number of arguments in the stack at the start of execution. */
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010037 unsigned int flags; /* The current execution flags. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010038 struct task *task; /* The task associated with the lua stack execution.
39 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010040 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010041 struct ebpt_node node;
42};
43
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010044struct hlua_com {
45 struct list purge_me; /* Part of the list of signals to be purged in the
46 case of the LUA execution stack crash. */
47 struct list wake_me; /* Part of list of signals to be targeted if an
48 event occurs. */
49 struct task *task; /* The task to be wake if an event occurs. */
50};
51
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010052/* This is a part of the list containing references to functions
53 * called at the initialisation time.
54 */
55struct hlua_init_function {
56 struct list l;
57 int function_ref;
58};
59
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010060/* This struct contains the lua data used to bind
61 * Lua function on HAProxy hook like sample-fetches
62 * or actions.
63 */
64struct hlua_function {
65 char *name;
66 int function_ref;
67};
68
Thierry FOURNIER258d8aa2015-02-16 20:23:40 +010069/* This struct is used with the structs:
70 * - http_req_rule
71 * - http_res_rule
72 * - tcp_rule
73 * It contains the lua execution configuration.
74 */
75struct hlua_rule {
76 struct hlua_function fcn;
77 char **args;
78};
79
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010080/* This struct contains the pointer provided on the most
81 * of internal HAProxy calls during the processing of
82 * rules, converters and sample-fetches. This struct is
83 * associated with the lua object called "TXN".
84 */
85struct hlua_txn {
86 struct session *s;
87 struct proxy *p;
88 void *l7;
89};
90
Thierry FOURNIERd0fa5382015-02-16 20:14:51 +010091/* This struct is used as a closure argument associated
92 * with dynamic sample-fetch created fucntions. This contains
93 * a pointer to the original sample_fetch struct. It is used
94 * to identify the function to execute with the sample fetch
95 * wrapper.
96 */
97struct hlua_sample_fetch {
98 struct sample_fetch *f;
99};
100
Thierry FOURNIER5b8608f2015-02-16 19:43:25 +0100101/* This struct contains data used with sleep functions. */
102struct hlua_sleep {
103 struct task *task; /* task associated with sleep. */
104 struct list com; /* list of signal to wake at the end of sleep. */
105 unsigned int wakeup_ms; /* hour to wakeup. */
106};
107
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100108/* This struct is used to create coprocess doing TCP or
109 * SSL I/O. It uses a fake session.
110 */
111struct hlua_socket {
112 struct session *s; /* Session used for socket I/O. */
113 luaL_Buffer b; /* buffer used to prepare strings. */
114};
115
Thierry FOURNIER5a6d3fd2015-02-09 16:38:34 +0100116/* This struct is used join to the class "channel". It
117 * just contains a pointer to the manipulated channel.
118 */
119struct hlua_channel {
120 struct channel *chn;
121};
122
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100123#else /* USE_LUA */
124
125/* Empty struct for compilation compatibility */
126struct hlua { };
127struct hlua_socket { };
128
129#endif /* USE_LUA */
130
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100131#endif /* _TYPES_HLUA_H */