summaryrefslogtreecommitdiff
path: root/rest-api-templates
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-08-27 19:19:36 +0000
committerDavid M. Lee <dlee@digium.com>2013-08-27 19:19:36 +0000
commit451993f4f57331fae84a9c04b31fd5663ccfc593 (patch)
treeb9baca6011939f78f161e64e1f8382a6acaa2c82 /rest-api-templates
parent3540c7ac6eca33609c294baa1fbcf56722536f6a (diff)
ARI: WebSocket event cleanup
Stasis events (which get distributed over the ARI WebSocket) are created by subscribing to the channel_all_cached and bridge_all_cached topics, filtering out events for channels/bridges currently subscribed to. There are two issues with that. First was a race condition, where messages in-flight to the master subscribe-to-all-things topic would get sent out, even though the events happened before the channel was put into Stasis. Secondly, as the number of channels and bridges grow in the system, the work spent filtering messages becomes excessive. Since r395954, individual channels and bridges have caching topics, and can be subscribed to individually. This patch takes advantage, so that channels and bridges are subscribed to on demand, instead of filtering the global topics. The one case where filtering is still required is handling BridgeMerge messages, which are published directly to the bridge_all topic. Other than the change to how subscriptions work, this patch mostly just moves code around. Most of the work generating JSON objects from messages was moved to .to_json handlers on the message types. The callback functions handling app subscriptions were moved from res_stasis (b/c they were global to the model) to stasis/app.c (b/c they are local to the app now). (closes issue ASTERISK-21969) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2754/ ........ Merged revisions 397816 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397820 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'rest-api-templates')
-rw-r--r--rest-api-templates/param_parsing.mustache12
-rw-r--r--rest-api-templates/res_ari_resource.c.mustache10
2 files changed, 16 insertions, 6 deletions
diff --git a/rest-api-templates/param_parsing.mustache b/rest-api-templates/param_parsing.mustache
index 59c59e958..aabd728fd 100644
--- a/rest-api-templates/param_parsing.mustache
+++ b/rest-api-templates/param_parsing.mustache
@@ -36,8 +36,16 @@
goto fin;
}
- args.{{c_name}}_count = ast_app_separate_args(
- args.{{c_name}}_parse, ',', vals, ARRAY_LEN(vals));
+ if (strlen(args.{{c_name}}_parse) == 0) {
+ /* ast_app_separate_args can't handle "" */
+ args.{{c_name}}_count = 1;
+ vals[0] = args.{{c_name}}_parse;
+ } else {
+ args.{{c_name}}_count = ast_app_separate_args(
+ args.{{c_name}}_parse, ',', vals,
+ ARRAY_LEN(vals));
+ }
+
if (args.{{c_name}}_count == 0) {
ast_ari_response_alloc_failed(response);
goto fin;
diff --git a/rest-api-templates/res_ari_resource.c.mustache b/rest-api-templates/res_ari_resource.c.mustache
index 906d55f0d..e6b2a88f4 100644
--- a/rest-api-templates/res_ari_resource.c.mustache
+++ b/rest-api-templates/res_ari_resource.c.mustache
@@ -174,14 +174,16 @@ fin: __attribute__((unused))
* negotiation. Param parsing should happen earlier, but we
* need a way to pass it through the WebSocket code to the
* callback */
- RAII_VAR(char *, msg, NULL, ast_free);
+ RAII_VAR(char *, msg, NULL, ast_json_free);
if (response->message) {
msg = ast_json_dump_string(response->message);
} else {
- msg = ast_strdup("?");
+ ast_log(LOG_ERROR, "Missing response message\n");
+ }
+ if (msg) {
+ ast_websocket_write(ws_session,
+ AST_WEBSOCKET_OPCODE_TEXT, msg, strlen(msg));
}
- ast_websocket_write(ws_session, AST_WEBSOCKET_OPCODE_TEXT, msg,
- strlen(msg));
}
{{> param_cleanup}}
}