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