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 ******************************************************************************/
17 #include <openssl/crypto.h>
18 #include <openssl/bn.h>
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"
26 #define YYERROR_VERBOSE
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();
39 boolean error_flag = FALSE;
40 static boolean local_addr_set = FALSE,
41 tcp_listen_port_set = FALSE,
42 kill_timer_set = FALSE,
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, ...);
54 static char *group_name = NULL;
56 string_map_t *config_defines;
61 static void yyprint(FILE *file, int type, const YYSTYPE& value);
62 #define YYPRINT(f,t,v) yyprint(f,t,v)
72 cf_timestamp_format ts_val;
73 execute_list_item execute_item_val;
76 %token ModuleParametersKeyword
78 %token TestportParametersKeyword
80 %token ExternalCommandsKeyword
82 %token ComponentsKeyword
83 %token MainControllerKeyword
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"
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"
107 %token LogFile "LogFile of FileName"
108 %token EmergencyLogging
109 %token EmergencyLoggingBehaviour
110 %token EmergencyLoggingBehaviourValue "BufferAll or BufferMasked"
111 %token EmergencyLoggingMask
114 %token TimestampFormat
115 %token ConsoleTimestampFormat
116 %token SourceInfoFormat "LogSourceInfo or SourceInfoFormat"
123 %token BeginControlPart
124 %token EndControlPart
128 %token <str_val> Identifier
129 %token ASN1LowerIdentifier "ASN.1 identifier beginning with a lowercase letter"
131 %token <int_val> Number
132 %token <float_val> Float
133 %token BooleanValue "true or false"
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"
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 */
152 %token UnixSocketEnabled
153 %token YesToken "yes" /* from MAIN_CONTROLLER section */
160 %token DiskFullAction
163 %token Re_try /* Retry clashes with an enum in Qt */
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
173 %destructor { Free($$); }
184 Free($$.module_name);
185 Free($$.testcase_name);
189 %destructor { BN_free($$); }
200 Source of conflicts (2 S/R):
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
208 The built-in Bison behavior always chooses the shift over the reduce
209 (the * is interpreted as multiplication).
220 ModuleParametersSection
222 | TestportParametersSection
224 | ExternalCommandsSection
227 | MainControllerSection
232 /******************* [MODULE_PARAMETERS] section *******************/
234 ModuleParametersSection:
235 ModuleParametersKeyword ModuleParameters
240 | ModuleParameters ModuleParameter optSemiColon
244 ParameterName ParamOpType ParameterValue
249 | '*' '.' ParameterNameSegment
252 ParameterNameSegment:
253 ParameterNameSegment '.' Identifier { Free($3); }
254 | ParameterNameSegment '[' Number ']' { BN_free($3); }
255 | Identifier { Free($1); }
260 | SimpleParameterValue LengthMatch
261 | SimpleParameterValue IfpresentKeyword
262 | SimpleParameterValue LengthMatch IfpresentKeyword
266 LengthKeyword '(' LengthBound ')'
267 | LengthKeyword '(' LengthBound DotDot LengthBound ')'
268 | LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
272 IntegerValue { BN_free($1); }
275 SimpleParameterValue:
276 IntegerValue { BN_free($1); }
284 | Cstring { Free($1); }
285 | UniversalCharstringValue
295 | PatternKeyword PatternChunkList
306 | PatternChunkList '&' PatternChunk
310 Cstring { Free($1); }
315 '(' '-' InfinityKeyword DotDot IntegerValue ')' { BN_free($5); }
316 | '(' IntegerValue DotDot IntegerValue ')' { BN_free($2); BN_free($4); }
317 | '(' IntegerValue DotDot InfinityKeyword ')' { BN_free($2); }
321 '(' '-' InfinityKeyword DotDot FloatValue ')'
322 | '(' FloatValue DotDot FloatValue ')'
323 | '(' FloatValue DotDot InfinityKeyword ')'
327 '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
331 | '(' IntegerValue ')' { $$ = $2; }
332 | '+' IntegerValue %prec UnarySign { $$ = $2; }
333 | '-' IntegerValue %prec UnarySign
335 BN_set_negative($2, !BN_is_negative($2));
338 | IntegerValue '+' IntegerValue
345 | IntegerValue '-' IntegerValue
352 | IntegerValue '*' IntegerValue
355 BN_CTX *ctx = BN_CTX_new();
357 BN_mul($$, $1, $3, ctx);
362 | IntegerValue '/' IntegerValue
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.");
371 BN_CTX *ctx = BN_CTX_new();
373 BN_div($$, NULL, $1, $3, ctx);
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
393 config_read_error("Floating point division by zero.");
400 ObjIdKeyword '{' ObjIdComponentList '}'
405 | ObjIdComponentList ObjIdComponent
414 Number { BN_free($1); }
418 Identifier '(' Number ')' { Free($1); BN_free($3); }
423 | BitstringValue ConcatOp Bstring
428 | HexstringValue ConcatOp Hstring
433 | OctetstringValue ConcatOp Ostring
436 UniversalCharstringValue:
437 Cstring seqUniversalCharstringFragment { Free($1); }
439 | Quadruple seqUniversalCharstringFragment
442 seqUniversalCharstringFragment:
443 ConcatOp UniversalCharstringFragment
444 | seqUniversalCharstringFragment ConcatOp UniversalCharstringFragment
447 UniversalCharstringFragment:
448 Cstring { Free($1); }
453 CharKeyword '(' IntegerValue ',' IntegerValue ',' IntegerValue ','
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.",
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.",
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.",
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);
502 | StringValue ConcatOp Cstring {
503 $$ = mputstr($1, $3);
509 Identifier { Free($1); }
510 | ASN1LowerIdentifier
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 ')'
524 ParameterValueOrNotUsedSymbol:
531 | TemplateItemList ',' ParameterValue
536 | FieldValueList ',' FieldValue
540 FieldName AssignmentChar ParameterValueOrNotUsedSymbol
544 Identifier { Free($1); }
545 | ASN1LowerIdentifier
550 | ArrayItemList ',' ArrayItem
554 ParameterValueOrNotUsedSymbol
555 | PermutationKeyword '(' TemplateItemList ')'
560 | IndexItemList ',' IndexItem
564 IndexItemIndex AssignmentChar ParameterValue
568 '[' IntegerValue ']' { BN_free($2); }
571 /******************* [LOGGING] section *******************/
574 LoggingKeyword LoggingParamList
579 | LoggingParamList LoggingParamLines optSemiColon
584 | ComponentId '.' LoggingParam
585 | ComponentId '.' LoggerPluginId '.' LoggingParam
586 | LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
587 | ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
592 | Identifier { Free($1); }
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); }
617 | LoggerPluginList ',' LoggerPlugin
621 Identifier { Free($1); }
622 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
629 | Re_try '(' Number ')' { BN_free($3); }
634 StringValue { $$ = $1; }
637 //optTestComponentIdentifier:
639 /* | Identifier '.' { Free($1); }
646 LoggingBitorCollection
647 | LoggingBitMask ListOp LoggingBitorCollection
655 LoggingBitorCollection:
657 | LoggingBitCollection
681 /******************* [TESTPORT_PARAMETERS] section *******************/
683 TestportParametersSection:
684 TestportParametersKeyword TestportParameterList
687 TestportParameterList:
689 | TestportParameterList TestportParameter optSemiColon
693 ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
694 TestportParameterValue
698 Identifier { Free($1); }
699 | Number { BN_free($1); }
703 | Cstring { Free($1); }
707 Identifier { Free($1); }
708 | Identifier ArrayRef { Free($1); }
713 '[' IntegerValue ']' { BN_free($2); }
714 | ArrayRef '[' IntegerValue ']' { BN_free($3); }
717 TestportParameterName:
718 Identifier { Free($1); }
721 TestportParameterValue:
722 StringValue { Free($1); }
725 /******************* [EXECUTE] section *******************/
728 ExecuteKeyword ExecuteList
733 | ExecuteList ExecuteItem optSemiColon
743 $$.testcase_name = NULL;
745 | Identifier '.' ControlKeyword
748 $$.testcase_name = NULL;
750 | Identifier '.' Identifier
753 $$.testcase_name = $3;
758 $$.testcase_name = mcopystr("*");
762 /******************* [EXTERNAL_COMMANDS] section *******************/
764 ExternalCommandsSection:
765 ExternalCommandsKeyword ExternalCommandList
770 | ExternalCommandList ExternalCommand optSemiColon
774 BeginControlPart AssignmentChar Command
775 | EndControlPart AssignmentChar Command
776 | BeginTestCase AssignmentChar Command
777 | EndTestCase AssignmentChar Command
781 StringValue { Free($1); }
784 /******************* [GROUPS] section *******************/
787 GroupsKeyword GroupList
792 | GroupList Group optSemiColon
796 GroupName AssignmentChar GroupMembers
804 Identifier { group_name = $1; }
810 if (group_name != NULL) cfg->add_host(group_name, NULL);
818 if (group_name != NULL && $1 != NULL)
819 cfg->add_host(group_name, $1);
822 | seqGroupMember ',' HostName
824 if (group_name != NULL && $3 != NULL)
825 cfg->add_host(group_name, $3);
836 size_t string_len = strlen($$);
837 for (size_t i = 0; i < string_len; i++) $$[i] = tolower($$[i]);
842 /******************* [COMPONENTS] section *******************/
845 ComponentsKeyword ComponentList
850 | ComponentList ComponentItem optSemiColon
854 ComponentName AssignmentChar ComponentLocation
856 if ($3 != NULL) cfg->add_component($3, $1);
863 Identifier { $$ = $1; }
868 Identifier { $$ = $1; }
869 | DNSName { $$ = $1; }
872 /******************* [MAIN_CONTROLLER] section *******************/
874 MainControllerSection:
875 MainControllerKeyword MCParameterList
880 | MCParameterList MCParameter optSemiColon
884 LocalAddress AssignmentChar HostName
886 check_duplicate_option("LocalAddress", &local_addr_set);
887 Free(cfg->local_addr);
888 cfg->local_addr = $3;
890 | TCPPort AssignmentChar IntegerValue
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.",
902 else cfg->tcp_listen_port = (unsigned short)BN_get_word($3);
906 OPENSSL_free(int_val_str);
908 | KillTimer AssignmentChar KillTimerValue
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);
915 | NumHCs AssignmentChar IntegerValue
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);
926 // Check if we really need to free this!
928 OPENSSL_free(int_val_str);
930 | UnixSocketEnabled AssignmentChar YesToken
932 cfg->unix_sockets_enabled = true;
934 | UnixSocketEnabled AssignmentChar NoToken
936 cfg->unix_sockets_enabled = false;
938 | UnixSocketEnabled AssignmentChar HostName
940 config_read_error("Only 'yes' or 'no' is accepted instead of '%s'", $3);
945 FloatValue { $$ = $1; }
948 double tmp = (double)BN_get_word($1);
949 if (BN_is_negative($1)) tmp *= -1;
955 /******************* [INCLUDE] section *******************/
958 IncludeKeyword IncludeFiles
963 | IncludeFiles IncludeFile
967 Cstring { Free($1); }
970 /******************* [DEFINE] section *******************/
976 /********************************************************/
991 int process_config_read_file(const char *file_name, config_data *pcfg)
994 local_addr_set = FALSE;
995 tcp_listen_port_set = FALSE;
996 kill_timer_set = FALSE;
1000 string_chain_t *filenames=NULL;
1003 /* Initializing parameters to default values */
1006 if(preproc_parse_file(file_name, &filenames, &config_defines))
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));
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;
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. */
1033 config_read_close();
1035 string_map_free(config_defines);
1036 config_defines=NULL;
1038 return error_flag ? -1 : 0;
1041 static void check_duplicate_option(const char *option_name,
1042 boolean *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;
1052 void yyprint(FILE *file, int type, const YYSTYPE& value)
1058 fprintf(file, "'%s'", value.str_val);
1062 char *string_repr = BN_bn2dec(value.int_val);
1063 fprintf(file, "%s", string_repr);
1064 OPENSSL_free(string_repr);