This patch ensures that giving boolean value to numeric attribute
types must be accepted.
---
src/smf/smfd/imm_modify_config/attribute.cc | 20 ++++++++++++++------
src/smf/smfd/imm_modify_demo/test_ccbhdl.cc | 12 +++++++++++-
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/src/smf/smfd/imm_modify_config/attribute.cc
b/src/smf/smfd/imm_modify_config/attribute.cc
index d31524f67..bf25ee0e9 100644
--- a/src/smf/smfd/imm_modify_config/attribute.cc
+++ b/src/smf/smfd/imm_modify_config/attribute.cc
@@ -49,15 +49,23 @@ template<typename T>
static bool StringToNumericValue(const std::string& str_value,
T& num_value, const SaImmValueTypeT imm_type) {
bool rc = true;
+ std::string input_str{str_value};
+
+ // User can input true/false to numeric attribute types.
+ // Have this convertion to ensure no failure at `string to numeric` step.
+ // Note: only accept `true`/`false` (C/C++), no accept other forms.
+ // E.g. True, TRUE, SA_TRUE, etc.
+ if (str_value == "true") input_str = "1";
+ if (str_value == "false") input_str = "0";
try {
switch (imm_type) {
case SA_IMM_ATTR_SAINT32T: {
- num_value = std::stoi(str_value);
+ num_value = std::stoi(input_str);
break;
}
case SA_IMM_ATTR_SAUINT32T: {
- auto tmp_value = std::stoul(str_value);
+ auto tmp_value = std::stoul(input_str);
if (tmp_value > UINT_MAX) {
throw std::out_of_range("Value > UINT_MAX");
} else {
@@ -67,19 +75,19 @@ static bool StringToNumericValue(const std::string&
str_value,
}
case SA_IMM_ATTR_SAINT64T:
case SA_IMM_ATTR_SATIMET: {
- num_value = std::stoll(str_value);
+ num_value = std::stoll(input_str);
break;
}
case SA_IMM_ATTR_SAUINT64T: {
- num_value = std::stoull(str_value);
+ num_value = std::stoull(input_str);
break;
}
case SA_IMM_ATTR_SAFLOATT: {
- num_value = std::stof(str_value);
+ num_value = std::stof(input_str);
break;
}
case SA_IMM_ATTR_SADOUBLET: {
- num_value = std::stod(str_value);
+ num_value = std::stod(input_str);
break;
}
default: {
diff --git a/src/smf/smfd/imm_modify_demo/test_ccbhdl.cc
b/src/smf/smfd/imm_modify_demo/test_ccbhdl.cc
index 727953edd..4b32267ed 100644
--- a/src/smf/smfd/imm_modify_demo/test_ccbhdl.cc
+++ b/src/smf/smfd/imm_modify_demo/test_ccbhdl.cc
@@ -92,6 +92,16 @@ void CreateOneObject(void) {
// Add the attribute to the object
imm_object.AddAttribute(attribute);
+ // SA_INT64_T multi-value attribute.
+ // Make sure boolean values are also accepted.
+ attribute.attribute_name = "SaInt64TValues";
+ attribute.value_type = SA_IMM_ATTR_SAINT64T;
+ attribute.values_as_strings.clear();
+ attribute.AddValue("true");
+ attribute.AddValue("false");
+ // Add the attribute to the object
+ imm_object.AddAttribute(attribute);
+
// SA_NAME_T multi-value attribute
SaNameT a_name;
attribute.attribute_name = "SaNameTValues";
@@ -230,7 +240,7 @@ int main() {
// Prepare/enable extended name
// ----------------------------
setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1);
-
+
if (EnableImmLongDn() == false) return -1;
// Note: Long DN must be configured in IMM configuration object before
--
2.18.0
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel