ISO 10646-conformant unicode syntaxes (artf381650) V3
[deliverable/titan.core.git] / mctr2 / cli / config_read.y
1 /******************************************************************************
2 * Copyright (c) 2000-2016 Ericsson Telecom AB
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Baji, Laszlo
10 * Balasko, Jeno
11 * Baranyi, Botond
12 * Beres, Szabolcs
13 * Delic, Adam
14 * Forstner, Matyas
15 * Gecse, Roland
16 * Kovacs, Ferenc
17 * Pandi, Krisztian
18 * Raduly, Csaba
19 * Szabados, Kristof
20 * Szabo, Bence Janos
21 * Szabo, Janos Zoltan – initial implementation
22 * Szalai, Gabor
23 * Zalanyi, Balazs Andor
24 *
25 ******************************************************************************/
26 %{
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <stdarg.h>
32 #include <ctype.h>
33 #include <errno.h>
34
35 #include <openssl/crypto.h>
36 #include <openssl/bn.h>
37
38 #include "../../common/memory.h"
39 #include "../../common/config_preproc.h"
40 #include "../mctr/config_data.h"
41 #include "../../core/Types.h"
42 #include "../../core/RInt.hh"
43
44 #define YYERROR_VERBOSE
45
46 extern FILE *config_read_in;
47 extern int config_read_lineno;
48 extern char *config_read_text;
49 extern int config_read_lex();
50 extern void config_read_restart(FILE *new_file);
51 extern void config_read_reset(const char* fname);
52 extern void config_read_close();
53 extern std::string get_cfg_read_current_file();
54
55 config_data *cfg;
56
57 boolean error_flag = FALSE;
58 static boolean local_addr_set = FALSE,
59 tcp_listen_port_set = FALSE,
60 kill_timer_set = FALSE,
61 num_hcs_set = FALSE;
62
63 static int config_read_parse();
64 int process_config_read_file(const char *file_name);
65 static void check_duplicate_option(const char *option_name,
66 boolean *option_flag);
67 void config_read_warning(const char *warning_str, ...);
68 void config_read_error(const char *error_str, ...);
69
70 /* For parameters */
71
72 static char *group_name = NULL;
73
74 string_map_t *config_defines;
75
76 #ifndef NDEBUG
77
78 union YYSTYPE;
79 static void yyprint(FILE *file, int type, const YYSTYPE& value);
80 #define YYPRINT(f,t,v) yyprint(f,t,v)
81
82 #endif
83
84 %}
85
86 %union {
87 char *str_val;
88 BIGNUM *int_val;
89 double float_val;
90 boolean bool_val;
91 cf_timestamp_format ts_val;
92 execute_list_item execute_item_val;
93 }
94
95 %token ModuleParametersKeyword
96 %token LoggingKeyword
97 %token ProfilerKeyword
98 %token TestportParametersKeyword
99 %token ExecuteKeyword
100 %token ExternalCommandsKeyword
101 %token GroupsKeyword
102 %token ComponentsKeyword
103 %token MainControllerKeyword
104 %token IncludeKeyword
105 %token DefineKeyword
106
107 %token ObjIdKeyword "objid"
108 %token CharKeyword "char"
109 %token ControlKeyword "control"
110 %token MTCKeyword "mtc"
111 %token SystemKeyword "system"
112 %token NULLKeyword "NULL"
113 %token nullKeyword "null"
114 %token OmitKeyword "omit"
115 %token AssignmentChar ":= or ="
116 %token ConcatChar "&="
117 %token ComplementKeyword "complement"
118 %token DotDot ".."
119 %token SupersetKeyword "superset"
120 %token SubsetKeyword "subset"
121 %token PatternKeyword "pattern"
122 %token PermutationKeyword "permutation"
123 %token LengthKeyword "length"
124 %token IfpresentKeyword "ifpresent"
125 %token InfinityKeyword "infinity"
126
127 %token LogFile "LogFile of FileName"
128 %token EmergencyLogging
129 %token EmergencyLoggingBehaviour
130 %token EmergencyLoggingBehaviourValue "BufferAll or BufferMasked"
131 %token EmergencyLoggingMask
132 %token EmergencyLoggingForFailVerdict
133 %token FileMask
134 %token ConsoleMask
135 %token TimestampFormat
136 %token ConsoleTimestampFormat
137 %token SourceInfoFormat "LogSourceInfo or SourceInfoFormat"
138 %token AppendFile
139 %token LogEventTypes
140 %token LogEntityName
141 %token MatchingHints
142 %token LoggerPlugins
143
144 %token BeginControlPart
145 %token EndControlPart
146 %token BeginTestCase
147 %token EndTestCase
148
149
150 %token <str_val> Identifier
151 %token ASN1LowerIdentifier "ASN.1 identifier beginning with a lowercase letter"
152 %token MacroRValue
153 %token <int_val> Number MPNumber "integer value"
154 %token <float_val> Float MPFloat "float value"
155 %token BooleanValue "true or false"
156 %token VerdictValue
157 %token Bstring "bit string value"
158 %token Hstring "hex string value"
159 %token Ostring "octet string value"
160 %token BstringMatch "bit string template"
161 %token HstringMatch "hex string template"
162 %token OstringMatch "octet string template"
163 %token <str_val> Cstring "character string value"
164 %token <str_val> MPCstring "charstring value"
165 %token <str_val> DNSName "a host name"
166 %token LoggingBit
167 %token LoggingBitCollection
168 %token <ts_val> TimestampValue "Time, Datetime or Seconds"
169 %token SourceInfoValue "None, Single or Stack"
170 %token YesNo "Yes or No" /* from LOGGING section */
171 %token LocalAddress
172 %token TCPPort
173 %token KillTimer
174 %token NumHCs
175 %token UnixSocketEnabled
176 %token YesToken "yes" /* from MAIN_CONTROLLER section */
177 %token NoToken "no"
178 %token Detailed
179 %token Compact
180 %token SubCategories
181 %token LogFileSize
182 %token LogFileNumber
183 %token DiskFullAction
184 %token Error
185 %token Stop
186 %token Re_try /* Retry clashes with an enum in Qt */
187 %token Delete
188
189 %token DisableProfilerKeyword "DisableProfiler"
190 %token DisableCoverageKeyword "DisableCoverage"
191 %token DatabaseFileKeyword "DatabaseFile"
192 %token AggregateDataKeyword "AggregateData"
193 %token StatisticsFileKeyword "StatisticsFile"
194 %token DisableStatisticsKeyword "DisableStatistics"
195 %token StatisticsFilterKeyword "StatisticsFilter"
196 %token StartAutomaticallyKeyword "StartAutomatically"
197 %token NetLineTimesKeyword "NetLineTimes"
198 %token NetFunctionTimesKeyword "NetFunctionTimes"
199 %token ProfilerStatsFlag "profiler statistics flag"
200
201 %type <int_val> IntegerValue
202 %type <float_val> FloatValue KillTimerValue
203 %type <str_val> HostName StringValue LogFileName
204 %type <str_val> ComponentName
205 %type <str_val> ComponentLocation
206 %type <execute_item_val> ExecuteItem
207
208 %destructor { Free($$); }
209 Identifier
210 DNSName
211 HostName
212 ComponentName
213 ComponentLocation
214 Cstring
215 MPCstring
216 StringValue
217 LogFileName
218
219 %destructor {
220 Free($$.module_name);
221 Free($$.testcase_name);
222 }
223 ExecuteItem
224
225 %destructor { BN_free($$); }
226 IntegerValue
227 Number
228 MPNumber
229
230 %left '&' /* to avoid shift/reduce conflicts */
231 %left '+' '-'
232 %left '*' '/'
233 %left UnarySign
234
235 %expect 1
236
237 /*
238 Source of conflicts (1 S/R):
239
240 1.) 1 conflict
241 When seeing a '*' token after a module parameter expression the parser cannot
242 decide whether the token is a multiplication operator (shift) or it refers to
243 all modules in the next module parameter (reduce).
244
245 The built-in Bison behavior always chooses the shift over the reduce
246 (the * is interpreted as multiplication).
247 */
248
249 %%
250
251 ConfigFile:
252 /* empty */
253 | ConfigFile Section
254 ;
255
256 Section:
257 ModuleParametersSection
258 | LoggingSection
259 | ProfilerSection
260 | TestportParametersSection
261 | ExecuteSection
262 | ExternalCommandsSection
263 | GroupsSection
264 | ComponentsSection
265 | MainControllerSection
266 | IncludeSection
267 | DefineSection
268 ;
269
270 /******************* [MODULE_PARAMETERS] section *******************/
271
272 ModuleParametersSection:
273 ModuleParametersKeyword ModuleParameters
274 ;
275
276 ModuleParameters:
277 /* empty */
278 | ModuleParameters ModuleParameter optSemiColon
279 ;
280
281 ModuleParameter:
282 ParameterName ParamOpType ParameterValue
283 ;
284
285 ParameterName:
286 ParameterNameSegment
287 | '*' '.' ParameterNameSegment
288 ;
289
290 ParameterNameSegment:
291 ParameterNameSegment '.' Identifier { Free($3); }
292 | ParameterNameSegment IndexItemIndex
293 | Identifier { Free($1); }
294
295
296 ParameterValue:
297 ParameterExpression
298 | ParameterExpression LengthMatch
299 | ParameterExpression IfpresentKeyword
300 | ParameterExpression LengthMatch IfpresentKeyword
301 ;
302
303 LengthMatch:
304 LengthKeyword '(' LengthBound ')'
305 | LengthKeyword '(' LengthBound DotDot LengthBound ')'
306 | LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
307 ;
308
309 LengthBound:
310 ParameterExpression
311 ;
312
313 ParameterExpression:
314 SimpleParameterValue
315 | ParameterReference
316 | '(' ParameterExpression ')'
317 | '+' ParameterExpression %prec UnarySign
318 | '-' ParameterExpression %prec UnarySign
319 | ParameterExpression '+' ParameterExpression
320 | ParameterExpression '-' ParameterExpression
321 | ParameterExpression '*' ParameterExpression
322 | ParameterExpression '/' ParameterExpression
323 | ParameterExpression '&' ParameterExpression
324 ;
325
326 ParameterReference:
327 ParameterNameSegment
328 ;
329
330 SimpleParameterValue:
331 MPNumber { BN_free($1); }
332 | MPFloat
333 | BooleanValue
334 | ObjIdValue
335 | VerdictValue
336 | BitstringValue
337 | HexstringValue
338 | OctetstringValue
339 | MPCstring { Free($1); }
340 | UniversalCharstringValue
341 | OmitKeyword
342 | NULLKeyword
343 | nullKeyword
344 | '?'
345 | '*'
346 | IntegerRange
347 | FloatRange
348 | StringRange
349 | PatternKeyword PatternChunk
350 | BstringMatch
351 | HstringMatch
352 | OstringMatch
353 | CompoundValue
354 | MTCKeyword
355 | SystemKeyword
356 ;
357
358 PatternChunk:
359 MPCstring { Free($1); }
360 | Quadruple
361 ;
362
363 IntegerRange:
364 '(' '-' InfinityKeyword DotDot MPNumber ')' { BN_free($5); }
365 | '(' MPNumber DotDot MPNumber ')' { BN_free($2); BN_free($4); }
366 | '(' MPNumber DotDot InfinityKeyword ')' { BN_free($2); }
367 ;
368
369 FloatRange:
370 '(' '-' InfinityKeyword DotDot MPFloat ')'
371 | '(' MPFloat DotDot MPFloat ')'
372 | '(' MPFloat DotDot InfinityKeyword ')'
373 ;
374
375 StringRange:
376 '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
377
378 IntegerValue:
379 Number { $$ = $1; }
380 | '(' IntegerValue ')' { $$ = $2; }
381 | '+' IntegerValue %prec UnarySign { $$ = $2; }
382 | '-' IntegerValue %prec UnarySign
383 {
384 BN_set_negative($2, !BN_is_negative($2));
385 $$ = $2;
386 }
387 | IntegerValue '+' IntegerValue
388 {
389 $$ = BN_new();
390 BN_add($$, $1, $3);
391 BN_free($1);
392 BN_free($3);
393 }
394 | IntegerValue '-' IntegerValue
395 {
396 $$ = BN_new();
397 BN_sub($$, $1, $3);
398 BN_free($1);
399 BN_free($3);
400 }
401 | IntegerValue '*' IntegerValue
402 {
403 $$ = BN_new();
404 BN_CTX *ctx = BN_CTX_new();
405 BN_CTX_init(ctx);
406 BN_mul($$, $1, $3, ctx);
407 BN_CTX_free(ctx);
408 BN_free($1);
409 BN_free($3);
410 }
411 | IntegerValue '/' IntegerValue
412 {
413 $$ = BN_new();
414 BIGNUM *BN_0 = BN_new();
415 BN_set_word(BN_0, 0);
416 if (BN_cmp($3, BN_0) == 0) {
417 config_read_error("Integer division by zero.");
418 $$ = BN_0;
419 } else {
420 BN_CTX *ctx = BN_CTX_new();
421 BN_CTX_init(ctx);
422 BN_div($$, NULL, $1, $3, ctx);
423 BN_CTX_free(ctx);
424 BN_free(BN_0);
425 }
426 BN_free($1);
427 BN_free($3);
428 }
429 ;
430
431 FloatValue:
432 Float { $$ = $1; }
433 | '(' FloatValue ')' { $$ = $2; }
434 | '+' FloatValue %prec UnarySign { $$ = $2; }
435 | '-' FloatValue %prec UnarySign { $$ = -$2; }
436 | FloatValue '+' FloatValue { $$ = $1 + $3; }
437 | FloatValue '-' FloatValue { $$ = $1 - $3; }
438 | FloatValue '*' FloatValue { $$ = $1 * $3; }
439 | FloatValue '/' FloatValue
440 {
441 if ($3 == 0.0) {
442 config_read_error("Floating point division by zero.");
443 $$ = 0.0;
444 } else $$ = $1 / $3;
445 }
446 ;
447
448 ObjIdValue:
449 ObjIdKeyword '{' ObjIdComponentList '}'
450 ;
451
452 ObjIdComponentList:
453 ObjIdComponent
454 | ObjIdComponentList ObjIdComponent
455 ;
456
457 ObjIdComponent:
458 NumberForm
459 | NameAndNumberForm
460 ;
461
462 NumberForm:
463 MPNumber { BN_free($1); }
464 ;
465
466 NameAndNumberForm:
467 Identifier '(' MPNumber ')' { Free($1); BN_free($3); }
468 ;
469
470 BitstringValue:
471 Bstring
472 ;
473
474 HexstringValue:
475 Hstring
476 ;
477
478 OctetstringValue:
479 Ostring
480 ;
481
482 UniversalCharstringValue:
483 Quadruple
484 | USI
485 ;
486
487 UniversalCharstringFragment:
488 MPCstring { Free($1); }
489 | Quadruple
490 ;
491
492 Quadruple:
493 CharKeyword '(' ParameterExpression ',' ParameterExpression ','
494 ParameterExpression ',' ParameterExpression ')'
495 ;
496
497 USI:
498 CharKeyword '(' UIDlike ')'
499 ;
500
501 UIDlike:
502 Cstring { Free($1); }
503 | UIDlike ',' Cstring { Free($3); }
504 ;
505
506 StringValue:
507 Cstring { $$ = $1; }
508 | StringValue '&' Cstring {
509 $$ = mputstr($1, $3);
510 Free($3);
511 }
512 ;
513
514 CompoundValue:
515 '{' '}'
516 | '{' FieldValueList '}'
517 | '{' ArrayItemList '}'
518 | '{' IndexItemList '}'
519 | '(' ParameterValue ',' TemplateItemList ')' /* at least 2 elements to avoid shift/reduce conflicts with the ParameterExpression rule */
520 | ComplementKeyword '(' TemplateItemList ')'
521 | SupersetKeyword '(' TemplateItemList ')'
522 | SubsetKeyword '(' TemplateItemList ')'
523 ;
524
525 ParameterValueOrNotUsedSymbol:
526 ParameterValue
527 | '-'
528 ;
529
530 TemplateItemList:
531 ParameterValue
532 | TemplateItemList ',' ParameterValue
533 ;
534
535 FieldValueList:
536 FieldValue
537 | FieldValueList ',' FieldValue
538 ;
539
540 FieldValue:
541 FieldName AssignmentChar ParameterValueOrNotUsedSymbol
542 ;
543
544 FieldName:
545 Identifier { Free($1); }
546 | ASN1LowerIdentifier
547 ;
548
549 ArrayItemList:
550 ArrayItem
551 | ArrayItemList ',' ArrayItem
552 ;
553
554 ArrayItem:
555 ParameterValueOrNotUsedSymbol
556 | PermutationKeyword '(' TemplateItemList ')'
557 ;
558
559 IndexItemList:
560 IndexItem
561 | IndexItemList ',' IndexItem
562 ;
563
564 IndexItem:
565 IndexItemIndex AssignmentChar ParameterValue
566 ;
567
568 IndexItemIndex:
569 '[' ParameterExpression ']'
570 ;
571
572 /******************* [LOGGING] section *******************/
573
574 LoggingSection:
575 LoggingKeyword LoggingParamList
576 ;
577
578 LoggingParamList:
579 /* empty */
580 | LoggingParamList LoggingParamLines optSemiColon
581 ;
582
583 LoggingParamLines:
584 LoggingParam
585 | ComponentId '.' LoggingParam
586 | ComponentId '.' LoggerPluginId '.' LoggingParam
587 | LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
588 | ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
589 ;
590
591 LoggerPluginId:
592 '*'
593 | Identifier { Free($1); }
594 ;
595
596 LoggingParam:
597 FileMask AssignmentChar LoggingBitMask
598 | ConsoleMask AssignmentChar LoggingBitMask
599 | LogFileSize AssignmentChar Number { BN_free($3); }
600 | EmergencyLogging AssignmentChar Number { BN_free($3); }
601 | EmergencyLoggingBehaviour AssignmentChar EmergencyLoggingBehaviourValue
602 | EmergencyLoggingMask AssignmentChar LoggingBitMask
603 | EmergencyLoggingForFailVerdict AssignmentChar YesNoOrBoolean
604 | LogFileNumber AssignmentChar Number { BN_free($3); }
605 | DiskFullAction AssignmentChar DiskFullActionValue
606 | LogFile AssignmentChar LogFileName { cfg->set_log_file($3); }
607 | TimestampFormat AssignmentChar TimestampValue
608 | ConsoleTimestampFormat AssignmentChar TimestampValue {cfg->tsformat=$3;}
609 | SourceInfoFormat AssignmentChar SourceInfoSetting
610 | AppendFile AssignmentChar YesNoOrBoolean
611 | LogEventTypes AssignmentChar LogEventTypesValue
612 | LogEntityName AssignmentChar YesNoOrBoolean
613 | MatchingHints AssignmentChar MatchVerbosityValue
614 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
615 ;
616
617 LoggerPluginList:
618 LoggerPlugin
619 | LoggerPluginList ',' LoggerPlugin
620 ;
621
622 LoggerPlugin:
623 Identifier { Free($1); }
624 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
625 ;
626
627 DiskFullActionValue:
628 Error
629 | Stop
630 | Re_try
631 | Re_try '(' Number ')' { BN_free($3); }
632 | Delete
633 ;
634
635 LogFileName:
636 StringValue { $$ = $1; }
637 ;
638
639 //optTestComponentIdentifier:
640 /* empty */
641 /* | Identifier '.' { Free($1); }
642 | Number '.'
643 | MTCKeyword '.'
644 | '*' '.'
645 ;*/
646
647 LoggingBitMask:
648 LoggingBitorCollection
649 | LoggingBitMask ListOp LoggingBitorCollection
650 ;
651
652 ListOp:
653 /* empty */
654 /*|*/ '|'
655 ;
656
657 LoggingBitorCollection:
658 LoggingBit
659 | LoggingBitCollection
660 ;
661
662 SourceInfoSetting:
663 SourceInfoValue
664 | YesNoOrBoolean
665 ;
666
667 YesNoOrBoolean:
668 YesNo
669 | BooleanValue
670 ;
671
672 LogEventTypesValue:
673 YesNoOrBoolean
674 | Detailed
675 | SubCategories
676 ;
677
678 MatchVerbosityValue:
679 Compact
680 | Detailed
681 ;
682
683 /*********************** [PROFILER] ********************************/
684
685 ProfilerSection:
686 ProfilerKeyword ProfilerSettings
687 ;
688
689 ProfilerSettings:
690 /* empty */
691 | ProfilerSettings ProfilerSetting optSemiColon
692 ;
693
694 ProfilerSetting:
695 DisableProfilerSetting
696 | DisableCoverageSetting
697 | DatabaseFileSetting
698 | AggregateDataSetting
699 | StatisticsFileSetting
700 | DisableStatisticsSetting
701 | StatisticsFilterSetting
702 | StartAutomaticallySetting
703 | NetLineTimesSetting
704 | NetFunctionTimesSetting
705 ;
706
707 DisableProfilerSetting:
708 DisableProfilerKeyword AssignmentChar BooleanValue
709 ;
710
711 DisableCoverageSetting:
712 DisableCoverageKeyword AssignmentChar BooleanValue
713 ;
714
715 DatabaseFileSetting:
716 DatabaseFileKeyword AssignmentChar StringValue { Free($3); }
717 ;
718
719 AggregateDataSetting:
720 AggregateDataKeyword AssignmentChar BooleanValue
721 ;
722
723 StatisticsFileSetting:
724 StatisticsFileKeyword AssignmentChar StringValue { Free($3); }
725 ;
726
727 DisableStatisticsSetting:
728 DisableStatisticsKeyword AssignmentChar BooleanValue
729 ;
730
731 StatisticsFilterSetting:
732 StatisticsFilterKeyword AssignmentChar ProfilerStatsFlags
733 | StatisticsFilterKeyword ConcatChar ProfilerStatsFlags
734 ;
735
736 ProfilerStatsFlags:
737 ProfilerStatsFlag
738 | ProfilerStatsFlag '&' ProfilerStatsFlags
739 | ProfilerStatsFlag '|' ProfilerStatsFlags
740 ;
741
742 StartAutomaticallySetting:
743 StartAutomaticallyKeyword AssignmentChar BooleanValue
744 ;
745
746 NetLineTimesSetting:
747 NetLineTimesKeyword AssignmentChar BooleanValue
748 ;
749
750 NetFunctionTimesSetting:
751 NetFunctionTimesKeyword AssignmentChar BooleanValue
752 ;
753
754 /******************* [TESTPORT_PARAMETERS] section *******************/
755
756 TestportParametersSection:
757 TestportParametersKeyword TestportParameterList
758 ;
759
760 TestportParameterList:
761 /* empty */
762 | TestportParameterList TestportParameter optSemiColon
763 ;
764
765 TestportParameter:
766 ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
767 TestportParameterValue
768 ;
769
770 ComponentId:
771 Identifier { Free($1); }
772 | Number { BN_free($1); }
773 | MTCKeyword
774 | '*'
775 | SystemKeyword
776 | Cstring { Free($1); }
777 ;
778
779 TestportName:
780 Identifier { Free($1); }
781 | Identifier ArrayRef { Free($1); }
782 | '*'
783 ;
784
785 ArrayRef:
786 '[' IntegerValue ']' { BN_free($2); }
787 | ArrayRef '[' IntegerValue ']' { BN_free($3); }
788 ;
789
790 TestportParameterName:
791 Identifier { Free($1); }
792 ;
793
794 TestportParameterValue:
795 StringValue { Free($1); }
796 ;
797
798 /******************* [EXECUTE] section *******************/
799
800 ExecuteSection:
801 ExecuteKeyword ExecuteList
802 ;
803
804 ExecuteList:
805 /* empty */
806 | ExecuteList ExecuteItem optSemiColon
807 {
808 cfg->add_exec($2);
809 }
810 ;
811
812 ExecuteItem:
813 Identifier
814 {
815 $$.module_name = $1;
816 $$.testcase_name = NULL;
817 }
818 | Identifier '.' ControlKeyword
819 {
820 $$.module_name = $1;
821 $$.testcase_name = NULL;
822 }
823 | Identifier '.' Identifier
824 {
825 $$.module_name = $1;
826 $$.testcase_name = $3;
827 }
828 | Identifier '.' '*'
829 {
830 $$.module_name = $1;
831 $$.testcase_name = mcopystr("*");
832 }
833 ;
834
835 /******************* [EXTERNAL_COMMANDS] section *******************/
836
837 ExternalCommandsSection:
838 ExternalCommandsKeyword ExternalCommandList
839 ;
840
841 ExternalCommandList:
842 /* empty */
843 | ExternalCommandList ExternalCommand optSemiColon
844 ;
845
846 ExternalCommand:
847 BeginControlPart AssignmentChar Command
848 | EndControlPart AssignmentChar Command
849 | BeginTestCase AssignmentChar Command
850 | EndTestCase AssignmentChar Command
851 ;
852
853 Command:
854 StringValue { Free($1); }
855 ;
856
857 /******************* [GROUPS] section *******************/
858
859 GroupsSection:
860 GroupsKeyword GroupList
861 ;
862
863 GroupList:
864 /* empty */
865 | GroupList Group optSemiColon
866 ;
867
868 Group:
869 GroupName AssignmentChar GroupMembers
870 {
871 Free(group_name);
872 group_name = NULL;
873 }
874 ;
875
876 GroupName:
877 Identifier { group_name = $1; }
878 ;
879
880 GroupMembers:
881 '*'
882 {
883 if (group_name != NULL) cfg->add_host(group_name, NULL);
884 }
885 | seqGroupMember
886 ;
887
888 seqGroupMember:
889 HostName
890 {
891 if (group_name != NULL && $1 != NULL)
892 cfg->add_host(group_name, $1);
893 Free($1);
894 }
895 | seqGroupMember ',' HostName
896 {
897 if (group_name != NULL && $3 != NULL)
898 cfg->add_host(group_name, $3);
899 Free($3);
900 }
901 ;
902
903 HostName:
904 DNSName { $$ = $1; }
905 | Identifier
906 {
907 $$ = $1;
908 if ($$ != NULL) {
909 size_t string_len = strlen($$);
910 for (size_t i = 0; i < string_len; i++) $$[i] = tolower($$[i]);
911 }
912 }
913 ;
914
915 /******************* [COMPONENTS] section *******************/
916
917 ComponentsSection:
918 ComponentsKeyword ComponentList
919 ;
920
921 ComponentList:
922 /* empty */
923 | ComponentList ComponentItem optSemiColon
924 ;
925
926 ComponentItem:
927 ComponentName AssignmentChar ComponentLocation
928 {
929 if ($3 != NULL) cfg->add_component($3, $1);
930 //Free($1);
931 //Free($3);
932 }
933 ;
934
935 ComponentName:
936 Identifier { $$ = $1; }
937 | '*' { $$ = NULL; }
938 ;
939
940 ComponentLocation:
941 Identifier { $$ = $1; }
942 | DNSName { $$ = $1; }
943 ;
944
945 /******************* [MAIN_CONTROLLER] section *******************/
946
947 MainControllerSection:
948 MainControllerKeyword MCParameterList
949 ;
950
951 MCParameterList:
952 /* empty */
953 | MCParameterList MCParameter optSemiColon
954 ;
955
956 MCParameter:
957 LocalAddress AssignmentChar HostName
958 {
959 check_duplicate_option("LocalAddress", &local_addr_set);
960 Free(cfg->local_addr);
961 cfg->local_addr = $3;
962 }
963 | TCPPort AssignmentChar IntegerValue
964 {
965 check_duplicate_option("TCPPort", &tcp_listen_port_set);
966 BIGNUM *BN_0 = BN_new();
967 BN_set_word(BN_0, 0);
968 BIGNUM *BN_65535 = BN_new();
969 BN_set_word(BN_65535, 65535);
970 char *int_val_str = BN_bn2dec($3);
971 if (BN_cmp($3, BN_0) < 0 || BN_cmp($3, BN_65535) > 0)
972 config_read_error("An integer value within range 0 .. 65535 was "
973 "expected for parameter TCPPort instead of %s.",
974 int_val_str);
975 else cfg->tcp_listen_port = (unsigned short)BN_get_word($3);
976 BN_free(BN_0);
977 BN_free(BN_65535);
978 BN_free($3);
979 OPENSSL_free(int_val_str);
980 }
981 | KillTimer AssignmentChar KillTimerValue
982 {
983 check_duplicate_option("KillTimer", &kill_timer_set);
984 if ($3 >= 0.0) cfg->kill_timer = $3;
985 else config_read_error("A non-negative numeric value was expected for "
986 "parameter KillTimer instead of %g.", $3);
987 }
988 | NumHCs AssignmentChar IntegerValue
989 {
990 check_duplicate_option("NumHCs", &num_hcs_set);
991 BIGNUM *BN_0 = BN_new();
992 BN_set_word(BN_0, 0);
993 char *int_val_str = BN_bn2dec($3);
994 if (BN_cmp($3, BN_0) <= 0)
995 config_read_error("A positive integer value was expected for "
996 "parameter NumHCs instead of %s.", int_val_str);
997 else cfg->num_hcs = (int)BN_get_word($3);
998 BN_free(BN_0);
999 // Check if we really need to free this!
1000 BN_free($3);
1001 OPENSSL_free(int_val_str);
1002 }
1003 | UnixSocketEnabled AssignmentChar YesToken
1004 {
1005 cfg->unix_sockets_enabled = true;
1006 }
1007 | UnixSocketEnabled AssignmentChar NoToken
1008 {
1009 cfg->unix_sockets_enabled = false;
1010 }
1011 | UnixSocketEnabled AssignmentChar HostName
1012 {
1013 config_read_error("Only 'yes' or 'no' is accepted instead of '%s'", $3);
1014 }
1015 ;
1016
1017 KillTimerValue:
1018 FloatValue { $$ = $1; }
1019 | IntegerValue
1020 {
1021 double tmp = (double)BN_get_word($1);
1022 if (BN_is_negative($1)) tmp *= -1;
1023 $$ = tmp;
1024 BN_free($1);
1025 }
1026 ;
1027
1028 /******************* [INCLUDE] section *******************/
1029
1030 IncludeSection:
1031 IncludeKeyword IncludeFiles
1032 ;
1033
1034 IncludeFiles:
1035 /* empty */
1036 | IncludeFiles IncludeFile
1037 ;
1038
1039 IncludeFile:
1040 Cstring { Free($1); }
1041 ;
1042
1043 /******************* [DEFINE] section *******************/
1044
1045 DefineSection:
1046 DefineKeyword
1047 ;
1048
1049 /********************************************************/
1050
1051 ParamOpType:
1052 AssignmentChar
1053 | ConcatChar
1054 ;
1055
1056 optSemiColon:
1057 /* empty */
1058 | ';'
1059 ;
1060
1061 %%
1062
1063
1064 int process_config_read_file(const char *file_name, config_data *pcfg)
1065 {
1066 // reset "locals"
1067 local_addr_set = FALSE;
1068 tcp_listen_port_set = FALSE;
1069 kill_timer_set = FALSE;
1070 num_hcs_set = FALSE;
1071
1072 error_flag = FALSE;
1073 string_chain_t *filenames=NULL;
1074 cfg = pcfg;
1075
1076 /* Initializing parameters to default values */
1077 cfg->clear();
1078
1079 if(preproc_parse_file(file_name, &filenames, &config_defines))
1080 error_flag=TRUE;
1081
1082 while(filenames) {
1083 char *fn=string_chain_cut(&filenames);
1084 config_read_lineno=1;
1085 /* The lexer can modify config_process_in
1086 * when it's input buffer is changed */
1087 config_read_in = fopen(fn, "r");
1088 if (config_read_in == NULL) {
1089 fprintf(stderr, "Cannot open configuration file: %s (%s)\n",
1090 fn, strerror(errno));
1091 error_flag=TRUE;
1092 } else {
1093 FILE* tmp_cfg = config_read_in;
1094 config_read_restart(config_read_in);
1095 config_read_reset(fn);
1096 if(config_read_parse()) error_flag=TRUE;
1097 fclose(tmp_cfg);
1098 /* During parsing flex or libc may use some system calls (e.g. ioctl)
1099 * that fail with an error status. Such error codes shall be ignored in
1100 * future error messages. */
1101 errno = 0;
1102 }
1103 Free(fn);
1104 }
1105
1106 config_read_close();
1107
1108 string_map_free(config_defines);
1109 config_defines=NULL;
1110
1111 return error_flag ? -1 : 0;
1112 }
1113
1114 static void check_duplicate_option(const char *option_name,
1115 boolean *option_flag)
1116 {
1117 if (*option_flag) {
1118 config_read_warning("Option `%s' was given more than once in section "
1119 "[MAIN_CONTROLLER].", option_name);
1120 } else *option_flag = TRUE;
1121 }
1122
1123
1124 #ifndef NDEBUG
1125 void yyprint(FILE *file, int type, const YYSTYPE& value)
1126 {
1127 switch (type) {
1128 case DNSName:
1129 case Identifier:
1130 case Cstring:
1131 fprintf(file, "'%s'", value.str_val);
1132 break;
1133
1134 case Number: {
1135 char *string_repr = BN_bn2dec(value.int_val);
1136 fprintf(file, "%s", string_repr);
1137 OPENSSL_free(string_repr);
1138 break; }
1139 default:
1140 break;
1141 }
1142 }
1143 #endif
This page took 0.055651 seconds and 5 git commands to generate.