[asterisk-commits] dlee: branch dlee/ari-event-remodel2 r392410 - in /team/dlee/ari-event-remode...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 21 09:43:34 CDT 2013


Author: dlee
Date: Fri Jun 21 09:43:30 2013
New Revision: 392410

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392410
Log:
Removed some duplicate code; fixed late night build errors

Modified:
    team/dlee/ari-event-remodel2/main/stasis_channels.c
    team/dlee/ari-event-remodel2/res/res_stasis.c

Modified: team/dlee/ari-event-remodel2/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/main/stasis_channels.c?view=diff&rev=392410&r1=392409&r2=392410
==============================================================================
--- team/dlee/ari-event-remodel2/main/stasis_channels.c (original)
+++ team/dlee/ari-event-remodel2/main/stasis_channels.c Fri Jun 21 09:43:30 2013
@@ -668,6 +668,44 @@
 		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)
+{
+	RAII_VAR(struct ast_json *, out, NULL, ast_json_unref);
+	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);
+	int res = 0;
+
+	if (blob == NULL || ast_json_is_null(blob)) {
+		out = ast_json_object_create();
+	} else {
+		/* blobs are immutable, so shallow copies are fine */
+		out = ast_json_copy(blob);
+	}
+
+	if (!out) {
+		return NULL;
+	}
+
+	res |= ast_json_object_set(out, "type", ast_json_string_create(type));
+	res |= ast_json_object_set(out, "timestamp",
+		ast_json_timeval(*tv, NULL));
+
+	/* For global channel messages, the snapshot is optional */
+	if (snapshot) {
+		res |= ast_json_object_set(out, "channel",
+			ast_channel_snapshot_to_json(snapshot));
+	}
+
+	if (res != 0) {
+		return NULL;
+	}
+
+	return ast_json_ref(out);
+}
+
 static struct ast_json *dtmf_end_to_json(struct stasis_message *message)
 {
 	struct ast_channel_blob *channel_blob = stasis_message_data(message);
@@ -707,51 +745,12 @@
 
 static struct ast_json *varset_to_json(struct stasis_message *message)
 {
-	RAII_VAR(struct ast_json *, res, NULL, ast_json_unref);
-	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);
-
-	res = ast_json_pack("{s: s, s: o, s: o, s: o, s: o}",
-		"type", "ChannelVarset",
-		"timestamp", ast_json_timeval(*tv, NULL),
-		"variable", ast_json_ref(ast_json_object_get(blob, "eventname")),
-		"value", ast_json_ref(blob));
-
-	if (snapshot) {
-		ast_json_object_set(res, "channel",
-			ast_channel_snapshot_to_json(snapshot));
-	}
-
-	return ast_json_ref(res);
+	return channel_blob_to_json(message, "ChannelVarset");
 }
 
 static struct ast_json *hangup_request_to_json(struct stasis_message *message)
 {
-	RAII_VAR(struct ast_json *, res, NULL, ast_json_unref);
-	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;
-	struct ast_json *field;
-	const struct timeval *tv = stasis_message_timestamp(message);
-
-	res = ast_json_pack("{s: s, s: o, s: o, s: o, s: o}",
-		"type", "ChannelHangupRequest",
-		"timestamp", ast_json_timeval(*tv, NULL),
-		"channel", ast_channel_snapshot_to_json(snapshot));
-
-	field = ast_json_object_get(blob, "cause");
-	if (field) {
-		ast_json_object_set(res, "cause", ast_json_ref(field));
-	}
-
-	field = ast_json_object_get(blob, "soft");
-	if (field) {
-		ast_json_object_set(res, "soft", ast_json_ref(field));
-	}
-
-	return ast_json_ref(res);
+	return channel_blob_to_json(message, "ChannelHangupRequest");
 }
 
 /*!

Modified: team/dlee/ari-event-remodel2/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/res_stasis.c?view=diff&rev=392410&r1=392409&r2=392410
==============================================================================
--- team/dlee/ari-event-remodel2/res/res_stasis.c (original)
+++ team/dlee/ari-event-remodel2/res/res_stasis.c Fri Jun 21 09:43:30 2013
@@ -314,9 +314,9 @@
 	return ast_json_pack("{s: s, s: o, s: s, s: s, s: o}",
 		"type", "ChannelDialplan",
 		"timestamp", ast_json_timeval(*tv, NULL),
-		"dialplan_app", snapshot->appl,
-		"dialplan_app_data", snapshot->data,
-		"channel", ast_channel_snapshot_to_json(snapshot));
+		"dialplan_app", new_snapshot->appl,
+		"dialplan_app_data", new_snapshot->data,
+		"channel", ast_channel_snapshot_to_json(new_snapshot));
 }
 
 static struct ast_json *channel_callerid(
@@ -338,10 +338,10 @@
 	return ast_json_pack("{s: s, s: o, s: i, s: s, s: o}",
 		"type", "ChannelCallerId",
 		"timestamp", ast_json_timeval(*tv, NULL),
-		"caller_presentation", snapshot->caller_pres,
+		"caller_presentation", new_snapshot->caller_pres,
 		"caller_presentation_txt", ast_describe_caller_presentation(
-			snapshot->caller_pres));
-		"channel", ast_channel_snapshot_to_json(snapshot));
+			new_snapshot->caller_pres),
+		"channel", ast_channel_snapshot_to_json(new_snapshot));
 }
 
 channel_snapshot_monitor channel_monitors[] = {




More information about the asterisk-commits mailing list