]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: stats: rename the stats state values an mark the old ones deprecated
authorWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:07:53 +0000 (18:07 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 6 May 2022 16:33:49 +0000 (18:33 +0200)
The STAT_ST_* values have been abused by virtually every applet and CLI
keyword handler, and this must not continue as it's a source of bugs and
of overly complicated code.

This patch renames the states to STAT_STATE_*, and keeps the previous
enum while marking each entry as deprecated. This should be sufficient to
catch out-of-tree code that might rely on them and to let them know what
to do with that.

include/haproxy/stats-t.h
src/http_ana.c
src/stats.c

index 6fbe28b40e43e2debcb2f3b48f448f8d6b7d3436..61c756a3e9a71ddcd13f2f29e9f091674f29bd1d 100644 (file)
@@ -123,12 +123,24 @@ enum {
 
 /* data transmission states for the stats responses */
 enum stat_state {
-       STAT_ST_INIT = 0,
-       STAT_ST_HEAD,
-       STAT_ST_INFO,
-       STAT_ST_LIST,
-       STAT_ST_END,
-       STAT_ST_FIN,
+       STAT_STATE_INIT = 0,
+       STAT_STATE_HEAD,
+       STAT_STATE_INFO,
+       STAT_STATE_LIST,
+       STAT_STATE_END,
+       STAT_STATE_FIN,
+};
+
+/* kept in 2.6 only for compatibility with legacy code. Will be removed in 2.7,
+ * please do not use these values anymore and defined your own!
+ */
+enum obsolete_stat_state {
+       STAT_ST_INIT __attribute__((deprecated)) = 0,
+       STAT_ST_HEAD __attribute__((deprecated)),
+       STAT_ST_INFO __attribute__((deprecated)),
+       STAT_ST_LIST __attribute__((deprecated)),
+       STAT_ST_END  __attribute__((deprecated)),
+       STAT_ST_FIN  __attribute__((deprecated)),
 };
 
 /* data transmission states for the stats responses inside a proxy */
index d2da6282ba703bd31adc3a08aa42ed88a24ff06e..4b3113e2dc8dc19988d1f96465ebb556be3649d9 100644 (file)
@@ -3928,7 +3928,7 @@ static int http_handle_stats(struct stream *s, struct channel *req)
        struct htx_sl *sl;
 
        appctx->st1 = 0;
-       ctx->state = STAT_ST_INIT;
+       ctx->state = STAT_STATE_INIT;
        ctx->st_code = STAT_STATUS_INIT;
        ctx->flags |= uri_auth->flags;
        ctx->flags |= STAT_FMT_HTML; /* assume HTML mode by default */
index 19c96cdfcaf80bccb130fb0ebbd4287fd150a9b5..bd73f483579097390c2a428103a6d16f95d344e6 100644 (file)
@@ -3733,11 +3733,11 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
        chunk_reset(&trash);
 
        switch (ctx->state) {
-       case STAT_ST_INIT:
-               ctx->state = STAT_ST_HEAD; /* let's start producing data */
+       case STAT_STATE_INIT:
+               ctx->state = STAT_STATE_HEAD; /* let's start producing data */
                /* fall through */
 
-       case STAT_ST_HEAD:
+       case STAT_STATE_HEAD:
                if (ctx->flags & STAT_FMT_HTML)
                        stats_dump_html_head(appctx, uri);
                else if (ctx->flags & STAT_JSON_SCHM)
@@ -3751,13 +3751,13 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                        goto full;
 
                if (ctx->flags & STAT_JSON_SCHM) {
-                       ctx->state = STAT_ST_FIN;
+                       ctx->state = STAT_STATE_FIN;
                        return 1;
                }
-               ctx->state = STAT_ST_INFO;
+               ctx->state = STAT_STATE_INFO;
                /* fall through */
 
-       case STAT_ST_INFO:
+       case STAT_STATE_INFO:
                if (ctx->flags & STAT_FMT_HTML) {
                        stats_dump_html_info(cs, uri);
                        if (!stats_putchk(rep, htx, &trash))
@@ -3768,10 +3768,10 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                        ctx->obj1 = proxies_list;
 
                ctx->px_st = STAT_PX_ST_INIT;
-               ctx->state = STAT_ST_LIST;
+               ctx->state = STAT_STATE_LIST;
                /* fall through */
 
-       case STAT_ST_LIST:
+       case STAT_STATE_LIST:
                switch (domain) {
                case STATS_DOMAIN_RESOLVERS:
                        if (!stats_dump_resolvers(cs, stat_l[domain],
@@ -3789,10 +3789,10 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                        break;
                }
 
-               ctx->state = STAT_ST_END;
+               ctx->state = STAT_STATE_END;
                /* fall through */
 
-       case STAT_ST_END:
+       case STAT_STATE_END:
                if (ctx->flags & (STAT_FMT_HTML|STAT_FMT_JSON)) {
                        if (ctx->flags & STAT_FMT_HTML)
                                stats_dump_html_end();
@@ -3802,15 +3802,15 @@ static int stats_dump_stat_to_buffer(struct conn_stream *cs, struct htx *htx,
                                goto full;
                }
 
-               ctx->state = STAT_ST_FIN;
+               ctx->state = STAT_STATE_FIN;
                /* fall through */
 
-       case STAT_ST_FIN:
+       case STAT_STATE_FIN:
                return 1;
 
        default:
                /* unknown state ! */
-               ctx->state = STAT_ST_FIN;
+               ctx->state = STAT_STATE_FIN;
                return -1;
        }