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