This patch adds a public interface for parsing expr XML. Before this patch, that operation was not possible. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@xxxxxxxxx> --- include/libnftables/expr.h | 3 +++ src/expr.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/libnftables.map | 1 + 3 files changed, 45 insertions(+) diff --git a/include/libnftables/expr.h b/include/libnftables/expr.h index 02f38d0..31946b3 100644 --- a/include/libnftables/expr.h +++ b/include/libnftables/expr.h @@ -8,6 +8,8 @@ extern "C" { #endif +#include <libnftables/rule.h> + struct nft_rule_expr; enum { @@ -35,6 +37,7 @@ struct nlmsghdr; void nft_rule_expr_build_payload(struct nlmsghdr *nlh, struct nft_rule_expr *expr); +int nft_rule_expr_parse(struct nft_rule_expr *expr, enum nft_rule_parse_type type, const char *data); int nft_rule_expr_snprintf(char *buf, size_t buflen, struct nft_rule_expr *expr, uint32_t type, uint32_t flags); enum { diff --git a/src/expr.c b/src/expr.c index 84fd64b..5c5af62 100644 --- a/src/expr.c +++ b/src/expr.c @@ -195,6 +195,47 @@ nft_rule_expr_build_payload(struct nlmsghdr *nlh, struct nft_rule_expr *expr) } EXPORT_SYMBOL(nft_rule_expr_build_payload); +static int nft_rule_expr_parse_xml(struct nft_rule_expr *expr, const char *xml) +{ +#ifdef XML_PARSING + mxml_node_t *tree; + + tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK); + if (tree == NULL) + goto einval; + + if (strcmp(tree->value.opaque, "expr") != 0) { + mxmlDelete(tree); + goto einval; + } + + expr = nft_mxml_expr_parse(tree); + if (expr == NULL) + return -1; + + return 0; + +einval: + errno = EINVAL; + return -1; +#else + errno = EOPNOTSUPP; + return -1; +#endif +} + +int nft_rule_expr_parse(struct nft_rule_expr *expr, enum nft_rule_parse_type type, const char *data) +{ + switch (type) { + case NFT_RULE_PARSE_XML: + return nft_rule_expr_parse_xml(expr, data); + default: + errno = EOPNOTSUPP; + return -1; + } +} +EXPORT_SYMBOL(nft_rule_expr_parse); + int nft_rule_expr_snprintf(char *buf, size_t size, struct nft_rule_expr *expr, uint32_t type, uint32_t flags) { diff --git a/src/libnftables.map b/src/libnftables.map index 614c705..16d8c05 100644 --- a/src/libnftables.map +++ b/src/libnftables.map @@ -93,6 +93,7 @@ global: nft_rule_expr_get_u64; nft_rule_expr_get_str; nft_rule_expr_build_payload; + nft_rule_expr_parse; nft_rule_expr_snprintf; nft_rule_expr_free; -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html