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

Bridge resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_bridges.h"
#include "ari/ari_model_validators.h"
Include dependency graph for res_ari_bridges.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_bridges_add_channel_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 /bridges/{bridgeId}/addChannel. More...
 
int ast_ari_bridges_add_channel_parse_body (struct ast_json *body, struct ast_ari_bridges_add_channel_args *args)
 Body parsing function for /bridges/{bridgeId}/addChannel. More...
 
static void ast_ari_bridges_clear_video_source_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 /bridges/{bridgeId}/videoSource. More...
 
static void ast_ari_bridges_create_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 /bridges. More...
 
int ast_ari_bridges_create_parse_body (struct ast_json *body, struct ast_ari_bridges_create_args *args)
 Body parsing function for /bridges. More...
 
static void ast_ari_bridges_create_with_id_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 /bridges/{bridgeId}. More...
 
int ast_ari_bridges_create_with_id_parse_body (struct ast_json *body, struct ast_ari_bridges_create_with_id_args *args)
 Body parsing function for /bridges/{bridgeId}. More...
 
static void ast_ari_bridges_destroy_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 /bridges/{bridgeId}. More...
 
static void ast_ari_bridges_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 /bridges/{bridgeId}. More...
 
static void ast_ari_bridges_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 /bridges. More...
 
static void ast_ari_bridges_play_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 /bridges/{bridgeId}/play. More...
 
int ast_ari_bridges_play_parse_body (struct ast_json *body, struct ast_ari_bridges_play_args *args)
 Body parsing function for /bridges/{bridgeId}/play. More...
 
static void ast_ari_bridges_play_with_id_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 /bridges/{bridgeId}/play/{playbackId}. More...
 
int ast_ari_bridges_play_with_id_parse_body (struct ast_json *body, struct ast_ari_bridges_play_with_id_args *args)
 Body parsing function for /bridges/{bridgeId}/play/{playbackId}. More...
 
static void ast_ari_bridges_record_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 /bridges/{bridgeId}/record. More...
 
int ast_ari_bridges_record_parse_body (struct ast_json *body, struct ast_ari_bridges_record_args *args)
 Body parsing function for /bridges/{bridgeId}/record. More...
 
static void ast_ari_bridges_remove_channel_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 /bridges/{bridgeId}/removeChannel. More...
 
int ast_ari_bridges_remove_channel_parse_body (struct ast_json *body, struct ast_ari_bridges_remove_channel_args *args)
 Body parsing function for /bridges/{bridgeId}/removeChannel. More...
 
static void ast_ari_bridges_set_video_source_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 /bridges/{bridgeId}/videoSource/{channelId}. More...
 
static void ast_ari_bridges_start_moh_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 /bridges/{bridgeId}/moh. More...
 
int ast_ari_bridges_start_moh_parse_body (struct ast_json *body, struct ast_ari_bridges_start_moh_args *args)
 Body parsing function for /bridges/{bridgeId}/moh. More...
 
static void ast_ari_bridges_stop_moh_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 /bridges/{bridgeId}/moh. 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 - Bridge 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,res_stasis_recording,res_stasis_playback", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers bridges
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_addChannel
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_moh
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_play
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_play_playbackId
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_record
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_removeChannel
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_videoSource
 REST handler for /api-docs/bridges.json. More...
 
static struct stasis_rest_handlers bridges_bridgeId_videoSource_channelId
 REST handler for /api-docs/bridges.json. More...
 

Detailed Description

Bridge resources.

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

Definition in file res_ari_bridges.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 1588 of file res_ari_bridges.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 1588 of file res_ari_bridges.c.

◆ ast_ari_bridges_add_channel_cb()

static void ast_ari_bridges_add_channel_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 /bridges/{bridgeId}/addChannel.

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 457 of file res_ari_bridges.c.

References ast_ari_bridges_add_channel_args::absorb_dtmf, ARRAY_LEN, ast_app_separate_args, ast_ari_bridges_add_channel(), ast_ari_bridges_add_channel_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_free, ast_log, ast_malloc, ast_strdup, ast_true(), ast_ari_bridges_add_channel_args::bridge_id, ast_ari_bridges_add_channel_args::channel, ast_ari_bridges_add_channel_args::channel_count, ast_ari_bridges_add_channel_args::channel_parse, ast_ari_bridges_add_channel_args::inhibit_connected_line_updates, LOG_ERROR, MAX_VALS, ast_ari_response::message, ast_ari_bridges_add_channel_args::mute, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_bridges_add_channel_args::role, and ast_variable::value.

461 {
463  struct ast_variable *i;
464 #if defined(AST_DEVMODE)
465  int is_valid;
466  int code;
467 #endif /* AST_DEVMODE */
468 
469  for (i = get_params; i; i = i->next) {
470  if (strcmp(i->name, "channel") == 0) {
471  /* Parse comma separated list */
472  char *vals[MAX_VALS];
473  size_t j;
474 
475  args.channel_parse = ast_strdup(i->value);
476  if (!args.channel_parse) {
478  goto fin;
479  }
480 
481  if (strlen(args.channel_parse) == 0) {
482  /* ast_app_separate_args can't handle "" */
483  args.channel_count = 1;
484  vals[0] = args.channel_parse;
485  } else {
487  args.channel_parse, ',', vals,
488  ARRAY_LEN(vals));
489  }
490 
491  if (args.channel_count == 0) {
493  goto fin;
494  }
495 
496  if (args.channel_count >= MAX_VALS) {
497  ast_ari_response_error(response, 400,
498  "Bad Request",
499  "Too many values for channel");
500  goto fin;
501  }
502 
503  args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
504  if (!args.channel) {
506  goto fin;
507  }
508 
509  for (j = 0; j < args.channel_count; ++j) {
510  args.channel[j] = (vals[j]);
511  }
512  } else
513  if (strcmp(i->name, "role") == 0) {
514  args.role = (i->value);
515  } else
516  if (strcmp(i->name, "absorbDTMF") == 0) {
517  args.absorb_dtmf = ast_true(i->value);
518  } else
519  if (strcmp(i->name, "mute") == 0) {
520  args.mute = ast_true(i->value);
521  } else
522  if (strcmp(i->name, "inhibitConnectedLineUpdates") == 0) {
524  } else
525  {}
526  }
527  for (i = path_vars; i; i = i->next) {
528  if (strcmp(i->name, "bridgeId") == 0) {
529  args.bridge_id = (i->value);
530  } else
531  {}
532  }
533  if (ast_ari_bridges_add_channel_parse_body(body, &args)) {
535  goto fin;
536  }
537  ast_ari_bridges_add_channel(headers, &args, response);
538 #if defined(AST_DEVMODE)
539  code = response->response_code;
540 
541  switch (code) {
542  case 0: /* Implementation is still a stub, or the code wasn't set */
543  is_valid = response->message == NULL;
544  break;
545  case 500: /* Internal Server Error */
546  case 501: /* Not Implemented */
547  case 400: /* Channel not found */
548  case 404: /* Bridge not found */
549  case 409: /* Bridge not in Stasis application; Channel currently recording */
550  case 422: /* Channel not in Stasis application */
551  is_valid = 1;
552  break;
553  default:
554  if (200 <= code && code <= 299) {
555  is_valid = ast_ari_validate_void(
556  response->message);
557  } else {
558  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/addChannel\n", code);
559  is_valid = 0;
560  }
561  }
562 
563  if (!is_valid) {
564  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/addChannel\n");
565  ast_ari_response_error(response, 500,
566  "Internal Server Error", "Response validation failed");
567  }
568 #endif /* AST_DEVMODE */
569 
570 fin: __attribute__((unused))
571  ast_free(args.channel_parse);
572  ast_free(args.channel);
573  return;
574 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
void ast_ari_bridges_add_channel(struct ast_variable *headers, struct ast_ari_bridges_add_channel_args *args, struct ast_ari_response *response)
Add a channel to a bridge.
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 ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:98
#define MAX_VALS
#define ast_log
Definition: astobj2.c:42
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define LOG_ERROR
Definition: logger.h:285
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
int ast_ari_bridges_add_channel_parse_body(struct ast_json *body, struct ast_ari_bridges_add_channel_args *args)
Body parsing function for /bridges/{bridgeId}/addChannel.
#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
#define ast_app_separate_args(a, b, c, d)

◆ ast_ari_bridges_add_channel_parse_body()

int ast_ari_bridges_add_channel_parse_body ( struct ast_json body,
struct ast_ari_bridges_add_channel_args args 
)

Body parsing function for /bridges/{bridgeId}/addChannel.

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 396 of file res_ari_bridges.c.

References ast_ari_bridges_add_channel_args::absorb_dtmf, ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_is_true(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), ast_malloc, ast_ari_bridges_add_channel_args::channel, ast_ari_bridges_add_channel_args::channel_count, ast_ari_bridges_add_channel_args::inhibit_connected_line_updates, ast_ari_bridges_add_channel_args::mute, and ast_ari_bridges_add_channel_args::role.

Referenced by ast_ari_bridges_add_channel_cb().

399 {
400  struct ast_json *field;
401  /* Parse query parameters out of it */
402  field = ast_json_object_get(body, "channel");
403  if (field) {
404  /* If they were silly enough to both pass in a query param and a
405  * JSON body, free up the query value.
406  */
407  ast_free(args->channel);
408  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
409  /* Multiple param passed as array */
410  size_t i;
411  args->channel_count = ast_json_array_size(field);
412  args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
413 
414  if (!args->channel) {
415  return -1;
416  }
417 
418  for (i = 0; i < args->channel_count; ++i) {
419  args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
420  }
421  } else {
422  /* Multiple param passed as single value */
423  args->channel_count = 1;
424  args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
425  if (!args->channel) {
426  return -1;
427  }
428  args->channel[0] = ast_json_string_get(field);
429  }
430  }
431  field = ast_json_object_get(body, "role");
432  if (field) {
433  args->role = ast_json_string_get(field);
434  }
435  field = ast_json_object_get(body, "absorbDTMF");
436  if (field) {
437  args->absorb_dtmf = ast_json_is_true(field);
438  }
439  field = ast_json_object_get(body, "mute");
440  if (field) {
441  args->mute = ast_json_is_true(field);
442  }
443  field = ast_json_object_get(body, "inhibitConnectedLineUpdates");
444  if (field) {
446  }
447  return 0;
448 }
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Definition: json.c:253
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_bridges_clear_video_source_cb()

static void ast_ari_bridges_clear_video_source_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 /bridges/{bridgeId}/videoSource.

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 796 of file res_ari_bridges.c.

References ast_ari_bridges_clear_video_source(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_bridges_clear_video_source_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

800 {
802  struct ast_variable *i;
803 #if defined(AST_DEVMODE)
804  int is_valid;
805  int code;
806 #endif /* AST_DEVMODE */
807 
808  for (i = path_vars; i; i = i->next) {
809  if (strcmp(i->name, "bridgeId") == 0) {
810  args.bridge_id = (i->value);
811  } else
812  {}
813  }
814  ast_ari_bridges_clear_video_source(headers, &args, response);
815 #if defined(AST_DEVMODE)
816  code = response->response_code;
817 
818  switch (code) {
819  case 0: /* Implementation is still a stub, or the code wasn't set */
820  is_valid = response->message == NULL;
821  break;
822  case 500: /* Internal Server Error */
823  case 501: /* Not Implemented */
824  case 404: /* Bridge not found */
825  is_valid = 1;
826  break;
827  default:
828  if (200 <= code && code <= 299) {
829  is_valid = ast_ari_validate_void(
830  response->message);
831  } else {
832  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/videoSource\n", code);
833  is_valid = 0;
834  }
835  }
836 
837  if (!is_valid) {
838  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/videoSource\n");
839  ast_ari_response_error(response, 500,
840  "Internal Server Error", "Response validation failed");
841  }
842 #endif /* AST_DEVMODE */
843 
844 fin: __attribute__((unused))
845  return;
846 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char * args
#define NULL
Definition: resample.c:96
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
void ast_ari_bridges_clear_video_source(struct ast_variable *headers, struct ast_ari_bridges_clear_video_source_args *args, struct ast_ari_response *response)
Removes any explicit video source in a multi-party mixing bridge. This operation has no effect on bri...
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

◆ ast_ari_bridges_create_cb()

static void ast_ari_bridges_create_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 /bridges.

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 133 of file res_ari_bridges.c.

References ast_ari_bridges_create(), ast_ari_bridges_create_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_bridge(), ast_log, ast_ari_bridges_create_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_ari_bridges_create_args::name, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_bridges_create_args::type, and ast_variable::value.

137 {
138  struct ast_ari_bridges_create_args args = {};
139  struct ast_variable *i;
140 #if defined(AST_DEVMODE)
141  int is_valid;
142  int code;
143 #endif /* AST_DEVMODE */
144 
145  for (i = get_params; i; i = i->next) {
146  if (strcmp(i->name, "type") == 0) {
147  args.type = (i->value);
148  } else
149  if (strcmp(i->name, "bridgeId") == 0) {
150  args.bridge_id = (i->value);
151  } else
152  if (strcmp(i->name, "name") == 0) {
153  args.name = (i->value);
154  } else
155  {}
156  }
157  if (ast_ari_bridges_create_parse_body(body, &args)) {
159  goto fin;
160  }
161  ast_ari_bridges_create(headers, &args, response);
162 #if defined(AST_DEVMODE)
163  code = response->response_code;
164 
165  switch (code) {
166  case 0: /* Implementation is still a stub, or the code wasn't set */
167  is_valid = response->message == NULL;
168  break;
169  case 500: /* Internal Server Error */
170  case 501: /* Not Implemented */
171  is_valid = 1;
172  break;
173  default:
174  if (200 <= code && code <= 299) {
175  is_valid = ast_ari_validate_bridge(
176  response->message);
177  } else {
178  ast_log(LOG_ERROR, "Invalid error response %d for /bridges\n", code);
179  is_valid = 0;
180  }
181  }
182 
183  if (!is_valid) {
184  ast_log(LOG_ERROR, "Response validation failed for /bridges\n");
185  ast_ari_response_error(response, 500,
186  "Internal Server Error", "Response validation failed");
187  }
188 #endif /* AST_DEVMODE */
189 
190 fin: __attribute__((unused))
191  return;
192 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
void ast_ari_bridges_create(struct ast_variable *headers, struct ast_ari_bridges_create_args *args, struct ast_ari_response *response)
Create a new bridge.
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 LOG_ERROR
Definition: logger.h:285
int ast_ari_validate_bridge(struct ast_json *json)
Validator for Bridge.
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_bridges_create_parse_body(struct ast_json *body, struct ast_ari_bridges_create_args *args)
Body parsing function for /bridges.

◆ ast_ari_bridges_create_parse_body()

int ast_ari_bridges_create_parse_body ( struct ast_json body,
struct ast_ari_bridges_create_args args 
)

Body parsing function for /bridges.

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 105 of file res_ari_bridges.c.

References ast_json_object_get(), ast_json_string_get(), ast_ari_bridges_create_args::bridge_id, ast_ari_bridges_create_args::name, and ast_ari_bridges_create_args::type.

Referenced by ast_ari_bridges_create_cb().

108 {
109  struct ast_json *field;
110  /* Parse query parameters out of it */
111  field = ast_json_object_get(body, "type");
112  if (field) {
113  args->type = ast_json_string_get(field);
114  }
115  field = ast_json_object_get(body, "bridgeId");
116  if (field) {
117  args->bridge_id = ast_json_string_get(field);
118  }
119  field = ast_json_object_get(body, "name");
120  if (field) {
121  args->name = ast_json_string_get(field);
122  }
123  return 0;
124 }
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
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
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_bridges_create_with_id_cb()

static void ast_ari_bridges_create_with_id_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 /bridges/{bridgeId}.

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 217 of file res_ari_bridges.c.

References ast_ari_bridges_create_with_id(), ast_ari_bridges_create_with_id_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_bridge(), ast_log, ast_ari_bridges_create_with_id_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_ari_bridges_create_with_id_args::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_bridges_create_with_id_args::type, and ast_variable::value.

221 {
223  struct ast_variable *i;
224 #if defined(AST_DEVMODE)
225  int is_valid;
226  int code;
227 #endif /* AST_DEVMODE */
228 
229  for (i = get_params; i; i = i->next) {
230  if (strcmp(i->name, "type") == 0) {
231  args.type = (i->value);
232  } else
233  if (strcmp(i->name, "name") == 0) {
234  args.name = (i->value);
235  } else
236  {}
237  }
238  for (i = path_vars; i; i = i->next) {
239  if (strcmp(i->name, "bridgeId") == 0) {
240  args.bridge_id = (i->value);
241  } else
242  {}
243  }
246  goto fin;
247  }
248  ast_ari_bridges_create_with_id(headers, &args, response);
249 #if defined(AST_DEVMODE)
250  code = response->response_code;
251 
252  switch (code) {
253  case 0: /* Implementation is still a stub, or the code wasn't set */
254  is_valid = response->message == NULL;
255  break;
256  case 500: /* Internal Server Error */
257  case 501: /* Not Implemented */
258  is_valid = 1;
259  break;
260  default:
261  if (200 <= code && code <= 299) {
262  is_valid = ast_ari_validate_bridge(
263  response->message);
264  } else {
265  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
266  is_valid = 0;
267  }
268  }
269 
270  if (!is_valid) {
271  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
272  ast_ari_response_error(response, 500,
273  "Internal Server Error", "Response validation failed");
274  }
275 #endif /* AST_DEVMODE */
276 
277 fin: __attribute__((unused))
278  return;
279 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
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
int ast_ari_bridges_create_with_id_parse_body(struct ast_json *body, struct ast_ari_bridges_create_with_id_args *args)
Body parsing function for /bridges/{bridgeId}.
#define LOG_ERROR
Definition: logger.h:285
int ast_ari_validate_bridge(struct ast_json *json)
Validator for Bridge.
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_bridges_create_with_id(struct ast_variable *headers, struct ast_ari_bridges_create_with_id_args *args, struct ast_ari_response *response)
Create a new bridge or updates an existing one.
struct ast_json * message
Definition: ari.h:93

◆ ast_ari_bridges_create_with_id_parse_body()

int ast_ari_bridges_create_with_id_parse_body ( struct ast_json body,
struct ast_ari_bridges_create_with_id_args args 
)

Body parsing function for /bridges/{bridgeId}.

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 193 of file res_ari_bridges.c.

References ast_json_object_get(), ast_json_string_get(), ast_ari_bridges_create_with_id_args::name, and ast_ari_bridges_create_with_id_args::type.

Referenced by ast_ari_bridges_create_with_id_cb().

196 {
197  struct ast_json *field;
198  /* Parse query parameters out of it */
199  field = ast_json_object_get(body, "type");
200  if (field) {
201  args->type = ast_json_string_get(field);
202  }
203  field = ast_json_object_get(body, "name");
204  if (field) {
205  args->name = ast_json_string_get(field);
206  }
207  return 0;
208 }
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
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
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_bridges_destroy_cb()

static void ast_ari_bridges_destroy_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 /bridges/{bridgeId}.

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 345 of file res_ari_bridges.c.

References ast_ari_bridges_destroy(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_bridges_destroy_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

349 {
351  struct ast_variable *i;
352 #if defined(AST_DEVMODE)
353  int is_valid;
354  int code;
355 #endif /* AST_DEVMODE */
356 
357  for (i = path_vars; i; i = i->next) {
358  if (strcmp(i->name, "bridgeId") == 0) {
359  args.bridge_id = (i->value);
360  } else
361  {}
362  }
363  ast_ari_bridges_destroy(headers, &args, response);
364 #if defined(AST_DEVMODE)
365  code = response->response_code;
366 
367  switch (code) {
368  case 0: /* Implementation is still a stub, or the code wasn't set */
369  is_valid = response->message == NULL;
370  break;
371  case 500: /* Internal Server Error */
372  case 501: /* Not Implemented */
373  case 404: /* Bridge not found */
374  is_valid = 1;
375  break;
376  default:
377  if (200 <= code && code <= 299) {
378  is_valid = ast_ari_validate_void(
379  response->message);
380  } else {
381  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
382  is_valid = 0;
383  }
384  }
385 
386  if (!is_valid) {
387  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
388  ast_ari_response_error(response, 500,
389  "Internal Server Error", "Response validation failed");
390  }
391 #endif /* AST_DEVMODE */
392 
393 fin: __attribute__((unused))
394  return;
395 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char * args
#define NULL
Definition: resample.c:96
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
void ast_ari_bridges_destroy(struct ast_variable *headers, struct ast_ari_bridges_destroy_args *args, struct ast_ari_response *response)
Shut down a bridge.
#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

◆ ast_ari_bridges_get_cb()

static void ast_ari_bridges_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 /bridges/{bridgeId}.

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 287 of file res_ari_bridges.c.

References ast_ari_bridges_get(), ast_ari_response_error(), ast_ari_validate_bridge(), ast_log, ast_ari_bridges_get_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

291 {
292  struct ast_ari_bridges_get_args args = {};
293  struct ast_variable *i;
294 #if defined(AST_DEVMODE)
295  int is_valid;
296  int code;
297 #endif /* AST_DEVMODE */
298 
299  for (i = path_vars; i; i = i->next) {
300  if (strcmp(i->name, "bridgeId") == 0) {
301  args.bridge_id = (i->value);
302  } else
303  {}
304  }
305  ast_ari_bridges_get(headers, &args, response);
306 #if defined(AST_DEVMODE)
307  code = response->response_code;
308 
309  switch (code) {
310  case 0: /* Implementation is still a stub, or the code wasn't set */
311  is_valid = response->message == NULL;
312  break;
313  case 500: /* Internal Server Error */
314  case 501: /* Not Implemented */
315  case 404: /* Bridge not found */
316  is_valid = 1;
317  break;
318  default:
319  if (200 <= code && code <= 299) {
320  is_valid = ast_ari_validate_bridge(
321  response->message);
322  } else {
323  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}\n", code);
324  is_valid = 0;
325  }
326  }
327 
328  if (!is_valid) {
329  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}\n");
330  ast_ari_response_error(response, 500,
331  "Internal Server Error", "Response validation failed");
332  }
333 #endif /* AST_DEVMODE */
334 
335 fin: __attribute__((unused))
336  return;
337 }
struct ast_variable * next
void ast_ari_bridges_get(struct ast_variable *headers, struct ast_ari_bridges_get_args *args, struct ast_ari_response *response)
Get bridge details.
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
int ast_ari_validate_bridge(struct ast_json *json)
Validator for Bridge.
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

◆ ast_ari_bridges_list_cb()

static void ast_ari_bridges_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 /bridges.

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 62 of file res_ari_bridges.c.

References ast_ari_bridges_list(), ast_ari_response_error(), ast_ari_validate_bridge_fn(), ast_ari_validate_list(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

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

static void ast_ari_bridges_play_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 /bridges/{bridgeId}/play.

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 1049 of file res_ari_bridges.c.

References ARRAY_LEN, ast_app_separate_args, ast_ari_bridges_play(), ast_ari_bridges_play_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_playback(), ast_free, ast_log, ast_malloc, ast_strdup, ast_ari_bridges_play_args::bridge_id, ast_ari_bridges_play_args::lang, LOG_ERROR, MAX_VALS, ast_ari_bridges_play_args::media, ast_ari_bridges_play_args::media_count, ast_ari_bridges_play_args::media_parse, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_bridges_play_args::offsetms, ast_ari_bridges_play_args::playback_id, ast_ari_response::response_code, ast_ari_bridges_play_args::skipms, and ast_variable::value.

1053 {
1054  struct ast_ari_bridges_play_args args = {};
1055  struct ast_variable *i;
1056 #if defined(AST_DEVMODE)
1057  int is_valid;
1058  int code;
1059 #endif /* AST_DEVMODE */
1060 
1061  for (i = get_params; i; i = i->next) {
1062  if (strcmp(i->name, "media") == 0) {
1063  /* Parse comma separated list */
1064  char *vals[MAX_VALS];
1065  size_t j;
1066 
1067  args.media_parse = ast_strdup(i->value);
1068  if (!args.media_parse) {
1070  goto fin;
1071  }
1072 
1073  if (strlen(args.media_parse) == 0) {
1074  /* ast_app_separate_args can't handle "" */
1075  args.media_count = 1;
1076  vals[0] = args.media_parse;
1077  } else {
1079  args.media_parse, ',', vals,
1080  ARRAY_LEN(vals));
1081  }
1082 
1083  if (args.media_count == 0) {
1085  goto fin;
1086  }
1087 
1088  if (args.media_count >= MAX_VALS) {
1089  ast_ari_response_error(response, 400,
1090  "Bad Request",
1091  "Too many values for media");
1092  goto fin;
1093  }
1094 
1095  args.media = ast_malloc(sizeof(*args.media) * args.media_count);
1096  if (!args.media) {
1098  goto fin;
1099  }
1100 
1101  for (j = 0; j < args.media_count; ++j) {
1102  args.media[j] = (vals[j]);
1103  }
1104  } else
1105  if (strcmp(i->name, "lang") == 0) {
1106  args.lang = (i->value);
1107  } else
1108  if (strcmp(i->name, "offsetms") == 0) {
1109  args.offsetms = atoi(i->value);
1110  } else
1111  if (strcmp(i->name, "skipms") == 0) {
1112  args.skipms = atoi(i->value);
1113  } else
1114  if (strcmp(i->name, "playbackId") == 0) {
1115  args.playback_id = (i->value);
1116  } else
1117  {}
1118  }
1119  for (i = path_vars; i; i = i->next) {
1120  if (strcmp(i->name, "bridgeId") == 0) {
1121  args.bridge_id = (i->value);
1122  } else
1123  {}
1124  }
1125  if (ast_ari_bridges_play_parse_body(body, &args)) {
1127  goto fin;
1128  }
1129  ast_ari_bridges_play(headers, &args, response);
1130 #if defined(AST_DEVMODE)
1131  code = response->response_code;
1132 
1133  switch (code) {
1134  case 0: /* Implementation is still a stub, or the code wasn't set */
1135  is_valid = response->message == NULL;
1136  break;
1137  case 500: /* Internal Server Error */
1138  case 501: /* Not Implemented */
1139  case 404: /* Bridge not found */
1140  case 409: /* Bridge not in a Stasis application */
1141  is_valid = 1;
1142  break;
1143  default:
1144  if (200 <= code && code <= 299) {
1145  is_valid = ast_ari_validate_playback(
1146  response->message);
1147  } else {
1148  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/play\n", code);
1149  is_valid = 0;
1150  }
1151  }
1152 
1153  if (!is_valid) {
1154  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/play\n");
1155  ast_ari_response_error(response, 500,
1156  "Internal Server Error", "Response validation failed");
1157  }
1158 #endif /* AST_DEVMODE */
1159 
1160 fin: __attribute__((unused))
1161  ast_free(args.media_parse);
1162  ast_free(args.media);
1163  return;
1164 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
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
int ast_ari_bridges_play_parse_body(struct ast_json *body, struct ast_ari_bridges_play_args *args)
Body parsing function for /bridges/{bridgeId}/play.
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
void ast_ari_bridges_play(struct ast_variable *headers, struct ast_ari_bridges_play_args *args, struct ast_ari_response *response)
Start playback of media on a bridge.
int response_code
Definition: ari.h:98
#define MAX_VALS
#define ast_log
Definition: astobj2.c:42
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
int ast_ari_validate_playback(struct ast_json *json)
Validator for Playback.
#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
#define ast_app_separate_args(a, b, c, d)

◆ ast_ari_bridges_play_parse_body()

int ast_ari_bridges_play_parse_body ( struct ast_json body,
struct ast_ari_bridges_play_args args 
)

Body parsing function for /bridges/{bridgeId}/play.

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 988 of file res_ari_bridges.c.

References ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), ast_malloc, ast_ari_bridges_play_args::lang, ast_ari_bridges_play_args::media, ast_ari_bridges_play_args::media_count, ast_ari_bridges_play_args::offsetms, ast_ari_bridges_play_args::playback_id, and ast_ari_bridges_play_args::skipms.

Referenced by ast_ari_bridges_play_cb().

991 {
992  struct ast_json *field;
993  /* Parse query parameters out of it */
994  field = ast_json_object_get(body, "media");
995  if (field) {
996  /* If they were silly enough to both pass in a query param and a
997  * JSON body, free up the query value.
998  */
999  ast_free(args->media);
1000  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
1001  /* Multiple param passed as array */
1002  size_t i;
1003  args->media_count = ast_json_array_size(field);
1004  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1005 
1006  if (!args->media) {
1007  return -1;
1008  }
1009 
1010  for (i = 0; i < args->media_count; ++i) {
1011  args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
1012  }
1013  } else {
1014  /* Multiple param passed as single value */
1015  args->media_count = 1;
1016  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1017  if (!args->media) {
1018  return -1;
1019  }
1020  args->media[0] = ast_json_string_get(field);
1021  }
1022  }
1023  field = ast_json_object_get(body, "lang");
1024  if (field) {
1025  args->lang = ast_json_string_get(field);
1026  }
1027  field = ast_json_object_get(body, "offsetms");
1028  if (field) {
1029  args->offsetms = ast_json_integer_get(field);
1030  }
1031  field = ast_json_object_get(body, "skipms");
1032  if (field) {
1033  args->skipms = ast_json_integer_get(field);
1034  }
1035  field = ast_json_object_get(body, "playbackId");
1036  if (field) {
1037  args->playback_id = ast_json_string_get(field);
1038  }
1039  return 0;
1040 }
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, ...).
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322
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_bridges_play_with_id_cb()

static void ast_ari_bridges_play_with_id_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 /bridges/{bridgeId}/play/{playbackId}.

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 1222 of file res_ari_bridges.c.

References ARRAY_LEN, ast_app_separate_args, ast_ari_bridges_play_with_id(), ast_ari_bridges_play_with_id_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_playback(), ast_free, ast_log, ast_malloc, ast_strdup, ast_ari_bridges_play_with_id_args::bridge_id, ast_ari_bridges_play_with_id_args::lang, LOG_ERROR, MAX_VALS, ast_ari_bridges_play_with_id_args::media, ast_ari_bridges_play_with_id_args::media_count, ast_ari_bridges_play_with_id_args::media_parse, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_bridges_play_with_id_args::offsetms, ast_ari_bridges_play_with_id_args::playback_id, ast_ari_response::response_code, ast_ari_bridges_play_with_id_args::skipms, and ast_variable::value.

1226 {
1228  struct ast_variable *i;
1229 #if defined(AST_DEVMODE)
1230  int is_valid;
1231  int code;
1232 #endif /* AST_DEVMODE */
1233 
1234  for (i = get_params; i; i = i->next) {
1235  if (strcmp(i->name, "media") == 0) {
1236  /* Parse comma separated list */
1237  char *vals[MAX_VALS];
1238  size_t j;
1239 
1240  args.media_parse = ast_strdup(i->value);
1241  if (!args.media_parse) {
1243  goto fin;
1244  }
1245 
1246  if (strlen(args.media_parse) == 0) {
1247  /* ast_app_separate_args can't handle "" */
1248  args.media_count = 1;
1249  vals[0] = args.media_parse;
1250  } else {
1252  args.media_parse, ',', vals,
1253  ARRAY_LEN(vals));
1254  }
1255 
1256  if (args.media_count == 0) {
1258  goto fin;
1259  }
1260 
1261  if (args.media_count >= MAX_VALS) {
1262  ast_ari_response_error(response, 400,
1263  "Bad Request",
1264  "Too many values for media");
1265  goto fin;
1266  }
1267 
1268  args.media = ast_malloc(sizeof(*args.media) * args.media_count);
1269  if (!args.media) {
1271  goto fin;
1272  }
1273 
1274  for (j = 0; j < args.media_count; ++j) {
1275  args.media[j] = (vals[j]);
1276  }
1277  } else
1278  if (strcmp(i->name, "lang") == 0) {
1279  args.lang = (i->value);
1280  } else
1281  if (strcmp(i->name, "offsetms") == 0) {
1282  args.offsetms = atoi(i->value);
1283  } else
1284  if (strcmp(i->name, "skipms") == 0) {
1285  args.skipms = atoi(i->value);
1286  } else
1287  {}
1288  }
1289  for (i = path_vars; i; i = i->next) {
1290  if (strcmp(i->name, "bridgeId") == 0) {
1291  args.bridge_id = (i->value);
1292  } else
1293  if (strcmp(i->name, "playbackId") == 0) {
1294  args.playback_id = (i->value);
1295  } else
1296  {}
1297  }
1298  if (ast_ari_bridges_play_with_id_parse_body(body, &args)) {
1300  goto fin;
1301  }
1302  ast_ari_bridges_play_with_id(headers, &args, response);
1303 #if defined(AST_DEVMODE)
1304  code = response->response_code;
1305 
1306  switch (code) {
1307  case 0: /* Implementation is still a stub, or the code wasn't set */
1308  is_valid = response->message == NULL;
1309  break;
1310  case 500: /* Internal Server Error */
1311  case 501: /* Not Implemented */
1312  case 404: /* Bridge not found */
1313  case 409: /* Bridge not in a Stasis application */
1314  is_valid = 1;
1315  break;
1316  default:
1317  if (200 <= code && code <= 299) {
1318  is_valid = ast_ari_validate_playback(
1319  response->message);
1320  } else {
1321  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/play/{playbackId}\n", code);
1322  is_valid = 0;
1323  }
1324  }
1325 
1326  if (!is_valid) {
1327  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/play/{playbackId}\n");
1328  ast_ari_response_error(response, 500,
1329  "Internal Server Error", "Response validation failed");
1330  }
1331 #endif /* AST_DEVMODE */
1332 
1333 fin: __attribute__((unused))
1334  ast_free(args.media_parse);
1335  ast_free(args.media);
1336  return;
1337 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
void ast_ari_bridges_play_with_id(struct ast_variable *headers, struct ast_ari_bridges_play_with_id_args *args, struct ast_ari_response *response)
Start playback of media on a bridge.
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 MAX_VALS
#define ast_log
Definition: astobj2.c:42
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
int ast_ari_validate_playback(struct ast_json *json)
Validator for Playback.
#define LOG_ERROR
Definition: logger.h:285
int ast_ari_bridges_play_with_id_parse_body(struct ast_json *body, struct ast_ari_bridges_play_with_id_args *args)
Body parsing function for /bridges/{bridgeId}/play/{playbackId}.
#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
#define ast_app_separate_args(a, b, c, d)

◆ ast_ari_bridges_play_with_id_parse_body()

int ast_ari_bridges_play_with_id_parse_body ( struct ast_json body,
struct ast_ari_bridges_play_with_id_args args 
)

Body parsing function for /bridges/{bridgeId}/play/{playbackId}.

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 1165 of file res_ari_bridges.c.

References ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), ast_malloc, ast_ari_bridges_play_with_id_args::lang, ast_ari_bridges_play_with_id_args::media, ast_ari_bridges_play_with_id_args::media_count, ast_ari_bridges_play_with_id_args::offsetms, and ast_ari_bridges_play_with_id_args::skipms.

Referenced by ast_ari_bridges_play_with_id_cb().

1168 {
1169  struct ast_json *field;
1170  /* Parse query parameters out of it */
1171  field = ast_json_object_get(body, "media");
1172  if (field) {
1173  /* If they were silly enough to both pass in a query param and a
1174  * JSON body, free up the query value.
1175  */
1176  ast_free(args->media);
1177  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
1178  /* Multiple param passed as array */
1179  size_t i;
1180  args->media_count = ast_json_array_size(field);
1181  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1182 
1183  if (!args->media) {
1184  return -1;
1185  }
1186 
1187  for (i = 0; i < args->media_count; ++i) {
1188  args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
1189  }
1190  } else {
1191  /* Multiple param passed as single value */
1192  args->media_count = 1;
1193  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1194  if (!args->media) {
1195  return -1;
1196  }
1197  args->media[0] = ast_json_string_get(field);
1198  }
1199  }
1200  field = ast_json_object_get(body, "lang");
1201  if (field) {
1202  args->lang = ast_json_string_get(field);
1203  }
1204  field = ast_json_object_get(body, "offsetms");
1205  if (field) {
1206  args->offsetms = ast_json_integer_get(field);
1207  }
1208  field = ast_json_object_get(body, "skipms");
1209  if (field) {
1210  args->skipms = ast_json_integer_get(field);
1211  }
1212  return 0;
1213 }
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, ...).
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322
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_bridges_record_cb()

static void ast_ari_bridges_record_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 /bridges/{bridgeId}/record.

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 1382 of file res_ari_bridges.c.

References ast_ari_bridges_record(), ast_ari_bridges_record_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_live_recording(), ast_log, ast_true(), ast_ari_bridges_record_args::beep, ast_ari_bridges_record_args::bridge_id, ast_ari_bridges_record_args::format, ast_ari_bridges_record_args::if_exists, LOG_ERROR, ast_ari_bridges_record_args::max_duration_seconds, ast_ari_bridges_record_args::max_silence_seconds, ast_ari_response::message, ast_variable::name, ast_ari_bridges_record_args::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_bridges_record_args::terminate_on, and ast_variable::value.

1386 {
1387  struct ast_ari_bridges_record_args args = {};
1388  struct ast_variable *i;
1389 #if defined(AST_DEVMODE)
1390  int is_valid;
1391  int code;
1392 #endif /* AST_DEVMODE */
1393 
1394  for (i = get_params; i; i = i->next) {
1395  if (strcmp(i->name, "name") == 0) {
1396  args.name = (i->value);
1397  } else
1398  if (strcmp(i->name, "format") == 0) {
1399  args.format = (i->value);
1400  } else
1401  if (strcmp(i->name, "maxDurationSeconds") == 0) {
1402  args.max_duration_seconds = atoi(i->value);
1403  } else
1404  if (strcmp(i->name, "maxSilenceSeconds") == 0) {
1405  args.max_silence_seconds = atoi(i->value);
1406  } else
1407  if (strcmp(i->name, "ifExists") == 0) {
1408  args.if_exists = (i->value);
1409  } else
1410  if (strcmp(i->name, "beep") == 0) {
1411  args.beep = ast_true(i->value);
1412  } else
1413  if (strcmp(i->name, "terminateOn") == 0) {
1414  args.terminate_on = (i->value);
1415  } else
1416  {}
1417  }
1418  for (i = path_vars; i; i = i->next) {
1419  if (strcmp(i->name, "bridgeId") == 0) {
1420  args.bridge_id = (i->value);
1421  } else
1422  {}
1423  }
1424  if (ast_ari_bridges_record_parse_body(body, &args)) {
1426  goto fin;
1427  }
1428  ast_ari_bridges_record(headers, &args, response);
1429 #if defined(AST_DEVMODE)
1430  code = response->response_code;
1431 
1432  switch (code) {
1433  case 0: /* Implementation is still a stub, or the code wasn't set */
1434  is_valid = response->message == NULL;
1435  break;
1436  case 500: /* Internal Server Error */
1437  case 501: /* Not Implemented */
1438  case 400: /* Invalid parameters */
1439  case 404: /* Bridge not found */
1440  case 409: /* Bridge is not in a Stasis application; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
1441  case 422: /* The format specified is unknown on this system */
1442  is_valid = 1;
1443  break;
1444  default:
1445  if (200 <= code && code <= 299) {
1447  response->message);
1448  } else {
1449  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/record\n", code);
1450  is_valid = 0;
1451  }
1452  }
1453 
1454  if (!is_valid) {
1455  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/record\n");
1456  ast_ari_response_error(response, 500,
1457  "Internal Server Error", "Response validation failed");
1458  }
1459 #endif /* AST_DEVMODE */
1460 
1461 fin: __attribute__((unused))
1462  return;
1463 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
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 LOG_ERROR
Definition: logger.h:285
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
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
int ast_ari_validate_live_recording(struct ast_json *json)
Validator for LiveRecording.
struct ast_json * message
Definition: ari.h:93
void ast_ari_bridges_record(struct ast_variable *headers, struct ast_ari_bridges_record_args *args, struct ast_ari_response *response)
Start a recording.
int ast_ari_bridges_record_parse_body(struct ast_json *body, struct ast_ari_bridges_record_args *args)
Body parsing function for /bridges/{bridgeId}/record.

◆ ast_ari_bridges_record_parse_body()

int ast_ari_bridges_record_parse_body ( struct ast_json body,
struct ast_ari_bridges_record_args args 
)

Body parsing function for /bridges/{bridgeId}/record.

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 1338 of file res_ari_bridges.c.

References ast_json_integer_get(), ast_json_is_true(), ast_json_object_get(), ast_json_string_get(), ast_ari_bridges_record_args::beep, ast_ari_bridges_record_args::format, ast_ari_bridges_record_args::if_exists, ast_ari_bridges_record_args::max_duration_seconds, ast_ari_bridges_record_args::max_silence_seconds, ast_ari_bridges_record_args::name, and ast_ari_bridges_record_args::terminate_on.

Referenced by ast_ari_bridges_record_cb().

1341 {
1342  struct ast_json *field;
1343  /* Parse query parameters out of it */
1344  field = ast_json_object_get(body, "name");
1345  if (field) {
1346  args->name = ast_json_string_get(field);
1347  }
1348  field = ast_json_object_get(body, "format");
1349  if (field) {
1350  args->format = ast_json_string_get(field);
1351  }
1352  field = ast_json_object_get(body, "maxDurationSeconds");
1353  if (field) {
1355  }
1356  field = ast_json_object_get(body, "maxSilenceSeconds");
1357  if (field) {
1359  }
1360  field = ast_json_object_get(body, "ifExists");
1361  if (field) {
1362  args->if_exists = ast_json_string_get(field);
1363  }
1364  field = ast_json_object_get(body, "beep");
1365  if (field) {
1366  args->beep = ast_json_is_true(field);
1367  }
1368  field = ast_json_object_get(body, "terminateOn");
1369  if (field) {
1370  args->terminate_on = ast_json_string_get(field);
1371  }
1372  return 0;
1373 }
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Definition: json.c:253
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
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
Abstract JSON element (object, array, string, int, ...).
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition: json.c:322

◆ ast_ari_bridges_remove_channel_cb()

static void ast_ari_bridges_remove_channel_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 /bridges/{bridgeId}/removeChannel.

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 620 of file res_ari_bridges.c.

References ARRAY_LEN, ast_app_separate_args, ast_ari_bridges_remove_channel(), ast_ari_bridges_remove_channel_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_free, ast_log, ast_malloc, ast_strdup, ast_ari_bridges_remove_channel_args::bridge_id, ast_ari_bridges_remove_channel_args::channel, ast_ari_bridges_remove_channel_args::channel_count, ast_ari_bridges_remove_channel_args::channel_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.

624 {
626  struct ast_variable *i;
627 #if defined(AST_DEVMODE)
628  int is_valid;
629  int code;
630 #endif /* AST_DEVMODE */
631 
632  for (i = get_params; i; i = i->next) {
633  if (strcmp(i->name, "channel") == 0) {
634  /* Parse comma separated list */
635  char *vals[MAX_VALS];
636  size_t j;
637 
638  args.channel_parse = ast_strdup(i->value);
639  if (!args.channel_parse) {
641  goto fin;
642  }
643 
644  if (strlen(args.channel_parse) == 0) {
645  /* ast_app_separate_args can't handle "" */
646  args.channel_count = 1;
647  vals[0] = args.channel_parse;
648  } else {
650  args.channel_parse, ',', vals,
651  ARRAY_LEN(vals));
652  }
653 
654  if (args.channel_count == 0) {
656  goto fin;
657  }
658 
659  if (args.channel_count >= MAX_VALS) {
660  ast_ari_response_error(response, 400,
661  "Bad Request",
662  "Too many values for channel");
663  goto fin;
664  }
665 
666  args.channel = ast_malloc(sizeof(*args.channel) * args.channel_count);
667  if (!args.channel) {
669  goto fin;
670  }
671 
672  for (j = 0; j < args.channel_count; ++j) {
673  args.channel[j] = (vals[j]);
674  }
675  } else
676  {}
677  }
678  for (i = path_vars; i; i = i->next) {
679  if (strcmp(i->name, "bridgeId") == 0) {
680  args.bridge_id = (i->value);
681  } else
682  {}
683  }
686  goto fin;
687  }
688  ast_ari_bridges_remove_channel(headers, &args, response);
689 #if defined(AST_DEVMODE)
690  code = response->response_code;
691 
692  switch (code) {
693  case 0: /* Implementation is still a stub, or the code wasn't set */
694  is_valid = response->message == NULL;
695  break;
696  case 500: /* Internal Server Error */
697  case 501: /* Not Implemented */
698  case 400: /* Channel not found */
699  case 404: /* Bridge not found */
700  case 409: /* Bridge not in Stasis application */
701  case 422: /* Channel not in this bridge */
702  is_valid = 1;
703  break;
704  default:
705  if (200 <= code && code <= 299) {
706  is_valid = ast_ari_validate_void(
707  response->message);
708  } else {
709  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/removeChannel\n", code);
710  is_valid = 0;
711  }
712  }
713 
714  if (!is_valid) {
715  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/removeChannel\n");
716  ast_ari_response_error(response, 500,
717  "Internal Server Error", "Response validation failed");
718  }
719 #endif /* AST_DEVMODE */
720 
721 fin: __attribute__((unused))
722  ast_free(args.channel_parse);
723  ast_free(args.channel);
724  return;
725 }
struct ast_variable * next
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
Structure for variables, used for configurations and for channel variables.
void ast_ari_bridges_remove_channel(struct ast_variable *headers, struct ast_ari_bridges_remove_channel_args *args, struct ast_ari_response *response)
Remove a channel from a bridge.
#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 ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:98
#define MAX_VALS
#define ast_log
Definition: astobj2.c:42
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define LOG_ERROR
Definition: logger.h:285
int ast_ari_bridges_remove_channel_parse_body(struct ast_json *body, struct ast_ari_bridges_remove_channel_args *args)
Body parsing function for /bridges/{bridgeId}/removeChannel.
#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
#define ast_app_separate_args(a, b, c, d)

◆ ast_ari_bridges_remove_channel_parse_body()

int ast_ari_bridges_remove_channel_parse_body ( struct ast_json body,
struct ast_ari_bridges_remove_channel_args args 
)

Body parsing function for /bridges/{bridgeId}/removeChannel.

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 575 of file res_ari_bridges.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_bridges_remove_channel_args::channel, and ast_ari_bridges_remove_channel_args::channel_count.

Referenced by ast_ari_bridges_remove_channel_cb().

578 {
579  struct ast_json *field;
580  /* Parse query parameters out of it */
581  field = ast_json_object_get(body, "channel");
582  if (field) {
583  /* If they were silly enough to both pass in a query param and a
584  * JSON body, free up the query value.
585  */
586  ast_free(args->channel);
587  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
588  /* Multiple param passed as array */
589  size_t i;
590  args->channel_count = ast_json_array_size(field);
591  args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
592 
593  if (!args->channel) {
594  return -1;
595  }
596 
597  for (i = 0; i < args->channel_count; ++i) {
598  args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
599  }
600  } else {
601  /* Multiple param passed as single value */
602  args->channel_count = 1;
603  args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
604  if (!args->channel) {
605  return -1;
606  }
607  args->channel[0] = ast_json_string_get(field);
608  }
609  }
610  return 0;
611 }
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_bridges_set_video_source_cb()

static void ast_ari_bridges_set_video_source_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 /bridges/{bridgeId}/videoSource/{channelId}.

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 733 of file res_ari_bridges.c.

References ast_ari_bridges_set_video_source(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_bridges_set_video_source_args::bridge_id, ast_ari_bridges_set_video_source_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

737 {
739  struct ast_variable *i;
740 #if defined(AST_DEVMODE)
741  int is_valid;
742  int code;
743 #endif /* AST_DEVMODE */
744 
745  for (i = path_vars; i; i = i->next) {
746  if (strcmp(i->name, "bridgeId") == 0) {
747  args.bridge_id = (i->value);
748  } else
749  if (strcmp(i->name, "channelId") == 0) {
750  args.channel_id = (i->value);
751  } else
752  {}
753  }
754  ast_ari_bridges_set_video_source(headers, &args, response);
755 #if defined(AST_DEVMODE)
756  code = response->response_code;
757 
758  switch (code) {
759  case 0: /* Implementation is still a stub, or the code wasn't set */
760  is_valid = response->message == NULL;
761  break;
762  case 500: /* Internal Server Error */
763  case 501: /* Not Implemented */
764  case 404: /* Bridge or Channel not found */
765  case 409: /* Channel not in Stasis application */
766  case 422: /* Channel not in this Bridge */
767  is_valid = 1;
768  break;
769  default:
770  if (200 <= code && code <= 299) {
771  is_valid = ast_ari_validate_void(
772  response->message);
773  } else {
774  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/videoSource/{channelId}\n", code);
775  is_valid = 0;
776  }
777  }
778 
779  if (!is_valid) {
780  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/videoSource/{channelId}\n");
781  ast_ari_response_error(response, 500,
782  "Internal Server Error", "Response validation failed");
783  }
784 #endif /* AST_DEVMODE */
785 
786 fin: __attribute__((unused))
787  return;
788 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char * args
#define NULL
Definition: resample.c:96
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
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
void ast_ari_bridges_set_video_source(struct ast_variable *headers, struct ast_ari_bridges_set_video_source_args *args, struct ast_ari_response *response)
Set a channel as the video source in a multi-party mixing bridge. This operation has no effect on bri...

◆ ast_ari_bridges_start_moh_cb()

static void ast_ari_bridges_start_moh_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 /bridges/{bridgeId}/moh.

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 867 of file res_ari_bridges.c.

References ast_ari_bridges_start_moh(), ast_ari_bridges_start_moh_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_bridges_start_moh_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_ari_bridges_start_moh_args::moh_class, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

871 {
873  struct ast_variable *i;
874 #if defined(AST_DEVMODE)
875  int is_valid;
876  int code;
877 #endif /* AST_DEVMODE */
878 
879  for (i = get_params; i; i = i->next) {
880  if (strcmp(i->name, "mohClass") == 0) {
881  args.moh_class = (i->value);
882  } else
883  {}
884  }
885  for (i = path_vars; i; i = i->next) {
886  if (strcmp(i->name, "bridgeId") == 0) {
887  args.bridge_id = (i->value);
888  } else
889  {}
890  }
891  if (ast_ari_bridges_start_moh_parse_body(body, &args)) {
893  goto fin;
894  }
895  ast_ari_bridges_start_moh(headers, &args, response);
896 #if defined(AST_DEVMODE)
897  code = response->response_code;
898 
899  switch (code) {
900  case 0: /* Implementation is still a stub, or the code wasn't set */
901  is_valid = response->message == NULL;
902  break;
903  case 500: /* Internal Server Error */
904  case 501: /* Not Implemented */
905  case 404: /* Bridge not found */
906  case 409: /* Bridge not in Stasis application */
907  is_valid = 1;
908  break;
909  default:
910  if (200 <= code && code <= 299) {
911  is_valid = ast_ari_validate_void(
912  response->message);
913  } else {
914  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/moh\n", code);
915  is_valid = 0;
916  }
917  }
918 
919  if (!is_valid) {
920  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/moh\n");
921  ast_ari_response_error(response, 500,
922  "Internal Server Error", "Response validation failed");
923  }
924 #endif /* AST_DEVMODE */
925 
926 fin: __attribute__((unused))
927  return;
928 }
struct ast_variable * next
int ast_ari_bridges_start_moh_parse_body(struct ast_json *body, struct ast_ari_bridges_start_moh_args *args)
Body parsing function for /bridges/{bridgeId}/moh.
void ast_ari_bridges_start_moh(struct ast_variable *headers, struct ast_ari_bridges_start_moh_args *args, struct ast_ari_response *response)
Play music on hold to a bridge or change the MOH class that is playing.
Structure for variables, used for configurations and for channel variables.
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 ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
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

◆ ast_ari_bridges_start_moh_parse_body()

int ast_ari_bridges_start_moh_parse_body ( struct ast_json body,
struct ast_ari_bridges_start_moh_args args 
)

Body parsing function for /bridges/{bridgeId}/moh.

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 847 of file res_ari_bridges.c.

References ast_json_object_get(), ast_json_string_get(), and ast_ari_bridges_start_moh_args::moh_class.

Referenced by ast_ari_bridges_start_moh_cb().

850 {
851  struct ast_json *field;
852  /* Parse query parameters out of it */
853  field = ast_json_object_get(body, "mohClass");
854  if (field) {
855  args->moh_class = ast_json_string_get(field);
856  }
857  return 0;
858 }
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
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
Abstract JSON element (object, array, string, int, ...).

◆ ast_ari_bridges_stop_moh_cb()

static void ast_ari_bridges_stop_moh_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 /bridges/{bridgeId}/moh.

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 936 of file res_ari_bridges.c.

References ast_ari_bridges_stop_moh(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_bridges_stop_moh_args::bridge_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

940 {
942  struct ast_variable *i;
943 #if defined(AST_DEVMODE)
944  int is_valid;
945  int code;
946 #endif /* AST_DEVMODE */
947 
948  for (i = path_vars; i; i = i->next) {
949  if (strcmp(i->name, "bridgeId") == 0) {
950  args.bridge_id = (i->value);
951  } else
952  {}
953  }
954  ast_ari_bridges_stop_moh(headers, &args, response);
955 #if defined(AST_DEVMODE)
956  code = response->response_code;
957 
958  switch (code) {
959  case 0: /* Implementation is still a stub, or the code wasn't set */
960  is_valid = response->message == NULL;
961  break;
962  case 500: /* Internal Server Error */
963  case 501: /* Not Implemented */
964  case 404: /* Bridge not found */
965  case 409: /* Bridge not in Stasis application */
966  is_valid = 1;
967  break;
968  default:
969  if (200 <= code && code <= 299) {
970  is_valid = ast_ari_validate_void(
971  response->message);
972  } else {
973  ast_log(LOG_ERROR, "Invalid error response %d for /bridges/{bridgeId}/moh\n", code);
974  is_valid = 0;
975  }
976  }
977 
978  if (!is_valid) {
979  ast_log(LOG_ERROR, "Response validation failed for /bridges/{bridgeId}/moh\n");
980  ast_ari_response_error(response, 500,
981  "Internal Server Error", "Response validation failed");
982  }
983 #endif /* AST_DEVMODE */
984 
985 fin: __attribute__((unused))
986  return;
987 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
const char * args
#define NULL
Definition: resample.c:96
int ast_ari_validate_void(struct ast_json *json)
Validator for native Swagger void.
Definition: res_ari_model.c:91
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
void ast_ari_bridges_stop_moh(struct ast_variable *headers, struct ast_ari_bridges_stop_moh_args *args, struct ast_ari_response *response)
Stop playing music on hold to a bridge.
#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

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 1588 of file res_ari_bridges.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 1569 of file res_ari_bridges.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().

1570 {
1571  int res = 0;
1572 
1573 
1574  res |= ast_ari_add_handler(&bridges);
1575  if (res) {
1576  unload_module();
1577  return AST_MODULE_LOAD_DECLINE;
1578  }
1579 
1580  return AST_MODULE_LOAD_SUCCESS;
1581 }
static int unload_module(void)
int ast_ari_add_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:179
static struct stasis_rest_handlers bridges
REST handler for /api-docs/bridges.json.
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 1563 of file res_ari_bridges.c.

References ast_ari_remove_handler().

Referenced by load_module().

1564 {
1566  return 0;
1567 }
int ast_ari_remove_handler(struct stasis_rest_handlers *handler)
Definition: res_ari.c:202
static struct stasis_rest_handlers bridges
REST handler for /api-docs/bridges.json.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "RESTful API module - Bridge 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,res_stasis_recording,res_stasis_playback", }
static

Definition at line 1588 of file res_ari_bridges.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 1588 of file res_ari_bridges.c.

◆ bridges

struct stasis_rest_handlers bridges
static

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

Definition at line 1553 of file res_ari_bridges.c.

◆ bridges_bridgeId

struct stasis_rest_handlers bridges_bridgeId
static

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

Definition at line 1541 of file res_ari_bridges.c.

◆ bridges_bridgeId_addChannel

struct stasis_rest_handlers bridges_bridgeId_addChannel
static

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

Definition at line 1466 of file res_ari_bridges.c.

◆ bridges_bridgeId_moh

struct stasis_rest_handlers bridges_bridgeId_moh
static

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

Definition at line 1503 of file res_ari_bridges.c.

◆ bridges_bridgeId_play

struct stasis_rest_handlers bridges_bridgeId_play
static

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

Definition at line 1523 of file res_ari_bridges.c.

◆ bridges_bridgeId_play_playbackId

struct stasis_rest_handlers bridges_bridgeId_play_playbackId
static

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

Definition at line 1513 of file res_ari_bridges.c.

◆ bridges_bridgeId_record

struct stasis_rest_handlers bridges_bridgeId_record
static

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

Definition at line 1532 of file res_ari_bridges.c.

◆ bridges_bridgeId_removeChannel

struct stasis_rest_handlers bridges_bridgeId_removeChannel
static

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

Definition at line 1475 of file res_ari_bridges.c.

◆ bridges_bridgeId_videoSource

struct stasis_rest_handlers bridges_bridgeId_videoSource
static

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

Definition at line 1494 of file res_ari_bridges.c.

◆ bridges_bridgeId_videoSource_channelId

struct stasis_rest_handlers bridges_bridgeId_videoSource_channelId
static

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

Definition at line 1484 of file res_ari_bridges.c.