-
Notifications
You must be signed in to change notification settings - Fork 13
/
test_regexp.c
125 lines (104 loc) · 4.39 KB
/
test_regexp.c
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <json.h>
#include "json_utils.h"
#define IPV6_REGEX "^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(([0-9A-Fa-f]{1,4}:){0,5}:((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|(::([0-9A-Fa-f]{1,4}:){0,5}((b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b).){3}(b((25[0-5])|(1d{2})|(2[0-4]d)|(d{1,2}))b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$"
#define IPV4_REGEX "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
int main()
{
/*
const char *to_test[] = {
"{ \"key\": \"labbcc\", \"key2\": [ \"cc\", \"aa\", \"bb\" ]}",
"{ \"key\": \"pabbcc\", \"key2\": [ 2 ]}",
"{ \"key\": \"babbcc\", \"key2\": [ ]}",
"{ \"key\": \"aabbcc\", \"key2\": [ { \"key3\": \"zz\" ]}",
"{ \"not_the_key\": \"aabbcc\" }",
"{ \"key\": 3 }",
"",
NULL,
};
const char *trusted = "{\"key\": \"[[:alpha:]]\", \"key2\": [\"[[:alpha:]]\"]}";
const char *to_test[] = {
"{ \"options\": { \"IPv4\": { \"Address\": \"12.12.12.12\" } } }",
"{ \"options\": { \"IPv4\": { \"Address\": \"999.12.12.12\" } } }",
"{ \"options\": { \"IPv4\": { \"Address\": \"...\" } } }",
"{ \"options\": { \"IPv6\": { \"Address\": \"2001:41D0:1:2E4e::1\" } } }",
"{ \"options\": { \"IPv6\": { \"Address\": \"2001::1:2E4e::1\" } } }",
"{ \"options\": { \"IPv6\": { \"Address\": \"::1:::2\" } } }",
NULL,
};
*/
/*
const char *to_test[] = {
"{ \"Identity\" : \"bob\", \"Passphrase\": \"secret123\" }",
"{ \"Identity\" : \"bob\", \"Passphrase\": \"123\" }",
"{ \"Identity\" : \"bob\" }",
"{ \"Passphrase\": \"123\" }",
"{ \"Identity\" : \"b o b\", \"Passphrase\": \"secr[}et123\" }",
"{ \"Identity\" : \"b?o!b\", \"Passphrase\": \"secret123\" }",
"{ \"Identity\" : \"\\b?o!b\", \"Passphrase\": \"//secret123\" }",
NULL
};
*/
const char *to_test[] = {
"{ \"Method\" : \"auto\" }",
"{ \"Method\" : \"manual\" }",
"{ \"Method\" : \"6to4\" }",
"{ \"Method\" : \"off\" }",
"{ \"Method\" : \"au to\" }",
"{ \"Method\" : \"auto \" }",
"{ \"Method\" : \"klfjsdlksdfjlskdfj\" }",
NULL
};
/*
const char *trusted = "{ \"service\": \"wifi_8888_8888_none\", \
\"options\": { \
\"IPv4\": { \
\"Address\": \"([[:digit:]]{1,3}\\.){3}\\.[[:digit:]]{1,3}\" \
} \
}";
*/
//struct json_object *jtmp, *jtrusted, *jsubtrusted, *jsubtrusted2, *jsubtrusted3;
struct json_object *jtmp, *jtrusted;
int i;
printf("\n[*] start\n");
//jtrusted = json_tokener_parse_ex(tok, trusted, strlen(trusted));
//printf("\n[*] jtok res: %s\n", json_tokener_error_desc(json_tokener_get_error(tok)));
jtrusted = json_object_new_object();
/*
jsubtrusted = json_object_new_object();
jsubtrusted2 = json_object_new_object();
jsubtrusted3 = json_object_new_object();
json_object_object_add(jsubtrusted2, "Address", json_object_new_string(IPV4_REGEX));
json_object_object_add(jsubtrusted, "IPv4", jsubtrusted2);
json_object_object_add(jsubtrusted3, "Address", json_object_new_string(IPV6_REGEX));
json_object_object_add(jsubtrusted, "IPv6", jsubtrusted3);
json_object_object_add(jtrusted, key_options, jsubtrusted);
*/
/*
json_object_object_add(jtrusted, "Identity",
json_object_new_string("^([[:alpha:]]+)$"));
json_object_object_add(jtrusted, "Passphrase",
json_object_new_string("^(([[:alpha:]]|[[:digit:]])*)$"));
*/
json_object_object_add(jtrusted, "Method",
json_object_new_string("^(auto|manual|6to4|off)$"));
for (i = 0; to_test[i]; i++) {
jtmp = json_tokener_parse(to_test[i]);
printf("\n[*] test %d ... ", i);
if (__json_type_dispatch(jtmp, jtrusted))
printf("PASSED");
else
printf("FAILED");
printf("\n---\n%s\n---\n", to_test[i]);
json_object_put(jtmp);
jtmp = NULL;
}
printf("\n[*] the end.\n");
json_object_put(jtrusted);
return 0;
}