| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
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. | |
| #define | DEFAULT_RECONSTRUCTION_CEILING AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE | 
| Default reconstruction size for multi-frame payload reconstruction. If exceeded the next frame will start a payload. | |
| #define | MAX_PROTOCOL_BUCKETS 7 | 
| Number of buckets for registered protocols. | |
| #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 ... | |
| #define | MAXIMUM_RECONSTRUCTION_CEILING AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE | 
| Maximum reconstruction size for multi-frame payload reconstruction. | |
| #define | MIN_WS_HDR_SZ 2 | 
| #define | optional_header_spec "%s%s%s" | 
| #define | print_optional_header(test, name, value) | 
| #define | WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" | 
| GUID used to compute the accept key, defined in the specifications. | |
| 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. | |
| int AST_OPTIONAL_API_NAME() | ast_websocket_add_protocol2 (struct ast_websocket_protocol *protocol) | 
| Add a sub-protocol handler to the default /ws server. | |
| const char *AST_OPTIONAL_API_NAME() | ast_websocket_client_accept_protocol (struct ast_websocket *ws) | 
| Retrieve the server accepted sub-protocol on the client. | |
| 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. | |
| 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. | |
| int AST_OPTIONAL_API_NAME() | ast_websocket_close (struct ast_websocket *session, uint16_t reason) | 
| Close function for websocket session. | |
| int AST_OPTIONAL_API_NAME() | ast_websocket_fd (struct ast_websocket *session) | 
| Get the file descriptor for a WebSocket session. | |
| 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. | |
| struct ast_sockaddr *AST_OPTIONAL_API_NAME() | ast_websocket_local_address (struct ast_websocket *session) | 
| Get the local address for a WebSocket connection session. | |
| 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. | |
| int AST_OPTIONAL_API_NAME() | ast_websocket_read_string (struct ast_websocket *ws, char **buf) | 
| Read a WebSocket frame containing string data. | |
| void AST_OPTIONAL_API_NAME() | ast_websocket_reconstruct_disable (struct ast_websocket *session) | 
| Disable multi-frame reconstruction. | |
| 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. | |
| void AST_OPTIONAL_API_NAME() | ast_websocket_ref (struct ast_websocket *session) | 
| Increase the reference count for a WebSocket session. | |
| struct ast_sockaddr *AST_OPTIONAL_API_NAME() | ast_websocket_remote_address (struct ast_websocket *session) | 
| Get the remote address for a WebSocket connected session. | |
| 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. | |
| const char *AST_OPTIONAL_API_NAME() | ast_websocket_result_to_str (enum ast_websocket_result result) | 
| Convert a websocket result code to a string. | |
| 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. | |
| 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. | |
| struct ast_websocket_server *AST_OPTIONAL_API_NAME() | ast_websocket_server_create (void) | 
| Creates a ast_websocket_server. | |
| 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. | |
| const char *AST_OPTIONAL_API_NAME() | ast_websocket_session_id (struct ast_websocket *session) | 
| Get the session ID for a WebSocket session. | |
| int AST_OPTIONAL_API_NAME() | ast_websocket_set_nonblock (struct ast_websocket *session) | 
| Set the socket of a WebSocket session to be non-blocking. | |
| int AST_OPTIONAL_API_NAME() | ast_websocket_set_timeout (struct ast_websocket *session, int timeout) | 
| Set the timeout on a non-blocking WebSocket session. | |
| struct ast_websocket_protocol *AST_OPTIONAL_API_NAME() | ast_websocket_sub_protocol_alloc (const char *name) | 
| Allocate a websocket sub-protocol instance. | |
| const char * | ast_websocket_type_to_str (enum ast_websocket_type type) | 
| void AST_OPTIONAL_API_NAME() | ast_websocket_unref (struct ast_websocket *session) | 
| Decrease the reference count for a WebSocket session. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| 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. | |
| static int | protocol_cmp_fn (void *obj, void *arg, int flags) | 
| Comparison function for protocols. | |
| static void | protocol_destroy_fn (void *obj) | 
| Destructor function for protocols. | |
| static int | protocol_hash_fn (const void *obj, const int flags) | 
| Hashing function for protocols. | |
| static void | session_destroy_fn (void *obj) | 
| Destructor function for sessions. | |
| 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, char **userinfo) | 
| Parse the given uri into a path and remote address. | |
| 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. | |
| static void | websocket_mask_payload (struct ast_websocket *session, char *frame, char *payload, uint64_t payload_size) | 
| Perform payload masking for client sessions. | |
| 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 = ASTERISK_GPL_KEY , .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 [] | 
| const char * | websocket_result_string_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 AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE | 
Default reconstruction size for multi-frame payload reconstruction. If exceeded the next frame will start a payload.
Definition at line 65 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 78 of file res_http_websocket.c.
| #define MAXIMUM_RECONSTRUCTION_CEILING AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE | 
Maximum reconstruction size for multi-frame payload reconstruction.
Definition at line 68 of file res_http_websocket.c.
| #define MIN_WS_HDR_SZ 2 | 
Definition at line 79 of file res_http_websocket.c.
| #define optional_header_spec "%s%s%s" | 
Definition at line 1442 of file res_http_websocket.c.
Definition at line 1443 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 1663 of file res_http_websocket.c.
| 
 | static | 
Definition at line 1663 of file res_http_websocket.c.
| struct ast_module * AST_MODULE_SELF_SYM | ( | void | ) | 
Definition at line 1663 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 1068 of file res_http_websocket.c.
References callback(), 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 1073 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 1318 of file res_http_websocket.c.
References websocket_client::accept_protocol, and ast_websocket::client.
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 1515 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(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and 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 1529 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_connect(), 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 324 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(), incoming_ws_established_cb(), outbound_session_apply_config(), outbound_session_handler_thread(), outbound_session_pc_close_thread(), outbound_sessions_load(), session_destroy_fn(), session_shutdown_cb(), webchan_hangup(), 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 477 of file res_http_websocket.c.
References ast_iostream_get_fd(), and session.
Referenced by incoming_ws_established_cb(), read_from_ws_and_queue(), session_read(), speech_test_server_cb(), webchan_call(), 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 497 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 492 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 618 of file res_http_websocket.c.
References ast_free, ast_log, ast_realloc, ast_websocket_close(), AST_WEBSOCKET_MAX_RX_PAYLOAD_SIZE, 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, MIN_WS_HDR_SZ, ntohll(), NULL, ast_websocket::opcode, ast_websocket::payload, ast_websocket::payload_len, session, and ws_safe_read().
Referenced by ast_websocket_read_string(), read_from_ws_and_queue(), session_read(), 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 1546 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 462 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 457 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 467 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 487 of file res_http_websocket.c.
References session.
Referenced by ari_websocket_send_event(), session_update(), session_write(), transport_create(), transport_read(), and websocket_established_cb().
| 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 1097 of file res_http_websocket.c.
References callback(), name, and websocket_remove_protocol_internal().
Referenced by AST_TEST_DEFINE(), and unload_module().
| const char *AST_OPTIONAL_API_NAME() ast_websocket_result_to_str | ( | enum ast_websocket_result | result | ) | 
Convert a websocket result code to a string.
| result | The result code to convert | 
Definition at line 1626 of file res_http_websocket.c.
References ARRAY_IN_BOUNDS, result, and websocket_result_string_map.
Referenced by ast_websocket_client_connect(), and webchan_call().
| 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 226 of file res_http_websocket.c.
References ao2_ref, ast_websocket_server_add_protocol2(), ast_websocket_sub_protocol_alloc(), callback(), 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 248 of file res_http_websocket.c.
References ao2_find, ao2_link_flags, ao2_lock, ao2_ref, ao2_unlock, ast_debug, ast_log, AST_WEBSOCKET_PROTOCOL_VERSION, LOG_WARNING, OBJ_KEY, OBJ_NOLOCK, and ast_websocket_server::protocols.
Referenced by ari_websocket_load_module(), 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 183 of file res_http_websocket.c.
References websocket_server_create_impl().
Referenced by ari_websocket_load_module(), and 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 282 of file res_http_websocket.c.
References ao2_find, ao2_ref, ao2_unlink, ast_debug, callback(), 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 516 of file res_http_websocket.c.
References session.
Referenced by websocket_established_cb().
| 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 502 of file res_http_websocket.c.
References ast_iostream_nonblock(), ast_iostream_set_exclusive_input(), and session.
Referenced by session_update(), 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 509 of file res_http_websocket.c.
References session, and ast_websocket::timeout.
Referenced by session_update(), 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 207 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 ari_websocket_load_module(), ast_websocket_server_add_protocol(), and load_module().
| const char * ast_websocket_type_to_str | ( | enum ast_websocket_type | type | ) | 
Definition at line 100 of file res_http_websocket.c.
References AST_WS_TYPE_ANY, AST_WS_TYPE_CLIENT, AST_WS_TYPE_CLIENT_PER_CALL, AST_WS_TYPE_CLIENT_PER_CALL_CONFIG, AST_WS_TYPE_CLIENT_PERSISTENT, AST_WS_TYPE_INBOUND, AST_WS_TYPE_SERVER, and type.
| 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 472 of file res_http_websocket.c.
References ao2_cleanup, and session.
Referenced by incoming_ws_established_cb(), outbound_session_handler_thread(), session_dtor(), speech_test_server_cb(), transport_dtor(), webchan_hangup(), websocket_cb(), websocket_destructor(), websocket_disconnect(), websocket_echo_callback(), and websocket_established_cb().
| 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 806 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, 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(), ast_variable::value, version, websocket_bad_request(), websocket_combine_key(), and WEBSOCKET_GUID.
Referenced by ari_handle_websocket(), and incoming_ws_http_callback().
| 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 482 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 390 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_websocket_read(), ast_websocket_write_string(), speech_test_server_cb(), webchan_write(), 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 1590 of file res_http_websocket.c.
References ast_debug, AST_WEBSOCKET_OPCODE_TEXT, ast_websocket_write(), buf, and len().
Referenced by AST_TEST_DEFINE(), dequeue_frame(), process_text_message(), queue_frame_from_buffer(), read_thread_handler(), session_write(), speech_test_server_handle_request(), and webchan_send_dtmf_text().
| 
 | static | 
Definition at line 1635 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 768 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 132 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 141 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 123 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 189 of file res_http_websocket.c.
References ao2_cleanup, ast_debug, ast_free, ast_iostream_close(), ast_sockaddr_stringify(), ast_websocket_close(), NULL, and session.
Referenced by ast_websocket_uri_cb(), and websocket_client_create().
| 
 | static | 
Definition at line 1647 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 1059 of file res_http_websocket.c.
References ast_websocket_server_add_protocol(), callback(), ast_http_uri::data, name, and websocketuri.
Referenced by ast_websocket_add_protocol(), and load_module().
| 
 | static | 
Definition at line 793 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 1158 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 1142 of file res_http_websocket.c.
References args, ast_free, and ast_ssl_teardown().
Referenced by websocket_client_args_create().
| 
 | static | 
Definition at line 1492 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, websocket_client_handshake(), WS_CLIENT_START_ERROR, and WS_OK.
Referenced by ast_websocket_client_create_with_options().
| 
 | static | 
Definition at line 1254 of file res_http_websocket.c.
References ao2_alloc, ao2_ref, websocket_client::args, ast_asprintf, ast_log, ast_strdup, ast_strlen_zero(), ast_uuid_generate_str(), 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(), ast_websocket::session_id, ast_tcptls_session_args::suppress_connection_msgs, websocket_client::suppress_connection_msgs, ast_websocket::timeout, websocket_client::userinfo, 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 1193 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 1239 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, websocket_client::ser, and websocket_client::userinfo.
Referenced by websocket_client_create().
| 
 | static | 
Definition at line 1324 of file res_http_websocket.c.
References ast_log, ast_websocket::client, websocket_client::host, LOG_ERROR, websocket_client::suppress_connection_msgs, WS_BAD_REQUEST, WS_INVALID_RESPONSE, WS_UNAUTHORIZED, and WS_URL_NOT_FOUND.
Referenced by websocket_client_handshake_get_response().
| 
 | static | 
Definition at line 1448 of file res_http_websocket.c.
References ast_http_create_basic_auth_header(), ast_iostream_printf(), ast_log, ast_str_buffer(), ast_strlen_zero(), ast_variables_destroy(), websocket_client::host, websocket_client::key, LOG_ERROR, NULL, optional_header_spec, print_optional_header, websocket_client::protocols, websocket_client::resource_name, websocket_client::ser, ast_tcptls_session_instance::stream, websocket_client::userinfo, ast_variable::value, websocket_client::version, websocket_client_handshake_get_response(), WS_ALLOCATE_ERROR, and WS_WRITE_ERROR.
Referenced by websocket_client_connect().
| 
 | static | 
Definition at line 1361 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 1110 of file res_http_websocket.c.
References ao2_ref, ast_str_append(), ast_str_create, ast_str_set(), ast_strdup, ast_uri_make_host_with_port(), ast_uri_parse_websocket(), ast_uri_path(), ast_uri_query(), ast_uri_user_info(), ast_uri::host, ast_uri::path, and ast_uri::uri.
Referenced by websocket_client_create().
| 
 | static | 
Definition at line 780 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 1023 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 304 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 379 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 1088 of file res_http_websocket.c.
References ast_websocket_server_remove_protocol(), callback(), ast_http_uri::data, name, and websocketuri.
Referenced by ast_websocket_remove_protocol(), and unload_module().
| 
 | static | 
Definition at line 159 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 152 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 178 of file res_http_websocket.c.
References websocket_server_create_impl().
Referenced by load_module().
| 
 | inlinestatic | 
Definition at line 550 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 1663 of file res_http_websocket.c.
| 
 | static | 
Definition at line 1663 of file res_http_websocket.c.
| 
 | static | 
Definition at line 370 of file res_http_websocket.c.
Referenced by websocket_opcode2str().
| const char* websocket_result_string_map[] | 
Definition at line 1608 of file res_http_websocket.c.
Referenced by ast_websocket_result_to_str().
| 
 | static | 
Definition at line 1013 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().