Asterisk - The Open Source Telephony Project GIT-master-f36a736
|
/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.
#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.
#define MESSAGES_INIT_SIZE 23 |
Initial size of a message queue.
Definition at line 45 of file resource_events.c.
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 args, ast_ari_events_user_event_parse_body(), ast_ari_response_error(), ast_ari_response_no_content(), ast_json_object_get(), ast_strlen_zero(), NULL, 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, and STASIS_APP_USER_USEREVENT_INVALID.
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 args, ast_debug, event_session_alloc(), and event_session::session_id.
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_registry, 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. |
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_registry, 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, event_session_registry, 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, app, APPS_NUM_BUCKETS, args, 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(), event_session_registry, handler(), LOG_WARNING, MESSAGES_INIT_SIZE, NULL, RAII_VAR, session, event_session::session_id, stasis_app_message_handler(), stasis_app_register(), and stasis_app_register_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(), ERROR_TYPE_INVALID_APP_PARAM, ERROR_TYPE_MISSING_APP_PARAM, ERROR_TYPE_OOM, ERROR_TYPE_STASIS_REGISTRATION, event_session_cleanup(), and session.
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, event_session_registry, event_session_shutdown(), and session.
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, OBJ_SEARCH_PARTIAL_KEY, and event_session::session_id.
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, and 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, session, and stasis_app_unregister().
Referenced by event_session_cleanup().
|
static |
Definition at line 458 of file resource_events.c.
References event_session_cleanup(), and session.
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 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, app_name(), 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(), and str.
Referenced by event_session_alloc().
|
static |
Local registry for created event_session objects.
Definition at line 68 of file resource_events.c.
Referenced by ast_ari_websocket_events_event_websocket_dtor(), ast_ari_websocket_events_event_websocket_established(), ast_ari_websocket_events_event_websocket_init(), event_session_alloc(), and event_session_cleanup().