diff options
author | Álvaro Neira Ayuso <alvaroneay@gmail.com> | 2014-01-06 00:51:14 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-01-06 13:20:46 +0100 |
commit | e87d2f9ef8a4a298de5514b30ec2d43d3c90a644 (patch) | |
tree | b1379f466db57d1a8bf8c2e6048f8a3933ef9639 /src/common.c | |
parent | b4a0d19dc1b16a614cdf0aa362f754e734486b38 (diff) |
src: new error reporting approach for XML/JSON parsers
I have added a new structure for reporting some errors in parser
that we can't cover with errno.
In this patch, we have three errors that we can't cover with errno:
NFT_PARSE_EBADINPUT : Bad XML/JSON format in the input
NFT_PARSE_EMISSINGNODE : Missing node in our input
NFT_PARSE_EBADTYPE : Wrong type value in a node
Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index f03e730..5c6ddbf 100644 --- a/src/common.c +++ b/src/common.c @@ -14,6 +14,7 @@ #include <libnftables/common.h> #include "internal.h" +#include<stdlib.h> struct nlmsghdr *nft_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq) @@ -34,3 +35,33 @@ struct nlmsghdr *nft_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, return nlh; } EXPORT_SYMBOL(nft_nlmsg_build_hdr); + +struct nft_parse_err *nft_parse_err_alloc(void) +{ + return calloc(1, sizeof(struct nft_parse_err)); +} +EXPORT_SYMBOL(nft_parse_err_alloc); + +void nft_parse_err_free(struct nft_parse_err *err) +{ + xfree(err); +} +EXPORT_SYMBOL(nft_parse_err_free); + +int nft_parse_perror(const char *str, struct nft_parse_err *err) +{ + switch (err->error) { + case NFT_PARSE_EBADINPUT: + return fprintf(stderr, "%s : Bad input format in line %d column %d\n", + str, err->line, err->column); + case NFT_PARSE_EMISSINGNODE: + return fprintf(stderr, "%s : Node \"%s\" not found\n", + str, err->node_name); + case NFT_PARSE_EBADTYPE: + return fprintf(stderr, "%s: Invalid type in node \"%s\"\n", + str, err->node_name); + default: + return fprintf(stderr, "Undefined error\n"); + } +} +EXPORT_SYMBOL(nft_parse_perror); |