forked from Annihil/mod_defender
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathJsonValidator.hpp
51 lines (44 loc) · 1.33 KB
/
JsonValidator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* _ _ __ _
* _ __ ___ ___ __| | __| | ___ / _| ___ _ __ __| | ___ _ __
* | '_ ` _ \ / _ \ / _` | / _` |/ _ \ |_ / _ \ '_ \ / _` |/ _ \ '__|
* | | | | | | (_) | (_| | | (_| | __/ _| __/ | | | (_| | __/ |
* |_| |_| |_|\___/ \__,_|___\__,_|\___|_| \___|_| |_|\__,_|\___|_|
* |_____|
* Copyright (c) 2017 Annihil
* Released under the GPLv3
*/
#ifndef MOD_DEFENDER_JSONVALIDATOR_H
#define MOD_DEFENDER_JSONVALIDATOR_H
#include "Util.h"
class RuntimeScanner;
/*
** To avoid getting DoS'ed, define max depth
** for JSON parser, as it is recursive
*/
#define JSON_MAX_DEPTH 10
/*
** this structure is used only for json parsing.
*/
typedef struct {
str_t json;
u_char *src;
unsigned long off = 0, len = 0;
u_char c;
int depth = 0;
str_t ckey;
} json_t;
class JsonValidator {
friend class RuntimeScanner;
private:
RuntimeScanner& scanner;
bool jsonObj(json_t &js);
bool jsonVal(json_t &js);
bool jsonArray(json_t &js);
bool jsonQuoted(json_t &js, str_t *ve);
bool jsonForward(json_t &js);
bool jsonSeek(json_t &js, unsigned char seek);
public:
JsonValidator(RuntimeScanner& scanner) : scanner(scanner) {}
void jsonParse(u_char *src, unsigned long len);
};
#endif //MOD_DEFENDER_JSONVALIDATOR_H