summaryrefslogtreecommitdiff
path: root/main/stasis_channels.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-11-22 20:10:46 +0000
committerKinsey Moore <kmoore@digium.com>2013-11-22 20:10:46 +0000
commitd9015a5356dfff70ce15ed2ea5726325de71d9e3 (patch)
treeb4b253dcc96a4cbc27f54ee294dae45264e12dbb /main/stasis_channels.c
parent1c45a32ee861fa427e0243abe03c729966fa4436 (diff)
ARI: Don't leak implementation details
This change prevents channels used as implementation details from leaking out to ARI. It does this by preventing creation of JSON blobs of channel snapshots created from those channels and sanitizing JSON blobs of bridge snapshots as they are created. This introduces a framework for excluding information from output targeted at Stasis applications on a consumer-by-consumer basis using channel sanitization callbacks which could be extended to bridges or endpoints if necessary. This prevents unhelpful error messages from being generated by ast_json_pack. This also corrects a bug where BridgeCreated events would not be created. (closes issue ASTERISK-22744) Review: https://reviewboard.asterisk.org/r/2987/ Reported by: David M. Lee ........ Merged revisions 403069 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403070 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stasis_channels.c')
-rw-r--r--main/stasis_channels.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index f178df35b..38aac982e 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -755,11 +755,15 @@ void ast_publish_channel_state(struct ast_channel *chan)
stasis_publish(ast_channel_topic(chan), message);
}
-struct ast_json *ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot)
+struct ast_json *ast_channel_snapshot_to_json(
+ const struct ast_channel_snapshot *snapshot,
+ const struct stasis_message_sanitizer *sanitize)
{
RAII_VAR(struct ast_json *, json_chan, NULL, ast_json_unref);
- if (snapshot == NULL) {
+ if (snapshot == NULL
+ || (sanitize && sanitize->channel_snapshot
+ && sanitize->channel_snapshot(snapshot))) {
return NULL;
}
@@ -817,8 +821,10 @@ int ast_channel_snapshot_caller_id_equal(
strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
}
-static struct ast_json *channel_blob_to_json(struct stasis_message *message,
- const char *type)
+static struct ast_json *channel_blob_to_json(
+ struct stasis_message *message,
+ const char *type,
+ const struct stasis_message_sanitizer *sanitize)
{
RAII_VAR(struct ast_json *, out, NULL, ast_json_unref);
struct ast_channel_blob *channel_blob = stasis_message_data(message);
@@ -844,8 +850,13 @@ static struct ast_json *channel_blob_to_json(struct stasis_message *message,
/* For global channel messages, the snapshot is optional */
if (snapshot) {
- res |= ast_json_object_set(out, "channel",
- ast_channel_snapshot_to_json(snapshot));
+ struct ast_json *json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
+
+ if (!json_channel) {
+ return NULL;
+ }
+
+ res |= ast_json_object_set(out, "channel", json_channel);
}
if (res != 0) {
@@ -855,7 +866,9 @@ static struct ast_json *channel_blob_to_json(struct stasis_message *message,
return ast_json_ref(out);
}
-static struct ast_json *dtmf_end_to_json(struct stasis_message *message)
+static struct ast_json *dtmf_end_to_json(
+ struct stasis_message *message,
+ const struct stasis_message_sanitizer *sanitize)
{
struct ast_channel_blob *channel_blob = stasis_message_data(message);
struct ast_json *blob = channel_blob->blob;
@@ -863,43 +876,59 @@ static struct ast_json *dtmf_end_to_json(struct stasis_message *message)
const char *direction =
ast_json_string_get(ast_json_object_get(blob, "direction"));
const struct timeval *tv = stasis_message_timestamp(message);
+ struct ast_json *json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
/* Only present received DTMF end events as JSON */
if (strcasecmp("Received", direction) != 0) {
return NULL;
}
+ if (!json_channel) {
+ return NULL;
+ }
+
return ast_json_pack("{s: s, s: o, s: O, s: O, s: o}",
"type", "ChannelDtmfReceived",
"timestamp", ast_json_timeval(*tv, NULL),
"digit", ast_json_object_get(blob, "digit"),
"duration_ms", ast_json_object_get(blob, "duration_ms"),
- "channel", ast_channel_snapshot_to_json(snapshot));
+ "channel", json_channel);
}
-static struct ast_json *user_event_to_json(struct stasis_message *message)
+static struct ast_json *user_event_to_json(
+ struct stasis_message *message,
+ const struct stasis_message_sanitizer *sanitize)
{
struct ast_channel_blob *channel_blob = stasis_message_data(message);
struct ast_json *blob = channel_blob->blob;
struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
const struct timeval *tv = stasis_message_timestamp(message);
+ struct ast_json *json_channel = ast_channel_snapshot_to_json(snapshot, sanitize);
+
+ if (!json_channel) {
+ return NULL;
+ }
return ast_json_pack("{s: s, s: o, s: O, s: O, s: o}",
"type", "ChannelUserevent",
"timestamp", ast_json_timeval(*tv, NULL),
"eventname", ast_json_object_get(blob, "eventname"),
"userevent", blob,
- "channel", ast_channel_snapshot_to_json(snapshot));
+ "channel", json_channel);
}
-static struct ast_json *varset_to_json(struct stasis_message *message)
+static struct ast_json *varset_to_json(
+ struct stasis_message *message,
+ const struct stasis_message_sanitizer *sanitize)
{
- return channel_blob_to_json(message, "ChannelVarset");
+ return channel_blob_to_json(message, "ChannelVarset", sanitize);
}
-static struct ast_json *hangup_request_to_json(struct stasis_message *message)
+static struct ast_json *hangup_request_to_json(
+ struct stasis_message *message,
+ const struct stasis_message_sanitizer *sanitize)
{
- return channel_blob_to_json(message, "ChannelHangupRequest");
+ return channel_blob_to_json(message, "ChannelHangupRequest", sanitize);
}
/*!