nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * Copyright (c) 2010 Serge A. Zaitsev
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22  
23 #ifndef __JSMN_H_
24 #define __JSMN_H_
25  
26 #include <stddef.h>
27  
28 #include <glib.h>
29 #include <ws_symbol_export.h>
30  
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34  
35 /**
36 * JSON type identifier. Basic types are:
37 * o Object
38 * o Array
39 * o String
40 * o Other primitive: number, boolean (true/false) or null
41 */
42 typedef enum {
43 JSMN_PRIMITIVE = 0,
44 JSMN_OBJECT = 1,
45 JSMN_ARRAY = 2,
46 JSMN_STRING = 3
47 } jsmntype_t;
48  
49 typedef enum {
50 /* Not enough tokens were provided */
51 JSMN_ERROR_NOMEM = -1,
52 /* Invalid character inside JSON string */
53 JSMN_ERROR_INVAL = -2,
54 /* The string is not a full JSON packet, more bytes expected */
55 JSMN_ERROR_PART = -3
56 } jsmnerr_t;
57  
58 /**
59 * JSON token description.
60 * type type (object, array, string etc.)
61 * start start position in JSON data string
62 * end end position in JSON data string
63 * size the size of the token
64 */
65 typedef struct {
66 jsmntype_t type;
67 int start;
68 int end;
69 int size;
70 #ifdef JSMN_PARENT_LINKS
71 int parent;
72 #endif
73 } jsmntok_t;
74  
75 /**
76 * JSON parser. Contains an array of token blocks available. Also stores
77 * the string being parsed now and current position in that string
78 */
79 typedef struct {
80 unsigned int pos; /* offset in the JSON string */
81 unsigned int toknext; /* next token to allocate */
82 int toksuper; /* superior token node, e.g parent object or array */
83 } jsmn_parser;
84  
85 /**
86 * Create JSON parser over an array of tokens
87 */
88 WS_DLL_PUBLIC void jsmn_init(jsmn_parser *parser);
89  
90 /**
91 * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
92 * a single JSON object.
93 */
94 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
95 jsmntok_t *tokens, unsigned int num_tokens);
96  
97 /**
98 * Check if a buffer is json an returns true if it is.
99 */
100 WS_DLL_PUBLIC gboolean jsmn_is_json(const guint8* buf, const size_t len);
101  
102 #ifdef __cplusplus
103 }
104 #endif
105  
106 #endif /* __JSMN_H_ */
107  
108 /*
109 * Editor modelines - http://www.wireshark.org/tools/modelines.html
110 *
111 * Local variables:
112 * c-basic-offset: 8
113 * tab-width: 8
114 * indent-tabs-mode: t
115 * End:
116 *
117 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
118 * :indentSize=8:tabSize=8:noTabs=false:
119 */