From 4a684c2ee4cdff2c5c6bfa06d93b58cb4e868bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Neira=20Ayuso?= Date: Thu, 27 Jun 2013 21:56:18 +0200 Subject: src: support JSON format in chain, rule and expressions While at it, order possible switch cases of _snprintf. Signed-off-by: Alvaro Neira Ayuso Signed-off-by: Pablo Neira Ayuso --- src/expr/match.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/expr/match.c') diff --git a/src/expr/match.c b/src/expr/match.c index 7b4377f..7d0f078 100644 --- a/src/expr/match.c +++ b/src/expr/match.c @@ -226,6 +226,18 @@ static int nft_rule_expr_match_xml_parse(struct nft_rule_expr *e, char *xml) #endif } +static int nft_rule_expr_match_snprintf_json(char *buf, size_t len, + struct nft_expr_match *mt) +{ + int ret, size = len, offset = 0; + + ret = snprintf(buf, len, "\"name\" : \"%s\"", + mt->name); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + return offset; +} + static int nft_rule_expr_match_snprintf_xml(char *buf, size_t len, struct nft_expr_match *mt) { @@ -246,11 +258,13 @@ nft_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type, struct nft_expr_match *match = (struct nft_expr_match *)e->data; switch(type) { - case NFT_RULE_O_XML: - return nft_rule_expr_match_snprintf_xml(buf, len, match); case NFT_RULE_O_DEFAULT: return snprintf(buf, len, "name=%s rev=%u ", match->name, match->rev); + case NFT_RULE_O_XML: + return nft_rule_expr_match_snprintf_xml(buf, len, match); + case NFT_RULE_O_JSON: + return nft_rule_expr_match_snprintf_json(buf, len, match); default: break; } -- cgit v1.2.3