[asterisk-commits] tilghman: trunk r127609 - in /trunk: apps/ channels/ include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 2 16:27:53 CDT 2008


Author: tilghman
Date: Wed Jul  2 16:27:53 2008
New Revision: 127609

URL: http://svn.digium.com/view/asterisk?view=rev&rev=127609
Log:
Keep ast_app_inboxcount API compatible with 1.6.0.

Modified:
    trunk/apps/app_voicemail.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c
    trunk/channels/chan_unistim.c
    trunk/include/asterisk/app.h
    trunk/main/app.c
    trunk/main/manager.c

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Wed Jul  2 16:27:53 2008
@@ -2886,7 +2886,7 @@
 
 #ifdef ODBC_STORAGE
 /*! XXX \todo Fix this function to support multiple mailboxes in the intput string */
-static int inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
+static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	int x = -1;
 	int res;
@@ -2967,7 +2967,13 @@
 		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 		*oldmsgs = atoi(rowdata);
-		
+
+		if (!urgentmsgs) {
+			x = 0;
+			ast_odbc_release_obj(obj);
+			goto yuck;
+		}
+
 		snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir = '%s%s/%s/%s'", odbc_table, VM_SPOOL_DIR, context, tmp, "Urgent");
 		stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
 		if (!stmt) {
@@ -2998,6 +3004,11 @@
 		
 yuck:	
 	return x;
+}
+
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+{
+	return inboxcount2(mailbox, NULL, newmsgs, oldmsgs);
 }
 
 /*!
@@ -3333,7 +3344,7 @@
  *
  * \return zero on success, -1 on error.
  */
-static int inboxcount(const char *mailbox_context, int *urgentmsgs, int *newmsgs, int *oldmsgs)
+static int inboxcount2(const char *mailbox_context, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	char tmp[PATH_MAX] = "";
 	char *mailboxnc;
@@ -3360,7 +3371,7 @@
 		mb = tmp;
 		while ((cur = strsep(&mb, ", "))) {
 			if (!ast_strlen_zero(cur)) {
-				if (inboxcount(cur, urgentmsgs ? &tmpurgent : NULL, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+				if (inboxcount2(cur, urgentmsgs ? &tmpurgent : NULL, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
 					return -1;
 				else {
 					if (newmsgs)
@@ -3396,7 +3407,11 @@
 	}
 	return 0;
 }
-	
+
+static int inboxcount(const char *mailbox_context, int *newmsgs, int *oldmsgs)
+{
+	return inboxcount2(mailbox_context, NULL, newmsgs, oldmsgs);
+}
 
 /** 
  * \brief Determines if the given folder has messages.
@@ -3591,7 +3606,7 @@
 }
 
 
-static int inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
+static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	char tmp[256];
 	char *context;
@@ -3647,6 +3662,11 @@
 	return 0;
 }
 
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+{
+	return inboxcount2(mailbox, NULL, newmsgs, oldmsgs);
+}
+
 #endif
 
 static void run_externnotify(char *context, char *extension, const char *flag)
@@ -3681,10 +3701,10 @@
 	}
 
 	if (!ast_strlen_zero(externnotify)) {
-		if (inboxcount(ext_context, &urgentvoicemails, &newvoicemails, &oldvoicemails)) {
+		if (inboxcount2(ext_context, &urgentvoicemails, &newvoicemails, &oldvoicemails)) {
 			ast_log(AST_LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
 		} else {
-			snprintf(arguments, sizeof(arguments), "%s %s %s %d %d&", externnotify, context, extension, newvoicemails, urgentvoicemails);
+			snprintf(arguments, sizeof(arguments), "%s %s %s %d %d %d &", externnotify, context, extension, newvoicemails, oldvoicemails, urgentvoicemails);
 			ast_debug(1, "Executing %s\n", arguments);
 			ast_safe_system(arguments);
 		}
@@ -3956,7 +3976,7 @@
 #ifdef IMAP_STORAGE
 		/* Is ext a mailbox? */
 		/* must open stream for this user to get info! */
-		res = inboxcount(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
+		res = inboxcount(ext_context, &newmsgs, &oldmsgs);
 		if (res < 0) {
 			ast_log(AST_LOG_NOTICE, "Can not leave voicemail, unable to count messages\n");
 			return -1;
@@ -5061,7 +5081,7 @@
 
 	/* Leave voicemail for someone */
 	if (ast_app_has_voicemail(ext_context, NULL)) 
-		ast_app_inboxcount(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
+		ast_app_inboxcount2(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
 
 	queue_mwi_event(ext_context, urgentmsgs, newmsgs, oldmsgs);
 
@@ -8656,7 +8676,7 @@
 		manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
 		/* Urgent flag not passwd to externnotify here */
 		run_externnotify(vmu->context, vmu->mailbox, NULL);
-		ast_app_inboxcount(ext_context, &urgent, &new, &old);
+		ast_app_inboxcount2(ext_context, &urgent, &new, &old);
 		queue_mwi_event(ext_context, urgent, new, old);
 	}
 #ifdef IMAP_STORAGE
@@ -8803,7 +8823,7 @@
 	strcat(mailbox_full, "@");
 	strcat(mailbox_full, context);
 
-	inboxcount(mailbox_full, &urgent, &new, &old);
+	inboxcount2(mailbox_full, &urgent, &new, &old);
 	queue_mwi_event(mailbox_full, urgent, new, old);
 
 	return 0;
@@ -9028,13 +9048,13 @@
 		}
 	}
 	AST_LIST_TRAVERSE(&users, vmu, list) {
-		int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;
+		int newmsgs = 0, oldmsgs = 0;
 		char count[12], tmp[256] = "";
 
 		if ((a->argc == 3) || ((a->argc == 5) && !strcmp(context, vmu->context))) {
 			snprintf(tmp, sizeof(tmp), "%s@%s", vmu->mailbox, ast_strlen_zero(vmu->context) ? "default" : vmu->context);
-			inboxcount(tmp, &urgentmsgs, &newmsgs, &oldmsgs);
-			snprintf(count,sizeof(count),"%d",newmsgs+urgentmsgs);
+			inboxcount(tmp, &newmsgs, &oldmsgs);
+			snprintf(count, sizeof(count), "%d", newmsgs);
 			ast_cli(a->fd, HVSU_OUTPUT_FORMAT, vmu->context, vmu->mailbox, vmu->fullname, vmu->zonetag, count);
 			users_counter++;
 		}
@@ -9120,7 +9140,7 @@
 		if (ast_strlen_zero(mwi_sub->mailbox))
 			continue;
 
-		inboxcount(mwi_sub->mailbox, &urgent, &new, &old);
+		inboxcount2(mwi_sub->mailbox, &urgent, &new, &old);
 
 		if (urgent != mwi_sub->old_urgent || new != mwi_sub->old_new || old != mwi_sub->old_old) {
 			mwi_sub->old_urgent = urgent;
@@ -9320,8 +9340,8 @@
 		char dirname[256];
 
 #ifdef IMAP_STORAGE
-		int new, old, urgent;
-		inboxcount (vmu->mailbox, &urgent, &new, &old);
+		int new, old;
+		inboxcount(vmu->mailbox, &new, &old);
 #endif
 		
 		make_dir(dirname, sizeof(dirname), vmu->context, vmu->mailbox, "INBOX");
@@ -10128,7 +10148,7 @@
 
 	ast_cli_register_multiple(cli_voicemail, sizeof(cli_voicemail) / sizeof(struct ast_cli_entry));
 
-	ast_install_vm_functions(has_voicemail, inboxcount, messagecount, sayname);
+	ast_install_vm_functions(has_voicemail, inboxcount, inboxcount2, messagecount, sayname);
 	ast_realtime_require_field("voicemail", "uniqueid", RQ_UINTEGER3, 11, "password", RQ_CHAR, 10, SENTINEL);
 	ast_realtime_require_field("voicemail_data", "filename", RQ_CHAR, 30, "duration", RQ_UINTEGER3, 5, SENTINEL);
 

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Wed Jul  2 16:27:53 2008
@@ -6948,7 +6948,7 @@
 		iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
 		if (!ast_strlen_zero(p->mailbox)) {
 			struct ast_event *event;
-			int new, old, urgent;
+			int new, old;
 			char *mailbox, *context;
 
 			context = mailbox = ast_strdupa(p->mailbox);
@@ -6966,15 +6966,16 @@
 				new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
 				old = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
 				ast_event_destroy(event);
-			} else /* Fall back on checking the mailbox directly */
-				ast_app_inboxcount(p->mailbox, &urgent, &new, &old);
-
-			if (urgent > 255)
-				urgent = 255;
-			if (new > 255)
+			} else { /* Fall back on checking the mailbox directly */
+				ast_app_inboxcount(p->mailbox, &new, &old);
+			}
+
+			if (new > 255) {
 				new = 255;
-			if (old > 255)
+			}
+			if (old > 255) {
 				old = 255;
+			}
 			msgcount = (old << 8) | new;
 
 			iax_ie_append_short(&ied, IAX_IE_MSGCOUNT, msgcount);

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Wed Jul  2 16:27:53 2008
@@ -19750,7 +19750,7 @@
 {
 	/* Called with peerl lock, but releases it */
 	struct sip_pvt *p;
-	int newmsgs = 0, oldmsgs = 0, urgentmsgs = 0;
+	int newmsgs = 0, oldmsgs = 0;
 
 	if (ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY) && !peer->mwipvt)
 		return 0;
@@ -19769,7 +19769,7 @@
 	} else { /* Fall back to manually checking the mailbox */
 		struct ast_str *mailbox_str = ast_str_alloca(512);
 		peer_mailboxes_to_str(&mailbox_str, peer);
-		ast_app_inboxcount(mailbox_str->str, &urgentmsgs, &newmsgs, &oldmsgs);
+		ast_app_inboxcount(mailbox_str->str, &newmsgs, &oldmsgs);
 	}
 	
 	if (peer->mwipvt) {

Modified: trunk/channels/chan_unistim.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_unistim.c?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/channels/chan_unistim.c (original)
+++ trunk/channels/chan_unistim.c Wed Jul  2 16:27:53 2008
@@ -4375,7 +4375,7 @@
 static int unistim_send_mwi_to_peer(struct unistimsession *s, unsigned int tick)
 {
 	struct ast_event *event;
-	int new, old, urgent;
+	int new;
 	char *mailbox, *context;
 	struct unistim_line *peer = s->device->lines;
 
@@ -4388,27 +4388,28 @@
 		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);
 
 	if (event) {
 		new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-		old = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
 		ast_event_destroy(event);
-	} else /* Fall back on checking the mailbox directly */
-		ast_app_inboxcount(peer->mailbox, &urgent, &new, &old);
+	} else { /* Fall back on checking the mailbox directly */
+		new = ast_app_has_voicemail(peer->mailbox, "INBOX");
+	}
 
 	peer->nextmsgcheck = tick + TIMER_MWI;
 
 	/* Return now if it's the same thing we told them last time */
-	if (((new << 8) | (old)) == peer->lastmsgssent)
+	if (new == peer->lastmsgssent) {
 		return 0;
-
-	peer->lastmsgssent = ((new << 8) | (old));
-	if (new == 0)
+	}
+
+	peer->lastmsgssent = new;
+	if (new == 0) {
 		send_led_update(s, 0);
-	else
+	} else {
 		send_led_update(s, 1);
+	}
 
 	return 0;
 }

Modified: trunk/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/app.h?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/include/asterisk/app.h (original)
+++ trunk/include/asterisk/app.h Wed Jul  2 16:27:53 2008
@@ -104,17 +104,21 @@
 int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd);
 
 void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder),
-			      int (*inboxcount_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs),
+			      int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
+			      int (*inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs),
 			      int (*messagecount_func)(const char *context, const char *mailbox, const char *folder),
 			      int (*sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context));
-  
+
 void ast_uninstall_vm_functions(void);
 
 /*! \brief Determine if a given mailbox has any voicemail */
 int ast_app_has_voicemail(const char *mailbox, const char *folder);
 
+/*! \brief Determine number of new/old messages in a mailbox */
+int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs);
+
 /*! \brief Determine number of urgent/new/old messages in a mailbox */
-int ast_app_inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs);
+int ast_app_inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs);
 
 /*! Given a mailbox and context, play that mailbox owner's name to the channel specified */
 int ast_app_sayname(struct ast_channel *chan, const char *mailbox, const char *context);

Modified: trunk/main/app.c
URL: http://svn.digium.com/view/asterisk/trunk/main/app.c?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/main/app.c (original)
+++ trunk/main/app.c Wed Jul  2 16:27:53 2008
@@ -176,17 +176,20 @@
 }
 
 static int (*ast_has_voicemail_func)(const char *mailbox, const char *folder) = NULL;
-static int (*ast_inboxcount_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs) = NULL;
+static int (*ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL;
+static int (*ast_inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs) = NULL;
 static int (*ast_sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context) = NULL;
 static int (*ast_messagecount_func)(const char *context, const char *mailbox, const char *folder) = NULL;
 
 void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder),
-			      int (*inboxcount_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs),
+			      int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
+			      int (*inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs),
 			      int (*messagecount_func)(const char *context, const char *mailbox, const char *folder),
 			      int (*sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context))
 {
 	ast_has_voicemail_func = has_voicemail_func;
 	ast_inboxcount_func = inboxcount_func;
+	ast_inboxcount2_func = inboxcount2_func;
 	ast_messagecount_func = messagecount_func;
 	ast_sayname_func = sayname_func;
 }
@@ -195,6 +198,7 @@
 {
 	ast_has_voicemail_func = NULL;
 	ast_inboxcount_func = NULL;
+	ast_inboxcount2_func = NULL;
 	ast_messagecount_func = NULL;
 	ast_sayname_func = NULL;
 }
@@ -213,17 +217,42 @@
 }
 
 
-int ast_app_inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
+int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
 {
 	static int warned = 0;
-	if (newmsgs)
+	if (newmsgs) {
 		*newmsgs = 0;
-	if (oldmsgs)
+	}
+	if (oldmsgs) {
 		*oldmsgs = 0;
-	if (urgentmsgs)
+	}
+	if (ast_inboxcount_func) {
+		return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
+	}
+
+	if (!warned) {
+		warned++;
+		ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
+	}
+
+	return 0;
+}
+
+int ast_app_inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
+{
+	static int warned = 0;
+	if (newmsgs) {
+		*newmsgs = 0;
+	}
+	if (oldmsgs) {
+		*oldmsgs = 0;
+	}
+	if (urgentmsgs) {
 		*urgentmsgs = 0;
-	if (ast_inboxcount_func)
-		return ast_inboxcount_func(mailbox, urgentmsgs, newmsgs, oldmsgs);
+	}
+	if (ast_inboxcount_func) {
+		return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs);
+	}
 
 	if (!warned) {
 		warned++;

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=127609&r1=127608&r2=127609
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Wed Jul  2 16:27:53 2008
@@ -2430,7 +2430,7 @@
 		astman_send_error(s, m, "Mailbox not specified");
 		return 0;
 	}
-	ast_app_inboxcount(mailbox, &urgentmsgs, &newmsgs, &oldmsgs);
+	ast_app_inboxcount2(mailbox, &urgentmsgs, &newmsgs, &oldmsgs);
 	astman_start_ack(s, m);
 	astman_append(s,   "Message: Mailbox Message Count\r\n"
 			   "Mailbox: %s\r\n"




More information about the asterisk-commits mailing list