[Asterisk-cvs] asterisk/apps app_voicemail.c,1.189,1.190
markster at lists.digium.com
markster at lists.digium.com
Thu Dec 30 20:16:54 CST 2004
Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv29770/apps
Modified Files:
app_voicemail.c
Log Message:
Make voicemail registration apps register (bug #3034)
Index: app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.189
retrieving revision 1.190
diff -u -d -r1.189 -r1.190
--- app_voicemail.c 30 Dec 2004 01:58:07 -0000 1.189
+++ app_voicemail.c 31 Dec 2004 01:11:33 -0000 1.190
@@ -955,6 +955,7 @@
return x;
}
+
static int count_messages(char *dir)
{
return last_message_index(dir) + 1;
@@ -1251,6 +1252,7 @@
}
#else
+
static int count_messages(char *dir)
{
/* Find all .txt files - even if they are not in sequence from 0000 */
@@ -1839,6 +1841,124 @@
}
}
+static int has_voicemail(const char *mailbox, const char *folder)
+{
+ DIR *dir;
+ struct dirent *de;
+ char fn[256];
+ char tmp[256]="";
+ char *mb, *cur;
+ char *context;
+ int ret;
+ if (!folder)
+ folder = "INBOX";
+ /* If no mailbox, return immediately */
+ if (ast_strlen_zero(mailbox))
+ return 0;
+ if (strchr(mailbox, ',')) {
+ strncpy(tmp, mailbox, sizeof(tmp) - 1);
+ mb = tmp;
+ ret = 0;
+ while((cur = strsep(&mb, ","))) {
+ if (!ast_strlen_zero(cur)) {
+ if (has_voicemail(cur, folder))
+ return 1;
+ }
+ }
+ return 0;
+ }
+ strncpy(tmp, mailbox, sizeof(tmp) - 1);
+ context = strchr(tmp, '@');
+ if (context) {
+ *context = '\0';
+ context++;
+ } else
+ context = "default";
+ snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/%s", (char *)ast_config_AST_SPOOL_DIR, context, tmp, folder);
+ dir = opendir(fn);
+ if (!dir)
+ return 0;
+ while ((de = readdir(dir))) {
+ if (!strncasecmp(de->d_name, "msg", 3))
+ break;
+ }
+ closedir(dir);
+ if (de)
+ return 1;
+ return 0;
+}
+
+static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+{
+ DIR *dir;
+ struct dirent *de;
+ char fn[256];
+ char tmp[256]="";
+ char *mb, *cur;
+ char *context;
+ int ret;
+ if (newmsgs)
+ *newmsgs = 0;
+ if (oldmsgs)
+ *oldmsgs = 0;
+ /* If no mailbox, return immediately */
+ if (ast_strlen_zero(mailbox))
+ return 0;
+ if (strchr(mailbox, ',')) {
+ int tmpnew, tmpold;
+ strncpy(tmp, mailbox, sizeof(tmp) - 1);
+ mb = tmp;
+ ret = 0;
+ while((cur = strsep(&mb, ", "))) {
+ if (!ast_strlen_zero(cur)) {
+ if (messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+ return -1;
+ else {
+ if (newmsgs)
+ *newmsgs += tmpnew;
+ if (oldmsgs)
+ *oldmsgs += tmpold;
+ }
+ }
+ }
+ return 0;
+ }
+ strncpy(tmp, mailbox, sizeof(tmp) - 1);
+ context = strchr(tmp, '@');
+ if (context) {
+ *context = '\0';
+ context++;
+ } else
+ context = "default";
+ if (newmsgs) {
+ snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/INBOX", (char *)ast_config_AST_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/voicemail/%s/%s/Old", (char *)ast_config_AST_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;
+}
+
static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname);
static void copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt)
@@ -1885,7 +2005,7 @@
int newvoicemails = 0, oldvoicemails = 0;
if (!ast_strlen_zero(externnotify)) {
- if (ast_app_messagecount(extension, &newvoicemails, &oldvoicemails)) {
+ if (messagecount(extension, &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);
@@ -3037,7 +3157,7 @@
ast_destroy(mif); /* or here */
}
/* Leave voicemail for someone */
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, ast_app_has_voicemail(ext_context, NULL));
+ manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
run_externnotify(chan->context, ext_context);
saved_messages++;
@@ -4755,7 +4875,7 @@
close_mailbox(&vms, vmu);
if (valid) {
snprintf(ext_context, sizeof(ext_context), "%s@%s", vms.username, vmu->context);
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, ast_app_has_voicemail(ext_context, NULL));
+ manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
run_externnotify(chan->context, ext_context);
}
if (vmu)
@@ -5415,6 +5535,7 @@
res |= ast_unregister_application(app4);
ast_cli_unregister(&show_voicemail_users_cli);
ast_cli_unregister(&show_voicemail_zones_cli);
+ ast_uninstall_vm_functions();
return res;
}
@@ -5431,8 +5552,12 @@
if ((res=load_config())) {
return(res);
}
+
ast_cli_register(&show_voicemail_users_cli);
ast_cli_register(&show_voicemail_zones_cli);
+
+ ast_install_vm_functions(has_voicemail, messagecount);
+
return res;
}
@@ -5831,3 +5956,4 @@
{
return ASTERISK_GPL_KEY;
}
+
More information about the svn-commits
mailing list