WebSocket.h 2.8 KB

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