Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions
resource_applications.h File Reference

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

#include "asterisk/ari.h"
Include dependency graph for resource_applications.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_applications_filter_args
 
struct  ast_ari_applications_get_args
 
struct  ast_ari_applications_list_args
 
struct  ast_ari_applications_subscribe_args
 
struct  ast_ari_applications_unsubscribe_args
 

Functions

void ast_ari_applications_filter (struct ast_variable *headers, struct ast_ari_applications_filter_args *args, struct ast_ari_response *response)
 Filter application events types. More...
 
int ast_ari_applications_filter_parse_body (struct ast_json *body, struct ast_ari_applications_filter_args *args)
 Body parsing function for /applications/{applicationName}/eventFilter. More...
 
void ast_ari_applications_get (struct ast_variable *headers, struct ast_ari_applications_get_args *args, struct ast_ari_response *response)
 Get details of an application. More...
 
void ast_ari_applications_list (struct ast_variable *headers, struct ast_ari_applications_list_args *args, struct ast_ari_response *response)
 List all applications. More...
 
void ast_ari_applications_subscribe (struct ast_variable *headers, struct ast_ari_applications_subscribe_args *args, struct ast_ari_response *response)
 Subscribe an application to a event source. More...
 
int ast_ari_applications_subscribe_parse_body (struct ast_json *body, struct ast_ari_applications_subscribe_args *args)
 Body parsing function for /applications/{applicationName}/subscription. More...
 
void ast_ari_applications_unsubscribe (struct ast_variable *headers, struct ast_ari_applications_unsubscribe_args *args, struct ast_ari_response *response)
 Unsubscribe an application from an event source. More...
 
int ast_ari_applications_unsubscribe_parse_body (struct ast_json *body, struct ast_ari_applications_unsubscribe_args *args)
 Body parsing function for /applications/{applicationName}/subscription. More...
 

Detailed Description

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

Stasis application resources

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

Definition in file resource_applications.h.

Function Documentation

◆ ast_ari_applications_filter()

void ast_ari_applications_filter ( struct ast_variable headers,
struct ast_ari_applications_filter_args args,
struct ast_ari_response response 
)

Filter application events types.

Allowed and/or disallowed event type filtering can be done. The body (parameter) should specify a JSON key/value object that describes the type of event filtering needed. One, or both of the following keys can be designated:

"allowed" - Specifies an allowed list of event types
"disallowed" - Specifies a disallowed list of event types

Further, each of those key's value should be a JSON array that holds zero, or more JSON key/value objects. Each of these objects must contain the following key with an associated value:

"type" - The type name of the event to filter

The value must be the string name (case sensitive) of the event type that needs filtering. For example:

{ "allowed": [ { "type": "StasisStart" }, { "type": "StasisEnd" } ] }

As this specifies only an allowed list, then only those two event type messages are sent to the application. No other event messages are sent.

The following rules apply:

* If the body is empty, both the allowed and disallowed filters are set empty.
* If both list types are given then both are set to their respective values (note, specifying an empty array for a given type sets that type to empty).
* If only one list type is given then only that type is set. The other type is not updated.
* An empty "allowed" list means all events are allowed.
* An empty "disallowed" list means no events are disallowed.
* Disallowed events take precedence over allowed events if the event type is specified in both lists.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 172 of file resource_applications.c.

References ao2_ref, app, ast_ari_applications_filter_args::application_name, ast_ari_response_error(), ast_ari_response_ok(), ast_ari_applications_filter_args::filter, stasis_app_event_filter_set(), stasis_app_get_by_name(), and stasis_app_object_to_json().

Referenced by ast_ari_applications_filter_cb().

175 {
177 
178  if (!app) {
179  ast_ari_response_error(response, 404, "Not Found", "Application not found");
180  return;
181  }
182 
183  if (stasis_app_event_filter_set(app, args->filter)) {
184  ast_ari_response_error(response, 400, "Bad Request", "Invalid format definition");
185  } else {
187  }
188 
189  ao2_ref(app, -1);
190 }
struct ast_json * stasis_app_object_to_json(struct stasis_app *app)
Return the JSON representation of a Stasis application.
Definition: res_stasis.c:1866
struct stasis_app * stasis_app_get_by_name(const char *name)
Retrieve a handle to a Stasis application by its name.
Definition: res_stasis.c:1694
int stasis_app_event_filter_set(struct stasis_app *app, struct ast_json *filter)
Set the application's event type filter.
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ao2_ref(o, delta)
Definition: astobj2.h:464
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
static const char app[]
Definition: app_mysql.c:62

◆ ast_ari_applications_filter_parse_body()

int ast_ari_applications_filter_parse_body ( struct ast_json body,
struct ast_ari_applications_filter_args args 
)

Body parsing function for /applications/{applicationName}/eventFilter.

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 462 of file res_ari_applications.c.

465 {
466  /* Parse query parameters out of it */
467  return 0;
468 }

◆ ast_ari_applications_get()

void ast_ari_applications_get ( struct ast_variable headers,
struct ast_ari_applications_get_args args,
struct ast_ari_response response 
)

Get details of an application.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 72 of file resource_applications.c.

References ast_ari_applications_get_args::application_name, ast_ari_response_error(), ast_ari_response_ok(), and stasis_app_to_json().

Referenced by ast_ari_applications_get_cb().

75 {
76  struct ast_json *json;
77 
79 
80  if (!json) {
81  ast_ari_response_error(response, 404, "Not Found",
82  "Application not found");
83  return;
84  }
85 
86  ast_ari_response_ok(response, json);
87 }
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
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
Abstract JSON element (object, array, string, int, ...).
struct ast_json * stasis_app_to_json(const char *app_name)
Return the JSON representation of a Stasis application.
Definition: res_stasis.c:1876

◆ ast_ari_applications_list()

void ast_ari_applications_list ( struct ast_variable headers,
struct ast_ari_applications_list_args args,
struct ast_ari_response response 
)

List all applications.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 42 of file resource_applications.c.

References ao2_callback, ao2_cleanup, ao2_container_count(), ao2_lock, ao2_unlock, append_json(), ast_ari_response_error(), ast_ari_response_ok(), ast_json_array_create(), ast_json_array_size(), ast_json_ref(), ast_json_unref(), NULL, OBJ_NODATA, OBJ_NOLOCK, RAII_VAR, and stasis_app_get_all().

Referenced by ast_ari_applications_list_cb().

45 {
47  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
48  size_t count;
49 
51  json = ast_json_array_create();
52  if (!apps || !json) {
53  ast_ari_response_error(response, 500, "Internal Server Error",
54  "Allocation failed");
55  return;
56  }
57 
58  ao2_lock(apps);
59  count = ao2_container_count(apps);
62 
63  if (count != ast_json_array_size(json)) {
64  ast_ari_response_error(response, 500, "Internal Server Error",
65  "Allocation failed");
66  return;
67  }
68 
69  ast_ari_response_ok(response, ast_json_ref(json));
70 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Registered applications container.
Definition: pbx_app.c:67
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
static int append_json(void *obj, void *arg, int flags)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ao2_lock(a)
Definition: astobj2.h:718
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
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
struct ao2_container * stasis_app_get_all(void)
Gets the names of all registered Stasis applications.
Definition: res_stasis.c:1708
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:356
Abstract JSON element (object, array, string, int, ...).
Generic container type.

◆ ast_ari_applications_subscribe()

void ast_ari_applications_subscribe ( struct ast_variable headers,
struct ast_ari_applications_subscribe_args args,
struct ast_ari_response response 
)

Subscribe an application to a event source.

Returns the state of the application after the subscriptions have changed

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 89 of file resource_applications.c.

References ast_ari_applications_subscribe_args::application_name, ast_ari_response_error(), ast_ari_response_ok(), ast_json_ref(), ast_json_unref(), ast_strlen_zero, ast_ari_applications_subscribe_args::event_source, ast_ari_applications_subscribe_args::event_source_count, NULL, RAII_VAR, stasis_app_subscribe(), STASIS_ASR_APP_NOT_FOUND, STASIS_ASR_EVENT_SOURCE_BAD_SCHEME, STASIS_ASR_EVENT_SOURCE_NOT_FOUND, STASIS_ASR_INTERNAL_ERROR, and STASIS_ASR_OK.

Referenced by ast_ari_applications_subscribe_cb().

92 {
93  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
94  enum stasis_app_subscribe_res res;
95 
96  if (args->event_source_count <= 0) {
97  ast_ari_response_error(response, 400, "Bad Request",
98  "Missing parameter eventSource");
99  return;
100  }
101 
102  if (ast_strlen_zero(args->application_name)) {
103  ast_ari_response_error(response, 400, "Bad Request",
104  "Missing parameter applicationName");
105  return;
106  }
107 
109  args->event_source_count, &json);
110 
111  switch (res) {
112  case STASIS_ASR_OK:
113  ast_ari_response_ok(response, ast_json_ref(json));
114  break;
116  ast_ari_response_error(response, 404, "Not Found",
117  "Application not found");
118  break;
120  ast_ari_response_error(response, 422, "Unprocessable Entity",
121  "Event source does not exist");
122  break;
124  ast_ari_response_error(response, 400, "Bad Request",
125  "Invalid event source URI scheme");
126  break;
128  ast_ari_response_error(response, 500, "Internal Server Error",
129  "Error processing request");
130  break;
131  }
132 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json)
Subscribes an application to a list of event sources.
Definition: res_stasis.c:2045
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
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
stasis_app_subscribe_res
Return code for stasis_app_[un]subscribe.
Definition: stasis_app.h:282
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_applications_subscribe_parse_body()

int ast_ari_applications_subscribe_parse_body ( struct ast_json body,
struct ast_ari_applications_subscribe_args args 
)

Body parsing function for /applications/{applicationName}/subscription.

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 161 of file res_ari_applications.c.

References ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), ast_malloc, ast_ari_applications_subscribe_args::event_source, and ast_ari_applications_subscribe_args::event_source_count.

Referenced by ast_ari_applications_subscribe_cb().

164 {
165  struct ast_json *field;
166  /* Parse query parameters out of it */
167  field = ast_json_object_get(body, "eventSource");
168  if (field) {
169  /* If they were silly enough to both pass in a query param and a
170  * JSON body, free up the query value.
171  */
172  ast_free(args->event_source);
173  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
174  /* Multiple param passed as array */
175  size_t i;
177  args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
178 
179  if (!args->event_source) {
180  return -1;
181  }
182 
183  for (i = 0; i < args->event_source_count; ++i) {
185  }
186  } else {
187  /* Multiple param passed as single value */
188  args->event_source_count = 1;
189  args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
190  if (!args->event_source) {
191  return -1;
192  }
193  args->event_source[0] = ast_json_string_get(field);
194  }
195  }
196  return 0;
197 }
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define ast_free(a)
Definition: astmm.h:182
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_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:356
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition: json.c:360

◆ ast_ari_applications_unsubscribe()

void ast_ari_applications_unsubscribe ( struct ast_variable headers,
struct ast_ari_applications_unsubscribe_args args,
struct ast_ari_response response 
)

Unsubscribe an application from an event source.

Returns the state of the application after the subscriptions have changed

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 134 of file resource_applications.c.

References ast_ari_applications_unsubscribe_args::application_name, ast_ari_response_error(), ast_ari_response_ok(), ast_json_ref(), ast_json_unref(), ast_ari_applications_unsubscribe_args::event_source, ast_ari_applications_unsubscribe_args::event_source_count, NULL, RAII_VAR, stasis_app_unsubscribe(), STASIS_ASR_APP_NOT_FOUND, STASIS_ASR_EVENT_SOURCE_BAD_SCHEME, STASIS_ASR_EVENT_SOURCE_NOT_FOUND, STASIS_ASR_INTERNAL_ERROR, and STASIS_ASR_OK.

Referenced by ast_ari_applications_unsubscribe_cb().

137 {
138  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
139  enum stasis_app_subscribe_res res;
140 
141  if (args->event_source_count == 0) {
142  ast_ari_response_error(response, 400, "Bad Request",
143  "Missing parameter eventSource");
144  return;
145  }
146 
148  args->event_source_count, &json);
149 
150  switch (res) {
151  case STASIS_ASR_OK:
152  ast_ari_response_ok(response, ast_json_ref(json));
153  break;
155  ast_ari_response_error(response, 404, "Not Found",
156  "Application not found");
157  break;
159  ast_ari_response_error(response, 422, "Unprocessable Entity",
160  "Event source was not subscribed to");
161  break;
163  ast_ari_response_error(response, 400, "Bad Request",
164  "Invalid event source URI scheme");
165  break;
167  ast_ari_response_error(response, 500, "Internal Server Error",
168  "Error processing request");
169  }
170 }
enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name, const char **event_source_uris, int event_sources_count, struct ast_json **json)
Unsubscribes an application from a list of event sources.
Definition: res_stasis.c:2086
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
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
stasis_app_subscribe_res
Return code for stasis_app_[un]subscribe.
Definition: stasis_app.h:282
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_applications_unsubscribe_parse_body()

int ast_ari_applications_unsubscribe_parse_body ( struct ast_json body,
struct ast_ari_applications_unsubscribe_args args 
)

Body parsing function for /applications/{applicationName}/subscription.

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 311 of file res_ari_applications.c.

References ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), ast_malloc, ast_ari_applications_unsubscribe_args::event_source, and ast_ari_applications_unsubscribe_args::event_source_count.

Referenced by ast_ari_applications_unsubscribe_cb().

314 {
315  struct ast_json *field;
316  /* Parse query parameters out of it */
317  field = ast_json_object_get(body, "eventSource");
318  if (field) {
319  /* If they were silly enough to both pass in a query param and a
320  * JSON body, free up the query value.
321  */
322  ast_free(args->event_source);
323  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
324  /* Multiple param passed as array */
325  size_t i;
327  args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
328 
329  if (!args->event_source) {
330  return -1;
331  }
332 
333  for (i = 0; i < args->event_source_count; ++i) {
335  }
336  } else {
337  /* Multiple param passed as single value */
338  args->event_source_count = 1;
339  args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
340  if (!args->event_source) {
341  return -1;
342  }
343  args->event_source[0] = ast_json_string_get(field);
344  }
345  }
346  return 0;
347 }
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define ast_free(a)
Definition: astmm.h:182
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_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:356
Abstract JSON element (object, array, string, int, ...).
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition: json.c:360