45#define WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
48#define CLIENT_KEY_SIZE 16
51#define MAX_PROTOCOL_BUCKETS 7
55#define MAXIMUM_FRAME_SIZE 8192
60#define DEFAULT_RECONSTRUCTION_CEILING 8192
63#define MAXIMUM_RECONSTRUCTION_CEILING 8192
66#define MAXIMUM_FRAME_SIZE 65535
71#define DEFAULT_RECONSTRUCTION_CEILING MAXIMUM_FRAME_SIZE
74#define MAXIMUM_RECONSTRUCTION_CEILING MAXIMUM_FRAME_SIZE
84#define MAX_WS_HDR_SZ 14
85#define MIN_WS_HDR_SZ 2
114 return "per_call_config";
132 const char *
name = obj;
141 const char *protocol = arg;
176 if (!server->protocols) {
204 ast_verb(2,
"WebSocket connection %s '%s' closed\n",
session->client ?
"to" :
"from",
223 if (!protocol->
name) {
264 "expected version '%u', got version '%u'\n",
282 ast_verb(5,
"WebSocket registered sub-protocol '%s'\n", protocol->name);
304 ast_verb(5,
"WebSocket unregistered sub-protocol '%s'\n",
name);
315 uint8_t mask_key_idx;
317 uint8_t length = frame[1] & 0x7f;
320 mask_key_idx = length == 126 ? 4 : length == 127 ? 10 : 2;
322 for (i = 0; i < payload_size; i++) {
323 payload[i] ^= ((
char *)&mask_key)[i % 4];
335 char frame[8] = { 0, };
336 int header_size, fsize, res;
343 header_size =
session->client ? 6 : 2;
344 fsize = header_size + 2;
368 ast_verb(2,
"WebSocket connection %s '%s' forcefully closed due to fatal write error\n",
373 return res ==
sizeof(frame);
398 size_t header_size = 2;
403 ast_debug(3,
"Writing websocket %s frame, length %" PRIu64
"\n",
406 if (payload_size < 126) {
407 length = payload_size;
408 }
else if (payload_size < (1 << 16)) {
434 }
else if (length == 127) {
438 memcpy(&frame[header_size],
payload, payload_size);
452 ast_debug(1,
"Closing WS with 1011 because we can't fulfill a write request\n");
495 return &
session->remote_address;
500 return &
session->local_address;
573 errno = ECONNABORTED;
588 if (rlen < 0 &&
errno != EAGAIN) {
627 int mask_present = 0;
628 char *mask =
NULL, *new_payload =
NULL;
645 fin = (
session->buf[0] >> 7) & 1;
646 mask_present = (
session->buf[1] >> 7) & 1;
649 options_len += mask_present ? 4 : 0;
692 (*payload)[pos] ^= mask[pos % 4];
731 session->payload = new_payload;
789 unsigned combined_length = strlen(key) + strlen(
WEBSOCKET_GUID) + 1;
808 ast_str_set(&http_header, 0,
"Sec-WebSocket-Version: 7, 8, 13\r\n");
816 char *requested_protocols =
NULL, *protocol =
NULL;
826 ast_http_error(ser, 501,
"Not Implemented",
"Attempt to use unimplemented / unsupported method");
833 for (v = headers; v; v = v->
next) {
834 if (!strcasecmp(v->
name,
"Upgrade")) {
836 }
else if (!strcasecmp(v->
name,
"Sec-WebSocket-Key")) {
838 }
else if (!strcasecmp(v->
name,
"Sec-WebSocket-Key1")) {
840 }
else if (!strcasecmp(v->
name,
"Sec-WebSocket-Key2")) {
842 }
else if (!strcasecmp(v->
name,
"Sec-WebSocket-Protocol")) {
844 }
else if (!strcasecmp(v->
name,
"Sec-WebSocket-Version")) {
853 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - did not request WebSocket\n",
862 if (!protocol_handler) {
864 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - no protocols requested\n",
869 }
else if (key1 && key2) {
872 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - unsupported version '00/76' chosen\n",
878 if (!protocol_handler && protos) {
881 while (!protocol_handler && (protocol =
strsep(&requested_protocols,
","))) {
887 if (!protocol_handler) {
888 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - no protocols out of '%s' supported\n",
921 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - failed to generate a session id\n",
923 ast_http_error(ser, 500,
"Internal Server Error",
"Allocation failed");
930 ast_debug(3,
"WebSocket connection from '%s' rejected by protocol handler '%s'\n",
948 "HTTP/1.1 101 Switching Protocols\r\n"
950 "Connection: Upgrade\r\n"
951 "Sec-WebSocket-Accept: %s\r\n"
952 "Sec-WebSocket-Protocol: %s\r\n\r\n",
958 "HTTP/1.1 101 Switching Protocols\r\n"
960 "Connection: Upgrade\r\n"
961 "Sec-WebSocket-Accept: %s\r\n\r\n",
968 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - unsupported version '%d' chosen\n",
977 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - failed to enable keepalive\n",
987 ast_log(
LOG_WARNING,
"WebSocket connection from '%s' could not be accepted - failed to get local address\n",
1007 ao2_ref(protocol_handler, -1);
1021 .description =
"Asterisk HTTP WebSocket",
1033 ast_debug(1,
"Entering WebSocket echo loop\n");
1041 uint64_t payload_len;
1056 ast_debug(1,
"Ignored WebSocket opcode %u\n", opcode);
1061 ast_debug(1,
"Exiting WebSocket echo loop\n");
1117 struct ast_str **path,
char **userinfo)
1152 if (
args->tls_cfg) {
1177 args->accept_fd = -1;
1179 args->name =
"websocket client";
1192 snprintf(
args->hostname,
sizeof(
args->hostname),
1194 (
int) strcspn(host,
":"), host);
1214 memcpy(key + i, &num,
sizeof(
long));
1327 return ws->client->accept_protocol;
1333 if (response_code <= 0) {
1337 switch (response_code) {
1373 int has_upgrade = 0;
1374 int has_connection = 0;
1376 int has_protocol = 0;
1389 buf,
"HTTP/1.1", 101))) !=
WS_OK) {
1418 name,
"upgrade",
value,
"websocket")) < 0) {
1420 }
else if (!has_connection &&
1422 name,
"connection",
value,
"upgrade")) < 0) {
1424 }
else if (!has_accept &&
1430 }
else if (!has_protocol &&
1433 if (has_protocol < 0) {
1437 }
else if (!strcasecmp(
name,
"sec-websocket-extensions")) {
1439 "supported by client\n");
1444 return has_upgrade && has_connection && has_accept ?
1448#define optional_header_spec "%s%s%s"
1449#define print_optional_header(test, name, value) \
1451 test ? value : "", \
1457 size_t protocols_len = 0;
1472 "GET /%s HTTP/1.1\r\n"
1473 "Sec-WebSocket-Version: %d\r\n"
1474 "Upgrade: websocket\r\n"
1475 "Connection: Upgrade\r\n"
1479 "Sec-WebSocket-Key: %s\r\n"
1522 (
const char *uri,
const char *protocols,
struct ast_tls_config *tls_cfg,
1560 while (fragmented) {
1564 "error reading string data\n");
1584 "non string data received\n");
1599 uint64_t
len = strlen(
buf);
1601 ast_debug(3,
"Writing websocket string of length %" PRIu64
"\n",
len);
uint64_t ntohll(uint64_t net64)
char * strsep(char **str, const char *delims)
uint64_t htonll(uint64_t host64)
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ast_strndup(str, len)
A wrapper for strndup()
#define ast_realloc(p, len)
A wrapper for realloc()
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
#define ast_malloc(len)
A wrapper for malloc()
@ AO2_ALLOC_OPT_LOCK_MUTEX
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_unlink(container, obj)
Remove an object from a container.
#define ao2_link_flags(container, obj, flags)
Add an object to a container.
#define ao2_find(container, arg, flags)
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
@ OBJ_NOLOCK
Assume that the ao2_container is already locked.
#define ao2_alloc(data_size, destructor_fn)
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
static char version[AST_MAX_EXTENSION]
static struct ast_channel * callback(struct ast_channelstorage_instance *driver, ao2_callback_data_fn *cb_fn, void *arg, void *data, int ao2_flags)
Generic File Format Support. Should be included by clients of the file handling routines....
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Support for Private Asterisk HTTP Servers.
void ast_http_send(struct ast_tcptls_session_instance *ser, enum ast_http_method method, int status_code, const char *status_title, struct ast_str *http_header, struct ast_str *out, int fd, unsigned int static_content)
Generic function for sending HTTP/1.1 response.
ast_http_method
HTTP Request methods known by Asterisk.
int ast_http_header_parse(char *buf, char **name, char **value)
Parse a header into the given name/value strings.
int ast_http_header_match_in(const char *name, const char *expected_name, const char *value, const char *expected_value)
Check if the header name matches the expected header name. If so, then check to see if the value can ...
void ast_http_uri_unlink(struct ast_http_uri *urihandler)
Unregister a URI handler.
int ast_http_body_discard(struct ast_tcptls_session_instance *ser)
Read and discard any unread HTTP request body.
struct ast_variable * ast_http_create_basic_auth_header(const char *userid, const char *password)
Create an HTTP authorization header.
int ast_http_header_match(const char *name, const char *expected_name, const char *value, const char *expected_value)
Check if the header and value match (case insensitive) their associated expected values.
int ast_http_response_status_line(const char *buf, const char *version, int code)
Parse the http response status line.
void ast_http_request_close_on_completion(struct ast_tcptls_session_instance *ser)
Request the HTTP connection be closed after this HTTP request.
void ast_http_error(struct ast_tcptls_session_instance *ser, int status, const char *title, const char *text)
Send HTTP error message and close socket.
int ast_http_uri_link(struct ast_http_uri *urihandler)
Register a URI handler.
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
#define AST_WEBSOCKET_PROTOCOL_VERSION
Protocol version. This prevents dynamically loadable modules from registering if this struct is chang...
ast_websocket_result
Result code for a websocket client.
#define AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT
Default websocket write timeout, in ms.
ast_websocket_opcode
WebSocket operation codes.
@ AST_WEBSOCKET_OPCODE_PING
@ AST_WEBSOCKET_OPCODE_PONG
@ AST_WEBSOCKET_OPCODE_CONTINUATION
@ AST_WEBSOCKET_OPCODE_BINARY
@ AST_WEBSOCKET_OPCODE_CLOSE
@ AST_WEBSOCKET_OPCODE_TEXT
ast_websocket_type
WebSocket connection/configuration types.
@ AST_WS_TYPE_CLIENT_PER_CALL_CONFIG
@ AST_WS_TYPE_CLIENT_PERSISTENT
@ AST_WS_TYPE_CLIENT_PER_CALL
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.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_verb(level,...)
ssize_t ast_iostream_printf(struct ast_iostream *stream, const char *format,...)
Write a formatted string to an iostream.
ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size)
Read a LF-terminated string from an iostream.
void ast_iostream_set_timeout_inactivity(struct ast_iostream *stream, int timeout)
Set the iostream inactivity timeout timer.
SSL * ast_iostream_get_ssl(struct ast_iostream *stream)
Get a pointer to an iostream's OpenSSL SSL structure.
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream's file descriptor.
void ast_iostream_set_exclusive_input(struct ast_iostream *stream, int exclusive_input)
Set the iostream if it can exclusively depend upon the set timeouts.
ssize_t ast_iostream_read(struct ast_iostream *stream, void *buffer, size_t count)
Read data from an iostream.
void ast_iostream_set_timeout_sequence(struct ast_iostream *stream, struct timeval start, int timeout)
Set the iostream I/O sequence timeout timer.
void ast_iostream_nonblock(struct ast_iostream *stream)
Make an iostream non-blocking.
int ast_iostream_close(struct ast_iostream *stream)
Close an iostream.
void ast_iostream_set_timeout_disable(struct ast_iostream *stream)
Disable the iostream timeout timer.
int ast_iostream_wait_for_input(struct ast_iostream *stream, int timeout)
Wait for input on the iostream's file descriptor.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
Asterisk module definitions.
#define SCOPED_MODULE_USE(module)
@ AST_MODFLAG_GLOBAL_SYMBOLS
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_CHANNEL_DEPEND
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
int ast_getsockname(int sockfd, struct ast_sockaddr *addr)
Wrapper around getsockname(2) that uses struct ast_sockaddr.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
#define AST_OPTIONAL_API_NAME(name)
Expands to the name of the implementation function.
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.
void AST_OPTIONAL_API_NAME() ast_websocket_ref(struct ast_websocket *session)
Increase the reference count for a WebSocket session.
#define MAXIMUM_FRAME_SIZE
Size of the pre-determined buffer for WebSocket frames.
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.
const char *AST_OPTIONAL_API_NAME() ast_websocket_session_id(struct ast_websocket *session)
Get the session ID for a WebSocket session.
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 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.
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.
static void websocket_bad_request(struct ast_tcptls_session_instance *ser)
static struct ast_http_uri websocketuri
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.
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.
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.
static enum ast_websocket_result websocket_client_handshake_get_response(struct websocket_client *client)
static struct ast_websocket_protocol * one_protocol(struct ast_websocket_server *server)
If the server has exactly one configured protocol, return it.
static void websocket_client_args_destroy(void *obj)
static int ws_safe_read(struct ast_websocket *session, char *buf, size_t len, enum ast_websocket_opcode *opcode)
struct ast_sockaddr *AST_OPTIONAL_API_NAME() ast_websocket_local_address(struct ast_websocket *session)
Get the local address for a WebSocket connection session.
static enum ast_websocket_result websocket_client_connect(struct ast_websocket *ws, int timeout)
static int websocket_remove_protocol_internal(const char *name, ast_websocket_callback callback)
static struct ast_websocket * websocket_client_create(struct ast_websocket_client_options *options, enum ast_websocket_result *result)
#define optional_header_spec
#define MAX_PROTOCOL_BUCKETS
Number of buckets for registered protocols.
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_sockaddr *AST_OPTIONAL_API_NAME() ast_websocket_remote_address(struct ast_websocket *session)
Get the remote address for a WebSocket connected session.
static struct ast_websocket_server * websocket_server_internal_create(void)
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_is_secure(struct ast_websocket *session)
Get whether the WebSocket session is using a secure transport or not.
static void websocket_server_dtor(void *obj)
static enum ast_websocket_result websocket_client_handshake(struct websocket_client *client)
static void websocket_mask_payload(struct ast_websocket *session, char *frame, char *payload, uint64_t payload_size)
Perform payload masking for client sessions.
void AST_OPTIONAL_API_NAME() ast_websocket_reconstruct_disable(struct ast_websocket *session)
Disable multi-frame reconstruction.
static int protocol_cmp_fn(void *obj, void *arg, int flags)
Comparison function for protocols.
#define DEFAULT_RECONSTRUCTION_CEILING
Default reconstruction size for multi-frame payload reconstruction. If exceeded the next frame will s...
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.
static char * websocket_client_create_key(void)
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.
const char * ast_websocket_type_to_str(enum ast_websocket_type type)
int AST_OPTIONAL_API_NAME() ast_websocket_fd(struct ast_websocket *session)
Get the file descriptor for a WebSocket session.
static void protocol_destroy_fn(void *obj)
Destructor function for protocols.
static char * websocket_combine_key(const char *key, char *res, int res_size)
#define print_optional_header(test, name, value)
static struct ast_websocket_server * websocket_server_create_impl(void)
const char *AST_OPTIONAL_API_NAME() ast_websocket_client_accept_protocol(struct ast_websocket *ws)
Retrieve the server accepted sub-protocol on the client.
static int protocol_hash_fn(const void *obj, const int flags)
Hashing function for protocols.
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_server_add_protocol(struct ast_websocket_server *server, const char *name, ast_websocket_callback callback)
Add a sub-protocol handler to the given server.
static int websocket_add_protocol_internal(const char *name, ast_websocket_callback callback)
#define CLIENT_KEY_SIZE
Length of a websocket's client key.
static int load_module(void)
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.
static int unload_module(void)
#define WEBSOCKET_GUID
GUID used to compute the accept key, defined in the specifications.
const char * websocket_result_string_map[]
struct ast_websocket_protocol *AST_OPTIONAL_API_NAME() ast_websocket_sub_protocol_alloc(const char *name)
Allocate a websocket sub-protocol instance.
int AST_OPTIONAL_API_NAME() ast_websocket_set_timeout(struct ast_websocket *session, int timeout)
Set the timeout on a non-blocking WebSocket 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_close(struct ast_websocket *session, uint16_t reason)
Close function for websocket session.
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_remove_protocol(const char *name, ast_websocket_callback callback)
Remove a sub-protocol handler from the default /ws server.
static void session_destroy_fn(void *obj)
Destructor function for sessions.
void AST_OPTIONAL_API_NAME() ast_websocket_unref(struct ast_websocket *session)
Decrease the reference count for a WebSocket session.
static const char * websocket_opcode2str(enum ast_websocket_opcode opcode)
static const char * opcode_map[]
static struct ast_tcptls_session_args * websocket_client_args_create(const char *host, struct ast_tls_config *tls_cfg, enum ast_websocket_result *result)
int AST_OPTIONAL_API_NAME() ast_websocket_read_string(struct ast_websocket *ws, char **buf)
Read a WebSocket frame containing string data.
int AST_OPTIONAL_API_NAME() ast_websocket_add_protocol2(struct ast_websocket_protocol *protocol)
Add a sub-protocol handler to the default /ws server.
#define MAXIMUM_RECONSTRUCTION_CEILING
Maximum reconstruction size for multi-frame payload reconstruction.
const char *AST_OPTIONAL_API_NAME() ast_websocket_result_to_str(enum ast_websocket_result result)
Convert a websocket result code to a string.
String manipulation functions.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition of a URI handler.
ast_http_callback callback
Socket address structure.
Support for dynamic strings.
arguments for the accepting thread
struct ast_tls_config * tls_cfg
int suppress_connection_msgs
describes a server instance
struct ast_iostream * stream
struct ast_sockaddr remote_address
Stores parsed uri information.
Structure for variables, used for configurations and for channel variables.
struct ast_variable * next
Options used for a websocket client.
struct ast_tls_config * tls_cfg
A websocket protocol implementation.
ast_websocket_callback session_established
Callback called when a new session is established. Mandatory.
unsigned int version
Protocol version. Should be set to /ref AST_WEBSOCKET_PROTOCOL_VERSION.
char * name
Name of the protocol.
ast_websocket_pre_callback session_attempted
Callback called when a new session is attempted. Optional.
Structure for a WebSocket server.
struct ao2_container * protocols
Structure definition for session.
char buf[MAXIMUM_FRAME_SIZE]
struct ast_iostream * stream
struct websocket_client * client
struct ast_sockaddr local_address
uint16_t close_status_code
struct ast_sockaddr remote_address
char session_id[AST_UUID_STR_LEN]
enum ast_websocket_opcode opcode
struct ast_tcptls_session_args * args
struct ast_tcptls_session_instance * ser
struct ast_str * resource_name
int suppress_connection_msgs
void ast_ssl_teardown(struct ast_tls_config *cfg)
free resources used by an SSL server
struct ast_tcptls_session_instance * ast_tcptls_client_create(struct ast_tcptls_session_args *desc)
Creates a client connection's ast_tcptls_session_instance.
struct ast_tcptls_session_instance * ast_tcptls_client_start_timeout(struct ast_tcptls_session_instance *tcptls_session, int timeout)
Attempt to connect and start a tcptls session within the given timeout.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Handle unaligned data access.
static void put_unaligned_uint16(void *p, unsigned short datum)
static unsigned short get_unaligned_uint16(const void *p)
static void put_unaligned_uint64(void *p, uint64_t datum)
static void put_unaligned_uint32(void *p, unsigned int datum)
static uint64_t get_unaligned_uint64(const void *p)
const char * ast_uri_path(const struct ast_uri *uri)
Retrieve the uri path.
struct ast_uri * ast_uri_parse_websocket(const char *uri)
Parse the given websocket uri into a structure.
const char * ast_uri_query(const struct ast_uri *uri)
Retrieve the uri query parameters.
const char * ast_uri_user_info(const struct ast_uri *uri)
Retrieve the uri user information.
char * ast_uri_make_host_with_port(const struct ast_uri *uri)
Retrieve a string of the host and port.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max)
Encode data in base64.
long int ast_random(void)
#define ast_fd_set_flags(fd, flags)
Set flags on the given file descriptor.
#define ARRAY_IN_BOUNDS(v, a)
Checks to see if value is within the bounds of the given array.
void ast_sha1_hash_uint(uint8_t *digest, const char *input)
Produces SHA1 hash based on input string, stored in uint8_t array.
Universally unique identifier support.
char * ast_uuid_generate_str(char *buf, size_t size)
Generate a UUID string.