Asterisk - The Open Source Telephony Project GIT-master-590b490
Loading...
Searching...
No Matches
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_claim_channel_args
 
struct  ast_ari_events_event_websocket_args
 
struct  ast_ari_events_user_event_args
 

Functions

void ast_ari_events_claim_channel (struct ast_variable *headers, struct ast_ari_events_claim_channel_args *args, struct ast_ari_response *response)
 Claim a broadcast channel for this application.
 
int ast_ari_events_claim_channel_parse_body (struct ast_json *body, struct ast_ari_events_claim_channel_args *args)
 Body parsing function for /events/claim.
 
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.
 
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}.
 

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

void ast_ari_events_claim_channel ( struct ast_variable headers,
struct ast_ari_events_claim_channel_args args,
struct ast_ari_response response 
)

Claim a broadcast channel for this application.

Atomically claims a channel that is in broadcast state. Only the first claim succeeds.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 92 of file resource_events.c.

95{
96 int res;
97
98 if (ast_strlen_zero(args->channel_id)) {
99 ast_ari_response_error(response, 400, "Bad Request",
100 "channelId parameter is required");
101 return;
102 }
103
104 if (ast_strlen_zero(args->application)) {
105 ast_ari_response_error(response, 400, "Bad Request",
106 "application parameter is required");
107 return;
108 }
109
110 res = stasis_app_claim_channel(args->channel_id, args->application);
111
112 switch (res) {
113 case 0:
114 /* Success */
116 break;
117 case -1:
118 /* Channel not found */
119 ast_ari_response_error(response, 404, "Not Found",
120 "Channel not found or not in broadcast state");
121 break;
122 case -2:
123 /* Already claimed */
124 ast_ari_response_error(response, 409, "Conflict",
125 "Channel has already been claimed by another application");
126 break;
128 /* Module not loaded */
129 ast_ari_response_error(response, 501, "Not Implemented",
130 "Broadcast functionality not available (res_stasis_broadcast not loaded)");
131 break;
132 default:
133 ast_ari_response_error(response, 500, "Internal Server Error",
134 "Failed to claim channel");
135 break;
136 }
137}
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:212
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition res_ari.c:237
#define AST_OPTIONAL_API_UNAVAILABLE
A common value for optional API stub functions to return.
static struct @522 args
int AST_OPTIONAL_API_NAME() stasis_app_claim_channel(const char *channel_id, const char *app_name)
Attempt to claim a broadcast channel.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65

References args, ast_ari_response_error(), ast_ari_response_no_content(), AST_OPTIONAL_API_UNAVAILABLE, ast_strlen_zero(), and stasis_app_claim_channel().

Referenced by ast_ari_events_claim_channel_cb().

◆ ast_ari_events_claim_channel_parse_body()

int ast_ari_events_claim_channel_parse_body ( struct ast_json body,
struct ast_ari_events_claim_channel_args args 
)

Body parsing function for /events/claim.

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 210 of file res_ari_events.c.

213{
214 struct ast_json *field;
215 /* Parse query parameters out of it */
216 field = ast_json_object_get(body, "channelId");
217 if (field) {
218 args->channel_id = ast_json_string_get(field);
219 }
220 field = ast_json_object_get(body, "application");
221 if (field) {
222 args->application = ast_json_string_get(field);
223 }
224 return 0;
225}
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
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
Abstract JSON element (object, array, string, int, ...).

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_events_claim_channel_cb().

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

40{
42 struct ast_json *json_variables = NULL;
43
44 if (args->variables) {
46 json_variables = ast_json_object_get(args->variables, "variables");
47 }
48
49 if (ast_strlen_zero(args->application)) {
50 ast_ari_response_error(response, 400, "Bad Request",
51 "Missing parameter application");
52 return;
53 }
54
55 res = stasis_app_user_event(args->application,
56 args->event_name,
57 args->source, args->source_count,
58 json_variables);
59
60 switch (res) {
63 break;
64
66 ast_ari_response_error(response, 404, "Not Found",
67 "Application not found");
68 break;
69
71 ast_ari_response_error(response, 422, "Unprocessable Entity",
72 "Event source was not found");
73 break;
74
76 ast_ari_response_error(response, 400, "Bad Request",
77 "Invalid event source URI scheme");
78 break;
79
81 ast_ari_response_error(response, 400, "Bad Request",
82 "Invalid userevent data");
83 break;
84
86 default:
87 ast_ari_response_error(response, 500, "Internal Server Error",
88 "Error processing request");
89 }
90}
#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)

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