• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2018, 2022 Wind River Systems, Inc. and others. All Rights Reserved.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v2.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    https://www.eclipse.org/legal/epl-2.0/
10  * and the Eclipse Distribution License is available at
11  *   http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  *    Keith Holman - initial implementation and documentation
15  *    Sven Gambel - move WebSocket proxy support to generic proxy support
16  *******************************************************************************/
17 
18 #if !defined(WEBSOCKET_H)
19 #define WEBSOCKET_H
20 
21 #include "MQTTPacket.h"
22 
23 /**
24  * WebSocket op codes
25  * @{
26  */
27 #define WebSocket_OP_CONTINUE 0x0 /* 0000 - continue frame */
28 #define WebSocket_OP_TEXT     0x1 /* 0001 - text frame */
29 #define WebSocket_OP_BINARY   0x2 /* 0010 - binary frame */
30 #define WebSocket_OP_CLOSE    0x8 /* 1000 - close frame */
31 #define WebSocket_OP_PING     0x9 /* 1001 - ping frame */
32 #define WebSocket_OP_PONG     0xA /* 1010 - pong frame */
33 /** @} */
34 
35 /**
36  * Various close status codes
37  * @{
38  */
39 #define WebSocket_CLOSE_NORMAL          1000
40 #define WebSocket_CLOSE_GOING_AWAY      1001
41 #define WebSocket_CLOSE_PROTOCOL_ERROR  1002
42 #define WebSocket_CLOSE_UNKNOWN_DATA    1003
43 #define WebSocket_CLOSE_RESERVED        1004
44 #define WebSocket_CLOSE_NO_STATUS_CODE  1005 /* reserved: not to be used */
45 #define WebSocket_CLOSE_ABNORMAL        1006 /* reserved: not to be used */
46 #define WebSocket_CLOSE_BAD_DATA        1007
47 #define WebSocket_CLOSE_POLICY          1008
48 #define WebSocket_CLOSE_MSG_TOO_BIG     1009
49 #define WebSocket_CLOSE_NO_EXTENSION    1010
50 #define WebScoket_CLOSE_UNEXPECTED      1011
51 #define WebSocket_CLOSE_TLS_FAIL        1015 /* reserved: not be used */
52 /** @} */
53 
54 /* closes a websocket connection */
55 void WebSocket_close(networkHandles *net, int status_code, const char *reason);
56 
57 /* sends upgrade request */
58 int WebSocket_connect(networkHandles *net, int ssl, const char *uri);
59 
60 /* obtain data from network socket */
61 int WebSocket_getch(networkHandles *net, char* c);
62 char *WebSocket_getdata(networkHandles *net, size_t bytes, size_t* actual_len);
63 size_t WebSocket_framePos();
64 void WebSocket_framePosSeekTo(size_t);
65 
66 /* send data out, in websocket format only if required */
67 int WebSocket_putdatas(networkHandles* net, char** buf0, size_t* buf0len, PacketBuffers* bufs);
68 
69 /* releases any resources used by the websocket system */
70 void WebSocket_terminate(void);
71 
72 /* handles websocket upgrade request */
73 int WebSocket_upgrade(networkHandles *net);
74 
75 #endif /* WEBSOCKET_H */
76