vfs: check userland buffers before reading them.
[haiku.git] / headers / private / shared / Json.h
blob73746f21775d32435a8a3c9bd841589806ce6b03
1 /*
2 * Copyright 2017, Andrew Lindesay <apl@lindesay.co.nz>
3 * Copyright 2014, Augustin Cavalier (waddlesplash)
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef _JSON_H
7 #define _JSON_H
10 #include "JsonEventListener.h"
12 #include <Message.h>
13 #include <String.h>
16 namespace BPrivate {
18 class JsonParseContext;
20 class BJson {
22 public:
23 static status_t Parse(const char* JSON, BMessage& message);
24 static status_t Parse(const BString& JSON, BMessage& message);
25 static void Parse(BDataIO* data,
26 BJsonEventListener* listener);
28 private:
29 static bool NextChar(JsonParseContext& jsonParseContext,
30 char* c);
31 static bool NextNonWhitespaceChar(
32 JsonParseContext& jsonParseContext,
33 char* c);
35 static bool ParseAny(JsonParseContext& jsonParseContext);
36 static bool ParseObjectNameValuePair(
37 JsonParseContext& jsonParseContext);
38 static bool ParseObject(JsonParseContext& jsonParseContext);
39 static bool ParseArray(JsonParseContext& jsonParseContext);
40 static bool ParseEscapeUnicodeSequence(
41 JsonParseContext& jsonParseContext,
42 BString& stringResult);
43 static bool ParseStringEscapeSequence(
44 JsonParseContext& jsonParseContext,
45 BString& stringResult);
46 static bool ParseString(JsonParseContext& jsonParseContext,
47 json_event_type eventType);
48 static bool ParseExpectedVerbatimStringAndRaiseEvent(
49 JsonParseContext& jsonParseContext,
50 const char* expectedString,
51 size_t expectedStringLength,
52 char leadingChar,
53 json_event_type jsonEventType);
54 static bool ParseExpectedVerbatimString(
55 JsonParseContext& jsonParseContext,
56 const char* expectedString,
57 size_t expectedStringLength,
58 char leadingChar);
60 static bool IsValidNumber(BString& number);
61 static bool ParseNumber(JsonParseContext& jsonParseContext);
64 } // namespace BPrivate
66 using BPrivate::BJson;
68 #endif // _JSON_H