]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Ventoy2Disk/Ventoy2Disk/VentoyJson.h
Update languages.json (#1174)
[Ventoy.git] / Ventoy2Disk / Ventoy2Disk / VentoyJson.h
1 /******************************************************************************
2 * VentoyJson.h
3 *
4 * Copyright (c) 2021, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #ifndef __VENTOY_JSON_H__
22 #define __VENTOY_JSON_H__
23
24 #ifdef FOR_VTOY_JSON_CHECK
25 typedef unsigned char UINT8;
26 typedef unsigned short UINT16;
27 typedef unsigned int UINT32;
28 typedef unsigned long long UINT64;
29
30 #define Log printf
31 #define strcpy_s(a, b, c) strncpy(a, c, b)
32 #define sprintf_s snprintf
33 #endif
34
35 #define JSON_SUCCESS 0
36 #define JSON_FAILED 1
37 #define JSON_NOT_FOUND 2
38
39 typedef enum _JSON_TYPE
40 {
41 JSON_TYPE_NUMBER = 0,
42 JSON_TYPE_STRING,
43 JSON_TYPE_BOOL,
44 JSON_TYPE_ARRAY,
45 JSON_TYPE_OBJECT,
46 JSON_TYPE_NULL,
47 JSON_TYPE_BUTT
48 }JSON_TYPE;
49
50
51 typedef struct _VTOY_JSON
52 {
53 struct _VTOY_JSON *pstPrev;
54 struct _VTOY_JSON *pstNext;
55 struct _VTOY_JSON *pstChild;
56
57 JSON_TYPE enDataType;
58 union
59 {
60 char *pcStrVal;
61 int iNumVal;
62 UINT64 lValue;
63 }unData;
64
65 char *pcName;
66 }VTOY_JSON;
67
68 typedef struct _JSON_PARSE
69 {
70 char *pcKey;
71 void *pDataBuf;
72 UINT32 uiBufSize;
73 }JSON_PARSE;
74
75 #define JSON_NEW_ITEM(pstJson, ret) \
76 { \
77 (pstJson) = (VTOY_JSON *)malloc(sizeof(VTOY_JSON)); \
78 if (NULL == (pstJson)) \
79 { \
80 Log("Failed to alloc memory for json.\n"); \
81 return (ret); \
82 } \
83 memset((pstJson), 0, sizeof(VTOY_JSON));\
84 }
85
86 VTOY_JSON *vtoy_json_find_item
87 (
88 VTOY_JSON *pstJson,
89 JSON_TYPE enDataType,
90 const char *szKey
91 );
92 int vtoy_json_parse_value
93 (
94 char *pcNewStart,
95 char *pcRawStart,
96 VTOY_JSON *pstJson,
97 const char *pcData,
98 const char **ppcEnd
99 );
100 VTOY_JSON * vtoy_json_create(void);
101 int vtoy_json_parse(VTOY_JSON *pstJson, const char *szJsonData);
102
103 int vtoy_json_scan_parse
104 (
105 const VTOY_JSON *pstJson,
106 UINT32 uiParseNum,
107 JSON_PARSE *pstJsonParse
108 );
109
110 int vtoy_json_scan_array
111 (
112 VTOY_JSON *pstJson,
113 const char *szKey,
114 VTOY_JSON **ppstArrayItem
115 );
116
117 int vtoy_json_scan_array_ex
118 (
119 VTOY_JSON *pstJson,
120 const char *szKey,
121 VTOY_JSON **ppstArrayItem
122 );
123 int vtoy_json_scan_object
124 (
125 VTOY_JSON *pstJson,
126 const char *szKey,
127 VTOY_JSON **ppstObjectItem
128 );
129 int vtoy_json_get_int
130 (
131 VTOY_JSON *pstJson,
132 const char *szKey,
133 int *piValue
134 );
135 int vtoy_json_get_uint
136 (
137 VTOY_JSON *pstJson,
138 const char *szKey,
139 UINT32 *puiValue
140 );
141 int vtoy_json_get_uint64
142 (
143 VTOY_JSON *pstJson,
144 const char *szKey,
145 UINT64 *pui64Value
146 );
147 int vtoy_json_get_bool
148 (
149 VTOY_JSON *pstJson,
150 const char *szKey,
151 UINT8 *pbValue
152 );
153 int vtoy_json_get_string
154 (
155 VTOY_JSON *pstJson,
156 const char *szKey,
157 UINT32 uiBufLen,
158 char *pcBuf
159 );
160 const char * vtoy_json_get_string_ex(VTOY_JSON *pstJson, const char *szKey);
161 int vtoy_json_destroy(VTOY_JSON *pstJson);
162
163 #endif /* __VENTOY_JSON_H__ */
164