Patchwork [libnftables,2/5] src: expr: XML printing for binary data in targer and match

login
register
mail settings
Submitter Arturo Borrero
Date April 10, 2013, 4:40 p.m.
Message ID <20130410164002.6303.24175.stgit@nfdev.cica.es>
Download mbox | patch
Permalink /patch/235418/
State RFC
Headers show

Comments

Arturo Borrero - April 10, 2013, 4:40 p.m.
This is a try for expr/match and expr/target to be more XML friendly.

Signed-off-by: Arturo Borrero González <arturo.borrero.glez@gmail.com>
---
 src/expr/match.c  |    6 +++---
 src/expr/target.c |    6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)


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

Patch

diff --git a/src/expr/match.c b/src/expr/match.c
index f83a8ea..d1f5963 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -193,12 +193,12 @@  int nft_rule_expr_match_snprintf_xml(char *buf, size_t len,
 	int offset = 0;
 	uint8_t *data = (uint8_t *)mt->data;
 
-	ret = snprintf(buf, len, "\t\t<name>%s</name> <rev>%u</rev> <info>0x",
-				mt->name, mt->rev);
+	ret = snprintf(buf, len, "\t\t<name>%s</name> <rev>%u</rev> <info><len>%u</len>",
+				mt->name, mt->rev, mt->data_len);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	for (i=0; i < mt->data_len; i++) {
-	        ret = snprintf(buf+offset, len, "%x", data[i] & 0xff);
+	        ret = snprintf(buf+offset, len, "<data%d>0x%.2x</data%d>",i, data[i] & 0xff, i);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 	}
 
diff --git a/src/expr/target.c b/src/expr/target.c
index 86c9bc8..aae58ce 100644
--- a/src/expr/target.c
+++ b/src/expr/target.c
@@ -193,12 +193,12 @@  int nft_rule_exp_target_snprintf_xml(char *buf, size_t len,
 	int offset = 0;
 	uint8_t *data = (uint8_t *)tg->data;
 
-	ret = snprintf(buf, len, "\t\t<name>%s</name> <rev>%u</rev> <info>0x",
-			tg->name, tg->rev);
+	ret = snprintf(buf, len, "\t\t<name>%s</name> <rev>%u</rev> <info><len>%u</len>",
+			tg->name, tg->rev, tg->data_len);
 	SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 
 	for (i=0; i < tg->data_len; i++) {
-		ret = snprintf(buf+offset, len, "%x", data[i] & 0xff);
+		ret = snprintf(buf+offset, len, "<data%d>0x%.2x</data%d>",i, data[i] & 0xff, i);
 		SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
 	}