2015-09-22 21:22:48 +02:00
|
|
|
#ifndef RESPONSE_H
|
|
|
|
#define RESPONSE_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
struct Response
|
|
|
|
{
|
|
|
|
enum Code {
|
|
|
|
Success = 0, // Request successful
|
|
|
|
Fail, // General non-specified error
|
|
|
|
AlreadyUnlocked, // Authentication successful, but door is already unlocked
|
|
|
|
AlreadyLocked, // Authentication successful, but door is already locked
|
|
|
|
NotJson, // Request is not a valid JSON object
|
|
|
|
JsonError, // Request is valid JSON, but does not contain necessary material
|
|
|
|
InvalidToken, // Request contains invalid token
|
|
|
|
InvalidCredentials, // Invalid LDAP credentials
|
|
|
|
InvalidIP, // IP check failure
|
2015-09-22 21:31:26 +02:00
|
|
|
UnknownCommand, // Unknown action
|
2015-09-22 21:22:48 +02:00
|
|
|
LDAPInit, // Ldap initialization failed
|
2015-09-24 18:05:10 +02:00
|
|
|
AccessDenied, // Access denied
|
2015-09-25 00:25:26 +02:00
|
|
|
RESPONSE_NUM_ITEMS
|
2015-09-22 21:22:48 +02:00
|
|
|
} code;
|
|
|
|
std::string message;
|
|
|
|
|
|
|
|
Response() :
|
|
|
|
code(Fail),
|
|
|
|
message("General failure")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Response(Response::Code code, const std::string &message = "") :
|
|
|
|
code(code),
|
|
|
|
message(message)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-09-25 00:25:26 +02:00
|
|
|
static Response fromJson(const std::string &json);
|
|
|
|
std::string toJson() const;
|
|
|
|
|
|
|
|
// Returns true if code is success
|
|
|
|
operator bool() const;
|
|
|
|
|
2015-09-22 21:22:48 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
const static std::string _codeKey;
|
|
|
|
const static std::string _messageKey;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // RESPONSE_H
|