--- asterisk/apps/app_voicemail.c 2004-06-11 14:11:22.000000000 -0700 +++ asterisk_patched/apps/app_voicemail.c 2004-06-14 10:29:24.000000000 -0700 @@ -39,6 +39,8 @@ #include #include +#define EXTRA_LOG 0 + /* we define USESQLVM when we have MySQL or POSTGRES */ #ifdef USEMYSQLVM #include @@ -329,7 +331,11 @@ #ifdef USEPOSTGRESVM PGconn *dbhandler; -char dboption[256]; +char dboption[512]; +char db_changepassword_query[1024]; +char db_setpassword_query[1024]; +char db_getvmuser_query[1024]; + ast_mutex_t postgreslock; static int sql_init(void) @@ -361,13 +367,15 @@ int numFields, i; char *fname; - char query[240]; + char query[1024]; char options[160] = ""; struct ast_vm_user *retval; retval=malloc(sizeof(struct ast_vm_user)); -/* fprintf(stderr,"postgres find_user:\n"); */ +#if EXTRA_LOG + fprintf(strerr,"postgres find_user: mailbox=%s,context=%s\n",mailbox,context); +#endif if (retval) { memset(retval, 0, sizeof(struct ast_vm_user)); @@ -383,9 +391,10 @@ strcpy(retval->context, "default"); } populate_defaults(retval); - sprintf(query, "SELECT password,fullname,email,pager,options FROM voicemail WHERE context='%s' AND mailbox='%s'", retval->context, mailbox); - -/* fprintf(stderr,"postgres find_user: query = %s\n",query); */ + sprintf(query,db_getvmuser_query,mailbox,context); +#if EXTRA_LOG + fprintf(stderr,"postgres find_user: query = %s\n",query); +#endif ast_mutex_lock(&postgreslock); PGSQLres=PQexec(dbhandler,query); if (PGSQLres!=NULL) { @@ -443,14 +452,12 @@ static void vm_change_password(struct ast_vm_user *vmu, char *password) { - char query[400]; + char query[1024]; + sprintf(query,db_changepassword_query,password,vmu->password,vmu->mailbox,vmu->context); - if (*vmu->context) { - sprintf(query, "UPDATE voicemail SET password='%s' WHERE context='%s' AND mailbox='%s' AND (password='%s' OR password IS NULL)", password, vmu->context, vmu->mailbox, vmu->password); - } else { - sprintf(query, "UPDATE voicemail SET password='%s' WHERE mailbox='%s' AND (password='%s' OR password IS NULL)", password, vmu->mailbox, vmu->password); - } -/* fprintf(stderr,"postgres change_password: query = %s\n",query); */ +#if EXTRA_LOG + fprintf(stderr,"postgres change_password: query = %s\n",query); +#endif ast_mutex_lock(&postgreslock); PQexec(dbhandler, query); strcpy(vmu->password, password); @@ -459,15 +466,12 @@ static void reset_user_pw(char *context, char *mailbox, char *password) { - char query[320]; - - if (context) { - sprintf(query, "UPDATE voicemail SET password='%s' WHERE context='%s' AND mailbox='%s'", password, context, mailbox); - } else { - sprintf(query, "UPDATE voicemail SET password='%s' WHERE mailbox='%s'", password, mailbox); - } + char query[1024]; + sprintf(query,db_setpassword_query,password,mailbox,context); ast_mutex_lock(&postgreslock); -/* fprintf(stderr,"postgres reset_user_pw: query = %s\n",query); */ +#if EXTRA_LOG + fprintf(stderr,"postgres reset_user_pw: query = %s\n",query); +#endif PQexec(dbhandler, query); ast_mutex_unlock(&postgreslock); } @@ -1537,6 +1541,9 @@ struct ast_vm_user *vmu; struct ast_vm_user svm; +#if EXTRA_LOG + fprintf(stderr,"In leave_voicemail,unavail=%d\n",unavail); +#endif strncpy(tmp, ext, sizeof(tmp) - 1); ext = tmp; @@ -1574,6 +1581,9 @@ /* Play the beginning intro if desired */ if (strlen(prefile)) { if (ast_fileexists(prefile, NULL, NULL) > 0) { +#if EXTRA_LOG + fprintf(stderr,"Streaming file in leave_voicemail,%s\n",prefile); +#endif if (ast_streamfile(chan, prefile, chan->language) > -1) res = ast_waitstream(chan, ecodes); } else { @@ -3039,6 +3049,10 @@ } +#if EXTRA_LOG + fprintf(stderr,"In vm_execmain,data=%s,context=%s,username=%s\n",data,context,vms.username); +#endif + /* If ADSI is supported, setup login screen */ adsi_begin(chan, &useadsi); if (!skipuser && useadsi) @@ -3108,6 +3122,10 @@ mkdir(vms.curdir, 0700); snprintf(vms.curdir, sizeof(vms.curdir), "%s/voicemail/%s/%s", (char *)ast_config_AST_SPOOL_DIR, vmu->context, vms.username); mkdir(vms.curdir, 0700); + +#if EXTRA_LOG + fprintf(stderr,"Found valid user, context=%s,username=%s,curdir=%s\n",vmu->context,vms.username,vms.curdir); +#endif /* Retrieve old and new message counts */ open_mailbox(&vms, vmu, 1); vms.oldmessages = vms.lastmsg + 1; @@ -3828,11 +3846,36 @@ #ifdef USEPOSTGRESVM if (!(s=ast_variable_retrieve(cfg, "general", "dboption"))) { - strcpy(dboption, "dboption not-specified in voicemail.conf"); + strncpy(dboption, "dboption not-specified in voicemail.conf",sizeof(dboption)-1); } else { - strcpy(dboption, s); + strncpy(dboption, s, sizeof(dboption)-1); + } + if (!(s=ast_variable_retrieve(cfg, "general", "db_changepassword_query"))) { + strncpy(db_changepassword_query, + "UPDATE voicemail SET password='%s' WHERE (password='%s' OR password IS NULL) AND (mailbox='%s') AND (context='%s')", + sizeof(db_changepassword_query)-1); + } + else { + strncpy(db_changepassword_query, s,sizeof(db_changepassword_query)); + } + if (!(s=ast_variable_retrieve(cfg, "general", "db_setpassword_query"))) { + strncpy(db_setpassword_query, + "UPDATE voicemail SET password='%s' WHERE (mailbox='%s') AND (context='%s')", + sizeof(db_setpassword_query)-1); + } + else { + strncpy(db_setpassword_query, s, sizeof(db_setpassword_query)); + } + if (!(s=ast_variable_retrieve(cfg, "general", "db_getvmuser_query"))) { + strncpy(db_getvmuser_query, + "SELECT password,fullname,email,pager,options FROM voicemail WHERE (mailbox='%s') AND (context='%s')", + sizeof(db_getvmuser_query)-1); + } + else { + strncpy(db_getvmuser_query,s,sizeof(db_getvmuser_query)-1); } #endif + cat = ast_category_browse(cfg, NULL); while(cat) { if (strcasecmp(cat, "general")) {