Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Data Structures | Functions
resource_events.h File Reference

Generated file - declares stubs to be implemented in res/ari/resource_events.c. More...

#include "asterisk/ari.h"
Include dependency graph for resource_events.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_ari_events_event_websocket_args
 
struct  ast_ari_events_user_event_args
 

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_events_user_event_parse_body (struct ast_json *body, struct ast_ari_events_user_event_args *args)
 Body parsing function for /events/user/{eventName}. 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 *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...
 

Detailed Description

Generated file - declares stubs to be implemented in res/ari/resource_events.c.

WebSocket resource

Author
David M. Lee, II dlee@.nosp@m.digi.nosp@m.um.co.nosp@m.m

Definition in file resource_events.h.

Function Documentation

◆ ast_ari_events_user_event()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 532 of file resource_events.c.

535{
537 struct ast_json *json_variables = NULL;
538
539 if (args->variables) {
541 json_variables = ast_json_object_get(args->variables, "variables");
542 }
543
544 if (ast_strlen_zero(args->application)) {
545 ast_ari_response_error(response, 400, "Bad Request",
546 "Missing parameter application");
547 return;
548 }
549
550 res = stasis_app_user_event(args->application,
551 args->event_name,
552 args->source, args->source_count,
553 json_variables);
554
555 switch (res) {
558 break;
559
561 ast_ari_response_error(response, 404, "Not Found",
562 "Application not found");
563 break;
564
566 ast_ari_response_error(response, 422, "Unprocessable Entity",
567 "Event source was not found");
568 break;
569
571 ast_ari_response_error(response, 400, "Bad Request",
572 "Invalid event source URI scheme");
573 break;
574
576 ast_ari_response_error(response, 400, "Bad Request",
577 "Invalid userevent data");
578 break;
579
581 default:
582 ast_ari_response_error(response, 500, "Internal Server Error",
583 "Error processing request");
584 }
585}
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.
Definition: res_ari.c:259
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
#define NULL
Definition: resample.c:96
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_app_user_event_res
Return code for stasis_app_user_event.
Definition: stasis_app.h:255
@ STASIS_APP_USER_APP_NOT_FOUND
Definition: stasis_app.h:257
@ STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND
Definition: stasis_app.h:258
@ STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME
Definition: stasis_app.h:259
@ STASIS_APP_USER_USEREVENT_INVALID
Definition: stasis_app.h:260
@ STASIS_APP_USER_OK
Definition: stasis_app.h:256
@ STASIS_APP_USER_INTERNAL_ERROR
Definition: stasis_app.h:261
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)
Definition: res_stasis.c:2102
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Abstract JSON element (object, array, string, int, ...).
const char * args

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().

◆ ast_ari_events_user_event_parse_body()

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}.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 241 of file res_ari_events.c.

244{
245 struct ast_json *field;
246 /* Parse query parameters out of it */
247 field = ast_json_object_get(body, "application");
248 if (field) {
249 args->application = ast_json_string_get(field);
250 }
251 field = ast_json_object_get(body, "source");
252 if (field) {
253 /* If they were silly enough to both pass in a query param and a
254 * JSON body, free up the query value.
255 */
256 ast_free(args->source);
257 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
258 /* Multiple param passed as array */
259 size_t i;
260 args->source_count = ast_json_array_size(field);
261 args->source = ast_malloc(sizeof(*args->source) * args->source_count);
262
263 if (!args->source) {
264 return -1;
265 }
266
267 for (i = 0; i < args->source_count; ++i) {
268 args->source[i] = ast_json_string_get(ast_json_array_get(field, i));
269 }
270 } else {
271 /* Multiple param passed as single value */
272 args->source_count = 1;
273 args->source = ast_malloc(sizeof(*args->source) * args->source_count);
274 if (!args->source) {
275 return -1;
276 }
277 args->source[0] = ast_json_string_get(field);
278 }
279 }
280 return 0;
281}
#define ast_free(a)
Definition: astmm.h:180
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
enum ast_json_type ast_json_typeof(const struct ast_json *value)
Get the type of value.
Definition: json.c:78
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition: json.c:370
@ AST_JSON_ARRAY
Definition: json.h:165
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:283
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:366

References args, ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), and ast_malloc.

Referenced by ast_ari_events_user_event().

◆ ast_ari_websocket_events_event_websocket_attempted()

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.

Parameters
serHTTP TCP/TLS Server Session
headersHTTP headers
argsSwagger parameters
session_idThe id of the current session.
Return values
0success
non-zeroerror

Definition at line 488 of file resource_events.c.

491{
492 ast_debug(3, "/events WebSocket attempted\n");
493
494 /* Create the event session */
495 return event_session_alloc(ser, args, session_id);
496}
#define ast_debug(level,...)
Log a DEBUG message.
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.

References args, ast_debug, event_session_alloc(), and event_session::session_id.

Referenced by ast_ari_events_event_websocket_ws_attempted_cb().

◆ ast_ari_websocket_events_event_websocket_dtor()

void ast_ari_websocket_events_event_websocket_dtor ( void  )

WebSocket connection for events.

Definition at line 465 of file resource_events.c.

466{
468
471}
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
static int event_session_shutdown_cb(void *session, void *arg, int flags)
static struct ao2_container * event_session_registry
Local registry for created event_session objects.

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().

◆ ast_ari_websocket_events_event_websocket_established()

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.

Parameters
sessionARI WebSocket.
headersHTTP headers.
argsSwagger parameters.

Definition at line 498 of file resource_events.c.

501{
502 struct event_session *session;
503
504 struct ast_json *msg;
505 const char *session_id;
506
507 ast_debug(3, "/events WebSocket established\n");
508
509 ast_assert(ws_session != NULL);
510
511 session_id = ast_ari_websocket_session_id(ws_session);
512
513 /* Find the event_session and update its websocket */
515 if (session) {
518 } else {
520 "Failed to locate an event session for the provided websocket session\n");
521 }
522
523 /* We don't process any input, but we'll consume it waiting for EOF */
524 while ((msg = ast_ari_websocket_session_read(ws_session))) {
525 ast_json_unref(msg);
526 }
527
529 ao2_ref(session, -1);
530}
struct ast_json * ast_ari_websocket_session_read(struct ast_ari_websocket_session *session)
Read a message from an ARI WebSocket.
const char * ast_ari_websocket_session_id(const struct ast_ari_websocket_session *session)
Get the Session ID for an ARI WebSocket.
static struct ast_mansession session
#define ast_log
Definition: astobj2.c:42
#define ao2_unlink(container, obj)
Remove an object from a container.
Definition: astobj2.h:1578
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
#define LOG_WARNING
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
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.
A wrapper for the /ref ast_ari_websocket_session.
#define ast_assert(a)
Definition: utils.h:739

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().

◆ ast_ari_websocket_events_event_websocket_init()

int ast_ari_websocket_events_event_websocket_init ( void  )

WebSocket connection for events.

Return values
0success
-1error

Definition at line 473 of file resource_events.c.

474{
475 /* Try to instantiate the registry */
479 /* This is bad, bad. */
481 "Failed to allocate the local registry for websocket applications\n");
482 return -1;
483 }
484
485 return 0;
486}
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#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.
Definition: astobj2.h:1303
static int event_session_hash(const void *obj, const int flags)
AO2 hash function for event_session objects.
#define EVENT_SESSION_NUM_BUCKETS
static int event_session_compare(void *obj, void *arg, int flags)
AO2 comparison function for event_session objects.

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().