[asterisk-dev] [asterisk-commits] tilghman: branch 1.6.1 r249189 - in/branches/1.6.1: ./ apps/app_voicemail.c

Alec Davis sivad.a at paradise.net.nz
Sun Feb 28 00:36:00 CST 2010


Segfault in trunk that I debugged, and I'm sure in the 1.6.1 and 1.6.2
branches, for an extension with unconfigured voicemail.

Happens as soon as FXS extension goes off hook.


#0  0xb7ce3e18 in strcmp () from /lib/i686/cmov/libc.so.6
No symbol table info available.
#1  0xb711d6c3 in has_voicemail (mailbox=0xb684b98c "", folder=0x0) at
app_voicemail.c:5141
        tmp =
"\000\000\000\000è¥G\b\030\000\000\000\000\000\000\0003\002\000\000ôOÜ·ð¥G\b
\000\000\000\000\000\000\000\000#\000\000\000\000\000\000\000X¬7¶åJ\026\bð¥G
\b\035\000\000\000\004\000\000\000\220(t·#\000\000\000\000\000\000\000x¬7¶~J
\026\b\001\000\000\000\004\000\000\000\000\000\000\000tÞͷЭ7¶ð¥G\b#\002\000
\000\"\002\000\000#\002\000\000\000\000\000\000)ã\f\bð¥G\b`aÜ·\003\000\000\0
00\000\000\000\000\fº\037\b", '\0' <repeats 12 times>,
"\020\000\000\000#\000\r\000\220(t·È¬7¶\032&\b\bè¨\037\b\b\000\000\000)ã\f\b
ôOÜ·`aÜ·ð¥"...
        tmp2 = 0x0
        box = 0xb637abec ""
        context = 0xb713947d "default"
#2  0x08068475 in ast_app_has_voicemail (mailbox=0xb684b98c "", folder=0x0)
at app.c:258
        warned = 0
        __PRETTY_FUNCTION__ = "ast_app_has_voicemail"
#3  0xb76ecc96 in has_voicemail (p=0xb684a878) at chan_dahdi.c:4486
        new_msgs = 138911184
        event = (struct ast_event *) 0x0
        mailbox = 0xb637ad70 ""
        context = 0xb7734502 "default"
#4  0xb76e80b0 in my_has_voicemail (pvt=0xb684a878) at chan_dahdi.c:2382
        p = (struct dahdi_pvt *) 0xb684a878

-----Original Message-----
From: asterisk-commits-bounces at lists.digium.com
[mailto:asterisk-commits-bounces at lists.digium.com] On Behalf Of SVN commits
to the Asterisk project
Sent: Saturday, 27 February 2010 7:49 a.m.
To: asterisk-commits at lists.digium.com; svn-commits at lists.digium.com
Subject: [asterisk-commits] tilghman: branch 1.6.1 r249189 -
in/branches/1.6.1: ./ apps/app_voicemail.c

Author: tilghman
Date: Fri Feb 26 12:48:57 2010
New Revision: 249189

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=249189
Log:
Merged revisions 249187 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk

........
  r249187 | tilghman | 2010-02-26 12:41:57 -0600 (Fri, 26 Feb 2010) | 18
lines
  
  Cleanups to fix bugs in the VM count API functions.
  
  - Urgent voicemails were not attached, because the attachment code looked
in the wrong folder.
  - Urgent voicemails were sometimes counted twice when displaying the count
of new messages.
  - Backends were inconsistent as to which voicemails each API counted.
  
  (closes issue #15654)
   Reported by: tomo1657
   Patches: 
         20100225__issue15654.diff.txt uploaded by tilghman (license 14)
   Tested by: tilghman
  
  (closes issue #16448)
   Reported by: hevad
  
  Review: https://reviewboard.asterisk.org/r/525/
........

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/apps/app_voicemail.c

Propchange: branches/1.6.1/
----------------------------------------------------------------------------
--
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.1/apps/app_voicemail.c
URL:
http://svnview.digium.com/svn/asterisk/branches/1.6.1/apps/app_voicemail.c?v
iew=diff&rev=249189&r1=249188&r2=249189
============================================================================
==
--- branches/1.6.1/apps/app_voicemail.c (original)
+++ branches/1.6.1/apps/app_voicemail.c Fri Feb 26 12:48:57 2010
@@ -1687,16 +1687,7 @@
 		return 0;
 }
 
-/*!
- * \brief Gets the number of messages that exist in a mailbox folder.
- * \param context
- * \param mailbox
- * \param folder
- *
- * This method is used when IMAP backend is used.
- * \return The number of messages in this mailbox folder (zero or more).
- */
-static int messagecount(const char *context, const char *mailbox, const
char *folder)
+static int __messagecount(const char *context, const char *mailbox, 
+const char *folder)
 {
 	SEARCHPGM *pgm;
 	SEARCHHEADER *hdr;
@@ -1812,6 +1803,24 @@
 		ast_mutex_unlock(&vms_p->lock);
 	}
 	return 0;
+}
+
+/*!
+ * \brief Gets the number of messages that exist in a mailbox folder.
+ * \param context
+ * \param mailbox
+ * \param folder
+ *
+ * This method is used when IMAP backend is used.
+ * \return The number of messages in this mailbox folder (zero or more).
+ */
+static int messagecount(const char *context, const char *mailbox, const 
+char *folder) {
+	if (!strcmp(folder, "INBOX")) {
+		return __messagecount(context, mailbox, "INBOX") +
__messagecount(context, mailbox, "Urgent");
+	} else {
+		return __messagecount(context, mailbox, folder);
+	}
 }
 
 static int imap_store_file(char *dir, char *mailboxuser, char
*mailboxcontext, int msgnum, struct ast_channel *chan, struct ast_vm_user
*vmu, char *fmt, int duration, struct vm_state *vms, const char *flag) @@
-1998,23 +2007,21 @@
 		mailboxnc = (char *)mailbox_context;
 	}
 	if (newmsgs) {
-		if ((*newmsgs = messagecount(context, mailboxnc,
imapfolder)) < 0)
+		if ((*newmsgs = __messagecount(context, mailboxnc,
imapfolder)) < 0) 
+{
 			return -1;
+		}
 	}
 	if (oldmsgs) {
-		if ((*oldmsgs = messagecount(context, mailboxnc, "Old")) <
0)
+		if ((*oldmsgs = __messagecount(context, mailboxnc, "Old")) <
0) {
 			return -1;
+		}
 	}
 	if (urgentmsgs) {
-		if((*urgentmsgs = messagecount(context, mailboxnc,
"Urgent")) < 0)
+		if ((*urgentmsgs = __messagecount(context, mailboxnc,
"Urgent")) < 0) 
+{
 			return -1;
+		}
 	}
 	return 0;
-}
-
-static int inboxcount(const char *mailbox_context, int *newmsgs, int
*oldmsgs) -{
-	return inboxcount2(mailbox_context, NULL, newmsgs, oldmsgs);
 }
 
 /**
@@ -2032,19 +2039,21 @@
 	char tmp[256], *tmp2, *box, *context;
 	ast_copy_string(tmp, mailbox, sizeof(tmp));
 	tmp2 = tmp;
-	if (strchr(tmp2, ',')) {
-		while ((box = strsep(&tmp2, ","))) {
+	if (strchr(tmp2, ',') || strchr(tmp2, '&')) {
+		while ((box = strsep(&tmp2, ",&"))) {
 			if (!ast_strlen_zero(box)) {
-				if (has_voicemail(box, folder))
+				if (has_voicemail(box, folder)) {
 					return 1;
-			}
-		}
-	}
-	if ((context= strchr(tmp, '@')))
+				}
+			}
+		}
+	}
+	if ((context = strchr(tmp, '@'))) {
 		*context++ = '\0';
-	else
+	} else {
 		context = "default";
-	return messagecount(context, tmp, folder) ? 1 : 0;
+	}
+	return __messagecount(context, tmp, folder) ? 1 : 0;
 }
 
 /*!
@@ -4648,11 +4657,6 @@
 	return x;
 }
 
-static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs) -{
-	return inboxcount2(mailbox, NULL, newmsgs, oldmsgs);
-}
-
 /*!
  * \brief Gets the number of messages that exist in a mailbox folder.
  * \param context
@@ -4679,7 +4683,11 @@
 
 	obj = ast_odbc_request_obj(odbc_database, 0);
 	if (obj) {
-		snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE
dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox, folder);
+		if (!strcmp(folder, "INBOX")) {
+			snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s
WHERE dir = '%s%s/%s/INBOX' OR dir = '%s%s/%s/Urgent", odbc_table,
VM_SPOOL_DIR, context, mailbox, VM_SPOOL_DIR, context, mailbox);
+		} else {
+			snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s
WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, mailbox,
folder);
+		}
 		stmt = ast_odbc_prepare_and_execute(obj, generic_prepare,
&gps);
 		if (!stmt) {
 			ast_log(AST_LOG_WARNING, "SQL Execute
error!\n[%s]\n\n", sql); @@ -4720,7 +4728,7 @@  {
 	char tmp[256], *tmp2 = tmp, *box, *context;
 	ast_copy_string(tmp, mailbox, sizeof(tmp));
-	while ((context = box = strsep(&tmp2, ","))) {
+	while ((context = box = strsep(&tmp2, ",&"))) {
 		strsep(&context, "@");
 		if (ast_strlen_zero(context))
 			context = "default";
@@ -4799,7 +4807,7 @@
 
 static int messagecount(const char *context, const char *mailbox, const
char *folder)  {
-	return __has_voicemail(context, mailbox, folder, 0);
+	return __has_voicemail(context, mailbox, folder, 0) +
(strcmp(folder, 
+"INBOX") ? 0 : __has_voicemail(context, mailbox, "Urgent", 0));
 }
 
 static int __has_voicemail(const char *context, const char *mailbox, const
char *folder, int shortcircuit) @@ -4829,7 +4837,6 @@
 				ret = 1;
 				break;
 			} else if (!strncasecmp(de->d_name + 8, "txt", 3)) {
-				if (shortcircuit) return 1;
 				ret++;
 			}
 		}
@@ -4837,12 +4844,7 @@
 
 	closedir(dir);
 
-	/* If we are checking INBOX, we should check Urgent as well */
-	if (strcmp(folder, "INBOX") == 0) {
-		return (ret + __has_voicemail(context, mailbox, "Urgent",
shortcircuit));
-	} else {
-		return ret;
-	}
+	return ret;
 }
 
 /**
@@ -4851,20 +4853,24 @@
  * \param folder the folder to look in
  *
  * This function is used when the mailbox is stored in a filesystem back
end.
- * This invokes the messagecount(). Here we are interested in the presence
of messages (> 0) only, not the actual count.
+ * This invokes the __has_voicemail(). Here we are interested in the
presence of messages (> 0) only, not the actual count.
  * \return 1 if the folder has one or more messages. zero otherwise.
  */
 static int has_voicemail(const char *mailbox, const char *folder)  {
 	char tmp[256], *tmp2 = tmp, *box, *context;
 	ast_copy_string(tmp, mailbox, sizeof(tmp));
-	while ((box = strsep(&tmp2, ","))) {
+	while ((box = strsep(&tmp2, ",&"))) {
 		if ((context = strchr(box, '@')))
 			*context++ = '\0';
 		else
 			context = "default";
 		if (__has_voicemail(context, box, folder, 1))
 			return 1;
+		/* If we are checking INBOX, we should check Urgent as well
*/
+		if (!strcmp(folder, "INBOX") && __has_voicemail(context,
box, "Urgent", 1)) {
+			return 1;
+		}
 	}
 	return 0;
 }
@@ -4926,12 +4932,18 @@
 	return 0;
 }
 
+#endif
+
+/* Exactly the same function for file-based, ODBC-based, and 
+IMAP-based, so why create 3 different copies? */
 static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)  {
-	return inboxcount2(mailbox, NULL, newmsgs, oldmsgs);
-}
-
-#endif
+	int urgentmsgs = 0;
+	int res = inboxcount2(mailbox, &urgentmsgs, newmsgs, oldmsgs);
+	if (newmsgs) {
+		*newmsgs += urgentmsgs;
+	}
+	return res;
+}
 
 static void run_externnotify(char *context, char *extension, const char
*flag)  { @@ -5456,11 +5468,14 @@
 						int x;
 						/* It's easier just to try
to make it than to check for its existence */
 						create_dirpath(urgdir,
sizeof(urgdir), vmu->context, ext, "Urgent");
-						ast_debug(5, "Created an
Urgent message, moving file from %s to %s.\n",sfn,dfn);
 						x = last_message_index(vmu,
urgdir) + 1;
 						make_file(sfn, sizeof(sfn),
dir, msgnum);
 						make_file(dfn, sizeof(dfn),
urgdir, x);
+						ast_debug(5, "Created an
Urgent message, moving file from %s to 
+%s.\n", sfn, dfn);
 						RENAME(dir, msgnum,
vmu->mailbox, vmu->context, urgdir, x, sfn, dfn);
+						/* Notification must happen
for this new message in Urgent folder, not INBOX */
+						ast_copy_string(fn, dfn,
sizeof(fn));
+						msgnum = x;
 					}
 #endif
 					/* Notification needs to happen
after the copy, though. */ @@ -6352,7 +6367,7 @@
 	}
 	ast_channel_unlock(chan);
 
-	make_dir(todir, sizeof(todir), vmu->context, vmu->mailbox, "INBOX");
+	make_dir(todir, sizeof(todir), vmu->context, vmu->mailbox, 
+!ast_strlen_zero(flag) && !strcmp(flag, "Urgent") ? "Urgent" : 
+"INBOX");
 	make_file(fn, sizeof(fn), todir, msgnum);
 	snprintf(ext_context, sizeof(ext_context), "%s@%s", vmu->mailbox,
vmu->context);
 


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --

asterisk-commits mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-commits




More information about the asterisk-dev mailing list