]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: ssl/cli: make "show tlskeys" not use appctx->st2 anymore
authorWilly Tarreau <w@1wt.eu>
Thu, 5 May 2022 07:03:44 +0000 (09:03 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:13:36 +0000 (18:13 +0200)
A new "state" enum was added to "show_keys_ctx" for this, and only 3
states are needed.

src/ssl_sock.c

index 55b398fda24e14e3f043b63ebec4de410c00c324..161fb3341548f05149916e88bcd3a991a0a86aa8 100644 (file)
@@ -192,6 +192,11 @@ struct show_keys_ctx {
        int names_only;                /* non-zero = only show file names */
        int next_index;                /* next index to be dumped */
        int dump_entries;              /* dump entries also */
+       enum {
+               SHOW_KEYS_INIT = 0,
+               SHOW_KEYS_LIST,
+               SHOW_KEYS_DONE,
+       } state;                       /* phase of the current dump */
 };
 
 /* ssl_sock_io_cb is exported to see it resolved in "show fd" */
@@ -7221,11 +7226,11 @@ static int cli_io_handler_tlskeys_files(struct appctx *appctx)
        struct show_keys_ctx *ctx = appctx->svcctx;
        struct conn_stream *cs = appctx->owner;
 
-       switch (appctx->st2) {
-       case STAT_ST_INIT:
+       switch (ctx->state) {
+       case SHOW_KEYS_INIT:
                /* Display the column headers. If the message cannot be sent,
                 * quit the function with returning 0. The function is called
-                * later and restart at the state "STAT_ST_INIT".
+                * later and restart at the state "SHOW_KEYS_INIT".
                 */
                chunk_reset(&trash);
 
@@ -7247,10 +7252,10 @@ static int cli_io_handler_tlskeys_files(struct appctx *appctx)
                if (ctx->next_ref == NULL)
                        ctx->next_ref = tlskeys_list_get_next(&tlskeys_reference, &tlskeys_reference);
 
-               appctx->st2 = STAT_ST_LIST;
+               ctx->state = SHOW_KEYS_LIST;
                /* fall through */
 
-       case STAT_ST_LIST:
+       case SHOW_KEYS_LIST:
                while (ctx->next_ref) {
                        struct tls_keys_ref *ref = ctx->next_ref;
 
@@ -7317,12 +7322,10 @@ static int cli_io_handler_tlskeys_files(struct appctx *appctx)
                        /* get next list entry and check the end of the list */
                        ctx->next_ref = tlskeys_list_get_next(&ref->list, &tlskeys_reference);
                }
-
-               appctx->st2 = STAT_ST_FIN;
+               ctx->state = SHOW_KEYS_DONE;
                /* fall through */
 
        default:
-               appctx->st2 = STAT_ST_FIN;
                return 1;
        }
        return 0;