Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 1 | #ifndef _TYPES_HLUA_H |
| 2 | #define _TYPES_HLUA_H |
| 3 | |
Thierry FOURNIER | a718b29 | 2015-03-04 16:48:34 +0100 | [diff] [blame] | 4 | #ifdef USE_LUA |
| 5 | |
Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 6 | #include <lua.h> |
Thierry FOURNIER | 7e7ac32 | 2015-02-16 19:27:16 +0100 | [diff] [blame] | 7 | #include <lauxlib.h> |
| 8 | |
| 9 | #include <types/proxy.h> |
| 10 | #include <types/server.h> |
Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 11 | |
Thierry FOURNIER | 0efc94c | 2015-09-16 21:22:28 +0200 | [diff] [blame] | 12 | #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 FOURNIER | f0a64b6 | 2015-09-19 12:36:17 +0200 | [diff] [blame] | 20 | #define CLASS_APPLET_TCP "AppletTCP" |
Thierry FOURNIER | a30b5db | 2015-09-18 09:04:27 +0200 | [diff] [blame] | 21 | #define CLASS_APPLET_HTTP "AppletHTTP" |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 22 | |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 23 | struct stream; |
Thierry FOURNIER | 2ba18a2 | 2015-01-23 14:07:08 +0100 | [diff] [blame] | 24 | |
Thierry FOURNIER | a097fdf | 2015-03-03 15:17:35 +0100 | [diff] [blame] | 25 | #define HLUA_RUN 0x00000001 |
Thierry FOURNIER | 4abd3ae | 2015-03-03 17:29:06 +0100 | [diff] [blame] | 26 | #define HLUA_CTRLYIELD 0x00000002 |
Thierry FOURNIER | ef6a211 | 2015-03-05 17:45:34 +0100 | [diff] [blame] | 27 | #define HLUA_WAKERESWR 0x00000004 |
Thierry FOURNIER | 53e08ec | 2015-03-06 00:35:53 +0100 | [diff] [blame] | 28 | #define HLUA_WAKEREQWR 0x00000008 |
Thierry FOURNIER | 0a99b89 | 2015-08-26 00:14:17 +0200 | [diff] [blame] | 29 | #define HLUA_EXIT 0x00000010 |
Thierry FOURNIER | 7c39ab4 | 2015-09-27 22:53:33 +0200 | [diff] [blame] | 30 | #define HLUA_MUST_GC 0x00000020 |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 31 | |
Thierry FOURNIER | 7fa0549 | 2015-12-20 18:42:25 +0100 | [diff] [blame] | 32 | #define HLUA_F_AS_STRING 0x01 |
Thierry FOURNIER | ca98866 | 2015-12-20 18:43:03 +0100 | [diff] [blame] | 33 | #define HLUA_F_MAY_USE_HTTP 0x02 |
Thierry FOURNIER | 7fa0549 | 2015-12-20 18:42:25 +0100 | [diff] [blame] | 34 | |
Thierry Fournier | 49d4842 | 2016-02-19 12:09:29 +0100 | [diff] [blame] | 35 | #define HLUA_CONCAT_BLOCSZ 2048 |
| 36 | |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 37 | enum hlua_exec { |
| 38 | HLUA_E_OK = 0, |
| 39 | HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when |
| 40 | the associatedtask is waked. */ |
| 41 | HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message |
| 42 | in the top of stack. */ |
| 43 | HLUA_E_ERR, /* LUA stack execution failed without error message. */ |
| 44 | }; |
| 45 | |
| 46 | struct hlua { |
| 47 | lua_State *T; /* The LUA stack. */ |
| 48 | int Tref; /* The reference of the stack in coroutine case. |
| 49 | -1 for the main lua stack. */ |
| 50 | int Mref; /* The reference of the memory context in coroutine case. |
| 51 | -1 if the memory context is not used. */ |
| 52 | int nargs; /* The number of arguments in the stack at the start of execution. */ |
Thierry FOURNIER | a097fdf | 2015-03-03 15:17:35 +0100 | [diff] [blame] | 53 | unsigned int flags; /* The current execution flags. */ |
Thierry FOURNIER | c42c1ae | 2015-03-03 17:17:55 +0100 | [diff] [blame] | 54 | int wake_time; /* The lua wants to be waked at this time, or before. */ |
Thierry FOURNIER | 10770fa | 2015-09-29 01:59:42 +0200 | [diff] [blame] | 55 | unsigned int max_time; /* The max amount of execution time for an Lua process, in ms. */ |
| 56 | unsigned int start_time; /* The ms time when the Lua starts the last execution. */ |
| 57 | unsigned int run_time; /* Lua total execution time in ms. */ |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 58 | struct task *task; /* The task associated with the lua stack execution. |
| 59 | We must wake this task to continue the task execution */ |
Thierry FOURNIER | 9ff7e6e | 2015-01-23 11:08:20 +0100 | [diff] [blame] | 60 | struct list com; /* The list head of the signals attached to this task. */ |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 61 | struct ebpt_node node; |
| 62 | }; |
| 63 | |
Thierry FOURNIER | 9ff7e6e | 2015-01-23 11:08:20 +0100 | [diff] [blame] | 64 | struct hlua_com { |
| 65 | struct list purge_me; /* Part of the list of signals to be purged in the |
| 66 | case of the LUA execution stack crash. */ |
| 67 | struct list wake_me; /* Part of list of signals to be targeted if an |
| 68 | event occurs. */ |
| 69 | struct task *task; /* The task to be wake if an event occurs. */ |
| 70 | }; |
| 71 | |
Thierry FOURNIER | a4a0f3d | 2015-01-23 12:08:30 +0100 | [diff] [blame] | 72 | /* This is a part of the list containing references to functions |
| 73 | * called at the initialisation time. |
| 74 | */ |
| 75 | struct hlua_init_function { |
| 76 | struct list l; |
| 77 | int function_ref; |
| 78 | }; |
| 79 | |
Thierry FOURNIER | fa0e5dd | 2015-02-16 20:19:18 +0100 | [diff] [blame] | 80 | /* This struct contains the lua data used to bind |
| 81 | * Lua function on HAProxy hook like sample-fetches |
| 82 | * or actions. |
| 83 | */ |
| 84 | struct hlua_function { |
| 85 | char *name; |
| 86 | int function_ref; |
| 87 | }; |
| 88 | |
Thierry FOURNIER | 258d8aa | 2015-02-16 20:23:40 +0100 | [diff] [blame] | 89 | /* This struct is used with the structs: |
| 90 | * - http_req_rule |
| 91 | * - http_res_rule |
| 92 | * - tcp_rule |
| 93 | * It contains the lua execution configuration. |
| 94 | */ |
| 95 | struct hlua_rule { |
| 96 | struct hlua_function fcn; |
| 97 | char **args; |
| 98 | }; |
| 99 | |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 100 | /* This struct contains the pointer provided on the most |
| 101 | * of internal HAProxy calls during the processing of |
| 102 | * rules, converters and sample-fetches. This struct is |
| 103 | * associated with the lua object called "TXN". |
| 104 | */ |
| 105 | struct hlua_txn { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 106 | struct stream *s; |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 107 | struct proxy *p; |
Thierry FOURNIER | c4eebc8 | 2015-11-02 10:01:59 +0100 | [diff] [blame] | 108 | int dir; /* SMP_OPT_DIR_{REQ,RES} */ |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
Thierry FOURNIER | f0a64b6 | 2015-09-19 12:36:17 +0200 | [diff] [blame] | 111 | /* This struct contains the applet context. */ |
| 112 | struct hlua_appctx { |
| 113 | struct appctx *appctx; |
| 114 | luaL_Buffer b; /* buffer used to prepare strings. */ |
| 115 | struct hlua_txn htxn; |
| 116 | }; |
| 117 | |
Thierry FOURNIER | 2694a1a | 2015-03-11 20:13:36 +0100 | [diff] [blame] | 118 | /* This struc is used with sample fetches and sample converters. */ |
| 119 | struct hlua_smp { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 120 | struct stream *s; |
Thierry FOURNIER | 2694a1a | 2015-03-11 20:13:36 +0100 | [diff] [blame] | 121 | struct proxy *p; |
Thierry FOURNIER | 7fa0549 | 2015-12-20 18:42:25 +0100 | [diff] [blame] | 122 | unsigned int flags; /* LUA_F_OPT_* */ |
Thierry FOURNIER | c4eebc8 | 2015-11-02 10:01:59 +0100 | [diff] [blame] | 123 | int dir; /* SMP_OPT_DIR_{REQ,RES} */ |
Thierry FOURNIER | 2694a1a | 2015-03-11 20:13:36 +0100 | [diff] [blame] | 124 | }; |
| 125 | |
Thierry FOURNIER | 5b8608f | 2015-02-16 19:43:25 +0100 | [diff] [blame] | 126 | /* This struct contains data used with sleep functions. */ |
| 127 | struct hlua_sleep { |
| 128 | struct task *task; /* task associated with sleep. */ |
| 129 | struct list com; /* list of signal to wake at the end of sleep. */ |
| 130 | unsigned int wakeup_ms; /* hour to wakeup. */ |
| 131 | }; |
| 132 | |
Thierry FOURNIER | 7e7ac32 | 2015-02-16 19:27:16 +0100 | [diff] [blame] | 133 | /* This struct is used to create coprocess doing TCP or |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 134 | * SSL I/O. It uses a fake stream. |
Thierry FOURNIER | 7e7ac32 | 2015-02-16 19:27:16 +0100 | [diff] [blame] | 135 | */ |
| 136 | struct hlua_socket { |
Willy Tarreau | 87b0966 | 2015-04-03 00:22:06 +0200 | [diff] [blame] | 137 | struct stream *s; /* Stream used for socket I/O. */ |
Thierry FOURNIER | 7e7ac32 | 2015-02-16 19:27:16 +0100 | [diff] [blame] | 138 | luaL_Buffer b; /* buffer used to prepare strings. */ |
| 139 | }; |
| 140 | |
Thierry Fournier | 49d4842 | 2016-02-19 12:09:29 +0100 | [diff] [blame] | 141 | struct hlua_concat { |
| 142 | int size; |
| 143 | int len; |
| 144 | }; |
| 145 | |
Thierry FOURNIER | a718b29 | 2015-03-04 16:48:34 +0100 | [diff] [blame] | 146 | #else /* USE_LUA */ |
| 147 | |
| 148 | /* Empty struct for compilation compatibility */ |
| 149 | struct hlua { }; |
| 150 | struct hlua_socket { }; |
Thierry FOURNIER | 231ef1d | 2015-07-30 19:03:55 +0200 | [diff] [blame] | 151 | struct hlua_rule { }; |
Thierry FOURNIER | a718b29 | 2015-03-04 16:48:34 +0100 | [diff] [blame] | 152 | |
| 153 | #endif /* USE_LUA */ |
| 154 | |
Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 155 | #endif /* _TYPES_HLUA_H */ |