From 19925e0fbc1d709212ed82fe4e43fe6ef1ec3539 Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Mon, 5 Aug 2013 14:01:39 +0200 Subject: chain: Use nft_str2hooknum() in the XML parsing code. Note: I've used MXML_DESCEND_FIRST flag when calling nft_mxml_str_parse() to ensure that the parsing travels from the top of the chain XML tree. Signed-off-by: Arturo Borrero Gonzalez --- src/chain.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src/chain.c') diff --git a/src/chain.c b/src/chain.c index 4f07bf8..69ea68f 100644 --- a/src/chain.c +++ b/src/chain.c @@ -589,7 +589,8 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml) mxml_node_t *node = NULL; char *endptr = NULL; uint64_t utmp; - int family; + const char *hooknum_str; + int family, hooknum; /* NOTE: all XML nodes are mandatory */ @@ -686,29 +687,24 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml) /* Ignore (cannot be set)*/ node = mxmlFindElement(tree, tree, "use", NULL, NULL, MXML_DESCEND); - /* Get and set */ - node = mxmlFindElement(tree, tree, "hooknum", NULL, NULL, - MXML_DESCEND); - if (node == NULL) { + + hooknum_str = nft_mxml_str_parse(tree, "hooknum", MXML_DESCEND_FIRST); + if (hooknum_str == NULL) { mxmlDelete(tree); return -1; } - /* iterate the list of hooks until a match is found */ - for (utmp = 0; utmp < NF_INET_NUMHOOKS; utmp++) { - if (strcmp(node->child->value.opaque, hooknum2str_array[utmp]) == 0) { - c->hooknum = utmp; - c->flags |= (1 << NFT_CHAIN_ATTR_HOOKNUM); - break; - } - } + hooknum = nft_str2hooknum(hooknum_str); + free((char *)hooknum_str); - /* if no hook was found, error */ - if (!(c->flags & (1 << NFT_CHAIN_ATTR_HOOKNUM))) { + if (hooknum < 0) { mxmlDelete(tree); return -1; } + c->hooknum = hooknum; + c->flags |= (1 << NFT_CHAIN_ATTR_HOOKNUM); + /* Get and set */ node = mxmlFindElement(tree, tree, "policy", NULL, NULL, MXML_DESCEND); if (node == NULL) { -- cgit v1.2.3