clientmessage: add token regex and getter
Signed-off-by: Ralf Ramsauer <ralf@ramses-pyramidenbau.de>
This commit is contained in:
parent
474d941918
commit
62ac4f26e0
|
@ -8,17 +8,31 @@ const std::string Clientmessage::_lockButtonKey = "lockButton";
|
|||
const std::string Clientmessage::_emergencyUnlockKey = "emergencyUnlock";
|
||||
const std::string Clientmessage::_isOpenKey = "isOpen";
|
||||
|
||||
const std::regex Clientmessage::_token_regex(".*/([0-9a-fA-F]+)");
|
||||
|
||||
Clientmessage::Clientmessage(std::string web_address,
|
||||
bool isOpen,
|
||||
Doormessage doormessage) :
|
||||
_web_address(web_address),
|
||||
_token(),
|
||||
_isOpen(isOpen),
|
||||
_doormessage(doormessage)
|
||||
{
|
||||
std::smatch match;
|
||||
if (std::regex_match(_web_address, match, _token_regex)) {
|
||||
if (match.size() == 2) {
|
||||
_token = match[1].str();
|
||||
} else {
|
||||
_token = "ERROR";
|
||||
}
|
||||
} else {
|
||||
_token = "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
Clientmessage::Clientmessage() :
|
||||
_web_address(),
|
||||
_token(),
|
||||
_isOpen(false),
|
||||
_doormessage()
|
||||
{
|
||||
|
@ -32,6 +46,7 @@ Clientmessage &Clientmessage::operator=(const Clientmessage &rhs)
|
|||
}
|
||||
|
||||
this->_web_address = rhs._web_address;
|
||||
this->_token = rhs._token;
|
||||
this->_isOpen = rhs._isOpen;
|
||||
this->_doormessage = rhs._doormessage;
|
||||
|
||||
|
@ -52,6 +67,11 @@ std::string Clientmessage::toJson() const
|
|||
return writer.write(message);
|
||||
}
|
||||
|
||||
const std::string& Clientmessage::token() const
|
||||
{
|
||||
return _token;
|
||||
}
|
||||
|
||||
const std::string& Clientmessage::web_address() const
|
||||
{
|
||||
return _web_address;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef CLIENTMESSAGE_H
|
||||
#define CLIENTMESSAGE_H
|
||||
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
|
||||
|
@ -22,12 +23,14 @@ public:
|
|||
std::string toJson() const;
|
||||
|
||||
const std::string& web_address() const;
|
||||
const std::string& token() const;
|
||||
bool isOpen() const;
|
||||
const Doormessage& doormessage() const;
|
||||
|
||||
private:
|
||||
|
||||
std::string _web_address;
|
||||
std::string _token;
|
||||
bool _isOpen;
|
||||
Doormessage _doormessage;
|
||||
|
||||
|
@ -36,6 +39,8 @@ private:
|
|||
const static std::string _lockButtonKey;
|
||||
const static std::string _emergencyUnlockKey;
|
||||
const static std::string _isOpenKey;
|
||||
|
||||
const static std::regex _token_regex;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue