mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 20:04:50 +00:00
ARI event type filtering
Event type filtering is now enabled, and configurable per application. An app is now able to specify which events are sent to the application by configuring an allowed and/or disallowed list(s). This can be done by issuing the following: PUT /applications/{applicationName}/eventFilter And then enumerating the allowed/disallowed event types as a body parameter. ASTERISK-28106 Change-Id: I9671ba1fcdb3b6c830b553d4c5365aed5d588d5b
This commit is contained in:
committed by
George Joseph
parent
4a871c4b79
commit
1c5def4b18
@@ -459,6 +459,74 @@ fin: __attribute__((unused))
|
||||
ast_free(args.event_source);
|
||||
return;
|
||||
}
|
||||
int ast_ari_applications_filter_parse_body(
|
||||
struct ast_json *body,
|
||||
struct ast_ari_applications_filter_args *args)
|
||||
{
|
||||
/* Parse query parameters out of it */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Parameter parsing callback for /applications/{applicationName}/eventFilter.
|
||||
* \param get_params GET parameters in the HTTP request.
|
||||
* \param path_vars Path variables extracted from the request.
|
||||
* \param headers HTTP headers.
|
||||
* \param[out] response Response to the HTTP request.
|
||||
*/
|
||||
static void ast_ari_applications_filter_cb(
|
||||
struct ast_tcptls_session_instance *ser,
|
||||
struct ast_variable *get_params, struct ast_variable *path_vars,
|
||||
struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
|
||||
{
|
||||
struct ast_ari_applications_filter_args args = {};
|
||||
struct ast_variable *i;
|
||||
#if defined(AST_DEVMODE)
|
||||
int is_valid;
|
||||
int code;
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
for (i = path_vars; i; i = i->next) {
|
||||
if (strcmp(i->name, "applicationName") == 0) {
|
||||
args.application_name = (i->value);
|
||||
} else
|
||||
{}
|
||||
}
|
||||
args.filter = body;
|
||||
ast_ari_applications_filter(headers, &args, response);
|
||||
#if defined(AST_DEVMODE)
|
||||
code = response->response_code;
|
||||
|
||||
switch (code) {
|
||||
case 0: /* Implementation is still a stub, or the code wasn't set */
|
||||
is_valid = response->message == NULL;
|
||||
break;
|
||||
case 500: /* Internal Server Error */
|
||||
case 501: /* Not Implemented */
|
||||
case 400: /* Bad request. */
|
||||
case 404: /* Application does not exist. */
|
||||
is_valid = 1;
|
||||
break;
|
||||
default:
|
||||
if (200 <= code && code <= 299) {
|
||||
is_valid = ast_ari_validate_application(
|
||||
response->message);
|
||||
} else {
|
||||
ast_log(LOG_ERROR, "Invalid error response %d for /applications/{applicationName}/eventFilter\n", code);
|
||||
is_valid = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_valid) {
|
||||
ast_log(LOG_ERROR, "Response validation failed for /applications/{applicationName}/eventFilter\n");
|
||||
ast_ari_response_error(response, 500,
|
||||
"Internal Server Error", "Response validation failed");
|
||||
}
|
||||
#endif /* AST_DEVMODE */
|
||||
|
||||
fin: __attribute__((unused))
|
||||
return;
|
||||
}
|
||||
|
||||
/*! \brief REST handler for /api-docs/applications.json */
|
||||
static struct stasis_rest_handlers applications_applicationName_subscription = {
|
||||
@@ -471,14 +539,23 @@ static struct stasis_rest_handlers applications_applicationName_subscription = {
|
||||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/applications.json */
|
||||
static struct stasis_rest_handlers applications_applicationName_eventFilter = {
|
||||
.path_segment = "eventFilter",
|
||||
.callbacks = {
|
||||
[AST_HTTP_PUT] = ast_ari_applications_filter_cb,
|
||||
},
|
||||
.num_children = 0,
|
||||
.children = { }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/applications.json */
|
||||
static struct stasis_rest_handlers applications_applicationName = {
|
||||
.path_segment = "applicationName",
|
||||
.is_wildcard = 1,
|
||||
.callbacks = {
|
||||
[AST_HTTP_GET] = ast_ari_applications_get_cb,
|
||||
},
|
||||
.num_children = 1,
|
||||
.children = { &applications_applicationName_subscription, }
|
||||
.num_children = 2,
|
||||
.children = { &applications_applicationName_subscription,&applications_applicationName_eventFilter, }
|
||||
};
|
||||
/*! \brief REST handler for /api-docs/applications.json */
|
||||
static struct stasis_rest_handlers applications = {
|
||||
|
Reference in New Issue
Block a user