diff options
author | Arturo Borrero <arturo.borrero.glez@gmail.com> | 2013-09-26 00:13:02 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-09-27 15:59:04 +0200 |
commit | 3e40a89d43db8cf6c5947baa7221e57e2b9cf351 (patch) | |
tree | f815eb09b824f6530d137a158448d63571759f21 /src | |
parent | e7c068d131cc8e51aca6326f568b2333bf2076af (diff) |
set_elem: xml: avoid code duplication
This patch removes 3x code duplication in the XML snprintf function.
Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/set_elem.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/src/set_elem.c b/src/set_elem.c index a9e0751..885893b 100644 --- a/src/set_elem.c +++ b/src/set_elem.c @@ -519,7 +519,7 @@ static int nft_set_elem_snprintf_default(char *buf, size_t size, static int nft_set_elem_snprintf_xml(char *buf, size_t size, struct nft_set_elem *e, uint32_t flags) { - int ret, len = size, offset = 0; + int ret, len = size, offset = 0, type = DATA_NONE; ret = snprintf(buf, size, "<set_elem>" "<flags>%u</flags><key>", @@ -533,33 +533,19 @@ static int nft_set_elem_snprintf_xml(char *buf, size_t size, ret = snprintf(buf+offset, size, "</key>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - if (e->flags & (1 << NFT_SET_ELEM_ATTR_DATA)) { - ret = snprintf(buf+offset, size, "<data>"); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - - ret = nft_data_reg_snprintf(buf+offset, len, &e->data, - NFT_RULE_O_XML, flags, DATA_VALUE); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - - ret = snprintf(buf+offset, size, "</data>"); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - } else if (e->flags & (1 << NFT_SET_ELEM_ATTR_VERDICT)) { - ret = snprintf(buf+offset, size, "<data>"); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - - ret = nft_data_reg_snprintf(buf+offset, len, &e->data, - NFT_RULE_O_XML, flags, - DATA_VERDICT); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + if (e->flags & (1 << NFT_SET_ELEM_ATTR_DATA)) + type = DATA_VALUE; + else if (e->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) + type = DATA_CHAIN; + else if (e->flags & (1 << NFT_SET_ELEM_ATTR_VERDICT)) + type = DATA_VERDICT; - ret = snprintf(buf+offset, size, "</data>"); - SNPRINTF_BUFFER_SIZE(ret, size, len, offset); - } else if (e->flags & (1 << NFT_SET_ELEM_ATTR_CHAIN)) { + if (type != DATA_NONE) { ret = snprintf(buf+offset, size, "<data>"); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = nft_data_reg_snprintf(buf+offset, len, &e->data, - NFT_RULE_O_XML, flags, DATA_CHAIN); + NFT_RULE_O_XML, flags, type); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf+offset, size, "</data>"); |