summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/internal.h4
-rw-r--r--src/mxml.c46
-rw-r--r--src/set.c7
-rw-r--r--src/set_elem.c49
4 files changed, 35 insertions, 71 deletions
diff --git a/src/internal.h b/src/internal.h
index 1ebdb1a..17d1286 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -37,7 +37,9 @@ int nft_mxml_data_reg_parse(mxml_node_t *tree, const char *node_name, union nft_
int nft_mxml_num_parse(mxml_node_t *tree, const char *node_name, uint32_t mxml_flags, int base, void *number, enum nft_type type);
const char *nft_mxml_str_parse(mxml_node_t *tree, const char *node_name, uint32_t mxml_flags);
int nft_mxml_family_parse(mxml_node_t *tree, const char *node_name, uint32_t mxml_flags);
-struct nft_set_elem *nft_mxml_set_elem_parse(mxml_node_t *node);
+
+struct nft_set_elem;
+int nft_mxml_set_elem_parse(mxml_node_t *node, struct nft_set_elem *e);
#endif
#ifdef JSON_PARSING
diff --git a/src/mxml.c b/src/mxml.c
index 1f0a2df..b5de153 100644
--- a/src/mxml.c
+++ b/src/mxml.c
@@ -184,50 +184,4 @@ int nft_mxml_family_parse(mxml_node_t *tree, const char *node_name,
return family;
}
-
-struct nft_set_elem *nft_mxml_set_elem_parse(mxml_node_t *node)
-{
- mxml_node_t *save;
- char *set_elem_str;
- struct nft_set_elem *elem;
-
- if (node == NULL)
- goto einval;
-
- if (strcmp(node->value.opaque, "set_elem") != 0)
- goto einval;
-
- elem = nft_set_elem_alloc();
- if (elem == NULL)
- goto enomem;
-
- /* This is a hack for mxml to print just the current node */
- save = node->next;
- node->next = NULL;
-
- set_elem_str = mxmlSaveAllocString(node, MXML_NO_CALLBACK);
- node->next = save;
-
- if (set_elem_str == NULL) {
- xfree(elem);
- goto enomem;
- }
-
- if (nft_set_elem_parse(elem, NFT_SET_PARSE_XML,
- set_elem_str) != 0) {
- xfree(set_elem_str);
- xfree(elem);
- return NULL;
- }
-
- xfree(set_elem_str);
-
- return elem;
-einval:
- errno = EINVAL;
- return NULL;
-enomem:
- errno = ENOMEM;
- return NULL;
-}
#endif
diff --git a/src/set.c b/src/set.c
index eb90426..97856b3 100644
--- a/src/set.c
+++ b/src/set.c
@@ -355,7 +355,6 @@ static int nft_set_xml_parse(struct nft_set *s, char *xml)
s->flags |= (1 << NFT_SET_ATTR_FLAGS);
-
if (nft_mxml_num_parse(tree, "key_type", MXML_DESCEND_FIRST,
BASE_DEC, &s->key_type, NFT_TYPE_U32) != 0)
goto err;
@@ -380,17 +379,19 @@ static int nft_set_xml_parse(struct nft_set *s, char *xml)
s->flags |= (1 << NFT_SET_ATTR_DATA_LEN);
- /* Iterate over each <set_elem> */
for (node = mxmlFindElement(tree, tree, "set_elem", NULL,
NULL, MXML_DESCEND);
node != NULL;
node = mxmlFindElement(node, tree, "set_elem", NULL,
NULL, MXML_DESCEND)) {
- elem = nft_mxml_set_elem_parse(node);
+ elem = nft_set_elem_alloc();
if (elem == NULL)
goto err;
+ if (nft_mxml_set_elem_parse(node, elem) < 0)
+ goto err;
+
list_add_tail(&elem->head, &s->element_list);
}
diff --git a/src/set_elem.c b/src/set_elem.c
index d99b65e..73c100f 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -375,34 +375,21 @@ int nft_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s)
}
EXPORT_SYMBOL(nft_set_elems_nlmsg_parse);
-static int nft_set_elem_xml_parse(struct nft_set_elem *e, char *xml)
-{
#ifdef XML_PARSING
- mxml_node_t *tree;
+int nft_mxml_set_elem_parse(mxml_node_t *tree, struct nft_set_elem *e)
+{
mxml_node_t *node;
int set_elem_data;
- tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK);
- if (tree == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- if (strcmp(tree->value.opaque, "set_elem") != 0) {
- errno = EINVAL;
- goto err;
- }
-
if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST,
BASE_DEC, &e->set_elem_flags,
NFT_TYPE_U32) != 0)
- goto err;
+ return -1;
e->flags |= (1 << NFT_SET_ELEM_ATTR_FLAGS);
- if (nft_mxml_data_reg_parse(tree, "key",
- &e->key) != DATA_VALUE)
- goto err;
+ if (nft_mxml_data_reg_parse(tree, "key", &e->key) != DATA_VALUE)
+ return -1;
e->flags |= (1 << NFT_SET_ELEM_ATTR_KEY);
@@ -423,13 +410,33 @@ static int nft_set_elem_xml_parse(struct nft_set_elem *e, char *xml)
e->flags |= (1 << NFT_SET_ELEM_ATTR_CHAIN);
break;
default:
- goto err;
+ return -1;
}
}
-
- mxmlDelete(tree);
return 0;
+}
+#endif
+static int nft_set_elem_xml_parse(struct nft_set_elem *e, char *xml)
+{
+#ifdef XML_PARSING
+ mxml_node_t *tree;
+ int ret;
+
+ tree = mxmlLoadString(NULL, xml, MXML_OPAQUE_CALLBACK);
+ if (tree == NULL) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (strcmp(tree->value.opaque, "set_elem") != 0) {
+ errno = EINVAL;
+ goto err;
+ }
+
+ ret = nft_mxml_set_elem_parse(tree, e);
+ mxmlDelete(tree);
+ return ret;
err:
mxmlDelete(tree);
return -1;