]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: applet: move the applet definitions out of stream_interface
authorWilly Tarreau <w@1wt.eu>
Mon, 13 Apr 2015 11:24:54 +0000 (13:24 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Apr 2015 15:56:16 +0000 (17:56 +0200)
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.

include/proto/applet.h [new file with mode: 0644]
include/proto/dumpstats.h
include/proto/obj_type.h
include/proto/stream_interface.h
include/types/applet.h [new file with mode: 0644]
include/types/stream_interface.h
src/dumpstats.c
src/hlua.c
src/peers.c
src/stream.c
src/stream_interface.c

diff --git a/include/proto/applet.h b/include/proto/applet.h
new file mode 100644 (file)
index 0000000..61bca02
--- /dev/null
@@ -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 <stdlib.h>
+
+#include <common/config.h>
+#include <types/applet.h>
+#include <proto/connection.h>
+
+/* 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. <applet> 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:
+ */
index 61e39bf9d7b0be10f182641868309635243f8ed0..cbbb802a475b4dbf1909db176ac8c8f3651eb290 100644 (file)
@@ -24,6 +24,7 @@
 #define _PROTO_DUMPSTATS_H
 
 #include <common/config.h>
+#include <types/applet.h>
 #include <types/stream_interface.h>
 
 /* Flags for applet.ctx.stats.flags */
index a02e1d6923a6cde6a7ac678be068a45bc582b25c..6d6577cb68fc31d8230f0cc16ba37d54686e0129 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <common/config.h>
 #include <common/memory.h>
+#include <types/applet.h>
 #include <types/connection.h>
 #include <types/listener.h>
 #include <types/obj_type.h>
index ec52f1e60e78b9b100e6dc345d02e070665a7bb1..264596166cac6228ca1751fe6f7b4c2df063d984 100644 (file)
@@ -27,6 +27,7 @@
 #include <common/config.h>
 #include <types/stream.h>
 #include <types/stream_interface.h>
+#include <proto/applet.h>
 #include <proto/channel.h>
 #include <proto/connection.h>
 
@@ -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. <applet> 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 (file)
index 0000000..9146ee4
--- /dev/null
@@ -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 <types/hlua.h>
+#include <types/obj_type.h>
+#include <common/chunk.h>
+#include <common/config.h>
+
+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:
+ */
index 7e688cfecae43edba622ff5ccc0269eb07d8302c..9b228e57c83186b6d7c34d0ea468e9ef19f557fd 100644 (file)
 #ifndef _TYPES_STREAM_INTERFACE_H
 #define _TYPES_STREAM_INTERFACE_H
 
-#include <stdlib.h>
-#include <sys/socket.h>
-
-#include <types/hlua.h>
 #include <types/obj_type.h>
 #include <common/config.h>
 
@@ -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 */
 
 /*
index 4375bec71320f85c27dd27ae639c2891becfb4fe..d416ad006ef8791b1bad907b8be11a6f80497732 100644 (file)
@@ -37,6 +37,7 @@
 #include <common/version.h>
 #include <common/base64.h>
 
+#include <types/applet.h>
 #include <types/global.h>
 
 #include <proto/backend.h>
index d1531bef006f87eaf3f728ebeb39eb575ff468f3..4bc32e75110197079eeba3ee44ac237cee7ef522 100644 (file)
@@ -20,6 +20,7 @@
 #include <types/proxy.h>
 
 #include <proto/arg.h>
+#include <proto/applet.h>
 #include <proto/channel.h>
 #include <proto/hdr_idx.h>
 #include <proto/hlua.h>
index 6af565fa7ea032d2986f1b0cb5cb55a7333f83a3..7683150dce3653b06efefac70ea98d0931c080bd 100644 (file)
@@ -30,6 +30,7 @@
 #include <types/peers.h>
 
 #include <proto/acl.h>
+#include <proto/applet.h>
 #include <proto/channel.h>
 #include <proto/fd.h>
 #include <proto/frontend.h>
index e9a4b0d5b9176d1d97f6b66f889f68d7450ff4bb..ed97e488640c079378ef02bc5fb1c6cfb3e2233f 100644 (file)
@@ -19,6 +19,7 @@
 #include <common/debug.h>
 #include <common/memory.h>
 
+#include <types/applet.h>
 #include <types/capture.h>
 #include <types/global.h>
 
index 8df5008b82862821afc2234e641d300abfa85c11..ad865ca749b02d7f9fbf3a091b6ca6658c72e779 100644 (file)
@@ -27,6 +27,7 @@
 #include <common/ticks.h>
 #include <common/time.h>
 
+#include <proto/applet.h>
 #include <proto/channel.h>
 #include <proto/connection.h>
 #include <proto/pipe.h>