File: config_read.y

package info (click to toggle)
eclipse-titan 8.2.0-1
  • links: PTS
  • area: main
  • in suites: bookworm, sid
  • size: 103,544 kB
  • sloc: cpp: 271,008; ansic: 33,683; yacc: 23,419; makefile: 15,483; lex: 9,204; java: 4,848; perl: 4,555; sh: 2,242; xml: 1,378; javascript: 85; awk: 48; php: 32; python: 13
file content (1169 lines) | stat: -rw-r--r-- 25,308 bytes parent folder | download
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
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
/******************************************************************************
 * Copyright (c) 2000-2021 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Baji, Laszlo
 *   Balasko, Jeno
 *   Baranyi, Botond
 *   Beres, Szabolcs
 *   Delic, Adam
 *   Forstner, Matyas
 *   Gecse, Roland
 *   Kovacs, Ferenc
 *   Pandi, Krisztian
 *   Raduly, Csaba
 *   Szabados, Kristof
 *   Szabo, Bence Janos
 *   Szabo, Janos Zoltan – initial implementation
 *   Szalai, Gabor
 *   Zalanyi, Balazs Andor
 *
 ******************************************************************************/
%{

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#include <errno.h>

#include <openssl/crypto.h>
#include <openssl/bn.h>

#include "../../common/memory.h"
#include "../../common/config_preproc.h"
#include "../mctr/config_data.h"
#include "../../core/Types.h"
#include "../../core/RInt.hh"

#define YYERROR_VERBOSE

extern FILE *config_read_in;
extern int config_read_lineno;
extern char *config_read_text;
extern int config_read_lex();
extern void config_read_restart(FILE *new_file);
extern void config_read_reset(const char* fname);
extern void config_read_close();
extern std::string get_cfg_read_current_file();

config_data *cfg;

boolean error_flag = FALSE;
static boolean local_addr_set = FALSE,
  tcp_listen_port_set = FALSE,
  kill_timer_set = FALSE,
  num_hcs_set = FALSE;

static int config_read_parse();
int process_config_read_file(const char *file_name);
static void check_duplicate_option(const char *option_name,
  boolean *option_flag);
void config_read_warning(const char *warning_str, ...);
void config_read_error(const char *error_str, ...);

/* For parameters */

static char *group_name = NULL;

string_map_t *config_defines;

#ifndef NDEBUG

union YYSTYPE;
static void yyprint(FILE *file, int type, const YYSTYPE& value);
#define YYPRINT(f,t,v) yyprint(f,t,v)

#endif

%}

%union {
	char *str_val;
	BIGNUM *int_val;
	double float_val;
  boolean bool_val;
  cf_timestamp_format ts_val;
	execute_list_item	execute_item_val;
}

%token ModuleParametersKeyword
%token LoggingKeyword
%token ProfilerKeyword
%token TestportParametersKeyword
%token ExecuteKeyword
%token ExternalCommandsKeyword
%token GroupsKeyword
%token ComponentsKeyword
%token MainControllerKeyword
%token IncludeKeyword
%token DefineKeyword

%token ObjIdKeyword "objid"
%token CharKeyword "char"
%token ControlKeyword "control"
%token MTCKeyword "mtc"
%token SystemKeyword "system"
%token NULLKeyword "NULL"
%token nullKeyword "null"
%token OmitKeyword "omit"
%token AssignmentChar ":= or ="
%token ConcatChar "&="
%token ComplementKeyword "complement"
%token DotDot ".."
%token SupersetKeyword "superset"
%token SubsetKeyword "subset"
%token PatternKeyword "pattern"
%token PermutationKeyword "permutation"
%token LengthKeyword "length"
%token IfpresentKeyword "ifpresent"
%token InfinityKeyword "infinity"
%token NocaseKeyword "@nocase"

%token LogFile "LogFile of FileName"
%token EmergencyLogging
%token EmergencyLoggingBehaviour
%token EmergencyLoggingBehaviourValue "BufferAll or BufferMasked"
%token EmergencyLoggingMask
%token EmergencyLoggingForFailVerdict
%token FileMask
%token ConsoleMask
%token TimestampFormat
%token ConsoleTimestampFormat
%token SourceInfoFormat "LogSourceInfo or SourceInfoFormat"
%token AppendFile
%token LogEventTypes
%token LogEntityName
%token MatchingHints
%token LoggerPlugins

%token BeginControlPart
%token EndControlPart
%token BeginTestCase
%token EndTestCase


%token <str_val> Identifier
%token ASN1LowerIdentifier "ASN.1 identifier beginning with a lowercase letter"
%token MacroRValue
%token <int_val> Number MPNumber "integer value"
%token <float_val> Float MPFloat "float value"
%token BooleanValue "true or false"
%token VerdictValue
%token Bstring "bit string value"
%token Hstring "hex string value"
%token Ostring "octet string value"
%token BstringMatch "bit string template"
%token HstringMatch "hex string template"
%token OstringMatch "octet string template"
%token <str_val> Cstring "character string value"
%token <str_val> MPCstring "charstring value"
%token <str_val> DNSName "a host name"
%token LoggingBit
%token LoggingBitCollection
%token <ts_val> TimestampValue  "Time, Datetime or Seconds"
%token SourceInfoValue "None, Single or Stack"
%token YesNo "Yes or No" /* from LOGGING section */
%token LocalAddress
%token TCPPort
%token KillTimer
%token NumHCs
%token UnixSocketEnabled
%token YesToken "yes" /* from MAIN_CONTROLLER section */
%token NoToken  "no"
%token Detailed
%token Compact
%token SubCategories
%token LogFileSize
%token LogFileNumber
%token DiskFullAction
%token Error
%token Stop
%token Re_try /* Retry clashes with an enum in Qt */
%token Delete

%token DisableProfilerKeyword    "DisableProfiler"
%token DisableCoverageKeyword    "DisableCoverage"
%token DatabaseFileKeyword       "DatabaseFile"
%token AggregateDataKeyword      "AggregateData"
%token StatisticsFileKeyword     "StatisticsFile"
%token DisableStatisticsKeyword  "DisableStatistics"
%token StatisticsFilterKeyword   "StatisticsFilter"
%token StartAutomaticallyKeyword "StartAutomatically"
%token NetLineTimesKeyword       "NetLineTimes"
%token NetFunctionTimesKeyword   "NetFunctionTimes"
%token ProfilerStatsFlag        "profiler statistics flag"

%type <int_val> IntegerValue
%type <float_val> FloatValue KillTimerValue
%type <str_val> HostName StringValue LogFileName
%type <str_val> ComponentName
%type <str_val> ComponentLocation
%type <execute_item_val> ExecuteItem

%destructor { Free($$); }
Identifier
DNSName
HostName
ComponentName
ComponentLocation
Cstring
MPCstring
StringValue
LogFileName

%destructor {
  Free($$.module_name);
  Free($$.testcase_name);
}
ExecuteItem

%destructor { BN_free($$); }
IntegerValue
Number
MPNumber

%left '&' /* to avoid shift/reduce conflicts */
%left '+' '-'
%left '*' '/'
%left UnarySign

%expect 2

/*
Source of conflicts (1 S/R):

1.) 1 conflict
When seeing a '*' token after a module parameter expression the parser cannot
decide whether the token is a multiplication operator (shift) or it refers to
all modules in the next module parameter (reduce).

The built-in Bison behavior always chooses the shift over the reduce
(the * is interpreted as multiplication).
1 conflict:
infinity can be a float value in LengthMatch's upper bound (SimpleParameterValue)
or an infinityKeyword.
*/

%%

ConfigFile:
	/* empty */
	| ConfigFile Section
;

Section:
	ModuleParametersSection
	| LoggingSection
  | ProfilerSection
	| TestportParametersSection
	| ExecuteSection
	| ExternalCommandsSection
	| GroupsSection
	| ComponentsSection
	| MainControllerSection
	| IncludeSection
	| DefineSection
;

/******************* [MODULE_PARAMETERS] section *******************/

ModuleParametersSection:
	ModuleParametersKeyword ModuleParameters
;

ModuleParameters:
	/* empty */
	| ModuleParameters ModuleParameter optSemiColon
;

ModuleParameter:
    ParameterName ParamOpType ParameterValue
;

ParameterName:
  ParameterNameSegment
| '*' '.' ParameterNameSegment
;

ParameterNameSegment:
  ParameterNameSegment '.' Identifier { Free($3); }
| ParameterNameSegment IndexItemIndex
| Identifier                          { Free($1); }


ParameterValue:
  ParameterExpression
| ParameterExpression LengthMatch
| ParameterExpression IfpresentKeyword
| ParameterExpression LengthMatch IfpresentKeyword
;

LengthMatch:
  LengthKeyword '(' LengthBound ')'
| LengthKeyword '(' LengthBound DotDot LengthBound ')'
| LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
;

LengthBound:
  ParameterExpression
;

ParameterExpression:
  SimpleParameterValue
| ParameterReference
| '(' ParameterExpression ')'
| '+' ParameterExpression %prec UnarySign
| '-' ParameterExpression %prec UnarySign
| ParameterExpression '+' ParameterExpression
| ParameterExpression '-' ParameterExpression
| ParameterExpression '*' ParameterExpression
| ParameterExpression '/' ParameterExpression
| ParameterExpression '&' ParameterExpression
;

ParameterReference:
  ParameterNameSegment
;

SimpleParameterValue:
	MPNumber { BN_free($1); }
| MPFloat
| InfinityKeyword
| BooleanValue
| ObjIdValue
| VerdictValue
| BitstringValue
| HexstringValue
| OctetstringValue
| MPCstring { Free($1); }
| UniversalCharstringValue
| OmitKeyword
| NULLKeyword
| nullKeyword
| '?'
| '*'
| IntegerRange
| FloatRange
| StringRange
| PatternKeyword PatternChunk
| PatternKeyword NocaseKeyword PatternChunk
| BstringMatch
| HstringMatch
| OstringMatch
| CompoundValue
| MTCKeyword
| SystemKeyword
;

PatternChunk:
  MPCstring { Free($1); }
| Quadruple
;

IntegerRange:
  '(' '-' InfinityKeyword DotDot MPNumber ')' { BN_free($5); }
| '(' '-' InfinityKeyword DotDot '!' MPNumber ')' { BN_free($6); }
| '(' MPNumber DotDot MPNumber ')' { BN_free($2); BN_free($4); }
| '(' '!' MPNumber DotDot MPNumber ')' { BN_free($3); BN_free($5); }
| '(' MPNumber DotDot '!' MPNumber ')' { BN_free($2); BN_free($5); }
| '(' '!' MPNumber DotDot '!' MPNumber ')' { BN_free($3); BN_free($6); }
| '(' MPNumber DotDot InfinityKeyword ')' { BN_free($2); }
| '(' '!' MPNumber DotDot InfinityKeyword ')' { BN_free($3); }
;

FloatRange:
  '(' '-' InfinityKeyword DotDot MPFloat ')'
| '(' '!' '-' InfinityKeyword DotDot MPFloat ')'
| '(' '-' InfinityKeyword DotDot '!' MPFloat ')'
| '(' '!' '-' InfinityKeyword DotDot '!' MPFloat ')'
| '(' MPFloat DotDot MPFloat ')'
| '(' '!' MPFloat DotDot MPFloat ')'
| '(' MPFloat DotDot '!' MPFloat ')'
| '(' '!' MPFloat DotDot '!' MPFloat ')'
| '(' MPFloat DotDot InfinityKeyword ')'
| '(' '!' MPFloat DotDot InfinityKeyword ')'
| '(' MPFloat DotDot '!' InfinityKeyword ')'
| '(' '!' MPFloat DotDot '!' InfinityKeyword ')'
;
  
StringRange:
  '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
| '(' '!' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
| '(' UniversalCharstringFragment DotDot '!' UniversalCharstringFragment ')'
| '(' '!' UniversalCharstringFragment DotDot '!' UniversalCharstringFragment ')'

IntegerValue:
	Number { $$ = $1; }
	| '(' IntegerValue ')' { $$ = $2; }
	| '+' IntegerValue %prec UnarySign { $$ = $2; }
	| '-' IntegerValue %prec UnarySign
	{
	  BN_set_negative($2, !BN_is_negative($2));
    $$ = $2;
	}
	| IntegerValue '+' IntegerValue
	{
	  $$ = BN_new();
    BN_add($$, $1, $3);
    BN_free($1);
    BN_free($3);
	}
	| IntegerValue '-' IntegerValue
	{
	  $$ = BN_new();
    BN_sub($$, $1, $3);
    BN_free($1);
    BN_free($3);
	}
	| IntegerValue '*' IntegerValue
	{
	  $$ = BN_new();
    BN_CTX *ctx = BN_CTX_new();
    //BN_CTX_init(ctx);
    BN_mul($$, $1, $3, ctx);
    BN_CTX_free(ctx);
    BN_free($1);
    BN_free($3);
	}
	| IntegerValue '/' IntegerValue
  {
    $$ = BN_new();
    BIGNUM *BN_0 = BN_new();
    BN_set_word(BN_0, 0);
    if (BN_cmp($3, BN_0) == 0) {
      config_read_error("Integer division by zero.");
      $$ = BN_0;
    } else {
      BN_CTX *ctx = BN_CTX_new();
      //BN_CTX_init(ctx);
      BN_div($$, NULL, $1, $3, ctx);
      BN_CTX_free(ctx);
      BN_free(BN_0);
    }
    BN_free($1);
    BN_free($3);
  }
;

FloatValue:
	Float { $$ = $1; }
	| '(' FloatValue ')' { $$ = $2; }
	| '+' FloatValue %prec UnarySign { $$ = $2; }
	| '-' FloatValue %prec UnarySign { $$ = -$2; }
	| FloatValue '+' FloatValue { $$ = $1 + $3; }
	| FloatValue '-' FloatValue { $$ = $1 - $3; }
	| FloatValue '*' FloatValue { $$ = $1 * $3; }
	| FloatValue '/' FloatValue
{
	if ($3 == 0.0) {
		config_read_error("Floating point division by zero.");
		$$ = 0.0;
	} else $$ = $1 / $3;
}
;

ObjIdValue:
	ObjIdKeyword '{' ObjIdComponentList '}'
;

ObjIdComponentList:
	ObjIdComponent
	| ObjIdComponentList ObjIdComponent
;

ObjIdComponent:
	NumberForm
	| NameAndNumberForm
;

NumberForm:
	MPNumber { BN_free($1); }
;

NameAndNumberForm:
	Identifier '(' MPNumber ')' { Free($1); BN_free($3); }
;

BitstringValue:
	Bstring
;

HexstringValue:
	Hstring
;

OctetstringValue:
	Ostring
;

UniversalCharstringValue:
	Quadruple
	| USI
;

UniversalCharstringFragment:
	MPCstring { Free($1); }
	| Quadruple
;

Quadruple:
	CharKeyword '(' ParameterExpression ',' ParameterExpression ','
  ParameterExpression ',' ParameterExpression ')'
;

USI:
    CharKeyword '(' UIDlike ')'     
;

UIDlike:
    Cstring { Free($1); }
    | UIDlike ',' Cstring { Free($3); }
;

StringValue:
	Cstring { $$ = $1; }
	| StringValue '&' Cstring {
	  $$ = mputstr($1, $3);
	  Free($3);
	}
;

CompoundValue:
  '{' '}'
|	'{' FieldValueList '}'
| '{' ArrayItemList '}'
| '{' IndexItemList '}'
| '(' ParameterValue ',' TemplateItemList ')' /* at least 2 elements to avoid shift/reduce conflicts with the ParameterExpression rule */
| ComplementKeyword '(' TemplateItemList ')'
| SupersetKeyword '(' TemplateItemList ')'
| SubsetKeyword '(' TemplateItemList ')'
;

ParameterValueOrNotUsedSymbol:
  ParameterValue
| '-'
;

TemplateItemList:
  ParameterValue
| TemplateItemList ',' ParameterValue
;

FieldValueList:
	FieldValue
	| FieldValueList ',' FieldValue
;

FieldValue:
	FieldName AssignmentChar ParameterValueOrNotUsedSymbol
;

FieldName:
	Identifier { Free($1); }
	| ASN1LowerIdentifier
;

ArrayItemList:
	ArrayItem
	| ArrayItemList ',' ArrayItem
;

ArrayItem:
  ParameterValueOrNotUsedSymbol
| PermutationKeyword '(' TemplateItemList ')'
;

IndexItemList:
	IndexItem
	| IndexItemList ',' IndexItem
;

IndexItem:
	IndexItemIndex AssignmentChar ParameterValue
;

IndexItemIndex:
	'[' ParameterExpression ']'
;

/******************* [LOGGING] section *******************/

LoggingSection:
	LoggingKeyword LoggingParamList
;

LoggingParamList:
	/* empty */
	| LoggingParamList LoggingParamLines optSemiColon
;

LoggingParamLines:
	LoggingParam
	| ComponentId '.' LoggingParam
	| ComponentId '.' LoggerPluginId '.' LoggingParam
	| LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
	| ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
;

LoggerPluginId:
  '*'
  | Identifier { Free($1); }
;

LoggingParam:
	FileMask AssignmentChar LoggingBitMask
	| ConsoleMask AssignmentChar LoggingBitMask
	| LogFileSize AssignmentChar Number { BN_free($3); }
	| EmergencyLogging AssignmentChar Number { BN_free($3); }
	| EmergencyLoggingBehaviour AssignmentChar EmergencyLoggingBehaviourValue
	| EmergencyLoggingMask AssignmentChar LoggingBitMask
	| EmergencyLoggingForFailVerdict AssignmentChar YesNoOrBoolean
	| LogFileNumber AssignmentChar Number { BN_free($3); }
	| DiskFullAction AssignmentChar DiskFullActionValue
	| LogFile AssignmentChar LogFileName { cfg->set_log_file($3); }
	| TimestampFormat AssignmentChar TimestampValue
	| ConsoleTimestampFormat AssignmentChar TimestampValue {cfg->tsformat=$3;}
	| SourceInfoFormat AssignmentChar SourceInfoSetting
	| AppendFile AssignmentChar YesNoOrBoolean
	| LogEventTypes AssignmentChar LogEventTypesValue
	| LogEntityName AssignmentChar YesNoOrBoolean
	| MatchingHints AssignmentChar MatchVerbosityValue
	| Identifier AssignmentChar StringValue { Free($1); Free($3); }
;

LoggerPluginList:
	LoggerPlugin
	| LoggerPluginList ',' LoggerPlugin
;

LoggerPlugin:
  Identifier { Free($1); }
  | Identifier AssignmentChar StringValue { Free($1); Free($3); }
;

DiskFullActionValue:
	Error
	| Stop
	| Re_try
	| Re_try '(' Number ')' { BN_free($3); }
	| Delete
;

LogFileName:
	StringValue { $$ = $1; }
;

//optTestComponentIdentifier:
	/* empty */
/*	| Identifier '.' { Free($1); }
	| Number '.'
	| MTCKeyword '.'
	| '*' '.'
;*/

LoggingBitMask:
	LoggingBitorCollection
	| LoggingBitMask ListOp LoggingBitorCollection
;

ListOp:
	/* empty */
	/*|*/ '|'
;

LoggingBitorCollection:
	LoggingBit
	| LoggingBitCollection
;

SourceInfoSetting:
	SourceInfoValue
	| YesNoOrBoolean
;

YesNoOrBoolean:
	YesNo
	| BooleanValue
;

LogEventTypesValue:
	YesNoOrBoolean
	| Detailed
	| SubCategories
;

MatchVerbosityValue:
	Compact
	| Detailed
;

/*********************** [PROFILER] ********************************/

ProfilerSection:
  ProfilerKeyword ProfilerSettings
;

ProfilerSettings:
  /* empty */
| ProfilerSettings ProfilerSetting optSemiColon
;

ProfilerSetting:
  DisableProfilerSetting
| DisableCoverageSetting
| DatabaseFileSetting
| AggregateDataSetting
| StatisticsFileSetting
| DisableStatisticsSetting
| StatisticsFilterSetting
| StartAutomaticallySetting
| NetLineTimesSetting
| NetFunctionTimesSetting
;

DisableProfilerSetting:
  DisableProfilerKeyword AssignmentChar BooleanValue
;

DisableCoverageSetting:
  DisableCoverageKeyword AssignmentChar BooleanValue
;

DatabaseFileSetting:
  DatabaseFileKeyword AssignmentChar StringValue { Free($3); }
;

AggregateDataSetting:
  AggregateDataKeyword AssignmentChar BooleanValue
;

StatisticsFileSetting:
  StatisticsFileKeyword AssignmentChar StringValue { Free($3); }
;

DisableStatisticsSetting:
  DisableStatisticsKeyword AssignmentChar BooleanValue
;

StatisticsFilterSetting:
  StatisticsFilterKeyword AssignmentChar ProfilerStatsFlags
| StatisticsFilterKeyword ConcatChar ProfilerStatsFlags
;

ProfilerStatsFlags:
  ProfilerStatsFlag
| ProfilerStatsFlag '&' ProfilerStatsFlags
| ProfilerStatsFlag '|' ProfilerStatsFlags
;

StartAutomaticallySetting:
  StartAutomaticallyKeyword AssignmentChar BooleanValue
;

NetLineTimesSetting:
  NetLineTimesKeyword AssignmentChar BooleanValue
;

NetFunctionTimesSetting:
  NetFunctionTimesKeyword AssignmentChar BooleanValue
;

/******************* [TESTPORT_PARAMETERS] section *******************/

TestportParametersSection:
	TestportParametersKeyword TestportParameterList
;

TestportParameterList:
	/* empty */
	| TestportParameterList TestportParameter optSemiColon
;

TestportParameter:
	ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
	TestportParameterValue
;

ComponentId:
	Identifier { Free($1); }
	| Number { BN_free($1); }
	| MTCKeyword
	| '*'
	| SystemKeyword
	| Cstring { Free($1); }
;

TestportName:
	Identifier { Free($1); }
	| Identifier ArrayRef { Free($1); }
	| '*'
;

ArrayRef:
	'[' IntegerValue ']' { BN_free($2); }
	| ArrayRef '[' IntegerValue ']' { BN_free($3); }
;

TestportParameterName:
	Identifier { Free($1); }
;

TestportParameterValue:
	StringValue { Free($1); }
;

/******************* [EXECUTE] section *******************/

ExecuteSection:
	ExecuteKeyword ExecuteList
;

ExecuteList:
	/* empty */
	| ExecuteList ExecuteItem optSemiColon
{
	cfg->add_exec($2);
}
;

ExecuteItem:
	Identifier
{
	$$.module_name = $1;
	$$.testcase_name = NULL;
}
	| Identifier '.' ControlKeyword
{
	$$.module_name = $1;
	$$.testcase_name = NULL;
}
	| Identifier '.' Identifier
{
	$$.module_name = $1;
	$$.testcase_name = $3;
}
	| Identifier '.' '*'
{
	$$.module_name = $1;
	$$.testcase_name = mcopystr("*");
}
;

/******************* [EXTERNAL_COMMANDS] section *******************/

ExternalCommandsSection:
	ExternalCommandsKeyword ExternalCommandList
;

ExternalCommandList:
	/* empty */
	| ExternalCommandList ExternalCommand optSemiColon
;

ExternalCommand:
	BeginControlPart AssignmentChar Command
	| EndControlPart AssignmentChar Command
	| BeginTestCase AssignmentChar Command
	| EndTestCase AssignmentChar Command
;

Command:
	StringValue { Free($1); }
;

/******************* [GROUPS] section *******************/

GroupsSection:
	GroupsKeyword GroupList
;

GroupList:
	/* empty */
	| GroupList Group optSemiColon
;

Group:
	GroupName AssignmentChar GroupMembers
{
	Free(group_name);
	group_name = NULL;
}
;

GroupName:
	Identifier { group_name = $1; }
;

GroupMembers:
	'*'
{
	if (group_name != NULL) cfg->add_host(group_name, NULL);
}
	| seqGroupMember
;

seqGroupMember:
	HostName
{
	if (group_name != NULL && $1 != NULL)
		cfg->add_host(group_name, $1);
	Free($1);
}
	| seqGroupMember ',' HostName
{
	if (group_name != NULL && $3 != NULL)
		cfg->add_host(group_name, $3);
	Free($3);
}
;

HostName:
	DNSName { $$ = $1; }
	| Identifier
{
    $$ = $1;
    if ($$ != NULL) {
	    size_t string_len = strlen($$);
	    for (size_t i = 0; i < string_len; i++) $$[i] = tolower($$[i]);
    }
}
;

/******************* [COMPONENTS] section *******************/

ComponentsSection:
	ComponentsKeyword ComponentList
;

ComponentList:
	/* empty */
	| ComponentList ComponentItem optSemiColon
;

ComponentItem:
	ComponentName AssignmentChar ComponentLocation
{
	if ($3 != NULL) cfg->add_component($3, $1);
	//Free($1);
	//Free($3);
}
;

ComponentName:
	Identifier { $$ = $1; }
	| '*' { $$ = NULL; }
;

ComponentLocation:
	Identifier { $$ = $1; }
	| DNSName { $$ = $1; }
;

/******************* [MAIN_CONTROLLER] section *******************/

MainControllerSection:
	MainControllerKeyword MCParameterList
;

MCParameterList:
	/* empty */
	| MCParameterList MCParameter optSemiColon
;

MCParameter:
	LocalAddress AssignmentChar HostName
{
	check_duplicate_option("LocalAddress", &local_addr_set);
	Free(cfg->local_addr);
	cfg->local_addr = $3;
}
	| TCPPort AssignmentChar IntegerValue
{
	check_duplicate_option("TCPPort", &tcp_listen_port_set);
	BIGNUM *BN_0 = BN_new();
	BN_set_word(BN_0, 0);
  BIGNUM *BN_65535 = BN_new();
  BN_set_word(BN_65535, 65535);
  char *int_val_str = BN_bn2dec($3);
	if (BN_cmp($3, BN_0) < 0 || BN_cmp($3, BN_65535) > 0)
	  config_read_error("An integer value within range 0 .. 65535 was "
		                  "expected for parameter TCPPort instead of %s.",
		                  int_val_str);
  else cfg->tcp_listen_port = (unsigned short)BN_get_word($3);
  BN_free(BN_0);
  BN_free(BN_65535);
  BN_free($3);
  OPENSSL_free(int_val_str);
}
	| KillTimer AssignmentChar KillTimerValue
{
	check_duplicate_option("KillTimer", &kill_timer_set);
	if ($3 >= 0.0) cfg->kill_timer = $3;
	else config_read_error("A non-negative numeric value was expected for "
		"parameter KillTimer instead of %g.", $3);
}
	| NumHCs AssignmentChar IntegerValue
{
	check_duplicate_option("NumHCs", &num_hcs_set);
	BIGNUM *BN_0 = BN_new();
	BN_set_word(BN_0, 0);
	char *int_val_str = BN_bn2dec($3);
	if (BN_cmp($3, BN_0) <= 0)
	  config_read_error("A positive integer value was expected for "
		                  "parameter NumHCs instead of %s.", int_val_str);
  else cfg->num_hcs = (int)BN_get_word($3);
  BN_free(BN_0);
  // Check if we really need to free this!
  BN_free($3);
  OPENSSL_free(int_val_str);
}
  | UnixSocketEnabled AssignmentChar YesToken
{
  cfg->unix_sockets_enabled = true;
}
  | UnixSocketEnabled AssignmentChar NoToken
{
  cfg->unix_sockets_enabled = false;
}
  | UnixSocketEnabled AssignmentChar HostName
{
  config_read_error("Only 'yes' or 'no' is accepted instead of '%s'", $3);
}
;

KillTimerValue:
	FloatValue { $$ = $1; }
	| IntegerValue
	{
    double tmp = (double)BN_get_word($1);
    if (BN_is_negative($1)) tmp *= -1;
    $$ = tmp;
    BN_free($1);
  }
;

/******************* [INCLUDE] section *******************/

IncludeSection:
  IncludeKeyword IncludeFiles
;

IncludeFiles:
  /* empty */
| IncludeFiles IncludeFile
;

IncludeFile:
  Cstring { Free($1); }
;

/******************* [DEFINE] section *******************/

DefineSection:
  DefineKeyword
;

/********************************************************/

ParamOpType:
  AssignmentChar
| ConcatChar
;

optSemiColon:
	/* empty */
	| ';'
;

%%


int process_config_read_file(const char *file_name, config_data *pcfg)
{
#ifdef PARSER_DEBUG
  config_read_debug = 1;
#endif
  // reset "locals"
  local_addr_set = FALSE;
  tcp_listen_port_set = FALSE;
  kill_timer_set = FALSE;
  num_hcs_set = FALSE;

  error_flag = FALSE;
  string_chain_t *filenames=NULL;
  cfg = pcfg;

  /* Initializing parameters to default values */
  cfg->clear();

  if(preproc_parse_file(file_name, &filenames, &config_defines))
    error_flag=TRUE;

  while(filenames) {
    char *fn=string_chain_cut(&filenames);
    config_read_lineno=1;
    /* The lexer can modify config_process_in
     * when it's input buffer is changed */
    config_read_in = fopen(fn, "r");
    if (config_read_in == NULL) {
      fprintf(stderr, "Cannot open configuration file: %s (%s)\n",
              fn, strerror(errno));
      error_flag=TRUE;
    } else {
      FILE* tmp_cfg = config_read_in;
      config_read_restart(config_read_in);
      config_read_reset(fn);
      if(config_read_parse()) error_flag=TRUE;
      fclose(tmp_cfg);
      /* During parsing flex or libc may use some system calls (e.g. ioctl)
       * that fail with an error status. Such error codes shall be ignored in
       * future error messages. */
      errno = 0;
    }
    Free(fn);
  }

  config_read_close();

  string_map_free(config_defines);
  config_defines=NULL;

  return error_flag ? -1 : 0;
}

static void check_duplicate_option(const char *option_name,
  boolean *option_flag)
{
  if (*option_flag) {
    config_read_warning("Option `%s' was given more than once in section "
      "[MAIN_CONTROLLER].", option_name);
  } else *option_flag = TRUE;
}


#ifndef NDEBUG
void yyprint(FILE *file, int type, const YYSTYPE& value)
{
  switch (type) {
  case DNSName:
  case Identifier:
  case Cstring:
    fprintf(file, "'%s'", value.str_val);
    break;

  case Number: {
    char *string_repr = BN_bn2dec(value.int_val);
    fprintf(file, "%s", string_repr);
    OPENSSL_free(string_repr);
    break; }
  default:
    break;
  }
}
#endif