1 /******************************************************************************
2 * Copyright (c) 2000-2016 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
21 * Szabo, Janos Zoltan – initial implementation
23 * Zalanyi, Balazs Andor
25 ******************************************************************************/
35 #include <openssl/crypto.h>
36 #include <openssl/bn.h>
38 #include "../../common/memory.h"
39 #include "../../common/config_preproc.h"
40 #include "../mctr/config_data.h"
41 #include "../../core/Types.h"
42 #include "../../core/RInt.hh"
44 #define YYERROR_VERBOSE
46 extern FILE *config_read_in;
47 extern int config_read_lineno;
48 extern char *config_read_text;
49 extern int config_read_lex();
50 extern void config_read_restart(FILE *new_file);
51 extern void config_read_reset(const char* fname);
52 extern void config_read_close();
53 extern std::string get_cfg_read_current_file();
57 boolean error_flag = FALSE;
58 static boolean local_addr_set = FALSE,
59 tcp_listen_port_set = FALSE,
60 kill_timer_set = FALSE,
63 static int config_read_parse();
64 int process_config_read_file(const char *file_name);
65 static void check_duplicate_option(const char *option_name,
66 boolean *option_flag);
67 void config_read_warning(const char *warning_str, ...);
68 void config_read_error(const char *error_str, ...);
72 static char *group_name = NULL;
74 string_map_t *config_defines;
79 static void yyprint(FILE *file, int type, const YYSTYPE& value);
80 #define YYPRINT(f,t,v) yyprint(f,t,v)
91 cf_timestamp_format ts_val;
92 execute_list_item execute_item_val;
95 %token ModuleParametersKeyword
97 %token ProfilerKeyword
98 %token TestportParametersKeyword
100 %token ExternalCommandsKeyword
102 %token ComponentsKeyword
103 %token MainControllerKeyword
104 %token IncludeKeyword
107 %token ObjIdKeyword "objid"
108 %token CharKeyword "char"
109 %token ControlKeyword "control"
110 %token MTCKeyword "mtc"
111 %token SystemKeyword "system"
112 %token NULLKeyword "NULL"
113 %token nullKeyword "null"
114 %token OmitKeyword "omit"
115 %token AssignmentChar ":= or ="
116 %token ConcatChar "&="
117 %token ComplementKeyword "complement"
119 %token SupersetKeyword "superset"
120 %token SubsetKeyword "subset"
121 %token PatternKeyword "pattern"
122 %token PermutationKeyword "permutation"
123 %token LengthKeyword "length"
124 %token IfpresentKeyword "ifpresent"
125 %token InfinityKeyword "infinity"
127 %token LogFile "LogFile of FileName"
128 %token EmergencyLogging
129 %token EmergencyLoggingBehaviour
130 %token EmergencyLoggingBehaviourValue "BufferAll or BufferMasked"
131 %token EmergencyLoggingMask
132 %token EmergencyLoggingForFailVerdict
135 %token TimestampFormat
136 %token ConsoleTimestampFormat
137 %token SourceInfoFormat "LogSourceInfo or SourceInfoFormat"
144 %token BeginControlPart
145 %token EndControlPart
150 %token <str_val> Identifier
151 %token ASN1LowerIdentifier "ASN.1 identifier beginning with a lowercase letter"
153 %token <int_val> Number MPNumber "integer value"
154 %token <float_val> Float MPFloat "float value"
155 %token BooleanValue "true or false"
157 %token Bstring "bit string value"
158 %token Hstring "hex string value"
159 %token Ostring "octet string value"
160 %token BstringMatch "bit string template"
161 %token HstringMatch "hex string template"
162 %token OstringMatch "octet string template"
163 %token <str_val> Cstring "character string value"
164 %token <str_val> MPCstring "charstring value"
165 %token <str_val> DNSName "a host name"
167 %token LoggingBitCollection
168 %token <ts_val> TimestampValue "Time, Datetime or Seconds"
169 %token SourceInfoValue "None, Single or Stack"
170 %token YesNo "Yes or No" /* from LOGGING section */
175 %token UnixSocketEnabled
176 %token YesToken "yes" /* from MAIN_CONTROLLER section */
183 %token DiskFullAction
186 %token Re_try /* Retry clashes with an enum in Qt */
189 %token DisableProfilerKeyword "DisableProfiler"
190 %token DisableCoverageKeyword "DisableCoverage"
191 %token DatabaseFileKeyword "DatabaseFile"
192 %token AggregateDataKeyword "AggregateData"
193 %token StatisticsFileKeyword "StatisticsFile"
194 %token DisableStatisticsKeyword "DisableStatistics"
195 %token StatisticsFilterKeyword "StatisticsFilter"
196 %token StartAutomaticallyKeyword "StartAutomatically"
197 %token NetLineTimesKeyword "NetLineTimes"
198 %token NetFunctionTimesKeyword "NetFunctionTimes"
199 %token ProfilerStatsFlag "profiler statistics flag"
201 %type <int_val> IntegerValue
202 %type <float_val> FloatValue KillTimerValue
203 %type <str_val> HostName StringValue LogFileName
204 %type <str_val> ComponentName
205 %type <str_val> ComponentLocation
206 %type <execute_item_val> ExecuteItem
208 %destructor { Free($$); }
220 Free($$.module_name);
221 Free($$.testcase_name);
225 %destructor { BN_free($$); }
230 %left '&' /* to avoid shift/reduce conflicts */
238 Source of conflicts (1 S/R):
241 When seeing a '*' token after a module parameter expression the parser cannot
242 decide whether the token is a multiplication operator (shift) or it refers to
243 all modules in the next module parameter (reduce).
245 The built-in Bison behavior always chooses the shift over the reduce
246 (the * is interpreted as multiplication).
257 ModuleParametersSection
260 | TestportParametersSection
262 | ExternalCommandsSection
265 | MainControllerSection
270 /******************* [MODULE_PARAMETERS] section *******************/
272 ModuleParametersSection:
273 ModuleParametersKeyword ModuleParameters
278 | ModuleParameters ModuleParameter optSemiColon
282 ParameterName ParamOpType ParameterValue
287 | '*' '.' ParameterNameSegment
290 ParameterNameSegment:
291 ParameterNameSegment '.' Identifier { Free($3); }
292 | ParameterNameSegment IndexItemIndex
293 | Identifier { Free($1); }
298 | ParameterExpression LengthMatch
299 | ParameterExpression IfpresentKeyword
300 | ParameterExpression LengthMatch IfpresentKeyword
304 LengthKeyword '(' LengthBound ')'
305 | LengthKeyword '(' LengthBound DotDot LengthBound ')'
306 | LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
316 | '(' ParameterExpression ')'
317 | '+' ParameterExpression %prec UnarySign
318 | '-' ParameterExpression %prec UnarySign
319 | ParameterExpression '+' ParameterExpression
320 | ParameterExpression '-' ParameterExpression
321 | ParameterExpression '*' ParameterExpression
322 | ParameterExpression '/' ParameterExpression
323 | ParameterExpression '&' ParameterExpression
330 SimpleParameterValue:
331 MPNumber { BN_free($1); }
339 | MPCstring { Free($1); }
340 | UniversalCharstringValue
349 | PatternKeyword PatternChunk
359 MPCstring { Free($1); }
364 '(' '-' InfinityKeyword DotDot MPNumber ')' { BN_free($5); }
365 | '(' MPNumber DotDot MPNumber ')' { BN_free($2); BN_free($4); }
366 | '(' MPNumber DotDot InfinityKeyword ')' { BN_free($2); }
370 '(' '-' InfinityKeyword DotDot MPFloat ')'
371 | '(' MPFloat DotDot MPFloat ')'
372 | '(' MPFloat DotDot InfinityKeyword ')'
376 '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
380 | '(' IntegerValue ')' { $$ = $2; }
381 | '+' IntegerValue %prec UnarySign { $$ = $2; }
382 | '-' IntegerValue %prec UnarySign
384 BN_set_negative($2, !BN_is_negative($2));
387 | IntegerValue '+' IntegerValue
394 | IntegerValue '-' IntegerValue
401 | IntegerValue '*' IntegerValue
404 BN_CTX *ctx = BN_CTX_new();
406 BN_mul($$, $1, $3, ctx);
411 | IntegerValue '/' IntegerValue
414 BIGNUM *BN_0 = BN_new();
415 BN_set_word(BN_0, 0);
416 if (BN_cmp($3, BN_0) == 0) {
417 config_read_error("Integer division by zero.");
420 BN_CTX *ctx = BN_CTX_new();
422 BN_div($$, NULL, $1, $3, ctx);
433 | '(' FloatValue ')' { $$ = $2; }
434 | '+' FloatValue %prec UnarySign { $$ = $2; }
435 | '-' FloatValue %prec UnarySign { $$ = -$2; }
436 | FloatValue '+' FloatValue { $$ = $1 + $3; }
437 | FloatValue '-' FloatValue { $$ = $1 - $3; }
438 | FloatValue '*' FloatValue { $$ = $1 * $3; }
439 | FloatValue '/' FloatValue
442 config_read_error("Floating point division by zero.");
449 ObjIdKeyword '{' ObjIdComponentList '}'
454 | ObjIdComponentList ObjIdComponent
463 MPNumber { BN_free($1); }
467 Identifier '(' MPNumber ')' { Free($1); BN_free($3); }
482 UniversalCharstringValue:
487 UniversalCharstringFragment:
488 MPCstring { Free($1); }
493 CharKeyword '(' ParameterExpression ',' ParameterExpression ','
494 ParameterExpression ',' ParameterExpression ')'
498 CharKeyword '(' UIDlike ')'
502 Cstring { Free($1); }
503 | UIDlike ',' Cstring { Free($3); }
508 | StringValue '&' Cstring {
509 $$ = mputstr($1, $3);
516 | '{' FieldValueList '}'
517 | '{' ArrayItemList '}'
518 | '{' IndexItemList '}'
519 | '(' ParameterValue ',' TemplateItemList ')' /* at least 2 elements to avoid shift/reduce conflicts with the ParameterExpression rule */
520 | ComplementKeyword '(' TemplateItemList ')'
521 | SupersetKeyword '(' TemplateItemList ')'
522 | SubsetKeyword '(' TemplateItemList ')'
525 ParameterValueOrNotUsedSymbol:
532 | TemplateItemList ',' ParameterValue
537 | FieldValueList ',' FieldValue
541 FieldName AssignmentChar ParameterValueOrNotUsedSymbol
545 Identifier { Free($1); }
546 | ASN1LowerIdentifier
551 | ArrayItemList ',' ArrayItem
555 ParameterValueOrNotUsedSymbol
556 | PermutationKeyword '(' TemplateItemList ')'
561 | IndexItemList ',' IndexItem
565 IndexItemIndex AssignmentChar ParameterValue
569 '[' ParameterExpression ']'
572 /******************* [LOGGING] section *******************/
575 LoggingKeyword LoggingParamList
580 | LoggingParamList LoggingParamLines optSemiColon
585 | ComponentId '.' LoggingParam
586 | ComponentId '.' LoggerPluginId '.' LoggingParam
587 | LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
588 | ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
593 | Identifier { Free($1); }
597 FileMask AssignmentChar LoggingBitMask
598 | ConsoleMask AssignmentChar LoggingBitMask
599 | LogFileSize AssignmentChar Number { BN_free($3); }
600 | EmergencyLogging AssignmentChar Number { BN_free($3); }
601 | EmergencyLoggingBehaviour AssignmentChar EmergencyLoggingBehaviourValue
602 | EmergencyLoggingMask AssignmentChar LoggingBitMask
603 | EmergencyLoggingForFailVerdict AssignmentChar YesNoOrBoolean
604 | LogFileNumber AssignmentChar Number { BN_free($3); }
605 | DiskFullAction AssignmentChar DiskFullActionValue
606 | LogFile AssignmentChar LogFileName { cfg->set_log_file($3); }
607 | TimestampFormat AssignmentChar TimestampValue
608 | ConsoleTimestampFormat AssignmentChar TimestampValue {cfg->tsformat=$3;}
609 | SourceInfoFormat AssignmentChar SourceInfoSetting
610 | AppendFile AssignmentChar YesNoOrBoolean
611 | LogEventTypes AssignmentChar LogEventTypesValue
612 | LogEntityName AssignmentChar YesNoOrBoolean
613 | MatchingHints AssignmentChar MatchVerbosityValue
614 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
619 | LoggerPluginList ',' LoggerPlugin
623 Identifier { Free($1); }
624 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
631 | Re_try '(' Number ')' { BN_free($3); }
636 StringValue { $$ = $1; }
639 //optTestComponentIdentifier:
641 /* | Identifier '.' { Free($1); }
648 LoggingBitorCollection
649 | LoggingBitMask ListOp LoggingBitorCollection
657 LoggingBitorCollection:
659 | LoggingBitCollection
683 /*********************** [PROFILER] ********************************/
686 ProfilerKeyword ProfilerSettings
691 | ProfilerSettings ProfilerSetting optSemiColon
695 DisableProfilerSetting
696 | DisableCoverageSetting
697 | DatabaseFileSetting
698 | AggregateDataSetting
699 | StatisticsFileSetting
700 | DisableStatisticsSetting
701 | StatisticsFilterSetting
702 | StartAutomaticallySetting
703 | NetLineTimesSetting
704 | NetFunctionTimesSetting
707 DisableProfilerSetting:
708 DisableProfilerKeyword AssignmentChar BooleanValue
711 DisableCoverageSetting:
712 DisableCoverageKeyword AssignmentChar BooleanValue
716 DatabaseFileKeyword AssignmentChar StringValue { Free($3); }
719 AggregateDataSetting:
720 AggregateDataKeyword AssignmentChar BooleanValue
723 StatisticsFileSetting:
724 StatisticsFileKeyword AssignmentChar StringValue { Free($3); }
727 DisableStatisticsSetting:
728 DisableStatisticsKeyword AssignmentChar BooleanValue
731 StatisticsFilterSetting:
732 StatisticsFilterKeyword AssignmentChar ProfilerStatsFlags
733 | StatisticsFilterKeyword ConcatChar ProfilerStatsFlags
738 | ProfilerStatsFlag '&' ProfilerStatsFlags
739 | ProfilerStatsFlag '|' ProfilerStatsFlags
742 StartAutomaticallySetting:
743 StartAutomaticallyKeyword AssignmentChar BooleanValue
747 NetLineTimesKeyword AssignmentChar BooleanValue
750 NetFunctionTimesSetting:
751 NetFunctionTimesKeyword AssignmentChar BooleanValue
754 /******************* [TESTPORT_PARAMETERS] section *******************/
756 TestportParametersSection:
757 TestportParametersKeyword TestportParameterList
760 TestportParameterList:
762 | TestportParameterList TestportParameter optSemiColon
766 ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
767 TestportParameterValue
771 Identifier { Free($1); }
772 | Number { BN_free($1); }
776 | Cstring { Free($1); }
780 Identifier { Free($1); }
781 | Identifier ArrayRef { Free($1); }
786 '[' IntegerValue ']' { BN_free($2); }
787 | ArrayRef '[' IntegerValue ']' { BN_free($3); }
790 TestportParameterName:
791 Identifier { Free($1); }
794 TestportParameterValue:
795 StringValue { Free($1); }
798 /******************* [EXECUTE] section *******************/
801 ExecuteKeyword ExecuteList
806 | ExecuteList ExecuteItem optSemiColon
816 $$.testcase_name = NULL;
818 | Identifier '.' ControlKeyword
821 $$.testcase_name = NULL;
823 | Identifier '.' Identifier
826 $$.testcase_name = $3;
831 $$.testcase_name = mcopystr("*");
835 /******************* [EXTERNAL_COMMANDS] section *******************/
837 ExternalCommandsSection:
838 ExternalCommandsKeyword ExternalCommandList
843 | ExternalCommandList ExternalCommand optSemiColon
847 BeginControlPart AssignmentChar Command
848 | EndControlPart AssignmentChar Command
849 | BeginTestCase AssignmentChar Command
850 | EndTestCase AssignmentChar Command
854 StringValue { Free($1); }
857 /******************* [GROUPS] section *******************/
860 GroupsKeyword GroupList
865 | GroupList Group optSemiColon
869 GroupName AssignmentChar GroupMembers
877 Identifier { group_name = $1; }
883 if (group_name != NULL) cfg->add_host(group_name, NULL);
891 if (group_name != NULL && $1 != NULL)
892 cfg->add_host(group_name, $1);
895 | seqGroupMember ',' HostName
897 if (group_name != NULL && $3 != NULL)
898 cfg->add_host(group_name, $3);
909 size_t string_len = strlen($$);
910 for (size_t i = 0; i < string_len; i++) $$[i] = tolower($$[i]);
915 /******************* [COMPONENTS] section *******************/
918 ComponentsKeyword ComponentList
923 | ComponentList ComponentItem optSemiColon
927 ComponentName AssignmentChar ComponentLocation
929 if ($3 != NULL) cfg->add_component($3, $1);
936 Identifier { $$ = $1; }
941 Identifier { $$ = $1; }
942 | DNSName { $$ = $1; }
945 /******************* [MAIN_CONTROLLER] section *******************/
947 MainControllerSection:
948 MainControllerKeyword MCParameterList
953 | MCParameterList MCParameter optSemiColon
957 LocalAddress AssignmentChar HostName
959 check_duplicate_option("LocalAddress", &local_addr_set);
960 Free(cfg->local_addr);
961 cfg->local_addr = $3;
963 | TCPPort AssignmentChar IntegerValue
965 check_duplicate_option("TCPPort", &tcp_listen_port_set);
966 BIGNUM *BN_0 = BN_new();
967 BN_set_word(BN_0, 0);
968 BIGNUM *BN_65535 = BN_new();
969 BN_set_word(BN_65535, 65535);
970 char *int_val_str = BN_bn2dec($3);
971 if (BN_cmp($3, BN_0) < 0 || BN_cmp($3, BN_65535) > 0)
972 config_read_error("An integer value within range 0 .. 65535 was "
973 "expected for parameter TCPPort instead of %s.",
975 else cfg->tcp_listen_port = (unsigned short)BN_get_word($3);
979 OPENSSL_free(int_val_str);
981 | KillTimer AssignmentChar KillTimerValue
983 check_duplicate_option("KillTimer", &kill_timer_set);
984 if ($3 >= 0.0) cfg->kill_timer = $3;
985 else config_read_error("A non-negative numeric value was expected for "
986 "parameter KillTimer instead of %g.", $3);
988 | NumHCs AssignmentChar IntegerValue
990 check_duplicate_option("NumHCs", &num_hcs_set);
991 BIGNUM *BN_0 = BN_new();
992 BN_set_word(BN_0, 0);
993 char *int_val_str = BN_bn2dec($3);
994 if (BN_cmp($3, BN_0) <= 0)
995 config_read_error("A positive integer value was expected for "
996 "parameter NumHCs instead of %s.", int_val_str);
997 else cfg->num_hcs = (int)BN_get_word($3);
999 // Check if we really need to free this!
1001 OPENSSL_free(int_val_str);
1003 | UnixSocketEnabled AssignmentChar YesToken
1005 cfg->unix_sockets_enabled = true;
1007 | UnixSocketEnabled AssignmentChar NoToken
1009 cfg->unix_sockets_enabled = false;
1011 | UnixSocketEnabled AssignmentChar HostName
1013 config_read_error("Only 'yes' or 'no' is accepted instead of '%s'", $3);
1018 FloatValue { $$ = $1; }
1021 double tmp = (double)BN_get_word($1);
1022 if (BN_is_negative($1)) tmp *= -1;
1028 /******************* [INCLUDE] section *******************/
1031 IncludeKeyword IncludeFiles
1036 | IncludeFiles IncludeFile
1040 Cstring { Free($1); }
1043 /******************* [DEFINE] section *******************/
1049 /********************************************************/
1064 int process_config_read_file(const char *file_name, config_data *pcfg)
1067 local_addr_set = FALSE;
1068 tcp_listen_port_set = FALSE;
1069 kill_timer_set = FALSE;
1070 num_hcs_set = FALSE;
1073 string_chain_t *filenames=NULL;
1076 /* Initializing parameters to default values */
1079 if(preproc_parse_file(file_name, &filenames, &config_defines))
1083 char *fn=string_chain_cut(&filenames);
1084 config_read_lineno=1;
1085 /* The lexer can modify config_process_in
1086 * when it's input buffer is changed */
1087 config_read_in = fopen(fn, "r");
1088 if (config_read_in == NULL) {
1089 fprintf(stderr, "Cannot open configuration file: %s (%s)\n",
1090 fn, strerror(errno));
1093 FILE* tmp_cfg = config_read_in;
1094 config_read_restart(config_read_in);
1095 config_read_reset(fn);
1096 if(config_read_parse()) error_flag=TRUE;
1098 /* During parsing flex or libc may use some system calls (e.g. ioctl)
1099 * that fail with an error status. Such error codes shall be ignored in
1100 * future error messages. */
1106 config_read_close();
1108 string_map_free(config_defines);
1109 config_defines=NULL;
1111 return error_flag ? -1 : 0;
1114 static void check_duplicate_option(const char *option_name,
1115 boolean *option_flag)
1118 config_read_warning("Option `%s' was given more than once in section "
1119 "[MAIN_CONTROLLER].", option_name);
1120 } else *option_flag = TRUE;
1125 void yyprint(FILE *file, int type, const YYSTYPE& value)
1131 fprintf(file, "'%s'", value.str_val);
1135 char *string_repr = BN_bn2dec(value.int_val);
1136 fprintf(file, "%s", string_repr);
1137 OPENSSL_free(string_repr);