diff mbox

[libnftnl,3/4] expr: match: Do not print unset values in xml file

Message ID 1403630104-13118-4-git-send-email-anarey@gmail.com
State Accepted
Headers show

Commit Message

Ana Rey June 24, 2014, 5:15 p.m. UTC
It changes the parse and snprintf functions to omit unset values.

Signed-off-by: Ana Rey <anarey@gmail.com>
---
 src/expr/match.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/src/expr/match.c b/src/expr/match.c
index 572d0f9..604a8e6 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -198,9 +198,8 @@  static int nft_rule_expr_match_xml_parse(struct nft_rule_expr *e, mxml_node_t *t
 
 	name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST,
 				  NFT_XML_MAND, err);
-	if (name == NULL)
-		return -1;
-	nft_rule_expr_set_str(e, NFT_EXPR_MT_NAME, name);
+	if (name != NULL)
+		nft_rule_expr_set_str(e, NFT_EXPR_MT_NAME, name);
 
 	/* mt->info is ignored until other solution is reached */
 
@@ -231,13 +230,14 @@  static int nft_rule_expr_match_snprintf_xml(char *buf, size_t len,
 	int ret, size=len;
 	int offset = 0;
 
-	ret = snprintf(buf, len, "<name>%s</name>", mt->name);
-	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+	if (e->flags & (1 << NFT_EXPR_MT_NAME)) {
+		ret = snprintf(buf, len, "<name>%s</name>", mt->name);
+		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+	}
 
 	return offset;
 }
 
-
 static int
 nft_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type,
 			     uint32_t flags, struct nft_rule_expr *e)