blob: 851948b4a37e2664d263d44f2919676532a58654 [file] [log] [blame]
Willy Tarreau8a8d83b2015-04-13 13:24:54 +02001/*
2 * include/types/applet.h
3 * This file describes the applet struct and associated constants.
4 *
5 * Copyright (C) 2000-2015 Willy Tarreau - w@1wt.eu
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _TYPES_APPLET_H
23#define _TYPES_APPLET_H
24
25#include <types/hlua.h>
26#include <types/obj_type.h>
Thierry FOURNIERc069cfd2015-09-11 08:50:34 +020027#include <types/proxy.h>
28#include <types/stream.h>
Christopher Fauleta73e59b2016-12-09 17:30:18 +010029#include <common/buffer.h>
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020030#include <common/chunk.h>
31#include <common/config.h>
32
33struct appctx;
34
35/* Applet descriptor */
Willy Tarreau30576452015-04-13 13:50:30 +020036struct applet {
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020037 enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */
38 /* 3 unused bytes here */
39 char *name; /* applet's name to report in logs */
Thierry FOURNIERc069cfd2015-09-11 08:50:34 +020040 int (*init)(struct appctx *, struct proxy *px, struct stream *strm); /* callback to init ressources, may be NULL.
41 expect 1 if ok, 0 if an error occurs, -1 if miss data. */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020042 void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */
43 void (*release)(struct appctx *); /* callback to release resources, may be NULL */
Thierry FOURNIER1245a832015-09-22 00:02:58 +020044 unsigned int timeout; /* execution timeout. */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020045};
46
47/* Context of a running applet. */
48struct appctx {
Willy Tarreau81f38d62015-04-13 17:11:11 +020049 struct list runq; /* chaining in the applet run queue */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020050 enum obj_type obj_type; /* OBJ_TYPE_APPCTX */
51 /* 3 unused bytes here */
52 unsigned int st0; /* CLI state for stats, session state for peers */
53 unsigned int st1; /* prompt for stats, session error for peers */
54 unsigned int st2; /* output state for stats, unused by peers */
Willy Tarreau30576452015-04-13 13:50:30 +020055 struct applet *applet; /* applet this context refers to */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020056 void *owner; /* pointer to upper layer's entity (eg: stream interface) */
Thierry FOURNIER5a363e72015-09-27 19:29:33 +020057 struct act_rule *rule; /* rule associated with the applet. */
Willy Tarreau3b6e5472016-11-24 15:53:53 +010058 int (*io_handler)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK */
59 void (*io_release)(struct appctx *appctx); /* used within the cli_io_handler when st0 = CLI_ST_CALLBACK,
Thierry FOURNIER / OZON.IO6a22dcb2016-11-12 10:51:33 +010060 if the command is terminated or the session released */
Christopher Fauleta73e59b2016-12-09 17:30:18 +010061 struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +020062
63 union {
64 struct {
Willy Tarreauebec3512016-12-16 12:14:12 +010065 void *ptr; /* multi-purpose pointer for peers */
66 } peers; /* used by the peers applet */
67 struct {
68 int connected;
69 struct hlua_socket *socket;
70 struct list wake_on_read;
71 struct list wake_on_write;
72 } hlua_cosocket; /* used by the Lua cosockets */
73 struct {
74 struct hlua *hlua;
75 int flags;
76 struct task *task;
77 } hlua_apptcp; /* used by the Lua TCP services */
78 struct {
79 struct hlua *hlua;
80 int left_bytes; /* The max amount of bytes that we can read. */
81 int flags;
82 int status;
Robin H. Johnson52f5db22017-01-01 13:10:52 -080083 const char *reason;
Willy Tarreauebec3512016-12-16 12:14:12 +010084 struct task *task;
85 } hlua_apphttp; /* used by the Lua HTTP services */
86 struct {
87 struct task *task;
Willy Tarreauebec3512016-12-16 12:14:12 +010088 void *agent;
89 unsigned int version;
90 unsigned int max_frame_size;
Christopher Fauleta1cda022016-12-21 08:58:06 +010091 unsigned int flags;
92 struct list waiting_queue;
Willy Tarreauebec3512016-12-16 12:14:12 +010093 struct list list;
94 } spoe; /* used by SPOE filter */
95 struct {
96 const char *msg; /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
97 char *err; /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
Willy Tarreaua2d58722016-12-16 12:37:03 +010098 void *p0, *p1; /* general purpose pointers and integers for registered commands, initialized */
99 int i0, i1; /* to 0 by the CLI before first invocation of the keyword parser. */
Willy Tarreauebec3512016-12-16 12:14:12 +0100100 } cli; /* context used by the CLI */
101
102 /* all entries below are used by various CLI commands, please
103 * keep the grouped together and avoid adding new ones.
104 */
105 struct {
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200106 struct proxy *px;
107 struct server *sv;
108 void *l;
109 int scope_str; /* limit scope to a frontend/backend substring */
110 int scope_len; /* length of the string above in the buffer */
111 int px_st; /* STAT_PX_ST* */
112 unsigned int flags; /* STAT_* */
113 int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */
114 int st_code; /* the status code returned by an action */
115 } stats;
116 struct {
117 struct bref bref; /* back-reference from the session being dumped */
118 void *target; /* session we want to dump, or NULL for all */
119 unsigned int uid; /* if non-null, the uniq_id of the session being dumped */
120 int section; /* section of the session being dumped */
121 int pos; /* last position of the current session's buffer */
122 } sess;
123 struct {
124 int iid; /* if >= 0, ID of the proxy to filter on */
125 struct proxy *px; /* current proxy being dumped, NULL = not started yet. */
Willy Tarreau35069f82016-11-25 09:16:37 +0100126 unsigned int flag; /* bit0: buffer being dumped, 0 = req, 1 = resp ; bit1=skip req ; bit2=skip resp. */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200127 unsigned int sid; /* session ID of error being dumped */
128 int ptr; /* <0: headers, >=0 : text pointer to restart from */
129 int bol; /* pointer to beginning of current line */
130 } errors;
131 struct {
132 void *target; /* table we want to dump, or NULL for all */
133 struct proxy *proxy; /* table being currently dumped (first if NULL) */
134 struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */
135 long long value; /* value to compare against */
136 signed char data_type; /* type of data to compare, or -1 if none */
137 signed char data_op; /* operator (STD_OP_*) when data_type set */
Willy Tarreaua24bc782016-12-14 15:50:35 +0100138 char action; /* action on the table : one of STK_CLI_ACT_* */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200139 } table;
140 struct {
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200141 unsigned int display_flags;
142 struct pat_ref *ref;
143 struct pat_ref_elt *elt;
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200144 struct pattern_expr *expr;
145 struct chunk chunk;
146 } map;
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200147 struct {
Thierry FOURNIERebed6e92016-12-16 11:54:07 +0100148 struct hlua *hlua;
Thierry FOURNIER / OZON.IOa44fdd92016-11-13 13:19:20 +0100149 struct task *task;
Willy Tarreau8ae4f752016-12-14 15:41:45 +0100150 struct hlua_function *fcn;
Thierry FOURNIER / OZON.IOa44fdd92016-11-13 13:19:20 +0100151 } hlua_cli;
Willy Tarreauebec3512016-12-16 12:14:12 +0100152 /* NOTE: please add regular applet contexts (ie: not
153 * CLI-specific ones) above, before "cli".
154 */
155 } ctx; /* context-specific variables used by any applet */
Willy Tarreau8a8d83b2015-04-13 13:24:54 +0200156};
157
158#endif /* _TYPES_APPLET_H */
159
160/*
161 * Local variables:
162 * c-indent-level: 8
163 * c-basic-offset: 8
164 * End:
165 */