FreeRDP
websocket.h
1 
20 #ifndef FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_H
21 #define FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_H
22 
23 #include <winpr/wtypes.h>
24 #include <winpr/stream.h>
25 
26 #include <freerdp/api.h>
27 
28 #include "../../crypto/tls.h"
29 
30 #define WEBSOCKET_MASK_BIT 0x80
31 #define WEBSOCKET_FIN_BIT 0x80
32 
33 typedef enum
34 {
35  WebsocketContinuationOpcode = 0x0,
36  WebsocketTextOpcode = 0x1,
37  WebsocketBinaryOpcode = 0x2,
38  WebsocketCloseOpcode = 0x8,
39  WebsocketPingOpcode = 0x9,
40  WebsocketPongOpcode = 0xa,
41 } WEBSOCKET_OPCODE;
42 
43 typedef enum
44 {
45  WebsocketStateOpcodeAndFin,
46  WebsocketStateLengthAndMasking,
47  WebsocketStateShortLength,
48  WebsocketStateLongLength,
49  WebSocketStateMaskingKey,
50  WebSocketStatePayload,
51 } WEBSOCKET_STATE;
52 
53 typedef struct s_websocket_context websocket_context;
54 
55 FREERDP_LOCAL void websocket_context_free(websocket_context* context);
56 
57 WINPR_ATTR_MALLOC(websocket_context_free, 1)
58 FREERDP_LOCAL websocket_context* websocket_context_new(void);
59 
60 FREERDP_LOCAL BOOL websocket_context_reset(websocket_context* context);
61 
62 FREERDP_LOCAL BOOL websocket_context_write_wstream(websocket_context* context, BIO* bio,
63  wStream* sPacket, WEBSOCKET_OPCODE opcode);
64 FREERDP_LOCAL int websocket_context_write(websocket_context* context, BIO* bio, const BYTE* buf,
65  int isize, WEBSOCKET_OPCODE opcode);
66 FREERDP_LOCAL int websocket_context_read(websocket_context* encodingContext, BIO* bio,
67  BYTE* pBuffer, size_t size);
68 
69 WINPR_ATTR_MALLOC(Stream_Free, 1)
70 FREERDP_LOCAL wStream* websocket_context_packet_new(size_t len, WEBSOCKET_OPCODE opcode,
71  UINT32* pMaskingKey);
72 
73 FREERDP_LOCAL BOOL websocket_context_mask_and_send(BIO* bio, wStream* sPacket, wStream* sDataPacket,
74  UINT32 maskingKey);
75 
76 #endif /* FREERDP_LIB_CORE_GATEWAY_WEBSOCKET_H */