Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
res_ari_applications.c File Reference

Stasis application resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_applications.h"
#include "ari/ari_model_validators.h"
Include dependency graph for res_ari_applications.c:

Go to the source code of this file.

Macros

#define MAX_VALS   128
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
static void ast_ari_applications_filter_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /applications/{applicationName}/eventFilter. 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...
 
static void ast_ari_applications_get_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /applications/{applicationName}. More...
 
static void ast_ari_applications_list_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /applications. More...
 
static void ast_ari_applications_subscribe_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /applications/{applicationName}/subscription. 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...
 
static void ast_ari_applications_unsubscribe_cb (struct ast_tcptls_session_instance *ser, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 Parameter parsing callback for /applications/{applicationName}/subscription. 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...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Stasis application resources" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis", }
 
static struct stasis_rest_handlers applications
 REST handler for /api-docs/applications.json. More...
 
static struct stasis_rest_handlers applications_applicationName
 REST handler for /api-docs/applications.json. More...
 
static struct stasis_rest_handlers applications_applicationName_eventFilter
 REST handler for /api-docs/applications.json. More...
 
static struct stasis_rest_handlers applications_applicationName_subscription
 REST handler for /api-docs/applications.json. More...
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Stasis application resources.

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

Definition in file res_ari_applications.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 595 of file res_ari_applications.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 595 of file res_ari_applications.c.

◆ ast_ari_applications_filter_cb()

static void ast_ari_applications_filter_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /applications/{applicationName}/eventFilter.

Parameters
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 477 of file res_ari_applications.c.

References ast_ari_applications_filter_args::application_name, ast_ari_applications_filter(), ast_ari_response_error(), ast_ari_validate_application(), ast_log, ast_ari_applications_filter_args::filter, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

481 {
483  struct ast_variable *i;
484 #if defined(AST_DEVMODE)
485  int is_valid;
486  int code;
487 #endif /* AST_DEVMODE */
488 
489  for (i = path_vars; i; i = i->next) {
490  if (strcmp(i->name, "applicationName") == 0) {
491  args.application_name = (i->value);
492  } else
493  {}
494  }
495  args.filter = body;
496  ast_ari_applications_filter(headers, &args, response);
497 #if defined(AST_DEVMODE)
498  code = response->response_code;
499 
500  switch (code) {
501  case 0: /* Implementation is still a stub, or the code wasn't set */
502  is_valid = response->message == NULL;
503  break;
504  case 500: /* Internal Server Error */
505  case 501: /* Not Implemented */
506  case 400: /* Bad request. */
507  case 404: /* Application does not exist. */
508  is_valid = 1;
509  break;
510  default:
511  if (200 <= code && code <= 299) {
512  is_valid = ast_ari_validate_application(
513  response->message);
514  } else {
515  ast_log(LOG_ERROR, "Invalid error response %d for /applications/{applicationName}/eventFilter\n", code);
516  is_valid = 0;
517  }
518  }
519 
520  if (!is_valid) {
521  ast_log(LOG_ERROR, "Response validation failed for /applications/{applicationName}/eventFilter\n");
522  ast_ari_response_error(response, 500,
523  "Internal Server Error", "Response validation failed");
524  }
525 #endif /* AST_DEVMODE */
526 
527 fin: __attribute__((unused))
528  return;
529 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char * args
#define NULL
Definition: resample.c:96
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
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 ast_json * message
Definition: ari.h:93
int ast_ari_validate_application(struct ast_json *json)
Validator for Application.
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.

◆ 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_cb()

static void ast_ari_applications_get_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /applications/{applicationName}.

Parameters
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 110 of file res_ari_applications.c.

References ast_ari_applications_get_args::application_name, ast_ari_applications_get(), ast_ari_response_error(), ast_ari_validate_application(), ast_log, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

114 {
116  struct ast_variable *i;
117 #if defined(AST_DEVMODE)
118  int is_valid;
119  int code;
120 #endif /* AST_DEVMODE */
121 
122  for (i = path_vars; i; i = i->next) {
123  if (strcmp(i->name, "applicationName") == 0) {
124  args.application_name = (i->value);
125  } else
126  {}
127  }
128  ast_ari_applications_get(headers, &args, response);
129 #if defined(AST_DEVMODE)
130  code = response->response_code;
131 
132  switch (code) {
133  case 0: /* Implementation is still a stub, or the code wasn't set */
134  is_valid = response->message == NULL;
135  break;
136  case 500: /* Internal Server Error */
137  case 501: /* Not Implemented */
138  case 404: /* Application does not exist. */
139  is_valid = 1;
140  break;
141  default:
142  if (200 <= code && code <= 299) {
143  is_valid = ast_ari_validate_application(
144  response->message);
145  } else {
146  ast_log(LOG_ERROR, "Invalid error response %d for /applications/{applicationName}\n", code);
147  is_valid = 0;
148  }
149  }
150 
151  if (!is_valid) {
152  ast_log(LOG_ERROR, "Response validation failed for /applications/{applicationName}\n");
153  ast_ari_response_error(response, 500,
154  "Internal Server Error", "Response validation failed");
155  }
156 #endif /* AST_DEVMODE */
157 
158 fin: __attribute__((unused))
159  return;
160 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char * args
#define NULL
Definition: resample.c:96
int response_code
Definition: ari.h:98
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.
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
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 ast_json * message
Definition: ari.h:93
int ast_ari_validate_application(struct ast_json *json)
Validator for Application.

◆ ast_ari_applications_list_cb()

static void ast_ari_applications_list_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /applications.

Parameters
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 60 of file res_ari_applications.c.

References ast_ari_applications_list(), ast_ari_response_error(), ast_ari_validate_application_fn(), ast_ari_validate_list(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

64 {
66 #if defined(AST_DEVMODE)
67  int is_valid;
68  int code;
69 #endif /* AST_DEVMODE */
70 
71  ast_ari_applications_list(headers, &args, response);
72 #if defined(AST_DEVMODE)
73  code = response->response_code;
74 
75  switch (code) {
76  case 0: /* Implementation is still a stub, or the code wasn't set */
77  is_valid = response->message == NULL;
78  break;
79  case 500: /* Internal Server Error */
80  case 501: /* Not Implemented */
81  is_valid = 1;
82  break;
83  default:
84  if (200 <= code && code <= 299) {
85  is_valid = ast_ari_validate_list(response->message,
87  } else {
88  ast_log(LOG_ERROR, "Invalid error response %d for /applications\n", code);
89  is_valid = 0;
90  }
91  }
92 
93  if (!is_valid) {
94  ast_log(LOG_ERROR, "Response validation failed for /applications\n");
95  ast_ari_response_error(response, 500,
96  "Internal Server Error", "Response validation failed");
97  }
98 #endif /* AST_DEVMODE */
99 
100 fin: __attribute__((unused))
101  return;
102 }
void ast_ari_applications_list(struct ast_variable *headers, struct ast_ari_applications_list_args *args, struct ast_ari_response *response)
List all applications.
const char * args
#define NULL
Definition: resample.c:96
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
ari_validator ast_ari_validate_application_fn(void)
Function pointer to ast_ari_validate_application().
#define LOG_ERROR
Definition: logger.h:285
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 ast_json * message
Definition: ari.h:93
int ast_ari_validate_list(struct ast_json *json, int(*fn)(struct ast_json *))
Validator for a Swagger List[]/JSON array.

◆ ast_ari_applications_subscribe_cb()

static void ast_ari_applications_subscribe_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /applications/{applicationName}/subscription.

Parameters
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 206 of file res_ari_applications.c.

References ast_ari_applications_subscribe_args::application_name, ARRAY_LEN, ast_app_separate_args, ast_ari_applications_subscribe(), ast_ari_applications_subscribe_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_application(), ast_free, ast_log, ast_malloc, ast_strdup, ast_ari_applications_subscribe_args::event_source, ast_ari_applications_subscribe_args::event_source_count, ast_ari_applications_subscribe_args::event_source_parse, LOG_ERROR, MAX_VALS, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

210 {
212  struct ast_variable *i;
213 #if defined(AST_DEVMODE)
214  int is_valid;
215  int code;
216 #endif /* AST_DEVMODE */
217 
218  for (i = get_params; i; i = i->next) {
219  if (strcmp(i->name, "eventSource") == 0) {
220  /* Parse comma separated list */
221  char *vals[MAX_VALS];
222  size_t j;
223 
225  if (!args.event_source_parse) {
227  goto fin;
228  }
229 
230  if (strlen(args.event_source_parse) == 0) {
231  /* ast_app_separate_args can't handle "" */
232  args.event_source_count = 1;
233  vals[0] = args.event_source_parse;
234  } else {
236  args.event_source_parse, ',', vals,
237  ARRAY_LEN(vals));
238  }
239 
240  if (args.event_source_count == 0) {
242  goto fin;
243  }
244 
245  if (args.event_source_count >= MAX_VALS) {
246  ast_ari_response_error(response, 400,
247  "Bad Request",
248  "Too many values for event_source");
249  goto fin;
250  }
251 
252  args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
253  if (!args.event_source) {
255  goto fin;
256  }
257 
258  for (j = 0; j < args.event_source_count; ++j) {
259  args.event_source[j] = (vals[j]);
260  }
261  } else
262  {}
263  }
264  for (i = path_vars; i; i = i->next) {
265  if (strcmp(i->name, "applicationName") == 0) {
266  args.application_name = (i->value);
267  } else
268  {}
269  }
272  goto fin;
273  }
274  ast_ari_applications_subscribe(headers, &args, response);
275 #if defined(AST_DEVMODE)
276  code = response->response_code;
277 
278  switch (code) {
279  case 0: /* Implementation is still a stub, or the code wasn't set */
280  is_valid = response->message == NULL;
281  break;
282  case 500: /* Internal Server Error */
283  case 501: /* Not Implemented */
284  case 400: /* Missing parameter. */
285  case 404: /* Application does not exist. */
286  case 422: /* Event source does not exist. */
287  is_valid = 1;
288  break;
289  default:
290  if (200 <= code && code <= 299) {
291  is_valid = ast_ari_validate_application(
292  response->message);
293  } else {
294  ast_log(LOG_ERROR, "Invalid error response %d for /applications/{applicationName}/subscription\n", code);
295  is_valid = 0;
296  }
297  }
298 
299  if (!is_valid) {
300  ast_log(LOG_ERROR, "Response validation failed for /applications/{applicationName}/subscription\n");
301  ast_ari_response_error(response, 500,
302  "Internal Server Error", "Response validation failed");
303  }
304 #endif /* AST_DEVMODE */
305 
306 fin: __attribute__((unused))
308  ast_free(args.event_source);
309  return;
310 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define MAX_VALS
Structure for variables, used for configurations and for channel variables.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const char * args
#define NULL
Definition: resample.c:96
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition: res_ari.c:298
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
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.
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.
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define LOG_ERROR
Definition: logger.h:285
#define ast_free(a)
Definition: astmm.h:182
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 ast_json * message
Definition: ari.h:93
int ast_ari_validate_application(struct ast_json *json)
Validator for Application.
#define ast_app_separate_args(a, b, c, d)

◆ 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_cb()

static void ast_ari_applications_unsubscribe_cb ( struct ast_tcptls_session_instance ser,
struct ast_variable get_params,
struct ast_variable path_vars,
struct ast_variable headers,
struct ast_json body,
struct ast_ari_response response 
)
static

Parameter parsing callback for /applications/{applicationName}/subscription.

Parameters
get_paramsGET parameters in the HTTP request.
path_varsPath variables extracted from the request.
headersHTTP headers.
[out]responseResponse to the HTTP request.

Definition at line 356 of file res_ari_applications.c.

References ast_ari_applications_unsubscribe_args::application_name, ARRAY_LEN, ast_app_separate_args, ast_ari_applications_unsubscribe(), ast_ari_applications_unsubscribe_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_application(), ast_free, ast_log, ast_malloc, ast_strdup, ast_ari_applications_unsubscribe_args::event_source, ast_ari_applications_unsubscribe_args::event_source_count, ast_ari_applications_unsubscribe_args::event_source_parse, LOG_ERROR, MAX_VALS, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

360 {
362  struct ast_variable *i;
363 #if defined(AST_DEVMODE)
364  int is_valid;
365  int code;
366 #endif /* AST_DEVMODE */
367 
368  for (i = get_params; i; i = i->next) {
369  if (strcmp(i->name, "eventSource") == 0) {
370  /* Parse comma separated list */
371  char *vals[MAX_VALS];
372  size_t j;
373 
375  if (!args.event_source_parse) {
377  goto fin;
378  }
379 
380  if (strlen(args.event_source_parse) == 0) {
381  /* ast_app_separate_args can't handle "" */
382  args.event_source_count = 1;
383  vals[0] = args.event_source_parse;
384  } else {
386  args.event_source_parse, ',', vals,
387  ARRAY_LEN(vals));
388  }
389 
390  if (args.event_source_count == 0) {
392  goto fin;
393  }
394 
395  if (args.event_source_count >= MAX_VALS) {
396  ast_ari_response_error(response, 400,
397  "Bad Request",
398  "Too many values for event_source");
399  goto fin;
400  }
401 
402  args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
403  if (!args.event_source) {
405  goto fin;
406  }
407 
408  for (j = 0; j < args.event_source_count; ++j) {
409  args.event_source[j] = (vals[j]);
410  }
411  } else
412  {}
413  }
414  for (i = path_vars; i; i = i->next) {
415  if (strcmp(i->name, "applicationName") == 0) {
416  args.application_name = (i->value);
417  } else
418  {}
419  }
422  goto fin;
423  }
424  ast_ari_applications_unsubscribe(headers, &args, response);
425 #if defined(AST_DEVMODE)
426  code = response->response_code;
427 
428  switch (code) {
429  case 0: /* Implementation is still a stub, or the code wasn't set */
430  is_valid = response->message == NULL;
431  break;
432  case 500: /* Internal Server Error */
433  case 501: /* Not Implemented */
434  case 400: /* Missing parameter; event source scheme not recognized. */
435  case 404: /* Application does not exist. */
436  case 409: /* Application not subscribed to event source. */
437  case 422: /* Event source does not exist. */
438  is_valid = 1;
439  break;
440  default:
441  if (200 <= code && code <= 299) {
442  is_valid = ast_ari_validate_application(
443  response->message);
444  } else {
445  ast_log(LOG_ERROR, "Invalid error response %d for /applications/{applicationName}/subscription\n", code);
446  is_valid = 0;
447  }
448  }
449 
450  if (!is_valid) {
451  ast_log(LOG_ERROR, "Response validation failed for /applications/{applicationName}/subscription\n");
452  ast_ari_response_error(response, 500,
453  "Internal Server Error", "Response validation failed");
454  }
455 #endif /* AST_DEVMODE */
456 
457 fin: __attribute__((unused))
459  ast_free(args.event_source);
460  return;
461 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define MAX_VALS
Structure for variables, used for configurations and for channel variables.
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.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
const char * args
#define NULL
Definition: resample.c:96
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition: res_ari.c:298
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
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.
#define LOG_ERROR
Definition: logger.h:285
#define ast_free(a)
Definition: astmm.h:182
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 ast_json * message
Definition: ari.h:93
int ast_ari_validate_application(struct ast_json *json)
Validator for Application.
#define ast_app_separate_args(a, b, c, d)

◆ 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

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 595 of file res_ari_applications.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 576 of file res_ari_applications.c.

References ast_ari_add_handler(), AST_MODFLAG_DEFAULT, AST_MODULE_INFO(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, AST_MODULE_SUPPORT_CORE, ASTERISK_GPL_KEY, and unload_module().

577 {
578  int res = 0;
579 
580 
582  if (res) {
583  unload_module();
585  }
586 
588 }
static struct stasis_rest_handlers applications
REST handler for /api-docs/applications.json.
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:179
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
static int unload_module(void)

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 570 of file res_ari_applications.c.

References ast_ari_remove_handler().

Referenced by load_module().

571 {
573  return 0;
574 }
static struct stasis_rest_handlers applications
REST handler for /api-docs/applications.json.
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:202

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Stasis application resources" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .requires = "res_ari,res_ari_model,res_stasis", }
static

Definition at line 595 of file res_ari_applications.c.

◆ applications

struct stasis_rest_handlers applications
static

REST handler for /api-docs/applications.json.

Definition at line 561 of file res_ari_applications.c.

◆ applications_applicationName

struct stasis_rest_handlers applications_applicationName
static

REST handler for /api-docs/applications.json.

Definition at line 551 of file res_ari_applications.c.

◆ applications_applicationName_eventFilter

struct stasis_rest_handlers applications_applicationName_eventFilter
static

REST handler for /api-docs/applications.json.

Definition at line 542 of file res_ari_applications.c.

◆ applications_applicationName_subscription

struct stasis_rest_handlers applications_applicationName_subscription
static

REST handler for /api-docs/applications.json.

Definition at line 532 of file res_ari_applications.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 595 of file res_ari_applications.c.