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 | 2ba18a2 | 2015-01-23 14:07:08 +0100 | [diff] [blame] | 12 | #define CLASS_CORE "Core" |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 13 | #define CLASS_TXN "TXN" |
Thierry FOURNIER | bb53c7b | 2015-03-11 18:28:02 +0100 | [diff] [blame] | 14 | #define CLASS_FETCHES "Fetches" |
Thierry FOURNIER | 594afe7 | 2015-03-10 23:58:30 +0100 | [diff] [blame] | 15 | #define CLASS_CONVERTERS "Converters" |
Thierry FOURNIER | 7e7ac32 | 2015-02-16 19:27:16 +0100 | [diff] [blame] | 16 | #define CLASS_SOCKET "Socket" |
Thierry FOURNIER | 5a6d3fd | 2015-02-09 16:38:34 +0100 | [diff] [blame] | 17 | #define CLASS_CHANNEL "Channel" |
Thierry FOURNIER | 08504f4 | 2015-03-16 14:17:08 +0100 | [diff] [blame] | 18 | #define CLASS_HTTP "HTTP" |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 19 | |
| 20 | struct session; |
Thierry FOURNIER | 2ba18a2 | 2015-01-23 14:07:08 +0100 | [diff] [blame] | 21 | |
Thierry FOURNIER | a097fdf | 2015-03-03 15:17:35 +0100 | [diff] [blame] | 22 | #define HLUA_RUN 0x00000001 |
Thierry FOURNIER | 4abd3ae | 2015-03-03 17:29:06 +0100 | [diff] [blame] | 23 | #define HLUA_CTRLYIELD 0x00000002 |
Thierry FOURNIER | ef6a211 | 2015-03-05 17:45:34 +0100 | [diff] [blame] | 24 | #define HLUA_WAKERESWR 0x00000004 |
Thierry FOURNIER | 53e08ec | 2015-03-06 00:35:53 +0100 | [diff] [blame] | 25 | #define HLUA_WAKEREQWR 0x00000008 |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 26 | |
| 27 | enum hlua_exec { |
| 28 | HLUA_E_OK = 0, |
| 29 | HLUA_E_AGAIN, /* LUA yield, must resume the stack execution later, when |
| 30 | the associatedtask is waked. */ |
| 31 | HLUA_E_ERRMSG, /* LUA stack execution failed with a string error message |
| 32 | in the top of stack. */ |
| 33 | HLUA_E_ERR, /* LUA stack execution failed without error message. */ |
| 34 | }; |
| 35 | |
| 36 | struct hlua { |
| 37 | lua_State *T; /* The LUA stack. */ |
| 38 | int Tref; /* The reference of the stack in coroutine case. |
| 39 | -1 for the main lua stack. */ |
| 40 | int Mref; /* The reference of the memory context in coroutine case. |
| 41 | -1 if the memory context is not used. */ |
| 42 | 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] | 43 | unsigned int flags; /* The current execution flags. */ |
Thierry FOURNIER | c42c1ae | 2015-03-03 17:17:55 +0100 | [diff] [blame] | 44 | int wake_time; /* The lua wants to be waked at this time, or before. */ |
Thierry FOURNIER | bd41349 | 2015-03-03 16:52:26 +0100 | [diff] [blame] | 45 | int expire; /* Lua execution must be stopped over this time. */ |
Thierry FOURNIER | 380d093 | 2015-01-23 14:27:52 +0100 | [diff] [blame] | 46 | struct task *task; /* The task associated with the lua stack execution. |
| 47 | We must wake this task to continue the task execution */ |
Thierry FOURNIER | 9ff7e6e | 2015-01-23 11:08:20 +0100 | [diff] [blame] | 48 | 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] | 49 | struct ebpt_node node; |
| 50 | }; |
| 51 | |
Thierry FOURNIER | 9ff7e6e | 2015-01-23 11:08:20 +0100 | [diff] [blame] | 52 | struct hlua_com { |
| 53 | struct list purge_me; /* Part of the list of signals to be purged in the |
| 54 | case of the LUA execution stack crash. */ |
| 55 | struct list wake_me; /* Part of list of signals to be targeted if an |
| 56 | event occurs. */ |
| 57 | struct task *task; /* The task to be wake if an event occurs. */ |
| 58 | }; |
| 59 | |
Thierry FOURNIER | a4a0f3d | 2015-01-23 12:08:30 +0100 | [diff] [blame] | 60 | /* This is a part of the list containing references to functions |
| 61 | * called at the initialisation time. |
| 62 | */ |
| 63 | struct hlua_init_function { |
| 64 | struct list l; |
| 65 | int function_ref; |
| 66 | }; |
| 67 | |
Thierry FOURNIER | fa0e5dd | 2015-02-16 20:19:18 +0100 | [diff] [blame] | 68 | /* This struct contains the lua data used to bind |
| 69 | * Lua function on HAProxy hook like sample-fetches |
| 70 | * or actions. |
| 71 | */ |
| 72 | struct hlua_function { |
| 73 | char *name; |
| 74 | int function_ref; |
| 75 | }; |
| 76 | |
Thierry FOURNIER | 258d8aa | 2015-02-16 20:23:40 +0100 | [diff] [blame] | 77 | /* This struct is used with the structs: |
| 78 | * - http_req_rule |
| 79 | * - http_res_rule |
| 80 | * - tcp_rule |
| 81 | * It contains the lua execution configuration. |
| 82 | */ |
| 83 | struct hlua_rule { |
| 84 | struct hlua_function fcn; |
| 85 | char **args; |
| 86 | }; |
| 87 | |
Thierry FOURNIER | 65f34c6 | 2015-02-16 20:11:43 +0100 | [diff] [blame] | 88 | /* This struct contains the pointer provided on the most |
| 89 | * of internal HAProxy calls during the processing of |
| 90 | * rules, converters and sample-fetches. This struct is |
| 91 | * associated with the lua object called "TXN". |
| 92 | */ |
| 93 | struct hlua_txn { |
| 94 | struct session *s; |
| 95 | struct proxy *p; |
| 96 | void *l7; |
| 97 | }; |
| 98 | |
Thierry FOURNIER | 2694a1a | 2015-03-11 20:13:36 +0100 | [diff] [blame] | 99 | /* This struc is used with sample fetches and sample converters. */ |
| 100 | struct hlua_smp { |
| 101 | struct session *s; |
| 102 | struct proxy *p; |
| 103 | void *l7; |
| 104 | int stringsafe; |
| 105 | }; |
| 106 | |
Thierry FOURNIER | 5b8608f | 2015-02-16 19:43:25 +0100 | [diff] [blame] | 107 | /* This struct contains data used with sleep functions. */ |
| 108 | struct hlua_sleep { |
| 109 | struct task *task; /* task associated with sleep. */ |
| 110 | struct list com; /* list of signal to wake at the end of sleep. */ |
| 111 | unsigned int wakeup_ms; /* hour to wakeup. */ |
| 112 | }; |
| 113 | |
Thierry FOURNIER | 7e7ac32 | 2015-02-16 19:27:16 +0100 | [diff] [blame] | 114 | /* This struct is used to create coprocess doing TCP or |
| 115 | * SSL I/O. It uses a fake session. |
| 116 | */ |
| 117 | struct hlua_socket { |
| 118 | struct session *s; /* Session used for socket I/O. */ |
| 119 | luaL_Buffer b; /* buffer used to prepare strings. */ |
| 120 | }; |
| 121 | |
Thierry FOURNIER | a718b29 | 2015-03-04 16:48:34 +0100 | [diff] [blame] | 122 | #else /* USE_LUA */ |
| 123 | |
| 124 | /* Empty struct for compilation compatibility */ |
| 125 | struct hlua { }; |
| 126 | struct hlua_socket { }; |
| 127 | |
| 128 | #endif /* USE_LUA */ |
| 129 | |
Thierry FOURNIER | 6f1fd48 | 2015-01-23 14:06:13 +0100 | [diff] [blame] | 130 | #endif /* _TYPES_HLUA_H */ |