Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
WebSocket support for the Asterisk internal HTTP server. More...
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/http.h"
#include "asterisk/astobj2.h"
#include "asterisk/strings.h"
#include "asterisk/file.h"
#include "asterisk/unaligned.h"
#include "asterisk/uri.h"
#include "asterisk/uuid.h"
#include "asterisk/http_websocket.h"
Go to the source code of this file.
Data Structures | |
struct | ast_websocket |
Structure definition for session. More... | |
struct | ast_websocket_server |
Structure for a WebSocket server. More... | |
struct | websocket_client |
Macros | |
#define | AST_API_MODULE |
#define | CLIENT_KEY_SIZE 16 |
Length of a websocket's client key. More... | |
#define | DEFAULT_RECONSTRUCTION_CEILING MAXIMUM_FRAME_SIZE |
Default reconstruction size for multi-frame payload reconstruction. If exceeded the next frame will start a payload. More... | |
#define | MAX_PROTOCOL_BUCKETS 7 |
Number of buckets for registered protocols. More... | |
#define | MAX_WS_HDR_SZ 14 |
Maximum size of a websocket frame header 1 byte flags and opcode 1 byte mask flag + payload len 8 bytes max extended length 4 bytes optional masking key ... payload follows ... More... | |
#define | MAXIMUM_FRAME_SIZE 65535 |
Size of the pre-determined buffer for WebSocket frames. More... | |
#define | MAXIMUM_RECONSTRUCTION_CEILING MAXIMUM_FRAME_SIZE |
Maximum reconstruction size for multi-frame payload reconstruction. More... | |
#define | MIN_WS_HDR_SZ 2 |
#define | WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" |
GUID used to compute the accept key, defined in the specifications. More... | |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
struct ast_module * | AST_MODULE_SELF_SYM (void) |
int AST_OPTIONAL_API_NAME() | ast_websocket_add_protocol (const char *name, ast_websocket_callback callback) |
Add a sub-protocol handler to the default /ws server. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_add_protocol2 (struct ast_websocket_protocol *protocol) |
Add a sub-protocol handler to the default /ws server. More... | |
const char *AST_OPTIONAL_API_NAME() | ast_websocket_client_accept_protocol (struct ast_websocket *ws) |
Retrieve the server accepted sub-protocol on the client. More... | |
struct ast_websocket *AST_OPTIONAL_API_NAME() | ast_websocket_client_create (const char *uri, const char *protocols, struct ast_tls_config *tls_cfg, enum ast_websocket_result *result) |
Create, and connect, a websocket client. More... | |
struct ast_websocket *AST_OPTIONAL_API_NAME() | ast_websocket_client_create_with_options (struct ast_websocket_client_options *options, enum ast_websocket_result *result) |
Create, and connect, a websocket client using given options. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_close (struct ast_websocket *session, uint16_t reason) |
Close function for websocket session. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_fd (struct ast_websocket *session) |
Get the file descriptor for a WebSocket session. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_is_secure (struct ast_websocket *session) |
Get whether the WebSocket session is using a secure transport or not. More... | |
struct ast_sockaddr *AST_OPTIONAL_API_NAME() | ast_websocket_local_address (struct ast_websocket *session) |
Get the local address for a WebSocket connection session. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_read (struct ast_websocket *session, char **payload, uint64_t *payload_len, enum ast_websocket_opcode *opcode, int *fragmented) |
Read a WebSocket frame and handle it. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_read_string (struct ast_websocket *ws, char **buf) |
Read a WebSocket frame containing string data. More... | |
void AST_OPTIONAL_API_NAME() | ast_websocket_reconstruct_disable (struct ast_websocket *session) |
Disable multi-frame reconstruction. More... | |
void AST_OPTIONAL_API_NAME() | ast_websocket_reconstruct_enable (struct ast_websocket *session, size_t bytes) |
Enable multi-frame reconstruction up to a certain number of bytes. More... | |
void AST_OPTIONAL_API_NAME() | ast_websocket_ref (struct ast_websocket *session) |
Increase the reference count for a WebSocket session. More... | |
struct ast_sockaddr *AST_OPTIONAL_API_NAME() | ast_websocket_remote_address (struct ast_websocket *session) |
Get the remote address for a WebSocket connected session. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_remove_protocol (const char *name, ast_websocket_callback callback) |
Remove a sub-protocol handler from the default /ws server. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_server_add_protocol (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback) |
Add a sub-protocol handler to the given server. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_server_add_protocol2 (struct ast_websocket_server *server, struct ast_websocket_protocol *protocol) |
Add a sub-protocol handler to the given server. More... | |
struct ast_websocket_server *AST_OPTIONAL_API_NAME() | ast_websocket_server_create (void) |
Creates a ast_websocket_server. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_server_remove_protocol (struct ast_websocket_server *server, const char *name, ast_websocket_callback callback) |
Remove a sub-protocol handler from the given server. More... | |
const char *AST_OPTIONAL_API_NAME() | ast_websocket_session_id (struct ast_websocket *session) |
Get the session ID for a WebSocket session. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_set_nonblock (struct ast_websocket *session) |
Set the socket of a WebSocket session to be non-blocking. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_set_timeout (struct ast_websocket *session, int timeout) |
Set the timeout on a non-blocking WebSocket session. More... | |
struct ast_websocket_protocol *AST_OPTIONAL_API_NAME() | ast_websocket_sub_protocol_alloc (const char *name) |
Allocate a websocket sub-protocol instance. More... | |
void AST_OPTIONAL_API_NAME() | ast_websocket_unref (struct ast_websocket *session) |
Decrease the reference count for a WebSocket session. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_uri_cb (struct ast_tcptls_session_instance *ser, const struct ast_http_uri *urih, const char *uri, enum ast_http_method method, struct ast_variable *get_vars, struct ast_variable *headers) |
Callback suitable for use with a ast_http_uri. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_wait_for_input (struct ast_websocket *session, int timeout) |
Wait for the WebSocket session to be ready to be read. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_write (struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size) |
Write function for websocket traffic. More... | |
int AST_OPTIONAL_API_NAME() | ast_websocket_write_string (struct ast_websocket *ws, const char *buf) |
Construct and transmit a WebSocket frame containing string data. More... | |
static int | load_module (void) |
static struct ast_websocket_protocol * | one_protocol (struct ast_websocket_server *server) |
If the server has exactly one configured protocol, return it. More... | |
static int | protocol_cmp_fn (void *obj, void *arg, int flags) |
Comparison function for protocols. More... | |
static void | protocol_destroy_fn (void *obj) |
Destructor function for protocols. More... | |
static int | protocol_hash_fn (const void *obj, const int flags) |
Hashing function for protocols. More... | |
static void | session_destroy_fn (void *obj) |
Destructor function for sessions. More... | |
static int | unload_module (void) |
static int | websocket_add_protocol_internal (const char *name, ast_websocket_callback callback) |
static void | websocket_bad_request (struct ast_tcptls_session_instance *ser) |
static struct ast_tcptls_session_args * | websocket_client_args_create (const char *host, struct ast_tls_config *tls_cfg, enum ast_websocket_result *result) |
static void | websocket_client_args_destroy (void *obj) |
static enum ast_websocket_result | websocket_client_connect (struct ast_websocket *ws, int timeout) |
static struct ast_websocket * | websocket_client_create (struct ast_websocket_client_options *options, enum ast_websocket_result *result) |
static char * | websocket_client_create_key (void) |
static void | websocket_client_destroy (void *obj) |
static enum ast_websocket_result | websocket_client_handle_response_code (struct websocket_client *client, int response_code) |
static enum ast_websocket_result | websocket_client_handshake (struct websocket_client *client) |
static enum ast_websocket_result | websocket_client_handshake_get_response (struct websocket_client *client) |
static int | websocket_client_parse_uri (const char *uri, char **host, struct ast_str **path) |
Parse the given uri into a path and remote address. More... | |
static char * | websocket_combine_key (const char *key, char *res, int res_size) |
static void | websocket_echo_callback (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers) |
Simple echo implementation which echoes received text and binary frames. More... | |
static void | websocket_mask_payload (struct ast_websocket *session, char *frame, char *payload, uint64_t payload_size) |
Perform payload masking for client sessions. More... | |
static const char * | websocket_opcode2str (enum ast_websocket_opcode opcode) |
static int | websocket_remove_protocol_internal (const char *name, ast_websocket_callback callback) |
static struct ast_websocket_server * | websocket_server_create_impl (void) |
static void | websocket_server_dtor (void *obj) |
static struct ast_websocket_server * | websocket_server_internal_create (void) |
static int | ws_safe_read (struct ast_websocket *session, char *buf, size_t len, enum ast_websocket_opcode *opcode) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "HTTP WebSocket Support" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_CHANNEL_DEPEND, .requires = "http", } |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static const char * | opcode_map [] |
static struct ast_http_uri | websocketuri |
WebSocket support for the Asterisk internal HTTP server.
Definition in file res_http_websocket.c.
#define AST_API_MODULE |
Definition at line 41 of file res_http_websocket.c.
#define CLIENT_KEY_SIZE 16 |
Length of a websocket's client key.
Definition at line 48 of file res_http_websocket.c.
#define DEFAULT_RECONSTRUCTION_CEILING MAXIMUM_FRAME_SIZE |
Default reconstruction size for multi-frame payload reconstruction. If exceeded the next frame will start a payload.
Definition at line 71 of file res_http_websocket.c.
#define MAX_PROTOCOL_BUCKETS 7 |
Number of buckets for registered protocols.
Definition at line 51 of file res_http_websocket.c.
#define MAX_WS_HDR_SZ 14 |
Maximum size of a websocket frame header 1 byte flags and opcode 1 byte mask flag + payload len 8 bytes max extended length 4 bytes optional masking key ... payload follows ...
Definition at line 84 of file res_http_websocket.c.
#define MAXIMUM_FRAME_SIZE 65535 |
Size of the pre-determined buffer for WebSocket frames.
Definition at line 66 of file res_http_websocket.c.
#define MAXIMUM_RECONSTRUCTION_CEILING MAXIMUM_FRAME_SIZE |
Maximum reconstruction size for multi-frame payload reconstruction.
Definition at line 74 of file res_http_websocket.c.
#define MIN_WS_HDR_SZ 2 |
Definition at line 85 of file res_http_websocket.c.
#define WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" |
GUID used to compute the accept key, defined in the specifications.
Definition at line 45 of file res_http_websocket.c.
|
static |
Definition at line 1561 of file res_http_websocket.c.
|
static |
Definition at line 1561 of file res_http_websocket.c.
struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) |
Definition at line 1561 of file res_http_websocket.c.
int AST_OPTIONAL_API_NAME() ast_websocket_add_protocol | ( | const char * | name, |
ast_websocket_callback | callback | ||
) |
Add a sub-protocol handler to the default /ws server.
name | Name of the sub-protocol to register |
callback | Callback called when a new connection requesting the sub-protocol is established |
0 | success |
-1 | if sub-protocol handler could not be registered |
Definition at line 1052 of file res_http_websocket.c.
References name, and websocket_add_protocol_internal().
Referenced by AST_TEST_DEFINE(), and load_module().
int AST_OPTIONAL_API_NAME() ast_websocket_add_protocol2 | ( | struct ast_websocket_protocol * | protocol | ) |
Add a sub-protocol handler to the default /ws server.
protocol | The sub-protocol to register. Note that this must be allocated using /ref ast_websocket_sub_protocol_alloc. |
protocol
on success.0 | success |
-1 | if sub-protocol handler could not be registered |
Definition at line 1057 of file res_http_websocket.c.
References ast_websocket_server_add_protocol2(), ast_http_uri::data, and websocketuri.
const char *AST_OPTIONAL_API_NAME() ast_websocket_client_accept_protocol | ( | struct ast_websocket * | ws | ) |
Retrieve the server accepted sub-protocol on the client.
ws | the websocket client |
Definition at line 1275 of file res_http_websocket.c.
Referenced by AST_TEST_DEFINE().
struct ast_websocket *AST_OPTIONAL_API_NAME() ast_websocket_client_create | ( | const char * | uri, |
const char * | protocols, | ||
struct ast_tls_config * | tls_cfg, | ||
enum ast_websocket_result * | result | ||
) |
Create, and connect, a websocket client.
If the client websocket successfully connects, then the accepted protocol can be checked via a call to ast_websocket_client_accept_protocol.
ws[s]://<address>[:port][/<path>]The address (can be a host name) and port are parsed out and used to connect to the remote server. If multiple IPs are returned during address resolution then the first one is chosen.
uri | uri to connect to |
protocols | a comma separated string of supported protocols |
tls_cfg | secure websocket credentials |
result | result code set on client failure |
NULL | if object could not be created or connected |
Definition at line 1440 of file res_http_websocket.c.
References ast_websocket_client_create_with_options(), options, ast_websocket_client_options::protocols, result, ast_websocket_client_options::tls_cfg, and ast_websocket_client_options::uri.
Referenced by AST_TEST_DEFINE().
struct ast_websocket *AST_OPTIONAL_API_NAME() ast_websocket_client_create_with_options | ( | struct ast_websocket_client_options * | options, |
enum ast_websocket_result * | result | ||
) |
Create, and connect, a websocket client using given options.
If the client websocket successfully connects, then the accepted protocol can be checked via a call to ast_websocket_client_accept_protocol.
options | Websocket client options |
result | result code set on client failure |
NULL | if object could not be created or connected |
Definition at line 1454 of file res_http_websocket.c.
References ao2_ref, NULL, options, result, websocket_client_connect(), websocket_client_create(), and WS_OK.
Referenced by ast_websocket_client_create(), and websocket_connect().
int AST_OPTIONAL_API_NAME() ast_websocket_close | ( | struct ast_websocket * | session, |
uint16_t | reason | ||
) |
Close function for websocket session.
Close a WebSocket session by sending a message with the CLOSE opcode and an optional code.
Definition at line 308 of file res_http_websocket.c.
References ao2_lock, ao2_unlock, ast_iostream_close(), ast_iostream_set_timeout_disable(), ast_iostream_set_timeout_inactivity(), ast_iostream_write(), ast_sockaddr_stringify(), ast_verb, AST_WEBSOCKET_OPCODE_CLOSE, NULL, ast_websocket::opcode, put_unaligned_uint16(), session, and websocket_mask_payload().
Referenced by ast_websocket_read(), ast_websocket_write(), session_destroy_fn(), and ws_shutdown().
int AST_OPTIONAL_API_NAME() ast_websocket_fd | ( | struct ast_websocket * | session | ) |
Get the file descriptor for a WebSocket session.
Definition at line 461 of file res_http_websocket.c.
References ast_iostream_get_fd(), and session.
Referenced by ast_ari_websocket_session_read(), speech_test_server_cb(), websocket_echo_callback(), websocket_read(), and ws_shutdown().
int AST_OPTIONAL_API_NAME() ast_websocket_is_secure | ( | struct ast_websocket * | session | ) |
Get whether the WebSocket session is using a secure transport or not.
0 | if unsecure |
1 | if secure |
Definition at line 481 of file res_http_websocket.c.
References session.
Referenced by transport_create().
struct ast_sockaddr *AST_OPTIONAL_API_NAME() ast_websocket_local_address | ( | struct ast_websocket * | session | ) |
Get the local address for a WebSocket connection session.
Definition at line 476 of file res_http_websocket.c.
References session.
Referenced by transport_create().
int AST_OPTIONAL_API_NAME() ast_websocket_read | ( | struct ast_websocket * | session, |
char ** | payload, | ||
uint64_t * | payload_len, | ||
enum ast_websocket_opcode * | opcode, | ||
int * | fragmented | ||
) |
Read a WebSocket frame and handle it.
session | Pointer to the WebSocket session |
payload | Pointer to a char* which will be populated with a pointer to the payload if present |
payload_len | Pointer to a uint64_t which will be populated with the length of the payload if present |
opcode | Pointer to an enum which will be populated with the opcode of the frame |
fragmented | Pointer to an int which is set to 1 if payload is fragmented and 0 if not |
-1 | on error |
0 | on success |
Definition at line 602 of file res_http_websocket.c.
References ast_free, ast_log, ast_realloc, ast_websocket_close(), AST_WEBSOCKET_OPCODE_BINARY, AST_WEBSOCKET_OPCODE_CLOSE, AST_WEBSOCKET_OPCODE_CONTINUATION, AST_WEBSOCKET_OPCODE_PING, AST_WEBSOCKET_OPCODE_PONG, AST_WEBSOCKET_OPCODE_TEXT, ast_websocket_write(), frame_size, get_unaligned_uint16(), get_unaligned_uint64(), LOG_WARNING, MAXIMUM_FRAME_SIZE, MIN_WS_HDR_SZ, ntohll(), NULL, ast_websocket::opcode, ast_websocket::payload, ast_websocket::payload_len, session, and ws_safe_read().
Referenced by ast_ari_websocket_session_read(), ast_websocket_read_string(), speech_test_server_cb(), websocket_cb(), websocket_echo_callback(), and websocket_read().
int AST_OPTIONAL_API_NAME() ast_websocket_read_string | ( | struct ast_websocket * | ws, |
char ** | buf | ||
) |
Read a WebSocket frame containing string data.
ws | pointer to the websocket |
buf | string buffer to populate with data read from socket |
-1 | on error |
Definition at line 1471 of file res_http_websocket.c.
References ast_log, ast_strndup, AST_WEBSOCKET_OPCODE_CLOSE, AST_WEBSOCKET_OPCODE_CONTINUATION, AST_WEBSOCKET_OPCODE_PING, AST_WEBSOCKET_OPCODE_TEXT, ast_websocket_read(), buf, LOG_ERROR, ast_websocket::opcode, ast_websocket::payload, and ast_websocket::payload_len.
Referenced by AST_TEST_DEFINE().
void AST_OPTIONAL_API_NAME() ast_websocket_reconstruct_disable | ( | struct ast_websocket * | session | ) |
Disable multi-frame reconstruction.
session | Pointer to the WebSocket session |
Definition at line 446 of file res_http_websocket.c.
References session.
void AST_OPTIONAL_API_NAME() ast_websocket_reconstruct_enable | ( | struct ast_websocket * | session, |
size_t | bytes | ||
) |
Enable multi-frame reconstruction up to a certain number of bytes.
session | Pointer to the WebSocket session |
bytes | If a reconstructed payload exceeds the specified number of bytes the payload will be returned and upon reception of the next multi-frame a new reconstructed payload will begin. |
Definition at line 441 of file res_http_websocket.c.
References MAXIMUM_RECONSTRUCTION_CEILING, MIN, and session.
void AST_OPTIONAL_API_NAME() ast_websocket_ref | ( | struct ast_websocket * | session | ) |
Increase the reference count for a WebSocket session.
session | Pointer to the WebSocket session |
Definition at line 451 of file res_http_websocket.c.
References ao2_ref, and session.
Referenced by transport_create().
struct ast_sockaddr *AST_OPTIONAL_API_NAME() ast_websocket_remote_address | ( | struct ast_websocket * | session | ) |
Get the remote address for a WebSocket connected session.
Definition at line 471 of file res_http_websocket.c.
References session.
Referenced by ast_ari_websocket_session_get_remote_addr(), transport_create(), and transport_read().
int AST_OPTIONAL_API_NAME() ast_websocket_remove_protocol | ( | const char * | name, |
ast_websocket_callback | callback | ||
) |
Remove a sub-protocol handler from the default /ws server.
name | Name of the sub-protocol to unregister |
callback | Session Established callback that was previously registered with the sub-protocol |
0 | success |
-1 | if sub-protocol was not found or if callback did not match |
Definition at line 1081 of file res_http_websocket.c.
References name, and websocket_remove_protocol_internal().
Referenced by AST_TEST_DEFINE(), and unload_module().
int AST_OPTIONAL_API_NAME() ast_websocket_server_add_protocol | ( | struct ast_websocket_server * | server, |
const char * | name, | ||
ast_websocket_callback | callback | ||
) |
Add a sub-protocol handler to the given server.
server | The server to add the sub-protocol to |
name | Name of the sub-protocol to register |
callback | Callback called when a new connection requesting the sub-protocol is established |
0 | success |
-1 | if sub-protocol handler could not be registered |
Definition at line 210 of file res_http_websocket.c.
References ao2_ref, ast_websocket_server_add_protocol2(), ast_websocket_sub_protocol_alloc(), name, ast_websocket_server::protocols, and ast_websocket_protocol::session_established.
Referenced by websocket_add_protocol_internal().
int AST_OPTIONAL_API_NAME() ast_websocket_server_add_protocol2 | ( | struct ast_websocket_server * | server, |
struct ast_websocket_protocol * | protocol | ||
) |
Add a sub-protocol handler to the given server.
server | The server to add the sub-protocol to. |
protocol | The sub-protocol to register. Note that this must be allocated using /ref ast_websocket_sub_protocol_alloc. |
protocol
on success.0 | success |
-1 | if sub-protocol handler could not be registered |
Definition at line 232 of file res_http_websocket.c.
References ao2_find, ao2_link_flags, ao2_lock, ao2_ref, ao2_unlock, ast_log, ast_verb, AST_WEBSOCKET_PROTOCOL_VERSION, LOG_WARNING, OBJ_KEY, OBJ_NOLOCK, and ast_websocket_server::protocols.
Referenced by ast_websocket_add_protocol2(), ast_websocket_server_add_protocol(), and load_module().
struct ast_websocket_server *AST_OPTIONAL_API_NAME() ast_websocket_server_create | ( | void | ) |
Creates a ast_websocket_server.
NULL | on error |
Definition at line 167 of file res_http_websocket.c.
References websocket_server_create_impl().
Referenced by load_module().
int AST_OPTIONAL_API_NAME() ast_websocket_server_remove_protocol | ( | struct ast_websocket_server * | server, |
const char * | name, | ||
ast_websocket_callback | callback | ||
) |
Remove a sub-protocol handler from the given server.
server | The server to unregister the sub-protocol from |
name | Name of the sub-protocol to unregister |
callback | Callback that was previously registered with the sub-protocol |
0 | success |
-1 | if sub-protocol was not found or if callback did not match |
Definition at line 266 of file res_http_websocket.c.
References ao2_find, ao2_ref, ao2_unlink, ast_verb, name, OBJ_KEY, ast_websocket_server::protocols, and ast_websocket_protocol::session_established.
Referenced by websocket_remove_protocol_internal().
const char *AST_OPTIONAL_API_NAME() ast_websocket_session_id | ( | struct ast_websocket * | session | ) |
Get the session ID for a WebSocket session.
Definition at line 500 of file res_http_websocket.c.
References session.
Referenced by ast_ari_websocket_session_id().
int AST_OPTIONAL_API_NAME() ast_websocket_set_nonblock | ( | struct ast_websocket * | session | ) |
Set the socket of a WebSocket session to be non-blocking.
0 | on success |
-1 | on failure |
Definition at line 486 of file res_http_websocket.c.
References ast_iostream_nonblock(), ast_iostream_set_exclusive_input(), and session.
Referenced by ast_ari_websocket_session_create(), and websocket_cb().
int AST_OPTIONAL_API_NAME() ast_websocket_set_timeout | ( | struct ast_websocket * | session, |
int | timeout | ||
) |
Set the timeout on a non-blocking WebSocket session.
0 | on success |
-1 | on failure |
Definition at line 493 of file res_http_websocket.c.
References session, and ast_websocket::timeout.
Referenced by ast_ari_websocket_session_create(), and websocket_cb().
struct ast_websocket_protocol *AST_OPTIONAL_API_NAME() ast_websocket_sub_protocol_alloc | ( | const char * | name | ) |
Allocate a websocket sub-protocol instance.
NULL | on error |
Definition at line 191 of file res_http_websocket.c.
References ao2_alloc, ao2_ref, ast_strdup, AST_WEBSOCKET_PROTOCOL_VERSION, name, ast_websocket_protocol::name, NULL, protocol_destroy_fn(), and ast_websocket_protocol::version.
Referenced by ast_websocket_server_add_protocol(), and load_module().
void AST_OPTIONAL_API_NAME() ast_websocket_unref | ( | struct ast_websocket * | session | ) |
Decrease the reference count for a WebSocket session.
session | Pointer to the WebSocket session |
Definition at line 456 of file res_http_websocket.c.
References ao2_cleanup, and session.
Referenced by ast_ari_events_event_websocket_ws_established_cb(), speech_test_server_cb(), transport_dtor(), websocket_cb(), websocket_disconnect(), websocket_echo_callback(), and websocket_session_dtor().
int AST_OPTIONAL_API_NAME() ast_websocket_uri_cb | ( | struct ast_tcptls_session_instance * | ser, |
const struct ast_http_uri * | urih, | ||
const char * | uri, | ||
enum ast_http_method | method, | ||
struct ast_variable * | get_vars, | ||
struct ast_variable * | headers | ||
) |
Callback suitable for use with a ast_http_uri.
Set the data field of the ast_http_uri to ast_websocket_server.
Definition at line 790 of file res_http_websocket.c.
References ao2_alloc, ao2_find, ao2_ref, ast_debug, AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT, ast_getsockname(), ast_http_body_discard(), ast_http_error(), AST_HTTP_GET, ast_iostream_get_fd(), ast_iostream_get_ssl(), ast_iostream_printf(), ast_iostream_set_exclusive_input(), ast_log, ast_sockaddr_copy(), ast_sockaddr_stringify(), ast_strdupa, ast_strip(), ast_strlen_zero(), ast_uuid_generate_str(), AST_UUID_STR_LEN, ast_verb, base64, ast_http_uri::data, DEFAULT_RECONSTRUCTION_CEILING, LOG_WARNING, method, ast_variable::name, ast_websocket_protocol::name, ast_variable::next, NULL, OBJ_KEY, one_protocol(), ast_websocket_server::protocols, ast_tcptls_session_instance::remote_address, SCOPED_MODULE_USE, ast_module_info::self, session, ast_websocket_protocol::session_attempted, session_destroy_fn(), ast_websocket_protocol::session_established, ast_tcptls_session_instance::stream, strsep(), 210693f3123d_create_cdr_table::upgrade(), ast_variable::value, version, websocket_bad_request(), websocket_combine_key(), and WEBSOCKET_GUID.
Referenced by ari_handle_websocket().
int AST_OPTIONAL_API_NAME() ast_websocket_wait_for_input | ( | struct ast_websocket * | session, |
int | timeout | ||
) |
Wait for the WebSocket session to be ready to be read.
session | Pointer to the WebSocket session |
timeout | the number of milliseconds to wait |
-1 | if error occurred |
0 | if the timeout expired |
1 | if the WebSocket session is ready for reading |
Definition at line 466 of file res_http_websocket.c.
References ast_iostream_wait_for_input(), session, and ast_websocket::timeout.
Referenced by speech_test_server_cb(), websocket_cb(), websocket_echo_callback(), and websocket_read().
int AST_OPTIONAL_API_NAME() ast_websocket_write | ( | struct ast_websocket * | session, |
enum ast_websocket_opcode | opcode, | ||
char * | payload, | ||
uint64_t | payload_size | ||
) |
Write function for websocket traffic.
Construct and transmit a WebSocket frame.
Definition at line 374 of file res_http_websocket.c.
References ao2_lock, ao2_unlock, ast_alloca, ast_debug, ast_iostream_set_timeout_disable(), ast_iostream_set_timeout_sequence(), ast_iostream_write(), ast_tvnow(), ast_websocket_close(), frame_size, htonll(), ast_websocket::opcode, ast_websocket::payload, put_unaligned_uint16(), put_unaligned_uint64(), session, websocket_mask_payload(), and websocket_opcode2str().
Referenced by ast_ari_events_event_websocket_ws_established_cb(), ast_websocket_read(), ast_websocket_write_string(), speech_test_server_cb(), websocket_echo_callback(), websocket_write(), and ws_send_msg().
int AST_OPTIONAL_API_NAME() ast_websocket_write_string | ( | struct ast_websocket * | ws, |
const char * | buf | ||
) |
Construct and transmit a WebSocket frame containing string data.
ws | pointer to the websocket |
buf | string data to write to socket |
0 | if successfully written |
-1 | if error occurred |
Definition at line 1515 of file res_http_websocket.c.
References ast_debug, AST_WEBSOCKET_OPCODE_TEXT, ast_websocket_write(), buf, and len().
Referenced by ast_ari_websocket_session_write(), AST_TEST_DEFINE(), and speech_test_server_handle_request().
|
static |
Definition at line 1533 of file res_http_websocket.c.
References ast_http_uri_link(), AST_MODULE_LOAD_DECLINE, ast_http_uri::data, websocket_add_protocol_internal(), websocket_echo_callback(), websocket_server_internal_create(), and websocketuri.
|
static |
If the server has exactly one configured protocol, return it.
Definition at line 752 of file res_http_websocket.c.
References ao2_callback, ao2_container_count(), lock, NULL, OBJ_NOLOCK, ast_websocket_server::protocols, and SCOPED_AO2LOCK.
Referenced by ast_websocket_uri_cb().
|
static |
Comparison function for protocols.
Definition at line 116 of file res_http_websocket.c.
References CMP_MATCH, CMP_STOP, ast_websocket_protocol::name, and OBJ_KEY.
Referenced by websocket_server_create_impl().
|
static |
Destructor function for protocols.
Definition at line 125 of file res_http_websocket.c.
References ast_free, and ast_websocket_protocol::name.
Referenced by ast_websocket_sub_protocol_alloc().
|
static |
Hashing function for protocols.
Definition at line 107 of file res_http_websocket.c.
References ast_str_case_hash(), name, ast_websocket_protocol::name, and OBJ_KEY.
Referenced by websocket_server_create_impl().
|
static |
Destructor function for sessions.
Definition at line 173 of file res_http_websocket.c.
References ao2_cleanup, ast_free, ast_iostream_close(), ast_sockaddr_stringify(), ast_verb, ast_websocket_close(), NULL, and session.
Referenced by ast_websocket_uri_cb(), and websocket_client_create().
|
static |
Definition at line 1545 of file res_http_websocket.c.
References ao2_ref, ast_http_uri_unlink(), ast_http_uri::data, NULL, websocket_echo_callback(), websocket_remove_protocol_internal(), and websocketuri.
|
static |
Definition at line 1043 of file res_http_websocket.c.
References ast_websocket_server_add_protocol(), ast_http_uri::data, name, and websocketuri.
Referenced by ast_websocket_add_protocol(), and load_module().
|
static |
Definition at line 777 of file res_http_websocket.c.
References ast_http_error(), ast_http_request_close_on_completion(), ast_http_send(), AST_HTTP_UNKNOWN, ast_str_create, ast_str_set(), and NULL.
Referenced by ast_websocket_uri_cb().
|
static |
Definition at line 1140 of file res_http_websocket.c.
References ao2_alloc, ao2_ref, args, ast_free, ast_log, ast_sockaddr_copy(), ast_sockaddr_resolve(), LOG_ERROR, NULL, result, ast_tcptls_session_args::tls_cfg, websocket_client_args_destroy(), WS_ALLOCATE_ERROR, and WS_URI_RESOLVE_ERROR.
Referenced by websocket_client_create().
|
static |
Definition at line 1124 of file res_http_websocket.c.
References args, ast_free, and ast_ssl_teardown().
Referenced by websocket_client_args_create().
|
static |
Definition at line 1417 of file res_http_websocket.c.
References ao2_ref, websocket_client::args, ast_iostream_get_ssl(), ast_sockaddr_copy(), ast_tcptls_client_create(), ast_tcptls_client_start_timeout(), ast_websocket::client, NULL, ast_tcptls_session_instance::remote_address, ast_websocket::remote_address, ast_websocket::secure, websocket_client::ser, ast_tcptls_session_instance::stream, ast_websocket::stream, ast_websocket::timeout, websocket_client_handshake(), WS_CLIENT_START_ERROR, and WS_OK.
Referenced by ast_websocket_client_create_with_options().
|
static |
Definition at line 1231 of file res_http_websocket.c.
References ao2_alloc, ao2_ref, websocket_client::args, ast_log, ast_strdup, ast_websocket::client, DEFAULT_RECONSTRUCTION_CEILING, websocket_client::host, websocket_client::key, LOG_ERROR, NULL, ast_websocket::opcode, options, websocket_client::protocols, ast_websocket::reconstruct, websocket_client::resource_name, result, session_destroy_fn(), websocket_client::version, websocket_client_args_create(), websocket_client_create_key(), websocket_client_destroy(), websocket_client_parse_uri(), WS_ALLOCATE_ERROR, WS_KEY_ERROR, and WS_URI_PARSE_ERROR.
Referenced by ast_websocket_client_create_with_options().
|
static |
Definition at line 1175 of file res_http_websocket.c.
References ast_base64encode(), ast_log, ast_malloc, ast_random(), CLIENT_KEY_SIZE, LOG_ERROR, and NULL.
Referenced by websocket_client_create().
|
static |
Definition at line 1217 of file res_http_websocket.c.
References websocket_client::accept_protocol, ao2_cleanup, websocket_client::args, ast_free, websocket_client::host, websocket_client::key, websocket_client::protocols, websocket_client::resource_name, and websocket_client::ser.
Referenced by websocket_client_create().
|
static |
Definition at line 1281 of file res_http_websocket.c.
References ast_log, ast_websocket::client, websocket_client::host, LOG_ERROR, WS_BAD_REQUEST, WS_INVALID_RESPONSE, and WS_URL_NOT_FOUND.
Referenced by websocket_client_handshake_get_response().
|
static |
Definition at line 1387 of file res_http_websocket.c.
References ast_iostream_printf(), ast_log, ast_str_buffer(), ast_strlen_zero(), ast_websocket::client, websocket_client::host, websocket_client::key, LOG_ERROR, websocket_client::protocols, websocket_client::resource_name, websocket_client::ser, ast_tcptls_session_instance::stream, websocket_client::version, websocket_client_handshake_get_response(), and WS_WRITE_ERROR.
Referenced by websocket_client_connect().
|
static |
Definition at line 1306 of file res_http_websocket.c.
References websocket_client::accept_protocol, ast_http_header_match(), ast_http_header_match_in(), ast_http_header_parse(), ast_http_response_status_line(), ast_iostream_gets(), ast_log, ast_strdup, base64, buf, ast_websocket::client, errno, websocket_client::key, len(), LOG_ERROR, name, websocket_client::protocols, websocket_client::ser, ast_tcptls_session_instance::stream, value, websocket_client_handle_response_code(), websocket_combine_key(), WS_BAD_STATUS, WS_HEADER_MISMATCH, WS_HEADER_MISSING, WS_NOT_SUPPORTED, and WS_OK.
Referenced by websocket_client_handshake().
|
static |
Parse the given uri into a path and remote address.
Expected uri form:
[ws[s]]://<host>[:port][/<path>]
The returned host will contain the address and optional port while path will contain everything after the address/port if included.
Definition at line 1094 of file res_http_websocket.c.
References ao2_ref, ast_str_append(), ast_str_create, ast_str_set(), ast_uri_make_host_with_port(), ast_uri_parse_websocket(), ast_uri_path(), ast_uri_query(), ast_uri::host, ast_uri::path, and ast_uri::uri.
Referenced by websocket_client_create().
|
static |
Definition at line 764 of file res_http_websocket.c.
References ast_alloca, ast_base64encode(), ast_sha1_hash_uint(), and WEBSOCKET_GUID.
Referenced by ast_websocket_uri_cb(), and websocket_client_handshake_get_response().
|
static |
Simple echo implementation which echoes received text and binary frames.
Definition at line 1007 of file res_http_websocket.c.
References ast_debug, ast_fd_set_flags, ast_log, ast_websocket_fd(), AST_WEBSOCKET_OPCODE_BINARY, AST_WEBSOCKET_OPCODE_CLOSE, AST_WEBSOCKET_OPCODE_TEXT, ast_websocket_read(), ast_websocket_unref(), ast_websocket_wait_for_input(), ast_websocket_write(), end, LOG_WARNING, and session.
Referenced by load_module(), and unload_module().
|
static |
Perform payload masking for client sessions.
Definition at line 288 of file res_http_websocket.c.
References ast_random(), put_unaligned_uint32(), and session.
Referenced by ast_websocket_close(), and ast_websocket_write().
|
static |
Definition at line 363 of file res_http_websocket.c.
References AST_WEBSOCKET_OPCODE_CONTINUATION, AST_WEBSOCKET_OPCODE_PONG, ast_websocket::opcode, and opcode_map.
Referenced by ast_websocket_write().
|
static |
Definition at line 1072 of file res_http_websocket.c.
References ast_websocket_server_remove_protocol(), ast_http_uri::data, name, and websocketuri.
Referenced by ast_websocket_remove_protocol(), and unload_module().
|
static |
Definition at line 143 of file res_http_websocket.c.
References ao2_alloc, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_container_alloc_hash, ao2_ref, MAX_PROTOCOL_BUCKETS, NULL, protocol_cmp_fn(), protocol_hash_fn(), RAII_VAR, and websocket_server_dtor().
Referenced by ast_websocket_server_create(), and websocket_server_internal_create().
|
static |
Definition at line 136 of file res_http_websocket.c.
References ao2_cleanup, NULL, and ast_websocket_server::protocols.
Referenced by websocket_server_create_impl().
|
static |
Definition at line 162 of file res_http_websocket.c.
References websocket_server_create_impl().
Referenced by load_module().
|
inlinestatic |
Definition at line 534 of file res_http_websocket.c.
References ao2_lock, ao2_unlock, ast_assert, ast_iostream_read(), ast_iostream_wait_for_input(), ast_log, AST_WEBSOCKET_OPCODE_CLOSE, buf, errno, len(), LOG_ERROR, LOG_WARNING, ast_websocket::opcode, and session.
Referenced by ast_websocket_read().
|
static |
Definition at line 1561 of file res_http_websocket.c.
|
static |
Definition at line 1561 of file res_http_websocket.c.
|
static |
Definition at line 354 of file res_http_websocket.c.
Referenced by websocket_opcode2str().
|
static |
Definition at line 997 of file res_http_websocket.c.
Referenced by ast_websocket_add_protocol2(), load_module(), unload_module(), websocket_add_protocol_internal(), and websocket_remove_protocol_internal().