FreeRDP-WebConnect WebSockets gateway  1.0.0.167
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends Pages
RDP.hpp
1 /* vim: set et ts=4 sw=4 cindent:
2  *
3  * FreeRDP-WebConnect,
4  * A gateway for seamless access to your RDP-Sessions in any HTML5-compliant browser.
5  *
6  * Copyright 2012 Fritz Elfert <wsgate@fritz-elfert.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef _WSGATE_RDP_H_
21 #define _WSGATE_RDP_H_
22 
23 #include <pthread.h>
24 #include <map>
25 #include <string>
26 #include <boost/shared_ptr.hpp>
27 #include <boost/tuple/tuple.hpp>
28 
29 #include "rdpcommon.hpp"
30 
31 namespace wsgate {
32 
37  class RDP {
38 
39  public:
43  typedef enum {
44  STATE_INITIAL,
45  STATE_CONNECT,
46  STATE_CONNECTED,
47  STATE_CLOSED
48  } State;
49 
51  typedef boost::tuple<time_t, std::string> cursor;
52  typedef std::map<uint32_t, cursor> CursorMap;
53 
58  RDP(wspp::wshandler *h);
60  virtual ~RDP();
61 
66  void SetError(std::string msg);
76  bool Connect(std::string host, std::string user, std::string domain,
77  std::string pass, const WsRdpParams &params);
82  bool Disconnect();
87  bool CheckFileDescriptor();
93  void OnWsMessage(const std::string & data);
99  cursor GetCursor(uint32_t cid);
100 
101  private:
106  void SendInputSynchronizeEvent(uint32_t flags);
112  void SendInputKeyboardEvent(uint16_t flags, uint16_t code);
118  void SendInputUnicodeKeyboardEvent(uint16_t flags, uint16_t code);
124  void SendInputMouseEvent(uint16_t flags, uint16_t x, uint16_t y);
130  void SendInputExtendedMouseEvent(uint16_t flags, uint16_t x, uint16_t y);
131 
132  // Non-copyable
133  RDP(const RDP &);
134  RDP & operator=(const RDP &);
135 
136  void ThreadFunc();
137  void addError(const std::string &msg);
138 
139  void ContextNew(freerdp *inst, rdpContext *ctx);
140  void ContextFree(freerdp *inst, rdpContext *ctx);
141  boolean PreConnect(freerdp *inst);
142  boolean PostConnect(freerdp *inst);
143  boolean Authenticate(freerdp *inst, char** user, char** pass, char** domain);
144  boolean VerifyCertificate(freerdp *inst, char* subject, char* issuer, char* fprint);
145  int SendChannelData(freerdp *inst, int chId, uint8_t* data, int size);
146  int ReceiveChannelData(freerdp* inst, int chId, uint8_t* data, int size,
147  int flags, int total_size);
148 
149  void Pointer_New(rdpContext* context, rdpPointer* pointer);
150  void Pointer_Free(rdpContext* context, rdpPointer* pointer);
151  void Pointer_Set(rdpContext* context, rdpPointer* pointer);
152  void Pointer_SetNull(rdpContext* context);
153  void Pointer_SetDefault(rdpContext* context);
154 
155  static std::map<freerdp *, RDP *> m_instances;
156  freerdp *m_freerdp;
157  rdpContext *m_rdpContext;
158  rdpInput *m_rdpInput;
159  rdpSettings *m_rdpSettings;
160  bool m_bThreadLoop;
161  pthread_t m_worker;
162  wspp::wshandler *m_wshandler;
163  std::string m_errMsg;
164  State m_State;
165  Update *m_pUpdate;
166  Primary *m_pPrimary;
167  uint32_t m_lastError;
168  uint32_t m_ptrId;
169  CursorMap m_cursorMap;
170 
171  // Callbacks from C pthreads - Must be static in order t be assigned to C fnPtrs.
172  static void *cbThreadFunc(void *ctx);
173  // Callbacks from C - Must be static in order t be assigned to C fnPtrs.
174  static void cbContextNew(freerdp *inst, rdpContext *ctx);
175  static void cbContextFree(freerdp *inst, rdpContext *ctx);
176  static boolean cbPreConnect(freerdp *inst);
177  static boolean cbPostConnect(freerdp *inst);
178  static boolean cbAuthenticate(freerdp *inst, char** user, char** pass, char** domain);
179  static boolean cbVerifyCertificate(freerdp *inst, char* subject, char* issuer,
180  char* fprint);
181  static int cbSendChannelData(freerdp *inst, int chId, uint8_t* data, int size);
182  static int cbReceiveChannelData(freerdp* inst, int chId, uint8_t* data, int size,
183  int flags, int total_size);
184 
185  static void cbPointer_New(rdpContext* context, rdpPointer* pointer);
186  static void cbPointer_Free(rdpContext* context, rdpPointer* pointer);
187  static void cbPointer_Set(rdpContext* context, rdpPointer* pointer);
188  static void cbPointer_SetNull(rdpContext* context);
189  static void cbPointer_SetDefault(rdpContext* context);
190  };
191 }
192 
193 #endif