[libnftnl PATCH 3/5] expr: queue: Do not print unset values in xml

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It changes the parse and the snprint functions to omit unset values.

This xml file is gotten for a queue:

[...]
<expr type="queue">
	<num>0</num>
	<total>1</total>
	<flags>0</flags>
</expr>
[...]

Signed-off-by: Ana Rey <anarey@xxxxxxxxx>
---
 src/expr/queue.c | 39 +++++++++++++++++++++++++--------------
 1 file changed, 25 insertions(+), 14 deletions(-)

diff --git a/src/expr/queue.c b/src/expr/queue.c
index 1d47d48..5235027 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -168,21 +168,18 @@ nft_rule_expr_queue_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree,
 
 	if (nft_mxml_num_parse(tree, "num", MXML_DESCEND_FIRST, BASE_DEC,
 			       &queue_num, NFT_TYPE_U16, NFT_XML_MAND,
-			       err) != 0)
-		return -1;
-	nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_NUM, queue_num);
+			       err) == 0)
+		nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_NUM, queue_num);
 
 	if (nft_mxml_num_parse(tree, "total", MXML_DESCEND_FIRST, BASE_DEC,
 			       &queue_total, NFT_TYPE_U8,
-			       NFT_XML_MAND, err) != 0)
-		return -1;
-	nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_TOTAL, queue_total);
+			       NFT_XML_MAND, err) == 0)
+		nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_TOTAL, queue_total);
 
 	if (nft_mxml_num_parse(tree, "flags", MXML_DESCEND_FIRST, BASE_DEC,
 			       &flags, NFT_TYPE_U8,
-			       NFT_XML_MAND, err) != 0)
-		return -1;
-	nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_FLAGS, flags);
+			       NFT_XML_MAND, err) == 0)
+		nft_rule_expr_set_u16(e, NFT_EXPR_QUEUE_FLAGS, flags);
 
 	return 0;
 #else
@@ -218,13 +215,27 @@ static int nft_rule_expr_queue_snprintf_default(char *buf, size_t len,
 static int nft_rule_expr_queue_snprintf_xml(char *buf, size_t len,
 					    struct nft_rule_expr *e)
 {
+	int ret, size = len, offset = 0;
 	struct nft_expr_queue *queue = nft_expr_data(e);
 
-	return snprintf(buf, len, "<num>%u</num>"
-				  "<total>%u</total>"
-				  "<flags>%u</flags>",
-			queue->queuenum, queue->queues_total,
-			queue->flags);
+
+	if (e->flags & (1 << NFT_EXPR_QUEUE_NUM)) {
+		ret = snprintf(buf + offset, len, "<num>%u</num>",
+			       queue->queuenum);
+		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+	}
+
+	if (e->flags & (1 << NFT_EXPR_QUEUE_TOTAL)) {
+		ret = snprintf(buf + offset, len, "<total>%u</total>",
+			       queue->queues_total);
+		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+	}
+	if (e->flags & (1 << NFT_EXPR_QUEUE_FLAGS)) {
+		ret = snprintf(buf + offset, len, "<flags>%u</flags>",
+			       queue->flags);
+		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+	}
+	return offset;
 }
 
 static int nft_rule_expr_queue_snprintf_json(char *buf, size_t len,
-- 
2.0.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux