summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2008-07-02 21:27:53 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2008-07-02 21:27:53 +0000
commit885d17506b04b9988a1e8c66b272ce7c67619377 (patch)
tree507f4c47c1aefc693554b8df76781b4c44b0f75a
parent55e4daef88a20e99daa9a9729ad8728818602a40 (diff)
Keep ast_app_inboxcount API compatible with 1.6.0.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@127609 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--apps/app_voicemail.c58
-rw-r--r--channels/chan_iax2.c15
-rw-r--r--channels/chan_sip.c4
-rw-r--r--channels/chan_unistim.c19
-rw-r--r--include/asterisk/app.h10
-rw-r--r--main/app.c45
-rw-r--r--main/manager.c2
7 files changed, 104 insertions, 49 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 92c2421e1..54f7b030a 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -2886,7 +2886,7 @@ static int folder_int(const char *folder)
#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 @@ static int inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *o
}
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) {
@@ -3000,6 +3006,11 @@ yuck:
return x;
}
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+{
+ return inboxcount2(mailbox, NULL, newmsgs, oldmsgs);
+}
+
/*!
* \brief Gets the number of messages that exist in a mailbox folder.
* \param context
@@ -3333,7 +3344,7 @@ static int messagecount(const char *context, const char *mailbox, const char *fo
*
* \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 @@ static int inboxcount(const char *mailbox_context, int *urgentmsgs, int *newmsgs
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 @@ static int inboxcount(const char *mailbox_context, int *urgentmsgs, int *newmsgs
}
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 has_voicemail(const char *mailbox, const char *folder)
}
-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 @@ static int inboxcount(const char *mailbox, int *urgentmsgs, int *newmsgs, int *o
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 @@ static void run_externnotify(char *context, char *extension, const char *flag)
}
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 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_
#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 @@ 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_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 @@ out:
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 @@ static int append_mailbox(const char *context, const char *mbox, const char *dat
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 @@ static char *handle_voicemail_show_users(struct ast_cli_entry *e, int cmd, struc
}
}
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 @@ static void poll_subscribed_mailboxes(void)
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 @@ static int manager_list_voicemail_users(struct mansession *s, const struct messa
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 @@ static int load_module(void)
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);
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index f16c66c42..452a8e654 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -6948,7 +6948,7 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
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 @@ static int update_registry(struct sockaddr_in *sin, int callno, char *devtype, i
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);
+ } else { /* Fall back on checking the mailbox directly */
+ ast_app_inboxcount(p->mailbox, &new, &old);
+ }
- if (urgent > 255)
- urgent = 255;
- if (new > 255)
+ 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);
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 17b1dfa0f..8235d7ed0 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -19750,7 +19750,7 @@ static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *e
{
/* 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 @@ static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *e
} 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) {
diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index f806c1077..50f081d64 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -4375,7 +4375,7 @@ static int unistim_sendtext(struct ast_channel *ast, const char *text)
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 @@ static int unistim_send_mwi_to_peer(struct unistimsession *s, unsigned int tick)
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;
}
diff --git a/include/asterisk/app.h b/include/asterisk/app.h
index a30343587..4d1bcc3ae 100644
--- a/include/asterisk/app.h
+++ b/include/asterisk/app.h
@@ -104,17 +104,21 @@ int ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxl
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);
diff --git a/main/app.c b/main/app.c
index 852e3b88e..0ea5cefe6 100644
--- a/main/app.c
+++ b/main/app.c
@@ -176,17 +176,20 @@ 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_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 @@ void ast_uninstall_vm_functions(void)
{
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_has_voicemail(const char *mailbox, const char *folder)
}
-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 (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)
+ }
+ 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++;
diff --git a/main/manager.c b/main/manager.c
index 61d6da580..15fbbc841 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2430,7 +2430,7 @@ static int action_mailboxcount(struct mansession *s, const struct message *m)
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"