File: evd-websocket-protocol.h

package info (click to toggle)
event-dance 0.2.0-8~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,096 kB
  • sloc: ansic: 29,033; javascript: 2,709; makefile: 434; xml: 247; sh: 30; python: 27
file content (108 lines) | stat: -rw-r--r-- 5,296 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
 * evd-websocket-protocol.h
 *
 * EventDance, Peer-to-peer IPC library <http://eventdance.org>
 *
 * Copyright (C) 2012-2013, Igalia S.L.
 *
 * Authors:
 *   Eduardo Lima Mitev <elima@igalia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 3, or (at your option) any later version as published by
 * the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License at http://www.gnu.org/licenses/lgpl-3.0.txt
 * for more details.
 */

#ifndef __EVD_WEBSOCKET_PROTOCOL_H__
#define __EVD_WEBSOCKET_PROTOCOL_H__

#include "evd-web-service.h"
#include "evd-http-connection.h"
#include "evd-http-request.h"
#include "evd-peer.h"

G_BEGIN_DECLS

/* websocket connection states */
typedef enum
{
  EVD_WEBSOCKET_STATE_NONE,
  EVD_WEBSOCKET_STATE_OPENING,
  EVD_WEBSOCKET_STATE_OPENED,
  EVD_WEBSOCKET_STATE_CLOSING,
  EVD_WEBSOCKET_STATE_CLOSED
} EvdWebsocketState;

typedef enum
{
  EVD_WEBSOCKET_CLOSE_NORMAL           = 1000,
  EVD_WEBSOCKET_CLOSE_GOING_AWAY       = 1001,
  EVD_WEBSOCKET_CLOSE_PROTOCOL_ERROR   = 1002,
  EVD_WEBSOCKET_CLOSE_UNSUPPORTED_DATA = 1003,
  EVD_WEBSOCKET_CLOSE_RESERVED         = 1004,
  EVD_WEBSOCKET_CLOSE_NO_STATUS        = 1005,
  EVD_WEBSOCKET_CLOSE_ABNORMAL         = 1006,
  EVD_WEBSOCKET_CLOSE_INVALID_DATA     = 1007,
  EVD_WEBSOCKET_CLOSE_POLICY_VIOLATION = 1008,
  EVD_WEBSOCKET_CLOSE_MESSAGE_TOO_BIG  = 1009,
  EVD_WEBSOCKET_CLOSE_MANDATORY_EXT    = 1010,
  EVD_WEBSOCKET_CLOSE_INTERNAL_ERROR   = 1011,
  EVD_WEBSOCKET_CLOSE_TLS_HANDSHAKE    = 1015
} EvdWebsocketClose;

typedef void (* EvdWebsocketFrameCb)         (EvdHttpConnection *conn,
                                              const gchar       *frame,
                                              gsize              frame_length,
                                              gboolean           is_binary,
                                              gpointer           user_data);
typedef void (* EvdWebsocketCloseCb)         (EvdHttpConnection *conn,
                                              gboolean           gracefully,
                                              gpointer           user_data);


gboolean          evd_websocket_protocol_handle_handshake_request  (EvdHttpConnection  *conn,
                                                                    EvdHttpRequest     *request,
                                                                    GError            **error);

EvdHttpRequest *  evd_websocket_protocol_create_handshake_request  (const gchar  *url,
                                                                    const gchar  *sub_protocol,
                                                                    const gchar  *origin,
                                                                    gchar       **key_base64);

gboolean          evd_websocket_protocol_handle_handshake_response (EvdHttpConnection   *conn,
                                                                    SoupHTTPVersion      http_version,
                                                                    guint                status_code,
                                                                    SoupMessageHeaders  *headers,
                                                                    const gchar         *handshake_key,
                                                                    GError             **error);

void              evd_websocket_protocol_bind                      (EvdHttpConnection   *conn,
                                                                    EvdWebsocketFrameCb  frame_cb,
                                                                    EvdWebsocketCloseCb  close_cb,
                                                                    gpointer             user_data,
                                                                    GDestroyNotify       user_data_destroy_notify);
void              evd_websocket_protocol_unbind                    (EvdHttpConnection *conn);

gboolean          evd_websocket_protocol_close                     (EvdHttpConnection  *conn,
                                                                    guint16             code,
                                                                    const gchar        *reason,
                                                                    GError            **error);

gboolean          evd_websocket_protocol_send                      (EvdHttpConnection  *conn,
                                                                    const gchar        *frame,
                                                                    gsize               frame_len,
                                                                    EvdMessageType      frame_type,
                                                                    GError            **error);

EvdWebsocketState evd_websocket_protocol_get_state                 (EvdHttpConnection *conn);

G_END_DECLS

#endif /* __EVD_WEBSOCKET_PROTOCOL_H__ */