mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 11:58:52 +00:00
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
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
|
||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
|
||||
#include "asterisk/app.h"
|
||||
#include "asterisk/module.h"
|
||||
#include "asterisk/stasis_app.h"
|
||||
#include "ari/resource_asterisk.h"
|
||||
@@ -48,6 +49,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||
#include "ari/ari_model_validators.h"
|
||||
#endif
|
||||
|
||||
#define MAX_VALS 128
|
||||
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /asterisk/info.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
@@ -59,17 +62,48 @@ static void ast_ari_get_asterisk_info_cb(
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct ast_ari_response *response)
|
||||
{
|
||||
struct ast_get_asterisk_info_args args = {};
|
||||
struct ast_variable *i;
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
struct ast_get_asterisk_info_args args = {};
|
||||
struct ast_variable *i;
|
||||
|
||||
for (i = get_params; i; i = i->next) {
|
||||
if (strcmp(i->name, "only") == 0) {
|
||||
args.only = (i->value);
|
||||
/* Parse comma separated list */
|
||||
char *vals[MAX_VALS];
|
||||
size_t j;
|
||||
|
||||
args.only_parse = ast_strdup(i->value);
|
||||
if (!args.only_parse) {
|
||||
ast_ari_response_alloc_failed(response);
|
||||
goto fin;
|
||||
}
|
||||
|
||||
args.only_count = ast_app_separate_args(
|
||||
args.only_parse, ',', vals, ARRAY_LEN(vals));
|
||||
if (args.only_count == 0) {
|
||||
ast_ari_response_alloc_failed(response);
|
||||
goto fin;
|
||||
}
|
||||
|
||||
if (args.only_count >= MAX_VALS) {
|
||||
ast_ari_response_error(response, 400,
|
||||
"Bad Request",
|
||||
"Too many values for only");
|
||||
goto fin;
|
||||
}
|
||||
|
||||
args.only = ast_malloc(sizeof(*args.only) * args.only_count);
|
||||
if (!args.only) {
|
||||
ast_ari_response_alloc_failed(response);
|
||||
goto fin;
|
||||
}
|
||||
|
||||
for (j = 0; j < args.only_count; ++j) {
|
||||
args.only[j] = (vals[j]);
|
||||
}
|
||||
} else
|
||||
{}
|
||||
}
|
||||
@@ -101,6 +135,11 @@ static void ast_ari_get_asterisk_info_cb(
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
fin: __attribute__((unused))
|
||||
ast_free(args.only_parse);
|
||||
ast_free(args.only);
|
||||
return;
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /asterisk/variable.
|
||||
@@ -113,14 +152,13 @@ static void ast_ari_get_global_var_cb(
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct ast_ari_response *response)
|
||||
{
|
||||
struct ast_get_global_var_args args = {};
|
||||
struct ast_variable *i;
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
struct ast_get_global_var_args args = {};
|
||||
struct ast_variable *i;
|
||||
|
||||
for (i = get_params; i; i = i->next) {
|
||||
if (strcmp(i->name, "variable") == 0) {
|
||||
args.variable = (i->value);
|
||||
@@ -155,6 +193,9 @@ static void ast_ari_get_global_var_cb(
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
fin: __attribute__((unused))
|
||||
return;
|
||||
}
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /asterisk/variable.
|
||||
@@ -167,14 +208,13 @@ static void ast_ari_set_global_var_cb(
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct ast_ari_response *response)
|
||||
{
|
||||
struct ast_set_global_var_args args = {};
|
||||
struct ast_variable *i;
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
struct ast_set_global_var_args args = {};
|
||||
struct ast_variable *i;
|
||||
|
||||
for (i = get_params; i; i = i->next) {
|
||||
if (strcmp(i->name, "variable") == 0) {
|
||||
args.variable = (i->value);
|
||||
@@ -212,6 +252,9 @@ static void ast_ari_set_global_var_cb(
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
fin: __attribute__((unused))
|
||||
return;
|
||||
}
|
||||
|
||||
/*! \brief REST handler for /api-docs/asterisk.{format} */
|
||||
|
Reference in New Issue
Block a user