Use zaptel timers to wake up processes
[asterisk/asterisk.git] / apps / app_voicemail2.c
index 80c0b40..f2bb854 100755 (executable)
@@ -183,6 +183,27 @@ static struct ast_vm_user *find_user(struct ast_vm_user *ivm, char *context, cha
        return vmu;
 }
 
        return vmu;
 }
 
+static int reset_user_pw(char *context, char *mailbox, char *newpass)
+{
+       /* This function could be made to generate one from a database, too */
+       struct ast_vm_user *cur;
+       int res = -1;
+       ast_pthread_mutex_lock(&vmlock);
+       cur = users;
+       while(cur) {
+               if ((!context || !strcasecmp(context, cur->context)) &&
+                       (!strcasecmp(mailbox, cur->mailbox)))
+                               break;
+               cur=cur->next;
+       }
+       if (cur) {
+               strncpy(cur->password, newpass, sizeof(cur->password) - 1);
+               res = 0;
+       }
+       ast_pthread_mutex_unlock(&vmlock);
+       return res;
+}
+
 static int vm_change_password(struct ast_vm_user *vmu, char *newpassword)
 {
         /*  There's probably a better way of doing this. */
 static int vm_change_password(struct ast_vm_user *vmu, char *newpassword)
 {
         /*  There's probably a better way of doing this. */
@@ -257,6 +278,8 @@ static int vm_change_password(struct ast_vm_user *vmu, char *newpassword)
 
         unlink((char *)tmpin);
         rename((char *)tmpout,(char *)tmpin);
 
         unlink((char *)tmpin);
         rename((char *)tmpout,(char *)tmpin);
+       reset_user_pw(vmu->context, vmu->mailbox, newpassword);
+       strncpy(vmu->password, newpassword, sizeof(vmu->password) - 1);
        return(1);
 }
 
        return(1);
 }
 
@@ -655,6 +678,8 @@ static int play_and_record(struct ast_channel *chan, char *playfile, char *recor
        for (x=0;x<fmtcnt;x++) {
                if (!others[x])
                        break;
        for (x=0;x<fmtcnt;x++) {
                if (!others[x])
                        break;
+               ast_stream_rewind(others[x], 1000);
+               ast_truncstream(others[x]);
                ast_closestream(others[x]);
        }
        if (outmsg) {
                ast_closestream(others[x]);
        }
        if (outmsg) {
@@ -682,7 +707,6 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
        FILE *txt;
        int res = 0;
        int msgnum;
        FILE *txt;
        int res = 0;
        int msgnum;
-       int maxmessage=0;
        char date[256];
        char dir[256];
        char fn[256];
        char date[256];
        char dir[256];
        char fn[256];
@@ -823,7 +847,7 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
                                        fclose(txt);
                                } else
                                        ast_log(LOG_WARNING, "Error opening text file for output\n");
                                        fclose(txt);
                                } else
                                        ast_log(LOG_WARNING, "Error opening text file for output\n");
-                               res = play_and_record(chan, NULL, fn, maxmessage, fmt);
+                               res = play_and_record(chan, NULL, fn, vmmaxmessage, fmt);
                                if (res > 0)
                                        res = 0;
                                txt = fopen(txtfile, "a");
                                if (res > 0)
                                        res = 0;
                                txt = fopen(txtfile, "a");