Initial VES for DANOS vRouter
[demo.git] / vnfs / VESreporting_vFW5.0_DANOS / evel / evel-library / code / evel_library / jsmn.h
1 /*************************************************************************//**
2  *
3  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and 
14  * limitations under the License.
15  *
16  ****************************************************************************/
17
18 #ifndef __JSMN_H_
19 #define __JSMN_H_
20
21 #include <stddef.h>
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /**
28  * JSON type identifier. Basic types are:
29  *      o Object
30  *      o Array
31  *      o String
32  *      o Other primitive: number, boolean (true/false) or null
33  */
34 typedef enum {
35         JSMN_UNDEFINED = 0,
36         JSMN_OBJECT = 1,
37         JSMN_ARRAY = 2,
38         JSMN_STRING = 3,
39         JSMN_PRIMITIVE = 4
40 } jsmntype_t;
41
42 enum jsmnerr {
43         /* Not enough tokens were provided */
44         JSMN_ERROR_NOMEM = -1,
45         /* Invalid character inside JSON string */
46         JSMN_ERROR_INVAL = -2,
47         /* The string is not a full JSON packet, more bytes expected */
48         JSMN_ERROR_PART = -3
49 };
50
51 /**
52  * JSON token description.
53  * @param               type    type (object, array, string etc.)
54  * @param               start   start position in JSON data string
55  * @param               end             end position in JSON data string
56  */
57 typedef struct {
58         jsmntype_t type;
59         int start;
60         int end;
61         int size;
62 #ifdef JSMN_PARENT_LINKS
63         int parent;
64 #endif
65 } jsmntok_t;
66
67 /**
68  * JSON parser. Contains an array of token blocks available. Also stores
69  * the string being parsed now and current position in that string
70  */
71 typedef struct {
72         unsigned int pos; /* offset in the JSON string */
73         unsigned int toknext; /* next token to allocate */
74         int toksuper; /* superior token node, e.g parent object or array */
75 } jsmn_parser;
76
77 /**
78  * Create JSON parser over an array of tokens
79  */
80 void jsmn_init(jsmn_parser *parser);
81
82 /**
83  * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
84  * a single JSON object.
85  */
86 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
87                 jsmntok_t *tokens, unsigned int num_tokens);
88
89 #ifdef __cplusplus
90 }
91 #endif
92
93 #endif /* __JSMN_H_ */