Index: apps/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/Makefile,v
retrieving revision 1.71
diff -u -r1.71 Makefile
--- apps/Makefile	17 Jul 2004 20:12:28 -0000	1.71
+++ apps/Makefile	19 Jul 2004 23:59:52 -0000
@@ -11,7 +11,7 @@
 # the GNU General Public License
 #
 
-USE_MYSQL_VM_INTERFACE=0
+USE_MYSQL_VM_INTERFACE=1
 USE_POSTGRES_VM_INTERFACE=0
 
 #APPS=app_dial.so app_playback.so app_directory.so app_intercom.so app_mp3.so 
Index: apps/app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.136
diff -u -r1.136 app_voicemail.c
--- apps/app_voicemail.c	18 Jul 2004 20:50:37 -0000	1.136
+++ apps/app_voicemail.c	19 Jul 2004 23:59:54 -0000
@@ -359,7 +359,170 @@
 }
 
 #ifdef USEMYSQLVM
-#include "mysql-vm-routines.h"
+/*
+ * to use mysql, set USE_MYSQL_VM_INTERFACE to 1
+ * in asterisk/apps/Makefile 
+*/
+
+MYSQL *dbhandler=NULL;
+ast_mutex_t mysqllock;
+char dbuser[80];
+char dbpass[80];
+char dbhost[80];
+char dbname[80];
+char dbtable[80];
+char dbcontextcol[80];
+char dbmailboxcol[80];
+char dbpasswordcol[80];
+char dbfullnamecol[80];
+char dbemailcol[80];
+char dbpagercol[80];
+char dboptionscol[80];
+char dbstampcol[80];
+
+
+static int mysql_login(void)
+{
+	ast_verbose( VERBOSE_PREFIX_3 "Logging into database with user %s, password %s, and database %s\n", dbuser, dbpass, dbname);
+
+	dbhandler=mysql_init(NULL);
+	if (!mysql_real_connect(dbhandler, dbhost[0] ? dbhost : NULL, dbuser, dbpass, dbname, 0, NULL, 0)) {
+		ast_log(LOG_WARNING, "Error Logging into database\n");
+		return(-1);
+	}
+	ast_mutex_init(&mysqllock);
+	return(0);
+}
+
+static void mysql_logout(void)
+{
+	mysql_close(dbhandler);
+}
+
+#ifdef USESQLVM
+static struct ast_vm_user *find_user(struct ast_vm_user *ivm, char *context, char *mailbox)
+{
+	MYSQL_RES *result;
+	MYSQL_ROW rowval;
+	MYSQL_FIELD *fields;
+	int numFields, i;
+	char query[240];
+	char options[160] = "";
+	struct ast_vm_user *retval;
+
+	retval=malloc(sizeof(struct ast_vm_user));
+
+	if (retval) {
+		memset(retval, 0, sizeof(struct ast_vm_user));
+		retval->attach=-1;
+		retval->alloced=1;
+		retval->next=NULL;
+		if (mailbox) {
+			strcpy(retval->mailbox, mailbox);
+		}
+		if (context) {
+			strcpy(retval->context, context);
+		} else {
+			strcpy(retval->context, "default");
+			context = "default";
+		}
+
+		/* We should at this point have the context and retval->context else we free retval and return NULL */
+		if (*retval->context) {
+			sprintf(query, "SELECT %s,%s,%s,%s,%s FROM %s WHERE %s='%s' AND %s='%s'", 
+					dbpasswordcol, dbfullnamecol,dbemailcol,dbpagercol,dboptionscol,dbtable,dbcontextcol,context,dbmailboxcol,mailbox);
+		} else {
+			free(retval);
+			return(NULL);
+		}
+		ast_mutex_lock(&mysqllock);
+		mysql_query(dbhandler, query);
+		if ((result=mysql_store_result(dbhandler))!=NULL) {
+			if ((rowval=mysql_fetch_row(result))!=NULL) {
+				numFields=mysql_num_fields(result);
+				fields=mysql_fetch_fields(result);
+				for (i=0; i<numFields; i++) {
+					if (rowval[i]) {
+						if (!strcmp(fields[i].name, dbpasswordcol)) {
+							strcpy(retval->password, rowval[i]);
+						} else if (!strcmp(fields[i].name, dbfullnamecol)) {
+							strcpy(retval->fullname, rowval[i]);
+						} else if (!strcmp(fields[i].name, dbemailcol)) {
+							strcpy(retval->email, rowval[i]);
+						} else if (!strcmp(fields[i].name, dbpagercol)) {
+							strcpy(retval->pager, rowval[i]);
+						} else if (!strcmp(fields[i].name, dboptionscol)) {
+							strncpy(options, rowval[i], sizeof(options) - 1);
+							apply_options(retval, options);
+						}
+					}
+				}
+				mysql_free_result(result);
+				ast_mutex_unlock(&mysqllock);
+				return(retval);
+			} else {
+				mysql_free_result(result);
+				ast_mutex_unlock(&mysqllock);
+				free(retval);
+				return(NULL);
+			}
+		}
+		ast_mutex_unlock(&mysqllock);
+		free(retval);
+	}
+	return(NULL);
+}
+static void vm_change_password(struct ast_vm_user *vmu, char *password)
+{
+	char query[400];
+
+	if (*vmu->context) {
+		sprintf(query, "UPDATE %s SET %s='%s' WHERE %s='%s' AND %s='%s' AND %s='%s'", 
+		    dbtable, dbpasswordcol, password, dbcontextcol, vmu->context, dbmailboxcol, vmu->mailbox, dbpasswordcol, 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 %s SET %s='%s' WHERE %s='%s' AND %s='default' AND %s='%s'", 
+		    dbtable, dbpasswordcol, password, dbcontextcol, dbmailboxcol, vmu->mailbox, dbpasswordcol, vmu->password);
+	}
+	ast_mutex_lock(&mysqllock);
+	mysql_query(dbhandler, query);
+	strcpy(vmu->password, password);
+	ast_mutex_unlock(&mysqllock);
+}
+
+static void reset_user_pw(char *context, char *mailbox, char *password)
+{
+	char query[320];
+
+	if (context) {
+		sprintf(query, "UPDATE %s SET %s='%s' WHERE %s='%s' AND %s='%s'", 
+		    dbtable,dbpasswordcol,password, dbcontextcol,context, dbmailboxcol,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 %s SET %s='%s' WHERE %s='default' AND %s='%s'", 
+    		    dbtable,dbpasswordcol,password, dbcontextcol, dbmailboxcol,mailbox);
+	}
+	ast_mutex_lock(&mysqllock);
+	mysql_query(dbhandler, query);
+	ast_mutex_unlock(&mysqllock);
+}
+#endif
+
+static int sql_init(void)
+{
+	static int res;
+	if ((res=mysql_login())) {
+		return(res);
+	}
+	return 0;
+}
+
+static void sql_close(void)
+{
+	mysql_logout();
+}
 #endif
 
 #ifdef USEPOSTGRESVM
@@ -4348,26 +4511,71 @@
 		}
 
 #ifdef USEMYSQLVM
-		if (!(s=ast_variable_retrieve(cfg, "general", "dbuser"))) {
-			strncpy(dbuser, "test", sizeof(dbuser) - 1);
-		} else {
-			strncpy(dbuser, s, sizeof(dbuser) - 1);
-		}
-		if (!(s=ast_variable_retrieve(cfg, "general", "dbpass"))) {
-			strncpy(dbpass, "test", sizeof(dbpass) - 1);
-		} else {
-			strncpy(dbpass, s, sizeof(dbpass) - 1);
-		}
-		if (!(s=ast_variable_retrieve(cfg, "general", "dbhost"))) {
-			dbhost[0] = '\0';
-		} else {
-			strncpy(dbhost, s, sizeof(dbhost) - 1);
-		}
-		if (!(s=ast_variable_retrieve(cfg, "general", "dbname"))) {
-			strncpy(dbname, "vmdb", sizeof(dbname) - 1);
-		} else {
-			strncpy(dbname, s, sizeof(dbname) - 1);
-		}
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbuser"))) {
+                    strcpy(dbuser, "test");
+                } else {
+                    strcpy(dbuser, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbpass"))) {
+                    strcpy(dbpass, "test");
+                } else {
+                    strcpy(dbpass, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbhost"))) {
+                    strcpy(dbhost, "");
+                } else {
+                    strcpy(dbhost, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbname"))) {
+                    strcpy(dbname, "vmdb");
+                } else {
+                    strcpy(dbname, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbtable"))) {
+                    strcpy(dbtable, "users");
+                } else {
+                    strcpy(dbtable, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbcontextcol"))) {
+                    strcpy(dbcontextcol, "context");
+                } else {
+                    strcpy(dbcontextcol, s);
+                }
+		if (!(s=ast_variable_retrieve(cfg, "general", "dbmailboxcol"))) {
+	            strcpy(dbmailboxcol, "mailbox");
+	        } else {
+	            strcpy(dbmailboxcol, s);
+	        }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbpasswordcol"))) {
+                    strcpy(dbpasswordcol, "password");
+                } else {
+                    strcpy(dbpasswordcol, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbfullnamecol"))) {
+                    strcpy(dbfullnamecol, "fullname");
+                } else {
+                    strcpy(dbfullnamecol, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbemailcol"))) {
+                    strcpy(dbemailcol, "email");
+                } else {
+                    strcpy(dbemailcol, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbpagercol"))) {
+                    strcpy(dbpagercol, "pager");
+                } else {
+                    strcpy(dbpagercol, s);
+                }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dboptionscol"))) {
+                    strcpy(dboptionscol, "options");
+                } else {
+                    strcpy(dboptionscol, s);
+	        }
+                if (!(s=ast_variable_retrieve(cfg, "general", "dbstampcol"))) {
+                    strcpy(dbstampcol, "stamp");
+                } else {
+                    strcpy(dbstampcol, s);
+                }
 #endif
 
 #ifdef USEPOSTGRESVM
Index: channels/Makefile
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/Makefile,v
retrieving revision 1.57
diff -u -r1.57 Makefile
--- channels/Makefile	7 Jul 2004 09:34:01 -0000	1.57
+++ channels/Makefile	19 Jul 2004 23:59:54 -0000
@@ -13,7 +13,7 @@
 
 OSARCH=$(shell uname -s)
 
-USE_MYSQL_FRIENDS=0
+USE_MYSQL_FRIENDS=1
 USE_SIP_MYSQL_FRIENDS=0
 
 CHANNEL_LIBS=chan_modem.so chan_sip.so \
Index: channels/chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.173
diff -u -r1.173 chan_iax2.c
--- channels/chan_iax2.c	17 Jul 2004 20:58:00 -0000	1.173
+++ channels/chan_iax2.c	19 Jul 2004 23:59:56 -0000
@@ -106,6 +106,14 @@
 static char mydbpass[80];
 static char mydbhost[80];
 static char mydbname[80];
+static char mydbtable[80];
+static char mydbnamecol[80];
+static char mydbsecretcol[80];
+static char mydbcontextcol[80];
+static char mydbaccountcodecol[80];
+static char mydbipaddrcol[80];
+static char mydbportcol[80];
+static char mydbregsecondscol[80];
 #endif
 static char *desc = "Inter Asterisk eXchange (Ver 2)";
 static char *tdesc = "Inter Asterisk eXchange Driver (Ver 2)";
@@ -1871,8 +1879,8 @@
 		name = alloca(strlen(peer) * 2 + 1);
 		time(&nowtime);
 		mysql_real_escape_string(mysql, name, peer, strlen(peer));
-		snprintf(query, sizeof(query), "UPDATE iaxfriends SET ipaddr=\"%s\", port=\"%d\", regseconds=\"%ld\" WHERE name=\"%s\"", 
-			ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port), nowtime, name);
+		snprintf(query, sizeof(query), "UPDATE %s SET %s=\"%s\", %s=\"%d\", %s=\"%ld\" WHERE %s=\"%s\"", 
+			mydbtable, mydbipaddrcol, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), mydbportcol, ntohs(sin->sin_port), mydbregsecondscol, nowtime, mydbnamecol, name);
 		ast_mutex_lock(&mysqllock);
 		if (mysql_real_query(mysql, query, strlen(query))) 
 			ast_log(LOG_WARNING, "Unable to update database\n");
@@ -1899,7 +1907,7 @@
 		MYSQL_ROW rowval;
 		name = alloca(strlen(peer) * 2 + 1);
 		mysql_real_escape_string(mysql, name, peer, strlen(peer));
-		snprintf(query, sizeof(query), "SELECT name, secret, context, ipaddr, port, regseconds FROM iaxfriends WHERE name=\"%s\"", name);
+		snprintf(query, sizeof(query), "SELECT %s, %s, %s, %s, %s, %s FROM %s WHERE %s=\"%s\"", mydbnamecol, mydbsecretcol, mydbcontextcol, mydbipaddrcol, mydbportcol, mydbregsecondscol, mydbtable, mydbnamecol, name);
 		ast_mutex_lock(&mysqllock);
 		mysql_query(mysql, query);
 		if ((result = mysql_store_result(mysql))) {
@@ -1909,17 +1917,17 @@
 				success = 1;
 				for (x=0;x<numfields;x++) {
 					if (rowval[x]) {
-						if (!strcasecmp(fields[x].name, "secret")) {
+						if (!strcasecmp(fields[x].name, mydbsecretcol)) {
 							strncpy(p->secret, rowval[x], sizeof(p->secret) - 1);
-						} else if (!strcasecmp(fields[x].name, "context")) {
+						} else if (!strcasecmp(fields[x].name, mydbcontextcol)) {
 							strncpy(p->context, rowval[x], sizeof(p->context) - 1);
-						} else if (!strcasecmp(fields[x].name, "ipaddr")) {
+						} else if (!strcasecmp(fields[x].name, mydbipaddrcol)) {
 							inet_aton(rowval[x], &p->addr.sin_addr);
-						} else if (!strcasecmp(fields[x].name, "port")) {
+						} else if (!strcasecmp(fields[x].name, mydbportcol)) {
 							if (sscanf(rowval[x], "%i", &port) != 1)
 								port = 0;
 							p->addr.sin_port = htons(port);
-						} else if (!strcasecmp(fields[x].name, "regseconds")) {
+						} else if (!strcasecmp(fields[x].name, mydbregsecondscol)) {
 							if (sscanf(rowval[x], "%li", &regseconds) != 1)
 								regseconds = 0;
 						}
@@ -1968,7 +1976,7 @@
 		MYSQL_ROW rowval;
 		name = alloca(strlen(user) * 2 + 1);
 		mysql_real_escape_string(mysql, name, user, strlen(user));
-		snprintf(query, sizeof(query), "SELECT name, secret, context, ipaddr, port, regseconds, accountcode FROM iaxfriends WHERE name=\"%s\"", name);
+		snprintf(query, sizeof(query), "SELECT %s, %s, %s, %s, %s, %s, %s FROM %s WHERE %s=\"%s\"", mydbnamecol, mydbsecretcol, mydbcontextcol, mydbipaddrcol, mydbportcol, mydbregsecondscol, mydbaccountcodecol, mydbtable, mydbnamecol, name);
 		ast_mutex_lock(&mysqllock);
 		mysql_query(mysql, query);
 		if ((result = mysql_store_result(mysql))) {
@@ -1978,11 +1986,11 @@
 				success = 1;
 				for (x=0;x<numfields;x++) {
 					if (rowval[x]) {
-						if (!strcasecmp(fields[x].name, "secret")) {
+						if (!strcasecmp(fields[x].name, mydbsecretcol)) {
 							strncpy(p->secret, rowval[x], sizeof(p->secret) - 1);
-						} else if (!strcasecmp(fields[x].name, "context")) {
+						} else if (!strcasecmp(fields[x].name, mydbcontextcol)) {
 							strncpy(p->contexts->context, rowval[x], sizeof(p->contexts->context) - 1);
-						} else if (!strcasecmp(fields[x].name, "accountcode")) {
+						} else if (!strcasecmp(fields[x].name, mydbaccountcodecol)) {
 							strncpy(p->accountcode, rowval[x], sizeof(p->accountcode) - 1);
 						}
 					}
@@ -6627,14 +6635,30 @@
 				amaflags = format;
 			}
 #ifdef MYSQL_FRIENDS
-		} else if (!strcasecmp(v->name, "dbuser")) {
-			strncpy(mydbuser, v->value, sizeof(mydbuser) - 1);
-		} else if (!strcasecmp(v->name, "dbpass")) {
-			strncpy(mydbpass, v->value, sizeof(mydbpass) - 1);
-		} else if (!strcasecmp(v->name, "dbhost")) {
-			strncpy(mydbhost, v->value, sizeof(mydbhost) - 1);
-		} else if (!strcasecmp(v->name, "dbname")) {
-			strncpy(mydbname, v->value, sizeof(mydbname) - 1);
+                } else if (!strcasecmp(v->name, "dbuser")) {
+                    strncpy(mydbuser, v->value, sizeof(mydbuser) - 1);
+                } else if (!strcasecmp(v->name, "dbpass")) {
+                    strncpy(mydbpass, v->value, sizeof(mydbpass) - 1);
+                } else if (!strcasecmp(v->name, "dbhost")) {
+                    strncpy(mydbhost, v->value, sizeof(mydbhost) - 1);
+                } else if (!strcasecmp(v->name, "dbname")) {
+                    strncpy(mydbname, v->value, sizeof(mydbname) - 1);
+                } else if (!strcasecmp(v->name, "dbtable")) {
+                    strncpy(mydbtable, v->value, sizeof(mydbtable) - 1);
+                } else if (!strcasecmp(v->name, "dbnamecol")) {
+                    strncpy(mydbnamecol, v->value, sizeof(mydbnamecol) - 1);
+                } else if (!strcasecmp(v->name, "dbsecretcol")) {
+                    strncpy(mydbsecretcol, v->value, sizeof(mydbsecretcol) - 1);
+                } else if (!strcasecmp(v->name, "dbcontextcol")) {
+                    strncpy(mydbcontextcol, v->value, sizeof(mydbcontextcol) - 1);
+                } else if (!strcasecmp(v->name, "dbaccountcodecol")) {
+                    strncpy(mydbaccountcodecol, v->value, sizeof(mydbaccountcodecol) - 1);
+                } else if (!strcasecmp(v->name, "dbipaddrcol")) {
+                    strncpy(mydbipaddrcol, v->value, sizeof(mydbipaddrcol) - 1);
+                } else if (!strcasecmp(v->name, "dbportcol")) {
+                    strncpy(mydbportcol, v->value, sizeof(mydbportcol) - 1);
+                } else if (!strcasecmp(v->name, "dbregsecondscol")) {
+                    strncpy(mydbregsecondscol, v->value, sizeof(mydbregsecondscol) - 1);
 #endif
 		} else if (!strcasecmp(v->name, "language")) {
                         strncpy(language, v->value, sizeof(language) - 1);
Index: channels/chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.457
diff -u -r1.457 chan_sip.c
--- channels/chan_sip.c	17 Jul 2004 23:27:11 -0000	1.457
+++ channels/chan_sip.c	20 Jul 2004 00:00:00 -0000
@@ -115,7 +115,15 @@
 static char mydbuser[80];
 static char mydbpass[80];
 static char mydbhost[80];
+static char mydbtable[80];
 static char mydbname[80];
+static char mydbnamecol[80];
+static char mydbusernamecol[80];
+static char mydbsecretcol[80];
+static char mydbcontextcol[80];
+static char mydbipaddrcol[80];
+static char mydbportcol[80];
+static char mydbregsecondscol[80];
 #endif
 
 							/* SIP Debug		*/
@@ -1074,8 +1082,8 @@
 		time(&nowtime);
 		mysql_real_escape_string(mysql, name, peer, strlen(peer));
 		mysql_real_escape_string(mysql, uname, username, strlen(username));
-		snprintf(query, sizeof(query), "UPDATE sipfriends SET ipaddr=\"%s\", port=\"%d\", regseconds=\"%ld\", username=\"%s\" WHERE name=\"%s\"", 
-			ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port), nowtime + expiry, uname, name);
+		snprintf(query, sizeof(query), "UPDATE %s SET %s=\"%s\", %s=\"%d\", %s=\"%ld\", %s=\"%s\" WHERE %s=\"%s\"", 
+			mydbtable, mydbipaddrcol, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), mydbportcol, ntohs(sin->sin_port), mydbregsecondscol, nowtime + expiry, mydbusernamecol, uname, mydbnamecol, name);
 		ast_mutex_lock(&mysqllock);
 		if (mysql_real_query(mysql, query, strlen(query))) 
 			ast_log(LOG_WARNING, "Unable to update database\n");
@@ -1107,9 +1115,11 @@
 			mysql_real_escape_string(mysql, name, peer, strlen(peer));
 		}
 		if (sin)
-			snprintf(query, sizeof(query), "SELECT name, secret, context, username, ipaddr, port, regseconds FROM sipfriends WHERE ipaddr=\"%s\" AND port=\"%d\"", ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port));
+			snprintf(query, sizeof(query), "SELECT %s, %s, %s, %s, %s, %s, %s FROM %s WHERE %s=\"%s\" AND %s=\"%d\"", 
+    			    mydbnamecol, mydbsecretcol, mydbcontextcol, mydbusernamecol, mydbipaddrcol, mydbportcol, mydbregsecondscol, mydbtable, mydbipaddrcol, ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), mydbportcol, ntohs(sin->sin_port));
 		else
-			snprintf(query, sizeof(query), "SELECT name, secret, context, username, ipaddr, port, regseconds FROM sipfriends WHERE name=\"%s\"", name);
+			snprintf(query, sizeof(query), "SELECT %s, %s, %s, %s, %s, %s, %s FROM %s WHERE %s=\"%s\"", 
+    			    mydbnamecol, mydbsecretcol, mydbcontextcol, mydbusernamecol, mydbipaddrcol, mydbportcol, mydbregsecondscol, mydbtable, mydbnamecol, name);
 		ast_mutex_lock(&mysqllock);
 		mysql_query(mysql, query);
 		if ((result = mysql_store_result(mysql))) {
@@ -1120,21 +1130,21 @@
 				p->addr.sin_family = AF_INET;
 				for (x=0;x<numfields;x++) {
 					if (rowval[x]) {
-						if (!strcasecmp(fields[x].name, "secret")) {
+						if (!strcasecmp(fields[x].name, mydbsecretcol)) {
 							strncpy(p->secret, rowval[x], sizeof(p->secret) - 1);
-						} else if (!strcasecmp(fields[x].name, "name")) {
+						} else if (!strcasecmp(fields[x].name, mydbnamecol)) {
 							strncpy(p->name, rowval[x], sizeof(p->name) - 1);
-						} else if (!strcasecmp(fields[x].name, "context")) {
+						} else if (!strcasecmp(fields[x].name, mydbcontextcol)) {
 							strncpy(p->context, rowval[x], sizeof(p->context) - 1);
-						} else if (!strcasecmp(fields[x].name, "username")) {
+						} else if (!strcasecmp(fields[x].name, mydbusernamecol)) {
 							strncpy(p->username, rowval[x], sizeof(p->username) - 1);
-						} else if (!strcasecmp(fields[x].name, "ipaddr")) {
+						} else if (!strcasecmp(fields[x].name, mydbipaddrcol)) {
 							inet_aton(rowval[x], &p->addr.sin_addr);
-						} else if (!strcasecmp(fields[x].name, "port")) {
+						} else if (!strcasecmp(fields[x].name, mydbportcol)) {
 							if (sscanf(rowval[x], "%i", &port) != 1)
 								port = 0;
 							p->addr.sin_port = htons(port);
-						} else if (!strcasecmp(fields[x].name, "regseconds")) {
+						} else if (!strcasecmp(fields[x].name, mydbregsecondscol)) {
 							if (sscanf(rowval[x], "%li", &regseconds) != 1)
 								regseconds = 0;
 						}
@@ -8403,14 +8413,30 @@
 				ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config);
 			}
 #ifdef MYSQL_FRIENDS
-		} else if (!strcasecmp(v->name, "dbuser")) {
-			strncpy(mydbuser, v->value, sizeof(mydbuser) - 1);
-		} else if (!strcasecmp(v->name, "dbpass")) {
-			strncpy(mydbpass, v->value, sizeof(mydbpass) - 1);
-		} else if (!strcasecmp(v->name, "dbhost")) {
-			strncpy(mydbhost, v->value, sizeof(mydbhost) - 1);
-		} else if (!strcasecmp(v->name, "dbname")) {
-			strncpy(mydbname, v->value, sizeof(mydbname) - 1);
+                } else if (!strcasecmp(v->name, "dbuser")) {
+                        strncpy(mydbuser, v->value, sizeof(mydbuser) - 1);
+                } else if (!strcasecmp(v->name, "dbpass")) {
+                        strncpy(mydbpass, v->value, sizeof(mydbpass) - 1);
+                } else if (!strcasecmp(v->name, "dbhost")) {
+                        strncpy(mydbhost, v->value, sizeof(mydbhost) - 1);
+                } else if (!strcasecmp(v->name, "dbname")) {
+                        strncpy(mydbname, v->value, sizeof(mydbname) - 1);
+                } else if (!strcasecmp(v->name, "dbtable")) {
+                        strncpy(mydbtable, v->value, sizeof(mydbtable) - 1);
+                } else if (!strcasecmp(v->name, "dbnamecol")) {
+                        strncpy(mydbnamecol, v->value, sizeof(mydbnamecol) - 1);
+                } else if (!strcasecmp(v->name, "dbusernamecol")) {
+                        strncpy(mydbusernamecol, v->value, sizeof(mydbusernamecol) - 1);
+                } else if (!strcasecmp(v->name, "dbsecretcol")) {
+                        strncpy(mydbsecretcol, v->value, sizeof(mydbsecretcol) - 1);
+                } else if (!strcasecmp(v->name, "dbcontextcol")) {
+                        strncpy(mydbcontextcol, v->value, sizeof(mydbcontextcol) - 1);
+                } else if (!strcasecmp(v->name, "dbipaddrcol")) {
+                        strncpy(mydbipaddrcol, v->value, sizeof(mydbipaddrcol) - 1);
+                } else if (!strcasecmp(v->name, "dbportcol")) {
+                        strncpy(mydbportcol, v->value, sizeof(mydbportcol) - 1);
+                } else if (!strcasecmp(v->name, "dbregsecondscol")) {
+                        strncpy(mydbregsecondscol, v->value, sizeof(mydbregsecondscol) - 1);
 #endif
 		}
 		/* else if (strcasecmp(v->name,"type"))
Index: configs/iax.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/iax.conf.sample,v
retrieving revision 1.28
diff -u -r1.28 iax.conf.sample
--- configs/iax.conf.sample	12 Jul 2004 15:33:40 -0000	1.28
+++ configs/iax.conf.sample	20 Jul 2004 00:00:00 -0000
@@ -7,6 +7,19 @@
 ; local addresses).
 ;
 [general]
+;setup mysql lookups
+;dbname=asterisk
+;dbhost=localhost
+;dbuser=asterisk
+;dbpass=asterisk
+;dbtable=friends
+;dbnamecol=name
+;dbsecretcol=secret
+;dbcontextcol=context
+;dbaccountcodecol=accountcode
+;dbipaddrcol=ipaddr
+;dbportcol=port
+;dbregsecondscol=regseconds
 ;port=5036
 ;bindaddr=192.168.0.1
 ;
Index: configs/sip.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/sip.conf.sample,v
retrieving revision 1.36
diff -u -r1.36 sip.conf.sample
--- configs/sip.conf.sample	29 Jun 2004 14:44:29 -0000	1.36
+++ configs/sip.conf.sample	20 Jul 2004 00:00:00 -0000
@@ -21,6 +21,20 @@
 ;
 
 [general]
+;setup mysql lookups
+;dbname=asterisk
+;dbhost=localhost
+;dbuser=asterisk
+;dbpass=asterisk
+;dbtable=friends
+;dbnamecol=name
+;dbusernamecol=username
+;dbsecretcol=secret
+;dbcontextcol=context
+;dbipaddrcol=ipaddr
+;dbportcol=port
+;dbregsecondscol=regseconds
+
 context=default			; Default context for incoming calls
 ;recordhistory=yes		; Record SIP history by default (see sip history / sip no history)
 ;realm=mydomain.tld		; Realm for digest authentication
Index: configs/voicemail.conf.sample
===================================================================
RCS file: /usr/cvsroot/asterisk/configs/voicemail.conf.sample,v
retrieving revision 1.35
diff -u -r1.35 voicemail.conf.sample
--- configs/voicemail.conf.sample	17 Jul 2004 20:36:31 -0000	1.35
+++ configs/voicemail.conf.sample	20 Jul 2004 00:00:00 -0000
@@ -2,6 +2,22 @@
 ; Voicemail Configuration
 ;
 [general]
+; setup mysql lookups
+;dbname=asterisk
+;dbhost=localhost
+;dbuser=asterisk
+;dbpass=asterisk
+;dbtable=friends
+;dbcontextcol=vmcontext
+;dbmailboxcol=name
+;dbpasswordcol=secret
+;dbfullnamecol=username
+;dbemailcol=email
+;dbpagercol=pager
+;dboptionscol=vmoptions
+;dbstampcol=stamp
+
+
 ; Default formats for writing Voicemail
 ;format=g723sf|wav49|wav
 format=wav49|gsm|wav
