summaryrefslogtreecommitdiffstats
path: root/src/expr/match.c
diff options
context:
space:
mode:
authorÁlvaro Neira Ayuso <alvaroneay@gmail.com>2013-06-27 21:56:18 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-06-29 11:56:05 +0200
commit4a684c2ee4cdff2c5c6bfa06d93b58cb4e868bf6 (patch)
tree6216e645631bba685f1c17e0cce851d0c1c6c517 /src/expr/match.c
parentcaf4ac2e95a358f5b6ee64c4cc6c6c96a0bff24b (diff)
src: support JSON format in chain, rule and expressions
While at it, order possible switch cases of _snprintf. Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expr/match.c')
-rw-r--r--src/expr/match.c18
1 files changed, 16 insertions, 2 deletions
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;
}