* [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
* Re: [libnftables PATCH] xml: expr: fix public interface for parsing XML
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
0 siblings, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2013-07-26 14:19 UTC (permalink / raw)
To: Arturo Borrero Gonzalez; +Cc: netfilter-devel
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [libnftables PATCH] xml: expr: fix public interface for parsing XML
2013-07-26 14:19 ` Pablo Neira Ayuso
@ 2013-07-26 14:31 ` Arturo Borrero Gonzalez
2013-07-26 14:55 ` Pablo Neira Ayuso
0 siblings, 1 reply; 4+ messages in thread
From: Arturo Borrero Gonzalez @ 2013-07-26 14:31 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Netfilter Development Mailing list
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.
--
Arturo Borrero González
--
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [libnftables PATCH] xml: expr: fix public interface for parsing XML
2013-07-26 14:31 ` Arturo Borrero Gonzalez
@ 2013-07-26 14:55 ` Pablo Neira Ayuso
0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2013-07-26 14:55 UTC (permalink / raw)
To: Arturo Borrero Gonzalez; +Cc: Netfilter Development Mailing list
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.
^ permalink raw reply [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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.