Debian Codegraph @

src/decrypters/widevine/jsmn.h

raw
1 /*
2 * Copyright (C) 2017 peak3d (http://www.peak3d.de)
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #ifndef __JSMN_H_
10 #define __JSMN_H_
11
12 #include <stddef.h>
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18 /**
19 * JSON type identifier. Basic types are:
20 * o Object
21 * o Array
22 * o String
23 * o Other primitive: number, boolean (true/false) or null
24 */
25 typedef enum {
26 JSMN_UNDEFINED = 0,
27 JSMN_OBJECT = 1,
28 JSMN_ARRAY = 2,
29 JSMN_STRING = 3,
30 JSMN_PRIMITIVE = 4
31 } jsmntype_t;
32
33 enum jsmnerr {
34 /* Not enough tokens were provided */
35 JSMN_ERROR_NOMEM = -1,
36 /* Invalid character inside JSON string */
37 JSMN_ERROR_INVAL = -2,
38 /* The string is not a full JSON packet, more bytes expected */
39 JSMN_ERROR_PART = -3
40 };
41
42 /**
43 * JSON token description.
44 * @param type type (object, array, string etc.)
45 * @param start start position in JSON data string
46 * @param end end position in JSON data string
47 */
48 typedef struct {
49 jsmntype_t type;
50 int start;
51 int end;
52 int size;
53 #ifdef JSMN_PARENT_LINKS
54 int parent;
55 #endif
56 } jsmntok_t;
57
58 /**
59 * JSON parser. Contains an array of token blocks available. Also stores
60 * the string being parsed now and current position in that string
61 */
62 typedef struct {
63 unsigned int pos; /* offset in the JSON string */
64 unsigned int toknext; /* next token to allocate */
65 int toksuper; /* superior token node, e.g parent object or array */
66 } jsmn_parser;
67
68 /**
69 * Create JSON parser over an array of tokens
70 */
71 void jsmn_init(jsmn_parser *parser);
72
73 /**
74 * Run JSON parser. It parses a JSON data string into and array of tokens, each describing
75 * a single JSON object.
76 */
77 int jsmn_parse(jsmn_parser *parser, const char *js, size_t len,
78 jsmntok_t *tokens, unsigned int num_tokens);
79
80 #ifdef __cplusplus
81 }
82 #endif
83
84 #endif /* __JSMN_H_ */