39#define EVENT_SESSION_NUM_BUCKETS 23
42#define APPS_NUM_BUCKETS 7
45#define MESSAGES_INIT_SIZE 23
83 const char *msg_type, *msg_application;
84 int app_debug_enabled;
97 msg_application =
S_OR(
102 if (strcmp(msg_type,
"ApplicationReplaced") == 0 &&
103 strcmp(msg_application,
app_name) == 0) {
112 "Failed to dispatch '%s' message from Stasis app '%s'; could not update message\n",
115 }
else if (!
session->ws_session) {
121 "Queued '%s' message for Stasis app '%s'; websocket is not ready\n",
125 if (app_debug_enabled) {
128 ast_verbose(
"<--- Sending ARI event to %s --->\n%s\n",
157 const char *right_key = arg;
165 cmp = strcmp(object_left->
session_id, right_key);
168 cmp = strncmp(object_left->
session_id, right_key, strlen(right_key));
278 session->ws_session = ws_session;
347 "Stasis registration failed");
352 "Allocation failed");
357 "HTTP request is missing param: [app]");
362 "Invalid application provided in param [app].");
396 if (
args->app_count == 0) {
401 size =
sizeof(*session) + strlen(
session_id) + 1;
415 if (!
session->websocket_apps) {
425 if (
args->subscribe_all) {
431 for (i = 0; i <
args->app_count; ++i) {
432 const char *
app =
args->app[i];
481 "Failed to allocate the local registry for websocket applications\n");
492 ast_debug(3,
"/events WebSocket attempted\n");
505 const char *session_id;
507 ast_debug(3,
"/events WebSocket established\n");
520 "Failed to locate an event session for the provided websocket session\n");
539 if (
args->variables) {
546 "Missing parameter application");
562 "Application not found");
567 "Event source was not found");
572 "Invalid event source URI scheme");
577 "Invalid userevent data");
583 "Error processing request");
struct ast_json * ast_ari_websocket_session_read(struct ast_ari_websocket_session *session)
Read a message from an ARI WebSocket.
enum ast_json_encoding_format ast_ari_json_format(void)
Configured encoding format for JSON output.
const char * ast_ari_websocket_session_id(const struct ast_ari_websocket_session *session)
Get the Session ID for an ARI WebSocket.
struct ast_sockaddr * ast_ari_websocket_session_get_remote_addr(struct ast_ari_websocket_session *session)
Get the remote address from an ARI WebSocket.
int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session, struct ast_json *message)
Send a message to an ARI WebSocket.
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ao2_iterator_next(iter)
#define ao2_link(container, obj)
Add an object to a container.
@ 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,...
#define ao2_unlink(container, obj)
Remove an object from a container.
#define ao2_find(container, arg, flags)
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
@ OBJ_SEARCH_MASK
Search option field mask.
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
#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.
void ast_verbose(const char *fmt,...)
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.
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
char * ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format)
Encode a JSON value to a string.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
const char * app_name(struct ast_app *app)
static int event_session_shutdown_cb(void *session, void *arg, int flags)
static void event_session_dtor(void *obj)
Event session object destructor (event_session).
static void stasis_app_message_handler(void *data, const char *app_name, struct ast_json *message)
Callback handler for Stasis application messages.
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.
event_session_error_type
event_session error types.
@ ERROR_TYPE_INVALID_APP_PARAM
@ ERROR_TYPE_MISSING_APP_PARAM
@ ERROR_TYPE_STASIS_REGISTRATION
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.
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.
#define MESSAGES_INIT_SIZE
static void event_session_cleanup(struct event_session *session)
Processes cleanup actions for a event_session object.
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.
static int event_session_hash(const void *obj, const int flags)
AO2 hash function for event_session objects.
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.
#define EVENT_SESSION_NUM_BUCKETS
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.
int ast_ari_websocket_events_event_websocket_init(void)
WebSocket connection for events.
static int event_session_compare(void *obj, void *arg, int flags)
AO2 comparison function for event_session objects.
void ast_ari_websocket_events_event_websocket_dtor(void)
WebSocket connection for events.
static struct ao2_container * event_session_registry
Local registry for created event_session objects.
static void event_session_shutdown(struct event_session *session)
Explicitly shutdown a session.
Generated file - declares stubs to be implemented in res/ari/resource_events.c.
int ast_ari_events_user_event_parse_body(struct ast_json *body, struct ast_ari_events_user_event_args *args)
Body parsing function for /events/user/{eventName}.
Stasis Application API. See Stasis Application API for detailed documentation.
int stasis_app_event_allowed(const char *app_name, struct ast_json *event)
Check if the given event should be filtered.
stasis_app_user_event_res
Return code for stasis_app_user_event.
@ STASIS_APP_USER_APP_NOT_FOUND
@ STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND
@ STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME
@ STASIS_APP_USER_USEREVENT_INVALID
@ STASIS_APP_USER_INTERNAL_ERROR
int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
Register a new Stasis application.
void(* stasis_app_cb)(void *data, const char *app_name, struct ast_json *message)
Callback for Stasis application handler.
enum stasis_app_user_event_res stasis_app_user_event(const char *app_name, const char *event_name, const char **source_uris, int sources_count, struct ast_json *json_variables)
Generate a Userevent for stasis app (echo to AMI)
void stasis_app_unregister(const char *app_name)
Unregister a Stasis application.
int stasis_app_register_all(const char *app_name, stasis_app_cb handler, void *data)
Register a new Stasis application that receives all Asterisk events.
int stasis_app_get_debug_by_name(const char *app_name)
Get debug status of an application.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Abstract JSON element (object, array, string, int, ...).
describes a server instance
Structure for variables, used for configurations and for channel variables.
A wrapper for the /ref ast_ari_websocket_session.
struct event_session::@421 message_queue
struct ast_ari_websocket_session * ws_session
struct ao2_container * websocket_apps
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
int error(const char *format,...)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Vector container support.
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define AST_VECTOR(name, type)
Define a vector structure.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.