[asterisk-commits] dlee: branch dlee/allow-multiple r395395 - in /team/dlee/allow-multiple: res/...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 25 08:34:23 CDT 2013
Author: dlee
Date: Thu Jul 25 08:34:21 2013
New Revision: 395395
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395395
Log:
Implement allowMultiple
Modified:
team/dlee/allow-multiple/res/res_stasis_http_asterisk.c
team/dlee/allow-multiple/res/res_stasis_http_bridges.c
team/dlee/allow-multiple/res/res_stasis_http_events.c
team/dlee/allow-multiple/res/stasis_http/resource_asterisk.h
team/dlee/allow-multiple/res/stasis_http/resource_bridges.c
team/dlee/allow-multiple/res/stasis_http/resource_bridges.h
team/dlee/allow-multiple/res/stasis_http/resource_events.c
team/dlee/allow-multiple/res/stasis_http/resource_events.h
team/dlee/allow-multiple/rest-api-templates/param_parsing.mustache
team/dlee/allow-multiple/rest-api-templates/stasis_http_resource.h.mustache
team/dlee/allow-multiple/rest-api/api-docs/bridges.json
team/dlee/allow-multiple/rest-api/api-docs/channels.json
Modified: team/dlee/allow-multiple/res/res_stasis_http_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/res_stasis_http_asterisk.c?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/res_stasis_http_asterisk.c (original)
+++ team/dlee/allow-multiple/res/res_stasis_http_asterisk.c Thu Jul 25 08:34:21 2013
@@ -69,7 +69,14 @@
for (i = get_params; i; i = i->next) {
if (strcmp(i->name, "only") == 0) {
- args.only = (i->value);
+ void *p = ast_realloc(args.only,
+ sizeof(*args.only) * (args.only_count + 1));
+ if (!p) {
+ ast_log(LOG_ERROR, "OOM parsing only\n");
+ continue;
+ }
+ args.only = p;
+ args.only[args.only_count++] = (i->value);
} else
{}
}
Modified: team/dlee/allow-multiple/res/res_stasis_http_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/res_stasis_http_bridges.c?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/res_stasis_http_bridges.c (original)
+++ team/dlee/allow-multiple/res/res_stasis_http_bridges.c Thu Jul 25 08:34:21 2013
@@ -279,7 +279,14 @@
for (i = get_params; i; i = i->next) {
if (strcmp(i->name, "channel") == 0) {
- args.channel = (i->value);
+ void *p = ast_realloc(args.channel,
+ sizeof(*args.channel) * (args.channel_count + 1));
+ if (!p) {
+ ast_log(LOG_ERROR, "OOM parsing channel\n");
+ continue;
+ }
+ args.channel = p;
+ args.channel[args.channel_count++] = (i->value);
} else
{}
}
@@ -342,7 +349,14 @@
for (i = get_params; i; i = i->next) {
if (strcmp(i->name, "channel") == 0) {
- args.channel = (i->value);
+ void *p = ast_realloc(args.channel,
+ sizeof(*args.channel) * (args.channel_count + 1));
+ if (!p) {
+ ast_log(LOG_ERROR, "OOM parsing channel\n");
+ continue;
+ }
+ args.channel = p;
+ args.channel[args.channel_count++] = (i->value);
} else
{}
}
Modified: team/dlee/allow-multiple/res/res_stasis_http_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/res_stasis_http_events.c?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/res_stasis_http_events.c (original)
+++ team/dlee/allow-multiple/res/res_stasis_http_events.c Thu Jul 25 08:34:21 2013
@@ -58,7 +58,14 @@
for (i = get_params; i; i = i->next) {
if (strcmp(i->name, "app") == 0) {
- args.app = (i->value);
+ void *p = ast_realloc(args.app,
+ sizeof(*args.app) * (args.app_count + 1));
+ if (!p) {
+ ast_log(LOG_ERROR, "OOM parsing app\n");
+ continue;
+ }
+ args.app = p;
+ args.app[args.app_count++] = (i->value);
} else
{}
}
Modified: team/dlee/allow-multiple/res/stasis_http/resource_asterisk.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/stasis_http/resource_asterisk.h?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/stasis_http/resource_asterisk.h (original)
+++ team/dlee/allow-multiple/res/stasis_http/resource_asterisk.h Thu Jul 25 08:34:21 2013
@@ -42,7 +42,8 @@
/*! \brief Argument struct for stasis_http_get_asterisk_info() */
struct ast_get_asterisk_info_args {
/*! \brief Filter information returned */
- const char *only;
+ const char **only;
+ int only_count;
};
/*!
* \brief Gets Asterisk system information.
Modified: team/dlee/allow-multiple/res/stasis_http/resource_bridges.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/stasis_http/resource_bridges.c?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/stasis_http/resource_bridges.c (original)
+++ team/dlee/allow-multiple/res/stasis_http/resource_bridges.c Thu Jul 25 08:34:21 2013
@@ -1,4 +1,4 @@
-/* -*- C -*-
+/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2012 - 2013, Digium, Inc.
@@ -107,33 +107,81 @@
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 stasis_http_response *response, size_t count, const char **channels) {
+ RAII_VAR(struct control_list *, list, NULL, ao2_cleanup);
+ size_t i;
+
+ if (count <= 0 || !channels) {
+ stasis_http_response_error(response, 400, "Bad Request", "Missing parameter channel");
+ return NULL;
+ }
+
+ list = ao2_alloc(sizeof(*list), control_list_dtor);
+ if (!list) {
+ stasis_http_response_alloc_failed(response);
+ return NULL;
+ }
+
+ for (i = 0; i < count; ++i) {
+ list->controls[i] = find_channel_control(response, channels[i]);
+ if (!list->controls[i]) {
+ return NULL;
+ }
+ }
+
+ ao2_ref(list, +1);
+ return list;
+}
+
void stasis_http_add_channel_to_bridge(struct ast_variable *headers, struct ast_add_channel_to_bridge_args *args, struct stasis_http_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) {
return;
}
- control = find_channel_control(response, args->channel);
- if (!control) {
- return;
- }
-
- stasis_app_control_add_channel_to_bridge(control, bridge);
+ list = control_list_create(response, args->channel_count, args->channel);
+ if (!list) {
+ return;
+ }
+
+ for (i = 0; i < list->count; ++i) {
+ stasis_app_control_add_channel_to_bridge(list->controls[i], bridge);
+ }
+
stasis_http_response_no_content(response);
}
void stasis_http_remove_channel_from_bridge(struct ast_variable *headers, struct ast_remove_channel_from_bridge_args *args, struct stasis_http_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) {
return;
}
- control = find_channel_control(response, args->channel);
- if (!control) {
+ list = control_list_create(response, args->channel_count, args->channel);
+ if (!list) {
return;
}
@@ -141,10 +189,12 @@
* 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)) {
- stasis_http_response_error(response, 500, "Internal Error",
- "Could not remove channel from bridge");
- return;
+ for (i = 0; i < list->count; ++i) {
+ if (stasis_app_control_remove_channel_from_bridge(list->controls[i], bridge)) {
+ stasis_http_response_error(response, 500, "Internal Error",
+ "Could not remove channel from bridge");
+ return;
+ }
}
stasis_http_response_no_content(response);
Modified: team/dlee/allow-multiple/res/stasis_http/resource_bridges.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/stasis_http/resource_bridges.h?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/stasis_http/resource_bridges.h (original)
+++ team/dlee/allow-multiple/res/stasis_http/resource_bridges.h Thu Jul 25 08:34:21 2013
@@ -98,7 +98,8 @@
/*! \brief Bridge's id */
const char *bridge_id;
/*! \brief Channel's id */
- const char *channel;
+ const char **channel;
+ int channel_count;
};
/*!
* \brief Add a channel to a bridge.
@@ -113,7 +114,8 @@
/*! \brief Bridge's id */
const char *bridge_id;
/*! \brief Channel's id */
- const char *channel;
+ const char **channel;
+ int channel_count;
};
/*!
* \brief Remove a channel from a bridge.
Modified: team/dlee/allow-multiple/res/stasis_http/resource_events.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/stasis_http/resource_events.c?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/stasis_http/resource_events.c (original)
+++ team/dlee/allow-multiple/res/stasis_http/resource_events.c Thu Jul 25 08:34:21 2013
@@ -169,6 +169,7 @@
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");
@@ -192,7 +193,11 @@
return;
}
- res = session_register_apps(session, args->app);
+ res = 0;
+ for (i = 0; i < args->app_count; ++i) {
+ res |= session_register_apps(session, args->app[i]);
+ }
+
if (res != 0) {
ari_websocket_session_write(ws_session, ari_oom_json());
return;
Modified: team/dlee/allow-multiple/res/stasis_http/resource_events.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/res/stasis_http/resource_events.h?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/res/stasis_http/resource_events.h (original)
+++ team/dlee/allow-multiple/res/stasis_http/resource_events.h Thu Jul 25 08:34:21 2013
@@ -42,7 +42,8 @@
/*! \brief Argument struct for stasis_http_event_websocket() */
struct ast_event_websocket_args {
/*! \brief Comma seperated list of applications to subscribe to. */
- const char *app;
+ const char **app;
+ int app_count;
};
/*!
* \brief WebSocket connection for events.
Modified: team/dlee/allow-multiple/rest-api-templates/param_parsing.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/rest-api-templates/param_parsing.mustache?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/rest-api-templates/param_parsing.mustache (original)
+++ team/dlee/allow-multiple/rest-api-templates/param_parsing.mustache Thu Jul 25 08:34:21 2013
@@ -25,9 +25,23 @@
{{#has_query_parameters}}
for (i = get_params; i; i = i->next) {
{{#query_parameters}}
+{{^allow_multiple}}
if (strcmp(i->name, "{{name}}") == 0) {
args.{{c_name}} = {{c_convert}}(i->value);
} else
+{{/allow_multiple}}
+{{#allow_multiple}}
+ if (strcmp(i->name, "{{name}}") == 0) {
+ void *p = ast_realloc(args.{{c_name}},
+ sizeof(*args.{{c_name}}) * (args.{{c_name}}_count + 1));
+ if (!p) {
+ ast_log(LOG_ERROR, "OOM parsing {{c_name}}\n");
+ continue;
+ }
+ args.{{c_name}} = p;
+ args.{{c_name}}[args.{{c_name}}_count++] = {{c_convert}}(i->value);
+ } else
+{{/allow_multiple}}
{{/query_parameters}}
{}
}
Modified: team/dlee/allow-multiple/rest-api-templates/stasis_http_resource.h.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/rest-api-templates/stasis_http_resource.h.mustache?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/rest-api-templates/stasis_http_resource.h.mustache (original)
+++ team/dlee/allow-multiple/rest-api-templates/stasis_http_resource.h.mustache Thu Jul 25 08:34:21 2013
@@ -46,7 +46,13 @@
{{#description}}
/*! \brief {{{description}}} */
{{/description}}
+{{^allow_multiple}}
{{c_data_type}}{{c_space}}{{c_name}};
+{{/allow_multiple}}
+{{#allow_multiple}}
+ {{c_data_type}}{{c_space}}*{{c_name}};
+ int {{c_name}}_count;
+{{/allow_multiple}}
{{/parameters}}
};
{{#is_req}}
Modified: team/dlee/allow-multiple/rest-api/api-docs/bridges.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/rest-api/api-docs/bridges.json?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/rest-api/api-docs/bridges.json (original)
+++ team/dlee/allow-multiple/rest-api/api-docs/bridges.json Thu Jul 25 08:34:21 2013
@@ -277,7 +277,7 @@
"description": "Format to encode audio in",
"paramType": "query",
"required": true,
- "allowMultiple": true,
+ "allowMultiple": false,
"dataType": "string"
},
{
Modified: team/dlee/allow-multiple/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/allow-multiple/rest-api/api-docs/channels.json?view=diff&rev=395395&r1=395394&r2=395395
==============================================================================
--- team/dlee/allow-multiple/rest-api/api-docs/channels.json (original)
+++ team/dlee/allow-multiple/rest-api/api-docs/channels.json Thu Jul 25 08:34:21 2013
@@ -634,7 +634,7 @@
"description": "Format to encode audio in",
"paramType": "query",
"required": true,
- "allowMultiple": true,
+ "allowMultiple": false,
"dataType": "string"
},
{
More information about the asterisk-commits
mailing list