Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to a server. More...
Go to the source code of this file.
Data Structures | |
struct | ast_websocket_client_options |
Options used for a websocket client. More... | |
struct | ast_websocket_protocol |
A websocket protocol implementation. More... | |
Macros | |
#define | AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT 100 |
Default websocket write timeout, in ms. More... | |
#define | AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR "100" |
Default websocket write timeout, in ms (as a string) More... | |
#define | AST_WEBSOCKET_PROTOCOL_VERSION 1 |
Protocol version. This prevents dynamically loadable modules from registering if this struct is changed. More... | |
Typedefs | |
typedef void(* | ast_websocket_callback) (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers) |
Callback for when a new connection for a sub-protocol is established. More... | |
typedef int(* | ast_websocket_pre_callback) (struct ast_tcptls_session_instance *ser, struct ast_variable *parameters, struct ast_variable *headers, const char *session_id) |
Callback from the HTTP request attempting to establish a websocket connection. More... | |
Enumerations | |
enum | ast_websocket_opcode { AST_WEBSOCKET_OPCODE_TEXT = 0x1 , AST_WEBSOCKET_OPCODE_BINARY = 0x2 , AST_WEBSOCKET_OPCODE_PING = 0x9 , AST_WEBSOCKET_OPCODE_PONG = 0xA , AST_WEBSOCKET_OPCODE_CLOSE = 0x8 , AST_WEBSOCKET_OPCODE_CONTINUATION = 0x0 } |
WebSocket operation codes. More... | |
enum | ast_websocket_result { WS_OK , WS_ALLOCATE_ERROR , WS_KEY_ERROR , WS_URI_PARSE_ERROR , WS_URI_RESOLVE_ERROR , WS_BAD_STATUS , WS_INVALID_RESPONSE , WS_BAD_REQUEST , WS_URL_NOT_FOUND , WS_HEADER_MISMATCH , WS_HEADER_MISSING , WS_NOT_SUPPORTED , WS_WRITE_ERROR , WS_CLIENT_START_ERROR } |
Result code for a websocket client. More... | |
Functions | |
int | ast_websocket_add_protocol (const char *name, ast_websocket_callback callback) |
Add a sub-protocol handler to the default /ws server. More... | |
int | ast_websocket_add_protocol2 (struct ast_websocket_protocol *protocol) |
Add a sub-protocol handler to the default /ws server. More... | |
const char * | ast_websocket_client_accept_protocol (struct ast_websocket *ws) |
Retrieve the server accepted sub-protocol on the client. More... | |
struct ast_websocket * | 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_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_websocket_close (struct ast_websocket *session, uint16_t reason) |
Close a WebSocket session by sending a message with the CLOSE opcode and an optional code. More... | |
int | ast_websocket_fd (struct ast_websocket *session) |
Get the file descriptor for a WebSocket session. More... | |
int | 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_websocket_local_address (struct ast_websocket *session) |
Get the local address for a WebSocket connection session. More... | |
int | 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_websocket_read_string (struct ast_websocket *ws, char **buf) |
Read a WebSocket frame containing string data. More... | |
void | ast_websocket_reconstruct_disable (struct ast_websocket *session) |
Disable multi-frame reconstruction. More... | |
void | 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_websocket_ref (struct ast_websocket *session) |
Increase the reference count for a WebSocket session. More... | |
struct ast_sockaddr * | ast_websocket_remote_address (struct ast_websocket *session) |
Get the remote address for a WebSocket connected session. More... | |
int | ast_websocket_remove_protocol (const char *name, ast_websocket_callback callback) |
Remove a sub-protocol handler from the default /ws server. More... | |
int | 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_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_websocket_server_create (void) |
Creates a ast_websocket_server. More... | |
int | 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_websocket_session_id (struct ast_websocket *session) |
Get the session ID for a WebSocket session. More... | |
int | ast_websocket_set_nonblock (struct ast_websocket *session) |
Set the socket of a WebSocket session to be non-blocking. More... | |
int | 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_websocket_sub_protocol_alloc (const char *name) |
Allocate a websocket sub-protocol instance. More... | |
void | ast_websocket_unref (struct ast_websocket *session) |
Decrease the reference count for a WebSocket session. More... | |
int | 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_websocket_wait_for_input (struct ast_websocket *session, int timeout) |
Wait for the WebSocket session to be ready to be read. More... | |
int | ast_websocket_write (struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t payload_size) |
Construct and transmit a WebSocket frame. More... | |
int | ast_websocket_write_string (struct ast_websocket *ws, const char *buf) |
Construct and transmit a WebSocket frame containing string data. More... | |
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to a server.
Supported WebSocket versions in server implementation: Version 7 defined in specification http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-07 Version 8 defined in specification http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10 Version 13 defined in specification http://tools.ietf.org/html/rfc6455 Supported WebSocket versions in client implementation: Version 13 defined in specification http://tools.ietf.org/html/rfc6455
Definition in file http_websocket.h.
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT 100 |
Default websocket write timeout, in ms.
Definition at line 28 of file http_websocket.h.
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR "100" |
Default websocket write timeout, in ms (as a string)
Definition at line 31 of file http_websocket.h.
#define AST_WEBSOCKET_PROTOCOL_VERSION 1 |
Protocol version. This prevents dynamically loadable modules from registering if this struct is changed.
Definition at line 120 of file http_websocket.h.
typedef void(* ast_websocket_callback) (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers) |
Callback for when a new connection for a sub-protocol is established.
session | A WebSocket session structure |
parameters | Parameters extracted from the request URI |
headers | Headers included in the request |
Definition at line 101 of file http_websocket.h.
typedef int(* ast_websocket_pre_callback) (struct ast_tcptls_session_instance *ser, struct ast_variable *parameters, struct ast_variable *headers, const char *session_id) |
Callback from the HTTP request attempting to establish a websocket connection.
This callback occurs when an HTTP request is made to establish a websocket connection. Implementers of ast_websocket_protocol can use this to deny a request, or to set up application specific data before invocation of ast_websocket_callback.
ser | The TCP/TLS session |
parameters | Parameters extracted from the request URI |
headers | Headers included in the request |
session_id | The id of the current session. |
0 | The session should be accepted |
-1 | The session should be rejected. Note that the caller must send an error response using ast_http_error. |
Definition at line 88 of file http_websocket.h.
enum ast_websocket_opcode |
WebSocket operation codes.
Definition at line 51 of file http_websocket.h.
enum ast_websocket_result |
Result code for a websocket client.
Definition at line 399 of file http_websocket.h.
int 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_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_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_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_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_websocket_close | ( | struct ast_websocket * | session, |
uint16_t | reason | ||
) |
Close a WebSocket session by sending a message with the CLOSE opcode and an optional code.
session | Pointer to the WebSocket session |
reason | Reason code for closing the session as defined in the RFC |
0 | if successfully written |
-1 | if error occurred |
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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_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_websocket_write | ( | struct ast_websocket * | session, |
enum ast_websocket_opcode | opcode, | ||
char * | payload, | ||
uint64_t | payload_size | ||
) |
Construct and transmit a WebSocket frame.
session | Pointer to the WebSocket session |
opcode | WebSocket operation code to place in the frame |
payload | Optional pointer to a payload to add to the frame |
payload_size | Length of the payload (0 if no payload) |
0 | if successfully written |
-1 | if error occurred |
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_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().