[asterisk-commits] file: branch file/stasis_peerevent r391619 - in /team/file/stasis_peerevent: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 13 07:03:46 CDT 2013


Author: file
Date: Thu Jun 13 07:03:40 2013
New Revision: 391619

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391619
Log:
Incorporate review feedback.

Modified:
    team/file/stasis_peerevent/channels/chan_gulp.c
    team/file/stasis_peerevent/channels/chan_iax2.c
    team/file/stasis_peerevent/channels/chan_sip.c
    team/file/stasis_peerevent/channels/chan_skinny.c
    team/file/stasis_peerevent/main/manager_endpoints.c
    team/file/stasis_peerevent/main/stasis_endpoints.c
    team/file/stasis_peerevent/res/res_sip/sip_configuration.c

Modified: team/file/stasis_peerevent/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/channels/chan_gulp.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/channels/chan_gulp.c (original)
+++ team/file/stasis_peerevent/channels/chan_gulp.c Thu Jun 13 07:03:40 2013
@@ -637,12 +637,15 @@
 	enum ast_device_state state = AST_DEVICE_UNKNOWN;
 	RAII_VAR(struct ast_endpoint_snapshot *, endpoint_snapshot, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_caching_topic *, caching_topic, NULL, ao2_cleanup);
+	struct ast_devstate_aggregate aggregate;
+	int num, inuse = 0;
 
 	if (!endpoint) {
 		return AST_DEVICE_INVALID;
 	}
 
-	endpoint_snapshot = ast_endpoint_latest_snapshot(ast_endpoint_get_tech(endpoint->persistent), ast_endpoint_get_resource(endpoint->persistent), 1);
+	endpoint_snapshot = ast_endpoint_latest_snapshot(ast_endpoint_get_tech(endpoint->persistent),
+		ast_endpoint_get_resource(endpoint->persistent), 1);
 
 	if (endpoint_snapshot->state == AST_ENDPOINT_OFFLINE) {
 		state = AST_DEVICE_UNAVAILABLE;
@@ -650,40 +653,40 @@
 		state = AST_DEVICE_NOT_INUSE;
 	}
 
-	if (endpoint_snapshot->num_channels && (caching_topic = ast_channel_topic_all_cached())) {
-		struct ast_devstate_aggregate aggregate;
-		int num, inuse = 0;
-
-		ast_devstate_aggregate_init(&aggregate);
-
-		ao2_ref(caching_topic, +1);
-
-		for (num = 0; num < endpoint_snapshot->num_channels; num++) {
-			RAII_VAR(struct stasis_message *, msg, stasis_cache_get_extended(caching_topic, ast_channel_snapshot_type(), endpoint_snapshot->channel_ids[num], 1), ao2_cleanup);
-			struct ast_channel_snapshot *snapshot;
-
-			if (!msg) {
-				continue;
-			}
-
-			snapshot = stasis_message_data(msg);
-
-			if (snapshot->state == AST_STATE_DOWN) {
-				ast_devstate_aggregate_add(&aggregate, AST_DEVICE_NOT_INUSE);
-			} else if (snapshot->state == AST_STATE_RINGING) {
-				ast_devstate_aggregate_add(&aggregate, AST_DEVICE_RINGING);
-			} else if ((snapshot->state == AST_STATE_UP) || (snapshot->state == AST_STATE_RING) ||
-				(snapshot->state == AST_STATE_BUSY)) {
-				ast_devstate_aggregate_add(&aggregate, AST_DEVICE_INUSE);
-				inuse++;
-			}
-		}
-
-		if (endpoint->devicestate_busy_at && (inuse == endpoint->devicestate_busy_at)) {
-			state = AST_DEVICE_BUSY;
-		} else if (ast_devstate_aggregate_result(&aggregate) != AST_DEVICE_INVALID) {
-			state = ast_devstate_aggregate_result(&aggregate);
-		}
+	if (!endpoint_snapshot->num_channels || !(caching_topic = ast_channel_topic_all_cached())) {
+		return state;
+	}
+
+	ast_devstate_aggregate_init(&aggregate);
+
+	ao2_ref(caching_topic, +1);
+
+	for (num = 0; num < endpoint_snapshot->num_channels; num++) {
+		RAII_VAR(struct stasis_message *, msg, stasis_cache_get_extended(caching_topic, ast_channel_snapshot_type(),
+			endpoint_snapshot->channel_ids[num], 1), ao2_cleanup);
+		struct ast_channel_snapshot *snapshot;
+
+		if (!msg) {
+			continue;
+		}
+
+		snapshot = stasis_message_data(msg);
+
+		if (snapshot->state == AST_STATE_DOWN) {
+			ast_devstate_aggregate_add(&aggregate, AST_DEVICE_NOT_INUSE);
+		} else if (snapshot->state == AST_STATE_RINGING) {
+			ast_devstate_aggregate_add(&aggregate, AST_DEVICE_RINGING);
+		} else if ((snapshot->state == AST_STATE_UP) || (snapshot->state == AST_STATE_RING) ||
+			(snapshot->state == AST_STATE_BUSY)) {
+			ast_devstate_aggregate_add(&aggregate, AST_DEVICE_INUSE);
+			inuse++;
+		}
+	}
+
+	if (endpoint->devicestate_busy_at && (inuse == endpoint->devicestate_busy_at)) {
+		state = AST_DEVICE_BUSY;
+	} else if (ast_devstate_aggregate_result(&aggregate) != AST_DEVICE_INVALID) {
+		state = ast_devstate_aggregate_result(&aggregate);
 	}
 
 	return state;

Modified: team/file/stasis_peerevent/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/channels/chan_iax2.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/channels/chan_iax2.c (original)
+++ team/file/stasis_peerevent/channels/chan_iax2.c Thu Jun 13 07:03:40 2013
@@ -8583,8 +8583,8 @@
 		realtime_update_peer(peer->name, &peer->addr, 0);
 	ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
 	blob = ast_json_pack("{s: s, s: s}",
-		"PeerStatus", "Unregistered",
-		"Cause", "Expired");
+		"peer_status", "Unregistered",
+		"cause", "Expired");
 	ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 	/* modify entry in peercnts table as _not_ registered */
 	peercnt_modify(0, 0, &peer->addr);
@@ -8729,9 +8729,9 @@
 					    ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
 			ast_endpoint_set_state(p->endpoint, AST_ENDPOINT_ONLINE);
 			blob = ast_json_pack("{s: s, s: s, s: i}",
-				"PeerStatus", "Registered",
-				"Address", ast_inet_ntoa(sin->sin_addr),
-				"Port", ntohs(sin->sin_port));
+				"peer_status", "Registered",
+				"address", ast_inet_ntoa(sin->sin_addr),
+				"port", ntohs(sin->sin_port));
 			register_peer_exten(p, 1);
 			ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "IAX2/%s", p->name); /* Activate notification */
 		} else if (!ast_test_flag64(p, IAX_TEMPONLY)) {
@@ -8739,7 +8739,7 @@
 					    ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED");
 			ast_endpoint_set_state(p->endpoint, AST_ENDPOINT_OFFLINE);
 			blob = ast_json_pack("{s: s}",
-				"PeerStatus", "Unregistered");
+				"peer_status", "Unregistered");
 			register_peer_exten(p, 0);
 			ast_db_del("IAX/Registry", p->name);
 			ast_devstate_changed(AST_DEVICE_UNAVAILABLE, AST_DEVSTATE_CACHABLE, "IAX2/%s", p->name); /* Activate notification */
@@ -10786,8 +10786,8 @@
 							ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! Time: %d\n", peer->name, iaxs[fr->callno]->pingtime);
 							ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
 							blob = ast_json_pack("{s: s, s: i}",
-								"PeerStatus", "Reachable",
-								"Time", iaxs[fr->callno]->pingtime);
+								"peer_status", "Reachable",
+								"time", iaxs[fr->callno]->pingtime);
 							ast_devstate_changed(AST_DEVICE_NOT_INUSE, AST_DEVSTATE_CACHABLE, "IAX2/%s", peer->name); /* Activate notification */
 						}
 					} else if ((peer->historicms > 0) && (peer->historicms <= peer->maxms)) {
@@ -10795,8 +10795,8 @@
 							ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED (%d ms)!\n", peer->name, iaxs[fr->callno]->pingtime);
 							ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
 							blob = ast_json_pack("{s: s, s: i}",
-								"PeerStatus", "Lagged",
-								"Time", iaxs[fr->callno]->pingtime);
+								"peer_status", "Lagged",
+								"time", iaxs[fr->callno]->pingtime);
 							ast_devstate_changed(AST_DEVICE_UNAVAILABLE, AST_DEVSTATE_CACHABLE, "IAX2/%s", peer->name); /* Activate notification */
 						}
 					}
@@ -11919,8 +11919,8 @@
 		ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Time: %d\n", peer->name, peer->lastms);
 		ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
 		blob = ast_json_pack("{s: s, s: i}",
-			"PeerStatus", "Unreachable",
-			"Time", peer->lastms);
+			"peer_status", "Unreachable",
+			"time", peer->lastms);
 		ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 		ast_devstate_changed(AST_DEVICE_UNAVAILABLE, AST_DEVSTATE_CACHABLE, "IAX2/%s", peer->name); /* Activate notification */
 	}

Modified: team/file/stasis_peerevent/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/channels/chan_sip.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/channels/chan_sip.c (original)
+++ team/file/stasis_peerevent/channels/chan_sip.c Thu Jun 13 07:03:40 2013
@@ -15746,7 +15746,7 @@
 
 	ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
 	blob = ast_json_pack("{s: s, s: s}",
-		"PeerStatus", "Unregistered",
+		"peer_status", "Unregistered",
 		"cause", "Expired");
 	ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 	register_peer_exten(peer, FALSE);	/* Remove regexten */
@@ -16183,8 +16183,8 @@
 
 	ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
 	blob = ast_json_pack("{s: s, s: s}",
-		"PeerStatus", "Registered",
-		"Address", ast_sockaddr_stringify(&peer->addr));
+		"peer_status", "Registered",
+		"address", ast_sockaddr_stringify(&peer->addr));
 	ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 
 	/* Is this a new IP address for us? */
@@ -17220,8 +17220,8 @@
 				transmit_response_with_date(p, "200 OK", req);
 				ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
 				blob = ast_json_pack("{s: s, s: s}",
-					"PeerStatus", "Registered",
-					"Address", ast_sockaddr_stringify(addr));
+					"peer_status", "Registered",
+					"address", ast_sockaddr_stringify(addr));
 				ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 				send_mwi = 1;
 				res = 0;
@@ -17252,10 +17252,10 @@
 				const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
 
 				blob = ast_json_pack("{s: s, s: s, s: s, s: s}",
-					"PeerStatus", "Rejected",
-					"Cause", "AUTH_SECRET_FAILED",
-					"Address", peer_addr,
-					"Port", peer_port);
+					"peer_status", "Rejected",
+					"cause", "AUTH_SECRET_FAILED",
+					"address", peer_addr,
+					"port", peer_port);
 			}
 			break;
 		case AUTH_USERNAME_MISMATCH:
@@ -17273,10 +17273,10 @@
 					const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
 
 					blob = ast_json_pack("{s: s, s: s, s: s, s: s}",
-						"PeerStatus", "Rejected",
-						"Cause", res == AUTH_PEER_NOT_DYNAMIC ? "AUTH_PEER_NOT_DYNAMIC" : "URI_NOT_FOUND",
-						"Address", peer_addr,
-						"Port", peer_port);
+						"peer_status", "Rejected",
+						"cause", res == AUTH_PEER_NOT_DYNAMIC ? "AUTH_PEER_NOT_DYNAMIC" : "URI_NOT_FOUND",
+						"address", peer_addr,
+						"port", peer_port);
 				}
 			} else {
 				/* URI not found */
@@ -17287,10 +17287,10 @@
 						const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
 
 						blob = ast_json_pack("{s: s, s: s, s: s, s: s}",
-							"PeerStatus", "Rejected",
-							"Cause", "AUTH_PEER_NOT_DYNAMIC",
-							"Address", peer_addr,
-							"Port", peer_port);
+							"peer_status", "Rejected",
+							"cause", "AUTH_PEER_NOT_DYNAMIC",
+							"address", peer_addr,
+							"port", peer_port);
 					}
 				} else {
 					transmit_response(p, "404 Not found", &p->initreq);
@@ -17299,10 +17299,10 @@
 						const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
 
 						blob = ast_json_pack("{s: s, s: s, s: s, s: s}",
-							"PeerStatus", "Rejected",
-							"Cause", (res == AUTH_USERNAME_MISMATCH) ? "AUTH_USERNAME_MISMATCH" : "URI_NOT_FOUND",
-							"Address", peer_addr,
-							"Port", peer_port);
+							"peer_status", "Rejected",
+							"cause", (res == AUTH_USERNAME_MISMATCH) ? "AUTH_USERNAME_MISMATCH" : "URI_NOT_FOUND",
+							"address", peer_addr,
+							"port", peer_port);
 					}
 				}
 			}
@@ -23833,8 +23833,8 @@
 		}
 		ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
 		blob = ast_json_pack("{s: s, s: i}",
-			"PeerStatus", s,
-			"Time", pingtime);
+			"peer_status", s,
+			"time", pingtime);
 		ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 		if (is_reachable && sip_cfg.regextenonqualify)
 			register_peer_exten(peer, TRUE);
@@ -29123,8 +29123,8 @@
 		}
 		ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
 		blob = ast_json_pack("{s: s, s: s}",
-			"PeerStatus", "Unreachable",
-			"Time", "-1");
+			"peer_status", "Unreachable",
+			"time", "-1");
 		ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
 		if (sip_cfg.regextenonqualify) {
 			register_peer_exten(peer, FALSE);

Modified: team/file/stasis_peerevent/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/channels/chan_skinny.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/channels/chan_skinny.c (original)
+++ team/file/stasis_peerevent/channels/chan_skinny.c Thu Jun 13 07:03:40 2013
@@ -2297,7 +2297,7 @@
 				--instance;
 			}
 			ast_endpoint_set_state(d->endpoint, AST_ENDPOINT_ONLINE);
-			blob = ast_json_pack("{s: s}", "PeerStatus", "Registered");
+			blob = ast_json_pack("{s: s}", "peer_status", "Registered");
 			ast_endpoint_blob_publish(d->endpoint, ast_endpoint_state_type(), blob);
 			break;
 		}
@@ -2336,7 +2336,7 @@
 		}
 
 		ast_endpoint_set_state(d->endpoint, AST_ENDPOINT_OFFLINE);
-		blob = ast_json_pack("{s: s}", "PeerStatus", "Unregistered");
+		blob = ast_json_pack("{s: s}", "peer_status", "Unregistered");
 		ast_endpoint_blob_publish(d->endpoint, ast_endpoint_state_type(), blob);
 	}
 
@@ -8648,7 +8648,7 @@
 			unregister_exten(l);
 		}
 		ast_endpoint_set_state(d->endpoint, AST_ENDPOINT_OFFLINE);
-		blob = ast_json_pack("{s: s}", "PeerStatus", "Unregistered");
+		blob = ast_json_pack("{s: s}", "peer_status", "Unregistered");
 		ast_endpoint_blob_publish(d->endpoint, ast_endpoint_state_type(), blob);
 		if (s->fd > -1)
 			close(s->fd);

Modified: team/file/stasis_peerevent/main/manager_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/main/manager_endpoints.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/main/manager_endpoints.c (original)
+++ team/file/stasis_peerevent/main/manager_endpoints.c Thu Jun 13 07:03:40 2013
@@ -39,65 +39,25 @@
 
 static struct stasis_message_router *endpoint_router;
 
-/*!
- * \brief Callback used to determine whether a key should be skipped when converting a JSON object to a manager blob
- * \param key Key from JSON blob to be evaluated
- * \retval non-zero if the key should be excluded
- * \retval zero if the key should not be excluded
+/*! \brief The \ref stasis subscription returned by the forwarding of the endpoint topic
+ * to the manager topic
  */
-typedef int (*key_exclusion_cb)(const char *key);
-
-static struct ast_str *manager_str_from_json_object(struct ast_json *blob, key_exclusion_cb exclusion_cb)
-{
-	struct ast_str *output_str = ast_str_create(32);
-	struct ast_json_iter *blob_iter = ast_json_object_iter(blob);
-	if (!output_str || !blob_iter) {
-		return NULL;
-	}
-
-	do {
-		const char *key = ast_json_object_iter_key(blob_iter);
-		const char *value = ast_json_string_get(ast_json_object_iter_value(blob_iter));
-		if (exclusion_cb && exclusion_cb(key)) {
-			continue;
-		}
-
-		ast_str_append(&output_str, 0, "%s: %s\r\n", key, value);
-		if (!output_str) {
-			return NULL;
-		}
-	} while ((blob_iter = ast_json_object_iter_next(blob, blob_iter)));
-
-	return output_str;
-}
-
-static void endpoint_state_cb(void *data, struct stasis_subscription *sub,
-				    struct stasis_topic *topic,
-				    struct stasis_message *message)
-{
-	struct ast_endpoint_blob *obj = stasis_message_data(message);
-	RAII_VAR(struct ast_str *, peerstatus_event_string, NULL, ast_free);
-
-	peerstatus_event_string = manager_str_from_json_object(obj->blob, NULL);
-
-	manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
-		"ChannelType: %s\r\n"
-		"Peer: %s/%s\r\n"
-		"%s\r\n",
-		obj->snapshot->tech,
-		obj->snapshot->tech,
-		obj->snapshot->resource,
-		ast_str_buffer(peerstatus_event_string));
-}
+static struct stasis_subscription *topic_forwarder;
 
 static void manager_endpoints_shutdown(void)
 {
 	stasis_message_router_unsubscribe_and_join(endpoint_router);
 	endpoint_router = NULL;
+
+	stasis_unsubscribe(topic_forwarder);
+	topic_forwarder = NULL;
 }
 
 int manager_endpoints_init(void)
 {
+	struct stasis_topic *manager_topic;
+	struct stasis_topic *endpoint_topic;
+	struct stasis_message_router *message_router;
 	int ret = 0;
 
 	if (endpoint_router) {
@@ -107,17 +67,29 @@
 
 	ast_register_atexit(manager_endpoints_shutdown);
 
-	endpoint_router = stasis_message_router_create(
-		stasis_caching_get_topic(ast_endpoint_topic_all_cached()));
+	manager_topic = ast_manager_get_topic();
+	if (!manager_topic) {
+		return -1;
+	}
+	message_router = ast_manager_get_message_router();
+	if (!message_router) {
+		return -1;
+	}
+	endpoint_topic = stasis_caching_get_topic(ast_endpoint_topic_all_cached());
+	if (!endpoint_topic) {
+		return -1;
+	}
+
+	topic_forwarder = stasis_forward_all(endpoint_topic, manager_topic);
+	if (!topic_forwarder) {
+		return -1;
+	}
+
+	endpoint_router = stasis_message_router_create(endpoint_topic);
 
 	if (!endpoint_router) {
 		return -1;
 	}
-
-	ret |= stasis_message_router_add(endpoint_router,
-					 ast_endpoint_state_type(),
-					 endpoint_state_cb,
-					 NULL);
 
 	/* If somehow we failed to add any routes, just shut down the whole
 	 * thing and fail it.

Modified: team/file/stasis_peerevent/main/stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/main/stasis_endpoints.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/main/stasis_endpoints.c (original)
+++ team/file/stasis_peerevent/main/stasis_endpoints.c Thu Jun 13 07:03:40 2013
@@ -35,12 +35,89 @@
 #include "asterisk/stasis.h"
 #include "asterisk/stasis_endpoints.h"
 
+/*** DOCUMENTATION
+	<managerEvent language="en_US" name="PeerStatus">
+		<managerEventInstance class="EVENT_FLAG_SYSTEM">
+			<synopsis>Raised when the state of a peer changes.</synopsis>
+			<syntax>
+				<parameter name="ChannelType">
+					<para>The channel technology of the peer.</para>
+				</parameter>
+				<parameter name="Peer">
+					<para>The name of the peer (including channel technology).</para>
+				</parameter>
+				<parameter name="PeerStatus">
+					<para>New status of the peer.</para>
+					<enumlist>
+						<enum name="Unknown"/>
+						<enum name="Registered"/>
+						<enum name="Unregistered"/>
+						<enum name="Rejected"/>
+						<enum name="Lagged"/>
+					</enumlist>
+				</parameter>
+				<parameter name="Cause">
+					<para>The reason the status has changed.</para>
+				</parameter>
+				<parameter name="Address">
+					<para>New address of the peer.</para>
+				</parameter>
+				<parameter name="Port">
+					<para>New port for the peer.</para>
+				</parameter>
+				<parameter name="Time">
+					<para>Time it takes to reach the peer and receive a response.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+***/
+
+static struct ast_manager_event_blob *peerstatus_to_ami(struct stasis_message *msg);
+
 STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_snapshot_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_state_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_endpoint_state_type,
+	.to_ami = peerstatus_to_ami,
+);
 
 static struct stasis_topic *endpoint_topic_all;
 
 static struct stasis_caching_topic *endpoint_topic_all_cached;
+
+static struct ast_manager_event_blob *peerstatus_to_ami(struct stasis_message *msg)
+{
+	struct ast_endpoint_blob *obj = stasis_message_data(msg);
+	RAII_VAR(struct ast_str *, peerstatus_event_string, ast_str_create(64), ast_free);
+	const char *value;
+
+	/* peer_status is the only *required* thing */
+	if (!(value = ast_json_string_get(ast_json_object_get(obj->blob, "peer_status")))) {
+		return NULL;
+	}
+	ast_str_append(&peerstatus_event_string, 0, "PeerStatus: %s\r\n", value);
+
+	if ((value = ast_json_string_get(ast_json_object_get(obj->blob, "cause")))) {
+		ast_str_append(&peerstatus_event_string, 0, "Cause: %s\r\n", value);
+	}
+	if ((value = ast_json_string_get(ast_json_object_get(obj->blob, "address")))) {
+		ast_str_append(&peerstatus_event_string, 0, "Address: %s\r\n", value);
+	}
+	if ((value = ast_json_string_get(ast_json_object_get(obj->blob, "port")))) {
+		ast_str_append(&peerstatus_event_string, 0, "Port: %s\r\n", value);
+	}
+	if ((value = ast_json_string_get(ast_json_object_get(obj->blob, "time")))) {
+		ast_str_append(&peerstatus_event_string, 0, "Time: %s\r\n", value);
+	}
+
+	return ast_manager_event_blob_create(EVENT_FLAG_SYSTEM, "PeerStatus",
+		"ChannelType: %s\r\n"
+		"Peer: %s/%s\r\n"
+		"%s",
+		obj->snapshot->tech,
+		obj->snapshot->tech,
+		obj->snapshot->resource,
+		ast_str_buffer(peerstatus_event_string));
+}
 
 static void endpoint_blob_dtor(void *obj)
 {

Modified: team/file/stasis_peerevent/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/file/stasis_peerevent/res/res_sip/sip_configuration.c?view=diff&rev=391619&r1=391618&r2=391619
==============================================================================
--- team/file/stasis_peerevent/res/res_sip/sip_configuration.c (original)
+++ team/file/stasis_peerevent/res/res_sip/sip_configuration.c Thu Jun 13 07:03:40 2013
@@ -68,10 +68,10 @@
 
 	if ((contact = ast_sip_location_retrieve_contact_from_aor_list(persistent->aors))) {
 		ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_ONLINE);
-		blob = ast_json_pack("{s: s}", "PeerStatus", "Reachable");
+		blob = ast_json_pack("{s: s}", "peer_status", "Reachable");
 	} else {
 		ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_OFFLINE);
-		blob = ast_json_pack("{s: s}", "PeerStatus", "Unreachable");
+		blob = ast_json_pack("{s: s}", "peer_status", "Unreachable");
 	}
 
 	ast_endpoint_blob_publish(persistent->endpoint, ast_endpoint_state_type(), blob);




More information about the asterisk-commits mailing list