forked from FreeRDP/FreeRDP-WebConnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRDP.hpp
193 lines (176 loc) · 7.88 KB
/
RDP.hpp
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
/* vim: set et ts=4 sw=4 cindent:
*
* FreeRDP-WebConnect,
* A gateway for seamless access to your RDP-Sessions in any HTML5-compliant browser.
*
* Copyright 2012 Fritz Elfert <wsgate@fritz-elfert.de>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _WSGATE_RDP_H_
#define _WSGATE_RDP_H_
#include <pthread.h>
#include <map>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
#include "rdpcommon.hpp"
namespace wsgate {
/**
* This class serves as a wrapper around the
* main FreeRDP API.
*/
class RDP {
public:
/**
* Our connection states.
*/
typedef enum {
STATE_INITIAL,
STATE_CONNECT,
STATE_CONNECTED,
STATE_CLOSED
} State;
/// Map for storing cursor images of this session
typedef boost::tuple<time_t, std::string> cursor;
typedef std::map<uint32_t, cursor> CursorMap;
/**
* Constructor
* @param h The WebSockets handler to be used for communication with the client.
*/
RDP(wspp::wshandler *h);
/// Destructor
virtual ~RDP();
/**
* Sets the error message for the last error.
* @param msg The message.
*/
void SetError(std::string msg);
/**
* Initiates the actual RDP session.
* @param host The RDP host to connect to.
* @param user The user name to be used for the RDP session.
* @param domain The domain name to be used for the RDP session.
* @param pass The password to be used for the RDP session.
* @param params Additional parameters for the RDP session.
* @return true on success.
*/
bool Connect(std::string host, std::string user, std::string domain,
std::string pass, const WsRdpParams ¶ms);
/**
* Actively terminates a session.
* @return true on success.
*/
bool Disconnect();
/**
* Wraps the corresponding FreeRDP API call
* @return true on success.
*/
bool CheckFileDescriptor();
/**
* Handler for incoming WebSockets messages.
* Called from the WebSockets codec, whenever the client sent a message.
* @param data The binary payload of the incoming message.
*/
void OnWsMessage(const std::string & data);
/**
* Retrieves a custom cursor tuple by ID.
* @param cid Unique cursor ID (valid for current session).
* @return A tuple, containing the creation time and PNG-encoded RGBA image or a tuple containing 0 and an empty String, if no cursor image is defined for the given Id.
*/
cursor GetCursor(uint32_t cid);
private:
/**
* Wraps the corresponding FreeRDP API call.
* @param flags The flags as defined by the FreeRDP API.
*/
void SendInputSynchronizeEvent(uint32_t flags);
/**
* Wraps the corresponding FreeRDP API call.
* @param flags The flags as defined by the FreeRDP API.
* @param code The scan code as defined by the FreeRDP API.
*/
void SendInputKeyboardEvent(uint16_t flags, uint16_t code);
/**
* Wraps the corresponding FreeRDP API call.
* @param flags The flags as defined by the FreeRDP API.
* @param code The character code as defined by the FreeRDP API.
*/
void SendInputUnicodeKeyboardEvent(uint16_t flags, uint16_t code);
/**
* Wraps the corresponding FreeRDP API call.
* @param flags The flags as defined by the FreeRDP API.
* @param x, y The mouse coordinates as defined by the FreeRDP API.
*/
void SendInputMouseEvent(uint16_t flags, uint16_t x, uint16_t y);
/**
* Wraps the corresponding FreeRDP API call.
* @param flags The flags as defined by the FreeRDP API.
* @param x, y The mouse coordinates as defined by the FreeRDP API.
*/
void SendInputExtendedMouseEvent(uint16_t flags, uint16_t x, uint16_t y);
// Non-copyable
RDP(const RDP &);
RDP & operator=(const RDP &);
void ThreadFunc();
void addError(const std::string &msg);
void ContextNew(freerdp *inst, rdpContext *ctx);
void ContextFree(freerdp *inst, rdpContext *ctx);
boolean PreConnect(freerdp *inst);
boolean PostConnect(freerdp *inst);
boolean Authenticate(freerdp *inst, char** user, char** pass, char** domain);
boolean VerifyCertificate(freerdp *inst, char* subject, char* issuer, char* fprint);
int SendChannelData(freerdp *inst, int chId, uint8_t* data, int size);
int ReceiveChannelData(freerdp* inst, int chId, uint8_t* data, int size,
int flags, int total_size);
void Pointer_New(rdpContext* context, rdpPointer* pointer);
void Pointer_Free(rdpContext* context, rdpPointer* pointer);
void Pointer_Set(rdpContext* context, rdpPointer* pointer);
void Pointer_SetNull(rdpContext* context);
void Pointer_SetDefault(rdpContext* context);
static std::map<freerdp *, RDP *> m_instances;
freerdp *m_freerdp;
rdpContext *m_rdpContext;
rdpInput *m_rdpInput;
rdpSettings *m_rdpSettings;
bool m_bThreadLoop;
pthread_t m_worker;
wspp::wshandler *m_wshandler;
std::string m_errMsg;
State m_State;
Update *m_pUpdate;
Primary *m_pPrimary;
uint32_t m_lastError;
uint32_t m_ptrId;
CursorMap m_cursorMap;
// Callbacks from C pthreads - Must be static in order t be assigned to C fnPtrs.
static void *cbThreadFunc(void *ctx);
// Callbacks from C - Must be static in order t be assigned to C fnPtrs.
static void cbContextNew(freerdp *inst, rdpContext *ctx);
static void cbContextFree(freerdp *inst, rdpContext *ctx);
static boolean cbPreConnect(freerdp *inst);
static boolean cbPostConnect(freerdp *inst);
static boolean cbAuthenticate(freerdp *inst, char** user, char** pass, char** domain);
static boolean cbVerifyCertificate(freerdp *inst, char* subject, char* issuer,
char* fprint);
static int cbSendChannelData(freerdp *inst, int chId, uint8_t* data, int size);
static int cbReceiveChannelData(freerdp* inst, int chId, uint8_t* data, int size,
int flags, int total_size);
static void cbPointer_New(rdpContext* context, rdpPointer* pointer);
static void cbPointer_Free(rdpContext* context, rdpPointer* pointer);
static void cbPointer_Set(rdpContext* context, rdpPointer* pointer);
static void cbPointer_SetNull(rdpContext* context);
static void cbPointer_SetDefault(rdpContext* context);
};
}
#endif