• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
21 #ifndef __SOUP_WEBSOCKET_H__
22 #define __SOUP_WEBSOCKET_H__
23 
24 #include <libsoup/soup-types.h>
25 
26 G_BEGIN_DECLS
27 
28 #define SOUP_WEBSOCKET_ERROR (soup_websocket_error_get_quark ())
29 SOUP_AVAILABLE_IN_2_50
30 GQuark soup_websocket_error_get_quark (void) G_GNUC_CONST;
31 
32 typedef enum {
33 	SOUP_WEBSOCKET_ERROR_FAILED,
34 	SOUP_WEBSOCKET_ERROR_NOT_WEBSOCKET,
35 	SOUP_WEBSOCKET_ERROR_BAD_HANDSHAKE,
36 	SOUP_WEBSOCKET_ERROR_BAD_ORIGIN,
37 } SoupWebsocketError;
38 
39 typedef enum {
40 	SOUP_WEBSOCKET_CONNECTION_UNKNOWN,
41 	SOUP_WEBSOCKET_CONNECTION_CLIENT,
42 	SOUP_WEBSOCKET_CONNECTION_SERVER
43 } SoupWebsocketConnectionType;
44 
45 typedef enum {
46 	SOUP_WEBSOCKET_DATA_TEXT = 0x01,
47 	SOUP_WEBSOCKET_DATA_BINARY = 0x02,
48 } SoupWebsocketDataType;
49 
50 typedef enum {
51 	SOUP_WEBSOCKET_CLOSE_NORMAL = 1000,
52 	SOUP_WEBSOCKET_CLOSE_GOING_AWAY = 1001,
53 	SOUP_WEBSOCKET_CLOSE_PROTOCOL_ERROR = 1002,
54 	SOUP_WEBSOCKET_CLOSE_UNSUPPORTED_DATA = 1003,
55 	SOUP_WEBSOCKET_CLOSE_NO_STATUS = 1005,
56 	SOUP_WEBSOCKET_CLOSE_ABNORMAL = 1006,
57 	SOUP_WEBSOCKET_CLOSE_BAD_DATA = 1007,
58 	SOUP_WEBSOCKET_CLOSE_POLICY_VIOLATION = 1008,
59 	SOUP_WEBSOCKET_CLOSE_TOO_BIG = 1009,
60 	SOUP_WEBSOCKET_CLOSE_NO_EXTENSION = 1010,
61 	SOUP_WEBSOCKET_CLOSE_SERVER_ERROR = 1011,
62 	SOUP_WEBSOCKET_CLOSE_TLS_HANDSHAKE = 1015,
63 } SoupWebsocketCloseCode;
64 
65 typedef enum {
66 	SOUP_WEBSOCKET_STATE_OPEN = 1,
67 	SOUP_WEBSOCKET_STATE_CLOSING = 2,
68 	SOUP_WEBSOCKET_STATE_CLOSED = 3,
69 } SoupWebsocketState;
70 
71 SOUP_AVAILABLE_IN_2_50
72 void     soup_websocket_client_prepare_handshake (SoupMessage  *msg,
73 						  const char   *origin,
74 						  char        **protocols);
75 SOUP_AVAILABLE_IN_2_68
76 void     soup_websocket_client_prepare_handshake_with_extensions (SoupMessage *msg,
77                                                                   const char  *origin,
78                                                                   char       **protocols,
79                                                                   GPtrArray   *supported_extensions);
80 
81 SOUP_AVAILABLE_IN_2_50
82 gboolean soup_websocket_client_verify_handshake  (SoupMessage  *msg,
83 						  GError      **error);
84 SOUP_AVAILABLE_IN_2_68
85 gboolean soup_websocket_client_verify_handshake_with_extensions (SoupMessage *msg,
86                                                                  GPtrArray   *supported_extensions,
87                                                                  GList      **accepted_extensions,
88                                                                  GError     **error);
89 
90 SOUP_AVAILABLE_IN_2_50
91 gboolean soup_websocket_server_check_handshake   (SoupMessage  *msg,
92 						  const char   *origin,
93 						  char        **protocols,
94 						  GError      **error);
95 SOUP_AVAILABLE_IN_2_68
96 gboolean
97 soup_websocket_server_check_handshake_with_extensions (SoupMessage  *msg,
98                                                        const char   *origin,
99                                                        char        **protocols,
100                                                        GPtrArray    *supported_extensions,
101                                                        GError      **error);
102 
103 SOUP_AVAILABLE_IN_2_50
104 gboolean soup_websocket_server_process_handshake (SoupMessage  *msg,
105 						  const char   *expected_origin,
106 						  char        **protocols);
107 SOUP_AVAILABLE_IN_2_68
108 gboolean
109 soup_websocket_server_process_handshake_with_extensions (SoupMessage  *msg,
110                                                          const char   *expected_origin,
111                                                          char        **protocols,
112                                                          GPtrArray    *supported_extensions,
113                                                          GList       **accepted_extensions);
114 
115 G_END_DECLS
116 
117 #endif /* __SOUP_WEBSOCKET_H__ */
118