From e87d2f9ef8a4a298de5514b30ec2d43d3c90a644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Neira=20Ayuso?= Date: Mon, 6 Jan 2014 00:51:14 +0100 Subject: 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 Signed-off-by: Pablo Neira Ayuso --- examples/nft-set-json-add.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'examples/nft-set-json-add.c') diff --git a/examples/nft-set-json-add.c b/examples/nft-set-json-add.c index 9a4aa48..9553ebf 100644 --- a/examples/nft-set-json-add.c +++ b/examples/nft-set-json-add.c @@ -38,6 +38,7 @@ int main(int argc, char *argv[]) uint16_t family; char json[4096]; char reprint[4096]; + struct nft_parse_err *err; if (argc < 2) { printf("Usage: %s \n", argv[0]); @@ -62,10 +63,16 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + err = nft_parse_err_alloc(); + if (err == NULL) { + perror("error"); + exit(EXIT_FAILURE); + } + close(fd); - if (nft_set_parse(s, NFT_PARSE_JSON, json) < 0) { - printf("E: Unable to parse JSON file: %s\n", strerror(errno)); + if (nft_set_parse(s, NFT_PARSE_JSON, json, err) < 0) { + nft_parse_perror("Unable to parse JSON file", err); exit(EXIT_FAILURE); } @@ -80,6 +87,7 @@ int main(int argc, char *argv[]) NLM_F_CREATE|NLM_F_ACK, seq); nft_set_nlmsg_build_payload(nlh, s); nft_set_free(s); + nft_parse_err_free(err); nl = mnl_socket_open(NETLINK_NETFILTER); if (nl == NULL) { -- cgit v1.2.3 From 59e949294f4688bafe44b7def2972987224520c8 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Mon, 20 Jan 2014 10:26:57 +0100 Subject: rename library to libnftnl We plan to use this library name for the higher layer library. Signed-off-by: Pablo Neira Ayuso --- examples/nft-set-json-add.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/nft-set-json-add.c') diff --git a/examples/nft-set-json-add.c b/examples/nft-set-json-add.c index 9553ebf..a4535da 100644 --- a/examples/nft-set-json-add.c +++ b/examples/nft-set-json-add.c @@ -25,7 +25,7 @@ #include #include -#include +#include int main(int argc, char *argv[]) { -- cgit v1.2.3