From 658453c842eca668d6e5ffde6cb692b15b4789c1 Mon Sep 17 00:00:00 2001 From: juanmont Date: Wed, 16 May 2018 16:58:50 +0200 Subject: [PATCH] F #1548: Fixed bug with don't have END_TYPE (#2094) --- include/ScheduledAction.h | 4 ++-- src/vm_template/ScheduledAction.cc | 33 +++++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/ScheduledAction.h b/include/ScheduledAction.h index 0738170a77..1e898f8b23 100644 --- a/include/ScheduledAction.h +++ b/include/ScheduledAction.h @@ -85,9 +85,9 @@ public: * @param eo end type (date, times) * @param error in case of error * - * @return true if days are in range false (error) if not + * @return 0 if days are in range -1 (error) if not or -2 (not defined) */ - bool ends_in_range(EndOn eo, std::string& error); + int ends_in_range(EndOn eo, std::string& error); /** * This function parse and checks the sched action attributes: REPEAT, DAYS diff --git a/src/vm_template/ScheduledAction.cc b/src/vm_template/ScheduledAction.cc index a85f653b83..9a1fd45fdf 100644 --- a/src/vm_template/ScheduledAction.cc +++ b/src/vm_template/ScheduledAction.cc @@ -59,7 +59,7 @@ int SchedAction::endon(EndOn& eo) if ( et_s.empty() ) { - return 0; + return -2; } std::istringstream iss(et_s); @@ -164,7 +164,7 @@ bool SchedAction::days_in_range(Repeat r, std::string& error) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -bool SchedAction::ends_in_range(EndOn eo, std::string& error) +int SchedAction::ends_in_range(EndOn eo, std::string& error) { int end_value; int rc = vector_value("END_VALUE", end_value); @@ -172,13 +172,13 @@ bool SchedAction::ends_in_range(EndOn eo, std::string& error) if ( rc == -1 && eo != NEVER ) { error = "Missing END_VALUE"; - return false; + return -2; } if ( eo == TIMES && end_value <= 0 ) { error = "Error parsing END_VALUE, times has to be greater than 0"; - return false; + return -1; } else if ( eo == DATE ) { @@ -191,11 +191,11 @@ bool SchedAction::ends_in_range(EndOn eo, std::string& error) if (out == -1) { error = "Error parsing END_VALUE, wrong format for date."; - return false; + return -1; } } - return true; + return 0; } /* -------------------------------------------------------------------------- */ @@ -205,6 +205,7 @@ int SchedAction::parse(std::string& error, bool clean) { Repeat r; EndOn eo; + int rc_e, rc_ev; if ( repeat(r) == -1 ) { @@ -212,21 +213,29 @@ int SchedAction::parse(std::string& error, bool clean) return -1; } - if ( endon(eo) == -1 ) + rc_e = endon(eo); + rc_ev = ends_in_range(eo, error); + + if ( rc_e == -1 ) { error = "Error parsing END_TYPE attribute"; return -1; } - + else if ( rc_e == -2 && rc_ev != -2 ) + { + error = "Error END_VALUE defined but not valid END_TYPE found"; + return -1; + } + else if ( rc_e == 0 && rc_ev != 0 ) + { + return -1; + } + if ( !days_in_range(r, error) ) { return -1; } - if ( !ends_in_range(eo, error) ) - { - return -1; - } if (clean) {