summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2015-09-04 12:25:07 -0500
committerMatt Jordan <mjordan@digium.com>2015-09-22 13:27:14 -0500
commit4c9f613309d66ae6a8e5454cd53276459bcd2674 (patch)
tree2934381535e27f1ca732865d3805a78af7dc06d0 /res/ari
parentec514ad64dbc0014525008977c8c74c2856c9d3a (diff)
ARI: Add the ability to subscribe to all events
This patch adds the ability to subscribe to all events. There are two possible ways to accomplish this: (1) On initial WebSocket connection. This patch adds a new query parameter, 'subscribeAll'. If present and True, Asterisk will subscribe the applications to all ARI events. (2) Via the applications resource. When subscribing in this manner, an ARI client should merely specify a blank resource name, i.e., 'channels:' instead of 'channels:12354'. This will subscribe the application to all resources of the 'channels' type. ASTERISK-24870 #close Change-Id: I4a943b4db24442cf28bc64b24bfd541249790ad6
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/resource_events.c24
-rw-r--r--res/ari/resource_events.h2
2 files changed, 22 insertions, 4 deletions
diff --git a/res/ari/resource_events.c b/res/ari/resource_events.c
index 09bcafc2d..71d54b494 100644
--- a/res/ari/resource_events.c
+++ b/res/ari/resource_events.c
@@ -148,9 +148,11 @@ static void app_handler(void *data, const char *app_name,
* \brief Register for all of the apps given.
* \param session Session info struct.
* \param app_name Name of application to register.
+ * \param register_handler Pointer to the application registration handler
*/
static int session_register_app(struct event_session *session,
- const char *app_name)
+ const char *app_name,
+ int (* register_handler)(const char *, stasis_app_cb handler, void *data))
{
SCOPED_AO2LOCK(lock, session);
@@ -167,7 +169,7 @@ static int session_register_app(struct event_session *session,
return -1;
}
- stasis_app_register(app_name, app_handler, session);
+ register_handler(app_name, app_handler, session);
return 0;
}
@@ -178,6 +180,7 @@ int ast_ari_websocket_events_event_websocket_attempted(struct ast_tcptls_session
{
int res = 0;
size_t i, j;
+ int (* register_handler)(const char *, stasis_app_cb handler, void *data);
ast_debug(3, "/events WebSocket attempted\n");
@@ -186,13 +189,19 @@ int ast_ari_websocket_events_event_websocket_attempted(struct ast_tcptls_session
return -1;
}
+ if (args->subscribe_all) {
+ register_handler = &stasis_app_register_all;
+ } else {
+ register_handler = &stasis_app_register;
+ }
+
for (i = 0; i < args->app_count; ++i) {
if (ast_strlen_zero(args->app[i])) {
res = -1;
break;
}
- res |= stasis_app_register(args->app[i], app_handler, NULL);
+ res |= register_handler(args->app[i], app_handler, NULL);
}
if (res) {
@@ -213,6 +222,7 @@ void ast_ari_websocket_events_event_websocket_established(struct ast_ari_websock
struct ast_json *msg;
int res;
size_t i;
+ int (* register_handler)(const char *, stasis_app_cb handler, void *data);
ast_debug(3, "/events WebSocket connection\n");
@@ -222,12 +232,18 @@ void ast_ari_websocket_events_event_websocket_established(struct ast_ari_websock
return;
}
+ if (args->subscribe_all) {
+ register_handler = &stasis_app_register_all;
+ } else {
+ register_handler = &stasis_app_register;
+ }
+
res = 0;
for (i = 0; i < args->app_count; ++i) {
if (ast_strlen_zero(args->app[i])) {
continue;
}
- res |= session_register_app(session, args->app[i]);
+ res |= session_register_app(session, args->app[i], register_handler);
}
if (ao2_container_count(session->websocket_apps) == 0) {
diff --git a/res/ari/resource_events.h b/res/ari/resource_events.h
index 2b631819b..c48269958 100644
--- a/res/ari/resource_events.h
+++ b/res/ari/resource_events.h
@@ -47,6 +47,8 @@ struct ast_ari_events_event_websocket_args {
size_t app_count;
/*! Parsing context for app. */
char *app_parse;
+ /*! Subscribe to all Asterisk events. If provided, the applications listed will be subscribed to all events, effectively disabling the application specific subscriptions. Default is 'false'. */
+ int subscribe_all;
};
/*!