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