Inventory: Implement writing custom IPMI FRU property

Change-Id: I9286045c3c10cd8bed840f03cfcc92a5b236d9ca
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/writefrudata.cpp b/writefrudata.cpp
index 635653f..b36de7e 100644
--- a/writefrudata.cpp
+++ b/writefrudata.cpp
@@ -367,6 +367,7 @@
 
 std::string getFRUValue(const std::string& section,
                         const std::string& key,
+                        const std::string& delimiter,
                         IPMIFruInfo& fruData)
 {
 
@@ -400,6 +401,22 @@
     {
         fruValue = itr->second;
     }
+
+    //if the key is custom property then the value could be in two formats.
+    //1) custom field 2 = "value".
+    //2) custom field 2 =  "key:value".
+    //if delimeter length = 0 i.e custom field 2 = "value"
+
+    constexpr auto customProp = "Custom Field";
+    if (key.find(customProp) != std::string::npos)
+    {
+       if (delimiter.length() > 0)
+       {
+           size_t delimiterpos = fruValue.find(delimiter);
+           if (delimiterpos != std::string::npos)
+               fruValue = fruValue.substr(delimiterpos + 1);
+       }
+    }
     return fruValue;
 
 }
@@ -507,7 +524,7 @@
             PropertyMap props;//store all the properties
             for (auto& properties : interfaceList.second)
             {
-                std::string section, property, value;
+                std::string section, property, delimiter, value;
                 for (auto& info : properties.second)
                 {
                     if (info.first == "IPMIFruSection")
@@ -518,11 +535,26 @@
                     {
                         property = std::move(info.second);
                     }
+                    if (info.first == "IPMIFruValueDelimiter")
+                    {
+                        //Read the delimeter as ascii value
+                        //convert it into char
+                        if( info.second.length() > 0 )
+                        {
+                            char dlm = ' ';
+                            rc = sscanf(info.second.c_str(),"%hhd",&dlm);
+                            if (rc > 0)
+                            {
+                                delimiter = std::string(1,dlm);
+                            }
+                        }
+                    }
+
                 }
 
                 if (!section.empty() && !property.empty())
                 {
-                    value = getFRUValue(section, property, fruData);
+                    value = getFRUValue(section, property, delimiter, fruData);
                 }
                 props.emplace(std::move(properties.first), std::move(value));
             }