1 // SoftEther VPN Source Code - Stable Edition Repository
2 // Mayaqua Kernel
3 //
4 // SoftEther VPN Server, Client and Bridge are free software under the Apache License, Version 2.0.
5 //
6 // Copyright (c) Daiyuu Nobori.
7 // Copyright (c) SoftEther VPN Project, University of Tsukuba, Japan.
8 // Copyright (c) SoftEther Corporation.
9 // Copyright (c) all contributors on SoftEther VPN project in GitHub.
10 //
11 // All Rights Reserved.
12 //
13 // http://www.softether.org/
14 //
15 // This stable branch is officially managed by Daiyuu Nobori, the owner of SoftEther VPN Project.
16 // Pull requests should be sent to the Developer Edition Master Repository on https://github.com/SoftEtherVPN/SoftEtherVPN
17 //
18 // License: The Apache License, Version 2.0
19 // https://www.apache.org/licenses/LICENSE-2.0
20 //
21 // DISCLAIMER
22 // ==========
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 // SOFTWARE.
31 //
32 // THIS SOFTWARE IS DEVELOPED IN JAPAN, AND DISTRIBUTED FROM JAPAN, UNDER
33 // JAPANESE LAWS. YOU MUST AGREE IN ADVANCE TO USE, COPY, MODIFY, MERGE, PUBLISH,
34 // DISTRIBUTE, SUBLICENSE, AND/OR SELL COPIES OF THIS SOFTWARE, THAT ANY
35 // JURIDICAL DISPUTES WHICH ARE CONCERNED TO THIS SOFTWARE OR ITS CONTENTS,
36 // AGAINST US (SOFTETHER PROJECT, SOFTETHER CORPORATION, DAIYUU NOBORI OR OTHER
37 // SUPPLIERS), OR ANY JURIDICAL DISPUTES AGAINST US WHICH ARE CAUSED BY ANY KIND
38 // OF USING, COPYING, MODIFYING, MERGING, PUBLISHING, DISTRIBUTING, SUBLICENSING,
39 // AND/OR SELLING COPIES OF THIS SOFTWARE SHALL BE REGARDED AS BE CONSTRUED AND
40 // CONTROLLED BY JAPANESE LAWS, AND YOU MUST FURTHER CONSENT TO EXCLUSIVE
41 // JURISDICTION AND VENUE IN THE COURTS SITTING IN TOKYO, JAPAN. YOU MUST WAIVE
42 // ALL DEFENSES OF LACK OF PERSONAL JURISDICTION AND FORUM NON CONVENIENS.
43 // PROCESS MAY BE SERVED ON EITHER PARTY IN THE MANNER AUTHORIZED BY APPLICABLE
44 // LAW OR COURT RULE.
45 //
46 // USE ONLY IN JAPAN. DO NOT USE THIS SOFTWARE IN ANOTHER COUNTRY UNLESS YOU HAVE
47 // A CONFIRMATION THAT THIS SOFTWARE DOES NOT VIOLATE ANY CRIMINAL LAWS OR CIVIL
48 // RIGHTS IN THAT PARTICULAR COUNTRY. USING THIS SOFTWARE IN OTHER COUNTRIES IS
49 // COMPLETELY AT YOUR OWN RISK. THE SOFTETHER VPN PROJECT HAS DEVELOPED AND
50 // DISTRIBUTED THIS SOFTWARE TO COMPLY ONLY WITH THE JAPANESE LAWS AND EXISTING
51 // CIVIL RIGHTS INCLUDING PATENTS WHICH ARE SUBJECTS APPLY IN JAPAN. OTHER
52 // COUNTRIES' LAWS OR CIVIL RIGHTS ARE NONE OF OUR CONCERNS NOR RESPONSIBILITIES.
53 // WE HAVE NEVER INVESTIGATED ANY CRIMINAL REGULATIONS, CIVIL LAWS OR
54 // INTELLECTUAL PROPERTY RIGHTS INCLUDING PATENTS IN ANY OF OTHER 200+ COUNTRIES
55 // AND TERRITORIES. BY NATURE, THERE ARE 200+ REGIONS IN THE WORLD, WITH
56 // DIFFERENT LAWS. IT IS IMPOSSIBLE TO VERIFY EVERY COUNTRIES' LAWS, REGULATIONS
57 // AND CIVIL RIGHTS TO MAKE THE SOFTWARE COMPLY WITH ALL COUNTRIES' LAWS BY THE
58 // PROJECT. EVEN IF YOU WILL BE SUED BY A PRIVATE ENTITY OR BE DAMAGED BY A
59 // PUBLIC SERVANT IN YOUR COUNTRY, THE DEVELOPERS OF THIS SOFTWARE WILL NEVER BE
60 // LIABLE TO RECOVER OR COMPENSATE SUCH DAMAGES, CRIMINAL OR CIVIL
61 // RESPONSIBILITIES. NOTE THAT THIS LINE IS NOT LICENSE RESTRICTION BUT JUST A
62 // STATEMENT FOR WARNING AND DISCLAIMER.
63 //
64 // READ AND UNDERSTAND THE 'WARNING.TXT' FILE BEFORE USING THIS SOFTWARE.
65 // SOME SOFTWARE PROGRAMS FROM THIRD PARTIES ARE INCLUDED ON THIS SOFTWARE WITH
66 // LICENSE CONDITIONS WHICH ARE DESCRIBED ON THE 'THIRD_PARTY.TXT' FILE.
67 //
68 //
69 // SOURCE CODE CONTRIBUTION
70 // ------------------------
71 //
72 // Your contribution to SoftEther VPN Project is much appreciated.
73 // Please send patches to us through GitHub.
74 // Read the SoftEther VPN Patch Acceptance Policy in advance:
75 // http://www.softether.org/5-download/src/9.patch
76 //
77 //
78 // DEAR SECURITY EXPERTS
79 // ---------------------
80 //
81 // If you find a bug or a security vulnerability please kindly inform us
82 // about the problem immediately so that we can fix the security problem
83 // to protect a lot of users around the world as soon as possible.
84 //
85 // Our e-mail address for security reports is:
86 // softether-vpn-security [at] softether.org
87 //
88 // Please note that the above e-mail address is not a technical support
89 // inquiry address. If you need technical assistance, please visit
90 // http://www.softether.org/ and ask your question on the users forum.
91 //
92 // Thank you for your cooperation.
93 //
94 //
95 // NO MEMORY OR RESOURCE LEAKS
96 // ---------------------------
97 //
98 // The memory-leaks and resource-leaks verification under the stress
99 // test has been passed before release this source code.
100 
101 
102 // Str.h
103 // Header of Str.c
104 
105 #ifndef	STR_H
106 #define	STR_H
107 
108 // String token
109 struct TOKEN_LIST
110 {
111 	UINT NumTokens;
112 	char **Token;
113 };
114 
115 // INI_ENTRY
116 struct INI_ENTRY
117 {
118 	char *Key;
119 	char *Value;
120 	wchar_t *UnicodeValue;
121 };
122 
123 // Function prototype
124 UINT StrLen(char *str);
125 UINT StrSize(char *str);
126 bool StrCheckLen(char *str, UINT len);
127 bool StrCheckSize(char *str, UINT size);
128 UINT StrCpy(char *dst, UINT size, char *src);
129 UINT StrCpyAllowOverlap(char *dst, UINT size, char *src);
130 UINT StrCat(char *dst, UINT size, char *src);
131 UINT StrCatLeft(char *dst, UINT size, char *src);
132 char ToLower(char c);
133 char ToUpper(char c);
134 void StrUpper(char *str);
135 void StrLower(char *str);
136 int StrCmp(char *str1, char *str2);
137 int StrCmpi(char *str1, char *str2);
138 void FormatArgs(char *buf, UINT size, char *fmt, va_list args);
139 void Format(char *buf, UINT size, char *fmt, ...);
140 char *CopyFormat(char *fmt, ...);
141 void Print(char *fmt, ...);
142 void PrintArgs(char *fmt, va_list args);
143 void PrintStr(char *str);
144 void Debug(char *fmt, ...);
145 void DebugArgs(char *fmt, va_list args);
146 UINT ToInt(char *str);
147 bool ToBool(char *str);
148 int ToInti(char *str);
149 void ToStr(char *str, UINT i);
150 void ToStri(char *str, int i);
151 void ToStrx(char *str, UINT i);
152 void ToStrx8(char *str, UINT i);
153 void TrimCrlf(char *str);
154 void Trim(char *str);
155 void TrimRight(char *str);
156 void TrimLeft(char *str);
157 bool GetLine(char *str, UINT size);
158 void FreeToken(TOKEN_LIST *tokens);
159 bool IsInToken(TOKEN_LIST *t, char *str);
160 TOKEN_LIST *ParseToken(char *src, char *separator);
161 void InitStringLibrary();
162 void FreeStringLibrary();
163 bool CheckStringLibrary();
164 bool InChar(char *string, char c);
165 UINT SearchStrEx(char *string, char *keyword, UINT start, bool case_sensitive);
166 UINT SearchStri(char *string, char *keyword, UINT start);
167 UINT SearchStr(char *string, char *keyword, UINT start);
168 UINT CalcReplaceStrEx(char *string, char *old_keyword, char *new_keyword, bool case_sensitive);
169 UINT ReplaceStrEx(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword, bool case_sensitive);
170 UINT ReplaceStr(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword);
171 UINT ReplaceStri(char *dst, UINT size, char *string, char *old_keyword, char *new_keyword);
172 bool IsPrintableAsciiChar(char c);
173 bool IsPrintableAsciiStr(char *str);
174 void EnPrintableAsciiStr(char *str, char replace);
175 bool IsSafeChar(char c);
176 bool IsSafeStr(char *str);
177 void EnSafeStr(char *str, char replace);
178 void TruncateCharFromStr(char *str, char replace);
179 char *CopyStr(char *str);
180 void BinToStr(char *str, UINT str_size, void *data, UINT data_size);
181 void BinToStrW(wchar_t *str, UINT str_size, void *data, UINT data_size);
182 void PrintBin(void *data, UINT size);
183 bool StartWith(char *str, char *key);
184 bool EndWith(char *str, char *key);
185 bool TrimEndWith(char *dst, UINT dst_size, char *str, char *key);
186 UINT64 ToInt64(char *str);
187 UINT64 Json_ToInt64Ex(char *str, char **endptr, bool *error);
188 void ToStr64(char *str, UINT64 value);
189 char *ReplaceFormatStringFor64(char *fmt);
190 TOKEN_LIST *ParseCmdLine(char *str);
191 TOKEN_LIST *CopyToken(TOKEN_LIST *src);
192 TOKEN_LIST *NullToken();
193 bool IsNum(char *str);
194 LIST *StrToStrList(char *str, UINT size);
195 BUF *StrListToStr(LIST *o);
196 void FreeStrList(LIST *o);
197 TOKEN_LIST *ListToTokenList(LIST *o);
198 LIST *TokenListToList(TOKEN_LIST *t);
199 bool IsEmptyStr(char *str);
200 void BinToStrEx(char *str, UINT str_size, void *data, UINT data_size);
201 void BinToStrEx2(char *str, UINT str_size, void *data, UINT data_size, char padding_char);
202 char *CopyBinToStrEx(void *data, UINT data_size);
203 char *CopyBinToStr(void *data, UINT data_size);
204 BUF *StrToBin(char *str);
205 void MacToStr(char *str, UINT size, UCHAR *mac_address);
206 void ToStr3(char *str, UINT size, UINT64 v);
207 void ToStrByte(char *str, UINT size, UINT64 v);
208 void ToStrByte1000(char *str, UINT size, UINT64 v);
209 TOKEN_LIST *UniqueToken(TOKEN_LIST *t);
210 char *NormalizeCrlf(char *str);
211 bool IsAllUpperStr(char *str);
212 UINT StrWidth(char *str);
213 char *MakeCharArray(char c, UINT count);
214 void MakeCharArray2(char *str, char c, UINT count);
215 bool StrToMac(UCHAR *mac_address, char *str);
216 bool IsSplitChar(char c, char *split_str);
217 bool GetKeyAndValue(char *str, char *key, UINT key_size, char *value, UINT value_size, char *split_str);
218 LIST *ReadIni(BUF *b);
219 INI_ENTRY *GetIniEntry(LIST *o, char *key);
220 void FreeIni(LIST *o);
221 UINT IniIntValue(LIST *o, char *key);
222 UINT64 IniInt64Value(LIST *o, char *key);
223 char *IniStrValue(LIST *o, char *key);
224 wchar_t *IniUniStrValue(LIST *o, char *key);
225 bool IniHasValue(LIST *o, char *key);
226 bool InStr(char *str, char *keyword);
227 bool InStrEx(char *str, char *keyword, bool case_sensitive);
228 bool InStrList(char *target_str, char *tokens, char *splitter, bool case_sensitive);
229 TOKEN_LIST *ParseTokenWithoutNullStr(char *str, char *split_chars);
230 TOKEN_LIST *ParseTokenWithNullStr(char *str, char *split_chars);
231 char *DefaultTokenSplitChars();
232 bool IsCharInStr(char *str, char c);
233 UINT HexTo4Bit(char c);
234 char FourBitToHex(UINT value);
235 void ToHex(char *str, UINT value);
236 void ToHex64(char *str, UINT64 value);
237 UINT HexToInt(char *str);
238 UINT64 HexToInt64(char *str);
239 UINT SearchAsciiInBinary(void *data, UINT size, char *str, bool case_sensitive);
240 bool IsStrInStrTokenList(char *str_list, char *str, char *split_chars, bool case_sensitive);
241 void IntListToStr(char *str, UINT str_size, LIST *o, char *separate_str);
242 LIST *StrToIntList(char *str, bool sorted);
243 void NormalizeIntListStr(char *dst, UINT dst_size, char *src, bool sorted, char *separate_str);
244 void ClearStr(char *str, UINT str_size);
245 void SetStrCaseAccordingToBits(char *str, UINT bits);
246 char *UrlDecode(char *url_str);
247 
248 
249 // *** JSON strings support
250 // Original source code from Parson ( http://kgabis.github.com/parson/ )
251 // Modified by dnobori
252 /*
253 Parson ( http://kgabis.github.com/parson/ )
254 Copyright (c) 2012 - 2017 Krzysztof Gabis
255 
256 Permission is hereby granted, free of charge, to any person obtaining a copy
257 of this software and associated documentation files (the "Software"), to deal
258 in the Software without restriction, including without limitation the rights
259 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
260 copies of the Software, and to permit persons to whom the Software is
261 furnished to do so, subject to the following conditions:
262 
263 The above copyright notice and this permission notice shall be included in
264 all copies or substantial portions of the Software.
265 
266 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
267 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
268 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
269 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
270 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
271 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
272 THE SOFTWARE.
273 */
274 
275 
276 /* Type definitions */
277 typedef union JSON_VALUE_UNION {
278 	char        *string;
279 	UINT64       number;
280 	JSON_OBJECT *object;
281 	JSON_ARRAY  *array;
282 	int          boolean;
283 	int          null;
284 } JSON_VALUE_UNION;
285 
286 struct JSON_VALUE {
287 	JSON_VALUE      *parent;
288 	UINT  type;
289 	JSON_VALUE_UNION value;
290 };
291 
292 struct JSON_OBJECT {
293 	JSON_VALUE  *wrapping_value;
294 	char       **names;
295 	JSON_VALUE **values;
296 	UINT       count;
297 	UINT       capacity;
298 };
299 
300 struct JSON_ARRAY {
301 	JSON_VALUE  *wrapping_value;
302 	JSON_VALUE **items;
303 	UINT       count;
304 	UINT       capacity;
305 };
306 
307 
308 enum JSON_TYPES {
309 	JSON_TYPE_ERROR = -1,
310 	JSON_TYPE_NULL = 1,
311 	JSON_TYPE_STRING = 2,
312 	JSON_TYPE_NUMBER = 3,
313 	JSON_TYPE_OBJECT = 4,
314 	JSON_TYPE_ARRAY = 5,
315 	JSON_TYPE_BOOL = 6
316 };
317 //typedef unsigned int UINT;
318 
319 enum JSON_RETS {
320 	JSON_RET_OK = 0,
321 	JSON_RET_ERROR = -1
322 };
323 
324 typedef void * (*JSON_Malloc_Function)(UINT);
325 typedef void(*JSON_Free_Function)(void *);
326 
327 /* Call only once, before calling any other function from parson API. If not called, malloc and free
328 from stdlib will be used for all allocations */
329 void JsonSetAllocationFunctions(JSON_Malloc_Function malloc_fun, JSON_Free_Function free_fun);
330 
331 /*  Parses first JSON value in a string, returns NULL in case of error */
332 JSON_VALUE * JsonParseString(char *string);
333 
334 /*  Parses first JSON value in a string and ignores comments (/ * * / and //),
335 returns NULL in case of error */
336 JSON_VALUE * JsonParseStringWithComments(char *string);
337 
338 /* Serialization */
339 UINT      JsonGetSerializationSize(JSON_VALUE *value); /* returns 0 on fail */
340 UINT JsonSerializeToBuffer(JSON_VALUE *value, char *buf, UINT buf_size_in_bytes);
341 char *      JsonSerializeToString(JSON_VALUE *value);
342 
343 /* Pretty serialization */
344 UINT      JsonGetSerializationSizePretty(JSON_VALUE *value); /* returns 0 on fail */
345 UINT JsonSerializeToBufferPretty(JSON_VALUE *value, char *buf, UINT buf_size_in_bytes);
346 char *      JsonSerializeToStringPretty(JSON_VALUE *value);
347 char *JsonToStr(JSON_VALUE *v);
348 
349 void        JsonFreeString(char *string); /* frees string from json_serialize_to_string and json_serialize_to_string_pretty */
350 
351 										  /* Comparing */
352 int  JsonCmp(JSON_VALUE *a, JSON_VALUE *b);
353 
354 /* Validation
355 This is *NOT* JSON Schema. It validates json by checking if object have identically
356 named fields with matching types.
357 For example schema {"name":"", "age":0} will validate
358 {"name":"Joe", "age":25} and {"name":"Joe", "age":25, "gender":"m"},
359 but not {"name":"Joe"} or {"name":"Joe", "age":"Cucumber"}.
360 In case of arrays, only first value in schema is checked against all values in tested array.
361 Empty objects ({}) validate all objects, empty arrays ([]) validate all arrays,
362 null validates values of every type.
363 */
364 UINT JsonValidate(JSON_VALUE *schema, JSON_VALUE *value);
365 
366 /*
367 * JSON Object
368 */
369 JSON_VALUE  * JsonGet(JSON_OBJECT *object, char *name);
370 char  * JsonGetStr(JSON_OBJECT *object, char *name);
371 JSON_OBJECT * JsonGetObj(JSON_OBJECT *object, char *name);
372 JSON_ARRAY  * JsonGetArray(JSON_OBJECT *object, char *name);
373 UINT64        JsonGetNumber(JSON_OBJECT *object, char *name); /* returns 0 on fail */
374 bool          JsonGetBool(JSON_OBJECT *object, char *name); /* returns 0 on fail */
375 
376 															/* dotget functions enable addressing values with dot notation in nested objects,
377 															just like in structs or c++/java/c# objects (e.g. objectA.objectB.value).
378 															Because valid names in JSON can contain dots, some values may be inaccessible
379 															this way. */
380 JSON_VALUE  * JsonDotGet(JSON_OBJECT *object, char *name);
381 char  * JsonDotGetStr(JSON_OBJECT *object, char *name);
382 JSON_OBJECT * JsonDotGetObj(JSON_OBJECT *object, char *name);
383 JSON_ARRAY  * JsonDotGetArray(JSON_OBJECT *object, char *name);
384 UINT64        JsonDotGetNumber(JSON_OBJECT *object, char *name); /* returns 0 on fail */
385 bool          JsonDotGetBool(JSON_OBJECT *object, char *name); /* returns -1 on fail */
386 
387 															   /* Functions to get available names */
388 UINT        JsonGetCount(JSON_OBJECT *object);
389 char  * JsonGetName(JSON_OBJECT *object, UINT index);
390 JSON_VALUE  * JsonGetValueAt(JSON_OBJECT *object, UINT index);
391 JSON_VALUE  * JsonGetWrappingValue(JSON_OBJECT *object);
392 
393 /* Functions to check if object has a value with a specific name. Returned value is 1 if object has
394 * a value and 0 if it doesn't. dothas functions behave exactly like dotget functions. */
395 int JsonIsExists(JSON_OBJECT *object, char *name);
396 int JsonIsExistsWithValueType(JSON_OBJECT *object, char *name, UINT type);
397 
398 int JsonDotIsExists(JSON_OBJECT *object, char *name);
399 int JsonDotIsExistsWithValueType(JSON_OBJECT *object, char *name, UINT type);
400 
401 /* Creates new name-value pair or frees and replaces old value with a new one.
402 * json_object_set_value does not copy passed value so it shouldn't be freed afterwards. */
403 UINT JsonSet(JSON_OBJECT *object, char *name, JSON_VALUE *value);
404 UINT JsonSetStr(JSON_OBJECT *object, char *name, char *string);
405 UINT JsonSetUniStr(JSON_OBJECT *object, char *name, wchar_t *string);
406 UINT JsonSetNumber(JSON_OBJECT *object, char *name, UINT64 number);
407 UINT JsonSetBool(JSON_OBJECT *object, char *name, int boolean);
408 UINT JsonSetNull(JSON_OBJECT *object, char *name);
409 UINT JsonSetData(JSON_OBJECT *object, char *name, void *data, UINT size);
410 
411 /* Works like dotget functions, but creates whole hierarchy if necessary.
412 * json_object_dotset_value does not copy passed value so it shouldn't be freed afterwards. */
413 UINT JsonDotSet(JSON_OBJECT *object, char *name, JSON_VALUE *value);
414 UINT JsonDotSetStr(JSON_OBJECT *object, char *name, char *string);
415 UINT JsonDotSetNumber(JSON_OBJECT *object, char *name, UINT64 number);
416 UINT JsonDotSetBool(JSON_OBJECT *object, char *name, int boolean);
417 UINT JsonDotSetNull(JSON_OBJECT *object, char *name);
418 
419 /* Frees and removes name-value pair */
420 UINT JsonDelete(JSON_OBJECT *object, char *name);
421 
422 /* Works like dotget function, but removes name-value pair only on exact match. */
423 UINT JsonDotDelete(JSON_OBJECT *object, char *key);
424 
425 /* Removes all name-value pairs in object */
426 UINT JsonDeleteAll(JSON_OBJECT *object);
427 
428 /*
429 *JSON Array
430 */
431 JSON_VALUE  * JsonArrayGet(JSON_ARRAY *array, UINT index);
432 char  * JsonArrayGetStr(JSON_ARRAY *array, UINT index);
433 JSON_OBJECT * JsonArrayGetObj(JSON_ARRAY *array, UINT index);
434 JSON_ARRAY  * JsonArrayGetArray(JSON_ARRAY *array, UINT index);
435 UINT64        JsonArrayGetNumber(JSON_ARRAY *array, UINT index); /* returns 0 on fail */
436 bool           JsonArrayGetBool(JSON_ARRAY *array, UINT index); /* returns 0 on fail */
437 UINT        JsonArrayGetCount(JSON_ARRAY *array);
438 JSON_VALUE  * JsonArrayGetWrappingValue(JSON_ARRAY *array);
439 
440 /* Frees and removes value at given index, does nothing and returns JSONFailure if index doesn't exist.
441 * Order of values in array may change during execution.  */
442 UINT JsonArrayDelete(JSON_ARRAY *array, UINT i);
443 
444 /* Frees and removes from array value at given index and replaces it with given one.
445 * Does nothing and returns JSONFailure if index doesn't exist.
446 * json_array_replace_value does not copy passed value so it shouldn't be freed afterwards. */
447 UINT JsonArrayReplace(JSON_ARRAY *array, UINT i, JSON_VALUE *value);
448 UINT JsonArrayReplaceStr(JSON_ARRAY *array, UINT i, char* string);
449 UINT JsonArrayReplaceNumber(JSON_ARRAY *array, UINT i, UINT64 number);
450 UINT JsonArrayReplaceBool(JSON_ARRAY *array, UINT i, int boolean);
451 UINT JsonArrayReplaceNull(JSON_ARRAY *array, UINT i);
452 
453 /* Frees and removes all values from array */
454 UINT JsonArrayDeleteAll(JSON_ARRAY *array);
455 
456 /* Appends new value at the end of array.
457 * json_array_append_value does not copy passed value so it shouldn't be freed afterwards. */
458 UINT JsonArrayAdd(JSON_ARRAY *array, JSON_VALUE *value);
459 UINT JsonArrayAddStr(JSON_ARRAY *array, char *string);
460 UINT JsonArrayAddUniStr(JSON_ARRAY *array, wchar_t *string);
461 UINT JsonArrayAddNumber(JSON_ARRAY *array, UINT64 number);
462 UINT JsonArrayAddData(JSON_ARRAY *array, void *data, UINT size);
463 UINT JsonArrayAddBool(JSON_ARRAY *array, int boolean);
464 UINT JsonArrayAddNull(JSON_ARRAY *array);
465 
466 
467 /*
468 *JSON Value
469 */
470 JSON_VALUE * JsonNewObject(void);
471 JSON_VALUE * JsonNewArray(void);
472 JSON_VALUE * JsonNewStr(char *string); /* copies passed string */
473 JSON_VALUE * JsonNewNumber(UINT64 number);
474 JSON_VALUE * JsonNewBool(int boolean);
475 JSON_VALUE * JsonNewNull(void);
476 JSON_VALUE * JsonDeepCopy(JSON_VALUE *value);
477 void         JsonFree(JSON_VALUE *value);
478 
479 UINT JsonValueGetType(JSON_VALUE *value);
480 JSON_OBJECT *   JsonValueGetObject(JSON_VALUE *value);
481 JSON_ARRAY  *   JsonValueGetArray(JSON_VALUE *value);
482 char  *   JsonValueGetStr(JSON_VALUE *value);
483 UINT64          JsonValueGetNumber(JSON_VALUE *value);
484 bool            JsonValueGetBool(JSON_VALUE *value);
485 JSON_VALUE  *   JsonValueGetParent(JSON_VALUE *value);
486 
487 /* Same as above, but shorter */
488 UINT JsonType(JSON_VALUE *value);
489 JSON_OBJECT *   JsonObject(JSON_VALUE *value);
490 JSON_ARRAY  *   JsonArray(JSON_VALUE *value);
491 char  *   JsonString(JSON_VALUE *value);
492 UINT64          JsonNumber(JSON_VALUE *value);
493 int             JsonBool(JSON_VALUE *value);
494 
495 void SystemTimeToJsonStr(char *dst, UINT size, SYSTEMTIME *t);
496 void SystemTime64ToJsonStr(char *dst, UINT size, UINT64 t);
497 
498 JSON_VALUE *StrToJson(char *str);
499 
500 #endif	// STR_H
501 
502