Commit 841b1952 authored by Maria Fava's avatar Maria Fava
Browse files

first additions in filepath check

parent dc710657
......@@ -3,6 +3,7 @@
<commandServiceName value="ADDH/Command"></commandServiceName>
<stateServiceName value="ADDH/State"></stateServiceName>
<serverName value="ADDH"></serverName>
<outputDirPrefix value="ADDH/Prefix"></outputDirPrefix>
<header version="0">
<data destination="BCT372" destinationPrefix="" fromService="F16.BCT372" fromName="totalIntensityPreferred" />
......
......@@ -10,6 +10,8 @@
#include "ADDHWriter.h"
#include "Config.h"
#include <cstdlib>
/*! \namespace ntof
*
* namespace used for all the element of the nTOF
......@@ -53,16 +55,26 @@ void ADDHCmd::commandReceived(ntof::dim::DIMCmd &cmdData)
command.timingEvent = timingEvent;
command.filePath = filePath;
// Check if the command can be accepted
LOG(INFO) << "Command " << textValue << " received.";
if (textValue != "write" && textValue != "reset" && textValue != "clear")
std::string filePathPrefix = Config::instance().getvalue("outputDirPrefix", "ADDH/Prefix");
// Check if filePath is subpath of filePathPrefix
if(isValidPath(filePath, filePathPrefix))
{
setError(cmdData.getKey(), CMD_UNKNOWN, "Command unknown.");
// Check if the command can be accepted
LOG(INFO) << "Command " << textValue << " received.";
if (textValue != "write" && textValue != "reset" && textValue != "clear")
{
setError(cmdData.getKey(), CMD_UNKNOWN, "Command unknown.");
}
else
{
ADDHWriter::instance().addCommand(command);
setOk(cmdData.getKey(), std::string("Done!"));
}
}
else
{
ADDHWriter::instance().addCommand(command);
setOk(cmdData.getKey(), std::string("Done!"));
// setError();
}
}
else
......@@ -71,5 +83,22 @@ void ADDHCmd::commandReceived(ntof::dim::DIMCmd &cmdData)
setError(cmdData.getKey(), CMD_EMPTY, "Parent node is empty");
}
}
bool ADDHCmd::isValidPath(std::string filePath, std::string filePathPrefix)
{
if(filePath[0] != "/")
{
// filePath is relative, convert to absolute
char* absoluteFilePath = realpath(filePath, NULL);
filePath = absoluteFilePath;
free(absoluteFilePath);
}
if(filePath.find(filePathPrefix) != std::string:npos)
{
return true;
}
return false;
}
} // namespace addh
} // namespace ntof
......@@ -33,6 +33,8 @@ namespace addh {
*/
class ADDHCmd : public ntof::dim::DIMSuperCommand
{
private:
bool isValidPath(std::string filePath, std::stringFilePathPrefix);
public:
/*!
* \brief Constructor of the class ADDHCmd
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment