From a03e0c8ba8c9230a3890d6fbd813fcf051086e7f Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Fri, 13 Nov 2020 19:49:15 +0100 Subject: Fixed inconsistent callback function call if a token parsed. Signed-off-by: Toni Uhlig --- examples/c-captured/c-captured.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/c-captured/c-captured.c b/examples/c-captured/c-captured.c index 8b6785aea..d2ca51c2c 100644 --- a/examples/c-captured/c-captured.c +++ b/examples/c-captured/c-captured.c @@ -17,7 +17,16 @@ static enum nDPIsrvd_callback_return nDPIsrvd_json_callback(struct nDPIsrvd_sock { (void)user_data; - if (sock->jsmn.current_token % 2 == 1) + if (sock->jsmn.current_token == 0) { + /* Start of a JSON string. */ + printf("JSON "); + } + else if (sock->jsmn.current_token == sock->jsmn.tokens_found) + { + /* End of a JSON string. */ + printf(" EoF\n"); + } + else if (sock->jsmn.current_token % 2 == 1) { printf("[%.*s : ", sock->jsmn.tokens[sock->jsmn.current_token].end - sock->jsmn.tokens[sock->jsmn.current_token].start, @@ -68,7 +77,6 @@ int main(int argc, char ** argv) default: break; } - printf("EoF\n"); } return 0; -- cgit v1.2.3