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

Channel resources. More...

#include "asterisk.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/stasis_app.h"
#include "ari/resource_channels.h"
#include "ari/ari_model_validators.h"
Include dependency graph for res_ari_channels.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_channels_answer_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 /channels/{channelId}/answer. More...
 
static void ast_ari_channels_continue_in_dialplan_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 /channels/{channelId}/continue. More...
 
int ast_ari_channels_continue_in_dialplan_parse_body (struct ast_json *body, struct ast_ari_channels_continue_in_dialplan_args *args)
 Body parsing function for /channels/{channelId}/continue. More...
 
static void ast_ari_channels_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 /channels/create. More...
 
int ast_ari_channels_create_parse_body (struct ast_json *body, struct ast_ari_channels_create_args *args)
 Body parsing function for /channels/create. More...
 
static void ast_ari_channels_dial_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 /channels/{channelId}/dial. More...
 
int ast_ari_channels_dial_parse_body (struct ast_json *body, struct ast_ari_channels_dial_args *args)
 Body parsing function for /channels/{channelId}/dial. More...
 
static void ast_ari_channels_external_media_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 /channels/externalMedia. More...
 
int ast_ari_channels_external_media_parse_body (struct ast_json *body, struct ast_ari_channels_external_media_args *args)
 Body parsing function for /channels/externalMedia. More...
 
static void ast_ari_channels_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 /channels/{channelId}. More...
 
static void ast_ari_channels_get_channel_var_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 /channels/{channelId}/variable. More...
 
int ast_ari_channels_get_channel_var_parse_body (struct ast_json *body, struct ast_ari_channels_get_channel_var_args *args)
 Body parsing function for /channels/{channelId}/variable. More...
 
static void ast_ari_channels_hangup_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 /channels/{channelId}. More...
 
int ast_ari_channels_hangup_parse_body (struct ast_json *body, struct ast_ari_channels_hangup_args *args)
 Body parsing function for /channels/{channelId}. More...
 
static void ast_ari_channels_hold_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 /channels/{channelId}/hold. More...
 
static void ast_ari_channels_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 /channels. More...
 
static void ast_ari_channels_move_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 /channels/{channelId}/move. More...
 
int ast_ari_channels_move_parse_body (struct ast_json *body, struct ast_ari_channels_move_args *args)
 Body parsing function for /channels/{channelId}/move. More...
 
static void ast_ari_channels_mute_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 /channels/{channelId}/mute. More...
 
int ast_ari_channels_mute_parse_body (struct ast_json *body, struct ast_ari_channels_mute_args *args)
 Body parsing function for /channels/{channelId}/mute. More...
 
static void ast_ari_channels_originate_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 /channels. More...
 
int ast_ari_channels_originate_parse_body (struct ast_json *body, struct ast_ari_channels_originate_args *args)
 Body parsing function for /channels. More...
 
static void ast_ari_channels_originate_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 /channels/{channelId}. More...
 
int ast_ari_channels_originate_with_id_parse_body (struct ast_json *body, struct ast_ari_channels_originate_with_id_args *args)
 Body parsing function for /channels/{channelId}. More...
 
static void ast_ari_channels_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 /channels/{channelId}/play. More...
 
int ast_ari_channels_play_parse_body (struct ast_json *body, struct ast_ari_channels_play_args *args)
 Body parsing function for /channels/{channelId}/play. More...
 
static void ast_ari_channels_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 /channels/{channelId}/play/{playbackId}. More...
 
int ast_ari_channels_play_with_id_parse_body (struct ast_json *body, struct ast_ari_channels_play_with_id_args *args)
 Body parsing function for /channels/{channelId}/play/{playbackId}. More...
 
static void ast_ari_channels_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 /channels/{channelId}/record. More...
 
int ast_ari_channels_record_parse_body (struct ast_json *body, struct ast_ari_channels_record_args *args)
 Body parsing function for /channels/{channelId}/record. More...
 
static void ast_ari_channels_redirect_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 /channels/{channelId}/redirect. More...
 
int ast_ari_channels_redirect_parse_body (struct ast_json *body, struct ast_ari_channels_redirect_args *args)
 Body parsing function for /channels/{channelId}/redirect. More...
 
static void ast_ari_channels_ring_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 /channels/{channelId}/ring. More...
 
static void ast_ari_channels_ring_stop_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 /channels/{channelId}/ring. More...
 
static void ast_ari_channels_rtpstatistics_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 /channels/{channelId}/rtp_statistics. More...
 
static void ast_ari_channels_send_dtmf_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 /channels/{channelId}/dtmf. More...
 
int ast_ari_channels_send_dtmf_parse_body (struct ast_json *body, struct ast_ari_channels_send_dtmf_args *args)
 Body parsing function for /channels/{channelId}/dtmf. More...
 
static void ast_ari_channels_set_channel_var_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 /channels/{channelId}/variable. More...
 
int ast_ari_channels_set_channel_var_parse_body (struct ast_json *body, struct ast_ari_channels_set_channel_var_args *args)
 Body parsing function for /channels/{channelId}/variable. More...
 
static void ast_ari_channels_snoop_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 /channels/{channelId}/snoop. More...
 
int ast_ari_channels_snoop_channel_parse_body (struct ast_json *body, struct ast_ari_channels_snoop_channel_args *args)
 Body parsing function for /channels/{channelId}/snoop. More...
 
static void ast_ari_channels_snoop_channel_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 /channels/{channelId}/snoop/{snoopId}. More...
 
int ast_ari_channels_snoop_channel_with_id_parse_body (struct ast_json *body, struct ast_ari_channels_snoop_channel_with_id_args *args)
 Body parsing function for /channels/{channelId}/snoop/{snoopId}. More...
 
static void ast_ari_channels_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 /channels/{channelId}/moh. More...
 
int ast_ari_channels_start_moh_parse_body (struct ast_json *body, struct ast_ari_channels_start_moh_args *args)
 Body parsing function for /channels/{channelId}/moh. More...
 
static void ast_ari_channels_start_silence_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 /channels/{channelId}/silence. More...
 
static void ast_ari_channels_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 /channels/{channelId}/moh. More...
 
static void ast_ari_channels_stop_silence_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 /channels/{channelId}/silence. More...
 
static void ast_ari_channels_unhold_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 /channels/{channelId}/hold. More...
 
static void ast_ari_channels_unmute_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 /channels/{channelId}/mute. More...
 
int ast_ari_channels_unmute_parse_body (struct ast_json *body, struct ast_ari_channels_unmute_args *args)
 Body parsing function for /channels/{channelId}/mute. 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 - Channel 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_answer,res_stasis_playback,res_stasis_recording,res_stasis_snoop", }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct stasis_rest_handlers channels
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_answer
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_continue
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_dial
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_dtmf
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_hold
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_moh
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_move
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_mute
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_play
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_play_playbackId
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_record
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_redirect
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_ring
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_rtp_statistics
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_silence
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_snoop
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_snoop_snoopId
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_channelId_variable
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_create
 REST handler for /api-docs/channels.json. More...
 
static struct stasis_rest_handlers channels_externalMedia
 REST handler for /api-docs/channels.json. More...
 

Detailed Description

Channel resources.

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

Definition in file res_ari_channels.c.

Macro Definition Documentation

◆ MAX_VALS

#define MAX_VALS   128

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 3180 of file res_ari_channels.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 3180 of file res_ari_channels.c.

◆ ast_ari_channels_answer_cb()

static void ast_ari_channels_answer_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 /channels/{channelId}/answer.

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 966 of file res_ari_channels.c.

References ast_ari_channels_answer(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_answer_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.

970 {
972  struct ast_variable *i;
973 #if defined(AST_DEVMODE)
974  int is_valid;
975  int code;
976 #endif /* AST_DEVMODE */
977 
978  for (i = path_vars; i; i = i->next) {
979  if (strcmp(i->name, "channelId") == 0) {
980  args.channel_id = (i->value);
981  } else
982  {}
983  }
984  ast_ari_channels_answer(headers, &args, response);
985 #if defined(AST_DEVMODE)
986  code = response->response_code;
987 
988  switch (code) {
989  case 0: /* Implementation is still a stub, or the code wasn't set */
990  is_valid = response->message == NULL;
991  break;
992  case 500: /* Internal Server Error */
993  case 501: /* Not Implemented */
994  case 404: /* Channel not found */
995  case 409: /* Channel not in a Stasis application */
996  case 412: /* Channel in invalid state */
997  is_valid = 1;
998  break;
999  default:
1000  if (200 <= code && code <= 299) {
1001  is_valid = ast_ari_validate_void(
1002  response->message);
1003  } else {
1004  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/answer\n", code);
1005  is_valid = 0;
1006  }
1007  }
1008 
1009  if (!is_valid) {
1010  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/answer\n");
1011  ast_ari_response_error(response, 500,
1012  "Internal Server Error", "Response validation failed");
1013  }
1014 #endif /* AST_DEVMODE */
1015 
1016 fin: __attribute__((unused))
1017  return;
1018 }
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_channels_answer(struct ast_variable *headers, struct ast_ari_channels_answer_args *args, struct ast_ari_response *response)
Answer a channel.
#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_channels_continue_in_dialplan_cb()

static void ast_ari_channels_continue_in_dialplan_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 /channels/{channelId}/continue.

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 713 of file res_ari_channels.c.

References ast_ari_channels_continue_in_dialplan(), ast_ari_channels_continue_in_dialplan_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_continue_in_dialplan_args::channel_id, ast_ari_channels_continue_in_dialplan_args::context, ast_ari_channels_continue_in_dialplan_args::extension, ast_ari_channels_continue_in_dialplan_args::label, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_continue_in_dialplan_args::priority, ast_ari_response::response_code, and ast_variable::value.

717 {
719  struct ast_variable *i;
720 #if defined(AST_DEVMODE)
721  int is_valid;
722  int code;
723 #endif /* AST_DEVMODE */
724 
725  for (i = get_params; i; i = i->next) {
726  if (strcmp(i->name, "context") == 0) {
727  args.context = (i->value);
728  } else
729  if (strcmp(i->name, "extension") == 0) {
730  args.extension = (i->value);
731  } else
732  if (strcmp(i->name, "priority") == 0) {
733  args.priority = atoi(i->value);
734  } else
735  if (strcmp(i->name, "label") == 0) {
736  args.label = (i->value);
737  } else
738  {}
739  }
740  for (i = path_vars; i; i = i->next) {
741  if (strcmp(i->name, "channelId") == 0) {
742  args.channel_id = (i->value);
743  } else
744  {}
745  }
748  goto fin;
749  }
750  ast_ari_channels_continue_in_dialplan(headers, &args, response);
751 #if defined(AST_DEVMODE)
752  code = response->response_code;
753 
754  switch (code) {
755  case 0: /* Implementation is still a stub, or the code wasn't set */
756  is_valid = response->message == NULL;
757  break;
758  case 500: /* Internal Server Error */
759  case 501: /* Not Implemented */
760  case 404: /* Channel not found */
761  case 409: /* Channel not in a Stasis application */
762  case 412: /* Channel in invalid state */
763  is_valid = 1;
764  break;
765  default:
766  if (200 <= code && code <= 299) {
767  is_valid = ast_ari_validate_void(
768  response->message);
769  } else {
770  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/continue\n", code);
771  is_valid = 0;
772  }
773  }
774 
775  if (!is_valid) {
776  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/continue\n");
777  ast_ari_response_error(response, 500,
778  "Internal Server Error", "Response validation failed");
779  }
780 #endif /* AST_DEVMODE */
781 
782 fin: __attribute__((unused))
783  return;
784 }
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 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
int ast_ari_channels_continue_in_dialplan_parse_body(struct ast_json *body, struct ast_ari_channels_continue_in_dialplan_args *args)
Body parsing function for /channels/{channelId}/continue.
#define ast_log
Definition: astobj2.c:42
void ast_ari_channels_continue_in_dialplan(struct ast_variable *headers, struct ast_ari_channels_continue_in_dialplan_args *args, struct ast_ari_response *response)
Exit application; continue execution in the dialplan.
#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_channels_continue_in_dialplan_parse_body()

int ast_ari_channels_continue_in_dialplan_parse_body ( struct ast_json body,
struct ast_ari_channels_continue_in_dialplan_args args 
)

Body parsing function for /channels/{channelId}/continue.

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 681 of file res_ari_channels.c.

References ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_ari_channels_continue_in_dialplan_args::context, ast_ari_channels_continue_in_dialplan_args::extension, ast_ari_channels_continue_in_dialplan_args::label, and ast_ari_channels_continue_in_dialplan_args::priority.

Referenced by ast_ari_channels_continue_in_dialplan_cb().

684 {
685  struct ast_json *field;
686  /* Parse query parameters out of it */
687  field = ast_json_object_get(body, "context");
688  if (field) {
689  args->context = ast_json_string_get(field);
690  }
691  field = ast_json_object_get(body, "extension");
692  if (field) {
693  args->extension = ast_json_string_get(field);
694  }
695  field = ast_json_object_get(body, "priority");
696  if (field) {
697  args->priority = ast_json_integer_get(field);
698  }
699  field = ast_json_object_get(body, "label");
700  if (field) {
701  args->label = ast_json_string_get(field);
702  }
703  return 0;
704 }
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_channels_create_cb()

static void ast_ari_channels_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 /channels/create.

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 308 of file res_ari_channels.c.

References ast_ari_channels_create_args::app, ast_ari_channels_create_args::app_args, ast_ari_channels_create(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_create_args::channel_id, ast_ari_channels_create_args::endpoint, ast_ari_channels_create_args::formats, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_create_args::originator, ast_ari_channels_create_args::other_channel_id, ast_ari_response::response_code, ast_variable::value, and ast_ari_channels_create_args::variables.

312 {
314  struct ast_variable *i;
315 #if defined(AST_DEVMODE)
316  int is_valid;
317  int code;
318 #endif /* AST_DEVMODE */
319 
320  for (i = get_params; i; i = i->next) {
321  if (strcmp(i->name, "endpoint") == 0) {
322  args.endpoint = (i->value);
323  } else
324  if (strcmp(i->name, "app") == 0) {
325  args.app = (i->value);
326  } else
327  if (strcmp(i->name, "appArgs") == 0) {
328  args.app_args = (i->value);
329  } else
330  if (strcmp(i->name, "channelId") == 0) {
331  args.channel_id = (i->value);
332  } else
333  if (strcmp(i->name, "otherChannelId") == 0) {
334  args.other_channel_id = (i->value);
335  } else
336  if (strcmp(i->name, "originator") == 0) {
337  args.originator = (i->value);
338  } else
339  if (strcmp(i->name, "formats") == 0) {
340  args.formats = (i->value);
341  } else
342  {}
343  }
344  args.variables = body;
345  ast_ari_channels_create(headers, &args, response);
346 #if defined(AST_DEVMODE)
347  code = response->response_code;
348 
349  switch (code) {
350  case 0: /* Implementation is still a stub, or the code wasn't set */
351  is_valid = response->message == NULL;
352  break;
353  case 500: /* Internal Server Error */
354  case 501: /* Not Implemented */
355  case 409: /* Channel with given unique ID already exists. */
356  is_valid = 1;
357  break;
358  default:
359  if (200 <= code && code <= 299) {
360  is_valid = ast_ari_validate_channel(
361  response->message);
362  } else {
363  ast_log(LOG_ERROR, "Invalid error response %d for /channels/create\n", code);
364  is_valid = 0;
365  }
366  }
367 
368  if (!is_valid) {
369  ast_log(LOG_ERROR, "Response validation failed for /channels/create\n");
370  ast_ari_response_error(response, 500,
371  "Internal Server Error", "Response validation failed");
372  }
373 #endif /* AST_DEVMODE */
374 
375 fin: __attribute__((unused))
376  return;
377 }
struct ast_variable * next
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
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
void ast_ari_channels_create(struct ast_variable *headers, struct ast_ari_channels_create_args *args, struct ast_ari_response *response)
Create channel.
#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_channels_create_parse_body()

int ast_ari_channels_create_parse_body ( struct ast_json body,
struct ast_ari_channels_create_args args 
)

Body parsing function for /channels/create.

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 264 of file res_ari_channels.c.

References ast_ari_channels_create_args::app, ast_ari_channels_create_args::app_args, ast_json_object_get(), ast_json_string_get(), ast_ari_channels_create_args::channel_id, ast_ari_channels_create_args::endpoint, ast_ari_channels_create_args::formats, ast_ari_channels_create_args::originator, and ast_ari_channels_create_args::other_channel_id.

Referenced by ast_ari_channels_create().

267 {
268  struct ast_json *field;
269  /* Parse query parameters out of it */
270  field = ast_json_object_get(body, "endpoint");
271  if (field) {
272  args->endpoint = ast_json_string_get(field);
273  }
274  field = ast_json_object_get(body, "app");
275  if (field) {
276  args->app = ast_json_string_get(field);
277  }
278  field = ast_json_object_get(body, "appArgs");
279  if (field) {
280  args->app_args = ast_json_string_get(field);
281  }
282  field = ast_json_object_get(body, "channelId");
283  if (field) {
284  args->channel_id = ast_json_string_get(field);
285  }
286  field = ast_json_object_get(body, "otherChannelId");
287  if (field) {
288  args->other_channel_id = ast_json_string_get(field);
289  }
290  field = ast_json_object_get(body, "originator");
291  if (field) {
292  args->originator = ast_json_string_get(field);
293  }
294  field = ast_json_object_get(body, "formats");
295  if (field) {
296  args->formats = ast_json_string_get(field);
297  }
298  return 0;
299 }
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_channels_dial_cb()

static void ast_ari_channels_dial_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 /channels/{channelId}/dial.

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 2691 of file res_ari_channels.c.

References ast_ari_channels_dial(), ast_ari_channels_dial_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_dial_args::caller, ast_ari_channels_dial_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_channels_dial_args::timeout, and ast_variable::value.

2695 {
2696  struct ast_ari_channels_dial_args args = {};
2697  struct ast_variable *i;
2698 #if defined(AST_DEVMODE)
2699  int is_valid;
2700  int code;
2701 #endif /* AST_DEVMODE */
2702 
2703  for (i = get_params; i; i = i->next) {
2704  if (strcmp(i->name, "caller") == 0) {
2705  args.caller = (i->value);
2706  } else
2707  if (strcmp(i->name, "timeout") == 0) {
2708  args.timeout = atoi(i->value);
2709  } else
2710  {}
2711  }
2712  for (i = path_vars; i; i = i->next) {
2713  if (strcmp(i->name, "channelId") == 0) {
2714  args.channel_id = (i->value);
2715  } else
2716  {}
2717  }
2718  if (ast_ari_channels_dial_parse_body(body, &args)) {
2720  goto fin;
2721  }
2722  ast_ari_channels_dial(headers, &args, response);
2723 #if defined(AST_DEVMODE)
2724  code = response->response_code;
2725 
2726  switch (code) {
2727  case 0: /* Implementation is still a stub, or the code wasn't set */
2728  is_valid = response->message == NULL;
2729  break;
2730  case 500: /* Internal Server Error */
2731  case 501: /* Not Implemented */
2732  case 404: /* Channel cannot be found. */
2733  case 409: /* Channel cannot be dialed. */
2734  is_valid = 1;
2735  break;
2736  default:
2737  if (200 <= code && code <= 299) {
2738  is_valid = ast_ari_validate_void(
2739  response->message);
2740  } else {
2741  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dial\n", code);
2742  is_valid = 0;
2743  }
2744  }
2745 
2746  if (!is_valid) {
2747  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dial\n");
2748  ast_ari_response_error(response, 500,
2749  "Internal Server Error", "Response validation failed");
2750  }
2751 #endif /* AST_DEVMODE */
2752 
2753 fin: __attribute__((unused))
2754  return;
2755 }
struct ast_variable * next
int ast_ari_channels_dial_parse_body(struct ast_json *body, struct ast_ari_channels_dial_args *args)
Body parsing function for /channels/{channelId}/dial.
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
void ast_ari_channels_dial(struct ast_variable *headers, struct ast_ari_channels_dial_args *args, struct ast_ari_response *response)
Dial a created channel.

◆ ast_ari_channels_dial_parse_body()

int ast_ari_channels_dial_parse_body ( struct ast_json body,
struct ast_ari_channels_dial_args args 
)

Body parsing function for /channels/{channelId}/dial.

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 2667 of file res_ari_channels.c.

References ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_ari_channels_dial_args::caller, and ast_ari_channels_dial_args::timeout.

Referenced by ast_ari_channels_dial_cb().

2670 {
2671  struct ast_json *field;
2672  /* Parse query parameters out of it */
2673  field = ast_json_object_get(body, "caller");
2674  if (field) {
2675  args->caller = ast_json_string_get(field);
2676  }
2677  field = ast_json_object_get(body, "timeout");
2678  if (field) {
2679  args->timeout = ast_json_integer_get(field);
2680  }
2681  return 0;
2682 }
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_channels_external_media_cb()

static void ast_ari_channels_external_media_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 /channels/externalMedia.

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 2866 of file res_ari_channels.c.

References ast_ari_channels_external_media_args::app, ast_ari_channels_external_media(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_external_media_args::channel_id, ast_ari_channels_external_media_args::connection_type, ast_ari_channels_external_media_args::data, ast_ari_channels_external_media_args::direction, ast_ari_channels_external_media_args::encapsulation, ast_ari_channels_external_media_args::external_host, ast_ari_channels_external_media_args::format, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_channels_external_media_args::transport, ast_variable::value, and ast_ari_channels_external_media_args::variables.

2870 {
2872  struct ast_variable *i;
2873 #if defined(AST_DEVMODE)
2874  int is_valid;
2875  int code;
2876 #endif /* AST_DEVMODE */
2877 
2878  for (i = get_params; i; i = i->next) {
2879  if (strcmp(i->name, "channelId") == 0) {
2880  args.channel_id = (i->value);
2881  } else
2882  if (strcmp(i->name, "app") == 0) {
2883  args.app = (i->value);
2884  } else
2885  if (strcmp(i->name, "external_host") == 0) {
2886  args.external_host = (i->value);
2887  } else
2888  if (strcmp(i->name, "encapsulation") == 0) {
2889  args.encapsulation = (i->value);
2890  } else
2891  if (strcmp(i->name, "transport") == 0) {
2892  args.transport = (i->value);
2893  } else
2894  if (strcmp(i->name, "connection_type") == 0) {
2895  args.connection_type = (i->value);
2896  } else
2897  if (strcmp(i->name, "format") == 0) {
2898  args.format = (i->value);
2899  } else
2900  if (strcmp(i->name, "direction") == 0) {
2901  args.direction = (i->value);
2902  } else
2903  if (strcmp(i->name, "data") == 0) {
2904  args.data = (i->value);
2905  } else
2906  {}
2907  }
2908  args.variables = body;
2909  ast_ari_channels_external_media(headers, &args, response);
2910 #if defined(AST_DEVMODE)
2911  code = response->response_code;
2912 
2913  switch (code) {
2914  case 0: /* Implementation is still a stub, or the code wasn't set */
2915  is_valid = response->message == NULL;
2916  break;
2917  case 500: /* Internal Server Error */
2918  case 501: /* Not Implemented */
2919  case 400: /* Invalid parameters */
2920  case 409: /* Channel is not in a Stasis application; Channel is already bridged */
2921  is_valid = 1;
2922  break;
2923  default:
2924  if (200 <= code && code <= 299) {
2925  is_valid = ast_ari_validate_channel(
2926  response->message);
2927  } else {
2928  ast_log(LOG_ERROR, "Invalid error response %d for /channels/externalMedia\n", code);
2929  is_valid = 0;
2930  }
2931  }
2932 
2933  if (!is_valid) {
2934  ast_log(LOG_ERROR, "Response validation failed for /channels/externalMedia\n");
2935  ast_ari_response_error(response, 500,
2936  "Internal Server Error", "Response validation failed");
2937  }
2938 #endif /* AST_DEVMODE */
2939 
2940 fin: __attribute__((unused))
2941  return;
2942 }
struct ast_variable * next
void ast_ari_channels_external_media(struct ast_variable *headers, struct ast_ari_channels_external_media_args *args, struct ast_ari_response *response)
Start an External Media session.
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
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

◆ ast_ari_channels_external_media_parse_body()

int ast_ari_channels_external_media_parse_body ( struct ast_json body,
struct ast_ari_channels_external_media_args args 
)

Body parsing function for /channels/externalMedia.

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 2814 of file res_ari_channels.c.

References ast_ari_channels_external_media_args::app, ast_json_object_get(), ast_json_string_get(), ast_ari_channels_external_media_args::channel_id, ast_ari_channels_external_media_args::connection_type, ast_ari_channels_external_media_args::data, ast_ari_channels_external_media_args::direction, ast_ari_channels_external_media_args::encapsulation, ast_ari_channels_external_media_args::external_host, ast_ari_channels_external_media_args::format, and ast_ari_channels_external_media_args::transport.

Referenced by ast_ari_channels_external_media().

2817 {
2818  struct ast_json *field;
2819  /* Parse query parameters out of it */
2820  field = ast_json_object_get(body, "channelId");
2821  if (field) {
2822  args->channel_id = ast_json_string_get(field);
2823  }
2824  field = ast_json_object_get(body, "app");
2825  if (field) {
2826  args->app = ast_json_string_get(field);
2827  }
2828  field = ast_json_object_get(body, "external_host");
2829  if (field) {
2830  args->external_host = ast_json_string_get(field);
2831  }
2832  field = ast_json_object_get(body, "encapsulation");
2833  if (field) {
2834  args->encapsulation = ast_json_string_get(field);
2835  }
2836  field = ast_json_object_get(body, "transport");
2837  if (field) {
2838  args->transport = ast_json_string_get(field);
2839  }
2840  field = ast_json_object_get(body, "connection_type");
2841  if (field) {
2842  args->connection_type = ast_json_string_get(field);
2843  }
2844  field = ast_json_object_get(body, "format");
2845  if (field) {
2846  args->format = ast_json_string_get(field);
2847  }
2848  field = ast_json_object_get(body, "direction");
2849  if (field) {
2850  args->direction = ast_json_string_get(field);
2851  }
2852  field = ast_json_object_get(body, "data");
2853  if (field) {
2854  args->data = ast_json_string_get(field);
2855  }
2856  return 0;
2857 }
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_channels_get_cb()

static void ast_ari_channels_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 /channels/{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 385 of file res_ari_channels.c.

References ast_ari_channels_get(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_get_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.

389 {
390  struct ast_ari_channels_get_args args = {};
391  struct ast_variable *i;
392 #if defined(AST_DEVMODE)
393  int is_valid;
394  int code;
395 #endif /* AST_DEVMODE */
396 
397  for (i = path_vars; i; i = i->next) {
398  if (strcmp(i->name, "channelId") == 0) {
399  args.channel_id = (i->value);
400  } else
401  {}
402  }
403  ast_ari_channels_get(headers, &args, response);
404 #if defined(AST_DEVMODE)
405  code = response->response_code;
406 
407  switch (code) {
408  case 0: /* Implementation is still a stub, or the code wasn't set */
409  is_valid = response->message == NULL;
410  break;
411  case 500: /* Internal Server Error */
412  case 501: /* Not Implemented */
413  case 404: /* Channel not found */
414  is_valid = 1;
415  break;
416  default:
417  if (200 <= code && code <= 299) {
418  is_valid = ast_ari_validate_channel(
419  response->message);
420  } else {
421  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
422  is_valid = 0;
423  }
424  }
425 
426  if (!is_valid) {
427  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
428  ast_ari_response_error(response, 500,
429  "Internal Server Error", "Response validation failed");
430  }
431 #endif /* AST_DEVMODE */
432 
433 fin: __attribute__((unused))
434  return;
435 }
struct ast_variable * next
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
Structure for variables, used for configurations and for channel variables.
void ast_ari_channels_get(struct ast_variable *headers, struct ast_ari_channels_get_args *args, struct ast_ari_response *response)
Channel details.
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

◆ ast_ari_channels_get_channel_var_cb()

static void ast_ari_channels_get_channel_var_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 /channels/{channelId}/variable.

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 2298 of file res_ari_channels.c.

References ast_ari_channels_get_channel_var(), ast_ari_channels_get_channel_var_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_variable(), ast_log, ast_ari_channels_get_channel_var_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_variable::value, and ast_ari_channels_get_channel_var_args::variable.

2302 {
2304  struct ast_variable *i;
2305 #if defined(AST_DEVMODE)
2306  int is_valid;
2307  int code;
2308 #endif /* AST_DEVMODE */
2309 
2310  for (i = get_params; i; i = i->next) {
2311  if (strcmp(i->name, "variable") == 0) {
2312  args.variable = (i->value);
2313  } else
2314  {}
2315  }
2316  for (i = path_vars; i; i = i->next) {
2317  if (strcmp(i->name, "channelId") == 0) {
2318  args.channel_id = (i->value);
2319  } else
2320  {}
2321  }
2324  goto fin;
2325  }
2326  ast_ari_channels_get_channel_var(headers, &args, response);
2327 #if defined(AST_DEVMODE)
2328  code = response->response_code;
2329 
2330  switch (code) {
2331  case 0: /* Implementation is still a stub, or the code wasn't set */
2332  is_valid = response->message == NULL;
2333  break;
2334  case 500: /* Internal Server Error */
2335  case 501: /* Not Implemented */
2336  case 400: /* Missing variable parameter. */
2337  case 404: /* Channel or variable not found */
2338  case 409: /* Channel not in a Stasis application */
2339  is_valid = 1;
2340  break;
2341  default:
2342  if (200 <= code && code <= 299) {
2343  is_valid = ast_ari_validate_variable(
2344  response->message);
2345  } else {
2346  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
2347  is_valid = 0;
2348  }
2349  }
2350 
2351  if (!is_valid) {
2352  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
2353  ast_ari_response_error(response, 500,
2354  "Internal Server Error", "Response validation failed");
2355  }
2356 #endif /* AST_DEVMODE */
2357 
2358 fin: __attribute__((unused))
2359  return;
2360 }
struct ast_variable * next
int ast_ari_validate_variable(struct ast_json *json)
Validator for Variable.
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
void ast_ari_channels_get_channel_var(struct ast_variable *headers, struct ast_ari_channels_get_channel_var_args *args, struct ast_ari_response *response)
Get the value of a channel variable or function.
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
int ast_ari_channels_get_channel_var_parse_body(struct ast_json *body, struct ast_ari_channels_get_channel_var_args *args)
Body parsing function for /channels/{channelId}/variable.
struct ast_json * message
Definition: ari.h:93

◆ ast_ari_channels_get_channel_var_parse_body()

int ast_ari_channels_get_channel_var_parse_body ( struct ast_json body,
struct ast_ari_channels_get_channel_var_args args 
)

Body parsing function for /channels/{channelId}/variable.

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 2278 of file res_ari_channels.c.

References ast_json_object_get(), ast_json_string_get(), and ast_ari_channels_get_channel_var_args::variable.

Referenced by ast_ari_channels_get_channel_var_cb().

2281 {
2282  struct ast_json *field;
2283  /* Parse query parameters out of it */
2284  field = ast_json_object_get(body, "variable");
2285  if (field) {
2286  args->variable = ast_json_string_get(field);
2287  }
2288  return 0;
2289 }
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_channels_hangup_cb()

static void ast_ari_channels_hangup_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 /channels/{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 616 of file res_ari_channels.c.

References ast_ari_channels_hangup(), ast_ari_channels_hangup_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_hangup_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_hangup_args::reason, ast_ari_channels_hangup_args::reason_code, ast_ari_response::response_code, and ast_variable::value.

620 {
622  struct ast_variable *i;
623 #if defined(AST_DEVMODE)
624  int is_valid;
625  int code;
626 #endif /* AST_DEVMODE */
627 
628  for (i = get_params; i; i = i->next) {
629  if (strcmp(i->name, "reason_code") == 0) {
630  args.reason_code = (i->value);
631  } else
632  if (strcmp(i->name, "reason") == 0) {
633  args.reason = (i->value);
634  } else
635  {}
636  }
637  for (i = path_vars; i; i = i->next) {
638  if (strcmp(i->name, "channelId") == 0) {
639  args.channel_id = (i->value);
640  } else
641  {}
642  }
643  if (ast_ari_channels_hangup_parse_body(body, &args)) {
645  goto fin;
646  }
647  ast_ari_channels_hangup(headers, &args, response);
648 #if defined(AST_DEVMODE)
649  code = response->response_code;
650 
651  switch (code) {
652  case 0: /* Implementation is still a stub, or the code wasn't set */
653  is_valid = response->message == NULL;
654  break;
655  case 500: /* Internal Server Error */
656  case 501: /* Not Implemented */
657  case 400: /* Invalid reason for hangup provided */
658  case 404: /* Channel not found */
659  is_valid = 1;
660  break;
661  default:
662  if (200 <= code && code <= 299) {
663  is_valid = ast_ari_validate_void(
664  response->message);
665  } else {
666  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
667  is_valid = 0;
668  }
669  }
670 
671  if (!is_valid) {
672  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
673  ast_ari_response_error(response, 500,
674  "Internal Server Error", "Response validation failed");
675  }
676 #endif /* AST_DEVMODE */
677 
678 fin: __attribute__((unused))
679  return;
680 }
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 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_channels_hangup(struct ast_variable *headers, struct ast_ari_channels_hangup_args *args, struct ast_ari_response *response)
Delete (i.e. hangup) a channel.
int ast_ari_channels_hangup_parse_body(struct ast_json *body, struct ast_ari_channels_hangup_args *args)
Body parsing function for /channels/{channelId}.

◆ ast_ari_channels_hangup_parse_body()

int ast_ari_channels_hangup_parse_body ( struct ast_json body,
struct ast_ari_channels_hangup_args args 
)

Body parsing function for /channels/{channelId}.

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 592 of file res_ari_channels.c.

References ast_json_object_get(), ast_json_string_get(), ast_ari_channels_hangup_args::reason, and ast_ari_channels_hangup_args::reason_code.

Referenced by ast_ari_channels_hangup_cb().

595 {
596  struct ast_json *field;
597  /* Parse query parameters out of it */
598  field = ast_json_object_get(body, "reason_code");
599  if (field) {
600  args->reason_code = ast_json_string_get(field);
601  }
602  field = ast_json_object_get(body, "reason");
603  if (field) {
604  args->reason = ast_json_string_get(field);
605  }
606  return 0;
607 }
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_channels_hold_cb()

static void ast_ari_channels_hold_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 /channels/{channelId}/hold.

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 1424 of file res_ari_channels.c.

References ast_ari_channels_hold(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_hold_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.

1428 {
1429  struct ast_ari_channels_hold_args args = {};
1430  struct ast_variable *i;
1431 #if defined(AST_DEVMODE)
1432  int is_valid;
1433  int code;
1434 #endif /* AST_DEVMODE */
1435 
1436  for (i = path_vars; i; i = i->next) {
1437  if (strcmp(i->name, "channelId") == 0) {
1438  args.channel_id = (i->value);
1439  } else
1440  {}
1441  }
1442  ast_ari_channels_hold(headers, &args, response);
1443 #if defined(AST_DEVMODE)
1444  code = response->response_code;
1445 
1446  switch (code) {
1447  case 0: /* Implementation is still a stub, or the code wasn't set */
1448  is_valid = response->message == NULL;
1449  break;
1450  case 500: /* Internal Server Error */
1451  case 501: /* Not Implemented */
1452  case 404: /* Channel not found */
1453  case 409: /* Channel not in a Stasis application */
1454  case 412: /* Channel in invalid state */
1455  is_valid = 1;
1456  break;
1457  default:
1458  if (200 <= code && code <= 299) {
1459  is_valid = ast_ari_validate_void(
1460  response->message);
1461  } else {
1462  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
1463  is_valid = 0;
1464  }
1465  }
1466 
1467  if (!is_valid) {
1468  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
1469  ast_ari_response_error(response, 500,
1470  "Internal Server Error", "Response validation failed");
1471  }
1472 #endif /* AST_DEVMODE */
1473 
1474 fin: __attribute__((unused))
1475  return;
1476 }
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_channels_hold(struct ast_variable *headers, struct ast_ari_channels_hold_args *args, struct ast_ari_response *response)
Hold a channel.
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_channels_list_cb()

static void ast_ari_channels_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 /channels.

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 64 of file res_ari_channels.c.

References ast_ari_channels_list(), ast_ari_response_error(), ast_ari_validate_channel_fn(), ast_ari_validate_list(), ast_log, LOG_ERROR, ast_ari_response::message, NULL, and ast_ari_response::response_code.

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

static void ast_ari_channels_move_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 /channels/{channelId}/move.

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 809 of file res_ari_channels.c.

References ast_ari_channels_move_args::app, ast_ari_channels_move_args::app_args, ast_ari_channels_move(), ast_ari_channels_move_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_move_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.

813 {
814  struct ast_ari_channels_move_args args = {};
815  struct ast_variable *i;
816 #if defined(AST_DEVMODE)
817  int is_valid;
818  int code;
819 #endif /* AST_DEVMODE */
820 
821  for (i = get_params; i; i = i->next) {
822  if (strcmp(i->name, "app") == 0) {
823  args.app = (i->value);
824  } else
825  if (strcmp(i->name, "appArgs") == 0) {
826  args.app_args = (i->value);
827  } else
828  {}
829  }
830  for (i = path_vars; i; i = i->next) {
831  if (strcmp(i->name, "channelId") == 0) {
832  args.channel_id = (i->value);
833  } else
834  {}
835  }
836  if (ast_ari_channels_move_parse_body(body, &args)) {
838  goto fin;
839  }
840  ast_ari_channels_move(headers, &args, response);
841 #if defined(AST_DEVMODE)
842  code = response->response_code;
843 
844  switch (code) {
845  case 0: /* Implementation is still a stub, or the code wasn't set */
846  is_valid = response->message == NULL;
847  break;
848  case 500: /* Internal Server Error */
849  case 501: /* Not Implemented */
850  case 404: /* Channel not found */
851  case 409: /* Channel not in a Stasis application */
852  is_valid = 1;
853  break;
854  default:
855  if (200 <= code && code <= 299) {
856  is_valid = ast_ari_validate_void(
857  response->message);
858  } else {
859  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/move\n", code);
860  is_valid = 0;
861  }
862  }
863 
864  if (!is_valid) {
865  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/move\n");
866  ast_ari_response_error(response, 500,
867  "Internal Server Error", "Response validation failed");
868  }
869 #endif /* AST_DEVMODE */
870 
871 fin: __attribute__((unused))
872  return;
873 }
struct ast_variable * next
void ast_ari_channels_move(struct ast_variable *headers, struct ast_ari_channels_move_args *args, struct ast_ari_response *response)
Move the channel from one Stasis application to another.
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
int ast_ari_channels_move_parse_body(struct ast_json *body, struct ast_ari_channels_move_args *args)
Body parsing function for /channels/{channelId}/move.
#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_channels_move_parse_body()

int ast_ari_channels_move_parse_body ( struct ast_json body,
struct ast_ari_channels_move_args args 
)

Body parsing function for /channels/{channelId}/move.

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 785 of file res_ari_channels.c.

References ast_ari_channels_move_args::app, ast_ari_channels_move_args::app_args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_channels_move_cb().

788 {
789  struct ast_json *field;
790  /* Parse query parameters out of it */
791  field = ast_json_object_get(body, "app");
792  if (field) {
793  args->app = ast_json_string_get(field);
794  }
795  field = ast_json_object_get(body, "appArgs");
796  if (field) {
797  args->app_args = ast_json_string_get(field);
798  }
799  return 0;
800 }
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_channels_mute_cb()

static void ast_ari_channels_mute_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 /channels/{channelId}/mute.

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 1271 of file res_ari_channels.c.

References ast_ari_channels_mute(), ast_ari_channels_mute_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_mute_args::channel_id, ast_ari_channels_mute_args::direction, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

1275 {
1276  struct ast_ari_channels_mute_args args = {};
1277  struct ast_variable *i;
1278 #if defined(AST_DEVMODE)
1279  int is_valid;
1280  int code;
1281 #endif /* AST_DEVMODE */
1282 
1283  for (i = get_params; i; i = i->next) {
1284  if (strcmp(i->name, "direction") == 0) {
1285  args.direction = (i->value);
1286  } else
1287  {}
1288  }
1289  for (i = path_vars; i; i = i->next) {
1290  if (strcmp(i->name, "channelId") == 0) {
1291  args.channel_id = (i->value);
1292  } else
1293  {}
1294  }
1295  if (ast_ari_channels_mute_parse_body(body, &args)) {
1297  goto fin;
1298  }
1299  ast_ari_channels_mute(headers, &args, response);
1300 #if defined(AST_DEVMODE)
1301  code = response->response_code;
1302 
1303  switch (code) {
1304  case 0: /* Implementation is still a stub, or the code wasn't set */
1305  is_valid = response->message == NULL;
1306  break;
1307  case 500: /* Internal Server Error */
1308  case 501: /* Not Implemented */
1309  case 404: /* Channel not found */
1310  case 409: /* Channel not in a Stasis application */
1311  case 412: /* Channel in invalid state */
1312  is_valid = 1;
1313  break;
1314  default:
1315  if (200 <= code && code <= 299) {
1316  is_valid = ast_ari_validate_void(
1317  response->message);
1318  } else {
1319  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
1320  is_valid = 0;
1321  }
1322  }
1323 
1324  if (!is_valid) {
1325  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
1326  ast_ari_response_error(response, 500,
1327  "Internal Server Error", "Response validation failed");
1328  }
1329 #endif /* AST_DEVMODE */
1330 
1331 fin: __attribute__((unused))
1332  return;
1333 }
struct ast_variable * next
int ast_ari_channels_mute_parse_body(struct ast_json *body, struct ast_ari_channels_mute_args *args)
Body parsing function for /channels/{channelId}/mute.
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
void ast_ari_channels_mute(struct ast_variable *headers, struct ast_ari_channels_mute_args *args, struct ast_ari_response *response)
Mute a channel.

◆ ast_ari_channels_mute_parse_body()

int ast_ari_channels_mute_parse_body ( struct ast_json body,
struct ast_ari_channels_mute_args args 
)

Body parsing function for /channels/{channelId}/mute.

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 1251 of file res_ari_channels.c.

References ast_json_object_get(), ast_json_string_get(), and ast_ari_channels_mute_args::direction.

Referenced by ast_ari_channels_mute_cb().

1254 {
1255  struct ast_json *field;
1256  /* Parse query parameters out of it */
1257  field = ast_json_object_get(body, "direction");
1258  if (field) {
1259  args->direction = ast_json_string_get(field);
1260  }
1261  return 0;
1262 }
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_channels_originate_cb()

static void ast_ari_channels_originate_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 /channels.

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 175 of file res_ari_channels.c.

References ast_ari_channels_originate_args::app, ast_ari_channels_originate_args::app_args, ast_ari_channels_originate(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_originate_args::caller_id, ast_ari_channels_originate_args::channel_id, ast_ari_channels_originate_args::context, ast_ari_channels_originate_args::endpoint, ast_ari_channels_originate_args::extension, ast_ari_channels_originate_args::formats, ast_ari_channels_originate_args::label, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_originate_args::originator, ast_ari_channels_originate_args::other_channel_id, ast_ari_channels_originate_args::priority, ast_ari_response::response_code, ast_ari_channels_originate_args::timeout, ast_variable::value, and ast_ari_channels_originate_args::variables.

179 {
181  struct ast_variable *i;
182 #if defined(AST_DEVMODE)
183  int is_valid;
184  int code;
185 #endif /* AST_DEVMODE */
186 
187  for (i = get_params; i; i = i->next) {
188  if (strcmp(i->name, "endpoint") == 0) {
189  args.endpoint = (i->value);
190  } else
191  if (strcmp(i->name, "extension") == 0) {
192  args.extension = (i->value);
193  } else
194  if (strcmp(i->name, "context") == 0) {
195  args.context = (i->value);
196  } else
197  if (strcmp(i->name, "priority") == 0) {
198  args.priority = atol(i->value);
199  } else
200  if (strcmp(i->name, "label") == 0) {
201  args.label = (i->value);
202  } else
203  if (strcmp(i->name, "app") == 0) {
204  args.app = (i->value);
205  } else
206  if (strcmp(i->name, "appArgs") == 0) {
207  args.app_args = (i->value);
208  } else
209  if (strcmp(i->name, "callerId") == 0) {
210  args.caller_id = (i->value);
211  } else
212  if (strcmp(i->name, "timeout") == 0) {
213  args.timeout = atoi(i->value);
214  } else
215  if (strcmp(i->name, "channelId") == 0) {
216  args.channel_id = (i->value);
217  } else
218  if (strcmp(i->name, "otherChannelId") == 0) {
219  args.other_channel_id = (i->value);
220  } else
221  if (strcmp(i->name, "originator") == 0) {
222  args.originator = (i->value);
223  } else
224  if (strcmp(i->name, "formats") == 0) {
225  args.formats = (i->value);
226  } else
227  {}
228  }
229  args.variables = body;
230  ast_ari_channels_originate(headers, &args, response);
231 #if defined(AST_DEVMODE)
232  code = response->response_code;
233 
234  switch (code) {
235  case 0: /* Implementation is still a stub, or the code wasn't set */
236  is_valid = response->message == NULL;
237  break;
238  case 500: /* Internal Server Error */
239  case 501: /* Not Implemented */
240  case 400: /* Invalid parameters for originating a channel. */
241  case 409: /* Channel with given unique ID already exists. */
242  is_valid = 1;
243  break;
244  default:
245  if (200 <= code && code <= 299) {
246  is_valid = ast_ari_validate_channel(
247  response->message);
248  } else {
249  ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code);
250  is_valid = 0;
251  }
252  }
253 
254  if (!is_valid) {
255  ast_log(LOG_ERROR, "Response validation failed for /channels\n");
256  ast_ari_response_error(response, 500,
257  "Internal Server Error", "Response validation failed");
258  }
259 #endif /* AST_DEVMODE */
260 
261 fin: __attribute__((unused))
262  return;
263 }
struct ast_variable * next
void ast_ari_channels_originate(struct ast_variable *headers, struct ast_ari_channels_originate_args *args, struct ast_ari_response *response)
Create a new channel (originate).
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
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

◆ ast_ari_channels_originate_parse_body()

int ast_ari_channels_originate_parse_body ( struct ast_json body,
struct ast_ari_channels_originate_args args 
)

Body parsing function for /channels.

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 107 of file res_ari_channels.c.

References ast_ari_channels_originate_args::app, ast_ari_channels_originate_args::app_args, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_ari_channels_originate_args::caller_id, ast_ari_channels_originate_args::channel_id, ast_ari_channels_originate_args::context, ast_ari_channels_originate_args::endpoint, ast_ari_channels_originate_args::extension, ast_ari_channels_originate_args::formats, ast_ari_channels_originate_args::label, ast_ari_channels_originate_args::originator, ast_ari_channels_originate_args::other_channel_id, ast_ari_channels_originate_args::priority, and ast_ari_channels_originate_args::timeout.

Referenced by ast_ari_channels_originate().

110 {
111  struct ast_json *field;
112  /* Parse query parameters out of it */
113  field = ast_json_object_get(body, "endpoint");
114  if (field) {
115  args->endpoint = ast_json_string_get(field);
116  }
117  field = ast_json_object_get(body, "extension");
118  if (field) {
119  args->extension = ast_json_string_get(field);
120  }
121  field = ast_json_object_get(body, "context");
122  if (field) {
123  args->context = ast_json_string_get(field);
124  }
125  field = ast_json_object_get(body, "priority");
126  if (field) {
127  args->priority = ast_json_integer_get(field);
128  }
129  field = ast_json_object_get(body, "label");
130  if (field) {
131  args->label = ast_json_string_get(field);
132  }
133  field = ast_json_object_get(body, "app");
134  if (field) {
135  args->app = ast_json_string_get(field);
136  }
137  field = ast_json_object_get(body, "appArgs");
138  if (field) {
139  args->app_args = ast_json_string_get(field);
140  }
141  field = ast_json_object_get(body, "callerId");
142  if (field) {
143  args->caller_id = ast_json_string_get(field);
144  }
145  field = ast_json_object_get(body, "timeout");
146  if (field) {
147  args->timeout = ast_json_integer_get(field);
148  }
149  field = ast_json_object_get(body, "channelId");
150  if (field) {
151  args->channel_id = ast_json_string_get(field);
152  }
153  field = ast_json_object_get(body, "otherChannelId");
154  if (field) {
155  args->other_channel_id = ast_json_string_get(field);
156  }
157  field = ast_json_object_get(body, "originator");
158  if (field) {
159  args->originator = ast_json_string_get(field);
160  }
161  field = ast_json_object_get(body, "formats");
162  if (field) {
163  args->formats = ast_json_string_get(field);
164  }
165  return 0;
166 }
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_channels_originate_with_id_cb()

static void ast_ari_channels_originate_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 /channels/{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 500 of file res_ari_channels.c.

References ast_ari_channels_originate_with_id_args::app, ast_ari_channels_originate_with_id_args::app_args, ast_ari_channels_originate_with_id(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_originate_with_id_args::caller_id, ast_ari_channels_originate_with_id_args::channel_id, ast_ari_channels_originate_with_id_args::context, ast_ari_channels_originate_with_id_args::endpoint, ast_ari_channels_originate_with_id_args::extension, ast_ari_channels_originate_with_id_args::formats, ast_ari_channels_originate_with_id_args::label, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_originate_with_id_args::originator, ast_ari_channels_originate_with_id_args::other_channel_id, ast_ari_channels_originate_with_id_args::priority, ast_ari_response::response_code, ast_ari_channels_originate_with_id_args::timeout, ast_variable::value, and ast_ari_channels_originate_with_id_args::variables.

504 {
506  struct ast_variable *i;
507 #if defined(AST_DEVMODE)
508  int is_valid;
509  int code;
510 #endif /* AST_DEVMODE */
511 
512  for (i = get_params; i; i = i->next) {
513  if (strcmp(i->name, "endpoint") == 0) {
514  args.endpoint = (i->value);
515  } else
516  if (strcmp(i->name, "extension") == 0) {
517  args.extension = (i->value);
518  } else
519  if (strcmp(i->name, "context") == 0) {
520  args.context = (i->value);
521  } else
522  if (strcmp(i->name, "priority") == 0) {
523  args.priority = atol(i->value);
524  } else
525  if (strcmp(i->name, "label") == 0) {
526  args.label = (i->value);
527  } else
528  if (strcmp(i->name, "app") == 0) {
529  args.app = (i->value);
530  } else
531  if (strcmp(i->name, "appArgs") == 0) {
532  args.app_args = (i->value);
533  } else
534  if (strcmp(i->name, "callerId") == 0) {
535  args.caller_id = (i->value);
536  } else
537  if (strcmp(i->name, "timeout") == 0) {
538  args.timeout = atoi(i->value);
539  } else
540  if (strcmp(i->name, "otherChannelId") == 0) {
541  args.other_channel_id = (i->value);
542  } else
543  if (strcmp(i->name, "originator") == 0) {
544  args.originator = (i->value);
545  } else
546  if (strcmp(i->name, "formats") == 0) {
547  args.formats = (i->value);
548  } else
549  {}
550  }
551  for (i = path_vars; i; i = i->next) {
552  if (strcmp(i->name, "channelId") == 0) {
553  args.channel_id = (i->value);
554  } else
555  {}
556  }
557  args.variables = body;
558  ast_ari_channels_originate_with_id(headers, &args, response);
559 #if defined(AST_DEVMODE)
560  code = response->response_code;
561 
562  switch (code) {
563  case 0: /* Implementation is still a stub, or the code wasn't set */
564  is_valid = response->message == NULL;
565  break;
566  case 500: /* Internal Server Error */
567  case 501: /* Not Implemented */
568  case 400: /* Invalid parameters for originating a channel. */
569  case 409: /* Channel with given unique ID already exists. */
570  is_valid = 1;
571  break;
572  default:
573  if (200 <= code && code <= 299) {
574  is_valid = ast_ari_validate_channel(
575  response->message);
576  } else {
577  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}\n", code);
578  is_valid = 0;
579  }
580  }
581 
582  if (!is_valid) {
583  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}\n");
584  ast_ari_response_error(response, 500,
585  "Internal Server Error", "Response validation failed");
586  }
587 #endif /* AST_DEVMODE */
588 
589 fin: __attribute__((unused))
590  return;
591 }
struct ast_variable * next
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
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
void ast_ari_channels_originate_with_id(struct ast_variable *headers, struct ast_ari_channels_originate_with_id_args *args, struct ast_ari_response *response)
Create a new channel (originate with id).
struct ast_json * message
Definition: ari.h:93

◆ ast_ari_channels_originate_with_id_parse_body()

int ast_ari_channels_originate_with_id_parse_body ( struct ast_json body,
struct ast_ari_channels_originate_with_id_args args 
)

Body parsing function for /channels/{channelId}.

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 436 of file res_ari_channels.c.

References ast_ari_channels_originate_with_id_args::app, ast_ari_channels_originate_with_id_args::app_args, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_ari_channels_originate_with_id_args::caller_id, ast_ari_channels_originate_with_id_args::context, ast_ari_channels_originate_with_id_args::endpoint, ast_ari_channels_originate_with_id_args::extension, ast_ari_channels_originate_with_id_args::formats, ast_ari_channels_originate_with_id_args::label, ast_ari_channels_originate_with_id_args::originator, ast_ari_channels_originate_with_id_args::other_channel_id, ast_ari_channels_originate_with_id_args::priority, and ast_ari_channels_originate_with_id_args::timeout.

Referenced by ast_ari_channels_originate_with_id().

439 {
440  struct ast_json *field;
441  /* Parse query parameters out of it */
442  field = ast_json_object_get(body, "endpoint");
443  if (field) {
444  args->endpoint = ast_json_string_get(field);
445  }
446  field = ast_json_object_get(body, "extension");
447  if (field) {
448  args->extension = ast_json_string_get(field);
449  }
450  field = ast_json_object_get(body, "context");
451  if (field) {
452  args->context = ast_json_string_get(field);
453  }
454  field = ast_json_object_get(body, "priority");
455  if (field) {
456  args->priority = ast_json_integer_get(field);
457  }
458  field = ast_json_object_get(body, "label");
459  if (field) {
460  args->label = ast_json_string_get(field);
461  }
462  field = ast_json_object_get(body, "app");
463  if (field) {
464  args->app = ast_json_string_get(field);
465  }
466  field = ast_json_object_get(body, "appArgs");
467  if (field) {
468  args->app_args = ast_json_string_get(field);
469  }
470  field = ast_json_object_get(body, "callerId");
471  if (field) {
472  args->caller_id = ast_json_string_get(field);
473  }
474  field = ast_json_object_get(body, "timeout");
475  if (field) {
476  args->timeout = ast_json_integer_get(field);
477  }
478  field = ast_json_object_get(body, "otherChannelId");
479  if (field) {
480  args->other_channel_id = ast_json_string_get(field);
481  }
482  field = ast_json_object_get(body, "originator");
483  if (field) {
484  args->originator = ast_json_string_get(field);
485  }
486  field = ast_json_object_get(body, "formats");
487  if (field) {
488  args->formats = ast_json_string_get(field);
489  }
490  return 0;
491 }
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_channels_play_cb()

static void ast_ari_channels_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 /channels/{channelId}/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 1861 of file res_ari_channels.c.

References ARRAY_LEN, ast_app_separate_args, ast_ari_channels_play(), ast_ari_channels_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_channels_play_args::channel_id, ast_ari_channels_play_args::lang, LOG_ERROR, MAX_VALS, ast_ari_channels_play_args::media, ast_ari_channels_play_args::media_count, ast_ari_channels_play_args::media_parse, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_play_args::offsetms, ast_ari_channels_play_args::playback_id, ast_ari_response::response_code, ast_ari_channels_play_args::skipms, and ast_variable::value.

1865 {
1866  struct ast_ari_channels_play_args args = {};
1867  struct ast_variable *i;
1868 #if defined(AST_DEVMODE)
1869  int is_valid;
1870  int code;
1871 #endif /* AST_DEVMODE */
1872 
1873  for (i = get_params; i; i = i->next) {
1874  if (strcmp(i->name, "media") == 0) {
1875  /* Parse comma separated list */
1876  char *vals[MAX_VALS];
1877  size_t j;
1878 
1879  args.media_parse = ast_strdup(i->value);
1880  if (!args.media_parse) {
1882  goto fin;
1883  }
1884 
1885  if (strlen(args.media_parse) == 0) {
1886  /* ast_app_separate_args can't handle "" */
1887  args.media_count = 1;
1888  vals[0] = args.media_parse;
1889  } else {
1891  args.media_parse, ',', vals,
1892  ARRAY_LEN(vals));
1893  }
1894 
1895  if (args.media_count == 0) {
1897  goto fin;
1898  }
1899 
1900  if (args.media_count >= MAX_VALS) {
1901  ast_ari_response_error(response, 400,
1902  "Bad Request",
1903  "Too many values for media");
1904  goto fin;
1905  }
1906 
1907  args.media = ast_malloc(sizeof(*args.media) * args.media_count);
1908  if (!args.media) {
1910  goto fin;
1911  }
1912 
1913  for (j = 0; j < args.media_count; ++j) {
1914  args.media[j] = (vals[j]);
1915  }
1916  } else
1917  if (strcmp(i->name, "lang") == 0) {
1918  args.lang = (i->value);
1919  } else
1920  if (strcmp(i->name, "offsetms") == 0) {
1921  args.offsetms = atoi(i->value);
1922  } else
1923  if (strcmp(i->name, "skipms") == 0) {
1924  args.skipms = atoi(i->value);
1925  } else
1926  if (strcmp(i->name, "playbackId") == 0) {
1927  args.playback_id = (i->value);
1928  } else
1929  {}
1930  }
1931  for (i = path_vars; i; i = i->next) {
1932  if (strcmp(i->name, "channelId") == 0) {
1933  args.channel_id = (i->value);
1934  } else
1935  {}
1936  }
1937  if (ast_ari_channels_play_parse_body(body, &args)) {
1939  goto fin;
1940  }
1941  ast_ari_channels_play(headers, &args, response);
1942 #if defined(AST_DEVMODE)
1943  code = response->response_code;
1944 
1945  switch (code) {
1946  case 0: /* Implementation is still a stub, or the code wasn't set */
1947  is_valid = response->message == NULL;
1948  break;
1949  case 500: /* Internal Server Error */
1950  case 501: /* Not Implemented */
1951  case 404: /* Channel not found */
1952  case 409: /* Channel not in a Stasis application */
1953  case 412: /* Channel in invalid state */
1954  is_valid = 1;
1955  break;
1956  default:
1957  if (200 <= code && code <= 299) {
1958  is_valid = ast_ari_validate_playback(
1959  response->message);
1960  } else {
1961  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play\n", code);
1962  is_valid = 0;
1963  }
1964  }
1965 
1966  if (!is_valid) {
1967  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play\n");
1968  ast_ari_response_error(response, 500,
1969  "Internal Server Error", "Response validation failed");
1970  }
1971 #endif /* AST_DEVMODE */
1972 
1973 fin: __attribute__((unused))
1974  ast_free(args.media_parse);
1975  ast_free(args.media);
1976  return;
1977 }
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
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_channels_play_parse_body(struct ast_json *body, struct ast_ari_channels_play_args *args)
Body parsing function for /channels/{channelId}/play.
int response_code
Definition: ari.h:98
#define ast_log
Definition: astobj2.c:42
#define MAX_VALS
#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
void ast_ari_channels_play(struct ast_variable *headers, struct ast_ari_channels_play_args *args, struct ast_ari_response *response)
Start playback of media.
#define ast_app_separate_args(a, b, c, d)

◆ ast_ari_channels_play_parse_body()

int ast_ari_channels_play_parse_body ( struct ast_json body,
struct ast_ari_channels_play_args args 
)

Body parsing function for /channels/{channelId}/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 1800 of file res_ari_channels.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_channels_play_args::lang, ast_ari_channels_play_args::media, ast_ari_channels_play_args::media_count, ast_ari_channels_play_args::offsetms, ast_ari_channels_play_args::playback_id, and ast_ari_channels_play_args::skipms.

Referenced by ast_ari_channels_play_cb().

1803 {
1804  struct ast_json *field;
1805  /* Parse query parameters out of it */
1806  field = ast_json_object_get(body, "media");
1807  if (field) {
1808  /* If they were silly enough to both pass in a query param and a
1809  * JSON body, free up the query value.
1810  */
1811  ast_free(args->media);
1812  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
1813  /* Multiple param passed as array */
1814  size_t i;
1815  args->media_count = ast_json_array_size(field);
1816  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1817 
1818  if (!args->media) {
1819  return -1;
1820  }
1821 
1822  for (i = 0; i < args->media_count; ++i) {
1823  args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
1824  }
1825  } else {
1826  /* Multiple param passed as single value */
1827  args->media_count = 1;
1828  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1829  if (!args->media) {
1830  return -1;
1831  }
1832  args->media[0] = ast_json_string_get(field);
1833  }
1834  }
1835  field = ast_json_object_get(body, "lang");
1836  if (field) {
1837  args->lang = ast_json_string_get(field);
1838  }
1839  field = ast_json_object_get(body, "offsetms");
1840  if (field) {
1841  args->offsetms = ast_json_integer_get(field);
1842  }
1843  field = ast_json_object_get(body, "skipms");
1844  if (field) {
1845  args->skipms = ast_json_integer_get(field);
1846  }
1847  field = ast_json_object_get(body, "playbackId");
1848  if (field) {
1849  args->playback_id = ast_json_string_get(field);
1850  }
1851  return 0;
1852 }
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_channels_play_with_id_cb()

static void ast_ari_channels_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 /channels/{channelId}/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 2035 of file res_ari_channels.c.

References ARRAY_LEN, ast_app_separate_args, ast_ari_channels_play_with_id(), ast_ari_channels_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_channels_play_with_id_args::channel_id, ast_ari_channels_play_with_id_args::lang, LOG_ERROR, MAX_VALS, ast_ari_channels_play_with_id_args::media, ast_ari_channels_play_with_id_args::media_count, ast_ari_channels_play_with_id_args::media_parse, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_channels_play_with_id_args::offsetms, ast_ari_channels_play_with_id_args::playback_id, ast_ari_response::response_code, ast_ari_channels_play_with_id_args::skipms, and ast_variable::value.

2039 {
2041  struct ast_variable *i;
2042 #if defined(AST_DEVMODE)
2043  int is_valid;
2044  int code;
2045 #endif /* AST_DEVMODE */
2046 
2047  for (i = get_params; i; i = i->next) {
2048  if (strcmp(i->name, "media") == 0) {
2049  /* Parse comma separated list */
2050  char *vals[MAX_VALS];
2051  size_t j;
2052 
2053  args.media_parse = ast_strdup(i->value);
2054  if (!args.media_parse) {
2056  goto fin;
2057  }
2058 
2059  if (strlen(args.media_parse) == 0) {
2060  /* ast_app_separate_args can't handle "" */
2061  args.media_count = 1;
2062  vals[0] = args.media_parse;
2063  } else {
2065  args.media_parse, ',', vals,
2066  ARRAY_LEN(vals));
2067  }
2068 
2069  if (args.media_count == 0) {
2071  goto fin;
2072  }
2073 
2074  if (args.media_count >= MAX_VALS) {
2075  ast_ari_response_error(response, 400,
2076  "Bad Request",
2077  "Too many values for media");
2078  goto fin;
2079  }
2080 
2081  args.media = ast_malloc(sizeof(*args.media) * args.media_count);
2082  if (!args.media) {
2084  goto fin;
2085  }
2086 
2087  for (j = 0; j < args.media_count; ++j) {
2088  args.media[j] = (vals[j]);
2089  }
2090  } else
2091  if (strcmp(i->name, "lang") == 0) {
2092  args.lang = (i->value);
2093  } else
2094  if (strcmp(i->name, "offsetms") == 0) {
2095  args.offsetms = atoi(i->value);
2096  } else
2097  if (strcmp(i->name, "skipms") == 0) {
2098  args.skipms = atoi(i->value);
2099  } else
2100  {}
2101  }
2102  for (i = path_vars; i; i = i->next) {
2103  if (strcmp(i->name, "channelId") == 0) {
2104  args.channel_id = (i->value);
2105  } else
2106  if (strcmp(i->name, "playbackId") == 0) {
2107  args.playback_id = (i->value);
2108  } else
2109  {}
2110  }
2111  if (ast_ari_channels_play_with_id_parse_body(body, &args)) {
2113  goto fin;
2114  }
2115  ast_ari_channels_play_with_id(headers, &args, response);
2116 #if defined(AST_DEVMODE)
2117  code = response->response_code;
2118 
2119  switch (code) {
2120  case 0: /* Implementation is still a stub, or the code wasn't set */
2121  is_valid = response->message == NULL;
2122  break;
2123  case 500: /* Internal Server Error */
2124  case 501: /* Not Implemented */
2125  case 404: /* Channel not found */
2126  case 409: /* Channel not in a Stasis application */
2127  case 412: /* Channel in invalid state */
2128  is_valid = 1;
2129  break;
2130  default:
2131  if (200 <= code && code <= 299) {
2132  is_valid = ast_ari_validate_playback(
2133  response->message);
2134  } else {
2135  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/play/{playbackId}\n", code);
2136  is_valid = 0;
2137  }
2138  }
2139 
2140  if (!is_valid) {
2141  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/play/{playbackId}\n");
2142  ast_ari_response_error(response, 500,
2143  "Internal Server Error", "Response validation failed");
2144  }
2145 #endif /* AST_DEVMODE */
2146 
2147 fin: __attribute__((unused))
2148  ast_free(args.media_parse);
2149  ast_free(args.media);
2150  return;
2151 }
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_channels_play_with_id(struct ast_variable *headers, struct ast_ari_channels_play_with_id_args *args, struct ast_ari_response *response)
Start playback of media and specify the playbackId.
#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 MAX_VALS
#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_channels_play_with_id_parse_body(struct ast_json *body, struct ast_ari_channels_play_with_id_args *args)
Body parsing function for /channels/{channelId}/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_channels_play_with_id_parse_body()

int ast_ari_channels_play_with_id_parse_body ( struct ast_json body,
struct ast_ari_channels_play_with_id_args args 
)

Body parsing function for /channels/{channelId}/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 1978 of file res_ari_channels.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_channels_play_with_id_args::lang, ast_ari_channels_play_with_id_args::media, ast_ari_channels_play_with_id_args::media_count, ast_ari_channels_play_with_id_args::offsetms, and ast_ari_channels_play_with_id_args::skipms.

Referenced by ast_ari_channels_play_with_id_cb().

1981 {
1982  struct ast_json *field;
1983  /* Parse query parameters out of it */
1984  field = ast_json_object_get(body, "media");
1985  if (field) {
1986  /* If they were silly enough to both pass in a query param and a
1987  * JSON body, free up the query value.
1988  */
1989  ast_free(args->media);
1990  if (ast_json_typeof(field) == AST_JSON_ARRAY) {
1991  /* Multiple param passed as array */
1992  size_t i;
1993  args->media_count = ast_json_array_size(field);
1994  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1995 
1996  if (!args->media) {
1997  return -1;
1998  }
1999 
2000  for (i = 0; i < args->media_count; ++i) {
2001  args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
2002  }
2003  } else {
2004  /* Multiple param passed as single value */
2005  args->media_count = 1;
2006  args->media = ast_malloc(sizeof(*args->media) * args->media_count);
2007  if (!args->media) {
2008  return -1;
2009  }
2010  args->media[0] = ast_json_string_get(field);
2011  }
2012  }
2013  field = ast_json_object_get(body, "lang");
2014  if (field) {
2015  args->lang = ast_json_string_get(field);
2016  }
2017  field = ast_json_object_get(body, "offsetms");
2018  if (field) {
2019  args->offsetms = ast_json_integer_get(field);
2020  }
2021  field = ast_json_object_get(body, "skipms");
2022  if (field) {
2023  args->skipms = ast_json_integer_get(field);
2024  }
2025  return 0;
2026 }
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_channels_record_cb()

static void ast_ari_channels_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 /channels/{channelId}/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 2196 of file res_ari_channels.c.

References ast_ari_channels_record(), ast_ari_channels_record_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_live_recording(), ast_log, ast_true(), ast_ari_channels_record_args::beep, ast_ari_channels_record_args::channel_id, ast_ari_channels_record_args::format, ast_ari_channels_record_args::if_exists, LOG_ERROR, ast_ari_channels_record_args::max_duration_seconds, ast_ari_channels_record_args::max_silence_seconds, ast_ari_response::message, ast_variable::name, ast_ari_channels_record_args::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_channels_record_args::terminate_on, and ast_variable::value.

2200 {
2201  struct ast_ari_channels_record_args args = {};
2202  struct ast_variable *i;
2203 #if defined(AST_DEVMODE)
2204  int is_valid;
2205  int code;
2206 #endif /* AST_DEVMODE */
2207 
2208  for (i = get_params; i; i = i->next) {
2209  if (strcmp(i->name, "name") == 0) {
2210  args.name = (i->value);
2211  } else
2212  if (strcmp(i->name, "format") == 0) {
2213  args.format = (i->value);
2214  } else
2215  if (strcmp(i->name, "maxDurationSeconds") == 0) {
2216  args.max_duration_seconds = atoi(i->value);
2217  } else
2218  if (strcmp(i->name, "maxSilenceSeconds") == 0) {
2219  args.max_silence_seconds = atoi(i->value);
2220  } else
2221  if (strcmp(i->name, "ifExists") == 0) {
2222  args.if_exists = (i->value);
2223  } else
2224  if (strcmp(i->name, "beep") == 0) {
2225  args.beep = ast_true(i->value);
2226  } else
2227  if (strcmp(i->name, "terminateOn") == 0) {
2228  args.terminate_on = (i->value);
2229  } else
2230  {}
2231  }
2232  for (i = path_vars; i; i = i->next) {
2233  if (strcmp(i->name, "channelId") == 0) {
2234  args.channel_id = (i->value);
2235  } else
2236  {}
2237  }
2238  if (ast_ari_channels_record_parse_body(body, &args)) {
2240  goto fin;
2241  }
2242  ast_ari_channels_record(headers, &args, response);
2243 #if defined(AST_DEVMODE)
2244  code = response->response_code;
2245 
2246  switch (code) {
2247  case 0: /* Implementation is still a stub, or the code wasn't set */
2248  is_valid = response->message == NULL;
2249  break;
2250  case 500: /* Internal Server Error */
2251  case 501: /* Not Implemented */
2252  case 400: /* Invalid parameters */
2253  case 404: /* Channel not found */
2254  case 409: /* Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
2255  case 422: /* The format specified is unknown on this system */
2256  is_valid = 1;
2257  break;
2258  default:
2259  if (200 <= code && code <= 299) {
2261  response->message);
2262  } else {
2263  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);
2264  is_valid = 0;
2265  }
2266  }
2267 
2268  if (!is_valid) {
2269  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/record\n");
2270  ast_ari_response_error(response, 500,
2271  "Internal Server Error", "Response validation failed");
2272  }
2273 #endif /* AST_DEVMODE */
2274 
2275 fin: __attribute__((unused))
2276  return;
2277 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
void ast_ari_channels_record(struct ast_variable *headers, struct ast_ari_channels_record_args *args, struct ast_ari_response *response)
Start a recording.
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
int ast_ari_channels_record_parse_body(struct ast_json *body, struct ast_ari_channels_record_args *args)
Body parsing function for /channels/{channelId}/record.

◆ ast_ari_channels_record_parse_body()

int ast_ari_channels_record_parse_body ( struct ast_json body,
struct ast_ari_channels_record_args args 
)

Body parsing function for /channels/{channelId}/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 2152 of file res_ari_channels.c.

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

Referenced by ast_ari_channels_record_cb().

2155 {
2156  struct ast_json *field;
2157  /* Parse query parameters out of it */
2158  field = ast_json_object_get(body, "name");
2159  if (field) {
2160  args->name = ast_json_string_get(field);
2161  }
2162  field = ast_json_object_get(body, "format");
2163  if (field) {
2164  args->format = ast_json_string_get(field);
2165  }
2166  field = ast_json_object_get(body, "maxDurationSeconds");
2167  if (field) {
2169  }
2170  field = ast_json_object_get(body, "maxSilenceSeconds");
2171  if (field) {
2173  }
2174  field = ast_json_object_get(body, "ifExists");
2175  if (field) {
2176  args->if_exists = ast_json_string_get(field);
2177  }
2178  field = ast_json_object_get(body, "beep");
2179  if (field) {
2180  args->beep = ast_json_is_true(field);
2181  }
2182  field = ast_json_object_get(body, "terminateOn");
2183  if (field) {
2184  args->terminate_on = ast_json_string_get(field);
2185  }
2186  return 0;
2187 }
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_channels_redirect_cb()

static void ast_ari_channels_redirect_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 /channels/{channelId}/redirect.

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 894 of file res_ari_channels.c.

References ast_ari_channels_redirect(), ast_ari_channels_redirect_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_redirect_args::channel_id, ast_ari_channels_redirect_args::endpoint, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

898 {
900  struct ast_variable *i;
901 #if defined(AST_DEVMODE)
902  int is_valid;
903  int code;
904 #endif /* AST_DEVMODE */
905 
906  for (i = get_params; i; i = i->next) {
907  if (strcmp(i->name, "endpoint") == 0) {
908  args.endpoint = (i->value);
909  } else
910  {}
911  }
912  for (i = path_vars; i; i = i->next) {
913  if (strcmp(i->name, "channelId") == 0) {
914  args.channel_id = (i->value);
915  } else
916  {}
917  }
918  if (ast_ari_channels_redirect_parse_body(body, &args)) {
920  goto fin;
921  }
922  ast_ari_channels_redirect(headers, &args, response);
923 #if defined(AST_DEVMODE)
924  code = response->response_code;
925 
926  switch (code) {
927  case 0: /* Implementation is still a stub, or the code wasn't set */
928  is_valid = response->message == NULL;
929  break;
930  case 500: /* Internal Server Error */
931  case 501: /* Not Implemented */
932  case 400: /* Endpoint parameter not provided */
933  case 404: /* Channel or endpoint not found */
934  case 409: /* Channel not in a Stasis application */
935  case 422: /* Endpoint is not the same type as the channel */
936  case 412: /* Channel in invalid state */
937  is_valid = 1;
938  break;
939  default:
940  if (200 <= code && code <= 299) {
941  is_valid = ast_ari_validate_void(
942  response->message);
943  } else {
944  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/redirect\n", code);
945  is_valid = 0;
946  }
947  }
948 
949  if (!is_valid) {
950  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/redirect\n");
951  ast_ari_response_error(response, 500,
952  "Internal Server Error", "Response validation failed");
953  }
954 #endif /* AST_DEVMODE */
955 
956 fin: __attribute__((unused))
957  return;
958 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
void ast_ari_channels_redirect(struct ast_variable *headers, struct ast_ari_channels_redirect_args *args, struct ast_ari_response *response)
Redirect the channel to a different location.
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
int ast_ari_channels_redirect_parse_body(struct ast_json *body, struct ast_ari_channels_redirect_args *args)
Body parsing function for /channels/{channelId}/redirect.

◆ ast_ari_channels_redirect_parse_body()

int ast_ari_channels_redirect_parse_body ( struct ast_json body,
struct ast_ari_channels_redirect_args args 
)

Body parsing function for /channels/{channelId}/redirect.

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 874 of file res_ari_channels.c.

References ast_json_object_get(), ast_json_string_get(), and ast_ari_channels_redirect_args::endpoint.

Referenced by ast_ari_channels_redirect_cb().

877 {
878  struct ast_json *field;
879  /* Parse query parameters out of it */
880  field = ast_json_object_get(body, "endpoint");
881  if (field) {
882  args->endpoint = ast_json_string_get(field);
883  }
884  return 0;
885 }
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_channels_ring_cb()

static void ast_ari_channels_ring_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 /channels/{channelId}/ring.

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 1026 of file res_ari_channels.c.

References ast_ari_channels_ring(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_ring_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.

1030 {
1031  struct ast_ari_channels_ring_args args = {};
1032  struct ast_variable *i;
1033 #if defined(AST_DEVMODE)
1034  int is_valid;
1035  int code;
1036 #endif /* AST_DEVMODE */
1037 
1038  for (i = path_vars; i; i = i->next) {
1039  if (strcmp(i->name, "channelId") == 0) {
1040  args.channel_id = (i->value);
1041  } else
1042  {}
1043  }
1044  ast_ari_channels_ring(headers, &args, response);
1045 #if defined(AST_DEVMODE)
1046  code = response->response_code;
1047 
1048  switch (code) {
1049  case 0: /* Implementation is still a stub, or the code wasn't set */
1050  is_valid = response->message == NULL;
1051  break;
1052  case 500: /* Internal Server Error */
1053  case 501: /* Not Implemented */
1054  case 404: /* Channel not found */
1055  case 409: /* Channel not in a Stasis application */
1056  case 412: /* Channel in invalid state */
1057  is_valid = 1;
1058  break;
1059  default:
1060  if (200 <= code && code <= 299) {
1061  is_valid = ast_ari_validate_void(
1062  response->message);
1063  } else {
1064  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
1065  is_valid = 0;
1066  }
1067  }
1068 
1069  if (!is_valid) {
1070  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
1071  ast_ari_response_error(response, 500,
1072  "Internal Server Error", "Response validation failed");
1073  }
1074 #endif /* AST_DEVMODE */
1075 
1076 fin: __attribute__((unused))
1077  return;
1078 }
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_channels_ring(struct ast_variable *headers, struct ast_ari_channels_ring_args *args, struct ast_ari_response *response)
Indicate ringing to a channel.

◆ ast_ari_channels_ring_stop_cb()

static void ast_ari_channels_ring_stop_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 /channels/{channelId}/ring.

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 1086 of file res_ari_channels.c.

References ast_ari_channels_ring_stop(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_ring_stop_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.

1090 {
1092  struct ast_variable *i;
1093 #if defined(AST_DEVMODE)
1094  int is_valid;
1095  int code;
1096 #endif /* AST_DEVMODE */
1097 
1098  for (i = path_vars; i; i = i->next) {
1099  if (strcmp(i->name, "channelId") == 0) {
1100  args.channel_id = (i->value);
1101  } else
1102  {}
1103  }
1104  ast_ari_channels_ring_stop(headers, &args, response);
1105 #if defined(AST_DEVMODE)
1106  code = response->response_code;
1107 
1108  switch (code) {
1109  case 0: /* Implementation is still a stub, or the code wasn't set */
1110  is_valid = response->message == NULL;
1111  break;
1112  case 500: /* Internal Server Error */
1113  case 501: /* Not Implemented */
1114  case 404: /* Channel not found */
1115  case 409: /* Channel not in a Stasis application */
1116  case 412: /* Channel in invalid state */
1117  is_valid = 1;
1118  break;
1119  default:
1120  if (200 <= code && code <= 299) {
1121  is_valid = ast_ari_validate_void(
1122  response->message);
1123  } else {
1124  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/ring\n", code);
1125  is_valid = 0;
1126  }
1127  }
1128 
1129  if (!is_valid) {
1130  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/ring\n");
1131  ast_ari_response_error(response, 500,
1132  "Internal Server Error", "Response validation failed");
1133  }
1134 #endif /* AST_DEVMODE */
1135 
1136 fin: __attribute__((unused))
1137  return;
1138 }
struct ast_variable * next
void ast_ari_channels_ring_stop(struct ast_variable *headers, struct ast_ari_channels_ring_stop_args *args, struct ast_ari_response *response)
Stop ringing indication on a channel if locally generated.
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

◆ ast_ari_channels_rtpstatistics_cb()

static void ast_ari_channels_rtpstatistics_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 /channels/{channelId}/rtp_statistics.

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 2763 of file res_ari_channels.c.

References ast_ari_channels_rtpstatistics(), ast_ari_response_error(), ast_ari_validate_rtpstat(), ast_log, ast_ari_channels_rtpstatistics_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.

2767 {
2769  struct ast_variable *i;
2770 #if defined(AST_DEVMODE)
2771  int is_valid;
2772  int code;
2773 #endif /* AST_DEVMODE */
2774 
2775  for (i = path_vars; i; i = i->next) {
2776  if (strcmp(i->name, "channelId") == 0) {
2777  args.channel_id = (i->value);
2778  } else
2779  {}
2780  }
2781  ast_ari_channels_rtpstatistics(headers, &args, response);
2782 #if defined(AST_DEVMODE)
2783  code = response->response_code;
2784 
2785  switch (code) {
2786  case 0: /* Implementation is still a stub, or the code wasn't set */
2787  is_valid = response->message == NULL;
2788  break;
2789  case 500: /* Internal Server Error */
2790  case 501: /* Not Implemented */
2791  case 404: /* Channel cannot be found. */
2792  is_valid = 1;
2793  break;
2794  default:
2795  if (200 <= code && code <= 299) {
2796  is_valid = ast_ari_validate_rtpstat(
2797  response->message);
2798  } else {
2799  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/rtp_statistics\n", code);
2800  is_valid = 0;
2801  }
2802  }
2803 
2804  if (!is_valid) {
2805  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/rtp_statistics\n");
2806  ast_ari_response_error(response, 500,
2807  "Internal Server Error", "Response validation failed");
2808  }
2809 #endif /* AST_DEVMODE */
2810 
2811 fin: __attribute__((unused))
2812  return;
2813 }
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_channels_rtpstatistics(struct ast_variable *headers, struct ast_ari_channels_rtpstatistics_args *args, struct ast_ari_response *response)
RTP stats on a channel.
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
int ast_ari_validate_rtpstat(struct ast_json *json)
Validator for RTPstat.
struct ast_json * message
Definition: ari.h:93

◆ ast_ari_channels_send_dtmf_cb()

static void ast_ari_channels_send_dtmf_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 /channels/{channelId}/dtmf.

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 1175 of file res_ari_channels.c.

References ast_ari_channels_send_dtmf_args::after, ast_ari_channels_send_dtmf(), ast_ari_channels_send_dtmf_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_send_dtmf_args::before, ast_ari_channels_send_dtmf_args::between, ast_ari_channels_send_dtmf_args::channel_id, ast_ari_channels_send_dtmf_args::dtmf, ast_ari_channels_send_dtmf_args::duration, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

1179 {
1181  struct ast_variable *i;
1182 #if defined(AST_DEVMODE)
1183  int is_valid;
1184  int code;
1185 #endif /* AST_DEVMODE */
1186 
1187  for (i = get_params; i; i = i->next) {
1188  if (strcmp(i->name, "dtmf") == 0) {
1189  args.dtmf = (i->value);
1190  } else
1191  if (strcmp(i->name, "before") == 0) {
1192  args.before = atoi(i->value);
1193  } else
1194  if (strcmp(i->name, "between") == 0) {
1195  args.between = atoi(i->value);
1196  } else
1197  if (strcmp(i->name, "duration") == 0) {
1198  args.duration = atoi(i->value);
1199  } else
1200  if (strcmp(i->name, "after") == 0) {
1201  args.after = atoi(i->value);
1202  } else
1203  {}
1204  }
1205  for (i = path_vars; i; i = i->next) {
1206  if (strcmp(i->name, "channelId") == 0) {
1207  args.channel_id = (i->value);
1208  } else
1209  {}
1210  }
1211  if (ast_ari_channels_send_dtmf_parse_body(body, &args)) {
1213  goto fin;
1214  }
1215  ast_ari_channels_send_dtmf(headers, &args, response);
1216 #if defined(AST_DEVMODE)
1217  code = response->response_code;
1218 
1219  switch (code) {
1220  case 0: /* Implementation is still a stub, or the code wasn't set */
1221  is_valid = response->message == NULL;
1222  break;
1223  case 500: /* Internal Server Error */
1224  case 501: /* Not Implemented */
1225  case 400: /* DTMF is required */
1226  case 404: /* Channel not found */
1227  case 409: /* Channel not in a Stasis application */
1228  case 412: /* Channel in invalid state */
1229  is_valid = 1;
1230  break;
1231  default:
1232  if (200 <= code && code <= 299) {
1233  is_valid = ast_ari_validate_void(
1234  response->message);
1235  } else {
1236  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/dtmf\n", code);
1237  is_valid = 0;
1238  }
1239  }
1240 
1241  if (!is_valid) {
1242  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/dtmf\n");
1243  ast_ari_response_error(response, 500,
1244  "Internal Server Error", "Response validation failed");
1245  }
1246 #endif /* AST_DEVMODE */
1247 
1248 fin: __attribute__((unused))
1249  return;
1250 }
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 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_channels_send_dtmf(struct ast_variable *headers, struct ast_ari_channels_send_dtmf_args *args, struct ast_ari_response *response)
Send provided DTMF to a given channel.
int ast_ari_channels_send_dtmf_parse_body(struct ast_json *body, struct ast_ari_channels_send_dtmf_args *args)
Body parsing function for /channels/{channelId}/dtmf.
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_channels_send_dtmf_parse_body()

int ast_ari_channels_send_dtmf_parse_body ( struct ast_json body,
struct ast_ari_channels_send_dtmf_args args 
)

Body parsing function for /channels/{channelId}/dtmf.

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 1139 of file res_ari_channels.c.

References ast_ari_channels_send_dtmf_args::after, ast_json_integer_get(), ast_json_object_get(), ast_json_string_get(), ast_ari_channels_send_dtmf_args::before, ast_ari_channels_send_dtmf_args::between, ast_ari_channels_send_dtmf_args::dtmf, and ast_ari_channels_send_dtmf_args::duration.

Referenced by ast_ari_channels_send_dtmf_cb().

1142 {
1143  struct ast_json *field;
1144  /* Parse query parameters out of it */
1145  field = ast_json_object_get(body, "dtmf");
1146  if (field) {
1147  args->dtmf = ast_json_string_get(field);
1148  }
1149  field = ast_json_object_get(body, "before");
1150  if (field) {
1151  args->before = ast_json_integer_get(field);
1152  }
1153  field = ast_json_object_get(body, "between");
1154  if (field) {
1155  args->between = ast_json_integer_get(field);
1156  }
1157  field = ast_json_object_get(body, "duration");
1158  if (field) {
1159  args->duration = ast_json_integer_get(field);
1160  }
1161  field = ast_json_object_get(body, "after");
1162  if (field) {
1163  args->after = ast_json_integer_get(field);
1164  }
1165  return 0;
1166 }
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_channels_set_channel_var_cb()

static void ast_ari_channels_set_channel_var_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 /channels/{channelId}/variable.

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 2385 of file res_ari_channels.c.

References ast_ari_channels_set_channel_var(), ast_ari_channels_set_channel_var_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_set_channel_var_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_variable::value, ast_ari_channels_set_channel_var_args::value, and ast_ari_channels_set_channel_var_args::variable.

2389 {
2391  struct ast_variable *i;
2392 #if defined(AST_DEVMODE)
2393  int is_valid;
2394  int code;
2395 #endif /* AST_DEVMODE */
2396 
2397  for (i = get_params; i; i = i->next) {
2398  if (strcmp(i->name, "variable") == 0) {
2399  args.variable = (i->value);
2400  } else
2401  if (strcmp(i->name, "value") == 0) {
2402  args.value = (i->value);
2403  } else
2404  {}
2405  }
2406  for (i = path_vars; i; i = i->next) {
2407  if (strcmp(i->name, "channelId") == 0) {
2408  args.channel_id = (i->value);
2409  } else
2410  {}
2411  }
2414  goto fin;
2415  }
2416  ast_ari_channels_set_channel_var(headers, &args, response);
2417 #if defined(AST_DEVMODE)
2418  code = response->response_code;
2419 
2420  switch (code) {
2421  case 0: /* Implementation is still a stub, or the code wasn't set */
2422  is_valid = response->message == NULL;
2423  break;
2424  case 500: /* Internal Server Error */
2425  case 501: /* Not Implemented */
2426  case 400: /* Missing variable parameter. */
2427  case 404: /* Channel not found */
2428  case 409: /* Channel not in a Stasis application */
2429  is_valid = 1;
2430  break;
2431  default:
2432  if (200 <= code && code <= 299) {
2433  is_valid = ast_ari_validate_void(
2434  response->message);
2435  } else {
2436  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
2437  is_valid = 0;
2438  }
2439  }
2440 
2441  if (!is_valid) {
2442  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
2443  ast_ari_response_error(response, 500,
2444  "Internal Server Error", "Response validation failed");
2445  }
2446 #endif /* AST_DEVMODE */
2447 
2448 fin: __attribute__((unused))
2449  return;
2450 }
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 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_channels_set_channel_var(struct ast_variable *headers, struct ast_ari_channels_set_channel_var_args *args, struct ast_ari_response *response)
Set the value of a channel variable or function.
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_channels_set_channel_var_parse_body(struct ast_json *body, struct ast_ari_channels_set_channel_var_args *args)
Body parsing function for /channels/{channelId}/variable.

◆ ast_ari_channels_set_channel_var_parse_body()

int ast_ari_channels_set_channel_var_parse_body ( struct ast_json body,
struct ast_ari_channels_set_channel_var_args args 
)

Body parsing function for /channels/{channelId}/variable.

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 2361 of file res_ari_channels.c.

References ast_json_object_get(), ast_json_string_get(), ast_ari_channels_set_channel_var_args::value, and ast_ari_channels_set_channel_var_args::variable.

Referenced by ast_ari_channels_set_channel_var_cb().

2364 {
2365  struct ast_json *field;
2366  /* Parse query parameters out of it */
2367  field = ast_json_object_get(body, "variable");
2368  if (field) {
2369  args->variable = ast_json_string_get(field);
2370  }
2371  field = ast_json_object_get(body, "value");
2372  if (field) {
2373  args->value = ast_json_string_get(field);
2374  }
2375  return 0;
2376 }
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_channels_snoop_channel_cb()

static void ast_ari_channels_snoop_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 /channels/{channelId}/snoop.

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 2487 of file res_ari_channels.c.

References ast_ari_channels_snoop_channel_args::app, ast_ari_channels_snoop_channel_args::app_args, ast_ari_channels_snoop_channel(), ast_ari_channels_snoop_channel_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_snoop_channel_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_channels_snoop_channel_args::snoop_id, ast_ari_channels_snoop_channel_args::spy, ast_variable::value, and ast_ari_channels_snoop_channel_args::whisper.

2491 {
2493  struct ast_variable *i;
2494 #if defined(AST_DEVMODE)
2495  int is_valid;
2496  int code;
2497 #endif /* AST_DEVMODE */
2498 
2499  for (i = get_params; i; i = i->next) {
2500  if (strcmp(i->name, "spy") == 0) {
2501  args.spy = (i->value);
2502  } else
2503  if (strcmp(i->name, "whisper") == 0) {
2504  args.whisper = (i->value);
2505  } else
2506  if (strcmp(i->name, "app") == 0) {
2507  args.app = (i->value);
2508  } else
2509  if (strcmp(i->name, "appArgs") == 0) {
2510  args.app_args = (i->value);
2511  } else
2512  if (strcmp(i->name, "snoopId") == 0) {
2513  args.snoop_id = (i->value);
2514  } else
2515  {}
2516  }
2517  for (i = path_vars; i; i = i->next) {
2518  if (strcmp(i->name, "channelId") == 0) {
2519  args.channel_id = (i->value);
2520  } else
2521  {}
2522  }
2523  if (ast_ari_channels_snoop_channel_parse_body(body, &args)) {
2525  goto fin;
2526  }
2527  ast_ari_channels_snoop_channel(headers, &args, response);
2528 #if defined(AST_DEVMODE)
2529  code = response->response_code;
2530 
2531  switch (code) {
2532  case 0: /* Implementation is still a stub, or the code wasn't set */
2533  is_valid = response->message == NULL;
2534  break;
2535  case 500: /* Internal Server Error */
2536  case 501: /* Not Implemented */
2537  case 400: /* Invalid parameters */
2538  case 404: /* Channel not found */
2539  is_valid = 1;
2540  break;
2541  default:
2542  if (200 <= code && code <= 299) {
2543  is_valid = ast_ari_validate_channel(
2544  response->message);
2545  } else {
2546  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop\n", code);
2547  is_valid = 0;
2548  }
2549  }
2550 
2551  if (!is_valid) {
2552  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop\n");
2553  ast_ari_response_error(response, 500,
2554  "Internal Server Error", "Response validation failed");
2555  }
2556 #endif /* AST_DEVMODE */
2557 
2558 fin: __attribute__((unused))
2559  return;
2560 }
struct ast_variable * next
int ast_ari_channels_snoop_channel_parse_body(struct ast_json *body, struct ast_ari_channels_snoop_channel_args *args)
Body parsing function for /channels/{channelId}/snoop.
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
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
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_channels_snoop_channel(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_args *args, struct ast_ari_response *response)
Start snooping.

◆ ast_ari_channels_snoop_channel_parse_body()

int ast_ari_channels_snoop_channel_parse_body ( struct ast_json body,
struct ast_ari_channels_snoop_channel_args args 
)

Body parsing function for /channels/{channelId}/snoop.

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 2451 of file res_ari_channels.c.

References ast_ari_channels_snoop_channel_args::app, ast_ari_channels_snoop_channel_args::app_args, ast_json_object_get(), ast_json_string_get(), ast_ari_channels_snoop_channel_args::snoop_id, ast_ari_channels_snoop_channel_args::spy, and ast_ari_channels_snoop_channel_args::whisper.

Referenced by ast_ari_channels_snoop_channel_cb().

2454 {
2455  struct ast_json *field;
2456  /* Parse query parameters out of it */
2457  field = ast_json_object_get(body, "spy");
2458  if (field) {
2459  args->spy = ast_json_string_get(field);
2460  }
2461  field = ast_json_object_get(body, "whisper");
2462  if (field) {
2463  args->whisper = ast_json_string_get(field);
2464  }
2465  field = ast_json_object_get(body, "app");
2466  if (field) {
2467  args->app = ast_json_string_get(field);
2468  }
2469  field = ast_json_object_get(body, "appArgs");
2470  if (field) {
2471  args->app_args = ast_json_string_get(field);
2472  }
2473  field = ast_json_object_get(body, "snoopId");
2474  if (field) {
2475  args->snoop_id = ast_json_string_get(field);
2476  }
2477  return 0;
2478 }
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_channels_snoop_channel_with_id_cb()

static void ast_ari_channels_snoop_channel_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 /channels/{channelId}/snoop/{snoopId}.

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 2593 of file res_ari_channels.c.

References ast_ari_channels_snoop_channel_with_id_args::app, ast_ari_channels_snoop_channel_with_id_args::app_args, ast_ari_channels_snoop_channel_with_id(), ast_ari_channels_snoop_channel_with_id_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_channel(), ast_log, ast_ari_channels_snoop_channel_with_id_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, ast_ari_channels_snoop_channel_with_id_args::snoop_id, ast_ari_channels_snoop_channel_with_id_args::spy, ast_variable::value, and ast_ari_channels_snoop_channel_with_id_args::whisper.

2597 {
2599  struct ast_variable *i;
2600 #if defined(AST_DEVMODE)
2601  int is_valid;
2602  int code;
2603 #endif /* AST_DEVMODE */
2604 
2605  for (i = get_params; i; i = i->next) {
2606  if (strcmp(i->name, "spy") == 0) {
2607  args.spy = (i->value);
2608  } else
2609  if (strcmp(i->name, "whisper") == 0) {
2610  args.whisper = (i->value);
2611  } else
2612  if (strcmp(i->name, "app") == 0) {
2613  args.app = (i->value);
2614  } else
2615  if (strcmp(i->name, "appArgs") == 0) {
2616  args.app_args = (i->value);
2617  } else
2618  {}
2619  }
2620  for (i = path_vars; i; i = i->next) {
2621  if (strcmp(i->name, "channelId") == 0) {
2622  args.channel_id = (i->value);
2623  } else
2624  if (strcmp(i->name, "snoopId") == 0) {
2625  args.snoop_id = (i->value);
2626  } else
2627  {}
2628  }
2631  goto fin;
2632  }
2633  ast_ari_channels_snoop_channel_with_id(headers, &args, response);
2634 #if defined(AST_DEVMODE)
2635  code = response->response_code;
2636 
2637  switch (code) {
2638  case 0: /* Implementation is still a stub, or the code wasn't set */
2639  is_valid = response->message == NULL;
2640  break;
2641  case 500: /* Internal Server Error */
2642  case 501: /* Not Implemented */
2643  case 400: /* Invalid parameters */
2644  case 404: /* Channel not found */
2645  is_valid = 1;
2646  break;
2647  default:
2648  if (200 <= code && code <= 299) {
2649  is_valid = ast_ari_validate_channel(
2650  response->message);
2651  } else {
2652  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/snoop/{snoopId}\n", code);
2653  is_valid = 0;
2654  }
2655  }
2656 
2657  if (!is_valid) {
2658  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/snoop/{snoopId}\n");
2659  ast_ari_response_error(response, 500,
2660  "Internal Server Error", "Response validation failed");
2661  }
2662 #endif /* AST_DEVMODE */
2663 
2664 fin: __attribute__((unused))
2665  return;
2666 }
struct ast_variable * next
int ast_ari_validate_channel(struct ast_json *json)
Validator for Channel.
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
void ast_ari_channels_snoop_channel_with_id(struct ast_variable *headers, struct ast_ari_channels_snoop_channel_with_id_args *args, struct ast_ari_response *response)
Start snooping.
#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_channels_snoop_channel_with_id_parse_body(struct ast_json *body, struct ast_ari_channels_snoop_channel_with_id_args *args)
Body parsing function for /channels/{channelId}/snoop/{snoopId}.

◆ ast_ari_channels_snoop_channel_with_id_parse_body()

int ast_ari_channels_snoop_channel_with_id_parse_body ( struct ast_json body,
struct ast_ari_channels_snoop_channel_with_id_args args 
)

Body parsing function for /channels/{channelId}/snoop/{snoopId}.

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 2561 of file res_ari_channels.c.

References ast_ari_channels_snoop_channel_with_id_args::app, ast_ari_channels_snoop_channel_with_id_args::app_args, ast_json_object_get(), ast_json_string_get(), ast_ari_channels_snoop_channel_with_id_args::spy, and ast_ari_channels_snoop_channel_with_id_args::whisper.

Referenced by ast_ari_channels_snoop_channel_with_id_cb().

2564 {
2565  struct ast_json *field;
2566  /* Parse query parameters out of it */
2567  field = ast_json_object_get(body, "spy");
2568  if (field) {
2569  args->spy = ast_json_string_get(field);
2570  }
2571  field = ast_json_object_get(body, "whisper");
2572  if (field) {
2573  args->whisper = ast_json_string_get(field);
2574  }
2575  field = ast_json_object_get(body, "app");
2576  if (field) {
2577  args->app = ast_json_string_get(field);
2578  }
2579  field = ast_json_object_get(body, "appArgs");
2580  if (field) {
2581  args->app_args = ast_json_string_get(field);
2582  }
2583  return 0;
2584 }
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_channels_start_moh_cb()

static void ast_ari_channels_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 /channels/{channelId}/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 1557 of file res_ari_channels.c.

References ast_ari_channels_start_moh(), ast_ari_channels_start_moh_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_start_moh_args::channel_id, LOG_ERROR, ast_ari_response::message, ast_ari_channels_start_moh_args::moh_class, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

1561 {
1563  struct ast_variable *i;
1564 #if defined(AST_DEVMODE)
1565  int is_valid;
1566  int code;
1567 #endif /* AST_DEVMODE */
1568 
1569  for (i = get_params; i; i = i->next) {
1570  if (strcmp(i->name, "mohClass") == 0) {
1571  args.moh_class = (i->value);
1572  } else
1573  {}
1574  }
1575  for (i = path_vars; i; i = i->next) {
1576  if (strcmp(i->name, "channelId") == 0) {
1577  args.channel_id = (i->value);
1578  } else
1579  {}
1580  }
1581  if (ast_ari_channels_start_moh_parse_body(body, &args)) {
1583  goto fin;
1584  }
1585  ast_ari_channels_start_moh(headers, &args, response);
1586 #if defined(AST_DEVMODE)
1587  code = response->response_code;
1588 
1589  switch (code) {
1590  case 0: /* Implementation is still a stub, or the code wasn't set */
1591  is_valid = response->message == NULL;
1592  break;
1593  case 500: /* Internal Server Error */
1594  case 501: /* Not Implemented */
1595  case 404: /* Channel not found */
1596  case 409: /* Channel not in a Stasis application */
1597  case 412: /* Channel in invalid state */
1598  is_valid = 1;
1599  break;
1600  default:
1601  if (200 <= code && code <= 299) {
1602  is_valid = ast_ari_validate_void(
1603  response->message);
1604  } else {
1605  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
1606  is_valid = 0;
1607  }
1608  }
1609 
1610  if (!is_valid) {
1611  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
1612  ast_ari_response_error(response, 500,
1613  "Internal Server Error", "Response validation failed");
1614  }
1615 #endif /* AST_DEVMODE */
1616 
1617 fin: __attribute__((unused))
1618  return;
1619 }
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 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_channels_start_moh(struct ast_variable *headers, struct ast_ari_channels_start_moh_args *args, struct ast_ari_response *response)
Play music on hold to a channel.
int ast_ari_channels_start_moh_parse_body(struct ast_json *body, struct ast_ari_channels_start_moh_args *args)
Body parsing function for /channels/{channelId}/moh.

◆ ast_ari_channels_start_moh_parse_body()

int ast_ari_channels_start_moh_parse_body ( struct ast_json body,
struct ast_ari_channels_start_moh_args args 
)

Body parsing function for /channels/{channelId}/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 1537 of file res_ari_channels.c.

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

Referenced by ast_ari_channels_start_moh_cb().

1540 {
1541  struct ast_json *field;
1542  /* Parse query parameters out of it */
1543  field = ast_json_object_get(body, "mohClass");
1544  if (field) {
1545  args->moh_class = ast_json_string_get(field);
1546  }
1547  return 0;
1548 }
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_channels_start_silence_cb()

static void ast_ari_channels_start_silence_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 /channels/{channelId}/silence.

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 1687 of file res_ari_channels.c.

References ast_ari_channels_start_silence(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_start_silence_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.

1691 {
1693  struct ast_variable *i;
1694 #if defined(AST_DEVMODE)
1695  int is_valid;
1696  int code;
1697 #endif /* AST_DEVMODE */
1698 
1699  for (i = path_vars; i; i = i->next) {
1700  if (strcmp(i->name, "channelId") == 0) {
1701  args.channel_id = (i->value);
1702  } else
1703  {}
1704  }
1705  ast_ari_channels_start_silence(headers, &args, response);
1706 #if defined(AST_DEVMODE)
1707  code = response->response_code;
1708 
1709  switch (code) {
1710  case 0: /* Implementation is still a stub, or the code wasn't set */
1711  is_valid = response->message == NULL;
1712  break;
1713  case 500: /* Internal Server Error */
1714  case 501: /* Not Implemented */
1715  case 404: /* Channel not found */
1716  case 409: /* Channel not in a Stasis application */
1717  case 412: /* Channel in invalid state */
1718  is_valid = 1;
1719  break;
1720  default:
1721  if (200 <= code && code <= 299) {
1722  is_valid = ast_ari_validate_void(
1723  response->message);
1724  } else {
1725  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
1726  is_valid = 0;
1727  }
1728  }
1729 
1730  if (!is_valid) {
1731  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
1732  ast_ari_response_error(response, 500,
1733  "Internal Server Error", "Response validation failed");
1734  }
1735 #endif /* AST_DEVMODE */
1736 
1737 fin: __attribute__((unused))
1738  return;
1739 }
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_channels_start_silence(struct ast_variable *headers, struct ast_ari_channels_start_silence_args *args, struct ast_ari_response *response)
Play silence to a channel.
#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_channels_stop_moh_cb()

static void ast_ari_channels_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 /channels/{channelId}/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 1627 of file res_ari_channels.c.

References ast_ari_channels_stop_moh(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_stop_moh_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.

1631 {
1633  struct ast_variable *i;
1634 #if defined(AST_DEVMODE)
1635  int is_valid;
1636  int code;
1637 #endif /* AST_DEVMODE */
1638 
1639  for (i = path_vars; i; i = i->next) {
1640  if (strcmp(i->name, "channelId") == 0) {
1641  args.channel_id = (i->value);
1642  } else
1643  {}
1644  }
1645  ast_ari_channels_stop_moh(headers, &args, response);
1646 #if defined(AST_DEVMODE)
1647  code = response->response_code;
1648 
1649  switch (code) {
1650  case 0: /* Implementation is still a stub, or the code wasn't set */
1651  is_valid = response->message == NULL;
1652  break;
1653  case 500: /* Internal Server Error */
1654  case 501: /* Not Implemented */
1655  case 404: /* Channel not found */
1656  case 409: /* Channel not in a Stasis application */
1657  case 412: /* Channel in invalid state */
1658  is_valid = 1;
1659  break;
1660  default:
1661  if (200 <= code && code <= 299) {
1662  is_valid = ast_ari_validate_void(
1663  response->message);
1664  } else {
1665  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/moh\n", code);
1666  is_valid = 0;
1667  }
1668  }
1669 
1670  if (!is_valid) {
1671  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/moh\n");
1672  ast_ari_response_error(response, 500,
1673  "Internal Server Error", "Response validation failed");
1674  }
1675 #endif /* AST_DEVMODE */
1676 
1677 fin: __attribute__((unused))
1678  return;
1679 }
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_channels_stop_moh(struct ast_variable *headers, struct ast_ari_channels_stop_moh_args *args, struct ast_ari_response *response)
Stop playing music on hold to a channel.

◆ ast_ari_channels_stop_silence_cb()

static void ast_ari_channels_stop_silence_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 /channels/{channelId}/silence.

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 1747 of file res_ari_channels.c.

References ast_ari_channels_stop_silence(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_stop_silence_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.

1751 {
1753  struct ast_variable *i;
1754 #if defined(AST_DEVMODE)
1755  int is_valid;
1756  int code;
1757 #endif /* AST_DEVMODE */
1758 
1759  for (i = path_vars; i; i = i->next) {
1760  if (strcmp(i->name, "channelId") == 0) {
1761  args.channel_id = (i->value);
1762  } else
1763  {}
1764  }
1765  ast_ari_channels_stop_silence(headers, &args, response);
1766 #if defined(AST_DEVMODE)
1767  code = response->response_code;
1768 
1769  switch (code) {
1770  case 0: /* Implementation is still a stub, or the code wasn't set */
1771  is_valid = response->message == NULL;
1772  break;
1773  case 500: /* Internal Server Error */
1774  case 501: /* Not Implemented */
1775  case 404: /* Channel not found */
1776  case 409: /* Channel not in a Stasis application */
1777  case 412: /* Channel in invalid state */
1778  is_valid = 1;
1779  break;
1780  default:
1781  if (200 <= code && code <= 299) {
1782  is_valid = ast_ari_validate_void(
1783  response->message);
1784  } else {
1785  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/silence\n", code);
1786  is_valid = 0;
1787  }
1788  }
1789 
1790  if (!is_valid) {
1791  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/silence\n");
1792  ast_ari_response_error(response, 500,
1793  "Internal Server Error", "Response validation failed");
1794  }
1795 #endif /* AST_DEVMODE */
1796 
1797 fin: __attribute__((unused))
1798  return;
1799 }
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_channels_stop_silence(struct ast_variable *headers, struct ast_ari_channels_stop_silence_args *args, struct ast_ari_response *response)
Stop playing silence to a channel.
#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_channels_unhold_cb()

static void ast_ari_channels_unhold_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 /channels/{channelId}/hold.

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 1484 of file res_ari_channels.c.

References ast_ari_channels_unhold(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_unhold_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.

1488 {
1489  struct ast_ari_channels_unhold_args args = {};
1490  struct ast_variable *i;
1491 #if defined(AST_DEVMODE)
1492  int is_valid;
1493  int code;
1494 #endif /* AST_DEVMODE */
1495 
1496  for (i = path_vars; i; i = i->next) {
1497  if (strcmp(i->name, "channelId") == 0) {
1498  args.channel_id = (i->value);
1499  } else
1500  {}
1501  }
1502  ast_ari_channels_unhold(headers, &args, response);
1503 #if defined(AST_DEVMODE)
1504  code = response->response_code;
1505 
1506  switch (code) {
1507  case 0: /* Implementation is still a stub, or the code wasn't set */
1508  is_valid = response->message == NULL;
1509  break;
1510  case 500: /* Internal Server Error */
1511  case 501: /* Not Implemented */
1512  case 404: /* Channel not found */
1513  case 409: /* Channel not in a Stasis application */
1514  case 412: /* Channel in invalid state */
1515  is_valid = 1;
1516  break;
1517  default:
1518  if (200 <= code && code <= 299) {
1519  is_valid = ast_ari_validate_void(
1520  response->message);
1521  } else {
1522  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/hold\n", code);
1523  is_valid = 0;
1524  }
1525  }
1526 
1527  if (!is_valid) {
1528  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/hold\n");
1529  ast_ari_response_error(response, 500,
1530  "Internal Server Error", "Response validation failed");
1531  }
1532 #endif /* AST_DEVMODE */
1533 
1534 fin: __attribute__((unused))
1535  return;
1536 }
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_channels_unhold(struct ast_variable *headers, struct ast_ari_channels_unhold_args *args, struct ast_ari_response *response)
Remove a channel from hold.

◆ ast_ari_channels_unmute_cb()

static void ast_ari_channels_unmute_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 /channels/{channelId}/mute.

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 1354 of file res_ari_channels.c.

References ast_ari_channels_unmute(), ast_ari_channels_unmute_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_validate_void(), ast_log, ast_ari_channels_unmute_args::channel_id, ast_ari_channels_unmute_args::direction, LOG_ERROR, ast_ari_response::message, ast_variable::name, ast_variable::next, NULL, ast_ari_response::response_code, and ast_variable::value.

1358 {
1359  struct ast_ari_channels_unmute_args args = {};
1360  struct ast_variable *i;
1361 #if defined(AST_DEVMODE)
1362  int is_valid;
1363  int code;
1364 #endif /* AST_DEVMODE */
1365 
1366  for (i = get_params; i; i = i->next) {
1367  if (strcmp(i->name, "direction") == 0) {
1368  args.direction = (i->value);
1369  } else
1370  {}
1371  }
1372  for (i = path_vars; i; i = i->next) {
1373  if (strcmp(i->name, "channelId") == 0) {
1374  args.channel_id = (i->value);
1375  } else
1376  {}
1377  }
1378  if (ast_ari_channels_unmute_parse_body(body, &args)) {
1380  goto fin;
1381  }
1382  ast_ari_channels_unmute(headers, &args, response);
1383 #if defined(AST_DEVMODE)
1384  code = response->response_code;
1385 
1386  switch (code) {
1387  case 0: /* Implementation is still a stub, or the code wasn't set */
1388  is_valid = response->message == NULL;
1389  break;
1390  case 500: /* Internal Server Error */
1391  case 501: /* Not Implemented */
1392  case 404: /* Channel not found */
1393  case 409: /* Channel not in a Stasis application */
1394  case 412: /* Channel in invalid state */
1395  is_valid = 1;
1396  break;
1397  default:
1398  if (200 <= code && code <= 299) {
1399  is_valid = ast_ari_validate_void(
1400  response->message);
1401  } else {
1402  ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/mute\n", code);
1403  is_valid = 0;
1404  }
1405  }
1406 
1407  if (!is_valid) {
1408  ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/mute\n");
1409  ast_ari_response_error(response, 500,
1410  "Internal Server Error", "Response validation failed");
1411  }
1412 #endif /* AST_DEVMODE */
1413 
1414 fin: __attribute__((unused))
1415  return;
1416 }
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 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
void ast_ari_channels_unmute(struct ast_variable *headers, struct ast_ari_channels_unmute_args *args, struct ast_ari_response *response)
Unmute a channel.
#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_channels_unmute_parse_body(struct ast_json *body, struct ast_ari_channels_unmute_args *args)
Body parsing function for /channels/{channelId}/mute.

◆ ast_ari_channels_unmute_parse_body()

int ast_ari_channels_unmute_parse_body ( struct ast_json body,
struct ast_ari_channels_unmute_args args 
)

Body parsing function for /channels/{channelId}/mute.

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 1334 of file res_ari_channels.c.

References ast_json_object_get(), ast_json_string_get(), and ast_ari_channels_unmute_args::direction.

Referenced by ast_ari_channels_unmute_cb().

1337 {
1338  struct ast_json *field;
1339  /* Parse query parameters out of it */
1340  field = ast_json_object_get(body, "direction");
1341  if (field) {
1342  args->direction = ast_json_string_get(field);
1343  }
1344  return 0;
1345 }
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_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 3180 of file res_ari_channels.c.

◆ load_module()

static int load_module ( void  )
static

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

3162 {
3163  int res = 0;
3164 
3165 
3166  res |= ast_ari_add_handler(&channels);
3167  if (res) {
3168  unload_module();
3169  return AST_MODULE_LOAD_DECLINE;
3170  }
3171 
3172  return AST_MODULE_LOAD_SUCCESS;
3173 }
static int unload_module(void)
static struct stasis_rest_handlers channels
REST handler for /api-docs/channels.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

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 3155 of file res_ari_channels.c.

References ast_ari_remove_handler().

Referenced by load_module().

3156 {
3158  return 0;
3159 }
static struct stasis_rest_handlers channels
REST handler for /api-docs/channels.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 - Channel 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_answer,res_stasis_playback,res_stasis_recording,res_stasis_snoop", }
static

Definition at line 3180 of file res_ari_channels.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 3180 of file res_ari_channels.c.

◆ channels

struct stasis_rest_handlers channels
static

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

Definition at line 3145 of file res_ari_channels.c.

◆ channels_channelId

struct stasis_rest_handlers channels_channelId
static

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

Definition at line 3124 of file res_ari_channels.c.

◆ channels_channelId_answer

struct stasis_rest_handlers channels_channelId_answer
static

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

Definition at line 2981 of file res_ari_channels.c.

◆ channels_channelId_continue

struct stasis_rest_handlers channels_channelId_continue
static

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

Definition at line 2954 of file res_ari_channels.c.

◆ channels_channelId_dial

struct stasis_rest_handlers channels_channelId_dial
static

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

Definition at line 3106 of file res_ari_channels.c.

◆ channels_channelId_dtmf

struct stasis_rest_handlers channels_channelId_dtmf
static

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

Definition at line 3000 of file res_ari_channels.c.

◆ channels_channelId_hold

struct stasis_rest_handlers channels_channelId_hold
static

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

Definition at line 3019 of file res_ari_channels.c.

◆ channels_channelId_moh

struct stasis_rest_handlers channels_channelId_moh
static

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

Definition at line 3029 of file res_ari_channels.c.

◆ channels_channelId_move

struct stasis_rest_handlers channels_channelId_move
static

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

Definition at line 2963 of file res_ari_channels.c.

◆ channels_channelId_mute

struct stasis_rest_handlers channels_channelId_mute
static

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

Definition at line 3009 of file res_ari_channels.c.

◆ channels_channelId_play

struct stasis_rest_handlers channels_channelId_play
static

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

Definition at line 3059 of file res_ari_channels.c.

◆ channels_channelId_play_playbackId

struct stasis_rest_handlers channels_channelId_play_playbackId
static

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

Definition at line 3049 of file res_ari_channels.c.

◆ channels_channelId_record

struct stasis_rest_handlers channels_channelId_record
static

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

Definition at line 3068 of file res_ari_channels.c.

◆ channels_channelId_redirect

struct stasis_rest_handlers channels_channelId_redirect
static

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

Definition at line 2972 of file res_ari_channels.c.

◆ channels_channelId_ring

struct stasis_rest_handlers channels_channelId_ring
static

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

Definition at line 2990 of file res_ari_channels.c.

◆ channels_channelId_rtp_statistics

struct stasis_rest_handlers channels_channelId_rtp_statistics
static

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

Definition at line 3115 of file res_ari_channels.c.

◆ channels_channelId_silence

struct stasis_rest_handlers channels_channelId_silence
static

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

Definition at line 3039 of file res_ari_channels.c.

◆ channels_channelId_snoop

struct stasis_rest_handlers channels_channelId_snoop
static

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

Definition at line 3097 of file res_ari_channels.c.

◆ channels_channelId_snoop_snoopId

struct stasis_rest_handlers channels_channelId_snoop_snoopId
static

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

Definition at line 3087 of file res_ari_channels.c.

◆ channels_channelId_variable

struct stasis_rest_handlers channels_channelId_variable
static

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

Definition at line 3077 of file res_ari_channels.c.

◆ channels_create

struct stasis_rest_handlers channels_create
static

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

Definition at line 2945 of file res_ari_channels.c.

◆ channels_externalMedia

struct stasis_rest_handlers channels_externalMedia
static

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

Definition at line 3136 of file res_ari_channels.c.