summaryrefslogtreecommitdiffstats
path: root/src/mxml.c
diff options
context:
space:
mode:
authorArturo Borrero <arturo.borrero.glez@gmail.com>2013-07-05 16:28:06 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-07-06 00:11:55 +0200
commit1e8e5d4b55efe4f11334a5b55483b802cb704071 (patch)
treec9e948fca996743999917e7a55275432345728d5 /src/mxml.c
parent9e540bd2dd2a53dc017f4ca6bd8b46bd4a3e5c65 (diff)
src: xml: consolidate parsing of data_reg via nft_mxml_data_reg_parse
Move common code for XML parsing of data_reg to the new nft_mxml_data_reg_parse function. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/mxml.c')
-rw-r--r--src/mxml.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/mxml.c b/src/mxml.c
index 9aef645..07f29ac 100644
--- a/src/mxml.c
+++ b/src/mxml.c
@@ -76,4 +76,58 @@ int nft_mxml_reg_parse(mxml_node_t *tree, const char *reg_name, uint32_t flags)
err:
return -1;
}
+
+int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name,
+ union nft_data_reg *data_reg)
+{
+ mxml_node_t *node;
+ const char *type;
+ char *tmpstr = NULL;
+ int ret;
+
+ node = mxmlFindElement(tree, tree, node_name, NULL, NULL,
+ MXML_DESCEND_FIRST);
+ if (node == NULL || node->child == NULL) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ tmpstr = mxmlSaveAllocString(node, MXML_NO_CALLBACK);
+ if (tmpstr == NULL) {
+ errno = ENOMEM;
+ goto err;
+ }
+
+ ret = nft_data_reg_xml_parse(data_reg, tmpstr);
+ free(tmpstr);
+
+ if (ret < 0) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ node = mxmlFindElement(node, node, "data_reg", NULL, NULL,
+ MXML_DESCEND);
+ if (node == NULL || node->child == NULL) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ type = mxmlElementGetAttr(node, "type");
+ if (type == NULL) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ if (strcmp(type, "value") == 0)
+ return DATA_VALUE;
+ else if (strcmp(type, "verdict") == 0)
+ return DATA_VERDICT;
+ else if (strcmp(type, "chain") == 0)
+ return DATA_CHAIN;
+ else
+ errno = EINVAL;
+err:
+ return -1;
+}
#endif