[asterisk-commits] oej: branch oej/pinequeue-1.8 r367558 - in /team/oej/pinequeue-1.8: ./ addons...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 24 04:02:02 CDT 2012


Author: oej
Date: Thu May 24 04:01:56 2012
New Revision: 367558

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367558
Log:
Resolving conflicts, moving on with my life. I wish.

Modified:
    team/oej/pinequeue-1.8/   (props changed)
    team/oej/pinequeue-1.8/addons/format_mp3.c
    team/oej/pinequeue-1.8/apps/app_minivm.c
    team/oej/pinequeue-1.8/apps/app_page.c
    team/oej/pinequeue-1.8/apps/app_queue.c
    team/oej/pinequeue-1.8/apps/app_record.c
    team/oej/pinequeue-1.8/apps/app_voicemail.c
    team/oej/pinequeue-1.8/channels/chan_agent.c
    team/oej/pinequeue-1.8/channels/chan_dahdi.c
    team/oej/pinequeue-1.8/channels/chan_iax2.c
    team/oej/pinequeue-1.8/channels/chan_sip.c
    team/oej/pinequeue-1.8/channels/iax2-parser.c
    team/oej/pinequeue-1.8/channels/iax2-provision.c
    team/oej/pinequeue-1.8/channels/sig_analog.c
    team/oej/pinequeue-1.8/channels/sip/config_parser.c
    team/oej/pinequeue-1.8/channels/sip/reqresp_parser.c
    team/oej/pinequeue-1.8/funcs/func_devstate.c
    team/oej/pinequeue-1.8/funcs/func_dialgroup.c
    team/oej/pinequeue-1.8/funcs/func_lock.c
    team/oej/pinequeue-1.8/funcs/func_odbc.c
    team/oej/pinequeue-1.8/funcs/func_speex.c
    team/oej/pinequeue-1.8/include/asterisk/cel.h
    team/oej/pinequeue-1.8/include/asterisk/channel.h
    team/oej/pinequeue-1.8/include/asterisk/tcptls.h
    team/oej/pinequeue-1.8/main/acl.c
    team/oej/pinequeue-1.8/main/app.c
    team/oej/pinequeue-1.8/main/asterisk.c
    team/oej/pinequeue-1.8/main/cdr.c
    team/oej/pinequeue-1.8/main/cel.c
    team/oej/pinequeue-1.8/main/channel.c
    team/oej/pinequeue-1.8/main/cli.c
    team/oej/pinequeue-1.8/main/config.c
    team/oej/pinequeue-1.8/main/data.c
    team/oej/pinequeue-1.8/main/db.c
    team/oej/pinequeue-1.8/main/devicestate.c
    team/oej/pinequeue-1.8/main/editline/readline.c
    team/oej/pinequeue-1.8/main/editline/term.c
    team/oej/pinequeue-1.8/main/editline/tokenizer.c
    team/oej/pinequeue-1.8/main/enum.c
    team/oej/pinequeue-1.8/main/event.c
    team/oej/pinequeue-1.8/main/features.c
    team/oej/pinequeue-1.8/main/http.c
    team/oej/pinequeue-1.8/main/manager.c
    team/oej/pinequeue-1.8/main/netsock2.c
    team/oej/pinequeue-1.8/main/pbx.c
    team/oej/pinequeue-1.8/main/say.c
    team/oej/pinequeue-1.8/main/tcptls.c
    team/oej/pinequeue-1.8/main/xmldoc.c
    team/oej/pinequeue-1.8/pbx/dundi-parser.c
    team/oej/pinequeue-1.8/pbx/pbx_dundi.c
    team/oej/pinequeue-1.8/res/ael/ael.flex
    team/oej/pinequeue-1.8/res/ael/pval.c
    team/oej/pinequeue-1.8/res/res_calendar.c
    team/oej/pinequeue-1.8/res/res_calendar_caldav.c
    team/oej/pinequeue-1.8/res/res_calendar_ews.c
    team/oej/pinequeue-1.8/res/res_calendar_exchange.c
    team/oej/pinequeue-1.8/res/res_calendar_icalendar.c
    team/oej/pinequeue-1.8/res/res_jabber.c
    team/oej/pinequeue-1.8/res/res_monitor.c
    team/oej/pinequeue-1.8/res/res_musiconhold.c
    team/oej/pinequeue-1.8/res/res_odbc.c
    team/oej/pinequeue-1.8/res/res_rtp_asterisk.c
    team/oej/pinequeue-1.8/res/res_srtp.c

Propchange: team/oej/pinequeue-1.8/
------------------------------------------------------------------------------
    automerge = Is-there-life-off-net?

Propchange: team/oej/pinequeue-1.8/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu May 24 04:01:56 2012
@@ -1,1 +1,1 @@
-/branches/1.8:1-366090
+/branches/1.8:1-367557

Modified: team/oej/pinequeue-1.8/addons/format_mp3.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/addons/format_mp3.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/addons/format_mp3.c (original)
+++ team/oej/pinequeue-1.8/addons/format_mp3.c Thu May 24 04:01:56 2012
@@ -9,7 +9,7 @@
  * Thanks to mpglib from http://www.mpg123.org/
  * and Chris Stenton [jacs at gnome.co.uk]
  * for coding the ability to play stereo and non-8khz files
- 
+
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
  * any of the maintainers of this project for assistance;
@@ -48,20 +48,20 @@
 #define MP3_DCACHE 8192
 
 struct mp3_private {
-	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
-	char empty;				/* Empty character */
-	int lasttimeout;
-	int maxlen;
-	struct timeval last;
+	/*! state for the mp3 decoder */
 	struct mpstr mp;
+	/*! buffer to hold mp3 data after read from disk */
 	char sbuf[MP3_SCACHE];
+	/*! buffer for slinear audio after being decoded out of sbuf */
 	char dbuf[MP3_DCACHE];
+	/*! how much data has been written to the output buffer in the ast_filestream */
 	int buflen;
+	/*! how much data has been written to sbuf */
 	int sbuflen;
+	/*! how much data is left to be read out of dbuf, starting at dbufoffset */
 	int dbuflen;
+	/*! current offset for reading data out of dbuf */
 	int dbufoffset;
-	int sbufoffset;
-	int lastseek;
 	int offset;
 	long seek;
 };
@@ -107,17 +107,17 @@
 static void mp3_close(struct ast_filestream *s)
 {
 	struct mp3_private *p = s->_private;
-	
+
 	ExitMP3(&p->mp);
 	return;
 }
 
-static int mp3_squeue(struct ast_filestream *s) 
+static int mp3_squeue(struct ast_filestream *s)
 {
 	struct mp3_private *p = s->_private;
 	int res=0;
-	
-	p->lastseek = ftell(s->f);
+
+	res = ftell(s->f);
 	p->sbuflen = fread(p->sbuf, 1, MP3_SCACHE, s->f);
 	if(p->sbuflen < 0) {
 		ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", p->sbuflen, strerror(errno));
@@ -131,11 +131,11 @@
 	return 0;
 }
 
-static int mp3_dqueue(struct ast_filestream *s) 
+static int mp3_dqueue(struct ast_filestream *s)
 {
 	struct mp3_private *p = s->_private;
 	int res=0;
-	
+
 	if((res = decodeMP3(&p->mp,NULL,0,p->dbuf,MP3_DCACHE,&p->dbuflen)) == MP3_OK) {
 		p->sbuflen -= p->dbuflen;
 		p->dbufoffset = 0;
@@ -147,7 +147,7 @@
 {
 	struct mp3_private *p = s->_private;
 	int res = 0, bytes = 0;
-	
+
 	if(p->seek) {
 		ExitMP3(&p->mp);
 		InitMP3(&p->mp, OUTSCALE);
@@ -167,7 +167,7 @@
 			if(res == MP3_ERR)
 				return -1;
 		}
-		
+
 		p->seek = 0;
 		return 0;
 	}
@@ -181,7 +181,7 @@
 			if(mp3_squeue(s))
 				return -1;
 		}
-		
+
 	}
 
 	return 0;
@@ -194,36 +194,41 @@
 	int delay =0;
 	int save=0;
 
-	/* Send a frame from the file to the appropriate channel */
-
-	if(mp3_queue(s))
+	/* Pre-populate the buffer that holds audio to be returned (dbuf) */
+	if (mp3_queue(s)) {
 		return NULL;
-
-	if(p->dbuflen) {
-		for(p->buflen=0; p->buflen < MP3_BUFLEN && p->buflen < p->dbuflen; p->buflen++) {
-			s->buf[p->buflen + AST_FRIENDLY_OFFSET] = p->dbuf[p->buflen+p->dbufoffset];
-			p->sbufoffset++;
+	}
+
+	if (p->dbuflen) {
+		/* Read out what's waiting in dbuf */
+		for (p->buflen = 0; p->buflen < MP3_BUFLEN && p->buflen < p->dbuflen; p->buflen++) {
+			s->buf[p->buflen + AST_FRIENDLY_OFFSET] = p->dbuf[p->buflen + p->dbufoffset];
 		}
 		p->dbufoffset += p->buflen;
 		p->dbuflen -= p->buflen;
-
-		if(p->buflen < MP3_BUFLEN) {
-			if(mp3_queue(s))
-				return NULL;
-
-			for(save = p->buflen; p->buflen < MP3_BUFLEN; p->buflen++) {
-				s->buf[p->buflen + AST_FRIENDLY_OFFSET] = p->dbuf[(p->buflen-save)+p->dbufoffset];
-				p->sbufoffset++;
+	}
+
+	if (p->buflen < MP3_BUFLEN) {
+		/* dbuf didn't have enough, so reset dbuf, fill it back up and continue */
+		p->dbuflen = p->dbufoffset = 0;
+
+		if (mp3_queue(s)) {
+			return NULL;
+		}
+
+		/* Make sure dbuf has enough to complete this read attempt */
+		if (p->dbuflen >= (MP3_BUFLEN - p->buflen)) {
+			for (save = p->buflen; p->buflen < MP3_BUFLEN; p->buflen++) {
+				s->buf[p->buflen + AST_FRIENDLY_OFFSET] = p->dbuf[(p->buflen - save) + p->dbufoffset];
 			}
 			p->dbufoffset += (MP3_BUFLEN - save);
 			p->dbuflen -= (MP3_BUFLEN - save);
-
-		} 
-
-	}
-	
+		}
+
+	}
+
 	p->offset += p->buflen;
-	delay = p->buflen/2;
+	delay = p->buflen / 2;
 	s->fr.frametype = AST_FRAME_VOICE;
 	s->fr.subclass.codec = AST_FORMAT_SLINEAR;
 	AST_FRAME_SET_BUFFER(&s->fr, s->buf, AST_FRIENDLY_OFFSET, p->buflen);
@@ -266,16 +271,16 @@
 
 	p->seek = offset;
 	return fseek(s->f, offset, SEEK_SET);
-	
-}
-
-static int mp3_rewrite(struct ast_filestream *s, const char *comment) 
+
+}
+
+static int mp3_rewrite(struct ast_filestream *s, const char *comment)
 {
 	ast_log(LOG_ERROR,"I Can't write MP3 only read them.\n");
 	return -1;
 }
 
-static int mp3_trunc(struct ast_filestream *s) 
+static int mp3_trunc(struct ast_filestream *s)
 {
 
 	ast_log(LOG_ERROR,"I Can't write MP3 only read them.\n");
@@ -285,7 +290,7 @@
 static off_t mp3_tell(struct ast_filestream *s)
 {
 	struct mp3_private *p = s->_private;
-	
+
 	return p->offset/2;
 }
 
@@ -321,6 +326,6 @@
 static int unload_module(void)
 {
 	return ast_format_unregister(name);
-}	
+}
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MP3 format [Any rate but 8000hz mono is optimal]");

Modified: team/oej/pinequeue-1.8/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/apps/app_minivm.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/apps/app_minivm.c (original)
+++ team/oej/pinequeue-1.8/apps/app_minivm.c Thu May 24 04:01:56 2012
@@ -1255,6 +1255,8 @@
 
 	if (ast_strlen_zero(email)) {
 		ast_log(LOG_WARNING, "No address to send message to.\n");
+		ast_free(str1);
+		ast_free(str2);
 		return -1;	
 	}
 
@@ -1309,11 +1311,15 @@
 	}
 	if (!p) {
 		ast_log(LOG_WARNING, "Unable to open temporary file '%s'\n", tmp);
+		ast_free(str1);
+		ast_free(str2);
 		return -1;
 	}
 	/* Allocate channel used for chanvar substitution */
 	ast = ast_dummy_channel_alloc();
 	if (!ast) {
+		ast_free(str1);
+		ast_free(str2);
 		return -1;
 	}
 

Modified: team/oej/pinequeue-1.8/apps/app_page.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/apps/app_page.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/apps/app_page.c (original)
+++ team/oej/pinequeue-1.8/apps/app_page.c Thu May 24 04:01:56 2012
@@ -248,6 +248,7 @@
 		/* Append technology and resource */
 		if (ast_dial_append(dial, tech, resource) == -1) {
 			ast_log(LOG_ERROR, "Failed to add %s to outbound dial\n", tech);
+			ast_dial_destroy(dial);
 			continue;
 		}
 

Modified: team/oej/pinequeue-1.8/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/apps/app_queue.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/apps/app_queue.c (original)
+++ team/oej/pinequeue-1.8/apps/app_queue.c Thu May 24 04:01:56 2012
@@ -1828,9 +1828,17 @@
 	
 		if (!inserted) {
 			AST_LIST_INSERT_TAIL(&rl_iter->rules, rule, list);
-		}
-	}
-
+			inserted = 1;
+		}
+
+		break;
+	}
+
+	if (!inserted) {
+		ast_log(LOG_WARNING, "Unknown rule list name %s; ignoring.\n", list_name);
+		ast_free(rule);
+		return -1;
+	}
 	return 0;
 }
 
@@ -4218,6 +4226,7 @@
 	ast_channel_lock(qe->chan);
 	if (!(ds = ast_datastore_alloc(&queue_transfer_info, NULL))) {
 		ast_channel_unlock(qe->chan);
+		ast_free(qtds);
 		ast_log(LOG_WARNING, "Unable to create transfer datastore. queue_log will not show attended transfer\n");
 		return NULL;
 	}
@@ -4610,6 +4619,7 @@
 			int res2;
 
 			res2 = ast_autoservice_start(qe->chan);
+
 			/* instead of starting autoservice and jacking this thread to push sound to the
 			   peer channel, let's set up a background player to the peer channel and 
 			   get on with life in this thread. */
@@ -4619,7 +4629,9 @@
 				res2 |= ast_safe_sleep(peer, qe->parent->memberdelay * 1000);
 			}
 			if (!res2 && announce) {
-				play_file(peer, announce, ringing, qe->moh);;
+				if (play_file(peer, announce, ringing, qe->moh) < 0) {
+					ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", announce, peer->name);
+				}
 			}
 			if (!res2 && qe->parent->reportholdtime) {
 				int res3;
@@ -4632,11 +4644,15 @@
 					holdtimesecs = abs((now - qe->start) % 60);
 					if (holdtime > 0) {
 						ast_say_number(peer, holdtime, AST_DIGIT_ANY, peer->language, NULL);
-						play_file(peer, qe->parent->sound_minutes, ringing, qe->moh);
+						if (play_file(peer, qe->parent->sound_minutes, ringing, qe->moh) < 0) {
+							ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", qe->parent->sound_minutes, peer->name);
+						}
 					}
 					if (holdtimesecs > 1) {
 						ast_say_number(peer, holdtimesecs, AST_DIGIT_ANY, peer->language, NULL);
-						play_file(peer, qe->parent->sound_seconds, ringing, qe->moh);
+						if (play_file(peer, qe->parent->sound_seconds, ringing, qe->moh) < 0) {
+							ast_log(LOG_ERROR, "play_file failed for '%s' on %s\n", qe->parent->sound_seconds, peer->name);
+						}
 					}
 				}
 			}

Modified: team/oej/pinequeue-1.8/apps/app_record.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/apps/app_record.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/apps/app_record.c (original)
+++ team/oej/pinequeue-1.8/apps/app_record.c Thu May 24 04:01:56 2012
@@ -414,12 +414,14 @@
 out:
 	if ((silence > 0) && rfmt) {
 		res = ast_set_read_format(chan, rfmt);
-		if (res)
+		if (res) {
 			ast_log(LOG_WARNING, "Unable to restore read format on '%s'\n", chan->name);
-		if (sildet)
-			ast_dsp_free(sildet);
-	}
-
+		}
+	}
+
+	if (sildet) {
+		ast_dsp_free(sildet);
+	}
 	return res;
 }
 

Modified: team/oej/pinequeue-1.8/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/apps/app_voicemail.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/apps/app_voicemail.c (original)
+++ team/oej/pinequeue-1.8/apps/app_voicemail.c Thu May 24 04:01:56 2012
@@ -6892,7 +6892,10 @@
 			strncat(vms->introfn, "intro", sizeof(vms->introfn));
 			ast_play_and_wait(chan, INTRO);
 			ast_play_and_wait(chan, "beep");
-			play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vm_fmts, 1, vmu, (int *) duration, NULL, NULL, record_gain, vms, flag);
+			cmd = play_record_review(chan, NULL, vms->introfn, vmu->maxsecs, vm_fmts, 1, vmu, (int *) duration, NULL, NULL, record_gain, vms, flag);
+			if (cmd == -1) {
+				break;
+			}
 			cmd = 't';
 #else
 
@@ -9457,7 +9460,10 @@
 			retries = 0;
 		RETRIEVE(prefile, -1, vmu->mailbox, vmu->context);
 		if (ast_fileexists(prefile, NULL, NULL) <= 0) {
-			play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
+			cmd = play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, NULL, record_gain, vms, NULL);
+			if (cmd == -1) {
+				break;
+			}
 			cmd = 't';	
 		} else {
 			switch (cmd) {
@@ -11164,13 +11170,15 @@
 		AST_LIST_UNLOCK(&users);
 		return CLI_FAILURE;
 	}
-	if (a->argc == 3)
+	if (!context) {
 		ast_cli(a->fd, HVSU_OUTPUT_FORMAT, "Context", "Mbox", "User", "Zone", "NewMsg");
-	else {
+	} else {
 		int count = 0;
 		AST_LIST_TRAVERSE(&users, vmu, list) {
-			if (!strcmp(context, vmu->context))
+			if (!strcmp(context, vmu->context)) {
 				count++;
+				break;
+			}
 		}
 		if (count) {
 			ast_cli(a->fd, HVSU_OUTPUT_FORMAT, "Context", "Mbox", "User", "Zone", "NewMsg");
@@ -11184,7 +11192,7 @@
 		int newmsgs = 0, oldmsgs = 0;
 		char count[12], tmp[256] = "";
 
-		if ((a->argc == 3) || ((a->argc == 5) && !strcmp(context, vmu->context))) {
+		if (!context || !strcmp(context, vmu->context)) {
 			snprintf(tmp, sizeof(tmp), "%s@%s", vmu->mailbox, ast_strlen_zero(vmu->context) ? "default" : vmu->context);
 			inboxcount(tmp, &newmsgs, &oldmsgs);
 			snprintf(count, sizeof(count), "%d", newmsgs);
@@ -11519,16 +11527,22 @@
 static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata)
 {
 	uint32_t u, *uniqueid = ast_calloc(1, sizeof(*uniqueid));
-	if (ast_event_get_type(event) != AST_EVENT_UNSUB)
-		return;
-
-	if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
-		return;
 
 	if (!uniqueid) {
 		ast_log(LOG_ERROR, "Unable to allocate memory for uniqueid\n");
 		return;
 	}
+
+	if (ast_event_get_type(event) != AST_EVENT_UNSUB) {
+		ast_free(uniqueid);
+		return;
+	}
+
+	if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI) {
+		ast_free(uniqueid);
+		return;
+	}
+
 	u = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
 	*uniqueid = u;
 	if (ast_taskprocessor_push(mwi_subscription_tps, handle_unsubscribe, uniqueid) < 0) {
@@ -11561,6 +11575,7 @@
 
 static void start_poll_thread(void)
 {
+	int errcode;
 	mwi_sub_sub = ast_event_subscribe(AST_EVENT_SUB, mwi_sub_event_cb, "Voicemail MWI subscription", NULL,
 		AST_EVENT_IE_EVENTTYPE, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI,
 		AST_EVENT_IE_END);
@@ -11574,7 +11589,9 @@
 
 	poll_thread_run = 1;
 
-	ast_pthread_create(&poll_thread, NULL, mb_poll_thread, NULL);
+	if ((errcode = ast_pthread_create(&poll_thread, NULL, mb_poll_thread, NULL))) {
+		ast_log(LOG_ERROR, "Could not create thread: %s\n", strerror(errcode));
+	}
 }
 
 static void stop_poll_thread(void)
@@ -12509,8 +12526,10 @@
 		const char *val = ast_variable_retrieve(pwconf, "general", "password");
 		if (val) {
 			ast_copy_string(password, val, passwordlen);
- 			return;
-		}
+			ast_config_destroy(pwconf);
+			return;
+		}
+		ast_config_destroy(pwconf);
 	}
 	ast_log(LOG_NOTICE, "Failed reading voicemail password from %s, using secret from config file\n", secretfn);
 }
@@ -12519,26 +12538,33 @@
 	struct ast_config *conf;
 	struct ast_category *cat;
 	struct ast_variable *var;
-
-	if (!(conf=ast_config_new())) {
+	int res = -1;
+
+	if (!(conf = ast_config_new())) {
 		ast_log(LOG_ERROR, "Error creating new config structure\n");
-		return -1;
-	}
-	if (!(cat=ast_category_new("general","",1))) {
+		return res;
+	}
+	if (!(cat = ast_category_new("general", "", 1))) {
 		ast_log(LOG_ERROR, "Error creating new category structure\n");
-		return -1;
-	}
-	if (!(var=ast_variable_new("password",password,""))) {
+		ast_config_destroy(conf);
+		return res;
+	}
+	if (!(var = ast_variable_new("password", password, ""))) {
 		ast_log(LOG_ERROR, "Error creating new variable structure\n");
-		return -1;
-	}
-	ast_category_append(conf,cat);
-	ast_variable_append(cat,var);
-	if (ast_config_text_file_save(secretfn, conf, "app_voicemail")) {
+		ast_config_destroy(conf);
+		ast_category_destroy(cat);
+		return res;
+	}
+	ast_category_append(conf, cat);
+	ast_variable_append(cat, var);
+	if (!ast_config_text_file_save(secretfn, conf, "app_voicemail")) {
+		res = 0;
+	} else {
 		ast_log(LOG_ERROR, "Error writing voicemail password to %s\n", secretfn);
-		return -1;
-	}
-	return 0;
+	}
+
+	ast_config_destroy(conf);
+	return res;
 }
 
 static int vmsayname_exec(struct ast_channel *chan, const char *data)

Modified: team/oej/pinequeue-1.8/channels/chan_agent.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/channels/chan_agent.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/channels/chan_agent.c (original)
+++ team/oej/pinequeue-1.8/channels/chan_agent.c Thu May 24 04:01:56 2012
@@ -668,7 +668,9 @@
 			break;
 		case AST_FRAME_DTMF_END:
 			if (!p->acknowledged && (f->subclass.integer == p->acceptdtmf)) {
-				ast_verb(3, "%s acknowledged\n", p->chan->name);
+				if (p->chan) {
+					ast_verb(3, "%s acknowledged\n", p->chan->name);
+				}
 				p->acknowledged = 1;
 				ast_frfree(f);
 				f = &answer_frame;

Modified: team/oej/pinequeue-1.8/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/channels/chan_dahdi.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/channels/chan_dahdi.c (original)
+++ team/oej/pinequeue-1.8/channels/chan_dahdi.c Thu May 24 04:01:56 2012
@@ -7871,6 +7871,9 @@
 	struct ast_frame *f;
 
 	idx = dahdi_get_index(ast, p, 0);
+	if (idx < 0) {
+		return &ast_null_frame;
+	}
 	mysig = p->sig;
 	if (p->outsigmod > -1)
 		mysig = p->outsigmod;
@@ -7884,8 +7887,6 @@
 	p->subs[idx].f.data.ptr = NULL;
 	f = &p->subs[idx].f;
 
-	if (idx < 0)
-		return &p->subs[idx].f;
 	if (p->fake_event) {
 		res = p->fake_event;
 		p->fake_event = 0;
@@ -7965,6 +7966,7 @@
 #else
 		ast_log(LOG_WARNING, "Received bits changed on %s signalling?\n", sig2str(p->sig));
 #endif
+		break;
 	case DAHDI_EVENT_PULSE_START:
 		/* Stop tone if there's a pulse start and the PBX isn't started */
 		if (!ast->pbx)
@@ -8852,7 +8854,9 @@
 		ast_debug(1, "Exception on %d, channel %d\n", ast->fds[0],p->channel);
 	/* If it's not us, return NULL immediately */
 	if (ast != p->owner) {
-		ast_log(LOG_WARNING, "We're %s, not %s\n", ast->name, p->owner->name);
+		if (p->owner) {
+			ast_log(LOG_WARNING, "We're %s, not %s\n", ast->name, p->owner->name);
+		}
 		f = &p->subs[idx].f;
 		return f;
 	}
@@ -9218,6 +9222,7 @@
 				if ((ast->_state == AST_STATE_UP) && !p->outgoing) {
 					/* Treat this as a "hangup" instead of a "busy" on the assumption that
 					   a busy */
+					ast_frfree(f);
 					f = NULL;
 				}
 			} else if (f->frametype == AST_FRAME_DTMF_BEGIN
@@ -9243,7 +9248,8 @@
 				if (ast_tvdiff_ms(ast_tvnow(), p->waitingfordt) >= p->waitfordialtone ) {
 					p->waitingfordt.tv_sec = 0;
 					ast_log(LOG_WARNING, "Never saw dialtone on channel %d\n", p->channel);
-					f=NULL;
+					ast_frfree(f);
+					f = NULL;
 				} else if (f->frametype == AST_FRAME_VOICE) {
 					f->frametype = AST_FRAME_NULL;
 					f->subclass.integer = 0;
@@ -9258,6 +9264,7 @@
 								ast_log(LOG_WARNING, "Unable to initiate dialing on trunk channel %d\n", p->channel);
 								p->dop.dialstr[0] = '\0';
 								ast_mutex_unlock(&p->lock);
+								ast_frfree(f);
 								return NULL;
 							} else {
 								ast_log(LOG_DEBUG, "Sent deferred digit string: %s\n", p->dop.dialstr);
@@ -11673,14 +11680,13 @@
 		count = 0;
 		for (i = iflist; i; i = i->next) {
 			ast_mutex_lock(&i->lock);
-			if ((i->subs[SUB_REAL].dfd > -1) && i->sig && (!i->radio) && !(i->sig & SIG_MFCR2)) {
+			if (pfds && (i->subs[SUB_REAL].dfd > -1) && i->sig && (!i->radio) && !(i->sig & SIG_MFCR2)) {
 				if (analog_lib_handles(i->sig, i->radio, i->oprmode)) {
 					struct analog_pvt *p = i->sig_pvt;
 
-					if (!p)
+					if (!p) {
 						ast_log(LOG_ERROR, "No sig_pvt?\n");
-
-					if (!p->owner && !p->subs[SUB_REAL].owner) {
+					} else if (!p->owner && !p->subs[SUB_REAL].owner) {
 						/* This needs to be watched, as it lacks an owner */
 						pfds[count].fd = i->subs[SUB_REAL].dfd;
 						pfds[count].events = POLLPRI;

Modified: team/oej/pinequeue-1.8/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/channels/chan_iax2.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/channels/chan_iax2.c (original)
+++ team/oej/pinequeue-1.8/channels/chan_iax2.c Thu May 24 04:01:56 2012
@@ -4390,11 +4390,13 @@
 				/* Whoops, we weren't supposed to exist! */
 				peer = peer_unref(peer);
 				break;
-			} 
+			}
 		} else if (!strcasecmp(tmp->name, "regseconds")) {
 			ast_get_time_t(tmp->value, &regseconds, 0, NULL);
 		} else if (!strcasecmp(tmp->name, "ipaddr")) {
-			ast_sockaddr_parse(&peer->addr, tmp->value, PARSE_PORT_IGNORE);
+			if (!ast_sockaddr_parse(&peer->addr, tmp->value, PARSE_PORT_IGNORE)) {
+				ast_log(LOG_WARNING, "Failed to parse sockaddr '%s' for ipaddr of realtime peer '%s'\n", tmp->value, tmp->name);
+			}
 		} else if (!strcasecmp(tmp->name, "port")) {
 			ast_sockaddr_set_port(&peer->addr, atoi(tmp->value));
 		} else if (!strcasecmp(tmp->name, "host")) {
@@ -5277,7 +5279,7 @@
 			DEADLOCK_AVOIDANCE(&iaxsl[callno]);
 			pvt = iaxs[callno];
 		}
-		if (!pvt->peercallno) {
+		if (!pvt || !pvt->peercallno) {
 			return -1;
 		}
 	}
@@ -6881,6 +6883,7 @@
 		} else {
 			ast_cli(a->fd, "Peer %s not registered\n", a->argv[2]);
 		}
+		peer_unref(p);
 	} else {
 		ast_cli(a->fd, "Peer unknown: %s. Not unregistered\n", a->argv[2]);
 	}
@@ -8661,6 +8664,7 @@
 	expiry = strrchr(data, ':');
 	if (!expiry) {
 		ast_log(LOG_NOTICE, "IAX/Registry astdb entry missing expiry: '%s'\n", data);
+		return;
 	}
 	*expiry++ = '\0';
 
@@ -9836,6 +9840,7 @@
 		}
 		varlist = ast_calloc(1, sizeof(*varlist));
 		if (!varlist) {
+			ast_datastore_free(variablestore);
 			ast_log(LOG_ERROR, "Unable to assign new variable '%s'\n", data);
 			return -1;
 		}
@@ -11634,6 +11639,7 @@
 	ast_mutex_destroy(&thread->init_lock);
 	ast_cond_destroy(&thread->init_cond);
 	ast_free(thread);
+	/* Ignore check_return warning from Coverity for ast_atomic_dec_and_test below */
 	ast_atomic_dec_and_test(&iaxactivethreadcount);
 }
 
@@ -12212,7 +12218,10 @@
 			AST_LIST_UNLOCK(&idle_list);
 		}
 	}
-	ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL);
+	if (ast_pthread_create_background(&netthreadid, NULL, network_thread, NULL)) {
+		ast_log(LOG_ERROR, "Failed to create new thread!\n");
+		return -1;
+	}
 	ast_verb(2, "%d helper threads started\n", threadcount);
 	return 0;
 }

Modified: team/oej/pinequeue-1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/pinequeue-1.8/channels/chan_sip.c?view=diff&rev=367558&r1=367557&r2=367558
==============================================================================
--- team/oej/pinequeue-1.8/channels/chan_sip.c (original)
+++ team/oej/pinequeue-1.8/channels/chan_sip.c Thu May 24 04:01:56 2012
@@ -3157,7 +3157,7 @@
 	int len = strlen(sip_methods[id].text);
 	int l_name = name ? strlen(name) : 0;
 	/* true if the string is long enough, and ends with whitespace, and matches */
-	return (l_name >= len && name[len] < 33 &&
+	return (l_name >= len && name && name[len] < 33 &&
 		!strncasecmp(sip_methods[id].text, name, len));
 }
 
@@ -3461,7 +3461,7 @@
 		}
 		ast_debug(1, "Target address %s is not local, substituting externaddr\n",
 			  ast_sockaddr_stringify(them));
-	} else if (p) {
+	} else {
 		/* no remapping, but we bind to a specific address, so use it. */
 		switch (p->socket.type) {
 		case SIP_TRANSPORT_TCP:
@@ -3492,8 +3492,6 @@
 				ast_sockaddr_set_port(us, ast_sockaddr_port(&bindaddr));
 			}
 		}
-	} else if (!ast_sockaddr_is_any(&bindaddr)) {
-		ast_sockaddr_copy(us, &bindaddr);
 	}
 	ast_debug(3, "Setting SIP_TRANSPORT_%s with address %s\n", get_transport(p->socket.type), ast_sockaddr_stringify(us));
 }
@@ -3636,7 +3634,7 @@
 
 	pkt->retransid = -1; /* Kill this scheduler item */
 
-	if (pkt->owner && pkt->method != SIP_OPTIONS && xmitres == 0) {
+	if (pkt->method != SIP_OPTIONS && xmitres == 0) {
 		if (pkt->is_fatal || sipdebug) { /* Tell us if it's critical or if we're debugging */
 			ast_log(LOG_WARNING, "Retransmission timeout reached on transmission %s for seqno %u (%s %s) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n"
 				"Packet timed out after %dms with no response\n",
@@ -7126,6 +7124,8 @@
 	if (i->rtp) {
 		ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0));
 		ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1));
+		ast_rtp_instance_set_write_format(i->rtp, fmt);
+		ast_rtp_instance_set_read_format(i->rtp, fmt);
 	}
 	if (needvideo && i->vrtp) {
 		ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0));
@@ -7144,11 +7144,9 @@
 
 	tmp->writeformat = fmt;
 	tmp->rawwriteformat = fmt;
-	ast_rtp_instance_set_write_format(i->rtp, fmt);
 
 	tmp->readformat = fmt;
 	tmp->rawreadformat = fmt;
-	ast_rtp_instance_set_read_format(i->rtp, fmt);
 
 	tmp->tech_pvt = dialog_ref(i, "sip_new: set chan->tech_pvt to i");
 
@@ -7427,6 +7425,7 @@
 	if (f && (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) &&
 	    (ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_RFC2833)) {
 		ast_debug(1, "Ignoring DTMF (%c) RTP frame because dtmfmode is not RFC2833\n", f->subclass.integer);
+		ast_frfree(f);
 		return &ast_null_frame;
 	}
 
@@ -7438,6 +7437,7 @@
 		if (!(f->subclass.codec & p->jointcapability)) {
 			ast_debug(1, "Bogus frame of format '%s' received from '%s'!\n",
 				ast_getformatname(f->subclass.codec), p->owner->name);
+			ast_frfree(f);
 			return &ast_null_frame;
 		}
 		ast_debug(1, "Oooh, format changed to %s\n",
@@ -7465,7 +7465,7 @@
 			}
 		}
 	}
-	
+
 	return f;
 }
 
@@ -7500,6 +7500,7 @@
 				if (ast_async_goto(ast, target_context, "fax", 1)) {
 					ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context);
 				}
+				ast_frfree(fr);
 				fr = &ast_null_frame;
 			} else {
 				ast_channel_lock(ast);
@@ -7511,6 +7512,7 @@
 
 	/* Only allow audio through if they sent progress with SDP, or if the channel is actually answered */
 	if (fr && fr->frametype == AST_FRAME_VOICE && p->invitestate != INV_EARLY_MEDIA && ast->_state != AST_STATE_UP) {
+		ast_frfree(fr);
 		fr = &ast_null_frame;
 	}
 
@@ -8254,7 +8256,7 @@
 	int portnum = 0;
 	enum sip_transport transport = SIP_TRANSPORT_UDP;
 	char buf[256] = "";
-	char *username = NULL, *hostname = NULL, *secret = NULL, *authuser = NULL, *porta = NULL, *mailbox = NULL, *at = NULL;
+	char *username = NULL, *hostname = NULL, *secret = NULL, *authuser = NULL, *porta = NULL, *mailbox = NULL;
 
 	if (!value) {
 		return -1;
@@ -8262,13 +8264,12 @@
 
 	ast_copy_string(buf, value, sizeof(buf));
 
-	if (!(at = strstr(buf, "@"))) {
-		return -1;
-	}
+	username = buf;
 
 	if ((hostname = strrchr(buf, '@'))) {
 		*hostname++ = '\0';
-		username = buf;
+	} else {
+		return -1;
 	}
 
 	if ((secret = strchr(username, ':'))) {
@@ -12420,13 +12421,14 @@
 	/* If we have no DNS manager let's do a lookup */
 	if (!mwi->dnsmgr) {
 		char transport[MAXHOSTNAMELEN];
+		struct sip_subscription_mwi *saved;
 		snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(mwi->transport), get_srv_protocol(mwi->transport));
 
 		mwi->us.ss.ss_family = get_address_family_filter(&bindaddr); /* Filter address family */
-		ASTOBJ_REF(mwi); /* Add a ref for storing the mwi on the dnsmgr for updates */
-		ast_dnsmgr_lookup_cb(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_mwi, mwi);
+		saved = ASTOBJ_REF(mwi);
+		ast_dnsmgr_lookup_cb(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_mwi, saved);
 		if (!mwi->dnsmgr) {
-			ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy); /* dnsmgr disabled, remove reference */
+			ASTOBJ_UNREF(saved, sip_subscribe_mwi_destroy); /* dnsmgr disabled, remove reference */
 		}
 	}
 
@@ -14734,6 +14736,20 @@
 	ast_sockaddr_split_hostport(*hostport, hostport, &dont_care, PARSE_PORT_IGNORE);
 }
 
+/*! \internal \brief Helper function to update a peer's lastmsgssent value
+ */
+static void update_peer_lastmsgssent(struct sip_peer *peer, int value, int locked)
+{
+	if (!locked) {
+		ao2_lock(peer);
+	}
+	peer->lastmsgssent = value;
+	if (!locked) {
+		ao2_unlock(peer);
+	}
+}
+
+
 /*! \brief Verify registration of user
 	- Registration is done in several steps, first a REGISTER without auth
 	  to get a challenge (nonce) then a second one with auth
@@ -14747,6 +14763,7 @@
 	char tmp[256];
 	char *c, *name, *unused_password, *domain;
 	char *uri2 = ast_strdupa(uri);
+	int send_mwi = 0;
 
 	terminate_uri(uri2);
 
@@ -14850,19 +14867,16 @@
 					case PARSE_REGISTER_DENIED:
 						ast_log(LOG_WARNING, "Registration denied because of contact ACL\n");
 						transmit_response_with_date(p, "603 Denied", req);
-						peer->lastmsgssent = -1;
 						res = 0;
 						break;
 					case PARSE_REGISTER_FAILED:
 						ast_log(LOG_WARNING, "Failed to parse contact info\n");
 						transmit_response_with_date(p, "400 Bad Request", req);
-						peer->lastmsgssent = -1;
 						res = 0;
 						break;
 					case PARSE_REGISTER_QUERY:
 						ast_string_field_set(p, fullcontact, peer->fullcontact);
 						transmit_response_with_date(p, "200 OK", req);
-						peer->lastmsgssent = -1;
 						res = 0;
 						break;
 					case PARSE_REGISTER_UPDATE:
@@ -14870,8 +14884,7 @@
 						update_peer(peer, p->expiry);
 						/* Say OK and ask subsystem to retransmit msg counter */
 						transmit_response_with_date(p, "200 OK", req);
-						if (!ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY))
-							peer->lastmsgssent = -1;
+						send_mwi = 1;
 						res = 0;
 						break;
 					}
@@ -14896,19 +14909,17 @@
 			case PARSE_REGISTER_DENIED:
 				ast_log(LOG_WARNING, "Registration denied because of contact ACL\n");
 				transmit_response_with_date(p, "403 Forbidden (ACL)", req);
-				peer->lastmsgssent = -1;
 				res = 0;
 				break;
 			case PARSE_REGISTER_FAILED:
 				ast_log(LOG_WARNING, "Failed to parse contact info\n");
 				transmit_response_with_date(p, "400 Bad Request", req);
-				peer->lastmsgssent = -1;
 				res = 0;
 				break;
 			case PARSE_REGISTER_QUERY:
 				ast_string_field_set(p, fullcontact, peer->fullcontact);
 				transmit_response_with_date(p, "200 OK", req);
-				peer->lastmsgssent = -1;
+				send_mwi = 1;
 				res = 0;
 				break;
 			case PARSE_REGISTER_UPDATE:
@@ -14916,7 +14927,7 @@
 				/* Say OK and ask subsystem to retransmit msg counter */
 				transmit_response_with_date(p, "200 OK", req);
 				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));
-				peer->lastmsgssent = -1;
+				send_mwi = 1;
 				res = 0;
 				break;
 			}
@@ -14924,6 +14935,11 @@
 		}
 	}
 	if (!res) {
+		if (send_mwi) {
+			sip_send_mwi_to_peer(peer, 0);
+		} else {
+			update_peer_lastmsgssent(peer, -1, 0);
+		}
 		ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name);
 	}
 	if (res < 0) {
@@ -15263,7 +15279,7 @@
 			}
 			/* Remove enclosing double-quotes */
 			if (*reason_param == '"')
-				ast_strip_quoted(reason_param, "\"", "\"");
+				reason_param = ast_strip_quoted(reason_param, "\"", "\"");
 			if (!ast_strlen_zero(reason_param)) {
 				sip_set_redirstr(p, reason_param);
 				if (p->owner) {
@@ -15913,7 +15929,9 @@
 			p->sa = p->recv;
 		}
 
-		ast_sockaddr_resolve_first(&tmp, c, 0);
+		if (ast_sockaddr_resolve_first(&tmp, c, 0)) {
+			ast_log(LOG_WARNING, "Could not resolve socket address for '%s'\n", c);
+		}
 		port = ast_sockaddr_port(&tmp);
 		ast_sockaddr_set_port(&p->sa,
 				      port != 0 ? port : STANDARD_SIP_PORT);
@@ -16222,6 +16240,7 @@
 
 	/* Finally, apply the guest policy */
 	if (sip_cfg.allowguest) {
+		/* Ignore check_return warning from Coverity for get_rpid below. */
 		get_rpid(p, req);
 		p->rtptimeout = global_rtptimeout;
 		p->rtpholdtimeout = global_rtpholdtimeout;
@@ -17972,7 +17991,10 @@
 		return 0;	/* don't care, we scan all channels */
 	}
 
-	ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL);
+	if (ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
+		ast_log(LOG_WARNING, "Could not get RTP stats.\n");
+		return 0;
+	}
 
 	if (c && c->cdr && !ast_tvzero(c->cdr->start)) {
 		duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
@@ -22351,9 +22373,7 @@
 				}
 			}
 			transmit_response_reliable(p, "491 Request Pending", req);
-			p->pendinginvite = seqno;
 			check_via(p, req);
-			copy_request(&p->initreq, req);
 			ast_debug(1, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid);
 			/* Don't destroy dialog here */
 			res = 0;
@@ -22373,7 +22393,6 @@
 		if (p->owner) {
 			ast_debug(3, "INVITE w Replaces on existing call? Refusing action. [%s]\n", p->callid);
 			transmit_response_reliable(p, "400 Bad request", req);	/* The best way to not not accept the transfer */
-			p->pendinginvite = seqno;
 			check_via(p, req);
 			copy_request(&p->initreq, req);
 			/* Do not destroy existing call */
@@ -22392,7 +22411,6 @@
 			append_history(p, "Xfer", "INVITE/Replace Failed. Out of memory.");
 			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
 			p->invitestate = INV_COMPLETED;
-			p->pendinginvite = seqno;
 			check_via(p, req);
 			copy_request(&p->initreq, req);
 			res = -1;
@@ -22497,7 +22515,6 @@
 			}
 			refer_locked = 0;
 			p->invitestate = INV_COMPLETED;
-			p->pendinginvite = seqno;
 			check_via(p, req);
 			copy_request(&p->initreq, req);
 			res = -1;
@@ -25189,13 +25206,13 @@
 			if (!req->ignore && req->method == SIP_INVITE) {
 				transmit_response_reliable(p, "481 Call/Transaction Does Not Exist", req);
 				/* Will cease to exist after ACK */
+				return res;
 			} else if (req->method != SIP_ACK) {
 				transmit_response(p, "481 Call/Transaction Does Not Exist", req);
 				sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
-			} else {
-				ast_debug(1, "Got ACK for unknown dialog... strange.\n");
-			}
-			return res;
+				return res;
+			}
+			/* Otherwise, this is an ACK. It will always have a to-tag */
 		}
 	}
 
@@ -25646,12 +25663,14 @@
 	}
 
 	if (ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY) && !peer->mwipvt) {
+		update_peer_lastmsgssent(peer, -1, 1);
 		ao2_unlock(peer);
 		return 0;
 	}
 
 	/* Do we have an IP address? If not, skip this peer */
 	if (ast_sockaddr_isnull(&peer->addr) && ast_sockaddr_isnull(&peer->defaddr)) {
+		update_peer_lastmsgssent(peer, -1, 1);
 		ao2_unlock(peer);
 		return 0;
 	}
@@ -25662,6 +25681,11 @@
 		struct ast_str *mailbox_str = ast_str_alloca(512);
 		peer_mailboxes_to_str(&mailbox_str, peer);
 		ao2_unlock(peer);
+		/* If there is no mailbox do nothing */
+		if (ast_strlen_zero(mailbox_str->str)) {
+			update_peer_lastmsgssent(peer, -1, 0);
+			return 0;
+		}
 		ast_app_inboxcount(mailbox_str->str, &newmsgs, &oldmsgs);
 		ao2_lock(peer);
 	}
@@ -25674,6 +25698,7 @@
 		ao2_unlock(peer);
 		/* Build temporary dialog for this message */
 		if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) {
+			update_peer_lastmsgssent(peer, -1, 0);
 			return -1;
 		}
 
@@ -25686,7 +25711,7 @@
 			/* Maybe they're not registered, etc. */
 			dialog_unlink_all(p);
 			dialog_unref(p, "unref dialog p just created via sip_alloc");
-			/* sip_destroy(p); */
+			update_peer_lastmsgssent(peer, -1, 0);
 			return 0;
 		}
 		/* Recalculate our side, and recalculate Call ID */
@@ -25718,6 +25743,8 @@
 	transmit_notify_with_mwi(p, newmsgs, oldmsgs, vmexten);
 	sip_pvt_unlock(p);
 	dialog_unref(p, "unref dialog ptr p just before it goes out of scope at the end of sip_send_mwi_to_peer.");
+
+	update_peer_lastmsgssent(peer, ((newmsgs > 0x7fff ? 0x7fff0000 : (newmsgs << 16)) | (oldmsgs > 0xffff ? 0xffff : oldmsgs)), 0);
 
 	return 0;
 }
@@ -26202,8 +26229,12 @@
 */
 enum st_mode st_get_mode(struct sip_pvt *p, int no_cached)
 {
-	if (!p->stimer)
+	if (!p->stimer) {
 		sip_st_alloc(p);
+		if (!p->stimer) {
+			return SESSION_TIMER_MODE_INVALID;
+		}
+	}
 
 	if (!no_cached && p->stimer->st_cached_mode != SESSION_TIMER_MODE_INVALID)
 		return p->stimer->st_cached_mode;
@@ -29043,15 +29074,15 @@
 	return 0;
 }
 
-static int apply_directmedia_ha(struct sip_pvt *p, const char *op)
+static int apply_directmedia_ha(struct sip_pvt *p1, struct sip_pvt *p2, const char *op)
 {
 	struct ast_sockaddr us = { { 0, }, }, them = { { 0, }, };
 	int res = AST_SENSE_ALLOW;
 
-	ast_rtp_instance_get_remote_address(p->rtp, &them);
-	ast_rtp_instance_get_local_address(p->rtp, &us);
-
-	if ((res = ast_apply_ha(p->directmediaha, &them)) == AST_SENSE_DENY) {
+	ast_rtp_instance_get_remote_address(p1->rtp, &them);
+	ast_rtp_instance_get_local_address(p1->rtp, &us);
+
+	if ((res = ast_apply_ha(p2->relatedpeer->directmediaha, &them)) == AST_SENSE_DENY) {
 		const char *us_addr = ast_strdupa(ast_sockaddr_stringify(&us));

[... 2728 lines stripped ...]



More information about the asterisk-commits mailing list