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