From: Willy Tarreau Date: Mon, 13 Apr 2015 11:24:54 +0000 (+0200) Subject: REORG: applet: move the applet definitions out of stream_interface X-Git-Tag: v1.6-dev2~197 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a8d83b85cb7a1be8d25cb5fd400591e0829a62b;p=thirdparty%2Fhaproxy.git REORG: applet: move the applet definitions out of stream_interface We're tidying the definitions so that appctx lives on its own. A new set of applet.h files has been added for this purpose. --- diff --git a/include/proto/applet.h b/include/proto/applet.h new file mode 100644 index 0000000000..61bca0259f --- /dev/null +++ b/include/proto/applet.h @@ -0,0 +1,73 @@ +/* + * include/proto/applet.h + * This file contains applet function prototypes + * + * Copyright (C) 2000-2015 Willy Tarreau - w@1wt.eu + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _PROTO_APPLET_H +#define _PROTO_APPLET_H + +#include + +#include +#include +#include + +/* Initializes all required fields for a new appctx. Note that it does the + * minimum acceptable initialization for an appctx. This means only the + * 3 integer states st0, st1, st2 are zeroed. + */ +static inline void appctx_init(struct appctx *appctx) +{ + appctx->st0 = appctx->st1 = appctx->st2 = 0; +} + +/* Tries to allocate a new appctx and initialize its main fields. The appctx + * is returned on success, NULL on failure. The appctx must be released using + * pool_free2(connection) or appctx_free(), since it's allocated from the + * connection pool. is assigned as the applet, but it can be NULL. + */ +static inline struct appctx *appctx_new(struct si_applet *applet) +{ + struct appctx *appctx; + + appctx = pool_alloc2(pool2_connection); + if (likely(appctx != NULL)) { + appctx->obj_type = OBJ_TYPE_APPCTX; + appctx->applet = applet; + appctx_init(appctx); + } + return appctx; +} + +/* Releases an appctx previously allocated by appctx_new(). Note that + * we share the connection pool. + */ +static inline void appctx_free(struct appctx *appctx) +{ + pool_free2(pool2_connection, appctx); +} + +#endif /* _PROTO_APPLET_H */ + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/include/proto/dumpstats.h b/include/proto/dumpstats.h index 61e39bf9d7..cbbb802a47 100644 --- a/include/proto/dumpstats.h +++ b/include/proto/dumpstats.h @@ -24,6 +24,7 @@ #define _PROTO_DUMPSTATS_H #include +#include #include /* Flags for applet.ctx.stats.flags */ diff --git a/include/proto/obj_type.h b/include/proto/obj_type.h index a02e1d6923..6d6577cb68 100644 --- a/include/proto/obj_type.h +++ b/include/proto/obj_type.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/include/proto/stream_interface.h b/include/proto/stream_interface.h index ec52f1e60e..264596166c 100644 --- a/include/proto/stream_interface.h +++ b/include/proto/stream_interface.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -103,41 +104,6 @@ static inline struct stream_interface *si_opposite(struct stream_interface *si) return &LIST_ELEM(si, struct stream *, si[0])->si[1]; } -/* Initializes all required fields for a new appctx. Note that it does the - * minimum acceptable initialization for an appctx. This means only the - * 3 integer states st0, st1, st2 are zeroed. - */ -static inline void appctx_init(struct appctx *appctx) -{ - appctx->st0 = appctx->st1 = appctx->st2 = 0; -} - -/* Tries to allocate a new appctx and initialize its main fields. The appctx - * is returned on success, NULL on failure. The appctx must be released using - * pool_free2(connection) or appctx_free(), since it's allocated from the - * connection pool. is assigned as the applet, but it can be NULL. - */ -static inline struct appctx *appctx_new(struct si_applet *applet) -{ - struct appctx *appctx; - - appctx = pool_alloc2(pool2_connection); - if (likely(appctx != NULL)) { - appctx->obj_type = OBJ_TYPE_APPCTX; - appctx->applet = applet; - appctx_init(appctx); - } - return appctx; -} - -/* Releases an appctx previously allocated by appctx_new(). Note that - * we share the connection pool. - */ -static inline void appctx_free(struct appctx *appctx) -{ - pool_free2(pool2_connection, appctx); -} - /* initializes a stream interface in the SI_ST_INI state. It's detached from * any endpoint and only keeps its side which is expected to have already been * set. diff --git a/include/types/applet.h b/include/types/applet.h new file mode 100644 index 0000000000..9146ee4fde --- /dev/null +++ b/include/types/applet.h @@ -0,0 +1,117 @@ +/* + * include/types/applet.h + * This file describes the applet struct and associated constants. + * + * Copyright (C) 2000-2015 Willy Tarreau - w@1wt.eu + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation, version 2.1 + * exclusively. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef _TYPES_APPLET_H +#define _TYPES_APPLET_H + +#include +#include +#include +#include + +struct appctx; + +/* Applet descriptor */ +struct si_applet { + enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */ + /* 3 unused bytes here */ + char *name; /* applet's name to report in logs */ + void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */ + void (*release)(struct appctx *); /* callback to release resources, may be NULL */ +}; + +/* Context of a running applet. */ +struct appctx { + enum obj_type obj_type; /* OBJ_TYPE_APPCTX */ + /* 3 unused bytes here */ + unsigned int st0; /* CLI state for stats, session state for peers */ + unsigned int st1; /* prompt for stats, session error for peers */ + unsigned int st2; /* output state for stats, unused by peers */ + struct si_applet *applet; /* applet this context refers to */ + void *owner; /* pointer to upper layer's entity (eg: stream interface) */ + + union { + struct { + struct proxy *px; + struct server *sv; + void *l; + int scope_str; /* limit scope to a frontend/backend substring */ + int scope_len; /* length of the string above in the buffer */ + int px_st; /* STAT_PX_ST* */ + unsigned int flags; /* STAT_* */ + int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */ + int st_code; /* the status code returned by an action */ + } stats; + struct { + struct bref bref; /* back-reference from the session being dumped */ + void *target; /* session we want to dump, or NULL for all */ + unsigned int uid; /* if non-null, the uniq_id of the session being dumped */ + int section; /* section of the session being dumped */ + int pos; /* last position of the current session's buffer */ + } sess; + struct { + int iid; /* if >= 0, ID of the proxy to filter on */ + struct proxy *px; /* current proxy being dumped, NULL = not started yet. */ + unsigned int buf; /* buffer being dumped, 0 = req, 1 = rep */ + unsigned int sid; /* session ID of error being dumped */ + int ptr; /* <0: headers, >=0 : text pointer to restart from */ + int bol; /* pointer to beginning of current line */ + } errors; + struct { + void *target; /* table we want to dump, or NULL for all */ + struct proxy *proxy; /* table being currently dumped (first if NULL) */ + struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ + long long value; /* value to compare against */ + signed char data_type; /* type of data to compare, or -1 if none */ + signed char data_op; /* operator (STD_OP_*) when data_type set */ + } table; + struct { + const char *msg; /* pointer to a persistent message to be returned in PRINT state */ + char *err; /* pointer to a 'must free' message to be returned in PRINT_FREE state */ + } cli; + struct { + void *ptr; /* multi-purpose pointer for peers */ + } peers; + struct { + unsigned int display_flags; + struct pat_ref *ref; + struct pat_ref_elt *elt; + struct map_descriptor *desc; + struct pattern_expr *expr; + struct chunk chunk; + } map; + struct { + int connected; + struct hlua_socket *socket; + struct list wake_on_read; + struct list wake_on_write; + } hlua; + } ctx; /* used by stats I/O handlers to dump the stats */ +}; + +#endif /* _TYPES_APPLET_H */ + +/* + * Local variables: + * c-indent-level: 8 + * c-basic-offset: 8 + * End: + */ diff --git a/include/types/stream_interface.h b/include/types/stream_interface.h index 7e688cfeca..9b228e57c8 100644 --- a/include/types/stream_interface.h +++ b/include/types/stream_interface.h @@ -22,10 +22,6 @@ #ifndef _TYPES_STREAM_INTERFACE_H #define _TYPES_STREAM_INTERFACE_H -#include -#include - -#include #include #include @@ -103,17 +99,6 @@ struct stream_interface { int conn_retries; /* number of connect retries left */ }; -struct appctx; - -/* An applet designed to run in a stream interface */ -struct si_applet { - enum obj_type obj_type; /* object type = OBJ_TYPE_APPLET */ - /* 3 unused bytes here */ - char *name; /* applet's name to report in logs */ - void (*fct)(struct appctx *); /* internal I/O handler, may never be NULL */ - void (*release)(struct appctx *); /* callback to release resources, may be NULL */ -}; - /* operations available on a stream-interface */ struct si_ops { void (*update)(struct stream_interface *); /* I/O update function */ @@ -123,75 +108,6 @@ struct si_ops { void (*shutw)(struct stream_interface *); /* shut write function */ }; -/* Context of a running applet. */ -struct appctx { - enum obj_type obj_type; /* OBJ_TYPE_APPCTX */ - /* 3 unused bytes here */ - unsigned int st0; /* CLI state for stats, session state for peers */ - unsigned int st1; /* prompt for stats, session error for peers */ - unsigned int st2; /* output state for stats, unused by peers */ - struct si_applet *applet; /* applet this context refers to */ - void *owner; /* pointer to upper layer's entity (eg: stream interface) */ - - union { - struct { - struct proxy *px; - struct server *sv; - void *l; - int scope_str; /* limit scope to a frontend/backend substring */ - int scope_len; /* length of the string above in the buffer */ - int px_st; /* STAT_PX_ST* */ - unsigned int flags; /* STAT_* */ - int iid, type, sid; /* proxy id, type and service id if bounding of stats is enabled */ - int st_code; /* the status code returned by an action */ - } stats; - struct { - struct bref bref; /* back-reference from the session being dumped */ - void *target; /* session we want to dump, or NULL for all */ - unsigned int uid; /* if non-null, the uniq_id of the session being dumped */ - int section; /* section of the session being dumped */ - int pos; /* last position of the current session's buffer */ - } sess; - struct { - int iid; /* if >= 0, ID of the proxy to filter on */ - struct proxy *px; /* current proxy being dumped, NULL = not started yet. */ - unsigned int buf; /* buffer being dumped, 0 = req, 1 = rep */ - unsigned int sid; /* session ID of error being dumped */ - int ptr; /* <0: headers, >=0 : text pointer to restart from */ - int bol; /* pointer to beginning of current line */ - } errors; - struct { - void *target; /* table we want to dump, or NULL for all */ - struct proxy *proxy; /* table being currently dumped (first if NULL) */ - struct stksess *entry; /* last entry we were trying to dump (or first if NULL) */ - long long value; /* value to compare against */ - signed char data_type; /* type of data to compare, or -1 if none */ - signed char data_op; /* operator (STD_OP_*) when data_type set */ - } table; - struct { - const char *msg; /* pointer to a persistent message to be returned in PRINT state */ - char *err; /* pointer to a 'must free' message to be returned in PRINT_FREE state */ - } cli; - struct { - void *ptr; /* multi-purpose pointer for peers */ - } peers; - struct { - unsigned int display_flags; - struct pat_ref *ref; - struct pat_ref_elt *elt; - struct map_descriptor *desc; - struct pattern_expr *expr; - struct chunk chunk; - } map; - struct { - int connected; - struct hlua_socket *socket; - struct list wake_on_read; - struct list wake_on_write; - } hlua; - } ctx; /* used by stats I/O handlers to dump the stats */ -}; - #endif /* _TYPES_STREAM_INTERFACE_H */ /* diff --git a/src/dumpstats.c b/src/dumpstats.c index 4375bec713..d416ad006e 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -37,6 +37,7 @@ #include #include +#include #include #include diff --git a/src/hlua.c b/src/hlua.c index d1531bef00..4bc32e7511 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include diff --git a/src/peers.c b/src/peers.c index 6af565fa7e..7683150dce 100644 --- a/src/peers.c +++ b/src/peers.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include diff --git a/src/stream.c b/src/stream.c index e9a4b0d5b9..ed97e48864 100644 --- a/src/stream.c +++ b/src/stream.c @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/src/stream_interface.c b/src/stream_interface.c index 8df5008b82..ad865ca749 100644 --- a/src/stream_interface.c +++ b/src/stream_interface.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include