Message ID | 20130726120031.4081.51723.stgit@nfdev.cica.es |
---|---|
State | Deferred |
Headers | show |
Hi Arturo, On Fri, Jul 26, 2013 at 02:00:31PM +0200, Arturo Borrero Gonzalez wrote: > This patch adds a public interface for parsing expr XML. > Before this patch, that operation was not possible. rule parse already parses expressions. Do you need this? If so, please specify the usage. Thanks. -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 26 July 2013 16:19, Pablo Neira Ayuso <pablo@netfilter.org> wrote: > Hi Arturo, > > On Fri, Jul 26, 2013 at 02:00:31PM +0200, Arturo Borrero Gonzalez wrote: >> This patch adds a public interface for parsing expr XML. >> Before this patch, that operation was not possible. > > rule parse already parses expressions. > > Do you need this? If so, please specify the usage. Thanks. I don't need this. The only motivation was all object having a way of going from str to nft_* but expr. As you stated, currently the only way of parsing a XML expr is if the expr itself is nested inside a rule. but i'm fine without it ATM. Regards.
On Fri, Jul 26, 2013 at 04:31:47PM +0200, Arturo Borrero Gonzalez wrote: > On 26 July 2013 16:19, Pablo Neira Ayuso <pablo@netfilter.org> wrote: > > Hi Arturo, > > > > On Fri, Jul 26, 2013 at 02:00:31PM +0200, Arturo Borrero Gonzalez wrote: > >> This patch adds a public interface for parsing expr XML. > >> Before this patch, that operation was not possible. > > > > rule parse already parses expressions. > > > > Do you need this? If so, please specify the usage. Thanks. > > I don't need this. > > The only motivation was all object having a way of going from str to > nft_* but expr. > As you stated, currently the only way of parsing a XML expr is if the > expr itself is nested inside a rule. > > but i'm fine without it ATM. Let keep this back. I prefer not to add yet another interface for something we don't need at this moment. -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
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;
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@gmail.com> --- include/libnftables/expr.h | 3 +++ src/expr.c | 41 +++++++++++++++++++++++++++++++++++++++++ src/libnftables.map | 1 + 3 files changed, 45 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html