From 26e06d838d6471f5233c1da3fee012bf113564a5 Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Fri, 8 Feb 2013 17:51:56 +0100 Subject: src: add XML output support Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/chain.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/chain.c') diff --git a/src/chain.c b/src/chain.c index e12f82b..3c83e6d 100644 --- a/src/chain.c +++ b/src/chain.c @@ -437,8 +437,28 @@ int nft_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_chain *c) } EXPORT_SYMBOL(nft_chain_nlmsg_parse); -int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c, - uint32_t type, uint32_t flags) +static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c) +{ + return snprintf(buf, size, + "\n" + "\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\t\n" + "\t\n" + "\n", + c->name, c->handle, c->bytes, c->packets, + c->flags, c->type, c->table, c->prio, + c->use, c->hooknum, c->policy, c->family); +} + +static int nft_chain_snprintf_default(char *buf, size_t size, struct nft_chain *c) { return snprintf(buf, size, "family=%u table=%s chain=%s type=%s " "hook=%u prio=%d policy=%d use=%d " @@ -446,6 +466,20 @@ int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c, c->family, c->table, c->name, c->type, c->hooknum, c->prio, c->policy, c->use, c->packets, c->bytes); } + +int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *c, + uint32_t type, uint32_t flags) +{ + switch(type) { + case NFT_CHAIN_O_XML: + return nft_chain_snprintf_xml(buf, size, c); + case NFT_CHAIN_O_DEFAULT: + return nft_chain_snprintf_default(buf, size, c); + default: + break; + } + return -1; +} EXPORT_SYMBOL(nft_chain_snprintf); struct nft_chain_list { -- cgit v1.2.3