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