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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
|
#include <gtest/gtest.h>
#include "mpack.h"
#include "control_packet.h"
static u_char control_packet_active0[] = {
0x85, 0xA5, 0x74, 0x73, 0x79, 0x6E, 0x63, 0xA3, 0x32, 0x2E, 0x30, 0xAA, 0x73, 0x65, 0x73, 0x73,
0x69, 0x6F, 0x6E, 0x5F, 0x69, 0x64, 0xCF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xA5,
0x73, 0x74, 0x61, 0x74, 0x65, 0xA6, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0xA6, 0x6D, 0x65, 0x74,
0x68, 0x6F, 0x64, 0xAD, 0x70, 0x6F, 0x6C, 0x69, 0x63, 0x79, 0x5F, 0x75, 0x70, 0x64, 0x61, 0x74,
0x65, 0xA6, 0x70, 0x61, 0x72, 0x61, 0x6D, 0x73, 0x83, 0xA3, 0x73, 0x63, 0x65, 0x81, 0xA8, 0x72,
0x75, 0x6C, 0x65, 0x5F, 0x69, 0x64, 0x73, 0x92, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xA6, 0x73, 0x68, 0x61,
0x70, 0x65, 0x72, 0x81, 0xA8, 0x72, 0x75, 0x6C, 0x65, 0x5F, 0x69, 0x64, 0x73, 0x92, 0xC4, 0x10,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03,
0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0xA5, 0x70, 0x72, 0x6F, 0x78, 0x79, 0x82, 0xA8, 0x72, 0x75, 0x6C, 0x65, 0x5F, 0x69,
0x64, 0x73, 0x92, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x05, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xAD, 0x74, 0x63, 0x70, 0x5F, 0x68, 0x61, 0x6E, 0x64,
0x73, 0x68, 0x61, 0x6B, 0x65, 0xDC, 0x00, 0x24, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33,
0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33,
0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33,
0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33, 0xA3, 0x31, 0x32, 0x33,
0xA3, 0x31, 0x32, 0x33, 0x92, 0xCD, 0x15, 0xB3, 0xCD, 0x1A, 0x0A, 0x92, 0xCD, 0x15, 0xB3, 0xCD,
0x1A, 0x0A, 0x92, 0xCD, 0x15, 0xB3, 0xCD, 0x1A, 0x0A, 0x92, 0x01, 0x01, 0x92, 0x01, 0x01};
static u_char control_packet_active1[] = {
0x85, 0xA5, 0x74, 0x73, 0x79, 0x6E, 0x63, 0xA3, 0x32, 0x2E, 0x30, 0xAA, 0x73, 0x65, 0x73, 0x73,
0x69, 0x6F, 0x6E, 0x5F, 0x69, 0x64, 0xCF, 0x04, 0x08, 0x02, 0x1B, 0x68, 0x4C, 0x03, 0xE9, 0xA5,
0x73, 0x74, 0x61, 0x74, 0x65, 0xA6, 0x61, 0x63, 0x74, 0x69, 0x76, 0x65, 0xA6, 0x6D, 0x65, 0x74,
0x68, 0x6F, 0x64, 0xAD, 0x70, 0x6F, 0x6C, 0x69, 0x63, 0x79, 0x5F, 0x75, 0x70, 0x64, 0x61, 0x74,
0x65, 0xA6, 0x70, 0x61, 0x72, 0x61, 0x6D, 0x73, 0x81, 0xA3, 0x73, 0x63, 0x65, 0x81, 0xA8, 0x72,
0x75, 0x6C, 0x65, 0x5F, 0x69, 0x64, 0x73, 0x91, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
static u_char control_packet_opening[] = {
0x83, 0xA5, 0x74, 0x73, 0x79, 0x6E, 0x63, 0xA3, 0x32, 0x2E, 0x30, 0xAA, 0x73, 0x65, 0x73, 0x73,
0x69, 0x6F, 0x6E, 0x5F, 0x69, 0x64, 0xCF, 0x04, 0x08, 0x02, 0x1B, 0x68, 0x4C, 0x03, 0xE9, 0xA5,
0x73, 0x74, 0x61, 0x74, 0x65, 0xA7, 0x6F, 0x70, 0x65, 0x6E, 0x69, 0x6E, 0x67};
static u_char control_packet_send[] = {
0x85, 0xA5, 0x74, 0x73, 0x79, 0x6E, 0x63, 0xA3, 0x32, 0x2E, 0x30, 0xAA, 0x73, 0x65, 0x73, 0x73,
0x69, 0x6F, 0x6E, 0x5F, 0x69, 0x64, 0x01, 0xA5, 0x73, 0x74, 0x61, 0x74, 0x65, 0xA6, 0x61, 0x63,
0x74, 0x69, 0x76, 0x65, 0xA6, 0x6D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0xAA, 0x6C, 0x6F, 0x67, 0x5F,
0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0xA6, 0x70, 0x61, 0x72, 0x61, 0x6D, 0x73, 0x81, 0xA3, 0x73,
0x63, 0x65, 0x83, 0xB1, 0x73, 0x63, 0x5F, 0x72, 0x75, 0x6C, 0x65, 0x5F, 0x75, 0x75, 0x69, 0x64,
0x5F, 0x6C, 0x69, 0x73, 0x74, 0x92, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xB4, 0x73, 0x63, 0x5F, 0x72, 0x73,
0x70, 0x5F, 0x72, 0x61, 0x77, 0x5F, 0x75, 0x75, 0x69, 0x64, 0x5F, 0x6C, 0x69, 0x73, 0x74, 0x92,
0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04, 0xBA, 0x73, 0x63, 0x5F, 0x72, 0x73, 0x70, 0x5F, 0x64, 0x65, 0x63, 0x72,
0x79, 0x70, 0x74, 0x65, 0x64, 0x5F, 0x75, 0x75, 0x69, 0x64, 0x5F, 0x6C, 0x69, 0x73, 0x74, 0x92,
0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xC4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x04};
static uuid_t uuid1;
static uuid_t uuid2;
static uuid_t uuid3;
static uuid_t uuid4;
static uuid_t uuid5;
static uuid_t uuid6;
static const char *uuid1_str = "00000000-0000-0000-0000-000000000001";
static const char *uuid2_str = "00000000-0000-0000-0000-000000000002";
static const char *uuid3_str = "00000000-0000-0000-0000-000000000003";
static const char *uuid4_str = "00000000-0000-0000-0000-000000000004";
static const char *uuid5_str = "00000000-0000-0000-0000-000000000005";
static const char *uuid6_str = "00000000-0000-0000-0000-000000000006";
#if 1
TEST(CONTROL_PACKET, PACKAGE0)
{
char *data;
size_t size;
mpack_writer_t writer;
mpack_writer_init_growable(&writer, &data, &size);
// write the example on the msgpack homepage
mpack_build_map(&writer); // root begin
// tsync
mpack_write_cstr(&writer, "tsync");
mpack_write_cstr(&writer, "2.0");
// session_id
mpack_write_cstr(&writer, "session_id");
mpack_write_u64(&writer, 18446744073709551615);
// state
mpack_write_cstr(&writer, "state");
mpack_write_cstr(&writer, "active");
// method
mpack_write_cstr(&writer, "method");
mpack_write_cstr(&writer, "policy_update");
// params
{
mpack_write_cstr(&writer, "params");
mpack_build_map(&writer); // params value begin
// sce
{
mpack_write_cstr(&writer, "sce");
mpack_build_map(&writer);
mpack_write_cstr(&writer, "rule_ids");
mpack_build_array(&writer);
mpack_write_bin(&writer, (const char *)&uuid1, sizeof(uuid1));
mpack_write_bin(&writer, (const char *)&uuid2, sizeof(uuid2));
mpack_complete_array(&writer);
mpack_complete_map(&writer);
}
// shaper
{
mpack_write_cstr(&writer, "shaper");
mpack_build_map(&writer);
mpack_write_cstr(&writer, "rule_ids");
mpack_build_array(&writer);
mpack_write_bin(&writer, (const char *)&uuid3, sizeof(uuid3));
mpack_write_bin(&writer, (const char *)&uuid4, sizeof(uuid4));
mpack_complete_array(&writer);
mpack_complete_map(&writer);
}
// proxy
{
mpack_write_cstr(&writer, "proxy");
mpack_build_map(&writer); // proxy value begin
mpack_write_cstr(&writer, "rule_ids");
mpack_build_array(&writer);
mpack_write_bin(&writer, (const char *)&uuid5, sizeof(uuid5));
mpack_write_bin(&writer, (const char *)&uuid6, sizeof(uuid6));
mpack_complete_array(&writer);
mpack_write_cstr(&writer, "tcp_handshake");
mpack_build_array(&writer); // tcp_handshake value begin
mpack_write_u32(&writer, 1); // tcp_seq
mpack_write_u32(&writer, 1); // tcp_ack
mpack_write_u16(&writer, 1); // tcp_mss_client
mpack_write_u16(&writer, 1); // tcp_mss_server
mpack_write_u8(&writer, 1); // tcp_wsacle_client
mpack_write_u8(&writer, 1); // tcp_wsacle_server
mpack_write_u8(&writer, 1); // tcp_sack_client
mpack_write_u8(&writer, 1); // tcp_sack_server
mpack_write_u8(&writer, 1); // tcp_ts_client
mpack_write_u8(&writer, 1); // tcp_ts_server
mpack_write_u8(&writer, 1); // tcp_protocol
mpack_write_u16(&writer, 1); // tcp_window_client
mpack_write_u16(&writer, 1); // tcp_window_server
mpack_write_u32(&writer, 1); // tcp_ts_client_val
mpack_write_u32(&writer, 1); // tcp_ts_server_val
mpack_write_u8(&writer, 1); // tcp_info_packet_cur_dir
mpack_write_str(&writer, "123", 3); // src_sub_id
mpack_write_str(&writer, "123", 3); // dst_sub_id
mpack_write_str(&writer, "123", 3); // src_asn
mpack_write_str(&writer, "123", 3); // dst_asn
mpack_write_str(&writer, "123", 3); // src_organization
mpack_write_str(&writer, "123", 3); // dst_organization
mpack_write_str(&writer, "123", 3); // src_ip_location_country
mpack_write_str(&writer, "123", 3); // dst_ip_location_country
mpack_write_str(&writer, "123", 3); // src_ip_location_provine
mpack_write_str(&writer, "123", 3); // dst_ip_location_provine
mpack_write_str(&writer, "123", 3); // src_ip_location_city
mpack_write_str(&writer, "123", 3); // dst_ip_location_city
mpack_write_str(&writer, "123", 3); // src_ip_location_subdivision
mpack_write_str(&writer, "123", 3); // dst_ip_location_subdivision
mpack_write_str(&writer, "123", 3); // ssl_client_ja3_fingerprint
mpack_build_array(&writer); // fqdn_cat_id_val
mpack_write_u32(&writer, 5555);
mpack_write_u32(&writer, 6666);
mpack_complete_array(&writer);
mpack_build_array(&writer); // tcp_seq_sids
mpack_write_u16(&writer, 5555);
mpack_write_u16(&writer, 6666);
mpack_complete_array(&writer);
mpack_build_array(&writer); // tcp_ack_sids
mpack_write_u16(&writer, 5555);
mpack_write_u16(&writer, 6666);
mpack_complete_array(&writer);
mpack_build_array(&writer); // tcp_seq_route_ctx
mpack_write_u8(&writer, 1);
mpack_write_u8(&writer, 1);
mpack_complete_array(&writer);
mpack_build_array(&writer); // tcp_ack_route_ctx
mpack_write_u8(&writer, 1);
mpack_write_u8(&writer, 1);
mpack_complete_array(&writer);
mpack_complete_array(&writer); // tcp_handshake value end
mpack_complete_map(&writer); // proxy value end
}
mpack_complete_map(&writer); // params value end
}
mpack_complete_map(&writer); // root end
// finish writing
EXPECT_TRUE(mpack_writer_destroy(&writer) == mpack_ok);
EXPECT_TRUE(size == sizeof(control_packet_active0));
EXPECT_TRUE(memcmp(data, control_packet_active0, size) == 0);
// data to hex
for (size_t i = 0; i < size; i++)
{
printf("%02X, ", data[i]);
}
printf("\n");
free(data);
}
#endif
#if 1
TEST(CONTROL_PACKET, PACKAGE1)
{
char *data;
size_t size;
mpack_writer_t writer;
mpack_writer_init_growable(&writer, &data, &size);
// write the example on the msgpack homepage
mpack_build_map(&writer); // root begin
// tsync
mpack_write_cstr(&writer, "tsync");
mpack_write_cstr(&writer, "2.0");
// session_id
mpack_write_cstr(&writer, "session_id");
mpack_write_u64(&writer, 290484492702581737);
// state
mpack_write_cstr(&writer, "state");
mpack_write_cstr(&writer, "active");
// method
mpack_write_cstr(&writer, "method");
mpack_write_cstr(&writer, "policy_update");
// params
{
mpack_write_cstr(&writer, "params");
mpack_build_map(&writer); // params value begin
// sce
{
mpack_write_cstr(&writer, "sce");
mpack_build_map(&writer);
mpack_write_cstr(&writer, "rule_ids");
mpack_build_array(&writer);
mpack_write_bin(&writer, (const char *)&uuid1, sizeof(uuid1));
mpack_complete_array(&writer);
mpack_complete_map(&writer);
}
mpack_complete_map(&writer); // params value end
}
mpack_complete_map(&writer); // root end
// finish writing
EXPECT_TRUE(mpack_writer_destroy(&writer) == mpack_ok);
EXPECT_TRUE(size == sizeof(control_packet_active1));
EXPECT_TRUE(memcmp(data, control_packet_active1, size) == 0);
// data to hex
for (size_t i = 0; i < size; i++)
{
printf("%02X, ", data[i]);
}
printf("\n");
free(data);
}
#endif
#if 1
TEST(CONTROL_PACKET, PACKAGE2)
{
char *data;
size_t size;
mpack_writer_t writer;
mpack_writer_init_growable(&writer, &data, &size);
// write the example on the msgpack homepage
mpack_build_map(&writer); // root begin
// tsync
mpack_write_cstr(&writer, "tsync");
mpack_write_cstr(&writer, "2.0");
// session_id
mpack_write_cstr(&writer, "session_id");
mpack_write_u64(&writer, 290484492702581737);
// state
mpack_write_cstr(&writer, "state");
mpack_write_cstr(&writer, "opening");
mpack_complete_map(&writer); // root end
// finish writing
EXPECT_TRUE(mpack_writer_destroy(&writer) == mpack_ok);
EXPECT_TRUE(size == sizeof(control_packet_opening));
EXPECT_TRUE(memcmp(data, control_packet_opening, size) == 0);
// data to hex
for (size_t i = 0; i < size; i++)
{
printf("%02X, ", data[i]);
}
printf("\n");
free(data);
}
#endif
#if 1
TEST(CONTROL_PACKET, PARSE0)
{
char rule_uuid_str[UUID_STRING_SIZE];
struct control_packet handler;
EXPECT_TRUE(control_packet_parse(&handler, (const char *)control_packet_active0, sizeof(control_packet_active0)) == CTRL_PKT_SUCCESS);
control_packet_dump(&handler);
EXPECT_STREQ(handler.tsync, "2.0");
EXPECT_TRUE(handler.session_id == 18446744073709551615);
EXPECT_TRUE(handler.state == SESSION_STATE_ACTIVE);
EXPECT_STREQ(handler.method, "policy_update");
EXPECT_TRUE(uuid_array_get_count(&handler.rule_uuid_array) == 2);
uuid_unparse(*uuid_array_get_at(&handler.rule_uuid_array, 0), rule_uuid_str);
EXPECT_STREQ(rule_uuid_str, uuid1_str);
uuid_unparse(*uuid_array_get_at(&handler.rule_uuid_array, 1), rule_uuid_str);
EXPECT_STREQ(rule_uuid_str, uuid2_str);
}
#endif
#if 1
TEST(CONTROL_PACKET, PARSE1)
{
char rule_uuid_str[UUID_STRING_SIZE];
struct control_packet handler;
EXPECT_TRUE(control_packet_parse(&handler, (const char *)control_packet_active1, sizeof(control_packet_active1)) == CTRL_PKT_SUCCESS);
control_packet_dump(&handler);
EXPECT_STREQ(handler.tsync, "2.0");
EXPECT_TRUE(handler.session_id == 290484492702581737);
EXPECT_TRUE(handler.state == SESSION_STATE_ACTIVE);
EXPECT_STREQ(handler.method, "policy_update");
EXPECT_TRUE(uuid_array_get_count(&handler.rule_uuid_array) == 1);
uuid_unparse(*uuid_array_get_at(&handler.rule_uuid_array, 0), rule_uuid_str);
EXPECT_STREQ(rule_uuid_str, uuid1_str);
}
#endif
#if 1
TEST(CONTROL_PACKET, PARSE2)
{
struct control_packet handler;
EXPECT_TRUE(control_packet_parse(&handler, (const char *)control_packet_opening, sizeof(control_packet_opening)) == CTRL_PKT_SUCCESS);
control_packet_dump(&handler);
EXPECT_STREQ(handler.tsync, "2.0");
EXPECT_TRUE(handler.session_id == 290484492702581737);
EXPECT_TRUE(handler.state == SESSION_STATE_OPENING);
EXPECT_STREQ(handler.method, "");
EXPECT_TRUE(uuid_array_get_count(&handler.rule_uuid_array) == 0);
}
#endif
#if 1
TEST(CONTROL_PACKET, SEND)
{
uint64_t session_id = 1;
struct uuid_array rule_uuid_array;
uuid_array_init(&rule_uuid_array);
uuid_array_append(&rule_uuid_array, uuid1);
uuid_array_append(&rule_uuid_array, uuid2);
int rule_num = uuid_array_get_count(&rule_uuid_array);
struct uuid_array sf_uuid_array;
uuid_array_init(&sf_uuid_array);
uuid_array_append(&sf_uuid_array, uuid3);
uuid_array_append(&sf_uuid_array, uuid4);
int sf_num = uuid_array_get_count(&sf_uuid_array);
char *data;
size_t size;
mpack_writer_t writer;
mpack_writer_init_growable(&writer, &data, &size);
// write the example on the msgpack homepage
mpack_build_map(&writer); // root begin
// tsync
mpack_write_cstr(&writer, "tsync");
mpack_write_cstr(&writer, "2.0");
// session_id
mpack_write_cstr(&writer, "session_id");
mpack_write_u64(&writer, session_id);
// state
mpack_write_cstr(&writer, "state");
mpack_write_cstr(&writer, "active");
// method
mpack_write_cstr(&writer, "method");
mpack_write_cstr(&writer, "log_update");
// params
{
mpack_write_cstr(&writer, "params");
mpack_build_map(&writer); // params value begin
// sce
{
mpack_write_cstr(&writer, "sce");
mpack_build_map(&writer); // sce value begin
{
mpack_write_cstr(&writer, "sc_rule_uuid_list");
mpack_build_array(&writer); // sc_rule_list begin
for (int i = 0; i < rule_num; i++)
{
mpack_write_bin(&writer, (const char *)uuid_array_get_at(&rule_uuid_array, i), sizeof(uuid_t));
}
mpack_complete_array(&writer); // sc_rule_list end
}
{
mpack_write_cstr(&writer, "sc_rsp_raw_uuid_list");
mpack_build_array(&writer); // sc_rsp_raw begin
for (int i = 0; i < sf_num; i++)
{
mpack_write_bin(&writer, (const char *)uuid_array_get_at(&sf_uuid_array, i), sizeof(uuid_t));
}
mpack_complete_array(&writer); // sc_rsp_raw end
}
{
mpack_write_cstr(&writer, "sc_rsp_decrypted_uuid_list");
mpack_build_array(&writer); // sc_rsp_decrypted begin
for (int i = 0; i < sf_num; i++)
{
mpack_write_bin(&writer, (const char *)uuid_array_get_at(&sf_uuid_array, i), sizeof(uuid_t));
}
mpack_complete_array(&writer); // sc_rsp_decrypted end
}
mpack_complete_map(&writer); // sce value end
}
mpack_complete_map(&writer); // params value end
}
mpack_complete_map(&writer); // root end
// finish writing
if (mpack_writer_destroy(&writer) != mpack_ok)
{
assert(0);
if (data)
{
free(data);
data = NULL;
}
}
for (size_t i = 0; i < size; i++)
{
printf("%02X, ", data[i]);
}
printf("\n");
EXPECT_STREQ(data, (const char *)control_packet_send);
free(data);
}
#endif
int main(int argc, char **argv)
{
uuid_parse(uuid1_str, uuid1);
uuid_parse(uuid2_str, uuid2);
uuid_parse(uuid3_str, uuid3);
uuid_parse(uuid4_str, uuid4);
uuid_parse(uuid5_str, uuid5);
uuid_parse(uuid6_str, uuid6);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
|