Asterisk - The Open Source Telephony Project GIT-master-754dea3
|
WebSocket support for RESTful API's. More...
#include "asterisk.h"
#include "resource_events.h"
#include "ari_websockets.h"
#include "internal.h"
#include "asterisk/app.h"
#include "asterisk/ari.h"
#include "asterisk/astobj2.h"
#include "asterisk/http_websocket.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
Go to the source code of this file.
Macros | |
#define | APPS_NUM_BUCKETS 7 |
#define | ARI_WS_SESSION_NUM_BUCKETS 23 |
#define | MAX_VALS 128 |
#define | MESSAGES_INIT_SIZE 23 |
#define | VALIDATION_FAILED |
Variables | |
static struct ao2_container * | ari_ws_session_registry |
Local registry for created event_session objects. More... | |
struct ast_websocket_server * | ast_ws_server |
WebSocket support for RESTful API's.
Definition in file ari_websockets.c.
#define APPS_NUM_BUCKETS 7 |
Number of buckets for a websocket apps container. Remember to keep it a prime number!
Definition at line 45 of file ari_websockets.c.
#define ARI_WS_SESSION_NUM_BUCKETS 23 |
Number of buckets for the event session registry. Remember to keep it a prime number!
Definition at line 42 of file ari_websockets.c.
#define MAX_VALS 128 |
Definition at line 56 of file ari_websockets.c.
#define MESSAGES_INIT_SIZE 23 |
Initial size of a message queue.
Definition at line 48 of file ari_websockets.c.
#define VALIDATION_FAILED |
Definition at line 66 of file ari_websockets.c.
AO2_STRING_FIELD_CMP_FN | ( | ari_ws_session | , |
session_id | |||
) |
AO2_STRING_FIELD_HASH_FN | ( | ari_ws_session | , |
session_id | |||
) |
void ari_handle_websocket | ( | struct ast_tcptls_session_instance * | ser, |
const char * | uri, | ||
enum ast_http_method | method, | ||
struct ast_variable * | get_params, | ||
struct ast_variable * | headers | ||
) |
Wrapper for invoking the websocket code for an incoming connection.
ws_server | WebSocket server to invoke. |
ser | HTTP session. |
uri | Requested URI. |
method | Requested HTTP method. |
get_params | Parsed query parameters. |
headers | Parsed HTTP headers. |
Definition at line 221 of file ari_websockets.c.
References ast_websocket_uri_cb(), ast_ws_server, ast_http_uri::data, method, and ast_http_uri::uri.
Referenced by ast_ari_invoke().
int ari_websocket_load_module | ( | void | ) |
Definition at line 722 of file ari_websockets.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ao2_ref, ARI_WS_SESSION_NUM_BUCKETS, ari_ws_session_registry, ari_ws_session_registry_dtor(), ast_log, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_websocket_server_add_protocol2(), ast_websocket_server_create(), ast_websocket_sub_protocol_alloc(), ast_ws_server, LOG_WARNING, NULL, ast_websocket_protocol::session_attempted, ast_websocket_protocol::session_established, websocket_attempted_cb(), and websocket_established_cb().
Referenced by load_module().
void ari_websocket_send_event | ( | struct ari_ws_session * | ari_ws_session, |
const char * | app_name, | ||
struct ast_json * | message, | ||
int | debug_app | ||
) |
Callback handler for Stasis application messages.
Definition at line 244 of file ari_websockets.c.
References ao2_find, ao2_lock, ao2_unlock, app_name(), ari_ws_session_write(), ast_assert, ast_eid_default, ast_eid_to_str(), ast_json_dump_string_format(), ast_json_free(), ast_json_object_get(), ast_json_object_set(), AST_JSON_PRETTY, ast_json_ref(), ast_json_string_create(), ast_json_string_get(), ast_json_timeval(), ast_log, ast_sockaddr_stringify(), ast_strlen_zero(), ast_tvnow(), AST_VECTOR_APPEND, ast_verbose(), ast_websocket_remote_address(), ari_ws_session::ast_ws_session, LOG_WARNING, ari_ws_session::message_queue, msg_timestamp(), NULL, OBJ_NODATA, OBJ_UNLINK, S_OR, SCOPE_ENTER, SCOPE_EXIT, SCOPE_EXIT_LOG_RTN, stasis_app_event_allowed(), str, TRACE_ATLEAST, and ari_ws_session::websocket_apps.
Referenced by ari_ws_session_read(), send_rest_response(), and stasis_app_message_handler().
int ari_websocket_unload_module | ( | void | ) |
Definition at line 711 of file ari_websockets.c.
References ao2_cleanup, ari_ws_session_registry_dtor(), ast_ws_server, and NULL.
Referenced by unload_module().
|
static |
Definition at line 447 of file ari_websockets.c.
References ao2_ref, ao2_unlink, ari_ws_session_registry, and ari_ws_session_reset().
Referenced by ari_ws_session_shutdown_cb(), and websocket_established_cb().
|
static |
Definition at line 477 of file ari_websockets.c.
References ao2_alloc, ao2_cleanup, ao2_link, app, ari_ws_session::app_name, APPS_NUM_BUCKETS, args, ari_ws_session_dtor(), ari_ws_session_registry, ari_ws_session_reset(), ast_http_error(), ast_log, ast_str_container_add(), ast_str_container_alloc, ast_strdup, ast_strlen_zero(), AST_VECTOR_INIT, handler(), LOG_WARNING, ari_ws_session::message_queue, MESSAGES_INIT_SIZE, NULL, null_validator(), RAII_VAR, ari_ws_session::session_id, stasis_app_message_handler(), stasis_app_register(), stasis_app_register_all(), ari_ws_session::validator, and ari_ws_session::websocket_apps.
Referenced by websocket_attempted_cb().
|
static |
Definition at line 465 of file ari_websockets.c.
References ari_ws_session::app_name, ast_free, ast_websocket_unref(), ari_ws_session::ast_ws_session, and NULL.
Referenced by ari_ws_session_create().
|
static |
Definition at line 153 of file ari_websockets.c.
References ari_ws_session::app_name, ari_websocket_send_event(), ast_debug, ast_json_load_buf(), ast_json_pack(), ast_json_ref(), ast_json_unref(), ast_log, ast_wait_for_input(), ast_websocket_fd(), AST_WEBSOCKET_OPCODE_CLOSE, AST_WEBSOCKET_OPCODE_TEXT, ast_websocket_read(), ari_ws_session::ast_ws_session, errno, error(), LOG_WARNING, NULL, and RAII_VAR.
Referenced by websocket_established_cb().
|
static |
Definition at line 698 of file ari_websockets.c.
References ao2_callback, ao2_cleanup, ari_ws_session_registry, ari_ws_session_shutdown_cb(), NULL, OBJ_MULTIPLE, and OBJ_NODATA.
Referenced by ari_websocket_load_module(), and ari_websocket_unload_module().
|
static |
Definition at line 414 of file ari_websockets.c.
References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, app, ast_json_unref(), AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, lock, ari_ws_session::message_queue, NULL, SCOPED_AO2LOCK, stasis_app_unregister(), and ari_ws_session::websocket_apps.
Referenced by ari_ws_session_cleanup(), and ari_ws_session_create().
|
static |
Definition at line 691 of file ari_websockets.c.
References ari_ws_session_cleanup().
Referenced by ari_ws_session_registry_dtor().
|
static |
Definition at line 111 of file ari_websockets.c.
References ao2_cleanup, ao2_lock, ao2_ref, ao2_unlock, ari_ws_session_write(), ast_ari_config_get(), ast_json_unref(), ast_log, AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_GET, AST_VECTOR_RESET, AST_VECTOR_SIZE, ast_websocket_set_nonblock(), ast_websocket_set_timeout(), ari_ws_session::ast_ws_session, config, errno, LOG_ERROR, LOG_WARNING, ari_ws_session::message_queue, NULL, and RAII_VAR.
Referenced by websocket_established_cb().
|
static |
Definition at line 72 of file ari_websockets.c.
References ast_ari_json_format(), ast_json_dump_string_format(), ast_json_free(), ast_log, ast_sockaddr_stringify(), ast_websocket_remote_address(), ast_websocket_write_string(), ari_ws_session::ast_ws_session, LOG_ERROR, LOG_NOTICE, NULL, RAII_VAR, str, VALIDATION_FAILED, and ari_ws_session::validator.
Referenced by ari_websocket_send_event(), and ari_ws_session_update().
|
static |
Validator that always succeeds.
Definition at line 61 of file ari_websockets.c.
Referenced by ari_ws_session_create().
|
static |
Definition at line 339 of file ari_websockets.c.
References args, ARRAY_LEN, ast_app_separate_args, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_free, ast_malloc, ast_strdup, ast_true(), MAX_VALS, ast_variable::name, ast_variable::next, NULL, RAII_VAR, and ast_variable::value.
Referenced by websocket_attempted_cb().
|
static |
Definition at line 330 of file ari_websockets.c.
References app_name(), ari_websocket_send_event(), ast_assert, NULL, and stasis_app_get_debug_by_name().
Referenced by ari_ws_session_create().
|
static |
Definition at line 579 of file ari_websockets.c.
References args, ari_ws_session_create(), ast_ari_validate_message_fn(), ast_calloc, ast_free, ast_http_error(), ast_json_dump_string, ast_json_free(), ast_log, ast_sockaddr_stringify(), LOG_ERROR, NULL, parse_app_args(), RAII_VAR, and ast_tcptls_session_instance::remote_address.
Referenced by ari_websocket_load_module().
|
static |
Definition at line 638 of file ari_websockets.c.
References ao2_find, ao2_unlink, ari_ws_session::app_name, ari_websocket_process_request(), ari_ws_session_cleanup(), ari_ws_session_read(), ari_ws_session_registry, ari_ws_session_update(), ast_calloc, ast_free, ast_json_unref(), ast_sockaddr_stringify(), ast_trace, ast_websocket_remote_address(), ast_websocket_session_id(), ast_websocket_unref(), LOG_ERROR, ast_variable::name, ast_variable::next, NULL, OBJ_SEARCH_KEY, RAII_VAR, SCOPE_ENTER, SCOPE_EXIT, SCOPE_EXIT_LOG_RTN, TRACE_ATLEAST, and ast_variable::value.
Referenced by ari_websocket_load_module().
|
static |
Local registry for created event_session objects.
Definition at line 52 of file ari_websockets.c.
Referenced by ari_websocket_load_module(), ari_ws_session_cleanup(), ari_ws_session_create(), ari_ws_session_registry_dtor(), and websocket_established_cb().
struct ast_websocket_server* ast_ws_server |
Definition at line 54 of file ari_websockets.c.
Referenced by ari_handle_websocket(), ari_websocket_load_module(), and ari_websocket_unload_module().