[asterisk-commits] stasis endpoint.c: Fix contactstatus to json(). (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jul 14 09:37:00 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: stasis_endpoint.c: Fix contactstatus_to_json().
......................................................................


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
---
M main/stasis_endpoints.c
1 file changed, 25 insertions(+), 9 deletions(-)

Approvals:
  Mark Michelson: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/main/stasis_endpoints.c b/main/stasis_endpoints.c
index 2d11421..c32dbb4 100644
--- a/main/stasis_endpoints.c
+++ b/main/stasis_endpoints.c
@@ -253,6 +253,7 @@
 	struct ast_endpoint_blob *obj = stasis_message_data(msg);
 	struct ast_json *json_endpoint;
 	struct ast_json *json_final;
+	const char *rtt;
 	const struct timeval *tv = stasis_message_timestamp(msg);
 
 	json_endpoint = ast_endpoint_snapshot_to_json(obj->snapshot, NULL);
@@ -260,15 +261,30 @@
 		return NULL;
 	}
 
-	json_final = ast_json_pack("{s: s, s: o, s: o, s: { s: 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")),
-		"roundtrip_usec", ast_json_string_get(ast_json_object_get(obj->blob, "roundtrip_usec")));
+	/* The roundtrip time is optional. */
+	rtt = ast_json_string_get(ast_json_object_get(obj->blob, "roundtrip_usec"));
+	if (!ast_strlen_zero(rtt)) {
+		json_final = ast_json_pack("{s: s, s: o, s: o, s: { s: 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")),
+			"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) {
 		ast_json_unref(json_endpoint);
 	}

-- 
To view, visit https://gerrit.asterisk.org/3197
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I39bb2f86154ef54591270c58bfda8635070f9ea0
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>



More information about the asterisk-commits mailing list