Asterisk - The Open Source Telephony Project GIT-master-b023714
Loading...
Searching...
No Matches
Data Structures | Functions
resource_bridges.h File Reference

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

#include "asterisk/ari.h"
Include dependency graph for resource_bridges.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_bridges_add_channel_args
 
struct  ast_ari_bridges_clear_video_source_args
 
struct  ast_ari_bridges_create_args
 
struct  ast_ari_bridges_create_with_id_args
 
struct  ast_ari_bridges_destroy_args
 
struct  ast_ari_bridges_get_args
 
struct  ast_ari_bridges_list_args
 
struct  ast_ari_bridges_play_args
 
struct  ast_ari_bridges_play_with_id_args
 
struct  ast_ari_bridges_record_args
 
struct  ast_ari_bridges_remove_channel_args
 
struct  ast_ari_bridges_set_video_source_args
 
struct  ast_ari_bridges_start_moh_args
 
struct  ast_ari_bridges_stop_moh_args
 

Functions

void ast_ari_bridges_add_channel (struct ast_variable *headers, struct ast_ari_bridges_add_channel_args *args, struct ast_ari_response *response)
 Add a channel to a bridge.
 
int ast_ari_bridges_add_channel_parse_body (struct ast_json *body, struct ast_ari_bridges_add_channel_args *args)
 Body parsing function for /bridges/{bridgeId}/addChannel.
 
void ast_ari_bridges_clear_video_source (struct ast_variable *headers, struct ast_ari_bridges_clear_video_source_args *args, struct ast_ari_response *response)
 Removes any explicit video source in a multi-party mixing bridge. This operation has no effect on bridges with two or fewer participants. When no explicit video source is set, talk detection will be used to determine the active video stream.
 
void ast_ari_bridges_create (struct ast_variable *headers, struct ast_ari_bridges_create_args *args, struct ast_ari_response *response)
 Create a new bridge.
 
int ast_ari_bridges_create_parse_body (struct ast_json *body, struct ast_ari_bridges_create_args *args)
 Body parsing function for /bridges.
 
void ast_ari_bridges_create_with_id (struct ast_variable *headers, struct ast_ari_bridges_create_with_id_args *args, struct ast_ari_response *response)
 Create a new bridge.
 
int ast_ari_bridges_create_with_id_parse_body (struct ast_json *body, struct ast_ari_bridges_create_with_id_args *args)
 Body parsing function for /bridges/{bridgeId}.
 
void ast_ari_bridges_destroy (struct ast_variable *headers, struct ast_ari_bridges_destroy_args *args, struct ast_ari_response *response)
 Shut down a bridge.
 
void ast_ari_bridges_get (struct ast_variable *headers, struct ast_ari_bridges_get_args *args, struct ast_ari_response *response)
 Get bridge details.
 
void ast_ari_bridges_list (struct ast_variable *headers, struct ast_ari_bridges_list_args *args, struct ast_ari_response *response)
 List all active bridges in Asterisk.
 
void ast_ari_bridges_play (struct ast_variable *headers, struct ast_ari_bridges_play_args *args, struct ast_ari_response *response)
 Start playback of media on a bridge.
 
int ast_ari_bridges_play_parse_body (struct ast_json *body, struct ast_ari_bridges_play_args *args)
 Body parsing function for /bridges/{bridgeId}/play.
 
void ast_ari_bridges_play_with_id (struct ast_variable *headers, struct ast_ari_bridges_play_with_id_args *args, struct ast_ari_response *response)
 Start playback of media on a bridge.
 
int ast_ari_bridges_play_with_id_parse_body (struct ast_json *body, struct ast_ari_bridges_play_with_id_args *args)
 Body parsing function for /bridges/{bridgeId}/play/{playbackId}.
 
void ast_ari_bridges_record (struct ast_variable *headers, struct ast_ari_bridges_record_args *args, struct ast_ari_response *response)
 Start a recording.
 
int ast_ari_bridges_record_parse_body (struct ast_json *body, struct ast_ari_bridges_record_args *args)
 Body parsing function for /bridges/{bridgeId}/record.
 
void ast_ari_bridges_remove_channel (struct ast_variable *headers, struct ast_ari_bridges_remove_channel_args *args, struct ast_ari_response *response)
 Remove a channel from a bridge.
 
int ast_ari_bridges_remove_channel_parse_body (struct ast_json *body, struct ast_ari_bridges_remove_channel_args *args)
 Body parsing function for /bridges/{bridgeId}/removeChannel.
 
void ast_ari_bridges_set_video_source (struct ast_variable *headers, struct ast_ari_bridges_set_video_source_args *args, struct ast_ari_response *response)
 Set a channel as the video source in a multi-party mixing bridge. This operation has no effect on bridges with two or fewer participants.
 
void ast_ari_bridges_start_moh (struct ast_variable *headers, struct ast_ari_bridges_start_moh_args *args, struct ast_ari_response *response)
 Play music on hold to a bridge or change the MOH class that is playing.
 
int ast_ari_bridges_start_moh_parse_body (struct ast_json *body, struct ast_ari_bridges_start_moh_args *args)
 Body parsing function for /bridges/{bridgeId}/moh.
 
void ast_ari_bridges_stop_moh (struct ast_variable *headers, struct ast_ari_bridges_stop_moh_args *args, struct ast_ari_response *response)
 Stop playing music on hold to a bridge.
 

Detailed Description

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

Bridge resources

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

Definition in file resource_bridges.h.

Function Documentation

◆ ast_ari_bridges_add_channel()

void ast_ari_bridges_add_channel ( struct ast_variable headers,
struct ast_ari_bridges_add_channel_args args,
struct ast_ari_response response 
)

Add a channel to a bridge.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 191 of file resource_bridges.c.

194{
195 RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
196 RAII_VAR(struct control_list *, list, NULL, ao2_cleanup);
197 size_t i;
198 int has_error = 0;
199
200 if (!bridge) {
201 /* Response filled in by find_bridge() */
202 return;
203 }
204
205 list = control_list_create(response, args->channel_count, args->channel);
206 if (!list) {
207 /* Response filled in by control_list_create() */
208 return;
209 }
210
211 for (i = 0; i < list->count; ++i) {
212 stasis_app_control_clear_roles(list->controls[i]);
213 if (!ast_strlen_zero(args->role)) {
214 if (stasis_app_control_add_role(list->controls[i], args->role)) {
216 return;
217 }
218 }
219
220 /* Apply bridge features to each of the channel controls */
221 if (!stasis_app_control_bridge_features_init(list->controls[i])) {
222 stasis_app_control_absorb_dtmf_in_bridge(list->controls[i], args->absorb_dtmf);
223 stasis_app_control_mute_in_bridge(list->controls[i], args->mute);
224 stasis_app_control_inhibit_colp_in_bridge(list->controls[i], args->inhibit_connected_line_updates);
225 }
226 }
227
228 for (i = 0; i < list->count; ++i) {
229 if ((has_error = check_add_remove_channel(response, list->controls[i],
231 list->controls[i], bridge)))) {
232 break;
233 }
234 }
235
236 if (!has_error) {
238 }
239}
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:251
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition res_ari.c:237
#define ao2_cleanup(obj)
Definition astobj2.h:1934
static struct @519 args
#define NULL
Definition resample.c:96
static struct control_list * control_list_create(struct ast_ari_response *response, size_t count, const char **channels)
static struct ast_bridge * find_bridge(struct ast_ari_response *response, const char *bridge_id)
Finds a bridge, filling the response with an error, if appropriate.
static int check_add_remove_channel(struct ast_ari_response *response, struct stasis_app_control *control, enum stasis_app_control_channel_result result)
void stasis_app_control_mute_in_bridge(struct stasis_app_control *control, int mute)
Set whether audio from the channel is muted instead of passing through to the bridge.
Definition control.c:1515
int stasis_app_control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
Add a channel to the bridge.
Definition control.c:1428
void stasis_app_control_clear_roles(struct stasis_app_control *control)
Clear bridge roles currently applied to a channel controlled by a stasis app control.
Definition control.c:353
void stasis_app_control_absorb_dtmf_in_bridge(struct stasis_app_control *control, int absorb)
Set whether DTMF from the channel is absorbed instead of passing through to the bridge.
Definition control.c:1509
int stasis_app_control_add_role(struct stasis_app_control *control, const char *role)
Apply a bridge role to a channel controlled by a stasis app control.
Definition control.c:331
void stasis_app_control_inhibit_colp_in_bridge(struct stasis_app_control *control, int inhibit_colp)
Set whether COLP frames should be generated when joining the bridge.
Definition control.c:1521
int stasis_app_control_bridge_features_init(struct stasis_app_control *control)
Initialize bridge features into a channel control.
Definition control.c:1496
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
Structure that contains information about a bridge.
Definition bridge.h:353
#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:978

References ao2_cleanup, args, ast_ari_response_alloc_failed(), ast_ari_response_no_content(), ast_strlen_zero(), check_add_remove_channel(), control_list_create(), find_bridge(), NULL, RAII_VAR, stasis_app_control_absorb_dtmf_in_bridge(), stasis_app_control_add_channel_to_bridge(), stasis_app_control_add_role(), stasis_app_control_bridge_features_init(), stasis_app_control_clear_roles(), stasis_app_control_inhibit_colp_in_bridge(), and stasis_app_control_mute_in_bridge().

Referenced by ast_ari_bridges_add_channel_cb().

◆ ast_ari_bridges_add_channel_parse_body()

int ast_ari_bridges_add_channel_parse_body ( struct ast_json body,
struct ast_ari_bridges_add_channel_args args 
)

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

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 408 of file res_ari_bridges.c.

411{
412 struct ast_json *field;
413 /* Parse query parameters out of it */
414 field = ast_json_object_get(body, "channel");
415 if (field) {
416 /* If they were silly enough to both pass in a query param and a
417 * JSON body, free up the query value.
418 */
419 ast_free(args->channel);
420 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
421 /* Multiple param passed as array */
422 size_t i;
423 args->channel_count = ast_json_array_size(field);
424 args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
425
426 if (!args->channel) {
427 return -1;
428 }
429
430 for (i = 0; i < args->channel_count; ++i) {
431 args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
432 }
433 } else {
434 /* Multiple param passed as single value */
435 args->channel_count = 1;
436 args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
437 if (!args->channel) {
438 return -1;
439 }
440 args->channel[0] = ast_json_string_get(field);
441 }
442 }
443 field = ast_json_object_get(body, "role");
444 if (field) {
445 args->role = ast_json_string_get(field);
446 }
447 field = ast_json_object_get(body, "absorbDTMF");
448 if (field) {
449 args->absorb_dtmf = ast_json_is_true(field);
450 }
451 field = ast_json_object_get(body, "mute");
452 if (field) {
453 args->mute = ast_json_is_true(field);
454 }
455 field = ast_json_object_get(body, "inhibitConnectedLineUpdates");
456 if (field) {
457 args->inhibit_connected_line_updates = ast_json_is_true(field);
458 }
459 return 0;
460}
#define ast_free(a)
Definition astmm.h:180
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
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_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition json.c:370
@ AST_JSON_ARRAY
Definition json.h:165
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
int ast_json_is_true(const struct ast_json *value)
Check if value is JSON true.
Definition json.c:263
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition json.c:366
Abstract JSON element (object, array, string, int, ...).

References args, ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_is_true(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), and ast_malloc.

Referenced by ast_ari_bridges_add_channel_cb().

◆ ast_ari_bridges_clear_video_source()

void ast_ari_bridges_clear_video_source ( struct ast_variable headers,
struct ast_ari_bridges_clear_video_source_args args,
struct ast_ari_response response 
)

Removes any explicit video source in a multi-party mixing bridge. This operation has no effect on bridges with two or fewer participants. When no explicit video source is set, talk detection will be used to determine the active video stream.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1145 of file resource_bridges.c.

1147{
1148 struct ast_bridge *bridge;
1149
1150 bridge = find_bridge(response, args->bridge_id);
1151 if (!bridge) {
1152 return;
1153 }
1154
1155 ast_bridge_lock(bridge);
1157 ast_bridge_unlock(bridge);
1158
1159 ao2_ref(bridge, -1);
1161}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
void ast_bridge_set_talker_src_video_mode(struct ast_bridge *bridge)
Set the bridge to pick the strongest talker supporting video as the single source video feed.
Definition bridge.c:3845
#define ast_bridge_unlock(bridge)
Unlock the bridge.
Definition bridge.h:485
#define ast_bridge_lock(bridge)
Lock the bridge.
Definition bridge.h:474

References ao2_ref, args, ast_ari_response_no_content(), ast_bridge_lock, ast_bridge_set_talker_src_video_mode(), ast_bridge_unlock, and find_bridge().

Referenced by ast_ari_bridges_clear_video_source_cb().

◆ ast_ari_bridges_create()

void ast_ari_bridges_create ( struct ast_variable headers,
struct ast_ari_bridges_create_args args,
struct ast_ari_response response 
)

Create a new bridge.

This bridge persists until it has been shut down, or Asterisk has been shut down.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1024 of file resource_bridges.c.

1027{
1028 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
1029 RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
1030
1031 if (ast_bridge_topic_exists(args->bridge_id)) {
1033 response, 409, "Conflict",
1034 "Bridge with id '%s' already exists", args->bridge_id);
1035 return;
1036 }
1037
1038 bridge = stasis_app_bridge_create(args->type, args->name, args->bridge_id);
1039 if (!bridge) {
1041 response, 500, "Internal Error",
1042 "Unable to create bridge. Possible duplicate bridge id '%s'", args->bridge_id);
1043 return;
1044 }
1045
1046 ast_bridge_lock(bridge);
1047 snapshot = ast_bridge_snapshot_create(bridge);
1048 ast_bridge_unlock(bridge);
1049
1050 if (!snapshot) {
1052 response, 500, "Internal Error",
1053 "Unable to create snapshot for new bridge");
1054 return;
1055 }
1056
1057 ast_ari_response_ok(response,
1059}
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:212
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:229
struct stasis_message_sanitizer * stasis_app_get_sanitizer(void)
Get the Stasis message sanitizer for app_stasis applications.
struct ast_bridge * stasis_app_bridge_create(const char *type, const char *name, const char *id)
Create a bridge of the specified type.
Definition res_stasis.c:891
int ast_bridge_topic_exists(const char *uniqueid)
Check if a stasis topic exists for a bridge uniqueid.
struct ast_json * ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_bridge_snapshot.
struct ast_bridge_snapshot * ast_bridge_snapshot_create(struct ast_bridge *bridge)
Generate a snapshot of the bridge state. This is an ao2 object, so ao2_cleanup() to deallocate.
Structure that contains a snapshot of information about a bridge.
Definition bridge.h:318

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_ok(), ast_bridge_lock, ast_bridge_snapshot_create(), ast_bridge_snapshot_to_json(), ast_bridge_topic_exists(), ast_bridge_unlock, NULL, RAII_VAR, stasis_app_bridge_create(), and stasis_app_get_sanitizer().

Referenced by ast_ari_bridges_create_cb().

◆ ast_ari_bridges_create_parse_body()

int ast_ari_bridges_create_parse_body ( struct ast_json body,
struct ast_ari_bridges_create_args args 
)

Body parsing function for /bridges.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 107 of file res_ari_bridges.c.

110{
111 struct ast_json *field;
112 /* Parse query parameters out of it */
113 field = ast_json_object_get(body, "type");
114 if (field) {
115 args->type = ast_json_string_get(field);
116 }
117 field = ast_json_object_get(body, "bridgeId");
118 if (field) {
119 args->bridge_id = ast_json_string_get(field);
120 }
121 field = ast_json_object_get(body, "name");
122 if (field) {
123 args->name = ast_json_string_get(field);
124 }
125 return 0;
126}

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_bridges_create_cb().

◆ ast_ari_bridges_create_with_id()

void ast_ari_bridges_create_with_id ( struct ast_variable headers,
struct ast_ari_bridges_create_with_id_args args,
struct ast_ari_response response 
)

Create a new bridge.

This bridge persists until it has been shut down, or Asterisk has been shut down.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1061 of file resource_bridges.c.

1064{
1065 RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
1066 RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup);
1067
1068 if (ast_bridge_topic_exists(args->bridge_id)) {
1070 response, 409, "Conflict",
1071 "Bridge with id '%s' already exists", args->bridge_id);
1072 return;
1073 }
1074
1075 bridge = stasis_app_bridge_create(args->type, args->name, args->bridge_id);
1076 if (!bridge) {
1078 response, 500, "Internal Error",
1079 "Unable to create bridge");
1080 return;
1081 }
1082
1083 ast_bridge_lock(bridge);
1084 snapshot = ast_bridge_snapshot_create(bridge);
1085 ast_bridge_unlock(bridge);
1086
1087 if (!snapshot) {
1089 response, 500, "Internal Error",
1090 "Unable to create snapshot for new bridge");
1091 return;
1092 }
1093
1094 ast_ari_response_ok(response,
1096}

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_ok(), ast_bridge_lock, ast_bridge_snapshot_create(), ast_bridge_snapshot_to_json(), ast_bridge_topic_exists(), ast_bridge_unlock, NULL, RAII_VAR, stasis_app_bridge_create(), and stasis_app_get_sanitizer().

Referenced by ast_ari_bridges_create_with_id_cb().

◆ ast_ari_bridges_create_with_id_parse_body()

int ast_ari_bridges_create_with_id_parse_body ( struct ast_json body,
struct ast_ari_bridges_create_with_id_args args 
)

Body parsing function for /bridges/{bridgeId}.

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 198 of file res_ari_bridges.c.

201{
202 struct ast_json *field;
203 /* Parse query parameters out of it */
204 field = ast_json_object_get(body, "type");
205 if (field) {
206 args->type = ast_json_string_get(field);
207 }
208 field = ast_json_object_get(body, "name");
209 if (field) {
210 args->name = ast_json_string_get(field);
211 }
212 return 0;
213}

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_bridges_create_with_id_cb().

◆ ast_ari_bridges_destroy()

void ast_ari_bridges_destroy ( struct ast_variable headers,
struct ast_ari_bridges_destroy_args args,
struct ast_ari_response response 
)

Shut down a bridge.

If any channels are in this bridge, they will be removed and resume whatever they were doing beforehand.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 960 of file resource_bridges.c.

963{
964 RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
965 if (!bridge) {
966 return;
967 }
968
971}
void stasis_app_bridge_destroy(const char *bridge_id)
Destroy the bridge.
Definition res_stasis.c:901

References ao2_cleanup, args, ast_ari_response_no_content(), ast_channel::bridge, find_bridge(), RAII_VAR, and stasis_app_bridge_destroy().

Referenced by ast_ari_bridges_destroy_cb().

◆ ast_ari_bridges_get()

void ast_ari_bridges_get ( struct ast_variable headers,
struct ast_ari_bridges_get_args args,
struct ast_ari_response response 
)

Get bridge details.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 944 of file resource_bridges.c.

947{
949 if (!snapshot) {
951 response, 404, "Not Found",
952 "Bridge not found");
953 return;
954 }
955
956 ast_ari_response_ok(response,
958}
struct ast_bridge_snapshot * ast_bridge_get_snapshot_by_uniqueid(const char *bridge_id)
Returns the current snapshot for the bridge.

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_ok(), ast_bridge_get_snapshot_by_uniqueid(), ast_bridge_snapshot_to_json(), RAII_VAR, ast_channel::snapshot, and stasis_app_get_sanitizer().

Referenced by ast_ari_bridges_get_cb().

◆ ast_ari_bridges_list()

void ast_ari_bridges_list ( struct ast_variable headers,
struct ast_ari_bridges_list_args args,
struct ast_ari_response response 
)

List all active bridges in Asterisk.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 973 of file resource_bridges.c.

976{
978 RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
979 struct ao2_iterator i;
980 struct ast_bridge *bridge;
981
983 if (!bridges) {
985 return;
986 }
987
988 json = ast_json_array_create();
989 if (!json) {
991 return;
992 }
993
995 while ((bridge = ao2_iterator_next(&i))) {
996 struct ast_bridge_snapshot *snapshot;
997 struct ast_json *json_bridge = NULL;
998
999 /* Invisible bridges don't get shown externally and have no snapshot */
1001 ao2_ref(bridge, -1);
1002 continue;
1003 }
1004
1005 snapshot = ast_bridge_get_snapshot(bridge);
1006 if (snapshot) {
1007 json_bridge = ast_bridge_snapshot_to_json(snapshot, stasis_app_get_sanitizer());
1008 ao2_ref(snapshot, -1);
1009 }
1010
1011 ao2_ref(bridge, -1);
1012
1013 if (!json_bridge || ast_json_array_append(json, json_bridge)) {
1016 return;
1017 }
1018 }
1020
1021 ast_ari_response_ok(response, ast_json_ref(json));
1022}
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static struct ao2_container * bridges
Definition bridge.c:132
struct ao2_container * ast_bridges(void)
Returns the global bridges container.
Definition bridge.c:185
@ AST_BRIDGE_FLAG_INVISIBLE
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_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition json.c:378
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition json.c:67
struct ast_bridge_snapshot * ast_bridge_get_snapshot(struct ast_bridge *bridge)
Returns the current snapshot for the bridge.
Generic container type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821
struct ast_flags feature_flags
Definition bridge.h:373
#define ast_test_flag(p, flag)
Definition utils.h:63

References ao2_cleanup, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_ari_response_alloc_failed(), ast_ari_response_ok(), AST_BRIDGE_FLAG_INVISIBLE, ast_bridge_get_snapshot(), ast_bridge_snapshot_to_json(), ast_bridges(), ast_json_array_append(), ast_json_array_create(), ast_json_ref(), ast_json_unref(), ast_test_flag, bridges, ast_bridge::feature_flags, NULL, RAII_VAR, and stasis_app_get_sanitizer().

Referenced by ast_ari_bridges_list_cb().

◆ ast_ari_bridges_play()

void ast_ari_bridges_play ( struct ast_variable headers,
struct ast_ari_bridges_play_args args,
struct ast_ari_response response 
)

Start playback of media on a bridge.

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 670 of file resource_bridges.c.

673{
674 ari_bridges_handle_play(args->bridge_id,
675 args->media,
676 args->media_count,
677 args->announcer_format,
678 args->lang,
679 args->offsetms,
680 args->skipms,
681 args->playback_id,
682 response);
683}
static void ari_bridges_handle_play(const char *args_bridge_id, const char **args_media, size_t args_media_count, const char *args_format, const char *args_lang, int args_offset_ms, int args_skipms, const char *args_playback_id, struct ast_ari_response *response)

References args, and ari_bridges_handle_play().

Referenced by ast_ari_bridges_play_cb().

◆ ast_ari_bridges_play_parse_body()

int ast_ari_bridges_play_parse_body ( struct ast_json body,
struct ast_ari_bridges_play_args args 
)

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

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 1012 of file res_ari_bridges.c.

1015{
1016 struct ast_json *field;
1017 /* Parse query parameters out of it */
1018 field = ast_json_object_get(body, "media");
1019 if (field) {
1020 /* If they were silly enough to both pass in a query param and a
1021 * JSON body, free up the query value.
1022 */
1023 ast_free(args->media);
1024 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
1025 /* Multiple param passed as array */
1026 size_t i;
1027 args->media_count = ast_json_array_size(field);
1028 args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1029
1030 if (!args->media) {
1031 return -1;
1032 }
1033
1034 for (i = 0; i < args->media_count; ++i) {
1035 args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
1036 }
1037 } else {
1038 /* Multiple param passed as single value */
1039 args->media_count = 1;
1040 args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1041 if (!args->media) {
1042 return -1;
1043 }
1044 args->media[0] = ast_json_string_get(field);
1045 }
1046 }
1047 field = ast_json_object_get(body, "announcer_format");
1048 if (field) {
1049 args->announcer_format = ast_json_string_get(field);
1050 }
1051 field = ast_json_object_get(body, "lang");
1052 if (field) {
1053 args->lang = ast_json_string_get(field);
1054 }
1055 field = ast_json_object_get(body, "offsetms");
1056 if (field) {
1057 args->offsetms = ast_json_integer_get(field);
1058 }
1059 field = ast_json_object_get(body, "skipms");
1060 if (field) {
1061 args->skipms = ast_json_integer_get(field);
1062 }
1063 field = ast_json_object_get(body, "playbackId");
1064 if (field) {
1065 args->playback_id = ast_json_string_get(field);
1066 }
1067 return 0;
1068}
intmax_t ast_json_integer_get(const struct ast_json *integer)
Get the value from a JSON integer.
Definition json.c:332

References args, 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(), and ast_malloc.

Referenced by ast_ari_bridges_play_cb().

◆ ast_ari_bridges_play_with_id()

void ast_ari_bridges_play_with_id ( struct ast_variable headers,
struct ast_ari_bridges_play_with_id_args args,
struct ast_ari_response response 
)

Start playback of media on a bridge.

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 685 of file resource_bridges.c.

688{
689 ari_bridges_handle_play(args->bridge_id,
690 args->media,
691 args->media_count,
692 args->announcer_format,
693 args->lang,
694 args->offsetms,
695 args->skipms,
696 args->playback_id,
697 response);
698}

References args, and ari_bridges_handle_play().

Referenced by ast_ari_bridges_play_with_id_cb().

◆ ast_ari_bridges_play_with_id_parse_body()

int ast_ari_bridges_play_with_id_parse_body ( struct ast_json body,
struct ast_ari_bridges_play_with_id_args args 
)

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

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 1199 of file res_ari_bridges.c.

1202{
1203 struct ast_json *field;
1204 /* Parse query parameters out of it */
1205 field = ast_json_object_get(body, "media");
1206 if (field) {
1207 /* If they were silly enough to both pass in a query param and a
1208 * JSON body, free up the query value.
1209 */
1210 ast_free(args->media);
1211 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
1212 /* Multiple param passed as array */
1213 size_t i;
1214 args->media_count = ast_json_array_size(field);
1215 args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1216
1217 if (!args->media) {
1218 return -1;
1219 }
1220
1221 for (i = 0; i < args->media_count; ++i) {
1222 args->media[i] = ast_json_string_get(ast_json_array_get(field, i));
1223 }
1224 } else {
1225 /* Multiple param passed as single value */
1226 args->media_count = 1;
1227 args->media = ast_malloc(sizeof(*args->media) * args->media_count);
1228 if (!args->media) {
1229 return -1;
1230 }
1231 args->media[0] = ast_json_string_get(field);
1232 }
1233 }
1234 field = ast_json_object_get(body, "announcer_format");
1235 if (field) {
1236 args->announcer_format = ast_json_string_get(field);
1237 }
1238 field = ast_json_object_get(body, "lang");
1239 if (field) {
1240 args->lang = ast_json_string_get(field);
1241 }
1242 field = ast_json_object_get(body, "offsetms");
1243 if (field) {
1244 args->offsetms = ast_json_integer_get(field);
1245 }
1246 field = ast_json_object_get(body, "skipms");
1247 if (field) {
1248 args->skipms = ast_json_integer_get(field);
1249 }
1250 return 0;
1251}

References args, 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(), and ast_malloc.

Referenced by ast_ari_bridges_play_with_id_cb().

◆ ast_ari_bridges_record()

void ast_ari_bridges_record ( struct ast_variable headers,
struct ast_ari_bridges_record_args args,
struct ast_ari_response response 
)

Start a recording.

This records the mixed audio from all channels participating in this bridge.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 700 of file resource_bridges.c.

703{
704 RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
705 RAII_VAR(struct ast_channel *, record_channel, NULL, ast_hangup);
706 RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
707 RAII_VAR(struct stasis_app_recording *, recording, NULL, ao2_cleanup);
708 RAII_VAR(char *, recording_url, NULL, ast_free);
709 RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
711 RAII_VAR(char *, uri_encoded_name, NULL, ast_free);
712 RAII_VAR(struct stasis_forward *, channel_forward, NULL, stasis_forward_cancel);
713
714 struct stasis_topic *channel_topic;
715 struct stasis_topic *bridge_topic;
716 size_t uri_name_maxlen;
717 struct bridge_channel_control_thread_data *thread_data;
718 pthread_t threadid;
719 struct ast_format *file_format = NULL;
720 struct ast_format *channel_format = NULL;
721
722 ast_assert(response != NULL);
723
724 if (bridge == NULL) {
725 return;
726 }
727
729 if (!file_format) {
731 response, 422, "Unprocessable Entity",
732 "specified format is unknown on this system");
733 return;
734 }
735
736 if (!ast_strlen_zero(args->recorder_format)) {
737 channel_format = ast_format_cache_get(args->recorder_format);
738 if (!channel_format) {
740 response, 422, "Unprocessable Entity",
741 "specified recorder_format is unknown on this system");
742 return;
743 }
744 /*
745 * ast_format_cache_get() bumps the refcount but the other calls
746 * to retrieve formats don't so we'll drop this reference.
747 * It'll be bumped again in the prepare_bridge_media_channel() call below.
748 */
749 ao2_ref(channel_format, -1);
750
751 } else {
752 channel_format = file_format;
753 }
754
755 if (!(record_channel = prepare_bridge_media_channel("Recorder", channel_format))) {
757 response, 500, "Internal Server Error", "Failed to create recording channel");
758 return;
759 }
760
761 bridge_topic = ast_bridge_topic(bridge);
762 channel_topic = ast_channel_topic(record_channel);
763
764 /* Forward messages from the recording channel topic to the bridge topic so that anything listening for
765 * messages on the bridge topic will receive the recording start/stop messages. Other messages that would
766 * go to this channel will be suppressed since the channel is marked as internal.
767 */
768 if (!bridge_topic || !channel_topic || !(channel_forward = stasis_forward_all(channel_topic, bridge_topic))) {
770 response, 500, "Internal Error", "Could not forward record channel stasis messages to bridge topic");
771 return;
772 }
773
774 if (ast_unreal_channel_push_to_bridge(record_channel, bridge,
777 response, 500, "Internal Error", "Failed to put recording channel into the bridge");
778 return;
779 }
780
781 control = stasis_app_control_create(record_channel);
782 if (control == NULL) {
784 return;
785 }
786
788 if (options == NULL) {
790 return;
791 }
792
793 ast_string_field_build(options, target, "bridge:%s", args->bridge_id);
794 options->max_silence_seconds = args->max_silence_seconds;
795 options->max_duration_seconds = args->max_duration_seconds;
796 options->terminate_on =
798 options->if_exists =
800 options->beep = args->beep;
801
802 if (options->terminate_on == STASIS_APP_RECORDING_TERMINATE_INVALID) {
804 response, 400, "Bad Request",
805 "terminateOn invalid");
806 return;
807 }
808
809 if (options->if_exists == AST_RECORD_IF_EXISTS_ERROR) {
811 response, 400, "Bad Request",
812 "ifExists invalid");
813 return;
814 }
815
816 recording = stasis_app_control_record(control, options);
817 if (recording == NULL) {
818 switch(errno) {
819 case EINVAL:
820 /* While the arguments are invalid, we should have
821 * caught them prior to calling record.
822 */
824 response, 500, "Internal Server Error",
825 "Error parsing request");
826 break;
827 case EEXIST:
828 ast_ari_response_error(response, 409, "Conflict",
829 "Recording '%s' already exists and can not be overwritten",
830 args->name);
831 break;
832 case ENOMEM:
834 break;
835 case EPERM:
837 response, 400, "Bad Request",
838 "Recording name invalid");
839 break;
840 default:
842 "Unrecognized recording error: %s\n",
843 strerror(errno));
845 response, 500, "Internal Server Error",
846 "Internal Server Error");
847 break;
848 }
849 return;
850 }
851
852 uri_name_maxlen = strlen(args->name) * 3;
853 uri_encoded_name = ast_malloc(uri_name_maxlen);
854 if (!uri_encoded_name) {
856 return;
857 }
858 ast_uri_encode(args->name, uri_encoded_name, uri_name_maxlen, ast_uri_http);
859
860 if (ast_asprintf(&recording_url, "/recordings/live/%s",
861 uri_encoded_name) == -1) {
862 recording_url = NULL;
864 return;
865 }
866
867 json = stasis_app_recording_to_json(recording);
868 if (!json) {
870 return;
871 }
872
873 thread_data = ast_calloc(1, sizeof(*thread_data));
874 if (!thread_data) {
876 return;
877 }
878
879 thread_data->bridge_channel = record_channel;
880 thread_data->control = control;
881 thread_data->forward = channel_forward;
882
883 if (ast_pthread_create_detached(&threadid, NULL, bridge_channel_control_thread, thread_data)) {
885 ast_free(thread_data);
886 return;
887 }
888
889 /* These are owned by the other thread now, so we don't want RAII_VAR disposing of them. */
890 record_channel = NULL;
891 control = NULL;
892 channel_forward = NULL;
893
894 ast_ari_response_created(response, recording_url, ast_json_ref(json));
895}
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:258
#define ast_asprintf(ret, fmt,...)
A wrapper for asprintf()
Definition astmm.h:267
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_log
Definition astobj2.c:42
@ AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE
@ AST_BRIDGE_CHANNEL_FLAG_LONELY
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2513
struct stasis_topic * ast_channel_topic(struct ast_channel *chan)
A topic which publishes the events for a particular channel.
int ast_unreal_channel_push_to_bridge(struct ast_channel *ast, struct ast_bridge *bridge, unsigned int flags)
Push the semi2 unreal channel into a bridge from either member of the unreal pair.
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:2040
#define ast_format_cache_get(name)
Retrieve a named format from the cache.
file_format
Definition func_env.c:440
@ AST_RECORD_IF_EXISTS_ERROR
#define LOG_WARNING
int errno
static void * bridge_channel_control_thread(void *data)
static struct ast_channel * prepare_bridge_media_channel(const char *type, struct ast_format *channel_format)
struct stasis_forward * stasis_forward_cancel(struct stasis_forward *forward)
Definition stasis.c:1615
struct stasis_forward * stasis_forward_all(struct stasis_topic *from_topic, struct stasis_topic *to_topic)
Create a subscription which forwards all messages from one topic to another.
Definition stasis.c:1645
struct stasis_app_control * stasis_app_control_create(struct ast_channel *chan)
Creates a control handler for a channel that isn't in a stasis app.
Definition res_stasis.c:333
struct stasis_app_recording_options * stasis_app_recording_options_create(const char *name, const char *format)
Allocate a recording options object.
struct ast_json * stasis_app_recording_to_json(const struct stasis_app_recording *recording)
Construct a JSON model of a recording.
struct stasis_app_recording * stasis_app_control_record(struct stasis_app_control *control, struct stasis_app_recording_options *options)
Record media from a channel.
enum ast_record_if_exists stasis_app_recording_if_exists_parse(const char *str)
Parse a string into the if_exists enum.
#define STASIS_APP_RECORDING_TERMINATE_INVALID
char stasis_app_recording_termination_parse(const char *str)
Parse a string into the recording termination enum.
struct stasis_topic * ast_bridge_topic(struct ast_bridge *bridge)
A topic which publishes the events for a particular bridge.
#define ast_string_field_build(x, field, fmt, args...)
Set a field to a complex (built) value.
Main Channel structure associated with a channel.
Definition of a media format.
Definition format.c:43
struct stasis_app_control * control
Forwarding information.
Definition stasis.c:1598
static struct test_options options
#define ast_assert(a)
Definition utils.h:776
char * ast_uri_encode(const char *string, char *outbuf, int buflen, struct ast_flags spec)
Turn text string to URI-encoded XX version.
Definition utils.c:723
const struct ast_flags ast_uri_http
Definition utils.c:719
#define ast_pthread_create_detached(a, b, c, d)
Definition utils.h:625

References ao2_cleanup, ao2_ref, args, ast_ari_response_alloc_failed(), ast_ari_response_created(), ast_ari_response_error(), ast_asprintf, ast_assert, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE, AST_BRIDGE_CHANNEL_FLAG_LONELY, ast_bridge_topic(), ast_calloc, ast_channel_topic(), ast_format_cache_get, ast_free, ast_get_format_for_file_ext(), ast_hangup(), ast_json_ref(), ast_json_unref(), ast_log, ast_malloc, ast_pthread_create_detached, AST_RECORD_IF_EXISTS_ERROR, ast_string_field_build, ast_strlen_zero(), ast_unreal_channel_push_to_bridge(), ast_uri_encode(), ast_uri_http, ast_channel::bridge, bridge_channel_control_thread_data::bridge_channel, bridge_channel_control_thread(), ast_channel::channel_forward, bridge_channel_control_thread_data::control, errno, find_bridge(), bridge_channel_control_thread_data::forward, LOG_WARNING, NULL, options, prepare_bridge_media_channel(), RAII_VAR, stasis_app_control_create(), 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(), stasis_forward_all(), and stasis_forward_cancel().

Referenced by ast_ari_bridges_record_cb().

◆ ast_ari_bridges_record_parse_body()

int ast_ari_bridges_record_parse_body ( struct ast_json body,
struct ast_ari_bridges_record_args args 
)

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

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 1382 of file res_ari_bridges.c.

1385{
1386 struct ast_json *field;
1387 /* Parse query parameters out of it */
1388 field = ast_json_object_get(body, "name");
1389 if (field) {
1390 args->name = ast_json_string_get(field);
1391 }
1392 field = ast_json_object_get(body, "format");
1393 if (field) {
1394 args->format = ast_json_string_get(field);
1395 }
1396 field = ast_json_object_get(body, "recorder_format");
1397 if (field) {
1398 args->recorder_format = ast_json_string_get(field);
1399 }
1400 field = ast_json_object_get(body, "maxDurationSeconds");
1401 if (field) {
1402 args->max_duration_seconds = ast_json_integer_get(field);
1403 }
1404 field = ast_json_object_get(body, "maxSilenceSeconds");
1405 if (field) {
1406 args->max_silence_seconds = ast_json_integer_get(field);
1407 }
1408 field = ast_json_object_get(body, "ifExists");
1409 if (field) {
1410 args->if_exists = ast_json_string_get(field);
1411 }
1412 field = ast_json_object_get(body, "beep");
1413 if (field) {
1414 args->beep = ast_json_is_true(field);
1415 }
1416 field = ast_json_object_get(body, "terminateOn");
1417 if (field) {
1418 args->terminate_on = ast_json_string_get(field);
1419 }
1420 return 0;
1421}

References args, ast_json_integer_get(), ast_json_is_true(), ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_bridges_record_cb().

◆ ast_ari_bridges_remove_channel()

void ast_ari_bridges_remove_channel ( struct ast_variable headers,
struct ast_ari_bridges_remove_channel_args args,
struct ast_ari_response response 
)

Remove a channel from a bridge.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 241 of file resource_bridges.c.

244{
245 RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
246 RAII_VAR(struct control_list *, list, NULL, ao2_cleanup);
247 size_t i;
248
249 if (!bridge) {
250 /* Response filled in by find_bridge() */
251 return;
252 }
253
254 list = control_list_create(response, args->channel_count, args->channel);
255 if (!list) {
256 /* Response filled in by control_list_create() */
257 return;
258 }
259
260 /* Make sure all of the channels are in this bridge */
261 for (i = 0; i < list->count; ++i) {
262 if (stasis_app_get_bridge(list->controls[i]) != bridge) {
263 ast_log(LOG_WARNING, "Channel %s not in bridge %s\n",
264 args->channel[i], args->bridge_id);
265 ast_ari_response_error(response, 422,
266 "Unprocessable Entity",
267 "Channel not in this bridge");
268 return;
269 }
270 }
271
272 /* Now actually remove it */
273 for (i = 0; i < list->count; ++i) {
275 bridge);
276 }
277
279}
int stasis_app_control_remove_channel_from_bridge(struct stasis_app_control *control, struct ast_bridge *bridge)
Remove a channel from the bridge.
Definition control.c:1465
struct ast_bridge * stasis_app_get_bridge(struct stasis_app_control *control)
Gets the bridge currently associated with a control object.
Definition control.c:972

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_no_content(), ast_log, control_list_create(), find_bridge(), LOG_WARNING, NULL, RAII_VAR, stasis_app_control_remove_channel_from_bridge(), and stasis_app_get_bridge().

Referenced by ast_ari_bridges_remove_channel_cb().

◆ ast_ari_bridges_remove_channel_parse_body()

int ast_ari_bridges_remove_channel_parse_body ( struct ast_json body,
struct ast_ari_bridges_remove_channel_args args 
)

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

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 589 of file res_ari_bridges.c.

592{
593 struct ast_json *field;
594 /* Parse query parameters out of it */
595 field = ast_json_object_get(body, "channel");
596 if (field) {
597 /* If they were silly enough to both pass in a query param and a
598 * JSON body, free up the query value.
599 */
600 ast_free(args->channel);
601 if (ast_json_typeof(field) == AST_JSON_ARRAY) {
602 /* Multiple param passed as array */
603 size_t i;
604 args->channel_count = ast_json_array_size(field);
605 args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
606
607 if (!args->channel) {
608 return -1;
609 }
610
611 for (i = 0; i < args->channel_count; ++i) {
612 args->channel[i] = ast_json_string_get(ast_json_array_get(field, i));
613 }
614 } else {
615 /* Multiple param passed as single value */
616 args->channel_count = 1;
617 args->channel = ast_malloc(sizeof(*args->channel) * args->channel_count);
618 if (!args->channel) {
619 return -1;
620 }
621 args->channel[0] = ast_json_string_get(field);
622 }
623 }
624 return 0;
625}

References args, ast_free, AST_JSON_ARRAY, ast_json_array_get(), ast_json_array_size(), ast_json_object_get(), ast_json_string_get(), ast_json_typeof(), and ast_malloc.

Referenced by ast_ari_bridges_remove_channel_cb().

◆ ast_ari_bridges_set_video_source()

void ast_ari_bridges_set_video_source ( struct ast_variable headers,
struct ast_ari_bridges_set_video_source_args args,
struct ast_ari_response response 
)

Set a channel as the video source in a multi-party mixing bridge. This operation has no effect on bridges with two or fewer participants.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 1110 of file resource_bridges.c.

1112{
1113 struct ast_bridge *bridge;
1114 struct stasis_app_control *control;
1115
1116 bridge = find_bridge(response, args->bridge_id);
1117 if (!bridge) {
1118 return;
1119 }
1120
1121 control = find_channel_control(response, args->channel_id);
1122 if (!control) {
1123 ao2_ref(bridge, -1);
1124 return;
1125 }
1126
1127 if (stasis_app_get_bridge(control) != bridge) {
1128 ast_ari_response_error(response, 422,
1129 "Unprocessable Entity",
1130 "Channel not in this bridge");
1131 ao2_ref(bridge, -1);
1132 ao2_ref(control, -1);
1133 return;
1134 }
1135
1138
1139 ao2_ref(bridge, -1);
1140 ao2_ref(control, -1);
1141
1143}
void __ao2_cleanup(void *obj)
Definition astobj2.c:677
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
static struct stasis_app_control * find_channel_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.
static int bridge_set_video_source_cb(struct stasis_app_control *control, struct ast_channel *chan, void *data)
int stasis_app_send_command(struct stasis_app_control *control, stasis_app_command_cb command, void *data, command_data_destructor_fn data_destructor)
Invokes a command on a control's channel.
Definition control.c:939
struct ast_bridge * bridge
Definition control.c:67

References __ao2_cleanup(), ao2_bump, ao2_ref, args, ast_ari_response_error(), ast_ari_response_no_content(), stasis_app_control::bridge, bridge_set_video_source_cb(), find_bridge(), find_channel_control(), stasis_app_get_bridge(), and stasis_app_send_command().

Referenced by ast_ari_bridges_set_video_source_cb().

◆ ast_ari_bridges_start_moh()

void ast_ari_bridges_start_moh ( struct ast_variable headers,
struct ast_ari_bridges_start_moh_args args,
struct ast_ari_response response 
)

Play music on hold to a bridge or change the MOH class that is playing.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 897 of file resource_bridges.c.

900{
901 RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
902 struct ast_channel *moh_channel;
903 const char *moh_class = args->moh_class;
904
905 if (!bridge) {
906 /* The response is provided by find_bridge() */
907 return;
908 }
909
911 if (!moh_channel) {
913 return;
914 }
915
916 ast_moh_start(moh_channel, moh_class, NULL);
917 ast_channel_cleanup(moh_channel);
918
920
921}
#define ast_channel_cleanup(c)
Cleanup a channel reference.
Definition channel.h:3029
int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass)
Turn on music on hold on a given channel.
Definition channel.c:7753
struct ast_channel * stasis_app_bridge_moh_channel(struct ast_bridge *bridge)
Finds or creates an announcer channel in a bridge that can play music on hold.
Definition res_stasis.c:655
struct ast_bridge * bridge

References ao2_cleanup, args, ast_ari_response_alloc_failed(), ast_ari_response_no_content(), ast_channel_cleanup, ast_moh_start(), ast_channel::bridge, find_bridge(), NULL, RAII_VAR, and stasis_app_bridge_moh_channel().

Referenced by ast_ari_bridges_start_moh_cb().

◆ ast_ari_bridges_start_moh_parse_body()

int ast_ari_bridges_start_moh_parse_body ( struct ast_json body,
struct ast_ari_bridges_start_moh_args args 
)

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

Parameters
bodyThe JSON body from which to parse parameters.
[out]argsThe args structure to parse into.
Return values
zeroon success
non-zeroon failure

Definition at line 867 of file res_ari_bridges.c.

870{
871 struct ast_json *field;
872 /* Parse query parameters out of it */
873 field = ast_json_object_get(body, "mohClass");
874 if (field) {
875 args->moh_class = ast_json_string_get(field);
876 }
877 return 0;
878}

References args, ast_json_object_get(), and ast_json_string_get().

Referenced by ast_ari_bridges_start_moh_cb().

◆ ast_ari_bridges_stop_moh()

void ast_ari_bridges_stop_moh ( struct ast_variable headers,
struct ast_ari_bridges_stop_moh_args args,
struct ast_ari_response response 
)

Stop playing music on hold to a bridge.

This will only stop music on hold being played via POST bridges/{bridgeId}/moh.

Parameters
headersHTTP headers
argsSwagger parameters
[out]responseHTTP response

Definition at line 923 of file resource_bridges.c.

926{
927 RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
928
929 if (!bridge) {
930 /* the response is provided by find_bridge() */
931 return;
932 }
933
934 if (stasis_app_bridge_moh_stop(bridge)) {
936 response, 409, "Conflict",
937 "Bridge isn't playing music");
938 return;
939 }
940
942}
int stasis_app_bridge_moh_stop(struct ast_bridge *bridge)
Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel.
Definition res_stasis.c:675

References ao2_cleanup, args, ast_ari_response_error(), ast_ari_response_no_content(), ast_channel::bridge, find_bridge(), RAII_VAR, and stasis_app_bridge_moh_stop().

Referenced by ast_ari_bridges_stop_moh_cb().