|
Asterisk - The Open Source Telephony Project
18.5.0
|
/api-docs/events.{format} implementation- WebSocket resource More...
#include "asterisk.h"#include "resource_events.h"#include "asterisk/astobj2.h"#include "asterisk/http_websocket.h"#include "asterisk/stasis_app.h"#include "asterisk/vector.h"
Go to the source code of this file.
Data Structures | |
| struct | event_session |
| A wrapper for the /ref ast_ari_websocket_session. More... | |
Macros | |
| #define | APPS_NUM_BUCKETS 7 |
| #define | EVENT_SESSION_NUM_BUCKETS 23 |
| #define | MESSAGES_INIT_SIZE 23 |
Enumerations | |
| enum | event_session_error_type { ERROR_TYPE_STASIS_REGISTRATION = 1, ERROR_TYPE_OOM = 2, ERROR_TYPE_MISSING_APP_PARAM = 3, ERROR_TYPE_INVALID_APP_PARAM = 4 } |
| event_session error types. More... | |
Functions | |
| void | ast_ari_events_user_event (struct ast_variable *headers, struct ast_ari_events_user_event_args *args, struct ast_ari_response *response) |
| Generate a user event. More... | |
| int | ast_ari_websocket_events_event_websocket_attempted (struct ast_tcptls_session_instance *ser, struct ast_variable *headers, struct ast_ari_events_event_websocket_args *args, const char *session_id) |
| WebSocket connection for events. More... | |
| void | ast_ari_websocket_events_event_websocket_dtor (void) |
| WebSocket connection for events. More... | |
| void | ast_ari_websocket_events_event_websocket_established (struct ast_ari_websocket_session *ws_session, struct ast_variable *headers, struct ast_ari_events_event_websocket_args *args) |
| WebSocket connection for events. More... | |
| int | ast_ari_websocket_events_event_websocket_init (void) |
| WebSocket connection for events. More... | |
| static int | event_session_alloc (struct ast_tcptls_session_instance *ser, struct ast_ari_events_event_websocket_args *args, const char *session_id) |
| Creates an event_session object and registers its apps with Stasis. More... | |
| static int | event_session_allocation_error_handler (struct event_session *session, enum event_session_error_type error, struct ast_tcptls_session_instance *ser) |
| Handles event_session error processing. More... | |
| static void | event_session_cleanup (struct event_session *session) |
| Processes cleanup actions for a event_session object. More... | |
| static int | event_session_compare (void *obj, void *arg, int flags) |
| AO2 comparison function for event_session objects. More... | |
| static void | event_session_dtor (void *obj) |
| Event session object destructor (event_session). More... | |
| static int | event_session_hash (const void *obj, const int flags) |
| AO2 hash function for event_session objects. More... | |
| static void | event_session_shutdown (struct event_session *session) |
| Explicitly shutdown a session. More... | |
| static int | event_session_shutdown_cb (void *session, void *arg, int flags) |
| static void | event_session_update_websocket (struct event_session *session, struct ast_ari_websocket_session *ws_session) |
| Updates the websocket session for an event_session. More... | |
| static void | stasis_app_message_handler (void *data, const char *app_name, struct ast_json *message) |
| Callback handler for Stasis application messages. More... | |
Variables | |
| static struct ao2_container * | event_session_registry |
| Local registry for created event_session objects. More... | |
/api-docs/events.{format} implementation- WebSocket resource
Definition in file resource_events.c.
| #define APPS_NUM_BUCKETS 7 |
Number of buckets for a websocket apps container. Remember to keep it a prime number!
Definition at line 42 of file resource_events.c.
Referenced by event_session_alloc().
| #define EVENT_SESSION_NUM_BUCKETS 23 |
Number of buckets for the event session registry. Remember to keep it a prime number!
Definition at line 39 of file resource_events.c.
Referenced by ast_ari_websocket_events_event_websocket_init().
| #define MESSAGES_INIT_SIZE 23 |
Initial size of a message queue.
Definition at line 45 of file resource_events.c.
Referenced by event_session_alloc().
event_session error types.
Definition at line 58 of file resource_events.c.
| void ast_ari_events_user_event | ( | struct ast_variable * | headers, |
| struct ast_ari_events_user_event_args * | args, | ||
| struct ast_ari_response * | response | ||
| ) |
Generate a user event.
| headers | HTTP headers | |
| args | Swagger parameters | |
| [out] | response | HTTP response |
Definition at line 532 of file resource_events.c.
References ast_ari_events_user_event_args::application, ast_ari_events_user_event_parse_body(), ast_ari_response_error(), ast_ari_response_no_content(), ast_json_object_get(), ast_strlen_zero, ast_ari_events_user_event_args::event_name, NULL, ast_ari_events_user_event_args::source, ast_ari_events_user_event_args::source_count, STASIS_APP_USER_APP_NOT_FOUND, stasis_app_user_event(), STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME, STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND, STASIS_APP_USER_INTERNAL_ERROR, STASIS_APP_USER_OK, STASIS_APP_USER_USEREVENT_INVALID, and ast_ari_events_user_event_args::variables.
Referenced by ast_ari_events_user_event_cb().
| int ast_ari_websocket_events_event_websocket_attempted | ( | struct ast_tcptls_session_instance * | ser, |
| struct ast_variable * | headers, | ||
| struct ast_ari_events_event_websocket_args * | args, | ||
| const char * | session_id | ||
| ) |
WebSocket connection for events.
| ser | HTTP TCP/TLS Server Session |
| headers | HTTP headers |
| args | Swagger parameters |
| session_id | The id of the current session. |
| 0 | success |
| non-zero | error |
Definition at line 488 of file resource_events.c.
References ast_debug, and event_session_alloc().
Referenced by ast_ari_events_event_websocket_ws_attempted_cb().
| void ast_ari_websocket_events_event_websocket_dtor | ( | void | ) |
WebSocket connection for events.
Definition at line 465 of file resource_events.c.
References ao2_callback, ao2_cleanup, event_session_shutdown_cb(), NULL, OBJ_MULTIPLE, and OBJ_NODATA.
Referenced by load_module(), and unload_module().
| void ast_ari_websocket_events_event_websocket_established | ( | struct ast_ari_websocket_session * | session, |
| struct ast_variable * | headers, | ||
| struct ast_ari_events_event_websocket_args * | args | ||
| ) |
WebSocket connection for events.
| session | ARI WebSocket. |
| headers | HTTP headers. |
| args | Swagger parameters. |
| session_id | The id of the current session. |
Definition at line 498 of file resource_events.c.
References ao2_find, ao2_ref, ao2_unlink, ast_ari_websocket_session_id(), ast_ari_websocket_session_read(), ast_assert, ast_debug, ast_json_unref(), ast_log, event_session_cleanup(), event_session_update_websocket(), LOG_WARNING, NULL, OBJ_SEARCH_KEY, and session.
Referenced by ast_ari_events_event_websocket_ws_established_cb().
| int ast_ari_websocket_events_event_websocket_init | ( | void | ) |
WebSocket connection for events.
| 0 | success |
| -1 | error |
Definition at line 473 of file resource_events.c.
References AO2_ALLOC_OPT_LOCK_MUTEX, ao2_container_alloc_hash, ast_log, event_session_compare(), event_session_hash(), EVENT_SESSION_NUM_BUCKETS, LOG_WARNING, and NULL.
Referenced by load_module().
|
static |
Creates an event_session object and registers its apps with Stasis.
Definition at line 388 of file resource_events.c.
References ao2_alloc, ao2_cleanup, ao2_link, ast_ari_events_event_websocket_args::app, app, ast_ari_events_event_websocket_args::app_count, APPS_NUM_BUCKETS, ast_log, ast_str_container_add(), ast_str_container_alloc, ast_strlen_zero, AST_VECTOR_INIT, ERROR_TYPE_INVALID_APP_PARAM, ERROR_TYPE_MISSING_APP_PARAM, ERROR_TYPE_OOM, ERROR_TYPE_STASIS_REGISTRATION, event_session_allocation_error_handler(), event_session_dtor(), handler(), LOG_WARNING, MESSAGES_INIT_SIZE, NULL, RAII_VAR, session, stasis_app_message_handler(), stasis_app_register(), stasis_app_register_all(), and ast_ari_events_event_websocket_args::subscribe_all.
Referenced by ast_ari_websocket_events_event_websocket_attempted().
|
static |
Handles event_session error processing.
Definition at line 339 of file resource_events.c.
References ast_http_error(), ERROR_TYPE_INVALID_APP_PARAM, ERROR_TYPE_MISSING_APP_PARAM, ERROR_TYPE_OOM, ERROR_TYPE_STASIS_REGISTRATION, and event_session_cleanup().
Referenced by event_session_alloc().
|
static |
Processes cleanup actions for a event_session object.
Definition at line 297 of file resource_events.c.
References ao2_unlink, and event_session_shutdown().
Referenced by ast_ari_websocket_events_event_websocket_established(), event_session_allocation_error_handler(), and event_session_shutdown_cb().
|
static |
AO2 comparison function for event_session objects.
Definition at line 153 of file resource_events.c.
References CMP_MATCH, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.
Referenced by ast_ari_websocket_events_event_websocket_init().
|
static |
Event session object destructor (event_session).
Definition at line 316 of file resource_events.c.
References ast_assert, AST_VECTOR_SIZE, NULL, session, event_session::websocket_apps, and event_session::ws_session.
Referenced by event_session_alloc().
|
static |
AO2 hash function for event_session objects.
Computes hash value for the given event_session, with respect to the provided search flags.
Definition at line 191 of file resource_events.c.
References ast_assert, ast_str_hash(), OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and session.
Referenced by ast_ari_websocket_events_event_websocket_init().
|
static |
Explicitly shutdown a session.
An explicit shutdown is necessary, since the stasis_app has a reference to this session. We also need to be sure to null out the ws_session field, since the websocket is about to go away.
Definition at line 223 of file resource_events.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, NULL, SCOPED_AO2LOCK, stasis_app_unregister(), event_session::websocket_apps, and event_session::ws_session.
Referenced by event_session_cleanup().
|
static |
Definition at line 458 of file resource_events.c.
References event_session_cleanup().
Referenced by ast_ari_websocket_events_event_websocket_dtor().
|
static |
Updates the websocket session for an event_session.
The websocket for the given event_session will be updated to the value of the ws_session argument.
If the value of the ws_session is not NULL and there are messages in the event session's message_queue, the messages are dispatched and removed from the queue.
Definition at line 269 of file resource_events.c.
References ao2_lock, ao2_unlock, ast_ari_websocket_session_write(), ast_assert, ast_json_unref(), AST_VECTOR_ELEM_CLEANUP_NOOP, AST_VECTOR_GET, AST_VECTOR_RESET, AST_VECTOR_SIZE, NULL, and event_session::ws_session.
Referenced by ast_ari_websocket_events_event_websocket_established().
|
static |
Callback handler for Stasis application messages.
Definition at line 79 of file resource_events.c.
References ao2_find, ao2_lock, ao2_unlock, ast_ari_json_format(), ast_ari_websocket_session_get_remote_addr(), ast_ari_websocket_session_write(), ast_assert, ast_json_dump_string_format(), ast_json_free(), ast_json_object_get(), ast_json_object_set(), ast_json_ref(), ast_json_string_create(), ast_json_string_get(), ast_log, ast_sockaddr_stringify(), AST_VECTOR_APPEND, ast_verbose(), LOG_WARNING, NULL, OBJ_NODATA, OBJ_UNLINK, S_OR, session, stasis_app_event_allowed(), stasis_app_get_debug_by_name(), str, event_session::websocket_apps, and event_session::ws_session.
Referenced by event_session_alloc().
|
static |
Local registry for created event_session objects.
Definition at line 68 of file resource_events.c.
1.8.13