mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 03:50:31 +00:00
stasis_endpoint.c: Fix contactstatus_to_json().
The roundtrip_usec json member is optional. If it isn't present then don't put it into the converted json structure where ast_json_pack() will choke on it. Change-Id: I39bb2f86154ef54591270c58bfda8635070f9ea0
This commit is contained in:
@@ -253,6 +253,7 @@ static struct ast_json *contactstatus_to_json(struct stasis_message *msg, const
|
|||||||
struct ast_endpoint_blob *obj = stasis_message_data(msg);
|
struct ast_endpoint_blob *obj = stasis_message_data(msg);
|
||||||
struct ast_json *json_endpoint;
|
struct ast_json *json_endpoint;
|
||||||
struct ast_json *json_final;
|
struct ast_json *json_final;
|
||||||
|
const char *rtt;
|
||||||
const struct timeval *tv = stasis_message_timestamp(msg);
|
const struct timeval *tv = stasis_message_timestamp(msg);
|
||||||
|
|
||||||
json_endpoint = ast_endpoint_snapshot_to_json(obj->snapshot, NULL);
|
json_endpoint = ast_endpoint_snapshot_to_json(obj->snapshot, NULL);
|
||||||
@@ -260,15 +261,30 @@ static struct ast_json *contactstatus_to_json(struct stasis_message *msg, const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
json_final = ast_json_pack("{s: s, s: o, s: o, s: { s: s, s: s, s: s, s: s } } ",
|
/* The roundtrip time is optional. */
|
||||||
"type", "ContactStatusChange",
|
rtt = ast_json_string_get(ast_json_object_get(obj->blob, "roundtrip_usec"));
|
||||||
"timestamp", ast_json_timeval(*tv, NULL),
|
if (!ast_strlen_zero(rtt)) {
|
||||||
"endpoint", json_endpoint,
|
json_final = ast_json_pack("{s: s, s: o, s: o, s: { s: s, s: s, s: s, s: s } } ",
|
||||||
"contact_info",
|
"type", "ContactStatusChange",
|
||||||
"uri", ast_json_string_get(ast_json_object_get(obj->blob, "uri")),
|
"timestamp", ast_json_timeval(*tv, NULL),
|
||||||
"contact_status", ast_json_string_get(ast_json_object_get(obj->blob, "contact_status")),
|
"endpoint", json_endpoint,
|
||||||
"aor", ast_json_string_get(ast_json_object_get(obj->blob, "aor")),
|
"contact_info",
|
||||||
"roundtrip_usec", ast_json_string_get(ast_json_object_get(obj->blob, "roundtrip_usec")));
|
"uri", ast_json_string_get(ast_json_object_get(obj->blob, "uri")),
|
||||||
|
"contact_status", ast_json_string_get(ast_json_object_get(obj->blob,
|
||||||
|
"contact_status")),
|
||||||
|
"aor", ast_json_string_get(ast_json_object_get(obj->blob, "aor")),
|
||||||
|
"roundtrip_usec", rtt);
|
||||||
|
} else {
|
||||||
|
json_final = ast_json_pack("{s: s, s: o, s: o, s: { s: s, s: s, s: s } } ",
|
||||||
|
"type", "ContactStatusChange",
|
||||||
|
"timestamp", ast_json_timeval(*tv, NULL),
|
||||||
|
"endpoint", json_endpoint,
|
||||||
|
"contact_info",
|
||||||
|
"uri", ast_json_string_get(ast_json_object_get(obj->blob, "uri")),
|
||||||
|
"contact_status", ast_json_string_get(ast_json_object_get(obj->blob,
|
||||||
|
"contact_status")),
|
||||||
|
"aor", ast_json_string_get(ast_json_object_get(obj->blob, "aor")));
|
||||||
|
}
|
||||||
if (!json_final) {
|
if (!json_final) {
|
||||||
ast_json_unref(json_endpoint);
|
ast_json_unref(json_endpoint);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user