]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: applet: group all CLI contexts together
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Dec 2016 11:14:12 +0000 (12:14 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Dec 2016 18:40:13 +0000 (19:40 +0100)
The appctx storage became a real mess along the years. It now contains
mostly CLI-specific parts that share the same storage as the "cli" part
which in fact only contains the fields needed to pass an error message
to the caller, and it also has room a few other regular applets which
may become more and more common.

This first patch moves the parts around in the union so that all
standard applet parts are grouped together and the CLI-specific ones
are grouped together. It also adds a few comments to indicate what
certain parts are used for since it's sometimes a bit confusing.

include/types/applet.h

index be1f69cb8fb4ae02d1e4808b92202e4fe4524501..82e478174ebb132329fd5585cc3c3ba66554dd59 100644 (file)
@@ -61,6 +61,43 @@ struct appctx {
        struct buffer_wait buffer_wait; /* position in the list of objects waiting for a buffer */
 
        union {
+               struct {
+                       void *ptr;              /* multi-purpose pointer for peers */
+               } peers;                        /* used by the peers applet */
+               struct {
+                       int connected;
+                       struct hlua_socket *socket;
+                       struct list wake_on_read;
+                       struct list wake_on_write;
+               } hlua_cosocket;                /* used by the Lua cosockets */
+               struct {
+                       struct hlua *hlua;
+                       int flags;
+                       struct task *task;
+               } hlua_apptcp;                  /* used by the Lua TCP services */
+               struct {
+                       struct hlua *hlua;
+                       int left_bytes;         /* The max amount of bytes that we can read. */
+                       int flags;
+                       int status;
+                       struct task *task;
+               } hlua_apphttp;                 /* used by the Lua HTTP services */
+               struct {
+                       struct task *task;
+                       void        *ctx;
+                       void        *agent;
+                       unsigned int version;
+                       unsigned int max_frame_size;
+                       struct list  list;
+               } spoe;                         /* used by SPOE filter */
+               struct {
+                       const char *msg;        /* pointer to a persistent message to be returned in CLI_ST_PRINT state */
+                       char *err;              /* pointer to a 'must free' message to be returned in CLI_ST_PRINT_FREE state */
+               } cli;                          /* context used by the CLI */
+
+               /* all entries below are used by various CLI commands, please
+                * keep the grouped together and avoid adding new ones.
+                */
                struct {
                        struct proxy *px;
                        struct server *sv;
@@ -96,13 +133,6 @@ struct appctx {
                        signed char data_op;    /* operator (STD_OP_*) when data_type set */
                        char action;            /* action on the table : one of STK_CLI_ACT_* */
                } 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;
@@ -117,29 +147,11 @@ struct appctx {
                        struct tls_keys_ref *ref;
                } tlskeys;
 #endif
-               struct {
-                       int connected;
-                       struct hlua_socket *socket;
-                       struct list wake_on_read;
-                       struct list wake_on_write;
-               } hlua_cosocket;
                struct {
                        struct hlua *hlua;
                        struct task *task;
                        struct hlua_function *fcn;
                } hlua_cli;
-               struct {
-                       struct hlua *hlua;
-                       int flags;
-                       struct task *task;
-               } hlua_apptcp;
-               struct {
-                       struct hlua *hlua;
-                       int left_bytes; /* The max amount of bytes that we can read. */
-                       int flags;
-                       int status;
-                       struct task *task;
-               } hlua_apphttp;
                struct {
                        struct dns_resolvers *ptr;
                } resolvers;
@@ -154,16 +166,11 @@ struct appctx {
                struct {
                        char **var;
                } env;
-               struct {
-                       struct task *task;
-                       void        *ctx;
-                       void        *agent;
-                       unsigned int version;
-                       unsigned int max_frame_size;
-                       struct list  list;
-               } spoe;                         /* used by SPOE filter */
                struct list *cli_socket;        /* pointer to the latest dumped CLI socket in the list */
-       } ctx;                                  /* used by stats I/O handlers to dump the stats */
+               /* NOTE: please add regular applet contexts (ie: not
+                * CLI-specific ones) above, before "cli".
+                */
+       } ctx;                                  /* context-specific variables used by any applet */
 };
 
 #endif /* _TYPES_APPLET_H */