summaryrefslogtreecommitdiff
path: root/main/stasis_channels.c
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2015-12-14 14:04:15 -0400
committerJoshua Colp <jcolp@digium.com>2015-12-16 15:21:14 -0600
commitd17d9a92886429b185b7bc2e02e429fc43d39652 (patch)
tree689dceca969ae2a0e0b1bcc7074784f5eb98cb34 /main/stasis_channels.c
parent093f14d7f3e6a84fc2e6baf2ff950a915e9f91d8 (diff)
json: Audit ast_json_* usage for thread safety.
The JSON library Asterisk uses, jansson, is not thread safe for us in a few ways. To help with this wrappers for JSON object reference count increasing and decreasing were added which use a global lock to ensure they don't clobber over each other. This does not extend to reference count manipulation within the jansson library itself. This means you can't safely use the object borrowing specifier (O) in ast_json_pack and you can't share JSON instances between objects. This change removes uses of the O specifier and replaces them with the o specifier and an explicit ast_json_ref. Some cases of instance sharing have also been removed. ASTERISK-25601 #close Change-Id: I06550d8b0cc1bfeb56cab580a4e608ae4f1ec7d1
Diffstat (limited to 'main/stasis_channels.c')
-rw-r--r--main/stasis_channels.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index 1a4a90f52..eb1f1bc62 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -1016,6 +1016,10 @@ static struct ast_json *dtmf_end_to_json(
struct ast_channel_snapshot *snapshot = channel_blob->snapshot;
const char *direction =
ast_json_string_get(ast_json_object_get(blob, "direction"));
+ const char *digit =
+ ast_json_string_get(ast_json_object_get(blob, "digit"));
+ long duration_ms =
+ ast_json_integer_get(ast_json_object_get(blob, "duration_ms"));
const struct timeval *tv = stasis_message_timestamp(message);
struct ast_json *json_channel;
@@ -1029,11 +1033,11 @@ static struct ast_json *dtmf_end_to_json(
return NULL;
}
- return ast_json_pack("{s: s, s: o, s: O, s: O, s: o}",
+ return ast_json_pack("{s: s, s: o, s: s, s: i, 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"),
+ "digit", digit,
+ "duration_ms", duration_ms,
"channel", json_channel);
}
@@ -1057,6 +1061,12 @@ static struct ast_json *dial_to_json(
{
struct ast_multi_channel_blob *payload = stasis_message_data(message);
struct ast_json *blob = ast_multi_channel_blob_get_json(payload);
+ const char *dialstatus =
+ ast_json_string_get(ast_json_object_get(blob, "dialstatus"));
+ const char *forward =
+ ast_json_string_get(ast_json_object_get(blob, "forward"));
+ const char *dialstring =
+ ast_json_string_get(ast_json_object_get(blob, "dialstring"));
struct ast_json *caller_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "caller"), sanitize);
struct ast_json *peer_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "peer"), sanitize);
struct ast_json *forwarded_json = ast_channel_snapshot_to_json(ast_multi_channel_blob_get_channel(payload, "forwarded"), sanitize);
@@ -1064,12 +1074,12 @@ static struct ast_json *dial_to_json(
const struct timeval *tv = stasis_message_timestamp(message);
int res = 0;
- json = ast_json_pack("{s: s, s: o, s: O, s: O, s: O}",
+ json = ast_json_pack("{s: s, s: o, s: s, s: s, s: s}",
"type", "Dial",
"timestamp", ast_json_timeval(*tv, NULL),
- "dialstatus", ast_json_object_get(blob, "dialstatus"),
- "forward", ast_json_object_get(blob, "forward"),
- "dialstring", ast_json_object_get(blob, "dialstring"));
+ "dialstatus", dialstatus,
+ "forward", forward,
+ "dialstring", dialstring);
if (!json) {
ast_json_unref(caller_json);
ast_json_unref(peer_json);