aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--UPGRADE.txt6
-rw-r--r--app.c24
-rw-r--r--apps/app_hasnewvoicemail.c4
-rw-r--r--apps/app_voicemail.c95
-rw-r--r--channels/chan_iax2.c2
-rw-r--r--channels/chan_sip.c2
-rw-r--r--channels/chan_skinny.c2
-rw-r--r--include/asterisk/app.h8
-rw-r--r--manager.c2
9 files changed, 56 insertions, 89 deletions
diff --git a/UPGRADE.txt b/UPGRADE.txt
index 07f68b20b..b05600152 100644
--- a/UPGRADE.txt
+++ b/UPGRADE.txt
@@ -107,6 +107,12 @@ Applications:
to specify which DTMF digits can be used to accept a recording and
which digits can be used to cancel a recording.
+* ast_app_messagecount has been renamed to ast_app_inboxcount. There is now a
+ new ast_app_messagecount function which takes a single context/mailbox/folder
+ mailbox specification and returns the message count for that folder only.
+ This addresses the deficiency of not being able to count the number of
+ messages in folders other than INBOX and Old.
+
Manager:
* After executing the 'status' manager action, the "Status" manager events
diff --git a/app.c b/app.c
index 03e0fe2b3..8c6ceffa7 100644
--- a/app.c
+++ b/app.c
@@ -145,23 +145,23 @@ int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxle
}
static int (*ast_has_voicemail_func)(const char *mailbox, const char *folder) = NULL;
-static int (*ast_messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL;
-static int (*ast_messagecount2_func)(const char *context, const char *mailbox, const char *folder) = NULL;
+static int (*ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = 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 (*messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
- int (*messagecount2_func)(const char *context, const char *mailbox, const char *folder))
+ int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
+ int (*messagecount_func)(const char *context, const char *mailbox, const char *folder))
{
ast_has_voicemail_func = has_voicemail_func;
+ ast_inboxcount_func = inboxcount_func;
ast_messagecount_func = messagecount_func;
- ast_messagecount2_func = messagecount2_func;
}
void ast_uninstall_vm_functions(void)
{
ast_has_voicemail_func = NULL;
+ ast_inboxcount_func = NULL;
ast_messagecount_func = NULL;
- ast_messagecount2_func = NULL;
}
int ast_app_has_voicemail(const char *mailbox, const char *folder)
@@ -178,15 +178,15 @@ int ast_app_has_voicemail(const char *mailbox, const char *folder)
}
-int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
{
static int warned = 0;
if (newmsgs)
*newmsgs = 0;
if (oldmsgs)
*oldmsgs = 0;
- if (ast_messagecount_func)
- return ast_messagecount_func(mailbox, newmsgs, oldmsgs);
+ if (ast_inboxcount_func)
+ return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
if (!warned && (option_verbose > 2)) {
warned++;
@@ -196,11 +196,11 @@ int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
return 0;
}
-int ast_app_messagecount2(const char *context, const char *mailbox, const char *folder)
+int ast_app_messagecount(const char *context, const char *mailbox, const char *folder)
{
static int warned = 0;
- if (ast_messagecount2_func)
- return ast_messagecount2_func(context, mailbox, folder);
+ if (ast_messagecount_func)
+ return ast_messagecount_func(context, mailbox, folder);
if (!warned && (option_verbose > 2)) {
warned++;
diff --git a/apps/app_hasnewvoicemail.c b/apps/app_hasnewvoicemail.c
index 312e18231..a40a4874c 100644
--- a/apps/app_hasnewvoicemail.c
+++ b/apps/app_hasnewvoicemail.c
@@ -128,7 +128,7 @@ static int hasvoicemail_exec(struct ast_channel *chan, void *data)
priority_jump = 1;
}
- vmcount = ast_app_messagecount2(context, vmbox, vmfolder);
+ vmcount = ast_app_messagecount(context, vmbox, vmfolder);
/* Set the count in the channel variable */
if (varname) {
snprintf(tmp, sizeof(tmp), "%d", vmcount);
@@ -177,7 +177,7 @@ static int acf_vmcount_exec(struct ast_channel *chan, char *cmd, char *argsstr,
args.folder = "INBOX";
}
- snprintf(buf, len, "%d", ast_app_messagecount2(context, args.vmbox, args.folder));
+ snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
LOCAL_USER_REMOVE(u);
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 59786c3b0..25cca1ec5 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -2012,7 +2012,7 @@ static const char *mbox(int id)
}
#ifdef USE_ODBC_STORAGE
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
{
int x = -1;
int res;
@@ -2127,7 +2127,7 @@ yuck:
return x;
}
-static int messagecount2(const char *context, const char *mailbox, const char *folder)
+static int messagecount(const char *context, const char *mailbox, const char *folder)
{
struct odbc_obj *obj = NULL;
int nummsgs = 0;
@@ -2193,7 +2193,7 @@ static int has_voicemail(const char *mailbox, const char *folder)
else
context = "default";
- if (messagecount2(context, tmp, folder))
+ if (messagecount(context, tmp, folder))
return 1;
else
return 0;
@@ -2201,42 +2201,20 @@ static int has_voicemail(const char *mailbox, const char *folder)
#else
-static int __has_voicemail(const char *mailbox, const char *folder, int shortcircuit)
+static int __has_voicemail(const char *context, const char *mailbox, const char *folder, int shortcircuit)
{
DIR *dir;
struct dirent *de;
char fn[256];
- char tmp[256]="";
- char *mb, *cur;
- char *context;
int ret = 0;
if (!folder)
folder = "INBOX";
/* If no mailbox, return immediately */
if (ast_strlen_zero(mailbox))
return 0;
- if (strchr(mailbox, ',')) {
- ast_copy_string(tmp, mailbox, sizeof(tmp));
- mb = tmp;
- ret = 0;
- while((cur = strsep(&mb, ","))) {
- if (!ast_strlen_zero(cur)) {
- if ((ret += __has_voicemail(cur, folder, shortcircuit))) {
- if (shortcircuit)
- return 1;
- }
- }
- }
- return ret;
- }
- ast_copy_string(tmp, mailbox, sizeof(tmp));
- context = strchr(tmp, '@');
- if (context) {
- *context = '\0';
- context++;
- } else
+ if (!context)
context = "default";
- snprintf(fn, sizeof(fn), "%s%s/%s/%s", VM_SPOOL_DIR, context, tmp, folder);
+ snprintf(fn, sizeof(fn), "%s%s/%s/%s", VM_SPOOL_DIR, context, mailbox, folder);
dir = opendir(fn);
if (!dir)
return 0;
@@ -2255,21 +2233,26 @@ static int __has_voicemail(const char *mailbox, const char *folder, int shortcir
static int has_voicemail(const char *mailbox, const char *folder)
{
- return __has_voicemail(mailbox, folder, 1);
+ char tmp[256], *tmp2 = tmp, *mbox, *context;
+ ast_copy_string(tmp, mailbox, sizeof(tmp));
+ while ((mbox = strsep(&tmp2, ","))) {
+ if ((context = strchr(tmp2, '@')))
+ *context++ = '\0';
+ else
+ context = "default";
+ if (__has_voicemail(context, mbox, folder, 1))
+ return 1;
+ }
+ return 0;
}
-static int messagecount2(const char *context, const char *mailbox, const char *folder)
+static int messagecount(const char *context, const char *mailbox, const char *folder)
{
- char tmp[256];
- snprintf(tmp, sizeof(tmp), "%s@%s", mailbox, context);
- return __has_voicemail(tmp, folder, 0);
+ return __has_voicemail(context, mailbox, folder, 0);
}
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
{
- DIR *dir;
- struct dirent *de;
- char fn[256];
char tmp[256];
char *context;
@@ -2288,7 +2271,7 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
mb = tmp;
while((cur = strsep(&mb, ", "))) {
if (!ast_strlen_zero(cur)) {
- if (messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+ if (inboxcount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
return -1;
else {
if (newmsgs)
@@ -2307,32 +2290,10 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
context++;
} else
context = "default";
- if (newmsgs) {
- snprintf(fn, sizeof(fn), "%s%s/%s/INBOX", VM_SPOOL_DIR, context, tmp);
- dir = opendir(fn);
- if (dir) {
- while ((de = readdir(dir))) {
- if ((strlen(de->d_name) > 3) && !strncasecmp(de->d_name, "msg", 3) &&
- !strcasecmp(de->d_name + strlen(de->d_name) - 3, "txt"))
- (*newmsgs)++;
-
- }
- closedir(dir);
- }
- }
- if (oldmsgs) {
- snprintf(fn, sizeof(fn), "%s%s/%s/Old", VM_SPOOL_DIR, context, tmp);
- dir = opendir(fn);
- if (dir) {
- while ((de = readdir(dir))) {
- if ((strlen(de->d_name) > 3) && !strncasecmp(de->d_name, "msg", 3) &&
- !strcasecmp(de->d_name + strlen(de->d_name) - 3, "txt"))
- (*oldmsgs)++;
-
- }
- closedir(dir);
- }
- }
+ if (newmsgs)
+ *newmsgs = __has_voicemail(context, tmp, "INBOX", 0);
+ if (oldmsgs)
+ *oldmsgs = __has_voicemail(context, tmp, "Old", 0);
return 0;
}
@@ -2410,7 +2371,7 @@ static void run_externnotify(char *context, char *extension)
#else
if (!ast_strlen_zero(externnotify)) {
#endif
- if (messagecount(ext_context, &newvoicemails, &oldvoicemails)) {
+ if (inboxcount(ext_context, &newvoicemails, &oldvoicemails)) {
ast_log(LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
} else {
snprintf(arguments, sizeof(arguments), "%s %s %s %d&", externnotify, context, extension, newvoicemails);
@@ -3417,7 +3378,7 @@ static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu,
/* Leave voicemail for someone */
if (ast_app_has_voicemail(ext_context, NULL)) {
- ast_app_messagecount(ext_context, &newmsgs, &oldmsgs);
+ ast_app_inboxcount(ext_context, &newmsgs, &oldmsgs);
}
manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s@%s\r\nWaiting: %d\r\nNew: %d\r\nOld: %d\r\n", vmu->mailbox, vmu->context, ast_app_has_voicemail(ext_context, NULL), newmsgs, oldmsgs);
run_externnotify(vmu->context, vmu->mailbox);
@@ -6654,7 +6615,7 @@ static int load_module(void *mod)
/* compute the location of the voicemail spool directory */
snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);
- ast_install_vm_functions(has_voicemail, messagecount, messagecount2);
+ ast_install_vm_functions(has_voicemail, inboxcount, messagecount);
#if defined(USE_ODBC_STORAGE) && !defined(EXTENDED_ODBC_STORAGE)
ast_log(LOG_WARNING, "The current ODBC storage table format will be changed soon."
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 67aad714f..e98c6caaa 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -5677,7 +5677,7 @@ static int update_registry(char *name, struct sockaddr_in *sin, int callno, char
iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
if (!ast_strlen_zero(p->mailbox)) {
int new, old;
- ast_app_messagecount(p->mailbox, &new, &old);
+ ast_app_inboxcount(p->mailbox, &new, &old);
if (new > 255)
new = 255;
if (old > 255)
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 61cc31ca3..44e44f864 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -12193,7 +12193,7 @@ static int sip_send_mwi_to_peer(struct sip_peer *peer)
int newmsgs, oldmsgs;
/* Check for messages */
- ast_app_messagecount(peer->mailbox, &newmsgs, &oldmsgs);
+ ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs);
time(&peer->lastmsgcheck);
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index e219bd9b7..f157acb28 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -1311,7 +1311,7 @@ static void do_housekeeping(struct skinnysession *s)
if (skinnydebug) {
ast_verbose("Checking for voicemail Skinny %s@%s\n", sub->parent->name, sub->parent->parent->name);
}
- ast_app_messagecount(sub->parent->mailbox, &new, &old);
+ ast_app_inboxcount(sub->parent->mailbox, &new, &old);
if (skinnydebug) {
ast_verbose("Skinny %s@%s has voicemail!\n", sub->parent->name, sub->parent->parent->name);
}
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index b6b3574c2..af3aa31f9 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -100,8 +100,8 @@ int ast_app_getdata(struct ast_channel *c, char *prompt, char *s, int maxlen, in
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 (*messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
- int (*messagecount2_func)(const char *context, const char *mailbox, const char *folder));
+ int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
+ int (*messagecount_func)(const char *context, const char *mailbox, const char *folder));
void ast_uninstall_vm_functions(void);
@@ -109,10 +109,10 @@ void ast_uninstall_vm_functions(void);
int ast_app_has_voicemail(const char *mailbox, const char *folder);
/*! Determine number of new/old messages in a mailbox */
-int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs);
+int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs);
/*! Determine number of messages in a given mailbox and folder */
-int ast_app_messagecount2(const char *context, const char *mailbox, const char *folder);
+int ast_app_messagecount(const char *context, const char *mailbox, const char *folder);
/*! Safely spawn an external program while closing file descriptors
\note This replaces the \b system call in all Asterisk modules
diff --git a/manager.c b/manager.c
index 0a6b79469..a86cf58e3 100644
--- a/manager.c
+++ b/manager.c
@@ -1520,7 +1520,7 @@ static int action_mailboxcount(struct mansession *s, struct message *m)
astman_send_error(s, m, "Mailbox not specified");
return 0;
}
- ast_app_messagecount(mailbox, &newmsgs, &oldmsgs);
+ ast_app_inboxcount(mailbox, &newmsgs, &oldmsgs);
if (!ast_strlen_zero(id)) {
snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
}