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