blob: 88a8b8d2e9b4afe332e20faa30c716e5237c39a4 [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 FOURNIERbb53c7b2015-03-11 18:28:02 +010014#define CLASS_FETCHES "Fetches"
Thierry FOURNIER594afe72015-03-10 23:58:30 +010015#define CLASS_CONVERTERS "Converters"
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +010016#define CLASS_SOCKET "Socket"
Thierry FOURNIER5a6d3fd2015-02-09 16:38:34 +010017#define CLASS_CHANNEL "Channel"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010018
19struct session;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010020
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010021#define HLUA_RUN 0x00000001
Thierry FOURNIER4abd3ae2015-03-03 17:29:06 +010022#define HLUA_CTRLYIELD 0x00000002
Thierry FOURNIERef6a2112015-03-05 17:45:34 +010023#define HLUA_WAKERESWR 0x00000004
Thierry FOURNIER53e08ec2015-03-06 00:35:53 +010024#define HLUA_WAKEREQWR 0x00000008
Thierry FOURNIER380d0932015-01-23 14:27:52 +010025
26enum hlua_exec {
27 HLUA_E_OK = 0,
28 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
29 the associatedtask is waked. */
30 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
31 in the top of stack. */
32 HLUA_E_ERR, /* LUA stack execution failed without error message. */
33};
34
35struct hlua {
36 lua_State *T; /* The LUA stack. */
37 int Tref; /* The reference of the stack in coroutine case.
38 -1 for the main lua stack. */
39 int Mref; /* The reference of the memory context in coroutine case.
40 -1 if the memory context is not used. */
41 int nargs; /* The number of arguments in the stack at the start of execution. */
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010042 unsigned int flags; /* The current execution flags. */
Thierry FOURNIERc42c1ae2015-03-03 17:17:55 +010043 int wake_time; /* The lua wants to be waked at this time, or before. */
Thierry FOURNIERbd413492015-03-03 16:52:26 +010044 int expire; /* Lua execution must be stopped over this time. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010045 struct task *task; /* The task associated with the lua stack execution.
46 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010047 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010048 struct ebpt_node node;
49};
50
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010051struct hlua_com {
52 struct list purge_me; /* Part of the list of signals to be purged in the
53 case of the LUA execution stack crash. */
54 struct list wake_me; /* Part of list of signals to be targeted if an
55 event occurs. */
56 struct task *task; /* The task to be wake if an event occurs. */
57};
58
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010059/* This is a part of the list containing references to functions
60 * called at the initialisation time.
61 */
62struct hlua_init_function {
63 struct list l;
64 int function_ref;
65};
66
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010067/* This struct contains the lua data used to bind
68 * Lua function on HAProxy hook like sample-fetches
69 * or actions.
70 */
71struct hlua_function {
72 char *name;
73 int function_ref;
74};
75
Thierry FOURNIER258d8aa2015-02-16 20:23:40 +010076/* This struct is used with the structs:
77 * - http_req_rule
78 * - http_res_rule
79 * - tcp_rule
80 * It contains the lua execution configuration.
81 */
82struct hlua_rule {
83 struct hlua_function fcn;
84 char **args;
85};
86
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010087/* This struct contains the pointer provided on the most
88 * of internal HAProxy calls during the processing of
89 * rules, converters and sample-fetches. This struct is
90 * associated with the lua object called "TXN".
91 */
92struct hlua_txn {
93 struct session *s;
94 struct proxy *p;
95 void *l7;
96};
97
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +010098/* This struc is used with sample fetches and sample converters. */
99struct hlua_smp {
100 struct session *s;
101 struct proxy *p;
102 void *l7;
103 int stringsafe;
104};
105
Thierry FOURNIERd0fa5382015-02-16 20:14:51 +0100106/* This struct is used as a closure argument associated
107 * with dynamic sample-fetch created fucntions. This contains
108 * a pointer to the original sample_fetch struct. It is used
109 * to identify the function to execute with the sample fetch
110 * wrapper.
111 */
112struct hlua_sample_fetch {
113 struct sample_fetch *f;
114};
115
Thierry FOURNIER5b8608f2015-02-16 19:43:25 +0100116/* This struct contains data used with sleep functions. */
117struct hlua_sleep {
118 struct task *task; /* task associated with sleep. */
119 struct list com; /* list of signal to wake at the end of sleep. */
120 unsigned int wakeup_ms; /* hour to wakeup. */
121};
122
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100123/* This struct is used to create coprocess doing TCP or
124 * SSL I/O. It uses a fake session.
125 */
126struct hlua_socket {
127 struct session *s; /* Session used for socket I/O. */
128 luaL_Buffer b; /* buffer used to prepare strings. */
129};
130
Thierry FOURNIER5a6d3fd2015-02-09 16:38:34 +0100131/* This struct is used join to the class "channel". It
132 * just contains a pointer to the manipulated channel.
133 */
134struct hlua_channel {
135 struct channel *chn;
Thierry FOURNIERbd1f1322015-03-05 17:04:41 +0100136 struct session *s;
Thierry FOURNIER5a6d3fd2015-02-09 16:38:34 +0100137};
138
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100139#else /* USE_LUA */
140
141/* Empty struct for compilation compatibility */
142struct hlua { };
143struct hlua_socket { };
144
145#endif /* USE_LUA */
146
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100147#endif /* _TYPES_HLUA_H */