1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00
doorlockd-mirror/doorlockd/lib/response.h

45 lines
1.2 KiB
C
Raw Normal View History

2015-09-22 21:22:48 +02:00
#ifndef RESPONSE_H
#define RESPONSE_H
#include <string>
#include <json/json.h>
class Response
2015-09-22 21:22:48 +02:00
{
public:
2015-09-22 21:22:48 +02:00
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();
Response(Response::Code code, const std::string &message = "");
2015-09-22 21:22:48 +02:00
static Response fromJson(const Json::Value &root);
static Response fromString(const std::string &json);
2015-09-25 00:25:26 +02:00
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