[asterisk-commits] branch oej/subscribemwi r10626 - in /team/oej/subscribemwi: channels/ configs/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Feb 21 07:24:17 MST 2006


Author: oej
Date: Tue Feb 21 08:24:14 2006
New Revision: 10626

URL: http://svn.digium.com/view/asterisk?rev=10626&view=rev
Log:
- Small fixes for better compliance

Modified:
    team/oej/subscribemwi/channels/chan_sip.c
    team/oej/subscribemwi/configs/sip.conf.sample

Modified: team/oej/subscribemwi/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/subscribemwi/channels/chan_sip.c?rev=10626&r1=10625&r2=10626&view=diff
==============================================================================
--- team/oej/subscribemwi/channels/chan_sip.c (original)
+++ team/oej/subscribemwi/channels/chan_sip.c Tue Feb 21 08:24:14 2006
@@ -5220,7 +5220,6 @@
 	case AST_EXTENSION_REMOVED:
 		add_header(&req, "Subscription-State", "terminated;reason=noresource");
 		break;
-		break;
 	default:
 		if (p->expiry)
 			add_header(&req, "Subscription-State", "active");
@@ -5301,6 +5300,12 @@
 	ast_build_string(&t, &maxbytes, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no");
 	ast_build_string(&t, &maxbytes, "Message-Account: sip:%s@%s\r\n", !ast_strlen_zero(vmexten) ? vmexten : default_vmexten, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain);
 	ast_build_string(&t, &maxbytes, "Voice-Message: %d/%d (0/0)\r\n", newmsgs, oldmsgs);
+	if (p->subscribed) {
+		if (p->expiry)
+			add_header(&req, "Subscription-State", "active");
+		else	/* Expired */
+			add_header(&req, "Subscription-State", "terminated;reason=timeout");
+	}
 
 	if (t > tmp + sizeof(tmp))
 		ast_log(LOG_WARNING, "Buffer overflow detected!!  (Please file a bug report)\n");
@@ -8434,7 +8439,7 @@
 
 static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions)
 {
-#define FORMAT3 "%-15.15s  %-10.10s  %-11.11s  %-15.15s  %-13.13s  %-15.15s\n"
+#define FORMAT3 "%-15.15s  %-10.10s  %-11.11s  %-15.15s  %-13.13s  %-15.15s %-10.10s\n"
 #define FORMAT2 "%-15.15s  %-10.10s  %-11.11s  %-11.11s  %-4.4s  %-7.7s  %-15.15s\n"
 #define FORMAT  "%-15.15s  %-10.10s  %-11.11s  %5.5d/%5.5d  %-4.4s  %-3.3s %-3.3s  %-15.15s\n"
 	struct sip_pvt *cur;
@@ -8446,8 +8451,8 @@
 	cur = iflist;
 	if (!subscriptions)
 		ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
-	else
-		ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type");
+	else 
+		ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
 	while (cur) {
 		if (cur->subscribed == NONE && !subscriptions) {
 			ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), 
@@ -8463,8 +8468,12 @@
 		if (cur->subscribed != NONE && subscriptions) {
 			ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
 				ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, 
-			   	cur->callid, cur->exten, ast_extension_state2str(cur->laststate), 
-				subscription_type2str(cur->subscribed));
+			   	cur->callid,
+				cur->subscribed == MWI_NOTIFICATION ? "--" : cur->exten,
+				cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate), 
+				subscription_type2str(cur->subscribed),
+				cur->subscribed == MWI_NOTIFICATION ? (cur->relatedpeer ? cur->relatedpeer->mailbox : "<none>") : "<none>"
+);
 			numchans++;
 		}
 		cur = cur->next;
@@ -10887,9 +10896,8 @@
 				return 0;
 			}
 
-			transmit_response(p, "200 OK", req);
  			p->subscribed = MWI_NOTIFICATION;
-			if (authpeer->mwipvt != p)
+			if (authpeer->mwipvt && authpeer->mwipvt != p)
 				sip_destroy(authpeer->mwipvt);
 			authpeer->mwipvt = p;	/* Link from peer to pvt */
 			p->relatedpeer = authpeer;	/* Link from pvt to peer */
@@ -10927,6 +10935,7 @@
 			sip_scheddestroy(p, (p->expiry + 10) * 1000);	/* Set timer for destruction of call at expiration */
 
 		if (p->subscribed == MWI_NOTIFICATION) {
+			transmit_response(p, "200 OK", req);
 			if (p->relatedpeer) {	/* Send first notification */
 				ASTOBJ_WRLOCK(p->relatedpeer);
 				sip_send_mwi_to_peer(p->relatedpeer);
@@ -11336,6 +11345,24 @@
 	transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten);
 	return 0;
 }
+
+/*! \brief Check whether peer needs a new MWI notification check */
+static int does_peer_need_mwi(struct sip_peer *peer) {
+	time_t t;
+
+	if(ast_test_flag((&peer->flags_page2), SIP_PAGE2_SUBSCRIBEMWIONLY) &&  !peer->mwipvt) {	/* We don't have a subscription */
+		time(&peer->lastmsgcheck);	/* Reset timer */
+		return FALSE;
+	}
+
+	time(&t);
+			
+	if (!ast_strlen_zero(peer->mailbox) && ((t - peer->lastmsgcheck) > global_mwitime)) 
+		return TRUE;
+
+	return FALSE;
+}
+
 
 /*! \brief The SIP monitoring thread 
 \note	This thread monitors all the SIP sessions and peers that needs notification of mwi
@@ -11439,7 +11466,7 @@
 		curpeernum = 0;
 		peer = NULL;
 		ASTOBJ_CONTAINER_TRAVERSE(&peerl, !peer, do {
-			if ((curpeernum > lastpeernum) && !ast_strlen_zero(iterator->mailbox) && ((t - iterator->lastmsgcheck) > global_mwitime)) {
+			if ((curpeernum > lastpeernum) && does_peer_need_mwi(iterator)) {
 				fastrestart = TRUE;
 				lastpeernum = curpeernum;
 				peer = ASTOBJ_REF(iterator);
@@ -11448,28 +11475,9 @@
 		} while (0)
 		);
 		if (peer) {
-			int sendmwi = TRUE;
-			/* If this peer requires subscription for mwi, check if we have
-				a subscription */
-			if(ast_test_flag((&peer->flags_page2), SIP_PAGE2_SUBSCRIBEMWIONLY)) {
-				if (!peer->mwipvt) {
-					sendmwi = FALSE;
-					time(&peer->lastmsgcheck);	/* Reset timer */
-					//OEJ
-					ast_log(LOG_DEBUG, "Not sending MWI - no subscription for peer %s\n", peer->name);
-				} else {
-					//OEJ
-					ast_log(LOG_DEBUG, "Sending MWI to peer - active subscription for peer %s\n", peer->name);
-				}
-			
-			} else
-				ast_log(LOG_DEBUG, "Automatically always sending MWI to peer %s\n", peer->name);
-
-			if (sendmwi) {
-				ASTOBJ_WRLOCK(peer);
-				sip_send_mwi_to_peer(peer);
-				ASTOBJ_UNLOCK(peer);
-			}
+			ASTOBJ_WRLOCK(peer);
+			sip_send_mwi_to_peer(peer);
+			ASTOBJ_UNLOCK(peer);
 			ASTOBJ_UNREF(peer,sip_destroy_peer);
 		} else {
 			/* Reset where we come from */

Modified: team/oej/subscribemwi/configs/sip.conf.sample
URL: http://svn.digium.com/view/asterisk/team/oej/subscribemwi/configs/sip.conf.sample?rev=10626&r1=10625&r2=10626&view=diff
==============================================================================
--- team/oej/subscribemwi/configs/sip.conf.sample (original)
+++ team/oej/subscribemwi/configs/sip.conf.sample Tue Feb 21 08:24:14 2006
@@ -415,6 +415,8 @@
 ;dtmfmode=inband		; Choices are inband, rfc2833, or info
 ;defaultip=192.168.0.59		; IP used until peer registers
 ;mailbox=1234 at context,2345      ; Mailbox(-es) for message waiting indicator
+;subscribemwi=yes		; Only send notifications if this phone 
+				; subscribes for mailbox notification
 ;vmexten=voicemail      ; dialplan extension to reach mailbox 
                         ; sets the Message-Account in the MWI notify message
                         ; defaults to global vmexten which defaults to "asterisk"



More information about the asterisk-commits mailing list