-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparallel.c
More file actions
993 lines (814 loc) · 23.8 KB
/
parallel.c
File metadata and controls
993 lines (814 loc) · 23.8 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
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
/*Copyright (C) 2015 Nokia Solutions and Networks. */
/* This file is part of "Simple ASN.1 Checker". */
/* */
/* "Simple ASN.1 Checker" is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation, either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* "Simple ASN.1 Checker" is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with "Simple ASN.1 Checker". If not, see <http://www.gnu.org/licenses/>.*/
/*TO DO List: */
/*add line reference for "..." in a CHOICE */
/*give the value of constant when they are the source of error*/
/*give the line of the DEFAULT assignment for ENUMERATED*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ptype_asn.h"
#include "sac.tab.h"
extern definition_ptr my_list ;
extern definition_ptr my_list1 ;
extern definition_ptr my_list2 ;
extern int print_warnings;
extern int showIEchain;
extern char * content1;
extern char * content2;
IE_chain * IEChain1=NULL;
IE_chain * IEChain2=NULL;
extern int web; /*Boolean to indicate if the compilation is done for cgi */
int nb_error=0; /*number of non backward compatible errors*/
int nb_warnings=0; /*number of warnings*/
/*declaration of print functions*/
void showlines (int l1,int l2);
void safe_print (char *s) ;
void print_error (char * s,int l1, int l2);
void print_warning (char * s,int l1, int l2);
void print_error_4(char * s,int l1a, int l2a,int l1b, int l2b);
void add_BR () {
if (web) printf ("<BR>\n");
}
/*------ handling of IE Chain ----- */
IE_chain * add_IE (char * s) {
printf ("+");
safe_print (s);
printf ("\n");
add_BR();
}
IE_chain * add_IE2 (IE_chain * iec, char * c){
IE_chain * new_IE = NULL;
new_IE= malloc (sizeof (IE_chain));
new_IE->name=c;
new_IE->nxt=NULL;
if (iec==NULL) {
return new_IE;
}
else
{
IE_chain * temp=iec;
while (temp->nxt!=NULL)
{
temp=temp->nxt;
}
temp->nxt=new_IE;
return iec;
}
}
IE_chain * remove_last_IE (IE_chain * iec ){
if (iec==NULL) return NULL;
if(iec->nxt == NULL)
{
free (iec);
return NULL;
}
IE_chain * tmp =iec;
IE_chain * ptmp =iec;
while(tmp->nxt != NULL)
{
ptmp=tmp;
tmp = tmp->nxt;
}
ptmp->nxt=NULL;
free (tmp);
return iec;
}
IE_chain * last_IE (IE_chain * iec){
if (iec==NULL) return NULL;
if(iec->nxt == NULL)
{
return iec;
}
IE_chain * tmp =iec;
while(tmp->nxt != NULL)
{
tmp = tmp->nxt;
}
return tmp;
}
IE_chain * remove_n_last_IE (IE_chain * iec, int n) {
IE_chain * temp=iec;
int i;
for (i=0;i<n;i++) {
temp= remove_last_IE (temp);
}
return temp;
}
void IE_restore (IE_chain * iec) {
}
void clean_IE_chain (IE_chain * iec){
IE_chain * tmp=NULL;
if (iec!=NULL) {
tmp=iec->nxt;
free (iec);
clean_IE_chain (tmp);
}
}
void print_IE_chain (IE_chain * iec) {
IE_chain *tmp=iec;
while (tmp!= NULL)
{
safe_print (tmp->name);
if (tmp->nxt!=NULL) printf (" / ");
tmp=tmp->nxt;
}
}
/* --- end of handling of IE chain ---*/
int para_def (definition * l1, definition * l2)
{
if ((l1!=NULL)&&(l2!=NULL)) {
para_browse_element (l1->elem,l2->elem,-1,0,NULL,NULL);
}
}
int para_browse_content_sequence ( sequence_content * sc1, sequence_content * sc2,int op,int l1, int l2){
/*op: Optionality of the SEQUENCE : 0 Mandatory, 1 : OPTIONAL*/
/*l1 and l2: lines of the beginning of the SEQUENCE in the 2 files */
int tdflag=0; /*Flag tdflag (Three Dots flag) indicate that the SEQUENCE has been extended with three dots */
IE_chain * ic1;
IE_chain * ic2;
if ((sc1==NULL)&&(sc2!=NULL)&&(op==1)) {
if (print_warnings) {
print_warning ("Warning: Allowed non critical extension (SEQUENCE {} OP)",l1,l2);
new_branch_browse_content_sequence (sc2,1,l2);
}
return (0);
}
while ((sc1!=NULL)&&(sc2!=NULL)) {
if (sc1->threedots || sc2->threedots ) {/*In case of Three Dots: special case */
tdflag=1;
if (sc1->threedots!=sc2->threedots) {
print_error("ERROR: extension MISMATCH in a SEQUENCE",l1,l2);
return (1);
}
}
else
{
if (sc1->optionality!=sc2->optionality) {
print_error("ERROR: OPTIONALITY MISMATCH",sc1->elem->line,sc2->elem->line);
return (1);
}
if (strcmp (sc1->ie_value_name,sc2->ie_value_name)) {
if (print_warnings) {
print_warning ("Warning: name mismatch in a SEQUENCE ",sc1->elem->line,sc2->elem->line);
add_BR();
add_BR();
}
}
IEChain1=add_IE2(IEChain1,sc1->ie_value_name);
IEChain2=add_IE2(IEChain2,sc2->ie_value_name);
para_browse_element (sc1->elem, sc2->elem,0,sc1->optionality,sc1->default_str,sc2->default_str);
IEChain1=remove_last_IE(IEChain1);
IEChain2=remove_last_IE(IEChain2);
switch (sc1->optionality) {
case 1 : { /* OPTIONAL */
break;
}
case 2 : { /* DEFAULT */
/*in case of INTEGER, checks if DEFAULT value are the same */
if (7==sc1->elem->type) {
if (sc1->default_value!=sc2->default_value) {
/*The two INTEGERS do not have the same DEFAULT Value */
print_error ("ERROR: INTEGER DEFAULT mismatch ",sc1->elem->line,sc2->elem->line);
}
}
break;
}
}
}
sc1=sc1->nxt;
sc2=sc2->nxt;
}
/*checks the mew branch after the end of the first in case of extension*/
if ((tdflag)&&(sc2!=NULL)&&(sc1==NULL)) {
new_branch_browse_content_sequence (sc2,1,l2);
}
/*checks if the old file contains more element than the new file*/
if ((tdflag)&&(sc2==NULL)&&(sc1!=NULL)) {
print_error("ERROR: Old file Contains too much elements in a extended SEQUENCE",l1,l2);
}
if ((!tdflag)&&(!((sc1==NULL)&&(sc2==NULL)))) {
print_error("ERROR: ONE OF THE 2 SEQUENCE IS TOO LONG",l1,l2);
}
return (0);
}
int para_browse_choice_content ( choice_content * cc1, choice_content *cc2,int line1, int line2){
int tdflag=0;
IE_chain * ic1;
IE_chain * ic2;
while ((cc1!=NULL)&&(cc2!=NULL)) {
if (cc1->threedots || cc2->threedots ) {/*In case of Three Dots or extensions: special case */
tdflag=1;
if (cc1->threedots!=cc2->threedots) {
print_error("ERROR: Extension MISMATCH in a CHOICE",line1,line2);
return (1);
}
}
else
{
if (strcmp (cc1->ie_value_name,cc2->ie_value_name)) {
if (print_warnings) {
print_warning ("Warning: name mismatch in a CHOICE",cc1->elem->line,cc2->elem->line);
}
}
IEChain1=add_IE2(IEChain1,cc1->ie_value_name);
IEChain2=add_IE2(IEChain2,cc2->ie_value_name);
para_browse_element (cc1->elem, cc2->elem,1,0,NULL,NULL);
IEChain1=remove_last_IE(IEChain1);
IEChain2=remove_last_IE(IEChain2);
}
cc1=cc1->nxt;
cc2=cc2->nxt;
}
/*checks if the old file contains more element than the new file*/
if ((tdflag)&&((cc1!=NULL)&&(cc2==NULL))) {
print_error("ERROR: Old file Contains too much elements in a extended CHOICE",line1,line2);
}
return (0);
if ((!tdflag)&&(!((cc1==NULL)&&(cc2==NULL)))) {
print_error("ERROR: ONE OF THE 2 CHOICE IS TOO LONG",line1,line2);
}
return (0);
}
int para_browse_enumerated ( element *t1, element *t2,int source,int op,char * d1_str,char * d2_str,int line1,int line2){
/*line1 and line2 are the lines where the ENUMERATED is listed in the SEQUENCE*/
int i1,i2;
IE_chain * ie1;
IE_chain * ie2;
if (3==op) {
/*Checks if DEFAULT values are the same*/
i1=1; /* first element is number 1 */
ie1=t1->enumer.liste_enu;
while ((ie1!=NULL) &&(strcmp(ie1->name,d1_str))) {
i1++;
ie1=ie1->nxt;
}
i2=1;
ie2=t2->enumer.liste_enu;
while ((ie2!=NULL) &&(strcmp(ie2->name,d2_str))) {
i2++;
ie2=ie2->nxt;
}
if (i1!=i2) {
print_error_4("ERROR: ENUMERATED: DEFAULT differs ",line1,line2,t1->line,t2->line);
}
}
if ( ( (t2->enumer.val2)!= (t1->enumer.val2))) {
/*"..." are not at the same position*/
print_error("ERROR: ENUMERATED: usage of ... differs",t1->line,t2->line);
return (1);
}
if ((t1->enumer.val1!=t2->enumer.val1)&&((t2->enumer.val2)==0)) {
/*number of item differs */
print_error("ERROR: ENUMERATED: number of item differs ",t1->line,t2->line);
return (1);
}
if ( ((t1->enumer.val1)!=(t2->enumer.val1)) && ((t2->enumer.val2)!=0) ) {
/*"..." is used to extend the number of values */
if (print_warnings) {
print_warning("WARNING: ENUMERATED: ... used to extend the number of elements ",t1->line,t2->line);
}
}
if ((1==t1->enumer.val1)&&(0==op) && (0==source)) {
if (print_warnings) {
print_warning ("WARNING: Mandatory ENUMERATED with 1 choice only ",t1->line,t2->line);
}
}
/*Checks if the name of elements have changed */
ie1=t1->enumer.liste_enu;
ie2=t2->enumer.liste_enu;
while ((ie1!=NULL) &&(ie2!=NULL)) {
if (strcmp(ie1->name,ie2->name)) {
if (print_warnings) {
printf("WARNING: ENUMERATED: change of name in the elements %s -> %s, line: %d %d \n\n",ie1->name,ie2->name,t1->line,t2->line);
add_BR (); add_BR ();
}
}
ie2=ie2->nxt;
ie1=ie1->nxt;
}
}
int para_browse_NULL ( ){
}
int para_browse_BOOLEAN ( ){
}
int para_browse_IE_Name (element *t1, element * t2){
/* This function is never called */
}
int para_browse_element (element *t1, element *t2,int source,int op,char * d1_str,char * d2_str) {
/*source what is calling the function: 0:SEQUENCE, 1:CHOICE, -1:OTHER */
/*op: optionality of the IE in case of a sequence : 0 Mandatory, 1 OPTIONAL, 2 DEFAULT (INTEGER), 3 DEFAULT ENUMERATED */
/*This is used for the SEQUENCE {} OPTIONAL detection*/
/* d1/2_str is the string of the DEFAULT element in case of ENUMERATED DEFAULT*/
/*NOTE we have to add the possibility to remove uncoded parts like AccessStratumReleaseIndicator*/
int line1;
int line2;
/* used to save the line of the first IE in case of the definition is done in another place */
int icc1=0;
int icc2=0;
IE_chain * ie1;
IE_chain * ie2;
int i1;
int i2;
if ((t1!=NULL)&&(t2!=NULL)) {
int i;
line1=t1->line;
line2=t2->line;
/*Test if the names are the same */
if ((t1->type==10)&&(t2->type==10)) {
if (strcmp (t1->IE.IE_name,t2->IE.IE_name)) {
if (print_warnings) {
print_warning ("Warning: NAME mismatch",line1,line2);
}
}
}
/* Resolve IE_NAME-> Definition */
while ((t1->type==10)&&(t1->IE.link!=NULL)) {
IEChain1=add_IE2 (IEChain1,t1->IE.IE_name);
icc1++;
t1=t1->IE.link;
}
while ((t2->type==10)&&(t2->IE.link!=NULL)) {
IEChain2=add_IE2 (IEChain2,t2->IE.IE_name);
icc2++;
t2=t2->IE.link;
}
/* Check allowed extensions , 2=NULL*/
/* A NULL becomes something in the later version */
if ((source==1)&&(t1->type==2)&&(t2->type!=2)) {
/*We check that we are in a CHOICE, that the old version has NULL and the new version not a NULL */
if (print_warnings) {
print_warning("Warning: Allowed critical extension in CHOICE with NULL",t1->line,t2->line);
}
new_branch_browse_element (t2,1,op);
IEChain1=remove_n_last_IE (IEChain1,icc1);
IEChain2=remove_n_last_IE (IEChain2,icc2);
return (0);
}
/* case of critical extension : SEQUENCE {} MP inside a SEQUENCE */
if ((op==0)&&(source==0)&&(t1->type==0)&&(t1->a==NULL)) {
/*source=0: it comes from a SEQUENCE */
/*t1 is a SEQUENCE {}*/
if (print_warnings) {
print_warning("Warning: SEQUENCE {} MP in a SEQUENCE",t1->line,t2->line);
}
}
/* case of critical extension : SEQUENCE {} becomes CHOICE inside a CHOICE */
if ((op==0)&&(source==1)&&(t1->type==0)&&(t2->type==1)&&(t1->a==NULL)) {
/*source=1: it comes from a CHOICE */
/*t1 is a SEQUENCE {}*/
/*t2 is a CHOICE */
if (print_warnings) print_warning("Warning: Allowed critical extension in a CHOICE",t1->line,t2->line);
new_branch_browse_element (t2,1,op);
IEChain1=remove_n_last_IE (IEChain1,icc1);
IEChain2=remove_n_last_IE (IEChain2,icc2);
return (0);
}
if ((t1->type)!=(t2->type)) {
print_error_4 ("ERROR: TYPE MISMATCH",line1,line2,t1->line,t2->line);
IEChain1=remove_n_last_IE (IEChain1,icc1);
IEChain2=remove_n_last_IE (IEChain2,icc2);
return (1);
}
/* printf (" TYPE: %d ",el.type); */
switch (t1->type) {
case 0 : { /* SEQUENCE */
para_browse_content_sequence ( t1->a,t2->a,op,t1->line,t2->line);
break;
}
case 1 : { /* CHOICE */
para_browse_choice_content ( t1->b,t2->b,t1->line,t2->line);
break;
}
case 2 : { /* NULL */
para_browse_NULL ( );
break;
}
case 3 : { /* BOOLEAN */
para_browse_BOOLEAN ( );
break;
}
case 4 : { /* BITSTRING */
if (t1->string.type!=t2->string.type) {
/*The two SIZE of BIT STRING do not have the same type */
print_error ("ERROR: SIZE type mismatch for BITSTRING ",t1->line,t2->line);
break;
}
if ((t1->string.low!=t2->string.low) || ((t1->string.high!=t2->string.high))) {
/*The two SIZE do not have the same limits */
print_error ("ERROR: Two SIZEs of BITSTRING don't have the same limits",t1->line,t2->line);
}
if ((t1->string.link!=NULL)&&(t2->string.link!=NULL)){
para_browse_element (t1->string.link, t2->string.link,-1,op,d1_str,d2_str);
} else
{
if ((t1->string.link!=NULL)||(t2->string.link!=NULL)){
if (t1->string.link==NULL) {
if (print_warnings) {
print_warning ("Allowed extension in BITSTRING",t1->line,t2->line);
new_branch_browse_element (t2->string.link,-1,op);
}
} else
{
print_error ("ERROR: ERROR in BIT STRING",t1->line,t2->line);
}
}
}
break;
}
case 5 : { /* OCTETSTRING */
if (t1->string.type!=t2->string.type) {
/*The two SIZE of BIT STRING do not have the same type */
print_error ("ERROR: SIZE type mismatch for OCTET STRING ",t1->line,t2->line);
break;
}
if ((t1->string.low!=t2->string.low) || ((t1->string.high!=t2->string.high))) {
/*The two SIZE do not have the same limits */
print_error ("ERROR: Two SIZEs of OCTET STRING don't have the same limits",t1->line,t2->line);
}
if ((t1->string.link!=NULL)&&(t2->string.link!=NULL)){
para_browse_element (t1->string.link, t2->string.link,-1,op,d1_str,d2_str);
/*for the moment we only check the content*/
} else
{
if ((t1->string.link!=NULL)||(t2->string.link!=NULL)){
if (t1->string.link==NULL) {
if (print_warnings) {
print_warning("Allowed extension in OCTET STRING",t1->line,t2->line);
new_branch_browse_element (t2->string.link,-1,op);
}
} else
{
print_error ("ERROR: ERROR in OCTET STRING ",t1->line,t2->line);
}
}
}
break;
}
case 6 : { /* ENUMERATED */
para_browse_enumerated ( t1, t2,source, op, d1_str, d2_str,line1,line2);
break;
}
case 7 : { /* INTEGER */
if (t1->integ.type!=t2->integ.type) {
/*The two INTEGERS do not have the same type */
print_error ("ERROR: INTEGER type mismatch ",t1->line,t2->line);
break;
}
if ((t1->integ.low!=t2->integ.low) || ((t1->integ.high!=t2->integ.high))) {
/*The two INTEGERS do not have the same limits */
print_error ("ERROR: Two INTEGERS don't have the same limits ",t1->line,t2->line);
}
break;
}
case 10 : { /* IE name */
/*I don't think this part is used because we try to resolve the links at the beginning*/
para_browse_IE_Name ( t1,t2);
if ((t1->IE.link!=NULL)&& (t2->IE.link!=NULL)){
para_browse_element (t1->IE.link, t2->IE.link,-1,op,d1_str,d2_str);
}
break;
}
case 11 : { /* SEQUENCE OF */
if (t1->sequence_of.type!=t2->sequence_of.type) {
/*The two SIZE of SEQUENCE OF do not have the same type */
print_error ("ERROR: SIZE type mismatch for SEQUENCE OF ",t1->line,t2->line);
break;
}
if ((t1->sequence_of.low!=t2->sequence_of.low) || ((t1->sequence_of.high!=t2->sequence_of.high))) {
/*The two SIZE do not have the same limits */
print_error ("ERROR: Two SIZEs of SEQUENCE OF don't have the same limits",t1->line,t2->line);
}
if ((t1->sequence_of.link!=NULL)&&(t2->sequence_of.link!=NULL)){
para_browse_element (t1->sequence_of.link, t2->sequence_of.link,-1,op,d1_str,d2_str);
}
break;
}
}
}
if ((t1==NULL)||(t2==NULL))
if (print_warnings) {
printf ("Warning(link): One of the element is empty\n\n");
/*Not clear when does this happen*/
add_BR();
add_BR();
nb_warnings++;
}
IEChain1=remove_n_last_IE (IEChain1,icc1);
IEChain2=remove_n_last_IE (IEChain2,icc2);
}
void browse_PDUpara (definition_ptr liste1, definition_ptr liste2){
definition *tmp1 = liste1;
definition *tmp2 = liste2;
printf("Checking the PDU(s):\n\n");
add_BR();
add_BR();
while(tmp1 != NULL)
{
if (tmp1->PDU==1) {
tmp2=liste2;
while(tmp2 != NULL) {
if (!strcmp (tmp1->leftname,tmp2->leftname)){
printf ("Analysing PDU:");
safe_print (tmp1->leftname);
printf("\n");
add_BR();
IEChain1=add_IE2(IEChain1,tmp1->leftname);
IEChain2=add_IE2(IEChain2,tmp2->leftname);
para_def(tmp1,tmp2);
IEChain1=remove_last_IE(IEChain1);
IEChain2=remove_last_IE(IEChain2);
printf("**************************\n");
add_BR();
}
tmp2 = tmp2->nxt;
}
} /* if (tmp1->PDU==1) */
tmp1 = tmp1->nxt;
} /* while(tmp1 != NULL) */
printf("\n");
}
/* procedures to free the memory */
void free_element (element * elptr);
void free_sequence ( sequence_content * sc) {
sequence_content * tmp;
while (sc!=NULL) {
free_element(sc->elem);
tmp=sc->nxt;
free(sc);
sc=tmp;
}
}
void free_choice_sequence (choice_content *cc ) {
choice_content * tmp;
while (cc!=NULL) {
free_element(cc->elem);
tmp=cc->nxt;
free(cc);
cc=tmp;
}
}
void free_element (element * elptr) {
if (elptr!=NULL){
switch (elptr->type) {
case 0 : { /* SEQUENCE */
free_sequence ( elptr->a);
break;
}
case 1 : { /* CHOICE */
free_choice_sequence ( elptr->b);
break;
}
case 4 : { /* BITSTRING */
break;
}
case 5 : { /* OCTETSTRING */
break;
}
case 7 : { /*INTEGER */
free(elptr->integ.id);
free (elptr->integ.idlow);
break;
}
}
free (elptr);
}
}
void free_liste (definition_ptr liste) {
definition *tmp1 = liste;
definition *tmp2 = liste;
while(tmp1 != NULL)
{
free (tmp1->leftname);
free_element (tmp1->elem);
tmp2 = tmp1->nxt;
free (tmp1);
tmp1 = tmp2;
}
}
void free_IE_Chain (IE_chain * iec ) {
IE_chain * tmp = iec;
while (tmp!=NULL) {
tmp=remove_last_IE (tmp);
}
}
/* End of procedures to free the memory */
/* new branch parsing */
int new_branch_browse_element (element *t2,int source, int op) {
/*source what is calling the function: 0:SEQUENCE, 1:CHOICE, -1:OTHER */
/*op: optionality of the IE in case of a sequence : 0 Mandatory, 1 OPTIONAL 2 DEFAULT */
int line2;
int icc2=0;
/* used to save the line of the first IE in case of the definition is done in another place */
if (t2!=NULL) {
int i;
line2=t2->line;
/* Resolve IE_NAME-> Definition */
while ((t2->type==10)&&(t2->IE.link!=NULL))
{
IEChain2=add_IE2 (IEChain2,t2->IE.IE_name);
icc2++;
t2=t2->IE.link;
}
switch (t2->type) {
case 0 : { /* SEQUENCE */
new_branch_browse_content_sequence ( t2->a,op,t2->line);
break;
}
case 1 : { /* CHOICE */
new_branch_browse_choice_content ( t2->b,t2->line);
break;
}
case 4 : { /* BITSTRING */
if (t2->string.link!=NULL){
new_branch_browse_element (t2->string.link,-1,op);
}
break;
}
case 5 : { /* OCTETSTRING */
if (t2->string.link!=NULL){
new_branch_browse_element (t2->string.link,-1,op);
}
break;
}
case 6 : { /* ENUMERATED */
if ((1==t2->enumer.val1)&&(0==op)&& (0==source)) {
if (print_warnings) {
fprintf(stdout,"WARNING: Mandatory ENUMERATED with 1 choice only in the new branch line=%d\n",t2->line);
add_BR();
if (showIEchain) {
printf ("IE Chain for File 2:");
printf ("\n");
add_BR();
print_IE_chain (IEChain2);
printf ("\n");
add_BR();
}
printf ("\n");
add_BR();
nb_warnings++;
/* No call for print_warning because it is for 1 file only*/
}
}
break;
}
case 11 : { /* SEQUENCE OF */
if (t2->sequence_of.link!=NULL){
new_branch_browse_element (t2->sequence_of.link,-1,op);
}
break;
}
}
}
IEChain2=remove_n_last_IE (IEChain2,icc2);
}
int new_branch_browse_content_sequence (sequence_content * sc2,int op, int l2){
/*op: Optionality of the SEQUENCE : 0 Mandatory, 1 : OPTIONAL*/
/*l2: line of the beginning of the SEQUENCE */
IE_chain * ic2;
while (sc2!=NULL) {
if (!(sc2->threedots)) {
IEChain2=add_IE2(IEChain2,sc2->ie_value_name);
new_branch_browse_element (sc2->elem,0,sc2->optionality);
IEChain2=remove_last_IE(IEChain2);
}
sc2=sc2->nxt;
}
return (0);
}
int new_branch_browse_choice_content (choice_content *cc2,int line2){
int tdflag=0;
IE_chain * ic2;
while (cc2!=NULL) {
if (!(cc2->threedots)) {
IEChain2=add_IE2(IEChain2,cc2->ie_value_name);
new_branch_browse_element (cc2->elem,1,0);
IEChain2=remove_last_IE(IEChain2);
}
cc2=cc2->nxt;
}
return (0);
}
/* End of new branch parsing*/
/* Printing procedures*/
void print_error (char * s,int l1, int l2) {
fprintf(stdout,"%s line=%d %d\n",s,l1,l2);
add_BR();
showlines (l1,l2);
printf ("\n");
add_BR();
nb_error++;
}
void print_warning (char * s,int l1, int l2) {
fprintf(stdout,"%s line=%d %d\n",s,l1,l2);
add_BR();
showlines (l1,l2);
printf ("\n");
add_BR();
nb_warnings++;
}
void print_error_4(char * s,int l1a, int l2a,int l1b, int l2b) {
fprintf(stdout,"%s line=%d %d (%d %d)\n",s,l1a,l2a,l1b,l2b);
add_BR();
showlines (l1a,l2a);
showlines (l1b,l2b);
printf ("\n");
add_BR();
nb_error++;
}
void safe_print (char*s) {
//This function is used to print in case of online version (CGI). It prevents malicious code to be executed.
char *t;
int i,l;
char c;
l=strlen(s);
for (i=0;i<l;i++){
switch (c=s[i]) {
case '<' :
printf (" <");
break;
case '>' :
printf (">");
break;
default :
printf ("%c",c);
}
}
}
void print_line (char * c,int li) {
int l=1;
int i=0;
int j;
int len;
char line_text[256];
while (l<li) {
while (c[i]!='\n') {
i++;
}
l++;
i++;
}
j=i;
i++;
while ((c[i]!='\n') && (c[i]!='\r')){
i++;
}
len=i-j;
if (len>255) len=255;
strncpy (line_text,c+j,len);
line_text[len]=0;
safe_print (line_text);
}
void showlines (int l1,int l2) {
printf ("File 1(line %d):",l1);
print_line ( content1, l1);
printf ("\n");
add_BR();
printf ("File 2(line %d):",l2);
print_line ( content2, l2);
printf ("\n");
add_BR();
if (showIEchain) {
print_both_IEchain ();
}
}
int print_both_IEchain () {
printf ("IE Chain for File 1:");
printf ("\n");
add_BR();
print_IE_chain (IEChain1);
printf ("\n");
add_BR();
printf ("IE Chain for File 2:");
printf ("\n");
add_BR();
print_IE_chain (IEChain2);
printf ("\n");
add_BR();
}
int para ()
{
browse_PDUpara (my_list1,my_list2);
printf("Number of errors : %d\n",nb_error);
add_BR();
clean_IE_chain(IEChain1);
clean_IE_chain(IEChain2);
if (print_warnings) {
printf ("Number of warnings : %d\n",nb_warnings);
add_BR();
}
return (nb_error);
}