Index: asterisk-addons/mysql-vm-routines.h =================================================================== RCS file: /usr/cvsroot/asterisk-addons/mysql-vm-routines.h,v retrieving revision 1.7 diff -u -r1.7 mysql-vm-routines.h --- asterisk-addons/mysql-vm-routines.h 2 Jun 2004 03:21:33 -0000 1.7 +++ asterisk-addons/mysql-vm-routines.h 17 Jul 2004 07:08:08 -0000 @@ -36,7 +36,7 @@ MYSQL_ROW rowval; MYSQL_FIELD *fields; int numFields, i; - char query[240]; + char query[1024]; char options[160] = ""; struct ast_vm_user *retval; @@ -47,6 +47,7 @@ retval->attach=-1; retval->alloced=1; retval->next=NULL; + if (mailbox) { strcpy(retval->mailbox, mailbox); } @@ -59,11 +60,14 @@ /* We should at this point have the context and retval->context else we free retval and return NULL */ if (*retval->context) { - sprintf(query, "SELECT password,fullname,email,pager,options FROM users WHERE context='%s' AND mailbox='%s'", context, mailbox); + sprintf(query,db_getvmuser_query,mailbox,context ? context : "default" ); } else { free(retval); return(NULL); } +#if EXTRA_LOG + fprintf(stderr,"vm_find_user: query = %s\n",query); +#endif ast_mutex_lock(&mysqllock); mysql_query(dbhandler, query); if ((result=mysql_store_result(dbhandler))!=NULL) { @@ -71,6 +75,9 @@ numFields=mysql_num_fields(result); fields=mysql_fetch_fields(result); for (i=0; ipassword, rowval[i]); @@ -96,6 +103,11 @@ return(NULL); } } + else { +#if EXTRA_LOG + fprintf(stderr,"vm_find_user, cannot select user information\n"); +#endif + } ast_mutex_unlock(&mysqllock); free(retval); } @@ -103,15 +115,11 @@ } static void vm_change_password(struct ast_vm_user *vmu, char *password) { - char query[400]; - - if (*vmu->context) { - sprintf(query, "UPDATE users SET password='%s' WHERE context='%s' AND mailbox='%s' AND password='%s'", password, vmu->context, vmu->mailbox, vmu->password); - } else { - /* Lets be specific here since we can have for example exten 123 in diffrent contexts. - This has the ability to update/change passwords for all users with mailbox 123. */ - sprintf(query, "UPDATE users SET password='%s' WHERE mailbox='%s' AND password='%s' AND context='default'", password, vmu->mailbox, vmu->password); - } + char query[1024]; + sprintf(query,db_changepassword_query,password,vmu->password,vmu->mailbox,vmu->context ? vmu->context : "default" ); +#if EXTRA_LOG + fprintf(stderr,"vm_change_password: query = %s\n",query); +#endif ast_mutex_lock(&mysqllock); mysql_query(dbhandler, query); strcpy(vmu->password, password); @@ -120,15 +128,11 @@ static void reset_user_pw(char *context, char *mailbox, char *password) { - char query[320]; - - if (context) { - sprintf(query, "UPDATE users SET password='%s' WHERE context='%s' AND mailbox='%s'", password, context, mailbox); - } else { - /* Lets be specific here since we can have for example exten 123 in diffrent contexts. - This has the ability to reset passwords for all users with mailbox 123. */ - sprintf(query, "UPDATE users SET password='%s' WHERE mailbox='%s' AND context='default'", password, mailbox); - } + char query[1024]; + sprintf(query,db_setpassword_query,password,mailbox, context ? context : "default" ); +#if EXTRA_LOG + fprintf(stderr,"reset_user_pw: query = %s\n",query); +#endif ast_mutex_lock(&mysqllock); mysql_query(dbhandler, query); ast_mutex_unlock(&mysqllock);