yaml.anubis
7.13 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*
* Created by PyramIDE.
* User: フランスのトトロ aka (David RENÉ)
* Date: 07/06/2016
* Time: 23:15
* © David RENÉ
*/
read tools/basis.anubis
read tools/streams.anubis
transmit yaml_type.anubis
read yaml_parser.anubis
define One print_yaml_map (String indent_str, List(YAML_Key_Value) so_far).
define One
print_yaml_value
(
String indent_str,
String type,
String value
)=
println(indent_str + " - Type: " + type);
if value = "" then unique else println(indent_str + " - Value: " + value).
define One
print_yaml_list
(
String indent_str,
List(YAML_Value) so_far
)=
if so_far is
{
[ ] then
unique,
[l . t] then
if l is
{
null then
print_yaml_value(indent_str + " ", "null", ""),
string(str) then
print_yaml_value(indent_str + " ", "String", *str),
int(integer) then
print_yaml_value(indent_str + " ", "Integer", "" + *integer),
bool(boolean) then
with value_str =
if *boolean then
"true"
else
"false",
print_yaml_value(indent_str + " ", "Boolean", "" + value_str),
map(key_values) then
print_yaml_map(indent_str + " ", *key_values),
list(yaml_values) then
println(indent_str + " - List: [");
print_yaml_list(indent_str + " ", *yaml_values);
println(indent_str + " ]"),
};
(if t is [] then unique else println(""));
print_yaml_list(indent_str, t)
}.
define One
print_yaml_map
(
String indent_str,
List(YAML_Key_Value) so_far
)=
if so_far is
{
[ ] then unique,
[map . t] then
since map is key_value(key, yaml_value),
println(indent_str + " - Key name: " + key);
if *yaml_value is
{
null then
print_yaml_value(indent_str, "null", ""),
string(str) then
print_yaml_value(indent_str, "String", *str),
int(integer) then
print_yaml_value(indent_str, "Integer", "" + *integer),
bool(boolean) then
with value_str =
if *boolean then
"true"
else
"false",
print_yaml_value(indent_str, "Boolean", "" + value_str),
map(key_values) then
print_yaml_map(indent_str + " ", *key_values),
list(yaml_values) then
println(indent_str + " - List: [");
print_yaml_list(indent_str + " ", *yaml_values);
println(indent_str + " ]"),
};
(if t is [] then unique else println(""));
print_yaml_map(indent_str, t)
}.
define One
print_yaml_nodes
(
List(YAML_Node) so_far
)=
if so_far is
{
[ ] then unique,
[node . t] then
print(" YAML Node (");
if node is
{
map(key_values) then
println("map)");
print_yaml_map("", reverse(*key_values)),
list(values) then
println("list)");
print_yaml_list("", *values)
};
print_yaml_nodes(t)
}.
define One
print_yaml_documents
(
List(YAML_Document) so_far,
Int n
)=
if so_far is
{
[ ] then unique,
[doc . t] then
since doc is yaml_document(nodes),
println("YAML Document " + n + ":");
print_yaml_nodes(reverse(*nodes));
print_yaml_documents(t, n + 1)
}.
public define One
print_yaml_data
(
YAML yaml
)=
since yaml is yaml(documents),
print_yaml_documents(*documents, 1).
public define Maybe(YAML_Value)
get_value
(
List(YAML_Key_Value) key_values,
String search_key
)=
if key_values is
{
[] then failure,
[h . t] then
since h is key_value(key, value),
if search_key = key then
success(*value)
else
get_value(t, search_key)
}.
public define Maybe(List(YAML_Key_Value))
get_map_in_list_entry
(
List(YAML_Value) list_values,
String search_key
)=
if list_values is
{
[] then failure,
[h . t] then
//check if the first entry of the list value is a map
if h is map(key_values) then
//if yes check if the map's first entry key is equal to search key
if *key_values is
{
[] then get_map_in_list_entry(t, search_key),
[_key_value . _] then
since _key_value is key_value(key, value),
if key = search_key then
//check if the entry is map
if *value is map(_key_values) then
success(*_key_values)
else
get_map_in_list_entry(t, search_key)
else
get_map_in_list_entry(t, search_key)
}
else
get_map_in_list_entry(t, search_key)
}.
public define Maybe(YAML_Value)
get_YAML_value
(
List(YAML_Key_Value) root,
List(String) path
)=
if path is
{
[] then failure,
[current_name . tail] then
with final = if tail is [] then true else false,
if get_value(root, current_name) is
{
failure then failure,
success(r_value) then
//if is the final round hence we return the result
if final then
success(r_value)
// NOT Final round, continue to recurse on path to get targeted YAML_Value
else if r_value is map(new_root) then
//this is a map hencec recurse next
get_YAML_value(*new_root, tail)
//this is a list.
else if r_value is list(current_list) then
//Hence try to get an entry (1st level only) with a yaml_value which is YAML_Key_Value
//get the map within a list which the name of the key is current_name
if get_map_in_list_entry(*current_list, current_name) is
{
failure then failure,
success(new_root) then get_YAML_value(new_root, tail)
}
else
failure
}
}
.
public define Maybe(Bool)
get_Bool
(
List(YAML_Key_Value) root,
List(String) path
)=
if get_YAML_value(root, path) is
{
failure then failure,
success(y_value) then
if y_value is bool(vb_value) then
success(*vb_value)
else
failure
}.
public define Bool
get_Bool
(
List(YAML_Key_Value) root,
List(String) path,
Bool default
)=
if get_Bool(root, path) is
{
failure then default,
success(b_value) then b_value
}.
public define YAML
load
(
String yaml_file
)=
if (Maybe(RStream))file(yaml_file, read) is
{
failure then yaml(var([])),
success(f) then parse_YAML_file(make_stream(f))
}.
global define One
yaml_test
(
List(String) dummy
)=
with yaml_parsing_result = load(my_anubis_directory+"/IDPS/suricata/test.yaml"),
print_yaml_data(yaml_parsing_result).