diff options
Diffstat (limited to 'apps/app_voicemail.c')
-rw-r--r-- | apps/app_voicemail.c | 147 |
1 files changed, 68 insertions, 79 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c index f7882c20d..7223d3d4f 100644 --- a/apps/app_voicemail.c +++ b/apps/app_voicemail.c @@ -1212,7 +1212,7 @@ static int check_password(struct ast_vm_user *vmu, char *password) if (!ast_strlen_zero(ext_pass_check_cmd)) { char cmd[255], buf[255]; - ast_log(AST_LOG_DEBUG, "Verify password policies for %s\n", password); + ast_debug(1, "Verify password policies for %s\n", password); snprintf(cmd, sizeof(cmd), "%s %s %s %s %s", ext_pass_check_cmd, vmu->mailbox, vmu->context, vmu->password, password); if (vm_check_password_shell(cmd, buf, sizeof(buf))) { @@ -1754,8 +1754,7 @@ static void vm_imap_delete(char *file, int msgnum, struct ast_vm_user *vmu) ast_log(LOG_WARNING, "msgnum %d, mailbox message %lu is zero.\n", msgnum, messageNum); return; } - if (option_debug > 2) - ast_log(LOG_DEBUG, "deleting msgnum %d, which is mailbox message %lu\n", msgnum, messageNum); + ast_debug(3, "deleting msgnum %d, which is mailbox message %lu\n", msgnum, messageNum); /* delete message */ snprintf (arg, sizeof(arg), "%lu", messageNum); ast_mutex_lock(&vms->lock); @@ -1782,7 +1781,7 @@ static int imap_retrieve_greeting(const char *dir, const int msgnum, struct ast_ if (file) *file++ = '\0'; else { - ast_debug (1, "Failed to procure file name from directory passed.\n"); + ast_debug(1, "Failed to procure file name from directory passed.\n"); return -1; } } @@ -1878,7 +1877,7 @@ static int imap_retrieve_file(const char *dir, const int msgnum, const char *mai res = -1; goto exit; } - + make_file(vms->fn, sizeof(vms->fn), dir, msgnum); snprintf(vms->introfn, sizeof(vms->introfn), "%sintro", vms->fn); @@ -1888,8 +1887,7 @@ static int imap_retrieve_file(const char *dir, const int msgnum, const char *mai goto exit; } - if (option_debug > 2) - ast_log(LOG_DEBUG, "Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n", msgnum, vms->msgArray[msgnum]); + ast_debug(3, "Before mail_fetchheaders, curmsg is: %d, imap messages is %lu\n", msgnum, vms->msgArray[msgnum]); if (vms->msgArray[msgnum] == 0) { ast_log(LOG_WARNING, "Trying to access unknown message\n"); res = -1; @@ -2029,7 +2027,7 @@ static int __messagecount(const char *context, const char *mailbox, const char * return -1; } } - + /* No IMAP account available */ if (vmu->imapuser[0] == '\0') { ast_log(AST_LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox); @@ -2126,7 +2124,7 @@ static int imap_check_limits(struct ast_channel *chan, struct vm_state *vms, str ast_play_and_wait(chan, "vm-mailboxfull"); return -1; } - + /* Check if we have exceeded maxmsg */ ast_debug(3, "Checking message number quota: mailbox has %d messages, maximum is set to %d, current messages %d\n", msgnum, vmu->maxmsg, inprocess_count(vmu->mailbox, vmu->context, 0)); if (msgnum >= vmu->maxmsg - inprocess_count(vmu->mailbox, vmu->context, +1)) { @@ -2178,7 +2176,7 @@ static int imap_store_file(const char *dir, const char *mailboxuser, const char if (msgnum < 0 && !imapgreetings) { return 0; } - + if (imap_check_limits(chan, vms, vmu, msgcount)) { return -1; } @@ -2188,7 +2186,7 @@ static int imap_store_file(const char *dir, const char *mailboxuser, const char ast_debug(3, "Setting message flag \\\\FLAGGED.\n"); imap_flags = "\\FLAGGED"; } - + /* Attach only the first format */ fmt = ast_strdupa(fmt); stringp = fmt; @@ -2206,7 +2204,7 @@ static int imap_store_file(const char *dir, const char *mailboxuser, const char if (ast_fileexists(introfn, NULL, NULL) <= 0) { *introfn = '\0'; } - + if (ast_strlen_zero(vmu->email)) { /* We need the vmu->email to be set when we call make_email_file, but * if we keep it set, a duplicate e-mail will be created. So at the end @@ -2278,7 +2276,7 @@ static int imap_store_file(const char *dir, const char *mailboxuser, const char return -1; } ast_debug(3, "%s stored\n", fn); - + if (tempcopy) *(vmu->email) = '\0'; inprocess_count(vmu->mailbox, vmu->context, -1); @@ -2317,7 +2315,7 @@ static int inboxcount2(const char *mailbox_context, int *urgentmsgs, int *newmsg /* If no mailbox, return immediately */ if (ast_strlen_zero(mailbox_context)) return 0; - + ast_copy_string(tmp, mailbox_context, sizeof(tmp)); context = strchr(tmp, '@'); if (strchr(mailbox_context, ',')) { @@ -2499,16 +2497,14 @@ static int init_mailstream(struct vm_state *vms, int box) MAILSTREAM *stream = NIL; long debug; char tmp[256]; - + if (!vms) { ast_log(LOG_ERROR, "vm_state is NULL!\n"); return -1; } - if (option_debug > 2) - ast_log(LOG_DEBUG, "vm_state user is:%s\n", vms->imapuser); + ast_debug(3, "vm_state user is:%s\n", vms->imapuser); if (vms->mailstream == NIL || !vms->mailstream) { - if (option_debug) - ast_log(LOG_DEBUG, "mailstream not set.\n"); + ast_debug(1, "mailstream not set.\n"); } else { stream = vms->mailstream; } @@ -2541,8 +2537,7 @@ static int init_mailstream(struct vm_state *vms, int box) } /* Now connect to the target folder */ imap_mailbox_name(tmp, sizeof(tmp), vms, box, 1); - if (option_debug > 2) - ast_log(LOG_DEBUG, "Before mail_open, server: %s, box:%d\n", tmp, box); + ast_debug(3, "Before mail_open, server: %s, box:%d\n", tmp, box); ast_mutex_lock(&vms->lock); vms->mailstream = mail_open (stream, tmp, debug ? OP_DEBUG : NIL); ast_mutex_unlock(&vms->lock); @@ -2574,9 +2569,9 @@ static int open_mailbox(struct vm_state *vms, struct ast_vm_user *vmu, int box) ast_log(AST_LOG_ERROR, "Could not initialize mailstream\n"); return -1; } - + create_dirpath(vms->curdir, sizeof(vms->curdir), vmu->context, vms->username, vms->curbox); - + /* Check Quota */ if (box == 0) { ast_debug(3, "Mailbox name set to: %s, about to check quotas\n", mbox(vmu, box)); @@ -2853,13 +2848,13 @@ static void mm_parsequota(MAILSTREAM *stream, unsigned char *msg, QUOTALIST *pqu char *mailbox = stream->mailbox, *user; char buf[1024] = ""; unsigned long usage = 0, limit = 0; - + while (pquota) { usage = pquota->usage; limit = pquota->limit; pquota = pquota->next; } - + if (!(user = get_user_by_mailbox(mailbox, buf, sizeof(buf))) || (!(vms = get_vm_state_by_imapuser(user, 2)) && !(vms = get_vm_state_by_imapuser(user, 0)))) { ast_log(AST_LOG_ERROR, "No state found.\n"); return; @@ -2927,8 +2922,7 @@ static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu) if ((vms_p = pthread_getspecific(ts_vmstate.key)) && !strcmp(vms_p->imapuser, vmu->imapuser) && !strcmp(vms_p->username, vmu->mailbox)) { return vms_p; } - if (option_debug > 4) - ast_log(AST_LOG_DEBUG, "Adding new vmstate for %s\n", vmu->imapuser); + ast_debug(5, "Adding new vmstate for %s\n", vmu->imapuser); if (!(vms_p = ast_calloc(1, sizeof(*vms_p)))) return NULL; ast_copy_string(vms_p->imapuser, vmu->imapuser, sizeof(vms_p->imapuser)); @@ -2937,8 +2931,7 @@ static struct vm_state *create_vm_state_from_user(struct ast_vm_user *vmu) ast_copy_string(vms_p->context, vmu->context, sizeof(vms_p->context)); vms_p->mailstream = NIL; /* save for access from interactive entry point */ vms_p->imapversion = vmu->imapversion; - if (option_debug > 4) - ast_log(AST_LOG_DEBUG, "Copied %s to %s\n", vmu->imapuser, vms_p->imapuser); + ast_debug(5, "Copied %s to %s\n", vmu->imapuser, vms_p->imapuser); vms_p->updated = 1; /* set mailbox to INBOX! */ ast_copy_string(vms_p->curbox, mbox(vmu, 0), sizeof(vms_p->curbox)); @@ -3012,7 +3005,7 @@ static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, const char } ast_debug(3, "comparing mailbox %s@%s (i=%d) to vmstate mailbox %s@%s (i=%d)\n", mailbox, local_context, interactive, vlist->vms->username, vlist->vms->context, vlist->vms->interactive); - + if (!strcmp(vlist->vms->username, mailbox) && !strcmp(vlist->vms->context, local_context) && vlist->vms->interactive == interactive) { ast_debug(3, "Found it!\n"); AST_LIST_UNLOCK(&vmstates); @@ -3026,7 +3019,7 @@ static struct vm_state *get_vm_state_by_mailbox(const char *mailbox, const char return NULL; } -static void vmstate_insert(struct vm_state *vms) +static void vmstate_insert(struct vm_state *vms) { struct vmstate *v; struct vm_state *altvms; @@ -3036,7 +3029,7 @@ static void vmstate_insert(struct vm_state *vms) We can compare the username to find the duplicate */ if (vms->interactive == 1) { altvms = get_vm_state_by_mailbox(vms->username, vms->context, 0); - if (altvms) { + if (altvms) { ast_debug(3, "Duplicate mailbox %s, copying message info...\n", vms->username); vms->newmessages = altvms->newmessages; vms->oldmessages = altvms->oldmessages; @@ -3057,7 +3050,7 @@ static void vmstate_insert(struct vm_state *vms) if (!(v = ast_calloc(1, sizeof(*v)))) return; - + v->vms = vms; ast_debug(3, "Inserting vm_state for user:%s, mailbox %s\n", vms->imapuser, vms->username); @@ -3067,7 +3060,7 @@ static void vmstate_insert(struct vm_state *vms) AST_LIST_UNLOCK(&vmstates); } -static void vmstate_delete(struct vm_state *vms) +static void vmstate_delete(struct vm_state *vms) { struct vmstate *vc = NULL; struct vm_state *altvms = NULL; @@ -3084,9 +3077,9 @@ static void vmstate_delete(struct vm_state *vms) /* Interactive states are not stored within the persistent list */ return; } - + ast_debug(3, "Removing vm_state for user:%s, mailbox %s\n", vms->imapuser, vms->username); - + AST_LIST_LOCK(&vmstates); AST_LIST_TRAVERSE_SAFE_BEGIN(&vmstates, vc, list) { if (vc->vms == vms) { @@ -3105,7 +3098,7 @@ static void vmstate_delete(struct vm_state *vms) ast_log(AST_LOG_ERROR, "No vmstate found for user:%s, mailbox %s\n", vms->imapuser, vms->username); } -static void set_update(MAILSTREAM * stream) +static void set_update(MAILSTREAM * stream) { struct vm_state *vms; char *mailbox = stream->mailbox, *user; @@ -3122,7 +3115,7 @@ static void set_update(MAILSTREAM * stream) vms->updated = 1; /* Set updated flag since mailbox changed */ } -static void init_vm_state(struct vm_state *vms) +static void init_vm_state(struct vm_state *vms) { int x; vms->vmArrayIndex = 0; @@ -3132,7 +3125,7 @@ static void init_vm_state(struct vm_state *vms) ast_mutex_init(&vms->lock); } -static int save_body(BODY *body, struct vm_state *vms, char *section, char *format, int is_intro) +static int save_body(BODY *body, struct vm_state *vms, char *section, char *format, int is_intro) { char *body_content; char *body_decoded; @@ -3140,7 +3133,7 @@ static int save_body(BODY *body, struct vm_state *vms, char *section, char *form unsigned long len; unsigned long newlen; char filename[256]; - + if (!body || body == NIL) return -1; @@ -3149,9 +3142,9 @@ static int save_body(BODY *body, struct vm_state *vms, char *section, char *form ast_mutex_unlock(&vms->lock); if (body_content != NIL) { snprintf(filename, sizeof(filename), "%s.%s", fn, format); - /* ast_debug(1,body_content); */ + /* ast_debug(1, body_content); */ body_decoded = rfc822_base64((unsigned char *) body_content, len, &newlen); - /* If the body of the file is empty, return an error */ + /* If the body of the file is empty, return an error */ if (!newlen) { return -1; } @@ -4256,9 +4249,7 @@ static void prep_email_sub_vars(struct ast_channel *ast, struct ast_vm_user *vmu strcat(fromfile, ".txt"); } if (!(msg_cfg = ast_config_load(fromfile, config_flags))) { - if (option_debug > 0) { - ast_log(LOG_DEBUG, "Config load for message text file '%s' failed\n", fromfile); - } + ast_debug(1, "Config load for message text file '%s' failed\n", fromfile); return; } @@ -4930,7 +4921,7 @@ static int get_date(char *s, int len) { struct ast_tm tm; struct timeval t = ast_tvnow(); - + ast_localtime(&t, &tm, "UTC"); return ast_strftime(s, len, "%a %b %e %r UTC %Y", &tm); @@ -5669,8 +5660,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_ } /* If maxmsg is zero, act as a "greetings only" voicemail: Exit successfully without recording */ if (vmu->maxmsg == 0) { - if (option_debug > 2) - ast_log(LOG_DEBUG, "Greetings only VM (maxmsg=0), Skipping voicemail recording\n"); + ast_debug(3, "Greetings only VM (maxmsg=0), Skipping voicemail recording\n"); pbx_builtin_setvar_helper(chan, "VMSTATUS", "SUCCESS"); goto leave_vm_out; } @@ -5762,7 +5752,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, struct leave_vm_ } } vms->newmessages++; - + /* here is a big difference! We add one to it later */ msgnum = newmsgs + oldmsgs; ast_debug(3, "Messagecount set to %d\n", msgnum); @@ -6077,7 +6067,7 @@ static int save_to_folder(struct ast_vm_user *vmu, struct vm_state *vms, int msg /* get the real IMAP message number for this message */ snprintf(sequence, sizeof(sequence), "%ld", vms->msgArray[msg]); - + ast_debug(3, "Copying sequence %s to mailbox %s\n", sequence, mbox(vmu, box)); ast_mutex_lock(&vms->lock); /* if save to Old folder, put in INBOX as read */ @@ -6095,7 +6085,7 @@ static int save_to_folder(struct ast_vm_user *vmu, struct vm_state *vms, int msg /* Create the folder if it don't exist */ imap_mailbox_name(mailbox, sizeof(mailbox), vms, box, 1); /* Get the full mailbox name */ ast_debug(5, "Checking if folder exists: %s\n", mailbox); - if (mail_create(vms->mailstream, mailbox) == NIL) + if (mail_create(vms->mailstream, mailbox) == NIL) ast_debug(5, "Folder exists.\n"); else ast_log(AST_LOG_NOTICE, "Folder %s created!\n", mbox(vmu, box)); @@ -7407,7 +7397,6 @@ static int play_message_callerid(struct ast_channel *chan, struct vm_state *vms, int i; char *callerid, *name; char prefile[PATH_MAX] = ""; - /* If voicemail cid is not enabled, or we didn't get cid or context from * the attribute file, leave now. @@ -9092,7 +9081,7 @@ static int vm_newuser(struct ast_channel *chan, struct ast_vm_user *vmu, struct ast_debug(1, "User %s set password to %s of length %d\n", vms->username, newpassword, (int) strlen(newpassword)); cmd = ast_play_and_wait(chan, vm_passchanged); - /* If forcename is set, have the user record their name */ + /* If forcename is set, have the user record their name */ if (ast_test_flag(vmu, VM_FORCENAME)) { snprintf(prefile, sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username); if (ast_fileexists(prefile, NULL, NULL) < 1) { @@ -9214,10 +9203,10 @@ static int vm_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vms->username, newpassword, (int) strlen(newpassword)); cmd = ast_play_and_wait(chan, vm_passchanged); break; - case '*': + case '*': cmd = 't'; break; - default: + default: cmd = 0; snprintf(prefile, sizeof(prefile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, vms->username); RETRIEVE(prefile, -1, vmu->mailbox, vmu->context); @@ -9845,7 +9834,7 @@ static int vm_execmain(struct ast_channel *chan, const char *data) cmd = ast_play_and_wait(chan, "an-error-has-occured"); return -1; } - + /* Set language from config to override channel language */ if (!ast_strlen_zero(vmu->language)) ast_string_field_set(chan, language, vmu->language); @@ -10209,7 +10198,7 @@ static int vm_execmain(struct ast_channel *chan, const char *data) deleted = 1; #endif break; - + case '8': /* Forward the current messgae */ if (vms.lastmsg > -1) { cmd = forward_message(chan, context, &vms, vmu, vmfmts, 0, record_gain, in_urgent); @@ -10382,7 +10371,7 @@ out: #ifdef HAVE_IMAP_TK2006 if (LEVELUIDPLUS (vms.mailstream)) { mail_expunge_full(vms.mailstream, NIL, EX_UID); - } else + } else #endif mail_expunge(vms.mailstream); ast_mutex_unlock(&vms.lock); @@ -11682,11 +11671,11 @@ static int load_config(int reload) ast_copy_string(ext_pass_cmd, val, sizeof(ext_pass_cmd)); pwdchange = PWDCHANGE_EXTERNAL | PWDCHANGE_INTERNAL; } - + /* External password validation command */ if ((val = ast_variable_retrieve(cfg, "general", "externpasscheck"))) { ast_copy_string(ext_pass_check_cmd, val, sizeof(ext_pass_check_cmd)); - ast_log(AST_LOG_DEBUG, "found externpasscheck: %s\n", ext_pass_check_cmd); + ast_debug(1, "found externpasscheck: %s\n", ext_pass_check_cmd); } #ifdef IMAP_STORAGE @@ -11796,18 +11785,18 @@ static int load_config(int reload) } if (!smdi_iface) { ast_log(AST_LOG_ERROR, "No valid SMDI interface specfied, disabling SMDI voicemail notification\n"); - } + } } /* Silence treshold */ silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE); if ((val = ast_variable_retrieve(cfg, "general", "silencethreshold"))) silencethreshold = atoi(val); - - if (!(val = ast_variable_retrieve(cfg, "general", "serveremail"))) + + if (!(val = ast_variable_retrieve(cfg, "general", "serveremail"))) val = ASTERISK_USERNAME; ast_copy_string(serveremail, val, sizeof(serveremail)); - + vmmaxsecs = 0; if ((val = ast_variable_retrieve(cfg, "general", "maxsecs"))) { if (sscanf(val, "%30d", &x) == 1) { @@ -11903,12 +11892,12 @@ static int load_config(int reload) } /* Force new user to record name ? */ - if (!(val = ast_variable_retrieve(cfg, "general", "forcename"))) + if (!(val = ast_variable_retrieve(cfg, "general", "forcename"))) val = "no"; ast_set2_flag((&globalflags), ast_true(val), VM_FORCENAME); /* Force new user to record greetings ? */ - if (!(val = ast_variable_retrieve(cfg, "general", "forcegreetings"))) + if (!(val = ast_variable_retrieve(cfg, "general", "forcegreetings"))) val = "no"; ast_set2_flag((&globalflags), ast_true(val), VM_FORCEGREET); @@ -11931,7 +11920,7 @@ static int load_config(int reload) ast_debug(1, "VM Review Option disabled globally\n"); val = "no"; } - ast_set2_flag((&globalflags), ast_true(val), VM_REVIEW); + ast_set2_flag((&globalflags), ast_true(val), VM_REVIEW); /* Temporary greeting reminder */ if (!(val = ast_variable_retrieve(cfg, "general", "tempgreetwarn"))) { @@ -11945,49 +11934,49 @@ static int load_config(int reload) ast_debug(1, "VM next message wrap disabled globally\n"); val = "no"; } - ast_set2_flag((&globalflags), ast_true(val), VM_MESSAGEWRAP); + ast_set2_flag((&globalflags), ast_true(val), VM_MESSAGEWRAP); if (!(val = ast_variable_retrieve(cfg, "general", "operator"))){ ast_debug(1, "VM Operator break disabled globally\n"); val = "no"; } - ast_set2_flag((&globalflags), ast_true(val), VM_OPERATOR); + ast_set2_flag((&globalflags), ast_true(val), VM_OPERATOR); if (!(val = ast_variable_retrieve(cfg, "general", "saycid"))) { ast_debug(1, "VM CID Info before msg disabled globally\n"); val = "no"; - } - ast_set2_flag((&globalflags), ast_true(val), VM_SAYCID); + } + ast_set2_flag((&globalflags), ast_true(val), VM_SAYCID); if (!(val = ast_variable_retrieve(cfg, "general", "sendvoicemail"))){ ast_debug(1, "Send Voicemail msg disabled globally\n"); val = "no"; } ast_set2_flag((&globalflags), ast_true(val), VM_SVMAIL); - + if (!(val = ast_variable_retrieve(cfg, "general", "envelope"))) { ast_debug(1, "ENVELOPE before msg enabled globally\n"); val = "yes"; } - ast_set2_flag((&globalflags), ast_true(val), VM_ENVELOPE); + ast_set2_flag((&globalflags), ast_true(val), VM_ENVELOPE); if (!(val = ast_variable_retrieve(cfg, "general", "moveheard"))) { ast_debug(1, "Move Heard enabled globally\n"); val = "yes"; } - ast_set2_flag((&globalflags), ast_true(val), VM_MOVEHEARD); + ast_set2_flag((&globalflags), ast_true(val), VM_MOVEHEARD); if (!(val = ast_variable_retrieve(cfg, "general", "forward_urgent_auto"))) { ast_debug(1, "Autoset of Urgent flag on forwarded Urgent messages disabled globally\n"); val = "no"; } - ast_set2_flag((&globalflags), ast_true(val), VM_FWDURGAUTO); + ast_set2_flag((&globalflags), ast_true(val), VM_FWDURGAUTO); if (!(val = ast_variable_retrieve(cfg, "general", "sayduration"))) { ast_debug(1, "Duration info before msg enabled globally\n"); val = "yes"; } - ast_set2_flag((&globalflags), ast_true(val), VM_SAYDURATION); + ast_set2_flag((&globalflags), ast_true(val), VM_SAYDURATION); saydurationminfo = 2; if ((val = ast_variable_retrieve(cfg, "general", "saydurationm"))) { @@ -12008,9 +11997,9 @@ static int load_config(int reload) ast_copy_string(dialcontext, val, sizeof(dialcontext)); ast_debug(1, "found dialout context: %s\n", dialcontext); } else { - dialcontext[0] = '\0'; + dialcontext[0] = '\0'; } - + if ((val = ast_variable_retrieve(cfg, "general", "callback"))) { ast_copy_string(callcontext, val, sizeof(callcontext)); ast_debug(1, "found callback context: %s\n", callcontext); @@ -12024,7 +12013,7 @@ static int load_config(int reload) } else { exitcontext[0] = '\0'; } - + /* load password sounds configuration */ if ((val = ast_variable_retrieve(cfg, "general", "vm-password"))) ast_copy_string(vm_password, val, sizeof(vm_password)); |