summaryrefslogtreecommitdiffstats
path: root/src/table.c
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>2013-08-06 10:40:33 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2013-08-06 11:44:20 +0200
commitb58cf8947422ba695df80fe3b012b383fff22f7a (patch)
treeed5708d68972c225492771b57397c52bfef1fc4d /src/table.c
parentec75831c439ebd3475e0ba6766188d963538129a (diff)
src: xml: use nodes instead of attributes
When working with XML, it's desirable to work with nodes better than attributes. Table/chain/rules had attributes in their XML representation, and this patch transform those to nodes, ie: Before: <table name="filter"> <family>ip</family> <table_flags>0</table_flags> </table> After: <table> <name>filter</name> <family>ip</family> <table_flags>0</table_flags> </table> While at it: * There was a lot of redundant code that is now collapsed with the new nft_mxml_family_parse() helper function. * I've added a small fix: additional validation for the name of the current XML object, and also replace raw strtol calls to nft_strtoi. * Also, all XML testfiles are updated to keep passing the parsing tests and mantain the repo in consisten state. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/table.c')
-rw-r--r--src/table.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/table.c b/src/table.c
index 6875dd7..bb66717 100644
--- a/src/table.c
+++ b/src/table.c
@@ -222,7 +222,7 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml)
{
#ifdef XML_PARSING
mxml_node_t *tree = NULL;
- mxml_node_t *node = NULL;
+ const char *name;
int family;
/* NOTE: all XML nodes are mandatory */
@@ -232,8 +232,13 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml)
if (tree == NULL)
return -1;
- /* Get and set the name of the table */
- if (mxmlElementGetAttr(tree, "name") == NULL) {
+ if (strcmp(tree->value.opaque, "table") != 0) {
+ mxmlDelete(tree);
+ return -1;
+ }
+
+ name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST);
+ if (name == NULL) {
mxmlDelete(tree);
return -1;
}
@@ -241,18 +246,10 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml)
if (t->name)
xfree(t->name);
- t->name = strdup(mxmlElementGetAttr(tree, "name"));
+ t->name = name;
t->flags |= (1 << NFT_TABLE_ATTR_NAME);
- /* Get the and set <family> node */
- node = mxmlFindElement(tree, tree, "family", NULL, NULL,
- MXML_DESCEND_FIRST);
- if (node == NULL) {
- mxmlDelete(tree);
- return -1;
- }
-
- family = nft_str2family(node->child->value.opaque);
+ family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST);
if (family < 0) {
mxmlDelete(tree);
return -1;
@@ -261,7 +258,6 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml)
t->family = family;
t->flags |= (1 << NFT_TABLE_ATTR_FAMILY);
- /* Get and set <table_flags> */
if (nft_mxml_num_parse(tree, "table_flags", MXML_DESCEND, BASE_DEC,
&t->table_flags, NFT_TYPE_U32) != 0) {
mxmlDelete(tree);
@@ -360,7 +356,7 @@ static int nft_table_snprintf_json(char *buf, size_t size, struct nft_table *t)
static int nft_table_snprintf_xml(char *buf, size_t size, struct nft_table *t)
{
- return snprintf(buf, size, "<table name=\"%s\"><family>%s</family>"
+ return snprintf(buf, size, "<table><name>%s</name><family>%s</family>"
"<table_flags>%d</table_flags></table>",
t->name, nft_family2str(t->family), t->table_flags);
}