Browse Source

HPCC-18618 Change DFUDefFileRequest.Format to ESPenum

The existing DFUDefFileRequest.Format is defined as a string
although only 'xml' and 'def' are allowed. The DFUDefFile
returns a "Failed to parse XSLT source" error if an invalid
string is set as the Format. In this fix, the Format is changed
from string to ESPenum.

Signed-off-by: wangkx <kevin.wang@lexisnexis.com>
wangkx 7 years ago
parent
commit
7c0e27eefd
2 changed files with 17 additions and 7 deletions
  1. 7 1
      esp/scm/ws_dfu.ecm
  2. 10 6
      esp/services/ws_dfu/ws_dfuService.cpp

+ 7 - 1
esp/scm/ws_dfu.ecm

@@ -24,6 +24,12 @@ ESPenum DFUArrayActions : string
     AddToSuperfile("Add To Superfile"),
 };
 
+ESPenum DFUDefFileFormat : string
+{
+    xml("xml"),
+    def("def"),
+};
+
 ESPStruct SpaceItem
 {
     string Name;
@@ -310,7 +316,7 @@ ESPrequest []
 DFUDefFileRequest
 {
     string Name;
-    string Format;
+    ESPenum DFUDefFileFormat Format;
 };
 
 ESPresponse

+ 10 - 6
esp/services/ws_dfu/ws_dfuService.cpp

@@ -1497,6 +1497,10 @@ bool CWsDfuEx::onDFUDefFile(IEspContext &context,IEspDFUDefFileRequest &req, IEs
         if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Read, false))
             throw MakeStringException(ECLWATCH_DFU_ACCESS_DENIED, "Failed to access DFUDefFile. Permission denied.");
 
+        CDFUDefFileFormat format = req.getFormat();
+        if (format == DFUDefFileFormat_Undefined)
+            throw MakeStringException(ECLWATCH_INVALID_INPUT,"Invalid format");
+
         const char* fileName = req.getName();
         if (!fileName || !*fileName)
             throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
@@ -1516,7 +1520,7 @@ bool CWsDfuEx::onDFUDefFile(IEspContext &context,IEspDFUDefFileRequest &req, IEs
 
         getDefFile(userdesc.get(), req.getName(),rawStr);
         StringBuffer xsltFile;
-        xsltFile.append(getCFD()).append("smc_xslt/").append(req.getFormat()).append("_def_file.xslt");
+        xsltFile.append(getCFD()).append("smc_xslt/").append(req.getFormatAsString()).append("_def_file.xslt");
         xsltTransformer(xsltFile.str(),rawStr,returnStr);
 
         //set the file
@@ -1525,12 +1529,12 @@ bool CWsDfuEx::onDFUDefFile(IEspContext &context,IEspDFUDefFileRequest &req, IEs
         resp.setDefFile(buff);
 
         //set the type
-        StringBuffer type;
-        const char* format = req.getFormat();
-        if (!stricmp(format, "def"))
-            format = "plain";
+        StringBuffer type = "text/";
+        if (format == CDFUDefFileFormat_xml)
+            type.append("xml");
+        else
+            type.append("plain");
 
-        type.append("text/").append(format);
         resp.setDefFile_mimetype(type.str());
     }
     catch(IException* e)