mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-22 13:25:17 +00:00
Corrected api-docs for channel variables
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393968 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -106,9 +106,14 @@ static void stasis_http_get_asterisk_info_cb(
|
|||||||
* \param[out] response Response to the HTTP request.
|
* \param[out] response Response to the HTTP request.
|
||||||
*/
|
*/
|
||||||
static void stasis_http_get_global_var_cb(
|
static void stasis_http_get_global_var_cb(
|
||||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||||
struct ast_variable *headers, struct stasis_http_response *response)
|
struct ast_variable *headers, struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
int is_valid;
|
||||||
|
int code;
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
|
|
||||||
struct ast_get_global_var_args args = {};
|
struct ast_get_global_var_args args = {};
|
||||||
struct ast_variable *i;
|
struct ast_variable *i;
|
||||||
|
|
||||||
@@ -119,6 +124,29 @@ static void stasis_http_get_global_var_cb(
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
stasis_http_get_global_var(headers, &args, response);
|
stasis_http_get_global_var(headers, &args, response);
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
code = response->response_code;
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case 500: /* Internal server error */
|
||||||
|
is_valid = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (200 <= code && code <= 299) {
|
||||||
|
is_valid = ari_validate_variable(
|
||||||
|
response->message);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/variable\n", code);
|
||||||
|
is_valid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_valid) {
|
||||||
|
ast_log(LOG_ERROR, "Response validation failed for /asterisk/variable\n");
|
||||||
|
stasis_http_response_error(response, 500,
|
||||||
|
"Internal Server Error", "Response validation failed");
|
||||||
|
}
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief Parameter parsing callback for /asterisk/variable.
|
* \brief Parameter parsing callback for /asterisk/variable.
|
||||||
@@ -128,9 +156,14 @@ static void stasis_http_get_global_var_cb(
|
|||||||
* \param[out] response Response to the HTTP request.
|
* \param[out] response Response to the HTTP request.
|
||||||
*/
|
*/
|
||||||
static void stasis_http_set_global_var_cb(
|
static void stasis_http_set_global_var_cb(
|
||||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||||
struct ast_variable *headers, struct stasis_http_response *response)
|
struct ast_variable *headers, struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
int is_valid;
|
||||||
|
int code;
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
|
|
||||||
struct ast_set_global_var_args args = {};
|
struct ast_set_global_var_args args = {};
|
||||||
struct ast_variable *i;
|
struct ast_variable *i;
|
||||||
|
|
||||||
@@ -144,6 +177,29 @@ static void stasis_http_set_global_var_cb(
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
stasis_http_set_global_var(headers, &args, response);
|
stasis_http_set_global_var(headers, &args, response);
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
code = response->response_code;
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case 500: /* Internal server error */
|
||||||
|
is_valid = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (200 <= code && code <= 299) {
|
||||||
|
is_valid = ari_validate_void(
|
||||||
|
response->message);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_ERROR, "Invalid error response %d for /asterisk/variable\n", code);
|
||||||
|
is_valid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_valid) {
|
||||||
|
ast_log(LOG_ERROR, "Response validation failed for /asterisk/variable\n");
|
||||||
|
stasis_http_response_error(response, 500,
|
||||||
|
"Internal Server Error", "Response validation failed");
|
||||||
|
}
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief REST handler for /api-docs/asterisk.{format} */
|
/*! \brief REST handler for /api-docs/asterisk.{format} */
|
||||||
|
@@ -818,9 +818,14 @@ static void stasis_http_record_channel_cb(
|
|||||||
* \param[out] response Response to the HTTP request.
|
* \param[out] response Response to the HTTP request.
|
||||||
*/
|
*/
|
||||||
static void stasis_http_get_channel_var_cb(
|
static void stasis_http_get_channel_var_cb(
|
||||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||||
struct ast_variable *headers, struct stasis_http_response *response)
|
struct ast_variable *headers, struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
int is_valid;
|
||||||
|
int code;
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
|
|
||||||
struct ast_get_channel_var_args args = {};
|
struct ast_get_channel_var_args args = {};
|
||||||
struct ast_variable *i;
|
struct ast_variable *i;
|
||||||
|
|
||||||
@@ -837,6 +842,31 @@ static void stasis_http_get_channel_var_cb(
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
stasis_http_get_channel_var(headers, &args, response);
|
stasis_http_get_channel_var(headers, &args, response);
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
code = response->response_code;
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case 500: /* Internal server error */
|
||||||
|
case 404: /* Channel not found */
|
||||||
|
case 409: /* Channel not in a Stasis application */
|
||||||
|
is_valid = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (200 <= code && code <= 299) {
|
||||||
|
is_valid = ari_validate_variable(
|
||||||
|
response->message);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
|
||||||
|
is_valid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_valid) {
|
||||||
|
ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
|
||||||
|
stasis_http_response_error(response, 500,
|
||||||
|
"Internal Server Error", "Response validation failed");
|
||||||
|
}
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
}
|
}
|
||||||
/*!
|
/*!
|
||||||
* \brief Parameter parsing callback for /channels/{channelId}/variable.
|
* \brief Parameter parsing callback for /channels/{channelId}/variable.
|
||||||
@@ -846,9 +876,14 @@ static void stasis_http_get_channel_var_cb(
|
|||||||
* \param[out] response Response to the HTTP request.
|
* \param[out] response Response to the HTTP request.
|
||||||
*/
|
*/
|
||||||
static void stasis_http_set_channel_var_cb(
|
static void stasis_http_set_channel_var_cb(
|
||||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||||
struct ast_variable *headers, struct stasis_http_response *response)
|
struct ast_variable *headers, struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
int is_valid;
|
||||||
|
int code;
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
|
|
||||||
struct ast_set_channel_var_args args = {};
|
struct ast_set_channel_var_args args = {};
|
||||||
struct ast_variable *i;
|
struct ast_variable *i;
|
||||||
|
|
||||||
@@ -868,6 +903,31 @@ static void stasis_http_set_channel_var_cb(
|
|||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
stasis_http_set_channel_var(headers, &args, response);
|
stasis_http_set_channel_var(headers, &args, response);
|
||||||
|
#if defined(AST_DEVMODE)
|
||||||
|
code = response->response_code;
|
||||||
|
|
||||||
|
switch (code) {
|
||||||
|
case 500: /* Internal server error */
|
||||||
|
case 404: /* Channel not found */
|
||||||
|
case 409: /* Channel not in a Stasis application */
|
||||||
|
is_valid = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (200 <= code && code <= 299) {
|
||||||
|
is_valid = ari_validate_void(
|
||||||
|
response->message);
|
||||||
|
} else {
|
||||||
|
ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/variable\n", code);
|
||||||
|
is_valid = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_valid) {
|
||||||
|
ast_log(LOG_ERROR, "Response validation failed for /channels/{channelId}/variable\n");
|
||||||
|
stasis_http_response_error(response, 500,
|
||||||
|
"Internal Server Error", "Response validation failed");
|
||||||
|
}
|
||||||
|
#endif /* AST_DEVMODE */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief REST handler for /api-docs/channels.{format} */
|
/*! \brief REST handler for /api-docs/channels.{format} */
|
||||||
|
@@ -57,6 +57,44 @@ ari_validator ari_validate_asterisk_info_fn(void)
|
|||||||
return ari_validate_asterisk_info;
|
return ari_validate_asterisk_info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ari_validate_variable(struct ast_json *json)
|
||||||
|
{
|
||||||
|
int res = 1;
|
||||||
|
struct ast_json_iter *iter;
|
||||||
|
int has_value = 0;
|
||||||
|
|
||||||
|
for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
|
||||||
|
if (strcmp("value", ast_json_object_iter_key(iter)) == 0) {
|
||||||
|
int prop_is_valid;
|
||||||
|
has_value = 1;
|
||||||
|
prop_is_valid = ari_validate_string(
|
||||||
|
ast_json_object_iter_value(iter));
|
||||||
|
if (!prop_is_valid) {
|
||||||
|
ast_log(LOG_ERROR, "ARI Variable field value failed validation\n");
|
||||||
|
res = 0;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
ast_log(LOG_ERROR,
|
||||||
|
"ARI Variable has undocumented field %s\n",
|
||||||
|
ast_json_object_iter_key(iter));
|
||||||
|
res = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has_value) {
|
||||||
|
ast_log(LOG_ERROR, "ARI Variable missing required field value\n");
|
||||||
|
res = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
ari_validator ari_validate_variable_fn(void)
|
||||||
|
{
|
||||||
|
return ari_validate_variable;
|
||||||
|
}
|
||||||
|
|
||||||
int ari_validate_endpoint(struct ast_json *json)
|
int ari_validate_endpoint(struct ast_json *json)
|
||||||
{
|
{
|
||||||
int res = 1;
|
int res = 1;
|
||||||
|
@@ -161,6 +161,24 @@ int ari_validate_asterisk_info(struct ast_json *json);
|
|||||||
*/
|
*/
|
||||||
ari_validator ari_validate_asterisk_info_fn(void);
|
ari_validator ari_validate_asterisk_info_fn(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Validator for Variable.
|
||||||
|
*
|
||||||
|
* The value of a channel variable
|
||||||
|
*
|
||||||
|
* \param json JSON object to validate.
|
||||||
|
* \returns True (non-zero) if valid.
|
||||||
|
* \returns False (zero) if invalid.
|
||||||
|
*/
|
||||||
|
int ari_validate_variable(struct ast_json *json);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Function pointer to ari_validate_variable().
|
||||||
|
*
|
||||||
|
* See \ref ari_model_validators.h for more details.
|
||||||
|
*/
|
||||||
|
ari_validator ari_validate_variable_fn(void);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Validator for Endpoint.
|
* \brief Validator for Endpoint.
|
||||||
*
|
*
|
||||||
@@ -767,6 +785,8 @@ ari_validator ari_validate_stasis_start_fn(void);
|
|||||||
* JSON models
|
* JSON models
|
||||||
*
|
*
|
||||||
* AsteriskInfo
|
* AsteriskInfo
|
||||||
|
* Variable
|
||||||
|
* - value: string (required)
|
||||||
* Endpoint
|
* Endpoint
|
||||||
* - channel_ids: List[string] (required)
|
* - channel_ids: List[string] (required)
|
||||||
* - resource: string (required)
|
* - resource: string (required)
|
||||||
|
@@ -92,8 +92,9 @@
|
|||||||
},
|
},
|
||||||
"Variable": {
|
"Variable": {
|
||||||
"id": "Variable",
|
"id": "Variable",
|
||||||
|
"description": "The value of a channel variable",
|
||||||
"properties": {
|
"properties": {
|
||||||
"variable": {
|
"value": {
|
||||||
"required": true,
|
"required": true,
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "The value of the variable requested"
|
"description": "The value of the variable requested"
|
||||||
|
@@ -654,7 +654,7 @@
|
|||||||
"httpMethod": "GET",
|
"httpMethod": "GET",
|
||||||
"summary": "Get the value of a channel variable or function.",
|
"summary": "Get the value of a channel variable or function.",
|
||||||
"nickname": "getChannelVar",
|
"nickname": "getChannelVar",
|
||||||
"responseClass": "ChannelVariable",
|
"responseClass": "Variable",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "channelId",
|
"name": "channelId",
|
||||||
@@ -827,16 +827,6 @@
|
|||||||
"description": "Timestamp when channel was created"
|
"description": "Timestamp when channel was created"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"Variable": {
|
|
||||||
"id": "Variable",
|
|
||||||
"properties": {
|
|
||||||
"variable": {
|
|
||||||
"required": true,
|
|
||||||
"type": "string",
|
|
||||||
"description": "The value of the variable requested"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user