From 4edb05eb12dd69a0035d06aa6057d6d0e502d5ae Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Wed, 1 Oct 2025 18:53:41 +0200 Subject: [PATCH] CLEANUP: mjson: remove MJSON_ENABLE_NEXT code Remove the code used under #if MJSON_ENABLE_NEXT, which is not used within haproxy, to ease the maintenance of mjson. --- include/import/mjson.h | 5 --- src/mjson.c | 73 ------------------------------------------ 2 files changed, 78 deletions(-) diff --git a/include/import/mjson.h b/include/import/mjson.h index 55c1995d4..faa7ebf91 100644 --- a/include/import/mjson.h +++ b/include/import/mjson.h @@ -98,11 +98,6 @@ int mjson_get_bool(const char *s, int len, const char *path, int *v); int mjson_get_string(const char *s, int len, const char *path, char *to, int n); int mjson_get_hex(const char *s, int len, const char *path, char *to, int n); -#if MJSON_ENABLE_NEXT -int mjson_next(const char *s, int n, int off, int *koff, int *klen, int *voff, - int *vlen, int *vtype); -#endif - #if MJSON_ENABLE_BASE64 int mjson_get_base64(const char *s, int len, const char *path, char *to, int n); int mjson_base64_dec(const char *src, int n, char *dst, int dlen); diff --git a/src/mjson.c b/src/mjson.c index 1a1733fbf..539fd690c 100644 --- a/src/mjson.c +++ b/src/mjson.c @@ -393,79 +393,6 @@ int mjson_get_base64(const char *s, int len, const char *path, char *to, } #endif // MJSON_ENABLE_BASE64 -#if MJSON_ENABLE_NEXT -struct nextdata { - int off, len, depth, t, vo, arrayindex; - int *koff, *klen, *voff, *vlen, *vtype; -}; - -static int next_cb(int tok, const char *s, int off, int len, void *ud) { - struct nextdata *d = (struct nextdata *) ud; - // int i; - switch (tok) { - case '{': - case '[': - if (d->depth == 0 && tok == '[') d->arrayindex = 0; - if (d->depth == 1 && off > d->off) { - d->vo = off; - d->t = tok == '{' ? MJSON_TOK_OBJECT : MJSON_TOK_ARRAY; - if (d->voff) *d->voff = off; - if (d->vtype) *d->vtype = d->t; - } - d->depth++; - break; - case '}': - case ']': - d->depth--; - if (d->depth == 1 && d->vo) { - d->len = off + len; - if (d->vlen) *d->vlen = d->len - d->vo; - if (d->arrayindex >= 0) { - if (d->koff) *d->koff = d->arrayindex; // koff holds array index - if (d->klen) *d->klen = 0; // klen holds 0 - } - return 1; - } - if (d->depth == 1 && d->arrayindex >= 0) d->arrayindex++; - break; - case ',': - case ':': - break; - case MJSON_TOK_KEY: - if (d->depth == 1 && d->off < off) { - if (d->koff) *d->koff = off; // And report back to the user - if (d->klen) *d->klen = len; // If we have to - } - break; - default: - if (d->depth != 1) break; - // If we're iterating over the array - if (off > d->off) { - d->len = off + len; - if (d->vlen) *d->vlen = len; // value length - if (d->voff) *d->voff = off; // value offset - if (d->vtype) *d->vtype = tok; // value type - if (d->arrayindex >= 0) { - if (d->koff) *d->koff = d->arrayindex; // koff holds array index - if (d->klen) *d->klen = 0; // klen holds 0 - } - return 1; - } - if (d->arrayindex >= 0) d->arrayindex++; - break; - } - (void) s; - return 0; -} - -int mjson_next(const char *s, int n, int off, int *koff, int *klen, int *voff, - int *vlen, int *vtype) { - struct nextdata d = {off, 0, 0, 0, 0, -1, koff, klen, voff, vlen, vtype}; - mjson(s, n, next_cb, &d); - return d.len; -} -#endif - static int is_digit(int c) { return c >= '0' && c <= '9'; } -- 2.47.3