blob: ac56c2ab307094a41a3e677ccf6e7ff64aeec446 [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 FOURNIER0efc94c2015-09-16 21:22:28 +020012#define CLASS_CORE "Core"
13#define CLASS_TXN "TXN"
14#define CLASS_FETCHES "Fetches"
15#define CLASS_CONVERTERS "Converters"
16#define CLASS_SOCKET "Socket"
17#define CLASS_CHANNEL "Channel"
18#define CLASS_HTTP "HTTP"
19#define CLASS_MAP "Map"
Thierry FOURNIERf0a64b62015-09-19 12:36:17 +020020#define CLASS_APPLET_TCP "AppletTCP"
Thierry FOURNIERa30b5db2015-09-18 09:04:27 +020021#define CLASS_APPLET_HTTP "AppletHTTP"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010022
Willy Tarreau87b09662015-04-03 00:22:06 +020023struct stream;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010024
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010025#define HLUA_RUN 0x00000001
Thierry FOURNIER4abd3ae2015-03-03 17:29:06 +010026#define HLUA_CTRLYIELD 0x00000002
Thierry FOURNIERef6a2112015-03-05 17:45:34 +010027#define HLUA_WAKERESWR 0x00000004
Thierry FOURNIER53e08ec2015-03-06 00:35:53 +010028#define HLUA_WAKEREQWR 0x00000008
Thierry FOURNIER0a99b892015-08-26 00:14:17 +020029#define HLUA_EXIT 0x00000010
Thierry FOURNIER7c39ab42015-09-27 22:53:33 +020030#define HLUA_MUST_GC 0x00000020
Thierry FOURNIER380d0932015-01-23 14:27:52 +010031
32enum hlua_exec {
33 HLUA_E_OK = 0,
34 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
35 the associatedtask is waked. */
36 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
37 in the top of stack. */
38 HLUA_E_ERR, /* LUA stack execution failed without error message. */
39};
40
41struct hlua {
42 lua_State *T; /* The LUA stack. */
43 int Tref; /* The reference of the stack in coroutine case.
44 -1 for the main lua stack. */
45 int Mref; /* The reference of the memory context in coroutine case.
46 -1 if the memory context is not used. */
47 int nargs; /* The number of arguments in the stack at the start of execution. */
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010048 unsigned int flags; /* The current execution flags. */
Thierry FOURNIERc42c1ae2015-03-03 17:17:55 +010049 int wake_time; /* The lua wants to be waked at this time, or before. */
Thierry FOURNIERbd413492015-03-03 16:52:26 +010050 int expire; /* Lua execution must be stopped over this time. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010051 struct task *task; /* The task associated with the lua stack execution.
52 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010053 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010054 struct ebpt_node node;
55};
56
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010057struct hlua_com {
58 struct list purge_me; /* Part of the list of signals to be purged in the
59 case of the LUA execution stack crash. */
60 struct list wake_me; /* Part of list of signals to be targeted if an
61 event occurs. */
62 struct task *task; /* The task to be wake if an event occurs. */
63};
64
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010065/* This is a part of the list containing references to functions
66 * called at the initialisation time.
67 */
68struct hlua_init_function {
69 struct list l;
70 int function_ref;
71};
72
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010073/* This struct contains the lua data used to bind
74 * Lua function on HAProxy hook like sample-fetches
75 * or actions.
76 */
77struct hlua_function {
78 char *name;
79 int function_ref;
80};
81
Thierry FOURNIER258d8aa2015-02-16 20:23:40 +010082/* This struct is used with the structs:
83 * - http_req_rule
84 * - http_res_rule
85 * - tcp_rule
86 * It contains the lua execution configuration.
87 */
88struct hlua_rule {
89 struct hlua_function fcn;
90 char **args;
91};
92
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010093/* This struct contains the pointer provided on the most
94 * of internal HAProxy calls during the processing of
95 * rules, converters and sample-fetches. This struct is
96 * associated with the lua object called "TXN".
97 */
98struct hlua_txn {
Willy Tarreau87b09662015-04-03 00:22:06 +020099 struct stream *s;
Thierry FOURNIER65f34c62015-02-16 20:11:43 +0100100 struct proxy *p;
Thierry FOURNIER65f34c62015-02-16 20:11:43 +0100101};
102
Thierry FOURNIERf0a64b62015-09-19 12:36:17 +0200103/* This struct contains the applet context. */
104struct hlua_appctx {
105 struct appctx *appctx;
106 luaL_Buffer b; /* buffer used to prepare strings. */
107 struct hlua_txn htxn;
108};
109
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100110/* This struc is used with sample fetches and sample converters. */
111struct hlua_smp {
Willy Tarreau87b09662015-04-03 00:22:06 +0200112 struct stream *s;
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100113 struct proxy *p;
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100114 int stringsafe;
115};
116
Thierry FOURNIER5b8608f2015-02-16 19:43:25 +0100117/* This struct contains data used with sleep functions. */
118struct hlua_sleep {
119 struct task *task; /* task associated with sleep. */
120 struct list com; /* list of signal to wake at the end of sleep. */
121 unsigned int wakeup_ms; /* hour to wakeup. */
122};
123
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100124/* This struct is used to create coprocess doing TCP or
Willy Tarreau87b09662015-04-03 00:22:06 +0200125 * SSL I/O. It uses a fake stream.
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100126 */
127struct hlua_socket {
Willy Tarreau87b09662015-04-03 00:22:06 +0200128 struct stream *s; /* Stream used for socket I/O. */
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100129 luaL_Buffer b; /* buffer used to prepare strings. */
130};
131
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100132#else /* USE_LUA */
133
134/* Empty struct for compilation compatibility */
135struct hlua { };
136struct hlua_socket { };
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200137struct hlua_rule { };
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100138
139#endif /* USE_LUA */
140
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100141#endif /* _TYPES_HLUA_H */