soup-websocket.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
  2. /*
  3. * soup-websocket.h: This file was originally part of Cockpit.
  4. *
  5. * Copyright 2013, 2014 Red Hat, Inc.
  6. *
  7. * Cockpit is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Cockpit is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this library; If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef __SOUP_WEBSOCKET_H__
  21. #define __SOUP_WEBSOCKET_H__
  22. #include <libsoup/soup-types.h>
  23. G_BEGIN_DECLS
  24. #define SOUP_WEBSOCKET_ERROR (soup_websocket_error_get_quark ())
  25. SOUP_AVAILABLE_IN_2_50
  26. GQuark soup_websocket_error_get_quark (void) G_GNUC_CONST;
  27. typedef enum {
  28. SOUP_WEBSOCKET_ERROR_FAILED,
  29. SOUP_WEBSOCKET_ERROR_NOT_WEBSOCKET,
  30. SOUP_WEBSOCKET_ERROR_BAD_HANDSHAKE,
  31. SOUP_WEBSOCKET_ERROR_BAD_ORIGIN,
  32. } SoupWebsocketError;
  33. typedef enum {
  34. SOUP_WEBSOCKET_CONNECTION_UNKNOWN,
  35. SOUP_WEBSOCKET_CONNECTION_CLIENT,
  36. SOUP_WEBSOCKET_CONNECTION_SERVER
  37. } SoupWebsocketConnectionType;
  38. typedef enum {
  39. SOUP_WEBSOCKET_DATA_TEXT = 0x01,
  40. SOUP_WEBSOCKET_DATA_BINARY = 0x02,
  41. } SoupWebsocketDataType;
  42. typedef enum {
  43. SOUP_WEBSOCKET_CLOSE_NORMAL = 1000,
  44. SOUP_WEBSOCKET_CLOSE_GOING_AWAY = 1001,
  45. SOUP_WEBSOCKET_CLOSE_PROTOCOL_ERROR = 1002,
  46. SOUP_WEBSOCKET_CLOSE_UNSUPPORTED_DATA = 1003,
  47. SOUP_WEBSOCKET_CLOSE_NO_STATUS = 1005,
  48. SOUP_WEBSOCKET_CLOSE_ABNORMAL = 1006,
  49. SOUP_WEBSOCKET_CLOSE_BAD_DATA = 1007,
  50. SOUP_WEBSOCKET_CLOSE_POLICY_VIOLATION = 1008,
  51. SOUP_WEBSOCKET_CLOSE_TOO_BIG = 1009,
  52. SOUP_WEBSOCKET_CLOSE_NO_EXTENSION = 1010,
  53. SOUP_WEBSOCKET_CLOSE_SERVER_ERROR = 1011,
  54. SOUP_WEBSOCKET_CLOSE_TLS_HANDSHAKE = 1015,
  55. } SoupWebsocketCloseCode;
  56. typedef enum {
  57. SOUP_WEBSOCKET_STATE_OPEN = 1,
  58. SOUP_WEBSOCKET_STATE_CLOSING = 2,
  59. SOUP_WEBSOCKET_STATE_CLOSED = 3,
  60. } SoupWebsocketState;
  61. SOUP_AVAILABLE_IN_2_50
  62. void soup_websocket_client_prepare_handshake (SoupMessage *msg,
  63. const char *origin,
  64. char **protocols);
  65. SOUP_AVAILABLE_IN_2_50
  66. gboolean soup_websocket_client_verify_handshake (SoupMessage *msg,
  67. GError **error);
  68. SOUP_AVAILABLE_IN_2_50
  69. gboolean soup_websocket_server_check_handshake (SoupMessage *msg,
  70. const char *origin,
  71. char **protocols,
  72. GError **error);
  73. SOUP_AVAILABLE_IN_2_50
  74. gboolean soup_websocket_server_process_handshake (SoupMessage *msg,
  75. const char *expected_origin,
  76. char **protocols);
  77. G_END_DECLS
  78. #endif /* __SOUP_WEBSOCKET_H__ */