[asterisk-commits] jrothenberger: branch jrothenberger/asterisk-urgent r103672 - in /team/jrothe...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 14 10:09:20 CST 2008
Author: jrothenberger
Date: Thu Feb 14 10:09:20 2008
New Revision: 103672
URL: http://svn.digium.com/view/asterisk?view=rev&rev=103672
Log:
Updates as per code review.
Modified:
team/jrothenberger/asterisk-urgent/Makefile
team/jrothenberger/asterisk-urgent/UPGRADE.txt
team/jrothenberger/asterisk-urgent/apps/app_voicemail.c
team/jrothenberger/asterisk-urgent/include/asterisk/app.h
team/jrothenberger/asterisk-urgent/main/manager.c
Modified: team/jrothenberger/asterisk-urgent/Makefile
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/Makefile?view=diff&rev=103672&r1=103671&r2=103672
==============================================================================
--- team/jrothenberger/asterisk-urgent/Makefile (original)
+++ team/jrothenberger/asterisk-urgent/Makefile Thu Feb 14 10:09:20 2008
@@ -132,7 +132,7 @@
ASTVARRUNDIR=/var/run/asterisk
ASTMANDIR=/opt/asterisk/man
else
- ASTETCDIR=/usr/local/etc/asterisk
+ ASTETCDIR=$(sysconfdir)/asterisk
ASTLIBDIR=$(libdir)/asterisk
ASTHEADERDIR=$(includedir)/asterisk
ASTBINDIR=$(bindir)
Modified: team/jrothenberger/asterisk-urgent/UPGRADE.txt
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/UPGRADE.txt?view=diff&rev=103672&r1=103671&r2=103672
==============================================================================
--- team/jrothenberger/asterisk-urgent/UPGRADE.txt (original)
+++ team/jrothenberger/asterisk-urgent/UPGRADE.txt Thu Feb 14 10:09:20 2008
@@ -65,6 +65,8 @@
checking mailboxes for changes so that they can send MWI information to users.
Examples of situations that would require this option are web interfaces to
voicemail or an email client in the case of using IMAP storage.
+* The externnotify script should accept an additional (last) parameter
+ containing the string "URGENT" if there are new urgent messages in the INBOX.
Applications:
Modified: team/jrothenberger/asterisk-urgent/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/apps/app_voicemail.c?view=diff&rev=103672&r1=103671&r2=103672
==============================================================================
--- team/jrothenberger/asterisk-urgent/apps/app_voicemail.c (original)
+++ team/jrothenberger/asterisk-urgent/apps/app_voicemail.c Thu Feb 14 10:09:20 2008
@@ -240,9 +240,9 @@
OPT_RECORDGAIN = (1 << 3),
OPT_PREPEND_MAILBOX = (1 << 4),
OPT_AUTOPLAY = (1 << 6),
- OPT_MESSAGE_URGENT = (1 << 7),
- OPT_MESSAGE_PRIORITY = (1 << 8)
- OPT_DTMFEXIT = (1 << 9),
+ OPT_DTMFEXIT = (1 << 7),
+ OPT_MESSAGE_URGENT = (1 << 8),
+ OPT_MESSAGE_PRIORITY = (1 << 9)
} vm_option_flags;
enum {
@@ -1603,9 +1603,9 @@
/* For now, only count URGENT messages in INBOX */
static int count_messages(struct ast_vm_user *vmu, char *dir, int urgent)
{
- /* Find all .txt files - even if they are not in sequence from, int urgent 0000 */
-
- int vmcount = 0, is_urgent;
+ /* Find all .txt files - even if they are not in sequence from 0000 */
+
+ int vmcount = 0;
DIR *vmdir = NULL;
struct dirent *vment = NULL;
@@ -1618,8 +1618,7 @@
if (urgent == -1) { /* Count all messages */
vmcount++;
} else {
- is_urgent = check_if_urgent(dir, vment->d_name);
- if (is_urgent == urgent) { /* count urgent or non-urgent as specified */
+ if (urgent == check_if_urgent(dir, vment->d_name)) { /* count urgent or non-urgent as specified */
vmcount++;
}
}
@@ -2044,10 +2043,20 @@
} else if (!ast_strlen_zero(emailtitle)) {
fprintf(p, emailtitle, msgnum + 1, mailbox) ;
fprintf(p, ENDL) ;
- } else if (ast_test_flag((&globalflags), VM_PBXSKIP))
- fprintf(p, "Subject: New %s message %d in mailbox %s" ENDL, flag, msgnum + 1, mailbox);
- else
- fprintf(p, "Subject: [PBX]: New %s message %d in mailbox %s" ENDL, flag, msgnum + 1, mailbox);
+ } else if (ast_test_flag((&globalflags), VM_PBXSKIP)) {
+ if (ast_strlen_zero(flag)) {
+ fprintf(p, "Subject: New message %d in mailbox %s" ENDL, msgnum + 1, mailbox);
+ } else {
+ fprintf(p, "Subject: New %s message %d in mailbox %s" ENDL, flag, msgnum + 1, mailbox);
+ }
+ } else {
+ if (ast_strlen_zero(flag)) {
+ fprintf(p, "Subject: [PBX]: New message %d in mailbox %s" ENDL, msgnum + 1, mailbox);
+ } else {
+ fprintf(p, "Subject: [PBX]: New %s message %d in mailbox %s" ENDL, flag, msgnum + 1, mailbox);
+ }
+ }
+
fprintf(p, "Message-ID: <Asterisk-%d-%d-%s-%d@%s>" ENDL, msgnum + 1, (unsigned int)ast_random(), mailbox, (int)getpid(), host);
if (imap) {
/* additional information needed for IMAP searching */
@@ -2229,8 +2238,13 @@
ast_channel_free(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else
- fprintf(p, "Subject: New %s VM\n\n", flag);
+ } else {
+ if (ast_strlen_zero(flag)) {
+ fprintf(p, "Subject: New VM\n\n");
+ } else {
+ fprintf(p, "Subject: New %s VM\n\n", flag);
+ }
+ }
ast_strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
if (pagerbody) {
@@ -2367,6 +2381,8 @@
return 9;
else if (!strcasecmp(folder, "Deleted"))
return 10;
+ else if (!strcasecmp(folder, "URGENT"))
+ return 11;
else /*assume they meant INBOX if folder is not found otherwise*/
return 0;
}
@@ -2542,7 +2558,7 @@
char *imapflags = NIL;
/* Set urgent flag for IMAP message */
- if (flag != NULL && !strcmp(flag,"URGENT")) {
+ if (ast_strlen_zero(flag) && !strcmp(flag,"URGENT")) {
ast_debug(3, "Setting message flag \\\\FLAGGED.\n");
imapflags="\\FLAGGED";
}
@@ -2672,7 +2688,7 @@
if (fold == 1) {/*Old messages*/
return vms_p->oldmessages;
}
- if(fold == 2) {/*URGENT messages*/
+ if(fold == 11) {/*URGENT messages*/
return vms_p->urgentmessages;
}
}
@@ -2719,7 +2735,7 @@
pgm->seen = 1;
}
/* look for urgent messages */
- if (fold == 2) {
+ if (fold == 11) {
pgm->flagged = 1;
pgm->unflagged = 0;
}
@@ -2732,7 +2748,7 @@
vms_p->newmessages = vms_p->vmArrayIndex;
if (fold == 1)
vms_p->oldmessages = vms_p->vmArrayIndex;
- if(fold == 2)
+ if(fold == 11)
vms_p->urgentmessages = vms_p->vmArrayIndex;
/*Freeing the searchpgm also frees the searchhdr*/
mail_free_searchpgm(&pgm);
@@ -2892,41 +2908,21 @@
static int check_if_urgent(char *dir, char *filename)
{
- unsigned char buf[256];
- char flag[80]="";
- char *val;
- FILE *f;
+ const char *flag;
char path[256];
+ struct ast_config *msg_cfg;
+ struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
snprintf(path, sizeof(path), "%s/%s", dir, filename);
- ast_debug(1, "About to open file %s\n", path);
- f = fopen(path, "r");
-
- if (f) {
- while (!feof(f)) {
- fgets((char *)buf, sizeof(buf), f);
- if (!feof(f)) {
- /* ast_debug(1, "parsing line %s in file %s\n", buf, filename); */
- char *stringp=NULL;
- stringp = (char *)buf;
- strsep(&stringp, "=");
- val = strsep(&stringp, "=");
- if (!ast_strlen_zero(val)) {
- ast_debug(1, "** buf is set to %s\n", buf);
- if (strncmp((char *)buf, "flag", 4) == 0) {
- ast_copy_string(flag, val, sizeof(flag));
- ast_debug(1, "Found flag %s in file %s\n", flag, filename);
- if (flag && strncmp(flag,"URGENT",6) == 0) {
- ast_debug(1, "Found URGENT flag %s in file %s\n", flag, filename);
- return 1;
- }
- }
- }
- }
- }
- fclose(f);
- } else {
- ast_log(LOG_WARNING, "Could not open file %s\n", path);
+ msg_cfg = ast_config_load(path, config_flags);
+ if (!msg_cfg) {
+ ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", path);
+ return 0;
+ }
+ flag = ast_variable_retrieve(msg_cfg, "message", "flag");
+ if (!ast_strlen_zero(flag) && strcmp(flag,"URGENT") == 0) {
+ ast_debug(5, "Found URGENT flag %s in file %s\n", flag, path);
+ return 1;
}
return 0;
}
@@ -2961,12 +2957,13 @@
while ((de = readdir(dir))) {
if (!strncasecmp(de->d_name, "msg", 3)) {
- if (shortcircuit) {
+ if (shortcircuit && urgent != 1) {
ret = 1;
break;
} else if (!strncasecmp(de->d_name + 8, "txt", 3)) {
is_urgent = check_if_urgent(fn, de->d_name);
if (is_urgent == urgent) { /* count urgent or non-urgent as specified */
+ if (shortcircuit && is_urgent == 1) return 1;
ret++;
}
}
@@ -3087,7 +3084,7 @@
if (inboxcount(ext_context, &urgentvoicemails, &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 %s&", externnotify, context, extension, newvoicemails, flag ? flag : "");
+ snprintf(arguments, sizeof(arguments), "%s %s %s %d %s&", externnotify, context, extension, newvoicemails, S_OR(flag,""));
ast_debug(1, "Executing %s\n", arguments);
ast_safe_system(arguments);
}
@@ -3401,7 +3398,7 @@
snprintf(priority, sizeof(priority), "%d", chan->priority);
snprintf(origtime, sizeof(origtime), "%ld", (long)time(NULL));
get_date(date, sizeof(date));
- rtmsgid = ast_store_realtime("voicemail_data", "origmailbox", ext, "context", chan->context, "macrocontext", chan->macrocontext, "exten", chan->exten, "priority", priority, "callerchan", chan->name, "callerid", ast_callerid_merge(callerid, sizeof(callerid), chan->cid.cid_name, chan->cid.cid_num, "Unknown"), "origdate", date, "origtime", origtime, "category", category ? category : "", NULL);
+ rtmsgid = ast_store_realtime("voicemail_data", "origmailbox", ext, "context", chan->context, "macrocontext", chan->macrocontext, "exten", chan->exten, "priority", priority, "callerchan", chan->name, "callerid", ast_callerid_merge(callerid, sizeof(callerid), chan->cid.cid_name, chan->cid.cid_num, "Unknown"), "origdate", date, "origtime", origtime, "category", S_OR(category,""), NULL);
}
/* Store information */
@@ -4839,7 +4836,7 @@
char *attachedfilefmt;
char *temp;
char buf[1024];
- char flag[10];
+ char flag[80];
vms->starting = 0;
ast_debug(3,"Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n",vms->curmsg, vms->msgArray[vms->curmsg]);
@@ -4879,9 +4876,7 @@
return -1;
}
-
/* Find the format of the attached file */
-
strsep(&attachedfilefmt, ".");
if (!attachedfilefmt) {
ast_log(LOG_ERROR, "File format could not be obtained from IMAP message attachment\n");
@@ -4908,7 +4903,7 @@
}
/* URGENT has a carriage return on the end, so don't compare that */
- if (strncmp(flag,"URGENT",6) == 0) {
+ if (strcmp(flag,"URGENT") == 0) {
res = wait_file2(chan, vms, "vm-marked-urgent");
}
@@ -5004,7 +4999,7 @@
flag = ast_variable_retrieve(msg_cfg, "message", "flag");
/* Play the word urgent if we are listening to urgent messages */
- if (flag && strncmp(flag,"URGENT",6) == 0) {
+ if (flag && strcmp(flag,"URGENT") == 0) {
res = wait_file2(chan, vms, "vm-Urgent"); /* "urgent" */
}
@@ -5053,7 +5048,7 @@
}
/* URGENT has a carriage return on the end, so don't compare that */
- if (flag && strncmp(flag,"URGENT",6) == 0) {
+ if (flag && strcmp(flag,"URGENT") == 0) {
res = wait_file2(chan, vms, "vm-marked-urgent");
}
@@ -5182,7 +5177,6 @@
SEARCHPGM *pgm;
SEARCHHEADER *hdr;
int ret;
- char dbox[256];
ast_copy_string(vms->imapuser,vmu->imapuser, sizeof(vms->imapuser));
ast_debug(3,"Before init_mailstream, user is %s\n",vmu->imapuser);
Modified: team/jrothenberger/asterisk-urgent/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/include/asterisk/app.h?view=diff&rev=103672&r1=103671&r2=103672
==============================================================================
--- team/jrothenberger/asterisk-urgent/include/asterisk/app.h (original)
+++ team/jrothenberger/asterisk-urgent/include/asterisk/app.h Thu Feb 14 10:09:20 2008
@@ -112,7 +112,7 @@
/*! \brief Determine if a given mailbox has any voicemail */
int ast_app_has_voicemail(const char *mailbox, const char *folder);
-/*! Determine number of urgent/new/old messages in a mailbox */
+/*! \brief Determine number of urgent/new/old messages in a mailbox */
int ast_app_inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs);
/*! \brief Determine number of messages in a given mailbox and folder */
Modified: team/jrothenberger/asterisk-urgent/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/main/manager.c?view=diff&rev=103672&r1=103671&r2=103672
==============================================================================
--- team/jrothenberger/asterisk-urgent/main/manager.c (original)
+++ team/jrothenberger/asterisk-urgent/main/manager.c Thu Feb 14 10:09:20 2008
@@ -2051,7 +2051,7 @@
"Returns number of urgent, new and old messages.\n"
" Message: Mailbox Message Count\n"
" Mailbox: <mailboxid>\n"
-" UrgMessages: <count>\n"
+" UrgentMessages: <count>\n"
" NewMessages: <count>\n"
" OldMessages: <count>\n"
"\n";
More information about the asterisk-commits
mailing list