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

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

#include "asterisk/ari.h"
Include dependency graph for resource_channels.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_ari_channels_answer_args
 
struct  ast_ari_channels_continue_in_dialplan_args
 
struct  ast_ari_channels_create_args
 
struct  ast_ari_channels_dial_args
 
struct  ast_ari_channels_external_media_args
 
struct  ast_ari_channels_get_args
 
struct  ast_ari_channels_get_channel_var_args
 
struct  ast_ari_channels_hangup_args
 
struct  ast_ari_channels_hold_args
 
struct  ast_ari_channels_list_args
 
struct  ast_ari_channels_move_args
 
struct  ast_ari_channels_mute_args
 
struct  ast_ari_channels_originate_args
 
struct  ast_ari_channels_originate_with_id_args
 
struct  ast_ari_channels_play_args
 
struct  ast_ari_channels_play_with_id_args
 
struct  ast_ari_channels_record_args
 
struct  ast_ari_channels_redirect_args
 
struct  ast_ari_channels_ring_args
 
struct  ast_ari_channels_ring_stop_args
 
struct  ast_ari_channels_rtpstatistics_args
 
struct  ast_ari_channels_send_dtmf_args
 
struct  ast_ari_channels_set_channel_var_args
 
struct  ast_ari_channels_snoop_channel_args
 
struct  ast_ari_channels_snoop_channel_with_id_args
 
struct  ast_ari_channels_start_moh_args
 
struct  ast_ari_channels_start_silence_args
 
struct  ast_ari_channels_stop_moh_args
 
struct  ast_ari_channels_stop_silence_args
 
struct  ast_ari_channels_unhold_args
 
struct  ast_ari_channels_unmute_args
 

Functions

void ast_ari_channels_answer (struct ast_variable *headers, struct ast_ari_channels_answer_args *args, struct ast_ari_response *response)
 Answer a channel. More...
 
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. 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...
 
void ast_ari_channels_create (struct ast_variable *headers, struct ast_ari_channels_create_args *args, struct ast_ari_response *response)
 Create channel. 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...
 
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. 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...
 
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. 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...
 
void ast_ari_channels_get (struct ast_variable *headers, struct ast_ari_channels_get_args *args, struct ast_ari_response *response)
 Channel details. More...
 
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. 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...
 
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. 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...
 
void ast_ari_channels_hold (struct ast_variable *headers, struct ast_ari_channels_hold_args *args, struct ast_ari_response *response)
 Hold a channel. More...
 
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. More...
 
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. 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...
 
void ast_ari_channels_mute (struct ast_variable *headers, struct ast_ari_channels_mute_args *args, struct ast_ari_response *response)
 Mute a channel. 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...
 
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). 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...
 
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). 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...
 
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. 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...
 
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. 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...
 
void ast_ari_channels_record (struct ast_variable *headers, struct ast_ari_channels_record_args *args, struct ast_ari_response *response)
 Start a recording. 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...
 
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. 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...
 
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. More...
 
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. More...
 
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. More...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. 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...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void ast_ari_channels_unmute (struct ast_variable *headers, struct ast_ari_channels_unmute_args *args, struct ast_ari_response *response)
 Unmute a channel. 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...
 

Detailed Description

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

Channel resources

Author
David M. Lee, II [email protected][email protected]digi[email protected]um.co[email protected]m

Definition in file resource_channels.h.

Function Documentation

◆ ast_ari_channels_answer()

void ast_ari_channels_answer ( struct ast_variable headers,
struct ast_ari_channels_answer_args args,
struct ast_ari_response response 
)

Answer a channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 338 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), ast_ari_channels_answer_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_answer().

Referenced by ast_ari_channels_answer_cb().

341 {
342  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
343 
344  control = find_control(response, args->channel_id);
345  if (control == NULL) {
346  return;
347  }
348 
349  if (channel_state_invalid(control, response)) {
350  return;
351  }
352 
353  if (stasis_app_control_answer(control) != 0) {
355  response, 500, "Internal Server Error",
356  "Failed to answer channel");
357  return;
358  }
359 
360  ast_ari_response_no_content(response);
361 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int stasis_app_control_answer(struct stasis_app_control *control)
Answer the channel associated with this control.

◆ ast_ari_channels_continue_in_dialplan()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 180 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_no_content(), ast_assert, ast_debug, ast_findlabel_extension(), ast_log, AST_LOG_ERROR, ast_strlen_zero, ast_ari_channels_continue_in_dialplan_args::channel_id, channel_state_invalid(), context, ast_ari_channels_continue_in_dialplan_args::context, exten, ast_ari_channels_continue_in_dialplan_args::extension, find_control(), ast_ari_channels_continue_in_dialplan_args::label, NULL, ast_ari_channels_continue_in_dialplan_args::priority, RAII_VAR, S_OR, stasis_app_control_continue(), and stasis_app_control_get_snapshot().

Referenced by ast_ari_channels_continue_in_dialplan_cb().

184 {
185  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
186  RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
187  int ipri;
188  const char *context;
189  const char *exten;
190 
191  ast_assert(response != NULL);
192 
193  control = find_control(response, args->channel_id);
194  if (control == NULL) {
195  return;
196  }
197 
198  if (channel_state_invalid(control, response)) {
199  return;
200  }
201 
202  snapshot = stasis_app_control_get_snapshot(control);
203  if (!snapshot) {
204  ast_ari_response_error(response, 404, "Not Found", "Channel not found");
205  return;
206  }
207 
208  if (ast_strlen_zero(args->context)) {
209  context = snapshot->dialplan->context;
210  exten = S_OR(args->extension, snapshot->dialplan->exten);
211  } else {
212  context = args->context;
213  exten = S_OR(args->extension, "s");
214  }
215 
216  if (!ast_strlen_zero(args->label)) {
217  /* A label was provided in the request, use that */
218 
219  if (sscanf(args->label, "%30d", &ipri) != 1) {
220  ipri = ast_findlabel_extension(NULL, context, exten, args->label, NULL);
221  if (ipri == -1) {
222  ast_log(AST_LOG_ERROR, "Requested label: %s can not be found in context: %s\n", args->label, context);
223  ast_ari_response_error(response, 404, "Not Found", "Requested label can not be found");
224  return;
225  }
226  } else {
227  ast_debug(3, "Numeric value provided for label, jumping to that priority\n");
228  }
229 
230  if (ipri == 0) {
231  ast_log(AST_LOG_ERROR, "Invalid priority label '%s' specified for extension %s in context: %s\n",
232  args->label, exten, context);
233  ast_ari_response_error(response, 400, "Bad Request", "Requested priority is illegal");
234  return;
235  }
236 
237  } else if (args->priority) {
238  /* No label provided, use provided priority */
239  ipri = args->priority;
240  } else if (ast_strlen_zero(args->context) && ast_strlen_zero(args->extension)) {
241  /* Special case. No exten, context, or priority provided, then move on to the next priority */
242  ipri = snapshot->dialplan->priority + 1;
243  } else {
244  ipri = 1;
245  }
246 
247 
248  if (stasis_app_control_continue(control, context, exten, ipri)) {
250  return;
251  }
252 
253  ast_ari_response_no_content(response);
254 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority)
Exit res_stasis and continue execution in the dialplan.
Definition: control.c:389
Structure representing a snapshot of channel state.
#define ast_assert(a)
Definition: utils.h:695
#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
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define AST_LOG_ERROR
Definition: logger.h:290
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
int ast_findlabel_extension(struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
Find the priority of an extension that has the specified label.
Definition: pbx.c:4184
struct ast_channel_snapshot * stasis_app_control_get_snapshot(const struct stasis_app_control *control)
Returns the most recent snapshot for the associated channel.
Definition: control.c:860
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

void ast_ari_channels_create ( struct ast_variable headers,
struct ast_ari_channels_create_args args,
struct ast_ari_response response 
)

Create channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1778 of file resource_channels.c.

References ao2_bump, ao2_cleanup, ao2_ref, ast_ari_channels_create_args::app, ast_ari_channels_create_args::app_args, ari_channel_thread(), ast_ari_channels_create_parse_body(), ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_ok(), ast_calloc, ast_channel_cleanup, ast_channel_errno(), AST_CHANNEL_ERROR_ID_EXISTS, ast_channel_get_by_name(), ast_channel_nativeformats(), ast_channel_snapshot_get_latest(), ast_channel_snapshot_to_json(), ast_channel_uniqueid(), ast_format_cache_get, ast_format_cap_alloc, ast_format_cap_append, ast_format_cap_append_by_type(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_json_object_get(), AST_MEDIA_TYPE_AUDIO, ast_pthread_create_detached, ast_request(), ast_set_variables(), ast_str_append(), ast_str_create, ast_strdupa, ast_strip(), ast_strlen_zero, ari_channel_thread_data::chan, chan_data_destroy(), ast_ari_channels_create_args::channel_id, ast_ari_channels_create_args::endpoint, ast_ari_channels_create_args::formats, json_to_ast_variables(), NULL, ast_ari_channels_create_args::originator, ast_ari_channels_create_args::other_channel_id, save_dialstring(), stasis_app_subscribe_channel(), ari_channel_thread_data::stasis_stuff, strsep(), thread, ast_assigned_ids::uniqueid, ast_assigned_ids::uniqueid2, and ast_ari_channels_create_args::variables.

Referenced by ast_ari_channels_create_cb().

1781 {
1782  struct ast_variable *variables = NULL;
1783  struct ast_assigned_ids assignedids;
1784  struct ari_channel_thread_data *chan_data;
1785  struct ast_channel_snapshot *snapshot;
1786  pthread_t thread;
1787  char *dialtech;
1788  char *dialdevice = NULL;
1789  char *stuff;
1790  int cause;
1791  struct ast_format_cap *request_cap;
1792  struct ast_channel *originator;
1793 
1794  /* Parse any query parameters out of the body parameter */
1795  if (args->variables) {
1796  struct ast_json *json_variables;
1797 
1799  json_variables = ast_json_object_get(args->variables, "variables");
1800  if (json_variables
1801  && json_to_ast_variables(response, json_variables, &variables)) {
1802  return;
1803  }
1804  }
1805 
1806  assignedids.uniqueid = args->channel_id;
1807  assignedids.uniqueid2 = args->other_channel_id;
1808 
1809  if (!ast_strlen_zero(args->originator) && !ast_strlen_zero(args->formats)) {
1810  ast_ari_response_error(response, 400, "Bad Request",
1811  "Originator and formats can't both be specified");
1812  return;
1813  }
1814 
1815  if (ast_strlen_zero(args->endpoint)) {
1816  ast_ari_response_error(response, 400, "Bad Request",
1817  "Endpoint must be specified");
1818  return;
1819  }
1820 
1821  chan_data = ast_calloc(1, sizeof(*chan_data));
1822  if (!chan_data) {
1824  return;
1825  }
1826 
1827  chan_data->stasis_stuff = ast_str_create(32);
1828  if (!chan_data->stasis_stuff) {
1830  chan_data_destroy(chan_data);
1831  return;
1832  }
1833 
1834  ast_str_append(&chan_data->stasis_stuff, 0, "%s", args->app);
1835  if (!ast_strlen_zero(args->app_args)) {
1836  ast_str_append(&chan_data->stasis_stuff, 0, ",%s", args->app_args);
1837  }
1838 
1839  dialtech = ast_strdupa(args->endpoint);
1840  if ((stuff = strchr(dialtech, '/'))) {
1841  *stuff++ = '\0';
1842  dialdevice = stuff;
1843  }
1844 
1845  if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
1846  ast_ari_response_error(response, 400, "Bad Request",
1847  "Invalid endpoint specified");
1848  chan_data_destroy(chan_data);
1849  return;
1850  }
1851 
1852  originator = ast_channel_get_by_name(args->originator);
1853  if (originator) {
1854  request_cap = ao2_bump(ast_channel_nativeformats(originator));
1855  if (!ast_strlen_zero(args->app)) {
1856  stasis_app_subscribe_channel(args->app, originator);
1857  }
1858  } else if (!ast_strlen_zero(args->formats)) {
1859  char *format_name;
1860  char *formats_copy = ast_strdupa(args->formats);
1861 
1862  if (!(request_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
1864  chan_data_destroy(chan_data);
1865  return;
1866  }
1867 
1868  while ((format_name = ast_strip(strsep(&formats_copy, ",")))) {
1869  struct ast_format *fmt = ast_format_cache_get(format_name);
1870 
1871  if (!fmt || ast_format_cap_append(request_cap, fmt, 0)) {
1872  if (!fmt) {
1874  response, 400, "Bad Request",
1875  "Provided format (%s) was not found", format_name);
1876  } else {
1878  }
1879  ao2_ref(request_cap, -1);
1880  ao2_cleanup(fmt);
1881  chan_data_destroy(chan_data);
1882  return;
1883  }
1884  ao2_ref(fmt, -1);
1885  }
1886  } else {
1887  if (!(request_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
1889  chan_data_destroy(chan_data);
1890  return;
1891  }
1892 
1894  }
1895 
1896  chan_data->chan = ast_request(dialtech, request_cap, &assignedids, originator, dialdevice, &cause);
1897  ao2_cleanup(request_cap);
1898 
1899  if (!chan_data->chan) {
1901  ast_ari_response_error(response, 409, "Conflict",
1902  "Channel with given unique ID already exists");
1903  } else {
1905  }
1906  ast_channel_cleanup(originator);
1907  chan_data_destroy(chan_data);
1908  return;
1909  }
1910 
1911  if (!ast_strlen_zero(args->app)) {
1912  stasis_app_subscribe_channel(args->app, chan_data->chan);
1913  }
1914 
1915  if (variables) {
1916  ast_set_variables(chan_data->chan, variables);
1917  }
1918 
1919  ast_channel_cleanup(originator);
1920 
1921  if (save_dialstring(chan_data->chan, stuff)) {
1923  chan_data_destroy(chan_data);
1924  return;
1925  }
1926 
1928 
1929  if (ast_pthread_create_detached(&thread, NULL, ari_channel_thread, chan_data)) {
1931  chan_data_destroy(chan_data);
1932  } else {
1934  }
1935 
1936  ao2_ref(snapshot, -1);
1937 }
pthread_t thread
Definition: app_meetme.c:1089
Main Channel structure associated with a channel.
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:563
int ast_ari_channels_create_parse_body(struct ast_json *body, struct ast_ari_channels_create_args *args)
Body parsing function for /channels/create.
Structure for variables, used for configurations and for channel variables.
Structure representing a snapshot of channel state.
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8217
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
Definition of a media format.
Definition: format.c:43
static void * ari_channel_thread(void *data)
Thread that owns stasis-created channel.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
int ast_format_cap_append_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Add all codecs Asterisk knows about for a specific type to the capabilities structure.
Definition: format_cap.c:216
#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
#define ast_format_cache_get(name)
Definition: format_cache.h:286
#define ast_strlen_zero(foo)
Definition: strings.h:52
struct ast_channel * ast_request(const char *type, struct ast_format_cap *request_cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *addr, int *cause)
Requests a channel.
Definition: channel.c:6444
static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
#define ao2_bump(obj)
Definition: astobj2.h:491
static int save_dialstring(struct ast_channel *chan, const char *dialstring)
Save dialstring onto a channel datastore.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
const char * ast_channel_uniqueid(const struct ast_channel *chan)
struct ast_channel * chan
struct ast_str * stasis_stuff
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
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
enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name, struct ast_channel *chan)
Directly subscribe an application to a channel.
Definition: res_stasis.c:1984
struct ast_format_cap * ast_channel_nativeformats(const struct ast_channel *chan)
char * strsep(char **str, const char *delims)
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object...
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
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
static void chan_data_destroy(struct ari_channel_thread_data *chan_data)
Abstract JSON element (object, array, string, int, ...).
enum ast_channel_error ast_channel_errno(void)
Get error code for latest channel operation.
Definition: channel.c:11162
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:620

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

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1939 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_no_content(), ast_channel_adsicpe_set(), ast_channel_caller(), ast_channel_cleanup, ast_channel_connected(), ast_channel_datastore_inherit(), ast_channel_dialed(), ast_channel_get_by_name(), ast_channel_inherit_variables(), ast_channel_language(), ast_channel_lock, ast_channel_lock_both, ast_channel_musicclass(), ast_channel_redirecting(), ast_channel_req_accountcodes(), AST_CHANNEL_REQUESTOR_BRIDGE_PEER, ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_transfercapability(), ast_channel_transfercapability_set(), ast_channel_unlock, ast_connected_line_copy_from_caller(), ast_max_forwards_decrement(), ast_party_redirecting_copy(), AST_STATE_DOWN, AST_STATE_RESERVED, ast_strdupa, ast_strlen_zero, ast_ari_channels_dial_args::caller, ast_ari_channels_dial_args::channel_id, find_control(), NULL, RAII_VAR, restore_dialstring(), stasis_app_control_dial(), ast_ari_channels_dial_args::timeout, and ast_party_dialed::transit_network_select.

Referenced by ast_ari_channels_dial_cb().

1942 {
1943  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1944  RAII_VAR(struct ast_channel *, caller, NULL, ast_channel_cleanup);
1945  RAII_VAR(struct ast_channel *, callee, NULL, ast_channel_cleanup);
1946  char *dialstring;
1947 
1948  control = find_control(response, args->channel_id);
1949  if (control == NULL) {
1950  /* Response filled in by find_control */
1951  return;
1952  }
1953 
1954  caller = ast_channel_get_by_name(args->caller);
1955 
1956  callee = ast_channel_get_by_name(args->channel_id);
1957  if (!callee) {
1958  ast_ari_response_error(response, 404, "Not Found",
1959  "Callee not found");
1960  return;
1961  }
1962 
1963  if (ast_channel_state(callee) != AST_STATE_DOWN
1964  && ast_channel_state(callee) != AST_STATE_RESERVED) {
1965  ast_ari_response_error(response, 409, "Conflict",
1966  "Channel is not in the 'Down' state");
1967  return;
1968  }
1969 
1970  /* XXX This is straight up copied from main/dial.c. It's probably good
1971  * to separate this to some common method.
1972  */
1973  if (caller) {
1974  ast_channel_lock_both(caller, callee);
1975  } else {
1976  ast_channel_lock(callee);
1977  }
1978 
1979  dialstring = restore_dialstring(callee);
1980  if (!dialstring) {
1981  ast_channel_unlock(callee);
1982  if (caller) {
1983  ast_channel_unlock(caller);
1984  }
1985  ast_ari_response_error(response, 409, "Conflict",
1986  "Dialing a channel not created by ARI");
1987  return;
1988  }
1989  /* Make a copy of the dialstring just in case some jerk tries to hang up the
1990  * channel before we can actually dial
1991  */
1992  dialstring = ast_strdupa(dialstring);
1993 
1995  if (caller) {
1996  ast_channel_inherit_variables(caller, callee);
1997  ast_channel_datastore_inherit(caller, callee);
1999 
2000  /* Copy over callerid information */
2002 
2004 
2006 
2007  ast_channel_language_set(callee, ast_channel_language(caller));
2010  ast_channel_musicclass_set(callee, ast_channel_musicclass(caller));
2011 
2014  ast_channel_unlock(caller);
2015  }
2016 
2018  ast_channel_unlock(callee);
2019 
2020  if (stasis_app_control_dial(control, dialstring, args->timeout)) {
2022  return;
2023  }
2024 
2025  ast_ari_response_no_content(response);
2026 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
unsigned short ast_channel_transfercapability(const struct ast_channel *chan)
ast_channel_state
ast_channel states
Definition: channelstate.h:35
#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
static char * restore_dialstring(struct ast_channel *chan)
Retrieve the dialstring from the channel datastore.
#define ast_strlen_zero(foo)
Definition: strings.h:52
int ast_channel_datastore_inherit(struct ast_channel *from, struct ast_channel *to)
Inherit datastores from a parent to a child.
Definition: channel.c:2373
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct ast_party_connected_line * ast_channel_connected(struct ast_channel *chan)
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
int stasis_app_control_dial(struct stasis_app_control *control, const char *dialstring, unsigned int timeout)
Dial a channel.
Definition: control.c:1666
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
void ast_channel_req_accountcodes(struct ast_channel *chan, const struct ast_channel *requestor, enum ast_channel_requestor_relationship relationship)
Setup new channel accountcodes from the requestor channel after ast_request().
Definition: channel.c:6526
void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value)
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
ast_channel_adsicpe
Definition: channel.h:869
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_channel_inherit_variables(const struct ast_channel *parent, struct ast_channel *child)
Inherits channel variable from parent to child channel.
Definition: channel.c:6866
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
struct ast_party_redirecting * ast_channel_redirecting(struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2952
int transit_network_select
Transit Network Select.
Definition: channel.h:398
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
int ast_max_forwards_decrement(struct ast_channel *chan)
Decrement the max forwards count for a particular channel.
Definition: max_forwards.c:135
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_connected_line_copy_from_caller(struct ast_party_connected_line *dest, const struct ast_party_caller *src)
Copy the caller information to the connected line information.
Definition: channel.c:8389
void ast_channel_transfercapability_set(struct ast_channel *chan, unsigned short value)
const char * ast_channel_language(const struct ast_channel *chan)
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void ast_party_redirecting_copy(struct ast_party_redirecting *dest, const struct ast_party_redirecting *src)
Copy the source redirecting information to the destination redirecting.
Definition: channel.c:2135
const char * ast_channel_musicclass(const struct ast_channel *chan)

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

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.

Create a channel to an External Media source/sink.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 2176 of file resource_channels.c.

References ast_ari_channels_external_media_args::app, ast_ari_channels_external_media_parse_body(), ast_ari_response_error(), ast_assert, ast_json_object_get(), ast_sockaddr_split_hostport(), ast_strdupa, ast_strlen_zero, ast_ari_channels_external_media_args::connection_type, ast_ari_channels_external_media_args::direction, ast_ari_channels_external_media_args::encapsulation, ast_ari_channels_external_media_args::external_host, external_media_audiosocket_tcp(), external_media_rtp_udp(), ast_ari_channels_external_media_args::format, host, json_to_ast_variables(), NULL, PARSE_PORT_REQUIRE, ast_ari_channels_external_media_args::transport, and ast_ari_channels_external_media_args::variables.

Referenced by ast_ari_channels_external_media_cb().

2178 {
2179  struct ast_variable *variables = NULL;
2180  char *external_host;
2181  char *host = NULL;
2182  char *port = NULL;
2183 
2184  ast_assert(response != NULL);
2185 
2186  if (ast_strlen_zero(args->app)) {
2187  ast_ari_response_error(response, 400, "Bad Request", "app cannot be empty");
2188  return;
2189  }
2190 
2191  if (ast_strlen_zero(args->external_host)) {
2192  ast_ari_response_error(response, 400, "Bad Request", "external_host cannot be empty");
2193  return;
2194  }
2195 
2196  external_host = ast_strdupa(args->external_host);
2197  if (!ast_sockaddr_split_hostport(external_host, &host, &port, PARSE_PORT_REQUIRE)) {
2198  ast_ari_response_error(response, 400, "Bad Request", "external_host must be <host>:<port>");
2199  return;
2200  }
2201 
2202  if (ast_strlen_zero(args->format)) {
2203  ast_ari_response_error(response, 400, "Bad Request", "format cannot be empty");
2204  return;
2205  }
2206 
2207  if (ast_strlen_zero(args->encapsulation)) {
2208  args->encapsulation = "rtp";
2209  }
2210  if (ast_strlen_zero(args->transport)) {
2211  args->transport = "udp";
2212  }
2213  if (ast_strlen_zero(args->connection_type)) {
2214  args->connection_type = "client";
2215  }
2216  if (ast_strlen_zero(args->direction)) {
2217  args->direction = "both";
2218  }
2219 
2220  if (args->variables) {
2221  struct ast_json *json_variables;
2222 
2224  json_variables = ast_json_object_get(args->variables, "variables");
2225  if (json_variables
2226  && json_to_ast_variables(response, json_variables, &variables)) {
2227  return;
2228  }
2229  }
2230 
2231  if (strcasecmp(args->encapsulation, "rtp") == 0 && strcasecmp(args->transport, "udp") == 0) {
2232  external_media_rtp_udp(args, variables, response);
2233  } else if (strcasecmp(args->encapsulation, "audiosocket") == 0 && strcasecmp(args->transport, "tcp") == 0) {
2234  external_media_audiosocket_tcp(args, variables, response);
2235  } else {
2237  response, 501, "Not Implemented",
2238  "The encapsulation and/or transport is not supported");
2239  }
2240 }
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.
static void external_media_rtp_udp(struct ast_ari_channels_external_media_args *args, struct ast_variable *variables, struct ast_ari_response *response)
Structure for variables, used for configurations and for channel variables.
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
static char host[256]
Definition: muted.c:77
int ast_sockaddr_split_hostport(char *str, char **host, char **port, int flags)
Splits a string into its host and port components.
Definition: netsock2.c:164
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
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 * 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, ...).
static void external_media_audiosocket_tcp(struct ast_ari_channels_external_media_args *args, struct ast_variable *variables, struct ast_ari_response *response)

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

void ast_ari_channels_get ( struct ast_variable headers,
struct ast_ari_channels_get_args args,
struct ast_ari_response response 
)

Channel details.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 888 of file resource_channels.c.

References ao2_ref, ast_ari_response_error(), ast_ari_response_ok(), ast_channel_snapshot_get_latest(), ast_channel_snapshot_to_json(), ast_ari_channels_get_args::channel_id, and NULL.

Referenced by ast_ari_channels_get_cb().

891 {
892  struct ast_channel_snapshot *snapshot;
893 
895  if (!snapshot) {
897  response, 404, "Not Found",
898  "Channel not found");
899  return;
900  }
901 
902  ast_ari_response_ok(response,
904  ao2_ref(snapshot, -1);
905 }
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
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_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object...

◆ ast_ari_channels_get_channel_var()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1472 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_alloc_failed(), ast_ari_response_error(), ast_ari_response_ok(), ast_assert, ast_channel_cleanup, ast_channel_get_by_name(), ast_free, ast_func_read2(), ast_json_pack(), ast_json_ref(), ast_json_unref(), ast_str_buffer(), ast_str_create, ast_str_retrieve_variable(), ast_strlen_zero, ast_ari_channels_get_channel_var_args::channel_id, NULL, RAII_VAR, S_OR, value, and ast_ari_channels_get_channel_var_args::variable.

Referenced by ast_ari_channels_get_channel_var_cb().

1475 {
1476  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
1477  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1478  RAII_VAR(struct ast_str *, value, ast_str_create(32), ast_free);
1480 
1481  ast_assert(response != NULL);
1482 
1483  if (!value) {
1485  return;
1486  }
1487 
1488  if (ast_strlen_zero(args->variable)) {
1490  response, 400, "Bad Request",
1491  "Variable name is required");
1492  return;
1493  }
1494 
1495  if (ast_strlen_zero(args->channel_id)) {
1497  response, 400, "Bad Request",
1498  "Channel ID is required");
1499  return;
1500  }
1501 
1503  if (!channel) {
1505  response, 404, "Channel Not Found",
1506  "Provided channel was not found");
1507  return;
1508  }
1509 
1510  /* You may be tempted to lock the channel you're about to read from. You
1511  * would be wrong. Some dialplan functions put the channel into
1512  * autoservice, which deadlocks if the channel is already locked.
1513  * ast_str_retrieve_variable() does its own locking, and the dialplan
1514  * functions need to as well. We should be fine without the lock.
1515  */
1516 
1517  if (args->variable[strlen(args->variable) - 1] == ')') {
1518  if (ast_func_read2(channel, args->variable, &value, 0)) {
1520  response, 500, "Error With Function",
1521  "Unable to read provided function");
1522  return;
1523  }
1524  } else {
1525  if (!ast_str_retrieve_variable(&value, 0, channel, NULL, args->variable)) {
1527  response, 404, "Variable Not Found",
1528  "Provided variable was not found");
1529  return;
1530  }
1531  }
1532 
1533  if (!(json = ast_json_pack("{s: s}", "value", S_OR(ast_str_buffer(value), "")))) {
1535  return;
1536  }
1537 
1538  ast_ari_response_ok(response, ast_json_ref(json));
1539 }
Main Channel structure associated with a channel.
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
executes a read operation on a function
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_assert(a)
Definition: utils.h:695
Definition: muted.c:95
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
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
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#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
const char * ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
Abstract JSON element (object, array, string, int, ...).
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

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

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 907 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), AST_CAUSE_NORMAL, ast_channel_get_by_name(), ast_channel_hangupcause_set(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, ast_strlen_zero, ast_ari_channels_hangup_args::channel_id, convert_reason_to_hangup_code(), NULL, RAII_VAR, ast_ari_channels_hangup_args::reason, and ast_ari_channels_hangup_args::reason_code.

Referenced by ast_ari_channels_hangup_cb().

910 {
911  RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup);
912  int cause;
913 
914  chan = ast_channel_get_by_name(args->channel_id);
915  if (chan == NULL) {
917  response, 404, "Not Found",
918  "Channel not found");
919  return;
920  }
921 
922  if (!ast_strlen_zero(args->reason) && !ast_strlen_zero(args->reason_code)) {
923  ast_ari_response_error(response, 400, "Bad Request",
924  "The reason and reason_code can't both be specified");
925  return;
926  }
927 
928  if (!ast_strlen_zero(args->reason_code)) {
929  /* reason_code allows any hangup code */
930  if (sscanf(args->reason_code, "%30d", &cause) != 1) {
932  response, 400, "Invalid Reason Code",
933  "Invalid reason for hangup reason code provided");
934  return;
935  }
936  } else if (!ast_strlen_zero(args->reason)) {
937  /* reason allows only listed hangup reason */
938  cause = convert_reason_to_hangup_code(args->reason);
939  if (cause == -1) {
941  response, 400, "Invalid Reason",
942  "Invalid reason for hangup reason provided");
943  return;
944  }
945  } else {
946  /* not specified. set default hangup */
947  cause = AST_CAUSE_NORMAL;
948  }
949 
950  ast_channel_hangupcause_set(chan, cause);
952 
953  ast_ari_response_no_content(response);
954 }
Main Channel structure associated with a channel.
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
static int convert_reason_to_hangup_code(const char *reason)
Return the corresponded hangup code of the given reason.
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
int ast_softhangup(struct ast_channel *chan, int reason)
Softly hangup up a channel.
Definition: channel.c:2476
#define AST_CAUSE_NORMAL
Definition: causes.h:150
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

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

void ast_ari_channels_hold ( struct ast_variable headers,
struct ast_ari_channels_hold_args args,
struct ast_ari_response response 
)

Hold a channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 514 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_hold_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_hold().

Referenced by ast_ari_channels_hold_cb().

517 {
518  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
519 
520  control = find_control(response, args->channel_id);
521  if (control == NULL) {
522  /* Response filled in by find_control */
523  return;
524  }
525 
526  if (channel_state_invalid(control, response)) {
527  return;
528  }
529 
530  stasis_app_control_hold(control);
531 
532  ast_ari_response_no_content(response);
533 }
void stasis_app_control_hold(struct stasis_app_control *control)
Place the channel associated with the control on hold.
Definition: control.c:748
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_ari_channels_list()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 956 of file resource_channels.c.

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_ari_response_alloc_failed(), ast_ari_response_ok(), ast_channel_cache_all(), ast_channel_snapshot_to_json(), ast_json_array_append(), ast_json_array_create(), ast_json_ref(), ast_json_unref(), stasis_message_sanitizer::channel_snapshot, NULL, RAII_VAR, and stasis_app_get_sanitizer().

Referenced by ast_ari_channels_list_cb().

959 {
960  RAII_VAR(struct ao2_container *, snapshots, NULL, ao2_cleanup);
961  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
962  struct ao2_iterator i;
963  void *obj;
965 
966  snapshots = ast_channel_cache_all();
967 
968  json = ast_json_array_create();
969  if (!json) {
971  return;
972  }
973 
974  i = ao2_iterator_init(snapshots, 0);
975  while ((obj = ao2_iterator_next(&i))) {
976  struct ast_channel_snapshot *snapshot = obj;
977  int r;
978 
979  if (sanitize && sanitize->channel_snapshot
980  && sanitize->channel_snapshot(snapshot)) {
981  ao2_ref(snapshot, -1);
982  continue;
983  }
984 
986  json, ast_channel_snapshot_to_json(snapshot, NULL));
987  if (r != 0) {
990  ao2_ref(snapshot, -1);
991  return;
992  }
993  ao2_ref(snapshot, -1);
994  }
996 
997  ast_ari_response_ok(response, ast_json_ref(json));
998 }
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int(* channel_snapshot)(const struct ast_channel_snapshot *snapshot)
Callback which determines whether a channel should be sanitized from a message based on the channel&#39;s...
Definition: stasis.h:221
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
Structure representing a snapshot of channel state.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#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
Structure containing callbacks for Stasis message sanitization.
Definition: stasis.h:200
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * ast_channel_cache_all(void)
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:368
struct stasis_message_sanitizer * stasis_app_get_sanitizer(void)
Get the Stasis message sanitizer for app_stasis applications.
Definition: res_stasis.c:2264
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).
Generic container type.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.

◆ ast_ari_channels_move()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 256 of file resource_channels.c.

References ao2_cleanup, ast_ari_channels_move_args::app, ast_ari_channels_move_args::app_args, ast_ari_response_error(), ast_ari_response_no_content(), ast_ari_channels_move_args::channel_id, find_control(), NULL, RAII_VAR, and stasis_app_control_move().

Referenced by ast_ari_channels_move_cb().

259 {
260  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
261 
262  control = find_control(response, args->channel_id);
263  if (!control) {
264  return;
265  }
266 
267  if (stasis_app_control_move(control, args->app, args->app_args)) {
268  ast_ari_response_error(response, 500, "Internal Server Error",
269  "Failed to switch Stasis applications");
270  return;
271  }
272 
273  ast_ari_response_no_content(response);
274 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
int stasis_app_control_move(struct stasis_app_control *control, const char *app_name, const char *app_args)
Exit res_stasis and move to another Stasis application.
Definition: control.c:451
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

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

void ast_ari_channels_mute ( struct ast_variable headers,
struct ast_ari_channels_mute_args args,
struct ast_ari_response response 
)

Mute a channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 403 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), AST_FRAME_VOICE, AST_MUTE_DIRECTION_READ, AST_MUTE_DIRECTION_WRITE, ast_strlen_zero, ast_ari_channels_mute_args::channel_id, channel_state_invalid(), ast_ari_channels_mute_args::direction, find_control(), NULL, RAII_VAR, and stasis_app_control_mute().

Referenced by ast_ari_channels_mute_cb().

406 {
407  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
408  unsigned int direction = 0;
409  enum ast_frame_type frametype = AST_FRAME_VOICE;
410 
411  control = find_control(response, args->channel_id);
412  if (control == NULL) {
413  return;
414  }
415 
416  if (channel_state_invalid(control, response)) {
417  return;
418  }
419 
420  if (ast_strlen_zero(args->direction)) {
422  response, 400, "Bad Request",
423  "Direction is required");
424  return;
425  }
426 
427  if (!strcmp(args->direction, "in")) {
428  direction = AST_MUTE_DIRECTION_READ;
429  } else if (!strcmp(args->direction, "out")) {
430  direction = AST_MUTE_DIRECTION_WRITE;
431  } else if (!strcmp(args->direction, "both")) {
433  } else {
435  response, 400, "Bad Request",
436  "Invalid direction specified");
437  return;
438  }
439 
440  stasis_app_control_mute(control, direction, frametype);
441 
442  ast_ari_response_no_content(response);
443 }
int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
Mute the channel associated with this control.
Definition: control.c:631
#define NULL
Definition: resample.c:96
#define AST_MUTE_DIRECTION_WRITE
Definition: channel.h:4938
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_MUTE_DIRECTION_READ
Definition: channel.h:4937
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
ast_frame_type
Frame types.
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
direction

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

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

The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1433 of file resource_channels.c.

References ast_ari_channels_originate_args::app, ast_ari_channels_originate_args::app_args, ari_channels_handle_originate_with_id(), ast_ari_channels_originate_parse_body(), ast_channel_cleanup, ast_json_object_get(), ast_variables_destroy(), 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, json_to_ast_variables(), ast_ari_channels_originate_args::label, NULL, ast_ari_channels_originate_args::originator, ast_ari_channels_originate_args::other_channel_id, ast_ari_channels_originate_args::priority, ast_ari_channels_originate_args::timeout, and ast_ari_channels_originate_args::variables.

Referenced by ast_ari_channels_originate_cb().

1436 {
1437  struct ast_variable *variables = NULL;
1438  struct ast_channel *chan;
1439 
1440  /* Parse any query parameters out of the body parameter */
1441  if (args->variables) {
1442  struct ast_json *json_variables;
1443 
1445  json_variables = ast_json_object_get(args->variables, "variables");
1446  if (json_variables
1447  && json_to_ast_variables(response, json_variables, &variables)) {
1448  return;
1449  }
1450  }
1451 
1453  args->endpoint,
1454  args->extension,
1455  args->context,
1456  args->priority,
1457  args->label,
1458  args->app,
1459  args->app_args,
1460  args->caller_id,
1461  args->timeout,
1462  variables,
1463  args->channel_id,
1464  args->other_channel_id,
1465  args->originator,
1466  args->formats,
1467  response);
1468  ast_channel_cleanup(chan);
1469  ast_variables_destroy(variables);
1470 }
Main Channel structure associated with a channel.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Structure for variables, used for configurations and for channel variables.
static struct ast_channel * ari_channels_handle_originate_with_id(const char *args_endpoint, const char *args_extension, const char *args_context, long args_priority, const char *args_label, const char *args_app, const char *args_app_args, const char *args_caller_id, int args_timeout, struct ast_variable *variables, const char *args_channel_id, const char *args_other_channel_id, const char *args_originator, const char *args_formats, struct ast_ari_response *response)
#define NULL
Definition: resample.c:96
static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
int ast_ari_channels_originate_parse_body(struct ast_json *body, struct ast_ari_channels_originate_args *args)
Body parsing function for /channels.
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
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_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()

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

The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1394 of file resource_channels.c.

References ast_ari_channels_originate_with_id_args::app, ast_ari_channels_originate_with_id_args::app_args, ari_channels_handle_originate_with_id(), ast_ari_channels_originate_with_id_parse_body(), ast_channel_cleanup, ast_json_object_get(), ast_variables_destroy(), 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, json_to_ast_variables(), ast_ari_channels_originate_with_id_args::label, 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_channels_originate_with_id_args::timeout, and ast_ari_channels_originate_with_id_args::variables.

Referenced by ast_ari_channels_originate_with_id_cb().

1397 {
1398  struct ast_variable *variables = NULL;
1399  struct ast_channel *chan;
1400 
1401  /* Parse any query parameters out of the body parameter */
1402  if (args->variables) {
1403  struct ast_json *json_variables;
1404 
1406  json_variables = ast_json_object_get(args->variables, "variables");
1407  if (json_variables
1408  && json_to_ast_variables(response, json_variables, &variables)) {
1409  return;
1410  }
1411  }
1412 
1414  args->endpoint,
1415  args->extension,
1416  args->context,
1417  args->priority,
1418  args->label,
1419  args->app,
1420  args->app_args,
1421  args->caller_id,
1422  args->timeout,
1423  variables,
1424  args->channel_id,
1425  args->other_channel_id,
1426  args->originator,
1427  args->formats,
1428  response);
1429  ast_channel_cleanup(chan);
1430  ast_variables_destroy(variables);
1431 }
Main Channel structure associated with a channel.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Structure for variables, used for configurations and for channel variables.
static struct ast_channel * ari_channels_handle_originate_with_id(const char *args_endpoint, const char *args_extension, const char *args_context, long args_priority, const char *args_label, const char *args_app, const char *args_app_args, const char *args_caller_id, int args_timeout, struct ast_variable *variables, const char *args_channel_id, const char *args_other_channel_id, const char *args_originator, const char *args_formats, struct ast_ari_response *response)
#define NULL
Definition: resample.c:96
static int json_to_ast_variables(struct ast_ari_response *response, struct ast_json *json_variables, struct ast_variable **variables)
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
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}.
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_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()

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.

The media URI may be any of a number of URI's. Currently sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.)

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 718 of file resource_channels.c.

References ari_channels_handle_play(), ast_ari_channels_play_args::channel_id, 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().

721 {
723  args->channel_id,
724  args->media,
725  args->media_count,
726  args->lang,
727  args->offsetms,
728  args->skipms,
729  args->playback_id,
730  response);
731 }
static void ari_channels_handle_play(const char *args_channel_id, const char **args_media, size_t args_media_count, const char *args_lang, int args_offsetms, int args_skipms, const char *args_playback_id, struct ast_ari_response *response)

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

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.

The media URI may be any of a number of URI's. Currently sound:, recording:, number:, digits:, characters:, and tone: URI's are supported. This operation creates a playback resource that can be used to control the playback of media (pause, rewind, fast forward, etc.)

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 733 of file resource_channels.c.

References ari_channels_handle_play(), ast_ari_channels_play_with_id_args::channel_id, 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, ast_ari_channels_play_with_id_args::playback_id, and ast_ari_channels_play_with_id_args::skipms.

Referenced by ast_ari_channels_play_with_id_cb().

736 {
738  args->channel_id,
739  args->media,
740  args->media_count,
741  args->lang,
742  args->offsetms,
743  args->skipms,
744  args->playback_id,
745  response);
746 }
static void ari_channels_handle_play(const char *args_channel_id, const char **args_media, size_t args_media_count, const char *args_lang, int args_offsetms, int args_skipms, const char *args_playback_id, struct ast_ari_response *response)

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

void ast_ari_channels_record ( struct ast_variable headers,
struct ast_ari_channels_record_args args,
struct ast_ari_response response 
)

Start a recording.

Record audio from a channel. Note that this will not capture audio sent to the channel. The bridge itself has a record feature if that's what you want.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 748 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_created(), ast_ari_response_error(), ast_asprintf, ast_assert, ast_free, ast_get_format_for_file_ext(), ast_log, ast_malloc, AST_RECORD_IF_EXISTS_ERROR, ast_string_field_build, ast_uri_encode(), ast_uri_http, ast_ari_channels_record_args::beep, ast_ari_channels_record_args::channel_id, errno, find_control(), ast_ari_channels_record_args::format, ast_ari_channels_record_args::if_exists, LOG_WARNING, ast_ari_channels_record_args::max_duration_seconds, ast_ari_channels_record_args::max_silence_seconds, ast_ari_channels_record_args::name, NULL, options, RAII_VAR, stasis_app_control_record(), stasis_app_recording_if_exists_parse(), stasis_app_recording_options_create(), STASIS_APP_RECORDING_TERMINATE_INVALID, stasis_app_recording_termination_parse(), stasis_app_recording_to_json(), and ast_ari_channels_record_args::terminate_on.

Referenced by ast_ari_channels_record_cb().

751 {
752  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
753  RAII_VAR(struct stasis_app_recording *, recording, NULL, ao2_cleanup);
754  RAII_VAR(char *, recording_url, NULL, ast_free);
755  struct ast_json *json;
757  ao2_cleanup);
758  RAII_VAR(char *, uri_encoded_name, NULL, ast_free);
759  size_t uri_name_maxlen;
760 
761  ast_assert(response != NULL);
762 
763  if (args->max_duration_seconds < 0) {
765  response, 400, "Bad Request",
766  "max_duration_seconds cannot be negative");
767  return;
768  }
769 
770  if (args->max_silence_seconds < 0) {
772  response, 400, "Bad Request",
773  "max_silence_seconds cannot be negative");
774  return;
775  }
776 
777  control = find_control(response, args->channel_id);
778  if (control == NULL) {
779  /* Response filled in by find_control */
780  return;
781  }
782 
784  if (options == NULL) {
786  response, 500, "Internal Server Error",
787  "Out of memory");
788  }
789  ast_string_field_build(options, target, "channel:%s", args->channel_id);
790  options->max_silence_seconds = args->max_silence_seconds;
791  options->max_duration_seconds = args->max_duration_seconds;
792  options->terminate_on =
794  options->if_exists =
796  options->beep = args->beep;
797 
798  if (options->terminate_on == STASIS_APP_RECORDING_TERMINATE_INVALID) {
800  response, 400, "Bad Request",
801  "terminateOn invalid");
802  return;
803  }
804 
805  if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) {
807  response, 400, "Bad Request",
808  "ifExists invalid");
809  return;
810  }
811 
812  if (!ast_get_format_for_file_ext(options->format)) {
814  response, 422, "Unprocessable Entity",
815  "specified format is unknown on this system");
816  return;
817  }
818 
819  recording = stasis_app_control_record(control, options);
820  if (recording == NULL) {
821  switch(errno) {
822  case EINVAL:
823  /* While the arguments are invalid, we should have
824  * caught them prior to calling record.
825  */
827  response, 500, "Internal Server Error",
828  "Error parsing request");
829  break;
830  case EEXIST:
831  ast_ari_response_error(response, 409, "Conflict",
832  "Recording '%s' already exists and can not be overwritten",
833  args->name);
834  break;
835  case ENOMEM:
837  response, 500, "Internal Server Error",
838  "Out of memory");
839  break;
840  case EPERM:
842  response, 400, "Bad Request",
843  "Recording name invalid");
844  break;
845  default:
847  "Unrecognized recording error: %s\n",
848  strerror(errno));
850  response, 500, "Internal Server Error",
851  "Internal Server Error");
852  break;
853  }
854  return;
855  }
856 
857  uri_name_maxlen = strlen(args->name) * 3;
858  uri_encoded_name = ast_malloc(uri_name_maxlen);
859  if (!uri_encoded_name) {
861  response, 500, "Internal Server Error",
862  "Out of memory");
863  return;
864  }
865  ast_uri_encode(args->name, uri_encoded_name, uri_name_maxlen,
866  ast_uri_http);
867 
868  if (ast_asprintf(&recording_url, "/recordings/live/%s",
869  uri_encoded_name) == -1) {
870  recording_url = NULL;
872  response, 500, "Internal Server Error",
873  "Out of memory");
874  return;
875  }
876 
877  json = stasis_app_recording_to_json(recording);
878  if (!json) {
880  response, 500, "Internal Server Error",
881  "Out of memory");
882  return;
883  }
884 
885  ast_ari_response_created(response, recording_url, json);
886 }
void ast_ari_response_created(struct ast_ari_response *response, const char *url, struct ast_json *message)
Fill in a Created (201) ast_ari_response.
Definition: res_ari.c:305
#define LOG_WARNING
Definition: logger.h:274
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition: main/utils.c:577
#define ast_assert(a)
Definition: utils.h:695
char stasis_app_recording_termination_parse(const char *str)
Parse a string into the recording termination enum.
#define NULL
Definition: resample.c:96
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition: astmm.h:269
struct ast_json * stasis_app_recording_to_json(const struct stasis_app_recording *recording)
Construct a JSON model of a recording.
#define ast_log
Definition: astobj2.c:42
#define STASIS_APP_RECORDING_TERMINATE_INVALID
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
enum ast_record_if_exists stasis_app_recording_if_exists_parse(const char *str)
Parse a string into the if_exists enum.
int errno
#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 stasis_app_recording_options * stasis_app_recording_options_create(const char *name, const char *format)
Allocate a recording options object.
struct ast_format * ast_get_format_for_file_ext(const char *file_ext)
Get the ast_format associated with the given file extension.
Definition: file.c:1938
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
Definition: stringfields.h:550
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).
const struct ast_flags ast_uri_http
Definition: main/utils.c:573
static struct test_options options
struct stasis_app_recording * stasis_app_control_record(struct stasis_app_control *control, struct stasis_app_recording_options *options)
Record media from a channel.

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

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 276 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), ast_channel_snapshot_get_latest(), ast_strdupa, ast_strlen_zero, ast_ari_channels_redirect_args::channel_id, channel_state_invalid(), ast_ari_channels_redirect_args::endpoint, find_control(), NULL, RAII_VAR, and stasis_app_control_redirect().

Referenced by ast_ari_channels_redirect_cb().

279 {
280  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
281  RAII_VAR(struct ast_channel_snapshot *, chan_snapshot, NULL, ao2_cleanup);
282  char *tech;
283  char *resource;
284  int tech_len;
285 
286  control = find_control(response, args->channel_id);
287  if (!control) {
288  return;
289  }
290 
291  if (channel_state_invalid(control, response)) {
292  return;
293  }
294 
295  if (ast_strlen_zero(args->endpoint)) {
296  ast_ari_response_error(response, 400, "Not Found",
297  "Required parameter 'endpoint' not provided.");
298  return;
299  }
300 
301  tech = ast_strdupa(args->endpoint);
302  if (!(resource = strchr(tech, '/')) || !(tech_len = resource - tech)) {
303  ast_ari_response_error(response, 422, "Unprocessable Entity",
304  "Endpoint parameter '%s' does not contain tech/resource", args->endpoint);
305  return;
306  }
307 
308  *resource++ = '\0';
309  if (ast_strlen_zero(resource)) {
310  ast_ari_response_error(response, 422, "Unprocessable Entity",
311  "No resource provided in endpoint parameter '%s'", args->endpoint);
312  return;
313  }
314 
315  chan_snapshot = ast_channel_snapshot_get_latest(args->channel_id);
316  if (!chan_snapshot) {
317  ast_ari_response_error(response, 500, "Internal Server Error",
318  "Unable to find channel snapshot for '%s'", args->channel_id);
319  return;
320  }
321 
322  if (strncasecmp(chan_snapshot->base->type, tech, tech_len)) {
323  ast_ari_response_error(response, 422, "Unprocessable Entity",
324  "Endpoint technology '%s' does not match channel technology '%s'",
325  tech, chan_snapshot->base->type);
326  return;
327  }
328 
329  if (stasis_app_control_redirect(control, resource)) {
330  ast_ari_response_error(response, 500, "Internal Server Error",
331  "Failed to redirect channel");
332  return;
333  }
334 
335  ast_ari_response_no_content(response);
336 }
Structure representing a snapshot of channel state.
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint)
Redirect a channel in res_stasis to a particular endpoint.
Definition: control.c:500
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object...
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

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

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 363 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_ring_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_ring().

Referenced by ast_ari_channels_ring_cb().

366 {
367  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
368 
369  control = find_control(response, args->channel_id);
370  if (control == NULL) {
371  return;
372  }
373 
374  if (channel_state_invalid(control, response)) {
375  return;
376  }
377 
378  stasis_app_control_ring(control);
379 
380  ast_ari_response_no_content(response);
381 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
int stasis_app_control_ring(struct stasis_app_control *control)
Indicate ringing to the channel associated with this control.
Definition: control.c:592
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_ari_channels_ring_stop()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 383 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_ring_stop_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_ring_stop().

Referenced by ast_ari_channels_ring_stop_cb().

386 {
387  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
388 
389  control = find_control(response, args->channel_id);
390  if (control == NULL) {
391  return;
392  }
393 
394  if (channel_state_invalid(control, response)) {
395  return;
396  }
397 
399 
400  ast_ari_response_no_content(response);
401 }
int stasis_app_control_ring_stop(struct stasis_app_control *control)
Stop locally generated ringing on the channel associated with this control.
Definition: control.c:607
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_ari_channels_rtpstatistics()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 2028 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_ok(), ast_channel_cleanup, ast_channel_get_by_name(), ast_channel_lock, ast_channel_tech(), ast_channel_unlock, ast_rtp_instance_get_glue(), ast_rtp_instance_get_stats_all_json(), ast_ari_channels_rtpstatistics_args::channel_id, ast_rtp_glue::get_rtp_info, NULL, RAII_VAR, and ast_channel_tech::type.

Referenced by ast_ari_channels_rtpstatistics_cb().

2031 {
2032  RAII_VAR(struct ast_channel *, chan, NULL, ast_channel_cleanup);
2033  RAII_VAR(struct ast_rtp_instance *, rtp, NULL, ao2_cleanup);
2034  struct ast_json *j_res;
2035  const struct ast_channel_tech *tech;
2036  struct ast_rtp_glue *glue;
2037 
2038  chan = ast_channel_get_by_name(args->channel_id);
2039  if (!chan) {
2040  ast_ari_response_error(response, 404, "Not Found",
2041  "Channel not found");
2042  return;
2043  }
2044 
2045  ast_channel_lock(chan);
2046  tech = ast_channel_tech(chan);
2047  if (!tech) {
2048  ast_channel_unlock(chan);
2049  ast_ari_response_error(response, 404, "Not Found",
2050  "Channel's tech not found");
2051  return;
2052  }
2053 
2054  glue = ast_rtp_instance_get_glue(tech->type);
2055  if (!glue) {
2056  ast_channel_unlock(chan);
2057  ast_ari_response_error(response, 403, "Forbidden",
2058  "Unsupported channel type");
2059  return;
2060  }
2061 
2062  glue->get_rtp_info(chan, &rtp);
2063  if (!rtp) {
2064  ast_channel_unlock(chan);
2065  ast_ari_response_error(response, 404, "Not Found",
2066  "RTP info not found");
2067  return;
2068  }
2069 
2071  if (!j_res) {
2072  ast_channel_unlock(chan);
2073  ast_ari_response_error(response, 404, "Not Found",
2074  "Statistics not found");
2075  return;
2076  }
2077 
2078  ast_channel_unlock(chan);
2079  ast_ari_response_ok(response, j_res);
2080 
2081  return;
2082 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Main Channel structure associated with a channel.
const char *const type
Definition: channel.h:630
#define NULL
Definition: resample.c:96
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:729
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition: channel.h:2992
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:629
#define ast_channel_unlock(chan)
Definition: channel.h:2946
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
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
Abstract JSON element (object, array, string, int, ...).
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2206
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
struct ast_json * ast_rtp_instance_get_stats_all_json(struct ast_rtp_instance *instance)
Retrieve statistics about an RTP instance in json format.
Definition: rtp_engine.c:4019

◆ ast_ari_channels_send_dtmf()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 487 of file resource_channels.c.

References ast_ari_channels_send_dtmf_args::after, ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), ast_strlen_zero, ast_ari_channels_send_dtmf_args::before, ast_ari_channels_send_dtmf_args::between, ast_ari_channels_send_dtmf_args::channel_id, channel_state_invalid(), ast_ari_channels_send_dtmf_args::dtmf, ast_ari_channels_send_dtmf_args::duration, find_control(), NULL, RAII_VAR, and stasis_app_control_dtmf().

Referenced by ast_ari_channels_send_dtmf_cb().

490 {
491  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
492 
493  control = find_control(response, args->channel_id);
494  if (control == NULL) {
495  return;
496  }
497 
498  if (channel_state_invalid(control, response)) {
499  return;
500  }
501 
502  if (ast_strlen_zero(args->dtmf)) {
504  response, 400, "Bad Request",
505  "DTMF is required");
506  return;
507  }
508 
509  stasis_app_control_dtmf(control, args->dtmf, args->before, args->between, args->duration, args->after);
510 
511  ast_ari_response_no_content(response);
512 }
int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after)
Send DTMF to the channel associated with this control.
Definition: control.c:565
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

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

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1541 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), ast_assert, ast_strlen_zero, ast_ari_channels_set_channel_var_args::channel_id, find_control(), NULL, RAII_VAR, stasis_app_control_set_channel_var(), 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().

1544 {
1545  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
1546 
1547  ast_assert(response != NULL);
1548 
1549  if (ast_strlen_zero(args->variable)) {
1551  response, 400, "Bad Request",
1552  "Variable name is required");
1553  return;
1554  }
1555 
1556  control = find_control(response, args->channel_id);
1557  if (control == NULL) {
1558  /* response filled in by find_control */
1559  return;
1560  }
1561 
1562  if (stasis_app_control_set_channel_var(control, args->variable, args->value)) {
1564  response, 400, "Bad Request",
1565  "Failed to execute function");
1566  return;
1567  }
1568 
1569  ast_ari_response_no_content(response);
1570 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
void ast_ari_response_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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value)
Set a variable on the channel associated with this control to value.
Definition: control.c:711

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

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.

Snoop (spy/whisper) on a specific channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1651 of file resource_channels.c.

References ast_ari_channels_snoop_channel_args::app, ast_ari_channels_snoop_channel_args::app_args, ari_channels_handle_snoop_channel(), ast_ari_channels_snoop_channel_args::channel_id, 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().

1654 {
1656  args->channel_id,
1657  args->spy,
1658  args->whisper,
1659  args->app,
1660  args->app_args,
1661  args->snoop_id,
1662  response);
1663 }
static void ari_channels_handle_snoop_channel(const char *args_channel_id, const char *args_spy, const char *args_whisper, const char *args_app, const char *args_app_args, const char *args_snoop_id, struct ast_ari_response *response)

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

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.

Snoop (spy/whisper) on a specific channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1665 of file resource_channels.c.

References ast_ari_channels_snoop_channel_with_id_args::app, ast_ari_channels_snoop_channel_with_id_args::app_args, ari_channels_handle_snoop_channel(), ast_ari_channels_snoop_channel_with_id_args::channel_id, ast_ari_channels_snoop_channel_with_id_args::snoop_id, 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().

1668 {
1670  args->channel_id,
1671  args->spy,
1672  args->whisper,
1673  args->app,
1674  args->app_args,
1675  args->snoop_id,
1676  response);
1677 }
static void ari_channels_handle_snoop_channel(const char *args_channel_id, const char *args_spy, const char *args_whisper, const char *args_app, const char *args_app_args, const char *args_snoop_id, struct ast_ari_response *response)

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

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.

Using media operations such as /play on a channel playing MOH in this manner will suspend MOH without resuming automatically. If continuing music on hold is desired, the stasis application must reinitiate music on hold.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 556 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_start_moh_args::channel_id, channel_state_invalid(), find_control(), ast_ari_channels_start_moh_args::moh_class, NULL, RAII_VAR, and stasis_app_control_moh_start().

Referenced by ast_ari_channels_start_moh_cb().

559 {
560  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
561 
562  control = find_control(response, args->channel_id);
563  if (control == NULL) {
564  /* Response filled in by find_control */
565  return;
566  }
567 
568  if (channel_state_invalid(control, response)) {
569  return;
570  }
571 
572  stasis_app_control_moh_start(control, args->moh_class);
573  ast_ari_response_no_content(response);
574 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class)
Play music on hold to a channel (does not affect hold status)
Definition: control.c:780

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

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.

Using media operations such as /play on a channel playing silence in this manner will suspend silence without resuming automatically.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 596 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_start_silence_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_silence_start().

Referenced by ast_ari_channels_start_silence_cb().

599 {
600  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
601 
602  control = find_control(response, args->channel_id);
603  if (control == NULL) {
604  /* Response filled in by find_control */
605  return;
606  }
607 
608  if (channel_state_invalid(control, response)) {
609  return;
610  }
611 
613  ast_ari_response_no_content(response);
614 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void stasis_app_control_silence_start(struct stasis_app_control *control)
Start playing silence to a channel.
Definition: control.c:832

◆ ast_ari_channels_stop_moh()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 576 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_stop_moh_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_moh_stop().

Referenced by ast_ari_channels_stop_moh_cb().

579 {
580  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
581 
582  control = find_control(response, args->channel_id);
583  if (control == NULL) {
584  /* Response filled in by find_control */
585  return;
586  }
587 
588  if (channel_state_invalid(control, response)) {
589  return;
590  }
591 
593  ast_ari_response_no_content(response);
594 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void stasis_app_control_moh_stop(struct stasis_app_control *control)
Stop playing music on hold to a channel (does not affect hold status)
Definition: control.c:798

◆ ast_ari_channels_stop_silence()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 616 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_stop_silence_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_silence_stop().

Referenced by ast_ari_channels_stop_silence_cb().

619 {
620  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
621 
622  control = find_control(response, args->channel_id);
623  if (control == NULL) {
624  /* Response filled in by find_control */
625  return;
626  }
627 
628  if (channel_state_invalid(control, response)) {
629  return;
630  }
631 
633  ast_ari_response_no_content(response);
634 }
void stasis_app_control_silence_stop(struct stasis_app_control *control)
Stop playing silence to a channel.
Definition: control.c:855
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_ari_channels_unhold()

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.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 535 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_no_content(), ast_ari_channels_unhold_args::channel_id, channel_state_invalid(), find_control(), NULL, RAII_VAR, and stasis_app_control_unhold().

Referenced by ast_ari_channels_unhold_cb().

538 {
539  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
540 
541  control = find_control(response, args->channel_id);
542  if (control == NULL) {
543  /* Response filled in by find_control */
544  return;
545  }
546 
547  if (channel_state_invalid(control, response)) {
548  return;
549  }
550 
551  stasis_app_control_unhold(control);
552 
553  ast_ari_response_no_content(response);
554 }
#define NULL
Definition: resample.c:96
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
void stasis_app_control_unhold(struct stasis_app_control *control)
Remove the channel associated with the control from hold.
Definition: control.c:761
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_ari_channels_unmute()

void ast_ari_channels_unmute ( struct ast_variable headers,
struct ast_ari_channels_unmute_args args,
struct ast_ari_response response 
)

Unmute a channel.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 445 of file resource_channels.c.

References ao2_cleanup, ast_ari_response_error(), ast_ari_response_no_content(), AST_FRAME_VOICE, AST_MUTE_DIRECTION_READ, AST_MUTE_DIRECTION_WRITE, ast_strlen_zero, ast_ari_channels_unmute_args::channel_id, channel_state_invalid(), ast_ari_channels_unmute_args::direction, find_control(), NULL, RAII_VAR, and stasis_app_control_unmute().

Referenced by ast_ari_channels_unmute_cb().

448 {
449  RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
450  unsigned int direction = 0;
451  enum ast_frame_type frametype = AST_FRAME_VOICE;
452 
453  control = find_control(response, args->channel_id);
454  if (control == NULL) {
455  return;
456  }
457 
458  if (channel_state_invalid(control, response)) {
459  return;
460  }
461 
462  if (ast_strlen_zero(args->direction)) {
464  response, 400, "Bad Request",
465  "Direction is required");
466  return;
467  }
468 
469  if (!strcmp(args->direction, "in")) {
470  direction = AST_MUTE_DIRECTION_READ;
471  } else if (!strcmp(args->direction, "out")) {
472  direction = AST_MUTE_DIRECTION_WRITE;
473  } else if (!strcmp(args->direction, "both")) {
475  } else {
477  response, 400, "Bad Request",
478  "Invalid direction specified");
479  return;
480  }
481 
482  stasis_app_control_unmute(control, direction, frametype);
483 
484  ast_ari_response_no_content(response);
485 }
int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype)
Unmute the channel associated with this control.
Definition: control.c:659
#define NULL
Definition: resample.c:96
#define AST_MUTE_DIRECTION_WRITE
Definition: channel.h:4938
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_MUTE_DIRECTION_READ
Definition: channel.h:4937
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
ast_frame_type
Frame types.
static int channel_state_invalid(struct stasis_app_control *control, struct ast_ari_response *response)
Ensure channel is in a state that allows operation to be performed.
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_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
static struct stasis_app_control * find_control(struct ast_ari_response *response, const char *channel_id)
Finds the control object for a channel, filling the response with an error, if appropriate.
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
direction

◆ 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, ...).