-
Notifications
You must be signed in to change notification settings - Fork 7
/
SessionBrokerClient.cpp
89 lines (72 loc) · 2.54 KB
/
SessionBrokerClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// Created by Gyuhwan Park on 2023/01/28.
//
#include "SessionBrokerClient.hpp"
#include "messages/broker.h"
SessionBrokerClient::SessionBrokerClient(const std::string &socketPath):
_socketPath(socketPath)
{
}
SessionBrokerClient::~SessionBrokerClient() {
// TODO: ipcClient.close();
}
std::string SessionBrokerClient::getMessage(int reason) {
switch (reason) {
case REJECT_REASON_INTERNAL_ERROR:
return "Unknown error (REJECT_REASON_INTERNAL_ERROR)";
case REJECT_REASON_AUTHENTICATION_FAILED:
return "Authentication Failed";
case REJECT_REASON_SESSION_NOT_AVAILABLE:
return "Session not available";
case REJECT_REASON_INCOMPATIBLE_VERSION:
return "Incompatible version";
default:
return "Unknown error";
}
}
SessionBrokerResponse SessionBrokerClient::requestSession(const std::string &username, const std::string &password) {
// FIXME: use std::promise instaead
IPCConnection connection(_socketPath);
SessionBrokerResponse response;
connection.connect();
{
ULIPCSessionRequest request {};
std::strncpy(&request.username[0], username.c_str(), sizeof(request.username));
std::strncpy(&request.password[0], password.c_str(), sizeof(request.password));
connection.writeMessage(TYPE_SESSION_REQUEST, request);
std::memset(&request.password, 0x00, sizeof(request.password));
auto responseHeader = connection.nextHeader();
switch (responseHeader->messageType) {
case TYPE_SESSION_REQUEST_RESOLVED: {
auto body = connection.read<ULIPCSessionRequestResolved>(
sizeof(ULIPCSessionRequestResolved)
);
response = SessionBrokerResponse {
true,
std::string(body->path),
0
};
}
break;
case TYPE_SESSION_REQUEST_REJECTED: {
auto body = connection.read<ULIPCSessionRequestRejected>(
sizeof(ULIPCSessionRequestRejected)
);
response = SessionBrokerResponse {
false,
"",
body->reason
};
}
break;
default:
response = SessionBrokerResponse {
false,
"",
-1
};
}
}
connection.disconnect();
return std::move(response);
}