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)
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
134 %token <float_val> Float
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> DNSName "a host name"
146 %token LoggingBitCollection
147 %token <ts_val> TimestampValue "Time, Datetime or Seconds"
148 %token SourceInfoValue "None, Single or Stack"
149 %token YesNo "Yes or No" /* from LOGGING section */
154 %token UnixSocketEnabled
155 %token YesToken "yes" /* from MAIN_CONTROLLER section */
162 %token DiskFullAction
165 %token Re_try /* Retry clashes with an enum in Qt */
168 %token DisableProfilerKeyword "DisableProfiler"
169 %token DisableCoverageKeyword "DisableCoverage"
170 %token DatabaseFileKeyword "DatabaseFile"
171 %token AggregateDataKeyword "AggregateData"
172 %token StatisticsFileKeyword "StatisticsFile"
173 %token DisableStatisticsKeyword "DisableStatistics"
175 %type <int_val> IntegerValue
176 %type <float_val> FloatValue KillTimerValue
177 %type <str_val> HostName StringValue LogFileName
178 %type <str_val> ComponentName
179 %type <str_val> ComponentLocation
180 %type <execute_item_val> ExecuteItem
182 %destructor { Free($$); }
193 Free($$.module_name);
194 Free($$.testcase_name);
198 %destructor { BN_free($$); }
209 Source of conflicts (2 S/R):
211 1.) 2 conflicts in two distinct states
212 When seeing a '*' token after an integer or float value in section
213 [MODULE_PARAMETERS] parser cannot decide whether the token is a multiplication
214 operator (shift) or it refers to all modules in the next module parameter
217 The built-in Bison behavior always chooses the shift over the reduce
218 (the * is interpreted as multiplication).
229 ModuleParametersSection
232 | TestportParametersSection
234 | ExternalCommandsSection
237 | MainControllerSection
242 /******************* [MODULE_PARAMETERS] section *******************/
244 ModuleParametersSection:
245 ModuleParametersKeyword ModuleParameters
250 | ModuleParameters ModuleParameter optSemiColon
254 ParameterName ParamOpType ParameterValue
259 | '*' '.' ParameterNameSegment
262 ParameterNameSegment:
263 ParameterNameSegment '.' Identifier { Free($3); }
264 | ParameterNameSegment '[' Number ']' { BN_free($3); }
265 | Identifier { Free($1); }
270 | SimpleParameterValue LengthMatch
271 | SimpleParameterValue IfpresentKeyword
272 | SimpleParameterValue LengthMatch IfpresentKeyword
276 LengthKeyword '(' LengthBound ')'
277 | LengthKeyword '(' LengthBound DotDot LengthBound ')'
278 | LengthKeyword '(' LengthBound DotDot InfinityKeyword ')'
282 IntegerValue { BN_free($1); }
285 SimpleParameterValue:
286 IntegerValue { BN_free($1); }
294 | Cstring { Free($1); }
295 | UniversalCharstringValue
305 | PatternKeyword PatternChunkList
316 | PatternChunkList '&' PatternChunk
320 Cstring { Free($1); }
325 '(' '-' InfinityKeyword DotDot IntegerValue ')' { BN_free($5); }
326 | '(' IntegerValue DotDot IntegerValue ')' { BN_free($2); BN_free($4); }
327 | '(' IntegerValue DotDot InfinityKeyword ')' { BN_free($2); }
331 '(' '-' InfinityKeyword DotDot FloatValue ')'
332 | '(' FloatValue DotDot FloatValue ')'
333 | '(' FloatValue DotDot InfinityKeyword ')'
337 '(' UniversalCharstringFragment DotDot UniversalCharstringFragment ')'
341 | '(' IntegerValue ')' { $$ = $2; }
342 | '+' IntegerValue %prec UnarySign { $$ = $2; }
343 | '-' IntegerValue %prec UnarySign
345 BN_set_negative($2, !BN_is_negative($2));
348 | IntegerValue '+' IntegerValue
355 | IntegerValue '-' IntegerValue
362 | IntegerValue '*' IntegerValue
365 BN_CTX *ctx = BN_CTX_new();
367 BN_mul($$, $1, $3, ctx);
372 | IntegerValue '/' IntegerValue
375 BIGNUM *BN_0 = BN_new();
376 BN_set_word(BN_0, 0);
377 if (BN_cmp($3, BN_0) == 0) {
378 config_read_error("Integer division by zero.");
381 BN_CTX *ctx = BN_CTX_new();
383 BN_div($$, NULL, $1, $3, ctx);
394 | '(' FloatValue ')' { $$ = $2; }
395 | '+' FloatValue %prec UnarySign { $$ = $2; }
396 | '-' FloatValue %prec UnarySign { $$ = -$2; }
397 | FloatValue '+' FloatValue { $$ = $1 + $3; }
398 | FloatValue '-' FloatValue { $$ = $1 - $3; }
399 | FloatValue '*' FloatValue { $$ = $1 * $3; }
400 | FloatValue '/' FloatValue
403 config_read_error("Floating point division by zero.");
410 ObjIdKeyword '{' ObjIdComponentList '}'
415 | ObjIdComponentList ObjIdComponent
424 Number { BN_free($1); }
428 Identifier '(' Number ')' { Free($1); BN_free($3); }
433 | BitstringValue ConcatOp Bstring
438 | HexstringValue ConcatOp Hstring
443 | OctetstringValue ConcatOp Ostring
446 UniversalCharstringValue:
447 Cstring seqUniversalCharstringFragment { Free($1); }
449 | Quadruple seqUniversalCharstringFragment
452 seqUniversalCharstringFragment:
453 ConcatOp UniversalCharstringFragment
454 | seqUniversalCharstringFragment ConcatOp UniversalCharstringFragment
457 UniversalCharstringFragment:
458 Cstring { Free($1); }
463 CharKeyword '(' IntegerValue ',' IntegerValue ',' IntegerValue ','
466 char *int_val_str_1 = BN_bn2dec($3);
467 char *int_val_str_2 = BN_bn2dec($5);
468 char *int_val_str_3 = BN_bn2dec($7);
469 char *int_val_str_4 = BN_bn2dec($9);
470 BIGNUM *BN_0 = BN_new();
471 BN_set_word(BN_0, 0);
472 BIGNUM *BN_127 = BN_new();
473 BN_set_word(BN_127, 127);
474 BIGNUM *BN_255 = BN_new();
475 BN_set_word(BN_255, 255);
476 if (BN_cmp($3, BN_0) < 0 || BN_cmp($3, BN_127) > 0)
477 config_read_error("An integer value within range 0 .. 127 was expected "
478 "as first number of quadruple (group) instead of "
479 "%s.", int_val_str_1);
480 if (BN_cmp($5, BN_0) < 0 || BN_cmp($5, BN_255) > 0)
481 config_read_error("An integer value within range 0 .. 255 was expected "
482 "as second number of quadruple (plane) instead of %s.",
484 if (BN_cmp($7, BN_0) < 0 || BN_cmp($7, BN_255) > 0)
485 config_read_error("An integer value within range 0 .. 255 was expected "
486 "as third number of quadruple (row) instead of %s.",
488 if (BN_cmp($9, BN_0) < 0 || BN_cmp($9, BN_255) > 0)
489 config_read_error("An integer value within range 0 .. 255 was expected "
490 "as fourth number of quadruple (cell) instead of %d.",
499 OPENSSL_free(int_val_str_1);
500 OPENSSL_free(int_val_str_2);
501 OPENSSL_free(int_val_str_3);
502 OPENSSL_free(int_val_str_4);
512 | StringValue ConcatOp Cstring {
513 $$ = mputstr($1, $3);
519 Identifier { Free($1); }
520 | ASN1LowerIdentifier
525 | '{' FieldValueList '}'
526 | '{' ArrayItemList '}'
527 | '{' IndexItemList '}'
528 | '(' ParameterValue ',' TemplateItemList ')' /* at least 2 elements to avoid shift/reduce conflicts with IntegerValue and FloatValue rules */
529 | ComplementKeyword '(' TemplateItemList ')'
530 | SupersetKeyword '(' TemplateItemList ')'
531 | SubsetKeyword '(' TemplateItemList ')'
534 ParameterValueOrNotUsedSymbol:
541 | TemplateItemList ',' ParameterValue
546 | FieldValueList ',' FieldValue
550 FieldName AssignmentChar ParameterValueOrNotUsedSymbol
554 Identifier { Free($1); }
555 | ASN1LowerIdentifier
560 | ArrayItemList ',' ArrayItem
564 ParameterValueOrNotUsedSymbol
565 | PermutationKeyword '(' TemplateItemList ')'
570 | IndexItemList ',' IndexItem
574 IndexItemIndex AssignmentChar ParameterValue
578 '[' IntegerValue ']' { BN_free($2); }
581 /******************* [LOGGING] section *******************/
584 LoggingKeyword LoggingParamList
589 | LoggingParamList LoggingParamLines optSemiColon
594 | ComponentId '.' LoggingParam
595 | ComponentId '.' LoggerPluginId '.' LoggingParam
596 | LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
597 | ComponentId '.' LoggerPlugins AssignmentChar '{' LoggerPluginList '}'
602 | Identifier { Free($1); }
606 FileMask AssignmentChar LoggingBitMask
607 | ConsoleMask AssignmentChar LoggingBitMask
608 | LogFileSize AssignmentChar Number { BN_free($3); }
609 | EmergencyLogging AssignmentChar Number { BN_free($3); }
610 | EmergencyLoggingBehaviour AssignmentChar EmergencyLoggingBehaviourValue
611 | EmergencyLoggingMask AssignmentChar LoggingBitMask
612 | LogFileNumber AssignmentChar Number { BN_free($3); }
613 | DiskFullAction AssignmentChar DiskFullActionValue
614 | LogFile AssignmentChar LogFileName { cfg->set_log_file($3); }
615 | TimestampFormat AssignmentChar TimestampValue
616 | ConsoleTimestampFormat AssignmentChar TimestampValue {cfg->tsformat=$3;}
617 | SourceInfoFormat AssignmentChar SourceInfoSetting
618 | AppendFile AssignmentChar YesNoOrBoolean
619 | LogEventTypes AssignmentChar LogEventTypesValue
620 | LogEntityName AssignmentChar YesNoOrBoolean
621 | MatchingHints AssignmentChar MatchVerbosityValue
622 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
627 | LoggerPluginList ',' LoggerPlugin
631 Identifier { Free($1); }
632 | Identifier AssignmentChar StringValue { Free($1); Free($3); }
639 | Re_try '(' Number ')' { BN_free($3); }
644 StringValue { $$ = $1; }
647 //optTestComponentIdentifier:
649 /* | Identifier '.' { Free($1); }
656 LoggingBitorCollection
657 | LoggingBitMask ListOp LoggingBitorCollection
665 LoggingBitorCollection:
667 | LoggingBitCollection
691 /*********************** [PROFILER] ********************************/
694 ProfilerKeyword ProfilerSettings
699 | ProfilerSettings ProfilerSetting optSemiColon
703 DisableProfilerSetting
704 | DisableCoverageSetting
705 | DatabaseFileSetting
706 | AggregateDataSetting
707 | StatisticsFileSetting
708 | DisableStatisticsSetting
711 DisableProfilerSetting:
712 DisableProfilerKeyword AssignmentChar BooleanValue
715 DisableCoverageSetting:
716 DisableCoverageKeyword AssignmentChar BooleanValue
720 DatabaseFileKeyword AssignmentChar StringValue { Free($3); }
723 AggregateDataSetting:
724 AggregateDataKeyword AssignmentChar BooleanValue
727 StatisticsFileSetting:
728 StatisticsFileKeyword AssignmentChar StringValue { Free($3); }
731 DisableStatisticsSetting:
732 DisableStatisticsKeyword AssignmentChar BooleanValue
735 /******************* [TESTPORT_PARAMETERS] section *******************/
737 TestportParametersSection:
738 TestportParametersKeyword TestportParameterList
741 TestportParameterList:
743 | TestportParameterList TestportParameter optSemiColon
747 ComponentId '.' TestportName '.' TestportParameterName AssignmentChar
748 TestportParameterValue
752 Identifier { Free($1); }
753 | Number { BN_free($1); }
757 | Cstring { Free($1); }
761 Identifier { Free($1); }
762 | Identifier ArrayRef { Free($1); }
767 '[' IntegerValue ']' { BN_free($2); }
768 | ArrayRef '[' IntegerValue ']' { BN_free($3); }
771 TestportParameterName:
772 Identifier { Free($1); }
775 TestportParameterValue:
776 StringValue { Free($1); }
779 /******************* [EXECUTE] section *******************/
782 ExecuteKeyword ExecuteList
787 | ExecuteList ExecuteItem optSemiColon
797 $$.testcase_name = NULL;
799 | Identifier '.' ControlKeyword
802 $$.testcase_name = NULL;
804 | Identifier '.' Identifier
807 $$.testcase_name = $3;
812 $$.testcase_name = mcopystr("*");
816 /******************* [EXTERNAL_COMMANDS] section *******************/
818 ExternalCommandsSection:
819 ExternalCommandsKeyword ExternalCommandList
824 | ExternalCommandList ExternalCommand optSemiColon
828 BeginControlPart AssignmentChar Command
829 | EndControlPart AssignmentChar Command
830 | BeginTestCase AssignmentChar Command
831 | EndTestCase AssignmentChar Command
835 StringValue { Free($1); }
838 /******************* [GROUPS] section *******************/
841 GroupsKeyword GroupList
846 | GroupList Group optSemiColon
850 GroupName AssignmentChar GroupMembers
858 Identifier { group_name = $1; }
864 if (group_name != NULL) cfg->add_host(group_name, NULL);
872 if (group_name != NULL && $1 != NULL)
873 cfg->add_host(group_name, $1);
876 | seqGroupMember ',' HostName
878 if (group_name != NULL && $3 != NULL)
879 cfg->add_host(group_name, $3);
890 size_t string_len = strlen($$);
891 for (size_t i = 0; i < string_len; i++) $$[i] = tolower($$[i]);
896 /******************* [COMPONENTS] section *******************/
899 ComponentsKeyword ComponentList
904 | ComponentList ComponentItem optSemiColon
908 ComponentName AssignmentChar ComponentLocation
910 if ($3 != NULL) cfg->add_component($3, $1);
917 Identifier { $$ = $1; }
922 Identifier { $$ = $1; }
923 | DNSName { $$ = $1; }
926 /******************* [MAIN_CONTROLLER] section *******************/
928 MainControllerSection:
929 MainControllerKeyword MCParameterList
934 | MCParameterList MCParameter optSemiColon
938 LocalAddress AssignmentChar HostName
940 check_duplicate_option("LocalAddress", &local_addr_set);
941 Free(cfg->local_addr);
942 cfg->local_addr = $3;
944 | TCPPort AssignmentChar IntegerValue
946 check_duplicate_option("TCPPort", &tcp_listen_port_set);
947 BIGNUM *BN_0 = BN_new();
948 BN_set_word(BN_0, 0);
949 BIGNUM *BN_65535 = BN_new();
950 BN_set_word(BN_65535, 65535);
951 char *int_val_str = BN_bn2dec($3);
952 if (BN_cmp($3, BN_0) < 0 || BN_cmp($3, BN_65535) > 0)
953 config_read_error("An integer value within range 0 .. 65535 was "
954 "expected for parameter TCPPort instead of %s.",
956 else cfg->tcp_listen_port = (unsigned short)BN_get_word($3);
960 OPENSSL_free(int_val_str);
962 | KillTimer AssignmentChar KillTimerValue
964 check_duplicate_option("KillTimer", &kill_timer_set);
965 if ($3 >= 0.0) cfg->kill_timer = $3;
966 else config_read_error("A non-negative numeric value was expected for "
967 "parameter KillTimer instead of %g.", $3);
969 | NumHCs AssignmentChar IntegerValue
971 check_duplicate_option("NumHCs", &num_hcs_set);
972 BIGNUM *BN_0 = BN_new();
973 BN_set_word(BN_0, 0);
974 char *int_val_str = BN_bn2dec($3);
975 if (BN_cmp($3, BN_0) <= 0)
976 config_read_error("A positive integer value was expected for "
977 "parameter NumHCs instead of %s.", int_val_str);
978 else cfg->num_hcs = (int)BN_get_word($3);
980 // Check if we really need to free this!
982 OPENSSL_free(int_val_str);
984 | UnixSocketEnabled AssignmentChar YesToken
986 cfg->unix_sockets_enabled = true;
988 | UnixSocketEnabled AssignmentChar NoToken
990 cfg->unix_sockets_enabled = false;
992 | UnixSocketEnabled AssignmentChar HostName
994 config_read_error("Only 'yes' or 'no' is accepted instead of '%s'", $3);
999 FloatValue { $$ = $1; }
1002 double tmp = (double)BN_get_word($1);
1003 if (BN_is_negative($1)) tmp *= -1;
1009 /******************* [INCLUDE] section *******************/
1012 IncludeKeyword IncludeFiles
1017 | IncludeFiles IncludeFile
1021 Cstring { Free($1); }
1024 /******************* [DEFINE] section *******************/
1030 /********************************************************/
1045 int process_config_read_file(const char *file_name, config_data *pcfg)
1048 local_addr_set = FALSE;
1049 tcp_listen_port_set = FALSE;
1050 kill_timer_set = FALSE;
1051 num_hcs_set = FALSE;
1054 string_chain_t *filenames=NULL;
1057 /* Initializing parameters to default values */
1060 if(preproc_parse_file(file_name, &filenames, &config_defines))
1064 char *fn=string_chain_cut(&filenames);
1065 config_read_lineno=1;
1066 /* The lexer can modify config_process_in
1067 * when it's input buffer is changed */
1068 config_read_in = fopen(fn, "r");
1069 if (config_read_in == NULL) {
1070 fprintf(stderr, "Cannot open configuration file: %s (%s)\n",
1071 fn, strerror(errno));
1074 FILE* tmp_cfg = config_read_in;
1075 config_read_restart(config_read_in);
1076 config_read_reset(fn);
1077 if(config_read_parse()) error_flag=TRUE;
1079 /* During parsing flex or libc may use some system calls (e.g. ioctl)
1080 * that fail with an error status. Such error codes shall be ignored in
1081 * future error messages. */
1087 config_read_close();
1089 string_map_free(config_defines);
1090 config_defines=NULL;
1092 return error_flag ? -1 : 0;
1095 static void check_duplicate_option(const char *option_name,
1096 boolean *option_flag)
1099 config_read_warning("Option `%s' was given more than once in section "
1100 "[MAIN_CONTROLLER].", option_name);
1101 } else *option_flag = TRUE;
1106 void yyprint(FILE *file, int type, const YYSTYPE& value)
1112 fprintf(file, "'%s'", value.str_val);
1116 char *string_repr = BN_bn2dec(value.int_val);
1117 fprintf(file, "%s", string_repr);
1118 OPENSSL_free(string_repr);