asterisk/rest-api-templates/param_parsing.mustache
George Joseph 6691606723 ari: Implement 'debug all' and request/response logging
The 'ari set debug' command has been enhanced to accept 'all' as an
application name.  This allows dumping of all apps even if an app
hasn't registered yet.  To accomplish this, a new global_debug global
variable was added to res/stasis/app.c and new APIs were added to
set and query the value.

'ari set debug' now displays requests and responses as well as events.
This required refactoring the existing debug code.

* The implementation for 'ari set debug' was moved from stasis/cli.{c,h}
  to ari/cli.{c,h}, and stasis/cli.{c,h} were deleted.
* In order to print the body of incoming requests even if a request
  failed, the consumption of the body was moved from the ari stubs
  to ast_ari_callback in res_ari.c and the moustache templates were
  then regenerated.  The body is now passed to ast_ari_invoke and then
  on to the handlers.  This results in code savings since that template
  was inserted multiple times into all the stubs.

An additional change was made to the ao2_str_container implementation
to add partial key searching and a sort function.  The existing cli
code assumed it was already there when it wasn't so the tab completion
was never working.

Change-Id: Ief936f747ce47f1fb14035fbe61152cf766406bf
(cherry picked from commit 1d890874f3)
2017-01-23 10:25:58 -07:00

99 lines
2.5 KiB
Text

{{!
* 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) {
{{^allow_multiple}}
args.{{c_name}} = {{c_convert}}(i->value);
{{/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;
}
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));
}
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}}
} 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}}
{{^is_websocket}}
{{#parse_body}}
{{#body_parameter}}
args.{{c_name}} = body;
{{/body_parameter}}
{{^body_parameter}}
if (ast_ari_{{c_name}}_{{c_nickname}}_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
}
{{/body_parameter}}
{{/parse_body}}
{{/is_websocket}}