1 /******************************************************************************* 2 * Copyright (c) 2018 Wind River Systems, Inc. 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 v1.0 6 * and Eclipse Distribution License v1.0 which accompany this distribution. 7 * 8 * The Eclipse Public License is available at 9 * http://www.eclipse.org/legal/epl-v10.html 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 *******************************************************************************/ 16 17 #if !defined(WEBSOCKET_H) 18 #define WEBSOCKET_H 19 20 #include "Clients.h" 21 22 /** 23 * WebSocket op codes 24 * @{ 25 */ 26 #define WebSocket_OP_CONTINUE 0x0 /* 0000 - continue frame */ 27 #define WebSocket_OP_TEXT 0x1 /* 0001 - text frame */ 28 #define WebSocket_OP_BINARY 0x2 /* 0010 - binary frame */ 29 #define WebSocket_OP_CLOSE 0x8 /* 1000 - close frame */ 30 #define WebSocket_OP_PING 0x9 /* 1001 - ping frame */ 31 #define WebSocket_OP_PONG 0xA /* 1010 - pong frame */ 32 /** @} */ 33 34 /** 35 * Various close status codes 36 * @{ 37 */ 38 #define WebSocket_CLOSE_NORMAL 1000 39 #define WebSocket_CLOSE_GOING_AWAY 1001 40 #define WebSocket_CLOSE_PROTOCOL_ERROR 1002 41 #define WebSocket_CLOSE_UNKNOWN_DATA 1003 42 #define WebSocket_CLOSE_RESERVED 1004 43 #define WebSocket_CLOSE_NO_STATUS_CODE 1005 /* reserved: not to be used */ 44 #define WebSocket_CLOSE_ABNORMAL 1006 /* reserved: not to be used */ 45 #define WebSocket_CLOSE_BAD_DATA 1007 46 #define WebSocket_CLOSE_POLICY 1008 47 #define WebSocket_CLOSE_MSG_TOO_BIG 1009 48 #define WebSocket_CLOSE_NO_EXTENSION 1010 49 #define WebScoket_CLOSE_UNEXPECTED 1011 50 #define WebSocket_CLOSE_TLS_FAIL 1015 /* reserved: not be used */ 51 /** @} */ 52 53 /* closes a websocket connection */ 54 void WebSocket_close(networkHandles *net, int status_code, const char *reason); 55 56 /* sends upgrade request */ 57 int WebSocket_connect(networkHandles *net, const char *uri); 58 59 /* calculates the extra data required in a packet to hold a WebSocket frame header */ 60 size_t WebSocket_calculateFrameHeaderSize(networkHandles *net, int mask_data, 61 size_t data_len); 62 63 /* obtain data from network socket */ 64 int WebSocket_getch(networkHandles *net, char* c); 65 char *WebSocket_getdata(networkHandles *net, size_t bytes, size_t* actual_len); 66 67 /* send data out, in websocket format only if required */ 68 int WebSocket_putdatas(networkHandles* net, char* buf0, size_t buf0len, 69 int count, char** buffers, size_t* buflens, int* freeData); 70 71 /* releases any resources used by the websocket system */ 72 void WebSocket_terminate(void); 73 74 /* handles websocket upgrade request */ 75 int WebSocket_upgrade(networkHandles *net); 76 77 #endif /* WEBSOCKET_H */ 78