[asterisk-commits] file: branch file/stasis_peerevent r389240 - /team/file/stasis_peerevent/chan...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon May 20 11:04:39 CDT 2013
Author: file
Date: Mon May 20 11:04:33 2013
New Revision: 389240
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389240
Log:
Move PeerStatus manager events over to sending endpoint blob stasis messages. This will most likely be tweaked still.
Modified:
team/file/stasis_peerevent/channels/chan_iax2.c
team/file/stasis_peerevent/channels/chan_sip.c
team/file/stasis_peerevent/channels/chan_skinny.c
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=389240&r1=389239&r2=389240
==============================================================================
--- team/file/stasis_peerevent/channels/chan_iax2.c (original)
+++ team/file/stasis_peerevent/channels/chan_iax2.c Mon May 20 11:04:33 2013
@@ -8543,6 +8543,7 @@
static void __expire_registry(const void *data)
{
struct iax2_peer *peer = (struct iax2_peer *) data;
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
if (!peer)
return;
@@ -8557,7 +8558,10 @@
if (ast_test_flag64((&globalflags), IAX_RTUPDATE) && (ast_test_flag64(peer, IAX_TEMPONLY|IAX_RTCACHEFRIENDS)))
realtime_update_peer(peer->name, &peer->addr, 0);
ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
+ blob = ast_json_pack("{s: s, s: s}",
+ "PeerStatus", "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);
/* Reset the address */
@@ -8682,6 +8686,8 @@
}
if (ast_sockaddr_cmp(&p->addr, &sockaddr)) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
if (iax2_regfunk) {
iax2_regfunk(p->name, 1);
}
@@ -8698,18 +8704,25 @@
ast_verb(3, "Registered IAX2 '%s' (%s) at %s:%d\n", p->name,
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);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\nPort: %d\r\n", p->name, ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
+ blob = ast_json_pack("{s: s, s: s, s: i}",
+ "PeerStatus", "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)) {
ast_verb(3, "Unregistered IAX2 '%s' (%s)\n", p->name,
ast_test_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED) ? "AUTHENTICATED" : "UNAUTHENTICATED");
ast_endpoint_set_state(p->endpoint, AST_ENDPOINT_OFFLINE);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unregistered\r\n", p->name);
+ blob = ast_json_pack("{s: s}",
+ "PeerStatus", "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 */
}
+
+ ast_endpoint_blob_publish(p->endpoint, ast_endpoint_state_type(), blob);
+
/* Update the host */
/* Verify that the host is really there */
iax2_poke_peer(p, callno);
@@ -10915,22 +10928,28 @@
log_jitterstats(fr->callno);
if (iaxs[fr->callno]->peerpoke) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
peer = iaxs[fr->callno]->peerpoke;
if ((peer->lastms < 0) || (peer->historicms > peer->maxms)) {
if (iaxs[fr->callno]->pingtime <= peer->maxms) {
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);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, iaxs[fr->callno]->pingtime);
+ blob = ast_json_pack("{s: s, s: i}",
+ "PeerStatus", "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)) {
if (iaxs[fr->callno]->pingtime > peer->maxms) {
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);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, iaxs[fr->callno]->pingtime);
+ blob = ast_json_pack("{s: s, s: i}",
+ "PeerStatus", "Lagged",
+ "Time", iaxs[fr->callno]->pingtime);
ast_devstate_changed(AST_DEVICE_UNAVAILABLE, AST_DEVSTATE_CACHABLE, "IAX2/%s", peer->name); /* Activate notification */
}
}
+ ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
peer->lastms = iaxs[fr->callno]->pingtime;
if (peer->smoothing && (peer->lastms > -1))
peer->historicms = (iaxs[fr->callno]->pingtime + peer->historicms) / 2;
@@ -12010,9 +12029,14 @@
int callno;
if (peer->lastms > -1) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
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);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: IAX2\r\nPeer: IAX2/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, peer->lastms);
+ blob = ast_json_pack("{s: s, s: i}",
+ "PeerStatus", "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 */
}
if ((callno = peer->callno) > 0) {
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=389240&r1=389239&r2=389240
==============================================================================
--- team/file/stasis_peerevent/channels/chan_sip.c (original)
+++ team/file/stasis_peerevent/channels/chan_sip.c Mon May 20 11:04:33 2013
@@ -15738,6 +15738,7 @@
static int expire_register(const void *data)
{
struct sip_peer *peer = (struct sip_peer *)data;
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
if (!peer) { /* Hmmm. We have no peer. Weird. */
return 0;
@@ -15758,7 +15759,10 @@
}
ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name);
+ blob = ast_json_pack("{s: s, s: s}",
+ "PeerStatus", "Unregistered",
+ "cause", "Expired");
+ ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
register_peer_exten(peer, FALSE); /* Remove regexten */
ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", peer->name);
@@ -16003,6 +16007,7 @@
int start = 0;
int wildcard_found = 0;
int single_binding_found = 0;
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact));
@@ -16191,7 +16196,10 @@
}
ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n", peer->name, ast_sockaddr_stringify(&peer->addr));
+ blob = ast_json_pack("{s: s, s: s}",
+ "PeerStatus", "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? */
if (ast_sockaddr_cmp(&peer->addr, &oldsin)) {
@@ -17195,6 +17203,7 @@
/* Create peer if we have autocreate mode enabled */
peer = temp_peer(name);
if (peer) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
ao2_t_link(peers, peer, "link peer into peer table");
if (!ast_sockaddr_isnull(&peer->addr)) {
ao2_t_link(peers_by_ip, peer, "link peer into peers-by-ip table");
@@ -17224,7 +17233,10 @@
/* Say OK and ask subsystem to retransmit msg counter */
transmit_response_with_date(p, "200 OK", req);
ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n", peer->name, ast_sockaddr_stringify(addr));
+ blob = ast_json_pack("{s: s, s: s}",
+ "PeerStatus", "Registered",
+ "Address", ast_sockaddr_stringify(addr));
+ ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
send_mwi = 1;
res = 0;
break;
@@ -17243,6 +17255,8 @@
ast_devstate_changed(AST_DEVICE_UNKNOWN, AST_DEVSTATE_CACHABLE, "SIP/%s", peer->name);
}
if (res < 0) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
switch (res) {
case AUTH_SECRET_FAILED:
/* Wrong password in authentication. Go away, don't try again until you fixed it */
@@ -17250,14 +17264,12 @@
if (global_authfailureevents) {
const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
- "ChannelType: SIP\r\n"
- "Peer: SIP/%s\r\n"
- "PeerStatus: Rejected\r\n"
- "Cause: AUTH_SECRET_FAILED\r\n"
- "Address: %s\r\n"
- "Port: %s\r\n",
- name, peer_addr, peer_port);
+
+ blob = ast_json_pack("{s: s, s: s, s: s, s: s}",
+ "PeerStatus", "Rejected",
+ "Cause", "AUTH_SECRET_FAILED",
+ "Address", peer_addr,
+ "Port", peer_port);
}
break;
case AUTH_USERNAME_MISMATCH:
@@ -17273,16 +17285,12 @@
if (global_authfailureevents) {
const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
- "ChannelType: SIP\r\n"
- "Peer: SIP/%s\r\n"
- "PeerStatus: Rejected\r\n"
- "Cause: %s\r\n"
- "Address: %s\r\n"
- "Port: %s\r\n",
- name,
- res == AUTH_PEER_NOT_DYNAMIC ? "AUTH_PEER_NOT_DYNAMIC" : "URI_NOT_FOUND",
- peer_addr, peer_port);
+
+ 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);
}
} else {
/* URI not found */
@@ -17291,30 +17299,24 @@
if (global_authfailureevents) {
const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
- "ChannelType: SIP\r\n"
- "Peer: SIP/%s\r\n"
- "PeerStatus: Rejected\r\n"
- "Cause: AUTH_PEER_NOT_DYNAMIC\r\n"
- "Address: %s\r\n"
- "Port: %s\r\n",
- name, peer_addr, peer_port);
+
+ 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);
}
} else {
transmit_response(p, "404 Not found", &p->initreq);
if (global_authfailureevents) {
const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr));
const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr));
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
- "ChannelType: SIP\r\n"
- "Peer: SIP/%s\r\n"
- "PeerStatus: Rejected\r\n"
- "Cause: %s\r\n"
- "Address: %s\r\n"
- "Port: %s\r\n",
- name,
- (res == AUTH_USERNAME_MISMATCH) ? "AUTH_USERNAME_MISMATCH" : "URI_NOT_FOUND",
- peer_addr, peer_port);
+
+ 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);
}
}
}
@@ -17323,6 +17325,8 @@
default:
break;
}
+
+ ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
}
if (peer) {
sip_unref_peer(peer, "register_verify: sip_unref_peer: tossing stack peer pointer at end of func");
@@ -23813,6 +23817,8 @@
if (statechanged) {
const char *s = is_reachable ? "Reachable" : "Lagged";
char str_lastms[20];
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
snprintf(str_lastms, sizeof(str_lastms), "%d", pingtime);
ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n",
@@ -23821,13 +23827,13 @@
if (sip_cfg.peer_rtupdate) {
ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", str_lastms, SENTINEL);
}
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
- "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n",
- peer->name, s, pingtime);
+ ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
+ blob = ast_json_pack("{s: s, s: i}",
+ "PeerStatus", 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);
-
- ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_ONLINE);
}
pvt_set_needdestroy(p, "got OPTIONS response");
@@ -29703,12 +29709,17 @@
peer->pokeexpire = -1;
if (peer->lastms > -1) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Last qualify: %d\n", peer->name, peer->lastms);
if (sip_cfg.peer_rtupdate) {
ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", "-1", SENTINEL);
}
ast_endpoint_set_state(peer->endpoint, AST_ENDPOINT_OFFLINE);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1);
+ blob = ast_json_pack("{s: s, s: s}",
+ "PeerStatus", "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=389240&r1=389239&r2=389240
==============================================================================
--- team/file/stasis_peerevent/channels/chan_skinny.c (original)
+++ team/file/stasis_peerevent/channels/chan_skinny.c Mon May 20 11:04:33 2013
@@ -2250,6 +2250,8 @@
ast_sockaddr_from_sin(&addr, &s->sin);
if (!d->session && !strcasecmp(req->data.reg.name, d->id)
&& ast_apply_ha(d->ha, &addr)) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
s->device = d;
d->type = letohl(req->data.reg.type);
d->protocolversion = letohl(req->data.reg.protocolVersion);
@@ -2283,7 +2285,6 @@
l->instance = instance;
l->newmsgs = ast_app_has_voicemail(l->mailbox, NULL);
set_callforwards(l, NULL, SKINNY_CFWD_ALL|SKINNY_CFWD_BUSY|SKINNY_CFWD_NOANSWER);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: Skinny\r\nPeer: Skinny/%s@%s\r\nPeerStatus: Registered\r\n", l->name, d->name);
register_exten(l);
/* initialize MWI on line and device */
mwi_event_cb(l, NULL, NULL, NULL);
@@ -2294,6 +2295,8 @@
--instance;
}
ast_endpoint_set_state(d->endpoint, AST_ENDPOINT_ONLINE);
+ blob = ast_json_pack("{s: s}", "PeerStatus", "Registered");
+ ast_endpoint_blob_publish(d->endpoint, ast_endpoint_state_type(), blob);
break;
}
}
@@ -2313,6 +2316,7 @@
d = s->device;
if (d) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
d->session = NULL;
AST_LIST_TRAVERSE(&d->speeddials, sd, list) {
@@ -2324,13 +2328,14 @@
ast_format_cap_remove_all(l->cap);
ast_parse_allow_disallow(&l->prefs, l->cap, "all", 0);
l->instance = 0;
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: Skinny\r\nPeer: Skinny/%s@%s\r\nPeerStatus: Unregistered\r\n", l->name, d->name);
unregister_exten(l);
ast_devstate_changed(AST_DEVICE_UNAVAILABLE, AST_DEVSTATE_CACHABLE, "Skinny/%s", l->name);
}
}
ast_endpoint_set_state(d->endpoint, AST_ENDPOINT_OFFLINE);
+ blob = ast_json_pack("{s: s}", "PeerStatus", "Unregistered");
+ ast_endpoint_blob_publish(d->endpoint, ast_endpoint_state_type(), blob);
}
return -1; /* main loop will destroy the session */
@@ -8656,6 +8661,8 @@
AST_LIST_LOCK(&sessions);
/* Destroy all the interfaces and free their memory */
while((s = AST_LIST_REMOVE_HEAD(&sessions, list))) {
+ RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+
d = s->device;
AST_LIST_TRAVERSE(&d->lines, l, list){
ast_mutex_lock(&l->lock);
@@ -8670,10 +8677,11 @@
l->mwi_event_sub = stasis_unsubscribe(l->mwi_event_sub);
}
ast_mutex_unlock(&l->lock);
- manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: Skinny\r\nPeer: Skinny/%s@%s\r\nPeerStatus: Unregistered\r\n", l->name, d->name);
unregister_exten(l);
}
ast_endpoint_set_state(d->endpoint, AST_ENDPOINT_OFFLINE);
+ blob = ast_json_pack("{s: s}", "PeerStatus", "Unregistered");
+ ast_endpoint_blob_publish(d->endpoint, ast_endpoint_state_type(), blob);
if (s->fd > -1)
close(s->fd);
pthread_cancel(s->t);
More information about the asterisk-commits
mailing list