1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-11-16 12:09:10 +01:00
doorlockd-mirror/doorlockd/lib/response.h
Ralf Ramsauer 49a5b88f6c Big rewrite of several things
- Data type Token changed from uint64_t to std::string
- Added new class "Request" that describes a JSON TCP request
- Classes may now throw Responses for proper error handling
- Removed JSON parsing from Logic
- proper Error handling everywhere
- Many small fixes
- removed unnecessary includes
- removed using namespace std everywhere
2015-10-01 22:09:55 +02:00

45 lines
1.2 KiB
C++

#ifndef RESPONSE_H
#define RESPONSE_H
#include <string>
#include <json/json.h>
class Response
{
public:
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
UnknownCommand, // Unknown action
LDAPInit, // Ldap initialization failed
AccessDenied, // Access denied
RESPONSE_NUM_ITEMS
} code;
std::string message;
Response();
Response(Response::Code code, const std::string &message = "");
static Response fromJson(const Json::Value &root);
static Response fromString(const std::string &json);
std::string toJson() const;
// Returns true if code is success
operator bool() const;
private:
const static std::string _codeKey;
const static std::string _messageKey;
};
#endif // RESPONSE_H