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",
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;
162 right_key = object_right->session_id;
165 cmp = strcmp(object_left->session_id, right_key);
168 cmp = strncmp(object_left->session_id, right_key, strlen(right_key));
202 key = session->session_id;
304 if (event_session_registry) {
347 "Stasis registration failed");
352 "Allocation failed");
357 "HTTP request is missing param: [app]");
362 "Invalid application provided in param [app].");
401 size =
sizeof(*session) + strlen(session_id) + 1;
409 strncpy(
session->session_id, session_id, size -
sizeof(*
session));
415 if (!
session->websocket_apps) {
432 const char *
app = args->
app[i];
470 event_session_registry =
NULL;
478 if (!event_session_registry) {
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");
546 "Missing parameter application");
562 "Application not found");
567 "Event source was not found");
572 "Invalid event source URI scheme");
577 "Invalid userevnet data");
583 "Error processing request");
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
event_session_error_type
event_session error types.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_ari_websocket_session_id(const struct ast_ari_websocket_session *session)
Get the Session ID for an ARI WebSocket.
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.
enum ast_json_encoding_format ast_ari_json_format(void)
Configured encoding format for JSON output.
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.
The arg parameter is a search key, but is not an object.
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
static void event_session_dtor(void *obj)
Event session object destructor (event_session).
Generated file - declares stubs to be implemented in res/ari/resource_events.c.
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 ao2_callback(c, flags, cb_fn, arg)
void ast_json_free(void *p)
Asterisk's custom JSON allocator. Exposed for use by unit tests.
Structure for variables, used for configurations and for channel variables.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
int stasis_app_event_allowed(const char *app_name, struct ast_json *event)
Check if the given event should be filtered.
#define MESSAGES_INIT_SIZE
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct ast_sockaddr * ast_ari_websocket_session_get_remote_addr(struct ast_ari_websocket_session *session)
Get the remote address from an ARI WebSocket.
struct ast_json * ast_ari_websocket_session_read(struct ast_ari_websocket_session *session)
Read a message from an ARI WebSocket.
void ast_verbose(const char *fmt,...)
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
#define ast_strlen_zero(foo)
int stasis_app_get_debug_by_name(const char *app_name)
Get debug status of an application.
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}.
static void event_session_cleanup(struct event_session *session)
Processes cleanup actions for a event_session object.
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 ast_debug(level,...)
Log a DEBUG message.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
void stasis_app_unregister(const char *app_name)
Unregister a Stasis application.
#define AST_VECTOR_ELEM_CLEANUP_NOOP(elem)
Vector element cleanup that does nothing.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
static struct ast_mansession session
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.
A wrapper for the /ref ast_ari_websocket_session.
#define ao2_ref(o, delta)
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
struct ao2_container * websocket_apps
#define AST_VECTOR(name, type)
Define a vector structure.
static int event_session_shutdown_cb(void *session, void *arg, int flags)
Support for WebSocket connections within the Asterisk HTTP server and client WebSocket connections to...
char * ast_json_dump_string_format(struct ast_json *root, enum ast_json_encoding_format format)
Encode a JSON value to a string.
describes a server instance
#define EVENT_SESSION_NUM_BUCKETS
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
#define ao2_unlink(container, obj)
struct ast_ari_websocket_session * ws_session
static int event_session_hash(const void *obj, const int flags)
AO2 hash function for event_session objects.
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)
#define ao2_iterator_next(iter)
#define ao2_alloc(data_size, destructor_fn)
int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
Register a new Stasis application.
static void event_session_shutdown(struct event_session *session)
Explicitly shutdown a session.
#define SCOPED_AO2LOCK(varname, obj)
scoped lock specialization for ao2 mutexes.
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
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.
Vector container support.
static int event_session_compare(void *obj, void *arg, int flags)
AO2 comparison function for event_session objects.
#define ao2_find(container, arg, flags)
int ast_ari_websocket_events_event_websocket_init(void)
WebSocket connection for events.
void(* stasis_app_cb)(void *data, const char *app_name, struct ast_json *message)
Callback for Stasis application handler.
struct ast_json * variables
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.
The arg parameter is an object of the same type.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
stasis_app_user_event_res
Return code for stasis_app_user_event.
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
void ast_ari_websocket_events_event_websocket_dtor(void)
WebSocket connection for events.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
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 stasis_app_register_all(const char *app_name, stasis_app_cb handler, void *data)
Register a new Stasis application that receives all Asterisk events.
Abstract JSON element (object, array, string, int, ...).
int error(const char *format,...)
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)
Stasis Application API. See Stasis Application API for detailed documentation.
Search option field mask.
static struct ao2_container * event_session_registry
Local registry for created event_session objects.
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.
int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session, struct ast_json *message)
Send a message to an ARI WebSocket.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
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.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
#define ao2_link(container, obj)
static void stasis_app_message_handler(void *data, const char *app_name, struct ast_json *message)
Callback handler for Stasis application messages.