| 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 | |
| 76 | SOUP_AVAILABLE_IN_2_50 |
| 77 | gboolean soup_websocket_client_verify_handshake (SoupMessage *msg, |
| 78 | GError **error); |
| 79 | |
| 80 | SOUP_AVAILABLE_IN_2_50 |
| 81 | gboolean soup_websocket_server_check_handshake (SoupMessage *msg, |
| 82 | const char *origin, |
| 83 | char **protocols, |
| 84 | GError **error); |
| 85 | |
| 86 | SOUP_AVAILABLE_IN_2_50 |
| 87 | gboolean soup_websocket_server_process_handshake (SoupMessage *msg, |
| 88 | const char *expected_origin, |
| 89 | char **protocols); |
| 90 | |
| 91 | G_END_DECLS |
| 92 | |
| 93 | #endif /* __SOUP_WEBSOCKET_H__ */ |
| 94 | |