Asterisk - The Open Source Telephony Project GIT-master-8f1982c
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
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...
 

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 36 of file resource_events.c.

39{
41 struct ast_json *json_variables = NULL;
42
43 if (args->variables) {
45 json_variables = ast_json_object_get(args->variables, "variables");
46 }
47
48 if (ast_strlen_zero(args->application)) {
49 ast_ari_response_error(response, 400, "Bad Request",
50 "Missing parameter application");
51 return;
52 }
53
54 res = stasis_app_user_event(args->application,
55 args->event_name,
56 args->source, args->source_count,
57 json_variables);
58
59 switch (res) {
62 break;
63
65 ast_ari_response_error(response, 404, "Not Found",
66 "Application not found");
67 break;
68
70 ast_ari_response_error(response, 422, "Unprocessable Entity",
71 "Event source was not found");
72 break;
73
75 ast_ari_response_error(response, 400, "Bad Request",
76 "Invalid event source URI scheme");
77 break;
78
80 ast_ari_response_error(response, 400, "Bad Request",
81 "Invalid userevent data");
82 break;
83
85 default:
86 ast_ari_response_error(response, 500, "Internal Server Error",
87 "Error processing request");
88 }
89}
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:319
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:344
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:265
@ STASIS_APP_USER_APP_NOT_FOUND
Definition: stasis_app.h:267
@ STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND
Definition: stasis_app.h:268
@ STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME
Definition: stasis_app.h:269
@ STASIS_APP_USER_USEREVENT_INVALID
Definition: stasis_app.h:270
@ STASIS_APP_USER_OK
Definition: stasis_app.h:266
@ STASIS_APP_USER_INTERNAL_ERROR
Definition: stasis_app.h:271
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:2174
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 54 of file res_ari_events.c.

57{
58 struct ast_json *field;
59 /* Parse query parameters out of it */
60 field = ast_json_object_get(body, "application");
61 if (field) {
62 args->application = ast_json_string_get(field);
63 }
64 field = ast_json_object_get(body, "source");
65 if (field) {
66 /* If they were silly enough to both pass in a query param and a
67 * JSON body, free up the query value.
68 */
69 ast_free(args->source);
70 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
71 /* Multiple param passed as array */
72 size_t i;
73 args->source_count = ast_json_array_size(field);
74 args->source = ast_malloc(sizeof(*args->source) * args->source_count);
75
76 if (!args->source) {
77 return -1;
78 }
79
80 for (i = 0; i < args->source_count; ++i) {
81 args->source[i] = ast_json_string_get(ast_json_array_get(field, i));
82 }
83 } else {
84 /* Multiple param passed as single value */
85 args->source_count = 1;
86 args->source = ast_malloc(sizeof(*args->source) * args->source_count);
87 if (!args->source) {
88 return -1;
89 }
90 args->source[0] = ast_json_string_get(field);
91 }
92 }
93 return 0;
94}
#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().