diff options
author | Álvaro Neira Ayuso <alvaroneay@gmail.com> | 2013-08-20 17:58:46 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-08-20 21:01:09 +0200 |
commit | c83c53a26de25c1e2900f7841647cec3b57c7438 (patch) | |
tree | 4c0291b9a495e44911ba104650e2b04b4d4eb776 /src/expr/match.c | |
parent | 978988a0f4730f1da2cfd7e3fa0670711bb6b802 (diff) |
rule: Add json parser support
Add function for parsing rules in JSON format
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.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/expr/match.c b/src/expr/match.c index d155bb3..763e11e 100644 --- a/src/expr/match.c +++ b/src/expr/match.c @@ -170,6 +170,25 @@ static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *att return 0; } +static int nft_rule_expr_match_json_parse(struct nft_rule_expr *e, json_t *root) +{ +#ifdef JSON_PARSING + const char *name; + + name = nft_jansson_value_parse_str(root, "name"); + if (name == NULL) + return -1; + + nft_rule_expr_set_str(e, NFT_EXPR_MT_NAME, name); + + return 0; +#else + errno = EOPNOTSUPP; + return -1; +#endif +} + + static int nft_rule_expr_match_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree) { #ifdef XML_PARSING @@ -247,7 +266,8 @@ struct expr_ops expr_ops_match = { .parse = nft_rule_expr_match_parse, .build = nft_rule_expr_match_build, .snprintf = nft_rule_expr_match_snprintf, - .xml_parse = nft_rule_expr_match_xml_parse, + .xml_parse = nft_rule_expr_match_xml_parse, + .json_parse = nft_rule_expr_match_json_parse, }; static void __init expr_match_init(void) |