diff options
author | Florian Westphal <fw@strlen.de> | 2018-08-29 11:37:39 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2018-08-29 23:53:48 +0200 |
commit | 92029c1282958aad13eb8602c67b73caf2a08a09 (patch) | |
tree | bff7a62d56ba4fb33d3a44adcbfac1d3b726f95c /src | |
parent | 176d9ad8c351cff9f0c21da5b5f2848e4c77b249 (diff) |
src: osf: add json support
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/json.c | 5 | ||||
-rw-r--r-- | src/osf.c | 2 | ||||
-rw-r--r-- | src/parser_json.c | 17 |
3 files changed, 23 insertions, 1 deletions
@@ -811,6 +811,11 @@ json_t *socket_expr_json(const struct expr *expr, struct output_ctx *octx) socket_templates[expr->socket.key].token); } +json_t *osf_expr_json(const struct expr *expr, struct output_ctx *octx) +{ + return json_pack("{s:{s:s}}", "osf", "key", "name"); +} + json_t *integer_type_json(const struct expr *expr, struct output_ctx *octx) { char buf[1024] = "0x"; @@ -3,6 +3,7 @@ #include <utils.h> #include <string.h> #include <osf.h> +#include <json.h> static void osf_expr_print(const struct expr *expr, struct output_ctx *octx) { @@ -18,6 +19,7 @@ static const struct expr_ops osf_expr_ops = { .name = "osf", .print = osf_expr_print, .clone = osf_expr_clone, + .json = osf_expr_json, }; struct expr *osf_expr_alloc(const struct location *loc) diff --git a/src/parser_json.c b/src/parser_json.c index b51f95e1..6d8cda97 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -346,13 +346,27 @@ static struct expr *json_parse_meta_expr(struct json_ctx *ctx, return meta_expr_alloc(int_loc, key); } +static struct expr *json_parse_osf_expr(struct json_ctx *ctx, + const char *type, json_t *root) +{ + const char *key; + + if (json_unpack_err(ctx, root, "{s:s}", "key", &key)) + return NULL; + + if (!strcmp(key, "name")) + return osf_expr_alloc(int_loc); + + json_error(ctx, "Invalid osf key value."); + return NULL; +} + static struct expr *json_parse_socket_expr(struct json_ctx *ctx, const char *type, json_t *root) { const char *key; int keyval = -1; - if (json_unpack_err(ctx, root, "{s:s}", "key", &key)) return NULL; @@ -1181,6 +1195,7 @@ static struct expr *json_parse_expr(struct json_ctx *ctx, json_t *root) { "exthdr", json_parse_exthdr_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_SES | CTX_F_MAP }, { "tcp option", json_parse_tcp_option_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES }, { "meta", json_parse_meta_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP }, + { "osf", json_parse_osf_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_MAP }, { "socket", json_parse_socket_expr, CTX_F_PRIMARY }, { "rt", json_parse_rt_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_SES | CTX_F_MAP }, { "ct", json_parse_ct_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP }, |