netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libnftables PATCH] xml: expr: fix public interface for parsing XML
@ 2013-07-26 12:00 Arturo Borrero Gonzalez
  2013-07-26 14:19 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 4+ messages in thread
From: Arturo Borrero Gonzalez @ 2013-07-26 12:00 UTC (permalink / raw)
  To: netfilter-devel

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(+)

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;
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-26 14:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-26 12:00 [libnftables PATCH] xml: expr: fix public interface for parsing XML Arturo Borrero Gonzalez
2013-07-26 14:19 ` Pablo Neira Ayuso
2013-07-26 14:31   ` Arturo Borrero Gonzalez
2013-07-26 14:55     ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).