From e70852d10be037eb9bc47dc556476bcdc2dee2f9 Mon Sep 17 00:00:00 2001 From: MassimilianoPinto Date: Fri, 7 Jul 2017 17:57:02 +0200 Subject: [PATCH] Code cleanup in ReplaceRule::create_from() Code cleanup in ReplaceRule::create_from() --- server/modules/filter/masking/maskingrules.cc | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/server/modules/filter/masking/maskingrules.cc b/server/modules/filter/masking/maskingrules.cc index ba039f8af..4ae50942b 100644 --- a/server/modules/filter/masking/maskingrules.cc +++ b/server/modules/filter/masking/maskingrules.cc @@ -653,33 +653,30 @@ auto_ptr MaskingRules::ReplaceRule::create_from(json_t* pRul if (pReplace && pWith) { bool ok = true; + const char *err = NULL; + // Check replace if (!json_is_object(pReplace)) { - MXS_ERROR("A masking rule contains a '%s' key, but the value is not an object.", - KEY_REPLACE); - ok = false; + err = KEY_REPLACE; } - + // Check with if (!json_is_object(pWith)) { - MXS_ERROR("A masking rule contains a '%s' key, but the value is not an object.", - KEY_WITH); - ok = false; + err = KEY_WITH; + } + if (err) + { + MXS_ERROR("A masking rule contains a '%s' key, " + "but the value is not an object.", + err); + return sRule; } - if (pApplies_to && !json_is_array(pApplies_to)) + // Check for pApplies_to and pExempted + if (!validate_user_rules(pApplies_to, pExempted)) { - MXS_ERROR("A masking rule contains a '%s' key, but the value is not an array.", - KEY_APPLIES_TO); - ok = false; - } - - if (pExempted && !json_is_array(pExempted)) - { - MXS_ERROR("A masking rule contains a '%s' key, but the value is not an array.", - KEY_EXEMPTED); - ok = false; + return sRule; } if (ok)