diff options
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/buffer.c b/src/buffer.c index 57d3c0c..d97d517 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -62,10 +62,9 @@ static int nftnl_buf_put(struct nftnl_buf *b, const char *fmt, ...) int nftnl_buf_open(struct nftnl_buf *b, int type, const char *tag) { switch (type) { - case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "<%s>", tag); case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "{\"%s\":{", tag); + case NFTNL_OUTPUT_XML: default: return 0; } @@ -74,8 +73,6 @@ int nftnl_buf_open(struct nftnl_buf *b, int type, const char *tag) int nftnl_buf_close(struct nftnl_buf *b, int type, const char *tag) { switch (type) { - case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "</%s>", tag); case NFTNL_OUTPUT_JSON: /* Remove trailing comma in json */ if (b->size > 0 && b->buf[b->size - 1] == ',') { @@ -85,6 +82,7 @@ int nftnl_buf_close(struct nftnl_buf *b, int type, const char *tag) } return nftnl_buf_put(b, "}}"); + case NFTNL_OUTPUT_XML: default: return 0; } @@ -96,7 +94,6 @@ int nftnl_buf_open_array(struct nftnl_buf *b, int type, const char *tag) case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "{\"%s\":[", tag); case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "<%s>", tag); default: return 0; } @@ -108,7 +105,6 @@ int nftnl_buf_close_array(struct nftnl_buf *b, int type, const char *tag) case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "]}"); case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "</%s>", tag); default: return 0; } @@ -117,10 +113,9 @@ int nftnl_buf_close_array(struct nftnl_buf *b, int type, const char *tag) int nftnl_buf_u32(struct nftnl_buf *b, int type, uint32_t value, const char *tag) { switch (type) { - case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "<%s>%u</%s>", tag, value, tag); case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "\"%s\":%u,", tag, value); + case NFTNL_OUTPUT_XML: default: return 0; } @@ -129,10 +124,9 @@ int nftnl_buf_u32(struct nftnl_buf *b, int type, uint32_t value, const char *tag int nftnl_buf_s32(struct nftnl_buf *b, int type, uint32_t value, const char *tag) { switch (type) { - case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "<%s>%d</%s>", tag, value, tag); case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "\"%s\":%d,", tag, value); + case NFTNL_OUTPUT_XML: default: return 0; } @@ -141,10 +135,9 @@ int nftnl_buf_s32(struct nftnl_buf *b, int type, uint32_t value, const char *tag int nftnl_buf_u64(struct nftnl_buf *b, int type, uint64_t value, const char *tag) { switch (type) { - case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "<%s>%"PRIu64"</%s>", tag, value, tag); case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "\"%s\":%"PRIu64",", tag, value); + case NFTNL_OUTPUT_XML: default: return 0; } @@ -153,10 +146,9 @@ int nftnl_buf_u64(struct nftnl_buf *b, int type, uint64_t value, const char *tag int nftnl_buf_str(struct nftnl_buf *b, int type, const char *str, const char *tag) { switch (type) { - case NFTNL_OUTPUT_XML: - return nftnl_buf_put(b, "<%s>%s</%s>", tag, str, tag); case NFTNL_OUTPUT_JSON: return nftnl_buf_put(b, "\"%s\":\"%s\",", tag, str); + case NFTNL_OUTPUT_XML: default: return 0; } @@ -169,11 +161,7 @@ int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg, switch (type) { case NFTNL_OUTPUT_XML: - ret = nftnl_buf_put(b, "<%s>", tag); - ret = nftnl_data_reg_snprintf(b->buf + b->off, b->len, reg, - NFTNL_OUTPUT_XML, 0, reg_type); - nftnl_buf_update(b, ret); - return nftnl_buf_put(b, "</%s>", tag); + return 0; case NFTNL_OUTPUT_JSON: nftnl_buf_put(b, "\"%s\":{", tag); ret = nftnl_data_reg_snprintf(b->buf + b->off, b->len, reg, |