As requested by kpfleming, renaming messagecount to inboxcount and messagecount2 to messagecount.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@28745 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.4
Tilghman Lesher 19 years ago
parent 50775a944d
commit d0c36296d2

@ -107,6 +107,12 @@ Applications:
to specify which DTMF digits can be used to accept a recording and to specify which DTMF digits can be used to accept a recording and
which digits can be used to cancel a recording. 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: Manager:
* After executing the 'status' manager action, the "Status" manager events * After executing the 'status' manager action, the "Status" manager events

24
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_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_inboxcount_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_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), 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 (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
int (*messagecount2_func)(const char *context, const char *mailbox, const char *folder)) int (*messagecount_func)(const char *context, const char *mailbox, const char *folder))
{ {
ast_has_voicemail_func = has_voicemail_func; ast_has_voicemail_func = has_voicemail_func;
ast_inboxcount_func = inboxcount_func;
ast_messagecount_func = messagecount_func; ast_messagecount_func = messagecount_func;
ast_messagecount2_func = messagecount2_func;
} }
void ast_uninstall_vm_functions(void) void ast_uninstall_vm_functions(void)
{ {
ast_has_voicemail_func = NULL; ast_has_voicemail_func = NULL;
ast_inboxcount_func = NULL;
ast_messagecount_func = NULL; ast_messagecount_func = NULL;
ast_messagecount2_func = NULL;
} }
int ast_app_has_voicemail(const char *mailbox, const char *folder) 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; static int warned = 0;
if (newmsgs) if (newmsgs)
*newmsgs = 0; *newmsgs = 0;
if (oldmsgs) if (oldmsgs)
*oldmsgs = 0; *oldmsgs = 0;
if (ast_messagecount_func) if (ast_inboxcount_func)
return ast_messagecount_func(mailbox, newmsgs, oldmsgs); return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
if (!warned && (option_verbose > 2)) { if (!warned && (option_verbose > 2)) {
warned++; warned++;
@ -196,11 +196,11 @@ int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
return 0; 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; static int warned = 0;
if (ast_messagecount2_func) if (ast_messagecount_func)
return ast_messagecount2_func(context, mailbox, folder); return ast_messagecount_func(context, mailbox, folder);
if (!warned && (option_verbose > 2)) { if (!warned && (option_verbose > 2)) {
warned++; warned++;

@ -128,7 +128,7 @@ static int hasvoicemail_exec(struct ast_channel *chan, void *data)
priority_jump = 1; priority_jump = 1;
} }
vmcount = ast_app_messagecount2(context, vmbox, vmfolder); vmcount = ast_app_messagecount(context, vmbox, vmfolder);
/* Set the count in the channel variable */ /* Set the count in the channel variable */
if (varname) { if (varname) {
snprintf(tmp, sizeof(tmp), "%d", vmcount); 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"; 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); LOCAL_USER_REMOVE(u);

@ -2012,7 +2012,7 @@ static const char *mbox(int id)
} }
#ifdef USE_ODBC_STORAGE #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 x = -1;
int res; int res;
@ -2127,7 +2127,7 @@ yuck:
return x; 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; struct odbc_obj *obj = NULL;
int nummsgs = 0; int nummsgs = 0;
@ -2193,7 +2193,7 @@ static int has_voicemail(const char *mailbox, const char *folder)
else else
context = "default"; context = "default";
if (messagecount2(context, tmp, folder)) if (messagecount(context, tmp, folder))
return 1; return 1;
else else
return 0; return 0;
@ -2201,42 +2201,20 @@ static int has_voicemail(const char *mailbox, const char *folder)
#else #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; DIR *dir;
struct dirent *de; struct dirent *de;
char fn[256]; char fn[256];
char tmp[256]="";
char *mb, *cur;
char *context;
int ret = 0; int ret = 0;
if (!folder) if (!folder)
folder = "INBOX"; folder = "INBOX";
/* If no mailbox, return immediately */ /* If no mailbox, return immediately */
if (ast_strlen_zero(mailbox)) if (ast_strlen_zero(mailbox))
return 0; return 0;
if (strchr(mailbox, ',')) { if (!context)
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
context = "default"; 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); dir = opendir(fn);
if (!dir) if (!dir)
return 0; 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) 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]; return __has_voicemail(context, mailbox, folder, 0);
snprintf(tmp, sizeof(tmp), "%s@%s", mailbox, context);
return __has_voicemail(tmp, 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 tmp[256];
char *context; char *context;
@ -2288,7 +2271,7 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
mb = tmp; mb = tmp;
while((cur = strsep(&mb, ", "))) { while((cur = strsep(&mb, ", "))) {
if (!ast_strlen_zero(cur)) { 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; return -1;
else { else {
if (newmsgs) if (newmsgs)
@ -2307,32 +2290,10 @@ static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
context++; context++;
} else } else
context = "default"; context = "default";
if (newmsgs) { if (newmsgs)
snprintf(fn, sizeof(fn), "%s%s/%s/INBOX", VM_SPOOL_DIR, context, tmp); *newmsgs = __has_voicemail(context, tmp, "INBOX", 0);
dir = opendir(fn); if (oldmsgs)
if (dir) { *oldmsgs = __has_voicemail(context, tmp, "Old", 0);
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);
}
}
return 0; return 0;
} }
@ -2410,7 +2371,7 @@ static void run_externnotify(char *context, char *extension)
#else #else
if (!ast_strlen_zero(externnotify)) { if (!ast_strlen_zero(externnotify)) {
#endif #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); ast_log(LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
} else { } else {
snprintf(arguments, sizeof(arguments), "%s %s %s %d&", externnotify, context, extension, newvoicemails); 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 */ /* Leave voicemail for someone */
if (ast_app_has_voicemail(ext_context, NULL)) { 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); 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); run_externnotify(vmu->context, vmu->mailbox);
@ -6654,7 +6615,7 @@ static int load_module(void *mod)
/* compute the location of the voicemail spool directory */ /* compute the location of the voicemail spool directory */
snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR); 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) #if defined(USE_ODBC_STORAGE) && !defined(EXTENDED_ODBC_STORAGE)
ast_log(LOG_WARNING, "The current ODBC storage table format will be changed soon." ast_log(LOG_WARNING, "The current ODBC storage table format will be changed soon."

@ -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); iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
if (!ast_strlen_zero(p->mailbox)) { if (!ast_strlen_zero(p->mailbox)) {
int new, old; int new, old;
ast_app_messagecount(p->mailbox, &new, &old); ast_app_inboxcount(p->mailbox, &new, &old);
if (new > 255) if (new > 255)
new = 255; new = 255;
if (old > 255) if (old > 255)

@ -12193,7 +12193,7 @@ static int sip_send_mwi_to_peer(struct sip_peer *peer)
int newmsgs, oldmsgs; int newmsgs, oldmsgs;
/* Check for messages */ /* Check for messages */
ast_app_messagecount(peer->mailbox, &newmsgs, &oldmsgs); ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs);
time(&peer->lastmsgcheck); time(&peer->lastmsgcheck);

@ -1311,7 +1311,7 @@ static void do_housekeeping(struct skinnysession *s)
if (skinnydebug) { if (skinnydebug) {
ast_verbose("Checking for voicemail Skinny %s@%s\n", sub->parent->name, sub->parent->parent->name); 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) { if (skinnydebug) {
ast_verbose("Skinny %s@%s has voicemail!\n", sub->parent->name, sub->parent->parent->name); ast_verbose("Skinny %s@%s has voicemail!\n", sub->parent->name, sub->parent->parent->name);
} }

@ -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); 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), 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 (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
int (*messagecount2_func)(const char *context, const char *mailbox, const char *folder)); int (*messagecount_func)(const char *context, const char *mailbox, const char *folder));
void ast_uninstall_vm_functions(void); 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); int ast_app_has_voicemail(const char *mailbox, const char *folder);
/*! Determine number of new/old messages in a mailbox */ /*! 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 */ /*! 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 /*! Safely spawn an external program while closing file descriptors
\note This replaces the \b system call in all Asterisk modules \note This replaces the \b system call in all Asterisk modules

@ -1520,7 +1520,7 @@ static int action_mailboxcount(struct mansession *s, struct message *m)
astman_send_error(s, m, "Mailbox not specified"); astman_send_error(s, m, "Mailbox not specified");
return 0; return 0;
} }
ast_app_messagecount(mailbox, &newmsgs, &oldmsgs); ast_app_inboxcount(mailbox, &newmsgs, &oldmsgs);
if (!ast_strlen_zero(id)) { if (!ast_strlen_zero(id)) {
snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id); snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
} }

Loading…
Cancel
Save