[asterisk-commits] russell: branch russell/events r59248 - /team/russell/events/channels/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Mar 26 20:25:31 MST 2007


Author: russell
Date: Mon Mar 26 22:25:31 2007
New Revision: 59248

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59248
Log:
When a peer has a mailbox, subscribe to MWI events for that mailbox.
Also, when sending MWI along with a REGACK, get the mailbox information from
the event cache.  This makes chan_iax2 no longer manually check the inbox on
every registration.

Modified:
    team/russell/events/channels/chan_iax2.c

Modified: team/russell/events/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/channels/chan_iax2.c?view=diff&rev=59248&r1=59247&r2=59248
==============================================================================
--- team/russell/events/channels/chan_iax2.c (original)
+++ team/russell/events/channels/chan_iax2.c Mon Mar 26 22:25:31 2007
@@ -91,6 +91,7 @@
 #include "asterisk/netsock.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/event.h"
 
 #include "iax2.h"
 #include "iax2-parser.h"
@@ -366,7 +367,9 @@
 	int pokefreqnotok;				/*!< How often to check when the host has been determined to be down */
 	int historicms;					/*!< How long recent average responses took */
 	int smoothing;					/*!< Sample over how many units to determine historic ms */
-	
+
+	struct ast_event_sub *mwi_event_sub;
+
 	struct ast_ha *ha;
 	AST_LIST_ENTRY(iax2_peer) entry;
 };
@@ -879,6 +882,13 @@
 	.transfer = iax2_transfer,
 	.fixup = iax2_fixup,
 };
+
+static void mwi_event_cb(const struct ast_event *event)
+{
+	/* The MWI subscriptions exist just so the core knows we care about those
+	 * mailboxes.  However, we just grab the events out of the cache when it
+	 * is time to send MWI, since it is only sent with a REGACK. */
+}
 
 static void insert_idle_thread(struct iax2_thread *thread)
 {
@@ -5791,13 +5801,26 @@
 		iax_ie_append_short(&ied, IAX_IE_REFRESH, p->expiry);
 		iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
 		if (!ast_strlen_zero(p->mailbox)) {
+			struct ast_event *event;
 			int new, old;
-			ast_app_inboxcount(p->mailbox, &new, &old);
+
+			event = ast_event_get_cached(AST_EVENT_MWI,
+				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, p->mailbox,
+				AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+				AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+				AST_EVENT_IE_END);
+			if (event) {
+				new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+				old = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
+			} else /* Fall back on checking the mailbox directly */
+				ast_app_inboxcount(p->mailbox, &new, &old);
+
 			if (new > 255)
 				new = 255;
 			if (old > 255)
 				old = 255;
 			msgcount = (old << 8) | new;
+
 			iax_ie_append_short(&ied, IAX_IE_MSGCOUNT, msgcount);
 		}
 		if (ast_test_flag(p, IAX_HASCALLERID)) {
@@ -8691,8 +8714,16 @@
 		/* Make sure these are IPv4 addresses */
 		peer->addr.sin_family = AF_INET;
 	}
+
 	if (oldha)
 		ast_free_ha(oldha);
+
+	if (!ast_strlen_zero(peer->mailbox)) {
+		peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox,
+			AST_EVENT_IE_END);
+	}
+
 	return peer;
 }
 
@@ -8972,6 +9003,9 @@
 
 	if (peer->dnsmgr)
 		ast_dnsmgr_release(peer->dnsmgr);
+
+	if (peer->mwi_event_sub)
+		ast_event_unsubscribe(peer->mwi_event_sub);
 
 	ast_string_field_free_pools(peer);
 



More information about the asterisk-commits mailing list