Index: apps/app_voicemail.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v retrieving revision 1.276 diff -u -r1.276 app_voicemail.c --- apps/app_voicemail.c 28 Nov 2005 02:55:56 -0000 1.276 +++ apps/app_voicemail.c 30 Nov 2005 18:00:49 -0000 @@ -656,91 +656,89 @@ } while (!feof(configin)) { + char *user = NULL, *pass = NULL, *rest = NULL, *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL; + /* Read in the line */ fgets(inbuf, sizeof(inbuf), configin); linenum++; - if (!feof(configin)) { - char *user = NULL, *pass = NULL, *rest = NULL, - *comment = NULL, *tmpctx = NULL, *tmpctxend = NULL; - - if (ast_strlen_zero(inbuf)) { - fprintf(configout, "\n"); - continue; - } - /* Make a backup of it */ - ast_copy_string(orig, inbuf, sizeof(orig)); - - /* - Read the file line by line, split each line into a comment and command section - only parse the command portion of the line - */ - if (inbuf[strlen(inbuf) - 1] == '\n') - inbuf[strlen(inbuf) - 1] = '\0'; + if (ast_strlen_zero(inbuf)) { + fprintf(configout, "\n"); + continue; + } + + /* Make a backup of it */ + ast_copy_string(orig, inbuf, sizeof(orig)); - if ((comment = strchr(inbuf, ';'))) - *comment++ = '\0'; /* Now inbuf is terminated just before the comment */ + /* + Read the file line by line, split each line into a comment and command section + only parse the command portion of the line + */ + if (inbuf[strlen(inbuf) - 1] == '\n') + inbuf[strlen(inbuf) - 1] = '\0'; - if (ast_strlen_zero(inbuf)) { + if ((comment = strchr(inbuf, ';'))) + *comment++ = '\0'; /* Now inbuf is terminated just before the comment */ + + if (ast_strlen_zero(inbuf)) { + fprintf(configout, "%s", orig); + continue; + } + + /* Check for a context, first '[' to first ']' */ + if ((tmpctx = strchr(inbuf, '['))) { + tmpctxend = strchr(tmpctx, ']'); + if (tmpctxend) { + /* Valid context */ + ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx); fprintf(configout, "%s", orig); continue; } - - /* Check for a context, first '[' to first ']' */ - if ((tmpctx = strchr(inbuf, '['))) { - tmpctxend = strchr(tmpctx, ']'); - if (tmpctxend) { - /* Valid context */ - ast_copy_string(currcontext, tmpctx + 1, tmpctxend - tmpctx); - fprintf(configout, "%s", orig); - continue; - } - } - - /* This isn't a context line, check for MBX => PSWD... */ - user = inbuf; - if ((pass = strchr(user, '='))) { - /* We have a line in the form of aaaaa=aaaaaa */ + } + + /* This isn't a context line, check for MBX => PSWD... */ + user = inbuf; + if ((pass = strchr(user, '='))) { + /* We have a line in the form of aaaaa=aaaaaa */ + *pass++ = '\0'; + + user = ast_strip(user); + + if (*pass == '>') *pass++ = '\0'; - - user = ast_strip(user); - if (*pass == '>') - *pass++ = '\0'; + pass = ast_skip_blanks(pass); - pass = ast_skip_blanks(pass); - - /* - Since no whitespace allowed in fields, or more correctly white space - inside the fields is there for a purpose, we can just terminate pass - at the comma or EOL whichever comes first. - */ - if ((rest = strchr(pass, ','))) - *rest++ = '\0'; + /* + Since no whitespace allowed in fields, or more correctly white space + inside the fields is there for a purpose, we can just terminate pass + at the comma or EOL whichever comes first. + */ + if ((rest = strchr(pass, ','))) + *rest++ = '\0'; + } else { + user = NULL; + } + + /* Compare user, pass AND context */ + if (!ast_strlen_zero(user) && !strcmp(user, vmu->mailbox) && + !ast_strlen_zero(pass) && !strcmp(pass, vmu->password) && + !strcasecmp(currcontext, vmu->context)) { + /* This is the line */ + if (rest) { + fprintf(configout, "%s => %s,%s", user, newpassword, rest); } else { - user = NULL; - } - - /* Compare user, pass AND context */ - if (!ast_strlen_zero(user) && !strcmp(user, vmu->mailbox) && - !ast_strlen_zero(pass) && !strcmp(pass, vmu->password) && - !strcasecmp(currcontext, vmu->context)) { - /* This is the line */ - if (rest) { - fprintf(configout, "%s => %s,%s", user, newpassword, rest); - } else { - fprintf(configout, "%s => %s", user, newpassword); - } - /* If there was a comment on the line print it out */ - if (comment) { - fprintf(configout, ";%s\n", comment); - } else { - fprintf(configout, "\n"); - } + fprintf(configout, "%s => %s", user, newpassword); + } + /* If there was a comment on the line print it out */ + if (comment) { + fprintf(configout, ";%s\n", comment); } else { - /* Put it back like it was */ - fprintf(configout, "%s", orig); + fprintf(configout, "\n"); } + } else { + /* Put it back like it was */ + fprintf(configout, "%s", orig); } } fclose(configin);