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