diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/json.c | 13 | ||||
-rw-r--r-- | src/parser_json.c | 19 |
2 files changed, 27 insertions, 5 deletions
@@ -857,7 +857,18 @@ json_t *socket_expr_json(const struct expr *expr, struct output_ctx *octx) json_t *osf_expr_json(const struct expr *expr, struct output_ctx *octx) { - return json_pack("{s:{s:i, s:s}}", "osf", "ttl", expr->osf.ttl, "key", "name"); + json_t *root = json_pack("{s:s}", "key", "name"); + + switch (expr->osf.ttl) { + case 1: + json_object_set_new(root, "ttl", json_string("loose")); + break; + case 2: + json_object_set_new(root, "ttl", json_string("skip")); + break; + } + + return json_pack("{s:o}", "osf", root); } json_t *xfrm_expr_json(const struct expr *expr, struct output_ctx *octx) diff --git a/src/parser_json.c b/src/parser_json.c index fc0dc9a9..46a02fe1 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -375,14 +375,25 @@ static struct expr *json_parse_meta_expr(struct json_ctx *ctx, static struct expr *json_parse_osf_expr(struct json_ctx *ctx, const char *type, json_t *root) { - const char *key; - uint8_t ttl; + const char *key, *ttl; + uint8_t ttlval = 0; - if (json_unpack_err(ctx, root, "{s:i, s:s}", "ttl", ttl,"key", &key)) + if (json_unpack_err(ctx, root, "{s:s}", "key", &key)) return NULL; + if (!json_unpack(root, "{s:s}", "ttl", &ttl)) { + if (!strcmp(ttl, "loose")) { + ttlval = 1; + } else if (!strcmp(ttl, "skip")) { + ttlval = 2; + } else { + json_error(ctx, "Invalid osf ttl option '%s'.", ttl); + return NULL; + } + } + if (!strcmp(key, "name")) - return osf_expr_alloc(int_loc, ttl); + return osf_expr_alloc(int_loc, ttlval); json_error(ctx, "Invalid osf key value."); return NULL; |