diff options
Diffstat (limited to 'res/ari')
-rw-r--r-- | res/ari/resource_asterisk.h | 8 | ||||
-rw-r--r-- | res/ari/resource_bridges.c | 89 | ||||
-rw-r--r-- | res/ari/resource_bridges.h | 16 | ||||
-rw-r--r-- | res/ari/resource_events.c | 37 | ||||
-rw-r--r-- | res/ari/resource_events.h | 8 | ||||
-rw-r--r-- | res/ari/resource_sounds.h | 2 |
6 files changed, 123 insertions, 37 deletions
diff --git a/res/ari/resource_asterisk.h b/res/ari/resource_asterisk.h index 69539525e..d2f316a6b 100644 --- a/res/ari/resource_asterisk.h +++ b/res/ari/resource_asterisk.h @@ -41,8 +41,12 @@ /*! \brief Argument struct for ast_ari_get_asterisk_info() */ struct ast_get_asterisk_info_args { - /*! \brief Filter information returned */ - const char *only; + /*! \brief Array of Filter information returned */ + const char **only; + /*! \brief Length of only array. */ + size_t only_count; + /*! \brief Parsing context for only. */ + char *only_parse; }; /*! * \brief Gets Asterisk system information. 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; } diff --git a/res/ari/resource_bridges.h b/res/ari/resource_bridges.h index 892a3f269..d12432413 100644 --- a/res/ari/resource_bridges.h +++ b/res/ari/resource_bridges.h @@ -97,8 +97,12 @@ void ast_ari_delete_bridge(struct ast_variable *headers, struct ast_delete_bridg struct ast_add_channel_to_bridge_args { /*! \brief Bridge's id */ const char *bridge_id; - /*! \brief Channel's id */ - const char *channel; + /*! \brief Array of Ids of channels to add to bridge */ + const char **channel; + /*! \brief Length of channel array. */ + size_t channel_count; + /*! \brief Parsing context for channel. */ + char *channel_parse; }; /*! * \brief Add a channel to a bridge. @@ -112,8 +116,12 @@ void ast_ari_add_channel_to_bridge(struct ast_variable *headers, struct ast_add_ struct ast_remove_channel_from_bridge_args { /*! \brief Bridge's id */ const char *bridge_id; - /*! \brief Channel's id */ - const char *channel; + /*! \brief Array of Ids of channels to remove from bridge */ + const char **channel; + /*! \brief Length of channel array. */ + size_t channel_count; + /*! \brief Parsing context for channel. */ + char *channel_parse; }; /*! * \brief Remove a channel from a bridge. diff --git a/res/ari/resource_events.c b/res/ari/resource_events.c index e5490b546..dd474c3ce 100644 --- a/res/ari/resource_events.c +++ b/res/ari/resource_events.c @@ -143,35 +143,28 @@ static void app_handler(void *data, const char *app_name, /*! * \brief Register for all of the apps given. * \param session Session info struct. - * \param app_list Comma seperated list of app names to register. + * \param app_name Name of application to register. */ -static int session_register_apps(struct event_session *session, - const char *app_list) +static int session_register_app(struct event_session *session, + const char *app_name) { - RAII_VAR(char *, to_free, NULL, ast_free); - char *apps, *app_name; SCOPED_AO2LOCK(lock, session); ast_assert(session->ws_session != NULL); ast_assert(session->websocket_apps != NULL); - if (!app_list) { + if (ast_strlen_zero(app_name)) { return -1; } - to_free = apps = ast_strdup(app_list); - if (!apps) { - ast_ari_websocket_session_write(session->ws_session, ast_ari_oom_json()); + if (ast_str_container_add(session->websocket_apps, app_name)) { + ast_ari_websocket_session_write(session->ws_session, + ast_ari_oom_json()); return -1; } - while ((app_name = strsep(&apps, ","))) { - if (ast_str_container_add(session->websocket_apps, app_name)) { - ast_ari_websocket_session_write(session->ws_session, ast_ari_oom_json()); - return -1; - } - stasis_app_register(app_name, app_handler, session); - } + stasis_app_register(app_name, app_handler, session); + return 0; } @@ -182,6 +175,7 @@ void ast_ari_websocket_event_websocket(struct ast_ari_websocket_session *ws_sess RAII_VAR(struct event_session *, session, NULL, session_cleanup); struct ast_json *msg; int res; + size_t i; ast_debug(3, "/events WebSocket connection\n"); @@ -191,7 +185,15 @@ void ast_ari_websocket_event_websocket(struct ast_ari_websocket_session *ws_sess return; } - if (!args->app) { + res = 0; + for (i = 0; i < args->app_count; ++i) { + if (ast_strlen_zero(args->app[i])) { + continue; + } + res |= session_register_app(session, args->app[i]); + } + + if (ao2_container_count(session->websocket_apps) == 0) { RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref); msg = ast_json_pack("{s: s, s: [s]}", @@ -205,7 +207,6 @@ void ast_ari_websocket_event_websocket(struct ast_ari_websocket_session *ws_sess return; } - res = session_register_apps(session, args->app); if (res != 0) { ast_ari_websocket_session_write(ws_session, ast_ari_oom_json()); return; diff --git a/res/ari/resource_events.h b/res/ari/resource_events.h index 554ed9a87..ac7600e03 100644 --- a/res/ari/resource_events.h +++ b/res/ari/resource_events.h @@ -41,8 +41,12 @@ /*! \brief Argument struct for ast_ari_event_websocket() */ struct ast_event_websocket_args { - /*! \brief Comma seperated list of applications to subscribe to. */ - const char *app; + /*! \brief Array of Applications to subscribe to. */ + const char **app; + /*! \brief Length of app array. */ + size_t app_count; + /*! \brief Parsing context for app. */ + char *app_parse; }; /*! * \brief WebSocket connection for events. diff --git a/res/ari/resource_sounds.h b/res/ari/resource_sounds.h index 7cb22fb71..fa7cda23c 100644 --- a/res/ari/resource_sounds.h +++ b/res/ari/resource_sounds.h @@ -41,7 +41,9 @@ /*! \brief Argument struct for ast_ari_get_sounds() */ struct ast_get_sounds_args { + /*! \brief Lookup sound for a specific language. */ const char *lang; + /*! \brief Lookup sound in a specific format. */ const char *format; }; /*! |