stasis / manager / ari: Better filter messages.

Previously both AMI and ARI used a default route on
their stasis message router to handle some of the
messages for publishing out their respective
connection. This caused messages to be given to
their subscription that could not be formatted
into AMI or JSON.

This change adds an API call to the stasis message
router which allows a default route to be set as well
as formatters that the default route is expecting.
This allows both AMI and ARI to specify that their
default route only wants messages of their given
formatter. By doing so stasis can more intelligently
filter at publishing time so that they do not receive
messages which will not be turned into AMI or JSON.

ASTERISK-28244

Change-Id: I65272819a53ce99f869181d1d370da559a7d1703
This commit is contained in:
Joshua C. Colp
2019-01-10 15:34:32 -04:00
parent 44a862fb57
commit fcd07c34fb
5 changed files with 68 additions and 16 deletions

View File

@@ -387,19 +387,34 @@ void stasis_message_router_remove_cache_update(
int stasis_message_router_set_default(struct stasis_message_router *router,
stasis_subscription_cb callback,
void *data)
{
stasis_message_router_set_formatters_default(router, callback, data, STASIS_SUBSCRIPTION_FORMATTER_NONE);
/* While this implementation can never fail, it used to be able to */
return 0;
}
void stasis_message_router_set_formatters_default(struct stasis_message_router *router,
stasis_subscription_cb callback,
void *data,
enum stasis_subscription_message_formatters formatters)
{
ast_assert(router != NULL);
ast_assert(callback != NULL);
stasis_subscription_accept_formatters(router->subscription, formatters);
ao2_lock(router);
router->default_route.callback = callback;
router->default_route.data = data;
ao2_unlock(router);
stasis_subscription_set_filter(router->subscription, STASIS_SUBSCRIPTION_FILTER_FORCED_NONE);
/* While this implementation can never fail, it used to be able to */
return 0;
if (formatters == STASIS_SUBSCRIPTION_FORMATTER_NONE) {
/* Formatters govern what messages the default callback get, so it is only if none is
* specified that we accept all messages regardless.
*/
stasis_subscription_set_filter(router->subscription, STASIS_SUBSCRIPTION_FILTER_FORCED_NONE);
}
}
void stasis_message_router_accept_formatters(struct stasis_message_router *router,