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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
#include <string.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "types.h"
#include "xml_parse.h"
#include "union_type.h"
#include "ui_interface.h"
#include "ui_main_screen.h"
#include "ui_notif_dlg.h"
#include "ui_filters.h"
#include "../libresolver/locate_root.h"
#include "../libresolver/resolvers.h"
extern int debug_parser;
#if (ENABLE_DISPLAY_PARSE_INFO != 0)
# define INDENT_START 30
#else
# define INDENT_START 0
#endif
#define PARSER_DEBUG(fmt, args...) \
do { \
if (debug_parser) \
g_debug("WARNING: "fmt, ##args); \
} while(0)
#define PARSER_ERROR(fmt, args...) \
do { \
g_error("FATAL: "fmt, ##args); \
} while(0)
types_t *root = NULL;
static int xml_parse_doc(xmlDocPtr doc);
static int parse_attribute_name(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "name")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve name attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
return -1;
}
else {
PARSER_DEBUG("cannot retrieve name attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
return 0;
}
}
type->name = strdup ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_id(xmlNode *node, types_t *type) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "id")) == NULL) {
PARSER_ERROR("cannot retrieve id attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
return -1;
}
type->id = atoi ((char *) &node_attribute->children->content[1]);
return 0;
}
static int parse_attribute_size(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "size")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve size attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->size = -1;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve size attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->size = -1;
return 0;
}
}
type->size = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_align(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "align")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve align attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->align = -1;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve align attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->align = -1;
return 0;
}
}
type->align = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_line(xmlNode *node, types_t *type) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "line")) == NULL) {
type->line = -1;
return 0;
}
type->line = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_file(xmlNode *node, types_t *type) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "file")) == NULL) {
type->file = NULL;
return 0;
}
type->file = strdup ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_context(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "context")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve context attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->context = -1;
return -1;
}
else {
type->context = -1;
return 0;
}
}
type->context = atoi ((char *) &node_attribute->children->content[1]);
return 0;
}
static int parse_attribute_artificial(xmlNode *node, types_t *type) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "artificial")) == NULL) {
PARSER_DEBUG("cannot retrieve artificial attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->artificial = -1;
return 0;
}
type->artificial = atoi ((char *) &node_attribute->children->content[1]);
return 0;
}
static int parse_attribute_init(xmlNode *node, types_t *type) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "init")) == NULL) {
PARSER_ERROR("cannot retrieve init attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->init_value = -1;
return 0;
}
type->init_value = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_members(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "members")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve members attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->members = 0;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve members attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->members = 0;
return 0;
}
}
type->members = strdup ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_mangled(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "mangled")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve mangled attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->mangled = 0;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve mangled attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->mangled = 0;
return 0;
}
}
type->mangled = strdup ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_demangled(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "mangled")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve demangled attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->demangled = 0;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve demangled attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->demangled = 0;
return 0;
}
}
type->demangled = strdup ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_offset(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "offset")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve offset attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->offset = -1;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve offset attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->offset = -1;
return 0;
}
}
type->offset = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_bits(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "bits")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve bits attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->bits = -1;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve bits attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->bits = -1;
return 0;
}
}
type->bits = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_type(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "type")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve type attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->type_xml = 0;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve type attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->type_xml = 0;
return 0;
}
}
type->type_xml = atoi ((char *) &node_attribute->children->content[1]);
return 0;
}
static int parse_attribute_min(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "min")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve min attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->min = 0;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve min attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->min = 0;
return 0;
}
}
type->min = atoi ((char *) node_attribute->children->content);
return 0;
}
static int parse_attribute_max(xmlNode *node, types_t *type, int mandatory) {
xmlAttrPtr node_attribute;
if ((node_attribute = xmlHasProp (node, (xmlChar *) "max")) == NULL) {
if (mandatory) {
PARSER_ERROR("cannot retrieve max attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->max = 0;
return -1;
}
else {
PARSER_DEBUG("cannot retrieve max attribute in node %s, %s:%ld",
(char *)node->name, node->doc->URL, XML_GET_LINE(node));
type->max = 0;
return 0;
}
}
type->max = atoi ((char *) &node_attribute->children->content[1]);
return 0;
}
static int parse_enum_values(xmlNode *node, types_t *parent) {
types_t *new;
if (node == NULL || parent == NULL)
return -1;
new = type_new (TYPE_ENUMERATION_VALUE);
CHECK_FCT(parse_attribute_name(node, new, 1));
CHECK_FCT(parse_attribute_init(node, new));
CHECK_FCT(types_insert_tail(&parent->child, new));
return 0;
}
static int parse_enumeration(xmlNode *node, types_t **head) {
types_t *new;
xmlNode *enum_value_node;
if (node == NULL)
return -1;
new = type_new (TYPE_ENUMERATION);
CHECK_FCT(parse_attribute_name(node, new, 1));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_size(node, new, 1));
CHECK_FCT(parse_attribute_align(node, new, 1));
CHECK_FCT(parse_attribute_context(node, new, 0));
CHECK_FCT(parse_attribute_line(node, new));
CHECK_FCT(parse_attribute_file(node, new));
CHECK_FCT(parse_attribute_artificial(node, new));
CHECK_FCT(types_insert_tail(head, new));
/* Parse enum values */
for (enum_value_node = node->children; enum_value_node; enum_value_node = enum_value_node->next) {
if (strcmp ((char *) enum_value_node->name, "EnumValue") == 0)
CHECK_FCT(parse_enum_values(enum_value_node, new));
}
return 0;
}
static int parse_union(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_UNION);
CHECK_FCT(parse_attribute_name(node, new, 0));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_size(node, new, 1));
CHECK_FCT(parse_attribute_align(node, new, 1));
CHECK_FCT(parse_attribute_context(node, new, 0));
CHECK_FCT(parse_attribute_members(node, new, 0));
CHECK_FCT(parse_attribute_line(node, new));
CHECK_FCT(parse_attribute_file(node, new));
CHECK_FCT(parse_attribute_artificial(node, new));
CHECK_FCT(parse_attribute_mangled(node, new, 0));
CHECK_FCT(parse_attribute_demangled(node, new, 0));
if (new->name)
if (strcmp (new->name, "msg_s") == 0)
new->type_dissect_from_buffer = union_msg_dissect_from_buffer;
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_fundamental(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_FUNDAMENTAL);
CHECK_FCT(parse_attribute_name(node, new, 1));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_size(node, new, 0));
CHECK_FCT(parse_attribute_align(node, new, 0));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_struct(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_STRUCT);
CHECK_FCT(parse_attribute_name(node, new, 0));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_size(node, new, 0));
CHECK_FCT(parse_attribute_align(node, new, 0));
CHECK_FCT(parse_attribute_file(node, new));
CHECK_FCT(parse_attribute_line(node, new));
CHECK_FCT(parse_attribute_context(node, new, 0));
CHECK_FCT(parse_attribute_artificial(node, new));
CHECK_FCT(parse_attribute_members(node, new, 0));
CHECK_FCT(parse_attribute_mangled(node, new, 0));
CHECK_FCT(parse_attribute_demangled(node, new, 0));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_typedef(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_TYPEDEF);
CHECK_FCT(parse_attribute_name(node, new, 1));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_file(node, new));
CHECK_FCT(parse_attribute_line(node, new));
CHECK_FCT(parse_attribute_type(node, new, 1));
CHECK_FCT(parse_attribute_size(node, new, 0));
CHECK_FCT(parse_attribute_align(node, new, 0));
CHECK_FCT(parse_attribute_context(node, new, 0));
CHECK_FCT(parse_attribute_artificial(node, new));
CHECK_FCT(parse_attribute_members(node, new, 0));
CHECK_FCT(parse_attribute_mangled(node, new, 0));
CHECK_FCT(parse_attribute_demangled(node, new, 0));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_field(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_FIELD);
CHECK_FCT(parse_attribute_name(node, new, 1));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_type(node, new, 1));
CHECK_FCT(parse_attribute_size(node, new, 0));
CHECK_FCT(parse_attribute_bits(node, new, 0));
CHECK_FCT(parse_attribute_offset(node, new, 0));
CHECK_FCT(parse_attribute_align(node, new, 0));
CHECK_FCT(parse_attribute_context(node, new, 0));
CHECK_FCT(parse_attribute_artificial(node, new));
CHECK_FCT(parse_attribute_members(node, new, 0));
CHECK_FCT(parse_attribute_mangled(node, new, 0));
CHECK_FCT(parse_attribute_demangled(node, new, 0));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_file(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_FILE);
CHECK_FCT(parse_attribute_name(node, new, 1));
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_reference_type(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_REFERENCE);
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_type(node, new, 1));
CHECK_FCT(parse_attribute_size(node, new, 1));
CHECK_FCT(parse_attribute_align(node, new, 1));
CHECK_FCT(parse_attribute_context(node, new, 0));
CHECK_FCT(parse_attribute_offset(node, new, 0));
CHECK_FCT(parse_attribute_file(node, new));
CHECK_FCT(parse_attribute_line(node, new));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_array_type(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_ARRAY);
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_type(node, new, 1));
CHECK_FCT(parse_attribute_size(node, new, 0));
CHECK_FCT(parse_attribute_align(node, new, 1));
CHECK_FCT(parse_attribute_min(node, new, 1));
CHECK_FCT(parse_attribute_max(node, new, 1));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_pointer_type(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_POINTER);
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(parse_attribute_type(node, new, 1));
CHECK_FCT(parse_attribute_size(node, new, 1));
CHECK_FCT(parse_attribute_align(node, new, 1));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
static int parse_function_type(xmlNode *node, types_t **head) {
types_t *new;
if (node == NULL)
return -1;
new = type_new (TYPE_FUNCTION);
CHECK_FCT(parse_attribute_id(node, new));
CHECK_FCT(types_insert_tail(head, new));
return 0;
}
/**
* print_element_names:
* @a_node: the initial xml node to consider.
*
* Prints the names of the all the xml elements
* that are siblings or children of a given xml node.
*/
static int parse_elements(xmlNode * a_node, types_t **head) {
xmlNode *cur_node = NULL;
xmlNode *child_node = NULL;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
for (child_node = cur_node->children; child_node; child_node = child_node->next) {
if (child_node->type == XML_ELEMENT_NODE) {
if (strcmp ((char *) child_node->name, "Enumeration") == 0) {
CHECK_FCT_DO(parse_enumeration(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "FundamentalType") == 0) {
CHECK_FCT_DO(parse_fundamental(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "Struct") == 0) {
CHECK_FCT_DO(parse_struct(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "Union") == 0) {
CHECK_FCT_DO(parse_union(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "Typedef") == 0) {
CHECK_FCT_DO(parse_typedef(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "File") == 0) {
CHECK_FCT_DO(parse_file(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "Field") == 0) {
CHECK_FCT_DO(parse_field(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "ReferenceType") == 0) {
CHECK_FCT_DO(parse_reference_type(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "ArrayType") == 0) {
CHECK_FCT_DO(parse_array_type(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "PointerType") == 0) {
CHECK_FCT_DO(parse_pointer_type(child_node, head), return RC_FAIL);
}
else
if (strcmp ((char *) child_node->name, "FunctionType") == 0) {
CHECK_FCT_DO(parse_function_type(child_node, head), return RC_FAIL);
}
}
}
}
return RC_OK;
}
int xml_parse_buffer(const char *xml_buffer, const int size) {
xmlDocPtr doc; /* the resulting document tree */
if (xml_buffer == NULL) {
return -1;
}
g_message("Parsing XML definition from buffer ...");
doc = xmlReadMemory(xml_buffer, size, NULL, NULL, 0);
if (doc == NULL) {
g_warning("Failed to parse XML buffer: %s", xml_buffer);
ui_notification_dialog(GTK_MESSAGE_ERROR, "parse messages format definition", "Fail to parse XML buffer");
return RC_FAIL;
}
return xml_parse_doc(doc);
}
int xml_parse_file(const char *filename) {
xmlDocPtr doc; /* the resulting document tree */
if (filename == NULL) {
return -1;
}
doc = xmlReadFile (filename, NULL, 0);
if (doc == NULL) {
ui_notification_dialog(GTK_MESSAGE_ERROR, "parse messages format definition", "Failed to parse file \"%s\"", filename);
return RC_FAIL;
}
return xml_parse_doc(doc);
}
static int update_filters() {
types_t *types;
ui_init_filters(FALSE, TRUE);
types = messages_id_enum;
if (types != NULL)
{
types = types->child;
while (types != NULL)
{
if (strcmp (types->name, "MESSAGES_ID_MAX") != 0)
{
ui_filters_add (FILTER_MESSAGES, types->init_value, types->name, ENTRY_ENABLED_UNDEFINED, NULL, NULL);
}
types = types->next;
}
}
types = origin_task_id_type;
if (types != NULL)
{
types = types->child->child;
while (types != NULL) {
if ((strcmp (types->name, "TASK_FIRST") != 0) && (strcmp (types->name, "TASK_MAX") != 0))
{
ui_filters_add(FILTER_ORIGIN_TASKS, types->init_value, types->name, ENTRY_ENABLED_UNDEFINED, NULL, NULL);
}
types = types->next;
}
}
types = destination_task_id_type;
if (types != NULL)
{
types = types->child->child;
while (types != NULL) {
if ((strcmp (types->name, "TASK_FIRST") != 0) && (strcmp (types->name, "TASK_MAX") != 0))
{
ui_filters_add(FILTER_DESTINATION_TASKS, types->init_value, types->name, ENTRY_ENABLED_UNDEFINED, NULL, NULL);
}
types = types->next;
}
}
return RC_OK;
}
static int xml_parse_doc(xmlDocPtr doc) {
xmlNode *root_element = NULL;
types_t *head = NULL;
int ret = 0;
FILE *dissect_file = NULL;
if (ui_main_data.dissect_file_name != NULL) {
dissect_file = fopen (ui_main_data.dissect_file_name, "w");
}
/* Get the root element node */
root_element = xmlDocGetRootElement(doc);
ret = parse_elements(root_element, &head);
/* Free the document */
xmlFreeDoc(doc);
if (ret == RC_OK) {
resolve_typedefs (&head);
resolve_pointer_type (&head);
resolve_field (&head);
resolve_array (&head);
resolve_reference (&head);
resolve_struct (&head);
resolve_file (&head);
resolve_union (&head);
resolve_function (&head);
/* Locate the root element which corresponds to the MessageDef struct */
CHECK_FCT(locate_root("MessageDef", head, &root));
/* Locate the LTE time fields */
if (locate_type("lte_time", head, <e_time_type) == RC_OK)
{
CHECK_FCT(locate_type("frame", lte_time_type->child->child, <e_time_frame_type));
CHECK_FCT(locate_type("slot", lte_time_type->child->child, <e_time_slot_type));
}
/* Locate the message id field */
CHECK_FCT(locate_type("MessagesIds", head, &messages_id_enum));
/* Locate the header part of a message */
CHECK_FCT(locate_type("ittiMsgHeader", head, &message_header_type));
/* Locate the main message part */
CHECK_FCT(locate_type("msg", head, &message_type));
/* Locate the origin task id field */
CHECK_FCT(locate_type("originTaskId", message_header_type, &origin_task_id_type));
/* Locate the destination task id field */
CHECK_FCT(locate_type("destinationTaskId", message_header_type, &destination_task_id_type));
/* Locate the instance field */
CHECK_FCT(locate_type("instance", message_header_type, &instance_type));
/* Locate the message size field */
CHECK_FCT(locate_type("ittiMsgSize", message_header_type, &message_size_type));
// root->type_hr_display(root, 0);
update_filters();
if (dissect_file != NULL) {
g_debug("generating dissected types file \"%s\" ...", ui_main_data.dissect_file_name);
root->type_file_print (root, 0, dissect_file);
}
}
if (dissect_file != NULL) {
fclose (dissect_file);
}
g_message("Parsed XML definition");
return ret;
}
int dissect_signal_header(buffer_t *buffer, ui_set_signal_text_cb_t ui_set_signal_text_cb,
gpointer cb_user_data)
{
if (message_header_type == NULL) {
g_error("No messages format definition provided");
return RC_FAIL;
}
if (buffer == NULL) {
g_error("Failed buffer is NULL");
return RC_FAIL;
}
message_header_type->type_dissect_from_buffer(
message_header_type, ui_set_signal_text_cb, cb_user_data,
buffer, 0, 0, INDENT_START, TRUE);
return RC_OK;
}
int dissect_signal(buffer_t *buffer, ui_set_signal_text_cb_t ui_set_signal_text_cb,
gpointer cb_user_data)
{
if (message_type == NULL) {
g_error("No messages format definition provided");
return RC_FAIL;
}
if (buffer == NULL) {
g_error("Failed buffer is NULL");
return RC_FAIL;
}
message_type->type_dissect_from_buffer(message_type, ui_set_signal_text_cb, cb_user_data,
buffer, 0, 0, INDENT_START, TRUE);
return RC_OK;
}