Commit 605627ae authored by Axel Auweter's avatar Axel Auweter
Browse files

Fix for ticket #41 - Do not allow forward slash characters in sensor public names.

parent c4473bfd
......@@ -44,6 +44,7 @@ typedef enum {
SC_OK,
SC_INVALIDSESSION,
SC_INVALIDPATTERN,
SC_INVALIDPUBLICNAME,
SC_UNKNOWNSENSOR,
SC_UNKNOWNERROR
} SCError;
......
......@@ -26,6 +26,7 @@ protected:
CassSession* session;
bool validateSensorPattern(const char* sensorPattern);
bool validateSensorPublicName(std::string publicName);
public:
SCError publishSensor(std::string publicName, std::string sensorPattern);
......
......@@ -184,6 +184,14 @@ bool SensorConfigImpl::validateSensorPattern(const char* sensorPattern)
return true;
}
/*
* Validate the public name of a sensor.
* Sensor public names may not contain forward slash characters.
*/
bool SensorConfigImpl::validateSensorPublicName(std::string publicName)
{
return (publicName.find("/") == std::string::npos);
}
/*
* SensorConfigImpl public functions
......@@ -195,6 +203,11 @@ SCError SensorConfigImpl::publishSensor(std::string publicName, std::string sens
return SC_INVALIDPATTERN;
}
/* Check if the publicName is valid */
if (!validateSensorPublicName(publicName.c_str())) {
return SC_INVALIDPUBLICNAME;
}
/* Check if the session is valid */
if (!session) {
return SC_INVALIDSESSION;
......
......@@ -132,8 +132,24 @@ executeCommandError:
*/
void SensorAction::doPublishSensor(const char* publicName, const char* sensorPattern)
{
SCError err;
SensorConfig sensorConfig(connection);
sensorConfig.publishSensor(publicName, sensorPattern);
err = sensorConfig.publishSensor(publicName, sensorPattern);
switch(err) {
case SC_INVALIDPATTERN:
std::cout << "Invalid sensor pattern: " << sensorPattern << std::endl;
break;
case SC_INVALIDPUBLICNAME:
std::cout << "Invalid sensor public name: " << publicName << std::endl;
break;
case SC_INVALIDSESSION:
std::cout << "Invalid dcdb session." << std::endl;
break;
default:
break;
}
}
/*
......
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