summaryrefslogtreecommitdiff
path: root/res/ari/resource_bridges.c
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-08-02 14:36:32 +0000
committerDavid M. Lee <dlee@digium.com>2013-08-02 14:36:32 +0000
commit537ecebd2dc27120144498598f32dec97db6808d (patch)
treea3815f8c3f9cc7e2443d8cebc31a7b1d109aa81d /res/ari/resource_bridges.c
parent10c91bc96eafbf5f897869ede83127c9c267981c (diff)
ARI - implement allowMultiple for parameters
Swagger allows parameters to be specified as 'allowMultiple', meaning that the parameter may be specified as a comma separated list of values. I had written some of the API docs using that, but promptly forgot about implementing it. This patch finally fills in that gap. The codegen template was updated to represent 'allowMultiple' fields as array/size fields in the _args structs. It also parses the comma separated list using ast_app_separate_args(), so quoted strings in the argument will be handled properly. Review: https://reviewboard.asterisk.org/r/2698/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari/resource_bridges.c')
-rw-r--r--res/ari/resource_bridges.c89
1 files changed, 78 insertions, 11 deletions
diff --git a/res/ari/resource_bridges.c b/res/ari/resource_bridges.c
index 7730d0cd9..e4c7194ff 100644
--- a/res/ari/resource_bridges.c
+++ b/res/ari/resource_bridges.c
@@ -1,4 +1,4 @@
-/* -*- C -*-
+/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2012 - 2013, Digium, Inc.
@@ -107,33 +107,95 @@ static struct stasis_app_control *find_channel_control(
return control;
}
+struct control_list {
+ size_t count;
+ struct stasis_app_control *controls[];
+};
+
+static void control_list_dtor(void *obj) {
+ struct control_list *list = obj;
+ size_t i;
+
+ for (i = 0; i < list->count; ++i) {
+ ao2_cleanup(list->controls[i]);
+ list->controls[i] = NULL;
+ }
+}
+
+static struct control_list *control_list_create(struct ast_ari_response *response, size_t count, const char **channels) {
+ RAII_VAR(struct control_list *, list, NULL, ao2_cleanup);
+ size_t i;
+
+ if (count == 0 || !channels) {
+ ast_ari_response_error(response, 400, "Bad Request", "Missing parameter channel");
+ return NULL;
+ }
+
+ list = ao2_alloc(sizeof(*list) + count * sizeof(list->controls[0]), control_list_dtor);
+ if (!list) {
+ ast_ari_response_alloc_failed(response);
+ return NULL;
+ }
+
+ for (i = 0; i < count; ++i) {
+ if (ast_strlen_zero(channels[i])) {
+ continue;
+ }
+ list->controls[list->count] =
+ find_channel_control(response, channels[i]);
+ if (!list->controls[list->count]) {
+ return NULL;
+ }
+ ++list->count;
+ }
+
+ if (list->count == 0) {
+ ast_ari_response_error(response, 400, "Bad Request", "Missing parameter channel");
+ return NULL;
+ }
+
+ ao2_ref(list, +1);
+ return list;
+}
+
void ast_ari_add_channel_to_bridge(struct ast_variable *headers, struct ast_add_channel_to_bridge_args *args, struct ast_ari_response *response)
{
RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
- RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ RAII_VAR(struct control_list *, list, NULL, ao2_cleanup);
+ size_t i;
+
if (!bridge) {
+ /* Response filled in by find_bridge */
return;
}
- control = find_channel_control(response, args->channel);
- if (!control) {
+ list = control_list_create(response, args->channel_count, args->channel);
+ if (!list) {
+ /* Response filled in by control_list_create() */
return;
}
- stasis_app_control_add_channel_to_bridge(control, bridge);
+ for (i = 0; i < list->count; ++i) {
+ stasis_app_control_add_channel_to_bridge(list->controls[i], bridge);
+ }
+
ast_ari_response_no_content(response);
}
void ast_ari_remove_channel_from_bridge(struct ast_variable *headers, struct ast_remove_channel_from_bridge_args *args, struct ast_ari_response *response)
{
RAII_VAR(struct ast_bridge *, bridge, find_bridge(response, args->bridge_id), ao2_cleanup);
- RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ RAII_VAR(struct control_list *, list, NULL, ao2_cleanup);
+ size_t i;
+
if (!bridge) {
+ /* Response filled in by find_bridge */
return;
}
- control = find_channel_control(response, args->channel);
- if (!control) {
+ list = control_list_create(response, args->channel_count, args->channel);
+ if (!list) {
+ /* Response filled in by control_list_create() */
return;
}
@@ -141,9 +203,14 @@ void ast_ari_remove_channel_from_bridge(struct ast_variable *headers, struct ast
* the bridge the channel is in. This will be possible once the bridge uniqueid
* is added to the channel snapshot. A 409 response should be issued if the bridge
* uniqueids don't match */
- if (stasis_app_control_remove_channel_from_bridge(control, bridge)) {
- ast_ari_response_error(response, 500, "Internal Error",
- "Could not remove channel from bridge");
+ for (i = 0; i < list->count; ++i) {
+ if (stasis_app_control_remove_channel_from_bridge(list->controls[i], bridge)) {
+ ast_ari_response_error(response, 500, "Internal Error",
+ "Could not remove channel from bridge");
+ }
+ }
+
+ if (response->response_code) {
return;
}