blob: f481bdfa9033d430a0ae8fe84ea05868fd23d32b [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 FOURNIER08504f42015-03-16 14:17:08 +010018#define CLASS_HTTP "HTTP"
Thierry FOURNIER3def3932015-04-07 11:27:54 +020019#define CLASS_MAP "Map"
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010020
Willy Tarreau87b09662015-04-03 00:22:06 +020021struct stream;
Thierry FOURNIER2ba18a22015-01-23 14:07:08 +010022
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010023#define HLUA_RUN 0x00000001
Thierry FOURNIER4abd3ae2015-03-03 17:29:06 +010024#define HLUA_CTRLYIELD 0x00000002
Thierry FOURNIERef6a2112015-03-05 17:45:34 +010025#define HLUA_WAKERESWR 0x00000004
Thierry FOURNIER53e08ec2015-03-06 00:35:53 +010026#define HLUA_WAKEREQWR 0x00000008
Thierry FOURNIER380d0932015-01-23 14:27:52 +010027
28enum hlua_exec {
29 HLUA_E_OK = 0,
30 HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when
31 the associatedtask is waked. */
32 HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message
33 in the top of stack. */
34 HLUA_E_ERR, /* LUA stack execution failed without error message. */
35};
36
37struct hlua {
38 lua_State *T; /* The LUA stack. */
39 int Tref; /* The reference of the stack in coroutine case.
40 -1 for the main lua stack. */
41 int Mref; /* The reference of the memory context in coroutine case.
42 -1 if the memory context is not used. */
43 int nargs; /* The number of arguments in the stack at the start of execution. */
Thierry FOURNIERa097fdf2015-03-03 15:17:35 +010044 unsigned int flags; /* The current execution flags. */
Thierry FOURNIERc42c1ae2015-03-03 17:17:55 +010045 int wake_time; /* The lua wants to be waked at this time, or before. */
Thierry FOURNIERbd413492015-03-03 16:52:26 +010046 int expire; /* Lua execution must be stopped over this time. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010047 struct task *task; /* The task associated with the lua stack execution.
48 We must wake this task to continue the task execution */
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010049 struct list com; /* The list head of the signals attached to this task. */
Thierry FOURNIER380d0932015-01-23 14:27:52 +010050 struct ebpt_node node;
51};
52
Thierry FOURNIER9ff7e6e2015-01-23 11:08:20 +010053struct hlua_com {
54 struct list purge_me; /* Part of the list of signals to be purged in the
55 case of the LUA execution stack crash. */
56 struct list wake_me; /* Part of list of signals to be targeted if an
57 event occurs. */
58 struct task *task; /* The task to be wake if an event occurs. */
59};
60
Thierry FOURNIERa4a0f3d2015-01-23 12:08:30 +010061/* This is a part of the list containing references to functions
62 * called at the initialisation time.
63 */
64struct hlua_init_function {
65 struct list l;
66 int function_ref;
67};
68
Thierry FOURNIERfa0e5dd2015-02-16 20:19:18 +010069/* This struct contains the lua data used to bind
70 * Lua function on HAProxy hook like sample-fetches
71 * or actions.
72 */
73struct hlua_function {
74 char *name;
75 int function_ref;
76};
77
Thierry FOURNIER258d8aa2015-02-16 20:23:40 +010078/* This struct is used with the structs:
79 * - http_req_rule
80 * - http_res_rule
81 * - tcp_rule
82 * It contains the lua execution configuration.
83 */
84struct hlua_rule {
85 struct hlua_function fcn;
86 char **args;
87};
88
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010089/* This struct contains the pointer provided on the most
90 * of internal HAProxy calls during the processing of
91 * rules, converters and sample-fetches. This struct is
92 * associated with the lua object called "TXN".
93 */
94struct hlua_txn {
Willy Tarreau87b09662015-04-03 00:22:06 +020095 struct stream *s;
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010096 struct proxy *p;
Thierry FOURNIER65f34c62015-02-16 20:11:43 +010097};
98
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +010099/* This struc is used with sample fetches and sample converters. */
100struct hlua_smp {
Willy Tarreau87b09662015-04-03 00:22:06 +0200101 struct stream *s;
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100102 struct proxy *p;
Thierry FOURNIER2694a1a2015-03-11 20:13:36 +0100103 int stringsafe;
104};
105
Thierry FOURNIER5b8608f2015-02-16 19:43:25 +0100106/* This struct contains data used with sleep functions. */
107struct hlua_sleep {
108 struct task *task; /* task associated with sleep. */
109 struct list com; /* list of signal to wake at the end of sleep. */
110 unsigned int wakeup_ms; /* hour to wakeup. */
111};
112
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100113/* This struct is used to create coprocess doing TCP or
Willy Tarreau87b09662015-04-03 00:22:06 +0200114 * SSL I/O. It uses a fake stream.
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100115 */
116struct hlua_socket {
Willy Tarreau87b09662015-04-03 00:22:06 +0200117 struct stream *s; /* Stream used for socket I/O. */
Thierry FOURNIER7e7ac322015-02-16 19:27:16 +0100118 luaL_Buffer b; /* buffer used to prepare strings. */
119};
120
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100121#else /* USE_LUA */
122
123/* Empty struct for compilation compatibility */
124struct hlua { };
125struct hlua_socket { };
Thierry FOURNIER231ef1d2015-07-30 19:03:55 +0200126struct hlua_rule { };
Thierry FOURNIERa718b292015-03-04 16:48:34 +0100127
128#endif /* USE_LUA */
129
Thierry FOURNIER6f1fd482015-01-23 14:06:13 +0100130#endif /* _TYPES_HLUA_H */