netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
To: netfilter-devel@vger.kernel.org
Subject: [libnftables PATCH] xml: expr: fix public interface for parsing XML
Date: Fri, 26 Jul 2013 14:00:31 +0200	[thread overview]
Message-ID: <20130726120031.4081.51723.stgit@nfdev.cica.es> (raw)

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;
 


             reply	other threads:[~2013-07-26 12:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-26 12:00 Arturo Borrero Gonzalez [this message]
2013-07-26 14:19 ` [libnftables PATCH] xml: expr: fix public interface for parsing XML Pablo Neira Ayuso
2013-07-26 14:31   ` Arturo Borrero Gonzalez
2013-07-26 14:55     ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130726120031.4081.51723.stgit@nfdev.cica.es \
    --to=arturo.borrero.glez@gmail.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).