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 ******************************************************************************/
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)
73 cf_timestamp_format ts_val;
74 execute_list_item execute_item_val;
77 %token ModuleParametersKeyword
79 %token ProfilerKeyword
80 %token TestportParametersKeyword
82 %token ExternalCommandsKeyword
84 %token ComponentsKeyword
85 %token MainControllerKeyword
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"
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"
109 %token LogFile "LogFile of FileName"
110 %token EmergencyLogging
111 %token EmergencyLoggingBehaviour
112 %token EmergencyLoggingBehaviourValue "BufferAll or BufferMasked"
113 %token EmergencyLoggingMask
116 %token TimestampFormat
117 %token ConsoleTimestampFormat
118 %token SourceInfoFormat "LogSourceInfo or SourceInfoFormat"
125 %token BeginControlPart
126 %token EndControlPart
130 %token <str_val> Identifier
131 %token ASN1LowerIdentifier "ASN.1 identifier beginning with a lowercase letter"
133 %token <int_val> Number MPNumber "integer value"
134 %token <float_val> Float MPFloat "float value"
135 %token BooleanValue "true or false"
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"
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 */
155 %token UnixSocketEnabled
156 %token YesToken "yes" /* from MAIN_CONTROLLER section */
163 %token DiskFullAction
166 %token Re_try /* Retry clashes with an enum in Qt */
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"
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
188 %destructor { Free($$); }
200 Free($$.module_name);
201 Free($$.testcase_name);
205 %destructor { BN_free($$); }
210 %left '&' /* to avoid shift/reduce conflicts */
218 Source of conflicts (1 S/R):
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).
225 The built-in Bison behavior always chooses the shift over the reduce
226 (the * is interpreted as multiplication).
237 ModuleParametersSection
240 | TestportParametersSection
242 | ExternalCommandsSection
245 | MainControllerSection
250 /******************* [MODULE_PARAMETERS] section *******************/
252 ModuleParametersSection:
253 ModuleParametersKeyword ModuleParameters
258 | ModuleParameters ModuleParameter optSemiColon
262 ParameterName ParamOpType ParameterValue
267 | '*' '.' ParameterNameSegment
270 ParameterNameSegment:
271 ParameterNameSegment '.' Identifier { Free($3); }
272 | ParameterNameSegment IndexItemIndex
273 | Identifier { Free($1); }
278 | ParameterExpression LengthMatch
279 | ParameterExpression IfpresentKeyword
280 | ParameterExpression LengthMatch IfpresentKeyword
284 LengthKeyword '(' LengthBound ')'
285 | LengthKeyword '(' LengthBound DotDot LengthBound ')'
286 | LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
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
310 SimpleParameterValue:
311 MPNumber { BN_free($1); }
319 | MPCstring { Free($1); }
320 | UniversalCharstringValue
329 | PatternKeyword PatternChunk
339 MPCstring { Free($1); }
344 '(' '-' InfinityKeyword DotDot MPNumber ')' { BN_free($5); }
345 | '(' MPNumber DotDot MPNumber ')' { BN_free($2); BN_free($4); }
346 | '(' MPNumber DotDot InfinityKeyword ')' { BN_free($2); }
350 '(' '-' InfinityKeyword DotDot MPFloat ')'
351 | '(' MPFloat DotDot MPFloat ')'
352 | '(' MPFloat DotDot InfinityKeyword ')'
356 '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
360 | '(' IntegerValue ')' { $$ = $2; }
361 | '+' IntegerValue %prec UnarySign { $$ = $2; }
362 | '-' IntegerValue %prec UnarySign
364 BN_set_negative($2, !BN_is_negative($2));
367 | IntegerValue '+' IntegerValue
374 | IntegerValue '-' IntegerValue
381 | IntegerValue '*' IntegerValue
384 BN_CTX *ctx = BN_CTX_new();
386 BN_mul($$, $1, $3, ctx);
391 | IntegerValue '/' IntegerValue
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.");
400 BN_CTX *ctx = BN_CTX_new();
402 BN_div($$, NULL, $1, $3, ctx);
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
422 config_read_error("Floating point division by zero.");
429 ObjIdKeyword '{' ObjIdComponentList '}'
434 | ObjIdComponentList ObjIdComponent
443 MPNumber { BN_free($1); }
447 Identifier '(' MPNumber ')' { Free($1); BN_free($3); }
462 UniversalCharstringValue:
466 UniversalCharstringFragment:
467 MPCstring { Free($1); }
472 CharKeyword '(' ParameterExpression ',' ParameterExpression ','
473 ParameterExpression ',' ParameterExpression ')'
478 | StringValue '&' Cstring {
479 $$ = mputstr($1, $3);
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 ')'
495 ParameterValueOrNotUsedSymbol:
502 | TemplateItemList ',' ParameterValue
507 | FieldValueList ',' FieldValue
511 FieldName AssignmentChar ParameterValueOrNotUsedSymbol
515 Identifier { Free($1); }
516 | ASN1LowerIdentifier
521 | ArrayItemList ',' ArrayItem
525 ParameterValueOrNotUsedSymbol
526 | PermutationKeyword '(' TemplateItemList ')'
531 | IndexItemList ',' IndexItem
535 IndexItemIndex AssignmentChar ParameterValue
539 '[' ParameterExpression ']'
542 /******************* [LOGGING] section *******************/
545 LoggingKeyword LoggingParamList
550 | LoggingParamList LoggingParamLines optSemiColon
555 | ComponentId '.' LoggingParam
556 | ComponentId '.' LoggerPluginId '.' LoggingParam
557 | LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
558 | ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
563 | Identifier { Free($1); }
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); }
588 | LoggerPluginList ',' LoggerPlugin
592 Identifier { Free($1); }
593 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
600 | Re_try '(' Number ')' { BN_free($3); }
605 StringValue { $$ = $1; }
608 //optTestComponentIdentifier:
610 /* | Identifier '.' { Free($1); }
617 LoggingBitorCollection
618 | LoggingBitMask ListOp LoggingBitorCollection
626 LoggingBitorCollection:
628 | LoggingBitCollection
652 /*********************** [PROFILER] ********************************/
655 ProfilerKeyword ProfilerSettings
660 | ProfilerSettings ProfilerSetting optSemiColon
664 DisableProfilerSetting
665 | DisableCoverageSetting
666 | DatabaseFileSetting
667 | AggregateDataSetting
668 | StatisticsFileSetting
669 | DisableStatisticsSetting
670 | StatisticsFilterSetting
671 | StartAutomaticallySetting
672 | NetLineTimesSetting
673 | NetFunctionTimesSetting
676 DisableProfilerSetting:
677 DisableProfilerKeyword AssignmentChar BooleanValue
680 DisableCoverageSetting:
681 DisableCoverageKeyword AssignmentChar BooleanValue
685 DatabaseFileKeyword AssignmentChar StringValue { Free($3); }
688 AggregateDataSetting:
689 AggregateDataKeyword AssignmentChar BooleanValue
692 StatisticsFileSetting:
693 StatisticsFileKeyword AssignmentChar StringValue { Free($3); }
696 DisableStatisticsSetting:
697 DisableStatisticsKeyword AssignmentChar BooleanValue
700 StatisticsFilterSetting:
701 StatisticsFilterKeyword AssignmentChar ProfilerStatsFlags
702 | StatisticsFilterKeyword ConcatChar ProfilerStatsFlags
707 | ProfilerStatsFlag '&' ProfilerStatsFlags
708 | ProfilerStatsFlag '|' ProfilerStatsFlags
711 StartAutomaticallySetting:
712 StartAutomaticallyKeyword AssignmentChar BooleanValue
716 NetLineTimesKeyword AssignmentChar BooleanValue
719 NetFunctionTimesSetting:
720 NetFunctionTimesKeyword AssignmentChar BooleanValue
723 /******************* [TESTPORT_PARAMETERS] section *******************/
725 TestportParametersSection:
726 TestportParametersKeyword TestportParameterList
729 TestportParameterList:
731 | TestportParameterList TestportParameter optSemiColon
735 ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
736 TestportParameterValue
740 Identifier { Free($1); }
741 | Number { BN_free($1); }
745 | Cstring { Free($1); }
749 Identifier { Free($1); }
750 | Identifier ArrayRef { Free($1); }
755 '[' IntegerValue ']' { BN_free($2); }
756 | ArrayRef '[' IntegerValue ']' { BN_free($3); }
759 TestportParameterName:
760 Identifier { Free($1); }
763 TestportParameterValue:
764 StringValue { Free($1); }
767 /******************* [EXECUTE] section *******************/
770 ExecuteKeyword ExecuteList
775 | ExecuteList ExecuteItem optSemiColon
785 $$.testcase_name = NULL;
787 | Identifier '.' ControlKeyword
790 $$.testcase_name = NULL;
792 | Identifier '.' Identifier
795 $$.testcase_name = $3;
800 $$.testcase_name = mcopystr("*");
804 /******************* [EXTERNAL_COMMANDS] section *******************/
806 ExternalCommandsSection:
807 ExternalCommandsKeyword ExternalCommandList
812 | ExternalCommandList ExternalCommand optSemiColon
816 BeginControlPart AssignmentChar Command
817 | EndControlPart AssignmentChar Command
818 | BeginTestCase AssignmentChar Command
819 | EndTestCase AssignmentChar Command
823 StringValue { Free($1); }
826 /******************* [GROUPS] section *******************/
829 GroupsKeyword GroupList
834 | GroupList Group optSemiColon
838 GroupName AssignmentChar GroupMembers
846 Identifier { group_name = $1; }
852 if (group_name != NULL) cfg->add_host(group_name, NULL);
860 if (group_name != NULL && $1 != NULL)
861 cfg->add_host(group_name, $1);
864 | seqGroupMember ',' HostName
866 if (group_name != NULL && $3 != NULL)
867 cfg->add_host(group_name, $3);
878 size_t string_len = strlen($$);
879 for (size_t i = 0; i < string_len; i++) $$[i] = tolower($$[i]);
884 /******************* [COMPONENTS] section *******************/
887 ComponentsKeyword ComponentList
892 | ComponentList ComponentItem optSemiColon
896 ComponentName AssignmentChar ComponentLocation
898 if ($3 != NULL) cfg->add_component($3, $1);
905 Identifier { $$ = $1; }
910 Identifier { $$ = $1; }
911 | DNSName { $$ = $1; }
914 /******************* [MAIN_CONTROLLER] section *******************/
916 MainControllerSection:
917 MainControllerKeyword MCParameterList
922 | MCParameterList MCParameter optSemiColon
926 LocalAddress AssignmentChar HostName
928 check_duplicate_option("LocalAddress", &local_addr_set);
929 Free(cfg->local_addr);
930 cfg->local_addr = $3;
932 | TCPPort AssignmentChar IntegerValue
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.",
944 else cfg->tcp_listen_port = (unsigned short)BN_get_word($3);
948 OPENSSL_free(int_val_str);
950 | KillTimer AssignmentChar KillTimerValue
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);
957 | NumHCs AssignmentChar IntegerValue
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);
968 // Check if we really need to free this!
970 OPENSSL_free(int_val_str);
972 | UnixSocketEnabled AssignmentChar YesToken
974 cfg->unix_sockets_enabled = true;
976 | UnixSocketEnabled AssignmentChar NoToken
978 cfg->unix_sockets_enabled = false;
980 | UnixSocketEnabled AssignmentChar HostName
982 config_read_error("Only 'yes' or 'no' is accepted instead of '%s'", $3);
987 FloatValue { $$ = $1; }
990 double tmp = (double)BN_get_word($1);
991 if (BN_is_negative($1)) tmp *= -1;
997 /******************* [INCLUDE] section *******************/
1000 IncludeKeyword IncludeFiles
1005 | IncludeFiles IncludeFile
1009 Cstring { Free($1); }
1012 /******************* [DEFINE] section *******************/
1018 /********************************************************/
1033 int process_config_read_file(const char *file_name, config_data *pcfg)
1036 local_addr_set = FALSE;
1037 tcp_listen_port_set = FALSE;
1038 kill_timer_set = FALSE;
1039 num_hcs_set = FALSE;
1042 string_chain_t *filenames=NULL;
1045 /* Initializing parameters to default values */
1048 if(preproc_parse_file(file_name, &filenames, &config_defines))
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));
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;
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. */
1075 config_read_close();
1077 string_map_free(config_defines);
1078 config_defines=NULL;
1080 return error_flag ? -1 : 0;
1083 static void check_duplicate_option(const char *option_name,
1084 boolean *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;
1094 void yyprint(FILE *file, int type, const YYSTYPE& value)
1100 fprintf(file, "'%s'", value.str_val);
1104 char *string_repr = BN_bn2dec(value.int_val);
1105 fprintf(file, "%s", string_repr);
1106 OPENSSL_free(string_repr);