-
Notifications
You must be signed in to change notification settings - Fork 7
/
XrdpUlalacaPrivate.xrdpmodule.cpp
196 lines (148 loc) · 5.12 KB
/
XrdpUlalacaPrivate.xrdpmodule.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <sstream>
#include "XrdpUlalacaPrivate.hpp"
#include "messages/broker.h"
#include "ulalaca.hpp"
#include "SessionBrokerClient.hpp"
#include "ProjectorClient.hpp"
#include "ULSurface.hpp"
int XrdpUlalacaPrivate::libModStart(int width, int height, int bpp) {
// #517eb9
constexpr const unsigned int BACKGROUND_COLOR = 0xb97e51;
setSessionSize(width, height);
_surface->beginUpdate();
_surface->setForegroundColor(BACKGROUND_COLOR);
_surface->fillRect(0, 0, width, height);
_surface->endUpdate();
if (bpp != 32) {
LOG(LOG_LEVEL_WARNING, "client bpp %d is not supported, but using it anyway", bpp);
}
_bpp = bpp;
return 0;
}
int XrdpUlalacaPrivate::libModConnect() {
const std::string sessionBrokerIPCPath("/var/run/ulalaca_broker.sock");
try {
serverMessage("requesting session with given credentials...", 0);
SessionBrokerClient brokerClient(sessionBrokerIPCPath);
auto response = brokerClient.requestSession(_username, _password);
std::fill(_password.begin(), _password.end(), '\0');
_password.clear();
if (!response.isSuccessful) {
std::stringstream sstream;
sstream << "failed to request session for user " << _username << ": ";
switch (response.reason) {
case REJECT_REASON_AUTHENTICATION_FAILED:
sstream << "authentication failed (code 1)";
break;
case REJECT_REASON_SESSION_NOT_AVAILABLE:
sstream << "session not available; is sessionprojector.app running? (code 2)";
break;
case REJECT_REASON_INCOMPATIBLE_VERSION:
sstream << "incompatible IPC protocol version (code 3)";
break;
default:
sstream << "unknown error (code " << response.reason << ")";
break;
}
std::string message = sstream.str();
serverMessage(message.c_str(), 0);
return 1;
}
serverMessage("attaching to session..", 0);
// TODO: try-catch
attachToSession(response.sessionPath);
return 0;
} catch (SystemCallException &e) {
std::stringstream sstream;
sstream << "caught SystemCallException: " << e.what() << " (errno=" << e.getErrno() << ")";
std::string message = sstream.str();
serverMessage(message.c_str(), 0);
}
return 1;
}
int XrdpUlalacaPrivate::libModEvent(int type, long arg1, long arg2, long arg3, long arg4) {
XrdpEvent event {
(XrdpEvent::Type) type,
arg1, arg2, arg3, arg4
};
if (_projectorClient != nullptr) {
_projectorClient->handleEvent(event);
}
return 0;
}
int XrdpUlalacaPrivate::libModSignal() {
LOG(LOG_LEVEL_INFO, "lib_mod_signal() called");
return 0;
}
int XrdpUlalacaPrivate::libModEnd() {
LOG(LOG_LEVEL_INFO, "lib_mod_end() called");
if (_projectorClient != nullptr) {
_projectorClient->stop();
}
return 0;
}
int XrdpUlalacaPrivate::libModSetParam(const char *cstrName, const char *cstrValue) {
std::string name(cstrName);
std::string value(cstrValue);
if (name == "username") {
_username = value;
} else if (name == "password") {
_password = value;
} else if (name == "ip") {
_ip = value;
} else if (name == "port") {
_port = value;
} else if (name == "keylayout") {
_keyLayout = std::stoi(value);
} else if (name == "delay_ms") {
_delayMs = std::stoi(value);
} else if (name == "guid") {
auto *guid = reinterpret_cast<const struct guid *>(cstrValue);
_guid = *guid;
} else if (name == "disabled_encodings_mask") {
_encodingsMask = ~std::stoi(value);
} else if (name == "client_info") {
auto *clientInfo = reinterpret_cast<const struct xrdp_client_info *>(cstrValue);
_clientInfo = *clientInfo;
}
return 0;
}
int XrdpUlalacaPrivate::libModSessionChange(int, int) {
return 0;
}
int XrdpUlalacaPrivate::libModGetWaitObjs(tbus *readObjs, int *rcount, tbus *writeObjs, int *wcount, int *timeout) {
// FIXME
if (!_isUpdateThreadRunning) {
return 0;
}
if (_error != 0) {
return 1;
}
readObjs[(*rcount)++] = _projectorClient->descriptor();
readObjs[(*rcount)++] = _updateWaitObj;
writeObjs[(*wcount)++] = _projectorClient->descriptor();
return 0;
}
int XrdpUlalacaPrivate::libModCheckWaitObjs() {
// TODO: move ipcConnection.read()/write() to here..?
if (_error == 1) {
return 1;
}
return 0;
}
int XrdpUlalacaPrivate::libModFrameAck(int flags, int frameId) {
_surface->setAckFrameId(frameId);
return 0;
}
int XrdpUlalacaPrivate::libModSuppressOutput(int suppress, int left, int top, int right, int bottom) {
return 0;
}
int XrdpUlalacaPrivate::libModServerMonitorResize(int width, int height) {
return 0;
}
int XrdpUlalacaPrivate::libModServerMonitorFullInvalidate(int width, int height) {
return 0;
}
int XrdpUlalacaPrivate::libModServerVersionMessage() {
return 0;
}