[svn-commits] russell: branch phsultan/res_jabber-openssl r79475 - in /team/phsultan/res_ja...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 14 14:25:44 CDT 2007


Author: russell
Date: Tue Aug 14 14:25:43 2007
New Revision: 79475

URL: http://svn.digium.com/view/asterisk?view=rev&rev=79475
Log:
sync this branch with trunk, enable automerge

Added:
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ael-vtest21/
      - copied from r79471, trunk/pbx/ael/ael-test/ael-vtest21/
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ael-vtest21/extensions.ael
      - copied unchanged from r79471, trunk/pbx/ael/ael-test/ael-vtest21/extensions.ael
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-vtest21
      - copied unchanged from r79471, trunk/pbx/ael/ael-test/ref.ael-vtest21
Modified:
    team/phsultan/res_jabber-openssl/   (props changed)
    team/phsultan/res_jabber-openssl/CHANGES
    team/phsultan/res_jabber-openssl/Makefile
    team/phsultan/res_jabber-openssl/apps/app_meetme.c
    team/phsultan/res_jabber-openssl/apps/app_minivm.c
    team/phsultan/res_jabber-openssl/apps/app_queue.c
    team/phsultan/res_jabber-openssl/apps/app_speech_utils.c
    team/phsultan/res_jabber-openssl/apps/app_voicemail.c
    team/phsultan/res_jabber-openssl/channels/chan_gtalk.c
    team/phsultan/res_jabber-openssl/channels/chan_h323.c
    team/phsultan/res_jabber-openssl/channels/chan_iax2.c
    team/phsultan/res_jabber-openssl/channels/chan_jingle.c
    team/phsultan/res_jabber-openssl/channels/chan_local.c
    team/phsultan/res_jabber-openssl/channels/chan_mgcp.c
    team/phsultan/res_jabber-openssl/channels/chan_misdn.c
    team/phsultan/res_jabber-openssl/channels/chan_oss.c
    team/phsultan/res_jabber-openssl/channels/chan_phone.c
    team/phsultan/res_jabber-openssl/channels/chan_sip.c
    team/phsultan/res_jabber-openssl/channels/chan_skinny.c
    team/phsultan/res_jabber-openssl/channels/chan_zap.c
    team/phsultan/res_jabber-openssl/configs/queues.conf.sample
    team/phsultan/res_jabber-openssl/funcs/func_devstate.c
    team/phsultan/res_jabber-openssl/include/asterisk/channel.h
    team/phsultan/res_jabber-openssl/include/asterisk/devicestate.h
    team/phsultan/res_jabber-openssl/include/asterisk/event_defs.h
    team/phsultan/res_jabber-openssl/include/asterisk/lock.h
    team/phsultan/res_jabber-openssl/include/asterisk/speech.h
    team/phsultan/res_jabber-openssl/main/cdr.c
    team/phsultan/res_jabber-openssl/main/channel.c
    team/phsultan/res_jabber-openssl/main/devicestate.c
    team/phsultan/res_jabber-openssl/main/dial.c
    team/phsultan/res_jabber-openssl/main/event.c
    team/phsultan/res_jabber-openssl/main/file.c
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ael-test5/extensions.ael
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ael-test6/extensions.ael
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-ntest10
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test1
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test11
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test14
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test19
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test2
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test3
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test4
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-test6
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-vtest13
    team/phsultan/res_jabber-openssl/pbx/ael/ael-test/ref.ael-vtest17
    team/phsultan/res_jabber-openssl/pbx/pbx_ael.c
    team/phsultan/res_jabber-openssl/pbx/pbx_spool.c
    team/phsultan/res_jabber-openssl/res/res_features.c
    team/phsultan/res_jabber-openssl/res/res_odbc.c
    team/phsultan/res_jabber-openssl/res/res_speech.c
    team/phsultan/res_jabber-openssl/utils/ael_main.c

Propchange: team/phsultan/res_jabber-openssl/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/phsultan/res_jabber-openssl/
------------------------------------------------------------------------------
Binary property 'branch-1.4-blocked' - no diff available.

Propchange: team/phsultan/res_jabber-openssl/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/phsultan/res_jabber-openssl/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Aug 14 14:25:43 2007
@@ -1,1 +1,1 @@
-/trunk:1-78715
+/trunk:1-79473

Modified: team/phsultan/res_jabber-openssl/CHANGES
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/CHANGES?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/CHANGES (original)
+++ team/phsultan/res_jabber-openssl/CHANGES Tue Aug 14 14:25:43 2007
@@ -144,6 +144,7 @@
      position changes frequently.
   * Added additional information to EXITWITHTIMEOUT and EXITWITHKEY events in the
      queue log.
+  * Added ability for non-realtime queues to have realtime members
 
 MeetMe Changes
 --------------

Modified: team/phsultan/res_jabber-openssl/Makefile
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/Makefile?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/Makefile (original)
+++ team/phsultan/res_jabber-openssl/Makefile Tue Aug 14 14:25:43 2007
@@ -281,7 +281,11 @@
 	@echo " + Asterisk has successfully been built, and +"  
 	@echo " + can be installed by running:              +"
 	@echo " +                                           +"
+ifeq ($(MAKE), gmake)
+	@echo " +               $(MAKE) install               +"  
+else
 	@echo " +               $(MAKE) install                +"  
+endif
 	@echo " +-------------------------------------------+"  
 
 _all: cleantest $(SUBDIRS)
@@ -490,14 +494,22 @@
 	@echo " + configuration files (overwriting any      +"
 	@echo " + existing config files), run:              +"  
 	@echo " +                                           +"
+ifeq ($(MAKE), gmake)
+	@echo " +               $(MAKE) samples               +"
+else
 	@echo " +               $(MAKE) samples                +"
+endif
 	@echo " +                                           +"
 	@echo " +-----------------  or ---------------------+"
 	@echo " +                                           +"
 	@echo " + You can go ahead and install the asterisk +"
 	@echo " + program documentation now or later run:   +"
 	@echo " +                                           +"
+ifeq ($(MAKE), gmake)
+	@echo " +              $(MAKE) progdocs               +"
+else
 	@echo " +              $(MAKE) progdocs                +"
+endif
 	@echo " +                                           +"
 	@echo " + **Note** This requires that you have      +"
 	@echo " + doxygen installed on your local system    +"
@@ -669,7 +681,11 @@
 	@echo " + directories, and logs, run the following  +"
 	@echo " + command:                                  +"
 	@echo " +                                           +"
+ifeq ($(MAKE), gmake)
+	@echo " +            $(MAKE) uninstall-all            +"  
+else
 	@echo " +            $(MAKE) uninstall-all             +"  
+endif
 	@echo " +-------------------------------------------+"  
 
 uninstall-all: _uninstall

Modified: team/phsultan/res_jabber-openssl/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/apps/app_meetme.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/apps/app_meetme.c (original)
+++ team/phsultan/res_jabber-openssl/apps/app_meetme.c Tue Aug 14 14:25:43 2007
@@ -230,8 +230,7 @@
 "      'D' -- dynamically add conference, prompting for a PIN\n"
 "      'e' -- select an empty conference\n"
 "      'E' -- select an empty pinless conference\n"
-"      'F' -- Pass DTMF through the conference.  DTMF used to activate any\n"
-"             conference features will not be passed through.\n"
+"      'F' -- Pass DTMF through the conference.\n"
 "      'i' -- announce user join/leave with review\n"
 "      'I' -- announce user join/leave without review\n"
 "      'l' -- set listen only mode (Listen only, no talking)\n"
@@ -1514,7 +1513,7 @@
 
 	/* This device changed state now - if this is the first user */
 	if (conf->users == 1)
-		ast_device_state_changed("meetme:%s", conf->confno);
+		ast_devstate_changed(AST_DEVICE_INUSE, "meetme:%s", conf->confno);
 
 	ast_mutex_unlock(&conf->playlock);
 
@@ -2002,6 +2001,9 @@
 				} else if ((f->frametype == AST_FRAME_DTMF) && (confflags & CONFFLAG_EXIT_CONTEXT)) {
 					char tmp[2];
 
+					if (confflags & CONFFLAG_PASS_DTMF)
+						conf_queue_dtmf(conf, user, f);
+
 					tmp[0] = f->subclass;
 					tmp[1] = '\0';
 					if (!ast_goto_if_exists(chan, exitcontext, tmp, 1)) {
@@ -2020,10 +2022,14 @@
 					
 					pbx_builtin_setvar_helper(chan, "MEETME_EXIT_KEY", exitkey);
 						
+					if (confflags & CONFFLAG_PASS_DTMF)
+						conf_queue_dtmf(conf, user, f);
 					ret = 0;
 					ast_frfree(f);
 					break;
 				} else if (((f->frametype == AST_FRAME_DTMF) && (f->subclass == '*') && (confflags & CONFFLAG_STARMENU)) || ((f->frametype == AST_FRAME_DTMF) && menu_active)) {
+					if (confflags & CONFFLAG_PASS_DTMF)
+						conf_queue_dtmf(conf, user, f);
 					if (ioctl(fd, ZT_SETCONF, &ztc_empty)) {
 						ast_log(LOG_WARNING, "Error setting conference\n");
 						close(fd);
@@ -2327,7 +2333,7 @@
 
 		/* Change any states */
 		if (!conf->users)
-			ast_device_state_changed("meetme:%s", conf->confno);
+			ast_devstate_changed(AST_DEVICE_NOT_INUSE, "meetme:%s", conf->confno);
 		
 		/* Return the number of seconds the user was in the conf */
 		snprintf(meetmesecs, sizeof(meetmesecs), "%d", (int) (time(NULL) - user->jointime));
@@ -3299,6 +3305,23 @@
 	return ringing_station;
 }
 
+static enum ast_device_state sla_state_to_devstate(enum sla_trunk_state state)
+{
+	switch (state) {
+	case SLA_TRUNK_STATE_IDLE:
+		return AST_DEVICE_NOT_INUSE;
+	case SLA_TRUNK_STATE_RINGING:
+		return AST_DEVICE_RINGING;
+	case SLA_TRUNK_STATE_UP:
+		return AST_DEVICE_INUSE;
+	case SLA_TRUNK_STATE_ONHOLD:
+	case SLA_TRUNK_STATE_ONHOLD_BYME:
+		return AST_DEVICE_ONHOLD;
+	}
+
+	return AST_DEVICE_UNKNOWN;
+}
+
 static void sla_change_trunk_state(const struct sla_trunk *trunk, enum sla_trunk_state state, 
 	enum sla_which_trunk_refs inactive_only, const struct sla_trunk_ref *exclude)
 {
@@ -3311,7 +3334,8 @@
 				|| trunk_ref == exclude)
 				continue;
 			trunk_ref->state = state;
-			ast_device_state_changed("SLA:%s_%s", station->name, trunk->name);
+			ast_devstate_changed(sla_state_to_devstate(state), 
+				"SLA:%s_%s", station->name, trunk->name);
 			break;
 		}
 	}
@@ -3803,7 +3827,7 @@
 {
 	ast_atomic_fetchadd_int((int *) &event->trunk_ref->trunk->hold_stations, 1);
 	event->trunk_ref->state = SLA_TRUNK_STATE_ONHOLD_BYME;
-	ast_device_state_changed("SLA:%s_%s", 
+	ast_devstate_changed(AST_DEVICE_ONHOLD, "SLA:%s_%s", 
 		event->station->name, event->trunk_ref->trunk->name);
 	sla_change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_ONHOLD, 
 		INACTIVE_TRUNK_REFS, event->trunk_ref);
@@ -4313,7 +4337,8 @@
 			sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, ALL_TRUNK_REFS, NULL);
 		else {
 			trunk_ref->state = SLA_TRUNK_STATE_UP;
-			ast_device_state_changed("SLA:%s_%s", station->name, trunk_ref->trunk->name);
+			ast_devstate_changed(AST_DEVICE_INUSE, 
+				"SLA:%s_%s", station->name, trunk_ref->trunk->name);
 		}
 	}
 
@@ -4530,21 +4555,7 @@
 			AST_RWLIST_UNLOCK(&sla_trunks);
 			break;
 		}
-		switch (trunk_ref->state) {
-		case SLA_TRUNK_STATE_IDLE:
-			res = AST_DEVICE_NOT_INUSE;
-			break;
-		case SLA_TRUNK_STATE_RINGING:
-			res = AST_DEVICE_RINGING;
-			break;
-		case SLA_TRUNK_STATE_UP:
-			res = AST_DEVICE_INUSE;
-			break;
-		case SLA_TRUNK_STATE_ONHOLD:
-		case SLA_TRUNK_STATE_ONHOLD_BYME:
-			res = AST_DEVICE_ONHOLD;
-			break;
-		}
+		res = sla_state_to_devstate(trunk_ref->state);
 		AST_RWLIST_UNLOCK(&sla_trunks);
 	}
 	AST_RWLIST_UNLOCK(&sla_stations);

Modified: team/phsultan/res_jabber-openssl/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/apps/app_minivm.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/apps/app_minivm.c (original)
+++ team/phsultan/res_jabber-openssl/apps/app_minivm.c Tue Aug 14 14:25:43 2007
@@ -2275,11 +2275,11 @@
 	       int len = strlen("\n");
 	       switch (tmpwrite[1]) {
 	       case 'n':
-		      strncpy(tmpwrite+len, tmpwrite+2, strlen(tmpwrite+2)+1);
+		      memmove(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1);
 		      strncpy(tmpwrite, "\n", len);
 		      break;
 	       case 't':
-		      strncpy(tmpwrite+len, tmpwrite+2, strlen(tmpwrite+2)+1);
+		      memmove(tmpwrite + len, tmpwrite + 2, strlen(tmpwrite + 2) + 1);
 		      strncpy(tmpwrite, "\t", len);
 		      break;
 	       default:

Modified: team/phsultan/res_jabber-openssl/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/apps/app_queue.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/apps/app_queue.c (original)
+++ team/phsultan/res_jabber-openssl/apps/app_queue.c Tue Aug 14 14:25:43 2007
@@ -410,6 +410,7 @@
 
 static AST_LIST_HEAD_STATIC(queues, call_queue);
 
+static void update_realtime_members(struct call_queue *q);
 static int set_member_paused(const char *queuename, const char *interface, int paused);
 
 static void set_queue_result(struct ast_channel *chan, enum queue_result res)
@@ -1254,6 +1255,8 @@
 			ast_variables_destroy(queue_vars);
 
 		AST_LIST_UNLOCK(&queues);
+	} else {
+		update_realtime_members(q);
 	}
 	return q;
 }

Modified: team/phsultan/res_jabber-openssl/apps/app_speech_utils.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/apps/app_speech_utils.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/apps/app_speech_utils.c (original)
+++ team/phsultan/res_jabber-openssl/apps/app_speech_utils.c Tue Aug 14 14:25:43 2007
@@ -701,6 +701,7 @@
 		/* We sort of make a results entry */
 		speech->results = ast_calloc(1, sizeof(*speech->results));
 		if (speech->results != NULL) {
+			ast_speech_dtmf(speech, dtmf);
 			speech->results->score = 1000;
 			speech->results->text = ast_strdup(dtmf);
 			speech->results->grammar = ast_strdup("dtmf");

Modified: team/phsultan/res_jabber-openssl/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/apps/app_voicemail.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/apps/app_voicemail.c (original)
+++ team/phsultan/res_jabber-openssl/apps/app_voicemail.c Tue Aug 14 14:25:43 2007
@@ -1681,8 +1681,6 @@
 	copy(frompath2, topath2);
 	ast_variables_destroy(var);
 }
-#endif
-
 /*! \brief
  * A negative return value indicates an error.
  * \note Should always be called with a lock already set on dir.
@@ -1714,8 +1712,8 @@
 	return x - 1;
 }
 
-#endif
-
+#endif /*#ifndef IMAP_STORAGE*/
+#endif /*#else of #ifdef ODBC_STORAGE*/
 #ifndef ODBC_STORAGE
 static int vm_delete(char *file)
 {
@@ -2294,8 +2292,39 @@
 	};
 	return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown";
 }
+#ifdef IMAP_STORAGE
+static int folder_int(const char *folder)
+{
+	/*assume a NULL folder means INBOX*/
+	if (!folder)
+		return 0;
+	if(!strcasecmp(folder, "INBOX"))
+		return 0;
+	else if (!strcasecmp(folder, "Old"))
+		return 1;
+	else if (!strcasecmp(folder, "Work"))
+		return 2;
+	else if (!strcasecmp(folder, "Family"))
+		return 3;
+	else if (!strcasecmp(folder, "Friends"))
+		return 4;
+	else if (!strcasecmp(folder, "Cust1"))
+		return 5;
+	else if (!strcasecmp(folder, "Cust2"))
+		return 6;
+	else if (!strcasecmp(folder, "Cust3"))
+		return 7;
+	else if (!strcasecmp(folder, "Cust4"))
+		return 8;
+	else if (!strcasecmp(folder, "Cust5"))
+		return 9;
+	else /*assume they meant INBOX if folder is not found otherwise*/
+		return 0;
+}
+#endif
 
 #ifdef ODBC_STORAGE
+/*! XXX \todo Fix this function to support multiple mailboxes in the intput string */
 static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
 {
 	int x = -1;
@@ -2438,17 +2467,16 @@
 
 static int has_voicemail(const char *mailbox, const char *folder)
 {
-	char *context, tmp[256];
+	char tmp[256], *tmp2 = tmp, *mbox, *context;
 	ast_copy_string(tmp, mailbox, sizeof(tmp));
-	if ((context = strchr(tmp, '@')))
-		*context++ = '\0';
-	else
-		context = "default";
-
-	if (messagecount(context, tmp, folder))
-		return 1;
-	else
-		return 0;
+	while ((context = mbox = strsep(&tmp2, ","))) {
+		strsep(&context, "@");
+		if (ast_strlen_zero(context))
+			context = "default";
+		if (messagecount(context, mbox, folder))
+			return 1;
+	}
+	return 0;
 }
 
 #elif defined(IMAP_STORAGE)
@@ -2521,66 +2549,24 @@
 
 }
 
-static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int messagecount(const char *context, const char *mailbox, const char *folder)
 {
 	SEARCHPGM *pgm;
 	SEARCHHEADER *hdr;
  
- 	struct ast_vm_user *vmu;
- 	struct vm_state *vms_p;
- 	char tmp[256] = "";
- 	char *mb, *cur;
- 	char *mailboxnc; 
- 	char *context;
- 	int ret = 0;
-
- 	if (newmsgs)
- 		*newmsgs = 0;
-
- 	if (oldmsgs)
- 		*oldmsgs = 0;
- 
-	 ast_debug(3,"Mailbox is set to %s\n",mailbox);
-
- 	/* If no mailbox, return immediately */
- 	if (ast_strlen_zero(mailbox)) 
- 		return 0;
-
- 	if (strchr(mailbox, ',')) {
- 		int tmpnew, tmpold;
-		ast_copy_string(tmp, mailbox, sizeof(tmp));
- 		mb = tmp;
- 		ret = 0;
- 		while((cur = strsep(&mb, ", "))) {
- 			if (!ast_strlen_zero(cur)) {
- 				if (inboxcount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
- 					return -1;
- 				else {
- 					if (newmsgs)
- 						*newmsgs += tmpnew; 
- 					if (oldmsgs)
- 						*oldmsgs += tmpold;
- 				}
- 			}
- 		}
- 		return 0;
- 	}
-
-	ast_copy_string(tmp, mailbox, sizeof(tmp));
-
-	if ((context = strchr(tmp, '@'))) {
- 		*context = '\0';
- 		mailboxnc = tmp;
- 		context++;
- 	} else {
- 		context = "default";
- 		mailboxnc = (char *)mailbox;
- 	}
- 
- 	/* We have to get the user before we can open the stream! */
- 	/*ast_debug(1,"Before find_user, context is %s and mailbox is %s\n",context,mailbox); */
-	if (!(vmu = find_user(NULL, context, mailboxnc))) {
-		ast_log(LOG_ERROR, "Couldn't find mailbox %s in context %s\n", mailboxnc, context);
+	struct ast_vm_user *vmu;
+	struct vm_state *vms_p;
+	int ret = 0;
+	int fold = folder_int(folder);
+	
+	if (ast_strlen_zero(mailbox))
+		return 0;
+
+	/* We have to get the user before we can open the stream! */
+	/* ast_log (LOG_DEBUG,"Before find_user, context is %s and mailbox is %s\n",context,mailbox); */
+	vmu = find_user(NULL, context, mailbox);
+	if (!vmu) {
+		ast_log (LOG_ERROR,"Couldn't find mailbox %s in context %s\n",mailbox,context);
 		return -1;
 	}
 	
@@ -2591,108 +2577,184 @@
 		return -1;
  	}
 
- 	/* check if someone is accessing this box right now... */
-	if ((vms_p = get_vm_state_by_imapuser(vmu->imapuser, 1)) || (vms_p = get_vm_state_by_mailbox(mailboxnc, 1))) {
-		ast_debug(3,"Returning before search - user is logged in\n");
- 		*newmsgs = vms_p->newmessages;
- 		*oldmsgs = vms_p->oldmessages;
-		free_user(vmu);
- 		return 0;
- 	}
-
- 	/* add one if not there... */
-	if (!(vms_p = get_vm_state_by_imapuser(vmu->imapuser, 0)) && !(vms_p = get_vm_state_by_mailbox(mailboxnc, 0))) {
+	/* check if someone is accessing this box right now... */
+	vms_p = get_vm_state_by_imapuser(vmu->imapuser,1);
+	if (!vms_p) {
+		vms_p = get_vm_state_by_mailbox(mailbox,1);
+	}
+	if (vms_p) {
+		ast_debug(3, "Returning before search - user is logged in\n");
+		if(fold == 0) {/*INBOX*/
+			free_user(vmu);
+			return vms_p->newmessages;
+		}
+		if(fold == 1) {/*Old messages*/
+			free_user(vmu);
+		 	return vms_p->oldmessages;
+		}
+	}
+
+	/* add one if not there... */
+	vms_p = get_vm_state_by_imapuser(vmu->imapuser,0);
+	if (!vms_p) {
+		vms_p = get_vm_state_by_mailbox(mailbox,0);
+	}
+
+	if (!vms_p) {
 		ast_debug(3,"Adding new vmstate for %s\n",vmu->imapuser);
 		if (!(vms_p = ast_calloc(1, sizeof(*vms_p)))) {
 			free_user(vmu);
 			return -1;
 		}
- 		ast_copy_string(vms_p->imapuser,vmu->imapuser, sizeof(vms_p->imapuser));
- 		ast_copy_string(vms_p->username, mailboxnc, sizeof(vms_p->username)); /* save for access from interactive entry point */
- 		vms_p->mailstream = NIL; /* save for access from interactive entry point */
-		ast_debug(3,"Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
+		ast_copy_string(vms_p->imapuser,vmu->imapuser, sizeof(vms_p->imapuser));
+		ast_copy_string(vms_p->username, mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
+		vms_p->mailstream = NIL; /* save for access from interactive entry point */
+		ast_debug(3, "Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
 		vms_p->updated = 1;
 		/* set mailbox to INBOX! */
-		ast_copy_string(vms_p->curbox, mbox(NEW_FOLDER), sizeof(vms_p->curbox));
- 		init_vm_state(vms_p);
- 		vmstate_insert(vms_p);
- 	}
-
-	/* If no mailstream exists yet and even after attempting to initialize it fails, bail out */
-	ret = init_mailstream(vms_p, NEW_FOLDER);
+		ast_copy_string(vms_p->curbox, mbox(fold), sizeof(vms_p->curbox));
+		init_vm_state(vms_p);
+		vmstate_insert(vms_p);
+	}
+	ret = init_mailstream(vms_p, fold);
 	if (!vms_p->mailstream) {
 		ast_log (LOG_ERROR,"Houston we have a problem - IMAP mailstream is NULL\n");
 		free_user(vmu);
 		return -1;
 	}
-
-	if (!ret && vms_p->updated > 0) {
-		if (newmsgs) {
-			pgm = mail_newsearchpgm();
-			hdr = mail_newsearchheader("X-Asterisk-VM-Extension", (char *)mailboxnc);
-			pgm->header = hdr;
+	if (ret == 0) {
+		pgm = mail_newsearchpgm ();
+		hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailbox);
+		pgm->header = hdr;
+		if (fold != 1) {
 			pgm->unseen = 1;
 			pgm->seen = 0;
-			pgm->undeleted = 1;
-			pgm->deleted = 0;
-			vms_p->vmArrayIndex = 0;
-			mail_search_full(vms_p->mailstream, NULL, pgm, NIL);
-			*newmsgs = vms_p->vmArrayIndex;
-			vms_p->newmessages = vms_p->vmArrayIndex;
-			mail_free_searchpgm(&pgm);
-		}
-		if (oldmsgs) {
-			pgm = mail_newsearchpgm ();
-			hdr = mail_newsearchheader ("X-Asterisk-VM-Extension", (char *)mailboxnc);
-			pgm->header = hdr;
+		}
+		/* In the special case where fold is 1 (old messages) we have to do things a bit
+		 * differently. Old messages are stored in the INBOX but are marked as "seen"
+		 */
+		else {
 			pgm->unseen = 0;
 			pgm->seen = 1;
-			pgm->undeleted = 1;
-			pgm->deleted = 0;
-			vms_p->vmArrayIndex = 0;
-			mail_search_full(vms_p->mailstream, NULL, pgm, NIL);
-			*oldmsgs = vms_p->vmArrayIndex;
+		}
+		pgm->undeleted = 1;
+		pgm->deleted = 0;
+
+		vms_p->vmArrayIndex = 0;
+		mail_search_full (vms_p->mailstream, NULL, pgm, NIL);
+		if(fold == 0)
+			vms_p->newmessages = vms_p->vmArrayIndex;
+		if(fold == 1)
 			vms_p->oldmessages = vms_p->vmArrayIndex;
-			mail_free_searchpgm(&pgm);
-		}
-	}
-
- 	if (vms_p->updated > 1) {  /* changes, so we did the searches above */
- 		vms_p->updated = 0;
- 	} else {  /* no changes, so don't search */
- 		mail_ping(vms_p->mailstream);
- 		/* Keep the old data */
- 		*newmsgs = vms_p->newmessages;
- 		*oldmsgs = vms_p->oldmessages;
- 	}
-
+		/*Freeing the searchpgm also frees the searchhdr*/
+		mail_free_searchpgm(&pgm);
+		free_user(vmu);
+		vms_p->updated = 0;
+		return vms_p->vmArrayIndex;
+	} else {  
+		mail_ping(vms_p->mailstream);
+	}
 	free_user(vmu);
- 	return 0;
- }
+	return 0;
+}
+static int inboxcount(const char *mailbox_context, int *newmsgs, int *oldmsgs)
+{
+	char tmp[PATH_MAX] = "";
+	char *mailboxnc; 	
+	char *context;
+	char *mb;
+	char *cur;
+	if (newmsgs)
+		*newmsgs = 0;
+	if (oldmsgs)
+		*oldmsgs = 0;
+
+	ast_debug(3,"Mailbox is set to %s\n",mailbox_context);
+	/* If no mailbox, return immediately */
+	if (ast_strlen_zero(mailbox_context))
+		return 0;
+	
+	ast_copy_string(tmp, mailbox_context, sizeof(tmp));
+	context = strchr(tmp, '@');
+	if (strchr(mailbox_context, ',')) {
+		int tmpnew, tmpold;
+		ast_copy_string(tmp, mailbox_context, sizeof(tmp));
+		mb = tmp;
+		while((cur = strsep(&mb, ", "))) {
+			if (!ast_strlen_zero(cur)) {
+				if (inboxcount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+					return -1;
+				else {
+					if (newmsgs)
+						*newmsgs += tmpnew; 
+					if (oldmsgs)
+						*oldmsgs += tmpold;
+				}
+			}
+		}
+		return 0;
+	}
+	if (context) {
+		*context = '\0';
+		mailboxnc = tmp;
+		context++;
+	} else {
+		context = "default";
+		mailboxnc = (char *)mailbox_context;
+	}
+	if (newmsgs) {
+		if((*newmsgs = messagecount(context, mailboxnc, "INBOX")) < 0)
+			return -1;
+	}
+	if (oldmsgs) {
+		if((*oldmsgs = messagecount(context, mailboxnc, "Old")) < 0)
+			return -1;
+	}
+	return 0;
+}
+	
 
 static int has_voicemail(const char *mailbox, const char *folder)
 {
-	int newmsgs, oldmsgs;
-	
-	if(inboxcount(mailbox, &newmsgs, &oldmsgs))
+	char tmp[256], *tmp2, *mbox, *context;
+	ast_copy_string(tmp, mailbox, sizeof(tmp));
+	tmp2 = tmp;
+	if(strchr(tmp2, ',')) {
+		while((mbox = strsep(&tmp2, ","))) {
+			if(!ast_strlen_zero(mbox)) {
+				if (has_voicemail(mbox, folder))
+					return 1;
+			}
+		}
+	}
+	if ((context= strchr(tmp, '@')))
+		*context++ = '\0';
+	else
+		context = "default";
+	return messagecount(context, tmp, folder) ? 1 : 0;
+}
+
+static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt, char *dir)
+{
+	char dest[256];
+	struct vm_state *sendvms = NULL, *destvms = NULL;
+	char messagestring[10]; /*I guess this could be a problem if someone has more than 999999999 messages...*/
+	if(!(sendvms = get_vm_state_by_imapuser(vmu->imapuser, 2)))
+	{
+		ast_log(LOG_ERROR, "Couldn't get vm_state for originator's mailbox!!\n");
+		return -1;
+	}
+	if(!(destvms = get_vm_state_by_imapuser(recip->imapuser, 2)))
+	{
+		ast_log(LOG_ERROR, "Couldn't get vm_state for destination mailbox!\n");
+		return -1;
+	}
+	imap_mailbox_name(dest, destvms, imbox, 1);
+	snprintf(messagestring, sizeof(messagestring), "%ld", sendvms->msgArray[msgnum]);
+	if((mail_copy(sendvms->mailstream, messagestring, dest) == T))
 		return 0;
-	else
-		return folder? oldmsgs: newmsgs;
-}
-
-static int messagecount(const char *context, const char *mailbox, const char *folder)
-{
-	int newmsgs, oldmsgs;
- 	char tmp[256] = "";
-	
- 	if (ast_strlen_zero(mailbox))
- 		return 0;
-	sprintf(tmp,"%s@%s", mailbox, ast_strlen_zero(context)? "default": context);
-
-	if(inboxcount(tmp, &newmsgs, &oldmsgs))
-		return 0;
-	else
-		return folder? oldmsgs: newmsgs;
+	ast_log(LOG_WARNING, "Unable to copy message from mailbox %s to mailbox %s\n", vmu->mailbox, recip->mailbox);
+	return -1;
 }
 
 #endif
@@ -3241,7 +3303,6 @@
 						snprintf(tmpdur, sizeof(tmpdur), "%d", duration);
 						ast_update_realtime("voicemail_data", "id", tmpid, "filename", fn, "duration", tmpdur, NULL);
 					}
-#ifndef IMAP_STORAGE
 					/* We must store the file first, before copying the message, because
 					 * ODBC storage does the entire copy with SQL.
 					 */
@@ -3265,7 +3326,6 @@
 							free_user(recip);
 						}
 					}
-#endif
 					/* Notification and disposal needs to happen after the copy, though. */
 					if (ast_fileexists(fn, NULL, NULL)) {
 						notify_new_message(chan, vmu, msgnum, duration, fmt, S_OR(chan->cid.cid_num, NULL), S_OR(chan->cid.cid_name, NULL));
@@ -3997,15 +4057,17 @@
 static void queue_mwi_event(const char *mbox, int new, int old)
 {
 	struct ast_event *event;
-	char *mailbox;
+	char *mailbox, *context;
 
 	/* Strip off @default */
-	mailbox = ast_strdupa(mbox);
-	if (strstr(mailbox, "@default"))
-		mailbox = strsep(&mailbox, "@");
+	context = mailbox = ast_strdupa(mbox);
+	strsep(&context, "@");
+	if (ast_strlen_zero(context))
+		context = "default";
 
 	if (!(event = ast_event_new(AST_EVENT_MWI,
 			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
+			AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
 			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, new,
 			AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old,
 			AST_EVENT_IE_END))) {
@@ -4014,6 +4076,7 @@
 
 	ast_event_queue_and_cache(event,
 		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR,
+		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR,
 		AST_EVENT_IE_END);
 }
 

Modified: team/phsultan/res_jabber-openssl/channels/chan_gtalk.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/channels/chan_gtalk.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/channels/chan_gtalk.c (original)
+++ team/phsultan/res_jabber-openssl/channels/chan_gtalk.c Tue Aug 14 14:25:43 2007
@@ -979,9 +979,7 @@
 		cid = data;
 	}
 	cid = strsep(&cid, "@");
-	tmp->cid.cid_num = ast_strdup(cid);
 	tmp->cid.cid_ani = ast_strdup(cid);
-	tmp->cid.cid_name = ast_strdup(i->them);
 	if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s"))
 		tmp->cid.cid_dnid = ast_strdup(i->exten);
 	tmp->priority = 1;

Modified: team/phsultan/res_jabber-openssl/channels/chan_h323.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/channels/chan_h323.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/channels/chan_h323.c (original)
+++ team/phsultan/res_jabber-openssl/channels/chan_h323.c Tue Aug 14 14:25:43 2007
@@ -1079,9 +1079,7 @@
 
 		/* Don't use ast_set_callerid() here because it will
 		 * generate a needless NewCallerID event */
-		ch->cid.cid_num = ast_strdup(cid_num);
 		ch->cid.cid_ani = ast_strdup(cid_num);
-		ch->cid.cid_name = ast_strdup(cid_name);
 
 		if (pvt->cd.redirect_reason >= 0) {
 			ch->cid.cid_rdnis = ast_strdup(pvt->cd.redirect_number);

Modified: team/phsultan/res_jabber-openssl/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/phsultan/res_jabber-openssl/channels/chan_iax2.c?view=diff&rev=79475&r1=79474&r2=79475
==============================================================================
--- team/phsultan/res_jabber-openssl/channels/chan_iax2.c (original)
+++ team/phsultan/res_jabber-openssl/channels/chan_iax2.c Tue Aug 14 14:25:43 2007
@@ -1184,6 +1184,10 @@
 		return csub;
 }
 
+/*!
+ * \note This funtion calls realtime_peer -> reg_source_db -> iax2_poke_peer -> find_callno,
+ *       so do not call it with a pvt lock held.
+ */
 static struct iax2_peer *find_peer(const char *name, int realtime) 
 {
 	struct iax2_peer *peer = NULL;
@@ -1397,6 +1401,8 @@
  * However, it's too late to change that now.  Instead, we need to come up with
  * a better way of indexing active calls so that these frequent lookups are not
  * so expensive.
+ *
+ * \note Calling this function while holding another pvt lock can cause a deadlock.
  */
 static int find_callno(unsigned short callno, unsigned short dcallno, struct sockaddr_in *sin, int new, int lockpeer, int sockfd)
 {
@@ -2674,6 +2680,10 @@
 	return 0;
 }
 
+/*!
+ * \note This function calls reg_source_db -> iax2_poke_peer -> find_callno,
+ *       so do not call this with a pvt lock held.
+ */
 static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin)
 {
 	struct ast_variable *var;
@@ -3569,8 +3579,6 @@
 
 	/* Don't use ast_set_callerid() here because it will
 	 * generate a NewCallerID event before the NewChannel event */
-	tmp->cid.cid_num = ast_strdup(i->cid_num);
-	tmp->cid.cid_name = ast_strdup(i->cid_name);
 	if (!ast_strlen_zero(i->ani))
 		tmp->cid.cid_ani = ast_strdup(i->ani);
 	else
@@ -5331,10 +5339,11 @@
 	}
 
 	/* SLD: first call to lookup peer during registration */
+	ast_mutex_unlock(&iaxsl[callno]);
 	p = find_peer(peer, 1);
-
-	if (!p) {
-		if (authdebug)
+	ast_mutex_lock(&iaxsl[callno]);
+	if (!p || !iaxs[callno]) {
+		if (authdebug && !p)
 			ast_log(LOG_NOTICE, "No registration for peer '%s' (from %s)\n", peer, ast_inet_ntoa(sin->sin_addr));
 		return -1;
 	}
@@ -5441,8 +5450,8 @@
 
 	if (ast_test_flag(p, IAX_TEMPONLY))
 		destroy_peer(p);
+
 	return 0;
-	
 }
 
 static int authenticate(const char *challenge, const char *secret, const char *keyn, int authmethods, struct iax_ie_data *ied, struct sockaddr_in *sin, ast_aes_encrypt_key *ecx, ast_aes_decrypt_key *dcx)
@@ -5498,6 +5507,10 @@
 	return res;
 }
 
+/*!
+ * \note This function calls realtime_peer -> reg_source_db -> iax2_poke_peer -> find_callno,
+ *       so do not call this function with a pvt lock held.
+ */
 static int authenticate_reply(struct chan_iax2_pvt *p, struct sockaddr_in *sin, struct iax_ies *ies, const char *override, const char *okey)
 {
 	struct iax2_peer *peer = NULL;
@@ -5505,7 +5518,8 @@
 	int res = -1;
 	int authmethods = 0;
 	struct iax_ie_data ied;
-	
+	uint16_t callno = p->callno;
+
 	memset(&ied, 0, sizeof(ied));
 	
 	if (ies->username)
@@ -5542,10 +5556,23 @@
 		if (!peer) {
 			/* We checked our list and didn't find one.  It's unlikely, but possible, 
 			   that we're trying to authenticate *to* a realtime peer */
-			if ((peer = realtime_peer(p->peer, NULL))) {
+			const char *peer_name = ast_strdupa(p->peer);
+			ast_mutex_unlock(&iaxsl[callno]);
+			if ((peer = realtime_peer(peer_name, NULL))) {
+				ast_mutex_lock(&iaxsl[callno]);
+				if (!(p = iaxs[callno])) {
+					if (ast_test_flag(peer, IAX_TEMPONLY))
+						destroy_peer(peer);
+					return -1;
+				}
 				res = authenticate(p->challenge, peer->secret,peer->outkey, authmethods, &ied, sin, &p->ecx, &p->dcx);
 				if (ast_test_flag(peer, IAX_TEMPONLY))
 					destroy_peer(peer);
+			}
+			if (!peer) {
+				ast_mutex_lock(&iaxsl[callno]);
+				if (!(p = iaxs[callno]))
+					return -1;
 			}
 		}
 	}
@@ -5969,7 +5996,7 @@
 	}
 }
 
-static int update_registry(const char *name, struct sockaddr_in *sin, int callno, char *devtype, int fd, unsigned short refresh)
+static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, int fd, unsigned short refresh)
 {
 	/* Called from IAX thread only, with proper iaxsl lock */
 	struct iax_ie_data ied;
@@ -5977,12 +6004,23 @@
 	int msgcount;
 	char data[80];
 	int version;
+	const char *peer_name;
 
 	memset(&ied, 0, sizeof(ied));
 
+	peer_name = ast_strdupa(iaxs[callno]->peer);
+
 	/* SLD: Another find_peer call during registration - this time when we are really updating our registration */
-	if (!(p = find_peer(name, 1))) {
-		ast_log(LOG_WARNING, "No such peer '%s'\n", name);
+	ast_mutex_unlock(&iaxsl[callno]);
+	if (!(p = find_peer(peer_name, 1))) {
+		ast_mutex_lock(&iaxsl[callno]);
+		ast_log(LOG_WARNING, "No such peer '%s'\n", peer_name);
+		return -1;
+	}
+	ast_mutex_lock(&iaxsl[callno]);
+	if (!iaxs[callno]) {
+		if (ast_test_flag(p, IAX_TEMPONLY))
+			destroy_peer(p);
 		return -1;
 	}
 
@@ -5990,9 +6028,9 @@
 		if (sin->sin_addr.s_addr) {
 			time_t nowtime;
 			time(&nowtime);
-			realtime_update_peer(name, sin, nowtime);
+			realtime_update_peer(peer_name, sin, nowtime);
 		} else {
-			realtime_update_peer(name, sin, 0);
+			realtime_update_peer(peer_name, sin, 0);
 		}
 	}
 	if (inaddrcmp(&p->addr, sin)) {
@@ -6022,8 +6060,11 @@
 	}		
 
 	/* Make sure our call still exists, an INVAL at the right point may make it go away */
-	if (!iaxs[callno])
+	if (!iaxs[callno]) {
+		if (ast_test_flag(p, IAX_TEMPONLY))
+			destroy_peer(p);
 		return 0;
+	}
 
 	/* Store socket fd */
 	p->sockfd = fd;
@@ -6054,9 +6095,16 @@
 		if (!ast_strlen_zero(p->mailbox)) {
 			struct ast_event *event;
 			int new, old;
+			char *mailbox, *context;
+
+			context = mailbox = ast_strdupa(p->mailbox);
+			strsep(&context, "@");
+			if (ast_strlen_zero(context))
+				context = "default";
 
 			event = ast_event_get_cached(AST_EVENT_MWI,
-				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, p->mailbox,
+				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
+				AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
 				AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 				AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 				AST_EVENT_IE_END);
@@ -6088,13 +6136,24 @@
 	return send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGACK, 0, ied.buf, ied.pos, -1);
 }
 
-static int registry_authrequest(const char *name, int callno)
+static int registry_authrequest(int callno)
 {
 	struct iax_ie_data ied;
 	struct iax2_peer *p;
 	char challenge[10];
+	const char *peer_name;
+
+	peer_name = ast_strdupa(iaxs[callno]->peer);
+
 	/* SLD: third call to find_peer in registration */
-	p = find_peer(name, 1);
+	ast_mutex_unlock(&iaxsl[callno]);
+	p = find_peer(peer_name, 1);
+	ast_mutex_lock(&iaxsl[callno]);
+	if (!iaxs[callno]) {
+		if (p && ast_test_flag(p, IAX_TEMPONLY))
+			destroy_peer(p);
+		return -1;
+	}
 	if (p) {
 		memset(&ied, 0, sizeof(ied));
 		iax_ie_append_short(&ied, IAX_IE_AUTHMETHODS, p->authmethods);
@@ -6105,12 +6164,12 @@
 			/* snprintf(iaxs[callno]->challenge, sizeof(iaxs[callno]->challenge), "%d", (int)ast_random()); */
 			iax_ie_append_str(&ied, IAX_IE_CHALLENGE, iaxs[callno]->challenge);
 		}
-		iax_ie_append_str(&ied, IAX_IE_USERNAME, name);
+		iax_ie_append_str(&ied, IAX_IE_USERNAME, peer_name);
 		if (ast_test_flag(p, IAX_TEMPONLY))
 			destroy_peer(p);
 		return send_command(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_REGAUTH, 0, ied.buf, ied.pos, -1);;
 	} 
-	ast_log(LOG_WARNING, "No such peer '%s'\n", name);
+	ast_log(LOG_WARNING, "No such peer '%s'\n", peer_name);
 	return 0;
 }
 
@@ -6204,7 +6263,6 @@
 {
 	/* Schedule sending the authentication failure in one second, to prevent
 	   guessing */
-	ast_mutex_lock(&iaxsl[callno]);
 	if (iaxs[callno]) {
 		iaxs[callno]->authfail = failcode;
 		if (delayreject) {
@@ -6214,7 +6272,6 @@
 		} else
 			auth_reject((void *)(long)callno);
 	}
-	ast_mutex_unlock(&iaxsl[callno]);
 	return 0;
 }
 
@@ -7442,8 +7499,15 @@
 				/* Ignore if it's already up */
 				if (ast_test_flag(&iaxs[fr->callno]->state, IAX_STATE_STARTED | IAX_STATE_TBD))
 					break;
-				if (ies.provverpres && ies.serviceident && sin.sin_addr.s_addr)
+				if (ies.provverpres && ies.serviceident && sin.sin_addr.s_addr) {
+					ast_mutex_unlock(&iaxsl[fr->callno]);
 					check_provisioning(&sin, fd, ies.serviceident, ies.provver);
+					ast_mutex_lock(&iaxsl[fr->callno]);
+					if (!iaxs[fr->callno]) {
+						ast_mutex_unlock(&iaxsl[fr->callno]);
+						return 1;
+					}
+				}
 				/* If we're in trunk mode, do it now, and update the trunk number in our frame before continuing */
 				if (ast_test_flag(iaxs[fr->callno], IAX_TRUNK)) {
 					int new_callno;
@@ -7833,6 +7897,10 @@
 					ast_log(LOG_WARNING, 
 						"I don't know how to authenticate %s to %s\n", 
 						ies.username ? ies.username : "<unknown>", ast_inet_ntoa(iaxs[fr->callno]->addr.sin_addr));
+				}
+				if (!iaxs[fr->callno]) {
+					ast_mutex_unlock(&iaxsl[fr->callno]);
+					return 1;
 				}
 				break;
 			case IAX_COMMAND_AUTHREP:
@@ -8094,21 +8162,44 @@
 				if (delayreject)
 					send_command_immediate(iaxs[fr->callno], AST_FRAME_IAX, IAX_COMMAND_ACK, fr->ts, NULL, 0,fr->iseqno);
 				if (register_verify(fr->callno, &sin, &ies)) {
+					if (!iaxs[fr->callno]) {
+						ast_mutex_unlock(&iaxsl[fr->callno]);
+						return 1;
+					}
 					/* Send delayed failure */
 					auth_fail(fr->callno, IAX_COMMAND_REGREJ);
 					break;
+				}
+				if (!iaxs[fr->callno]) {

[... 7406 lines stripped ...]



More information about the svn-commits mailing list