2013-07-03 16:32:00 +00:00
|
|
|
{{!
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013, Digium, Inc.
|
|
|
|
*
|
|
|
|
* David M. Lee, II <dlee@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
}}
|
|
|
|
{{!
|
|
|
|
* Snippet for decoding parameters into an _args struct.
|
|
|
|
}}
|
|
|
|
{{#has_query_parameters}}
|
|
|
|
for (i = get_params; i; i = i->next) {
|
|
|
|
{{#query_parameters}}
|
|
|
|
if (strcmp(i->name, "{{name}}") == 0) {
|
2013-08-02 14:36:32 +00:00
|
|
|
{{^allow_multiple}}
|
2013-07-03 16:32:00 +00:00
|
|
|
args.{{c_name}} = {{c_convert}}(i->value);
|
2013-08-02 14:36:32 +00:00
|
|
|
{{/allow_multiple}}
|
|
|
|
{{#allow_multiple}}
|
|
|
|
/* Parse comma separated list */
|
|
|
|
char *vals[MAX_VALS];
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
args.{{c_name}}_parse = ast_strdup(i->value);
|
|
|
|
if (!args.{{c_name}}_parse) {
|
|
|
|
ast_ari_response_alloc_failed(response);
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
ARI: WebSocket event cleanup
Stasis events (which get distributed over the ARI WebSocket) are created
by subscribing to the channel_all_cached and bridge_all_cached topics,
filtering out events for channels/bridges currently subscribed to.
There are two issues with that. First was a race condition, where
messages in-flight to the master subscribe-to-all-things topic would get
sent out, even though the events happened before the channel was put
into Stasis. Secondly, as the number of channels and bridges grow in the
system, the work spent filtering messages becomes excessive.
Since r395954, individual channels and bridges have caching topics, and
can be subscribed to individually. This patch takes advantage, so that
channels and bridges are subscribed to on demand, instead of filtering
the global topics.
The one case where filtering is still required is handling BridgeMerge
messages, which are published directly to the bridge_all topic.
Other than the change to how subscriptions work, this patch mostly just
moves code around. Most of the work generating JSON objects from
messages was moved to .to_json handlers on the message types. The
callback functions handling app subscriptions were moved from res_stasis
(b/c they were global to the model) to stasis/app.c (b/c they are local
to the app now).
(closes issue ASTERISK-21969)
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/2754/
........
Merged revisions 397816 from http://svn.asterisk.org/svn/asterisk/branches/12
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397820 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2013-08-27 19:19:36 +00:00
|
|
|
if (strlen(args.{{c_name}}_parse) == 0) {
|
|
|
|
/* ast_app_separate_args can't handle "" */
|
|
|
|
args.{{c_name}}_count = 1;
|
|
|
|
vals[0] = args.{{c_name}}_parse;
|
|
|
|
} else {
|
|
|
|
args.{{c_name}}_count = ast_app_separate_args(
|
|
|
|
args.{{c_name}}_parse, ',', vals,
|
|
|
|
ARRAY_LEN(vals));
|
|
|
|
}
|
|
|
|
|
2013-08-02 14:36:32 +00:00
|
|
|
if (args.{{c_name}}_count == 0) {
|
|
|
|
ast_ari_response_alloc_failed(response);
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.{{c_name}}_count >= MAX_VALS) {
|
|
|
|
ast_ari_response_error(response, 400,
|
|
|
|
"Bad Request",
|
|
|
|
"Too many values for {{c_name}}");
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
args.{{c_name}} = ast_malloc(sizeof(*args.{{c_name}}) * args.{{c_name}}_count);
|
|
|
|
if (!args.{{c_name}}) {
|
|
|
|
ast_ari_response_alloc_failed(response);
|
|
|
|
goto fin;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0; j < args.{{c_name}}_count; ++j) {
|
|
|
|
args.{{c_name}}[j] = {{c_convert}}(vals[j]);
|
|
|
|
}
|
|
|
|
{{/allow_multiple}}
|
2013-07-03 16:32:00 +00:00
|
|
|
} else
|
|
|
|
{{/query_parameters}}
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
{{/has_query_parameters}}
|
|
|
|
{{#has_path_parameters}}
|
|
|
|
for (i = path_vars; i; i = i->next) {
|
|
|
|
{{#path_parameters}}
|
|
|
|
if (strcmp(i->name, "{{name}}") == 0) {
|
|
|
|
args.{{c_name}} = {{c_convert}}(i->value);
|
|
|
|
} else
|
|
|
|
{{/path_parameters}}
|
|
|
|
{}
|
|
|
|
}
|
|
|
|
{{/has_path_parameters}}
|
2013-11-27 15:48:39 +00:00
|
|
|
{{^is_websocket}}
|
|
|
|
{{#parse_body}}
|
|
|
|
{{#body_parameter}}
|
2015-01-23 15:21:56 +00:00
|
|
|
args.{{c_name}} = body;
|
2013-11-27 15:48:39 +00:00
|
|
|
{{/body_parameter}}
|
|
|
|
{{^body_parameter}}
|
2014-01-21 14:27:21 +00:00
|
|
|
if (ast_ari_{{c_name}}_{{c_nickname}}_parse_body(body, &args)) {
|
|
|
|
ast_ari_response_alloc_failed(response);
|
|
|
|
goto fin;
|
2013-11-27 15:48:39 +00:00
|
|
|
}
|
|
|
|
{{/body_parameter}}
|
|
|
|
{{/parse_body}}
|
|
|
|
{{/is_websocket}}
|