Index: channels/chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.179
diff -u -r1.179 chan_iax2.c
--- channels/chan_iax2.c	17 Aug 2004 23:57:36 -0000	1.179
+++ channels/chan_iax2.c	27 Aug 2004 16:22:03 -0000
@@ -106,6 +106,14 @@
 static char mydbpass[80];
 static char mydbhost[80];
 static char mydbname[80];
+static char mydbtable[80] = "iaxfriends";				/* Table to check in */
+static char mydbfield_peername[80] = "username";		/* Username field in db */
+static char mydbfield_secret[80] = "password";			/* Password/secret field in table, cleartext */
+static char mydbfield_ipaddr[80] = "ipaddr";			/* ipaddr field in table*/
+static char mydbfield_port[80]   = "port";				/* port field in table*/
+static char mydbfield_regseconds[80] = "regseconds";	/* regseconds field in table*/
+static char mydbfield_context[80] = "context";			/* context field in table*/
+static char mydbfield_accountcode[80] = "accountcode";	/* context field in table*/
 #endif
 static char *desc = "Inter Asterisk eXchange (Ver 2)";
 static char *tdesc = "Inter Asterisk eXchange Driver (Ver 2)";
@@ -1933,8 +1941,9 @@
 		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, mydbfield_ipaddr,ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr),mydbfield_port, ntohs(sin->sin_port), mydbfield_regseconds,nowtime, mydbfield_peername, name);
+		ast_log(LOG_NOTICE, "Executing SQL Query: %s\n",query);
 		ast_mutex_lock(&mysqllock);
 		if (mysql_real_query(mysql, query, strlen(query))) 
 			ast_log(LOG_WARNING, "Unable to update database\n");
@@ -1961,8 +1970,10 @@
 		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);
-		ast_mutex_lock(&mysqllock);
+		snprintf(query, sizeof(query), "SELECT %s, %s, %s, %s, %s, %s, %s FROM %s WHERE %s=\"%s\"", 
+			mydbfield_peername,mydbfield_secret,mydbfield_context,mydbfield_ipaddr,mydbfield_port,mydbfield_regseconds,mydbfield_accountcode,
+			mydbtable,mydbfield_peername,name);
+		ast_log(LOG_NOTICE, "Executing SQL Query: %s\n",query);
 		mysql_query(mysql, query);
 		if ((result = mysql_store_result(mysql))) {
 			if ((rowval = mysql_fetch_row(result))) {
@@ -1971,17 +1982,20 @@
 				success = 1;
 				for (x=0;x<numfields;x++) {
 					if (rowval[x]) {
-						if (!strcasecmp(fields[x].name, "secret")) {
+						if (!strcasecmp(fields[x].name, mydbfield_secret)) {
 							strncpy(p->secret, rowval[x], sizeof(p->secret) - 1);
-						} else if (!strcasecmp(fields[x].name, "context")) {
+							ast_log(LOG_NOTICE, "    Got secret from database: %s\n",p->secret);
+						} else if (!strcasecmp(fields[x].name, mydbfield_context)) {
 							strncpy(p->context, rowval[x], sizeof(p->context) - 1);
-						} else if (!strcasecmp(fields[x].name, "ipaddr")) {
+							ast_log(LOG_NOTICE, "    Got context from database: %s\n",p->context);
+						} else if (!strcasecmp(fields[x].name, mydbfield_ipaddr)) {
 							inet_aton(rowval[x], &p->addr.sin_addr);
-						} else if (!strcasecmp(fields[x].name, "port")) {
+							ast_log(LOG_NOTICE, "    Got IP Addr from database: %s\n",rowval[x]);
+						} else if (!strcasecmp(fields[x].name, mydbfield_port)) {
 							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, mydbfield_regseconds)) {
 							if (sscanf(rowval[x], "%li", &regseconds) != 1)
 								regseconds = 0;
 						}
@@ -2030,7 +2044,9 @@
 		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\"", 
+			mydbfield_peername,mydbfield_secret,mydbfield_context, mydbfield_ipaddr,mydbfield_port,mydbfield_regseconds,mydbfield_accountcode, mydbtable, mydbfield_peername,name);
+		ast_log(LOG_NOTICE, "Executing SQL Query: %s\n",query);
 		ast_mutex_lock(&mysqllock);
 		mysql_query(mysql, query);
 		if ((result = mysql_store_result(mysql))) {
@@ -2040,11 +2056,11 @@
 				success = 1;
 				for (x=0;x<numfields;x++) {
 					if (rowval[x]) {
-						if (!strcasecmp(fields[x].name, "secret")) {
+						if (!strcasecmp(fields[x].name, mydbfield_secret)) {
 							strncpy(p->secret, rowval[x], sizeof(p->secret) - 1);
-						} else if (!strcasecmp(fields[x].name, "context")) {
+						} else if (!strcasecmp(fields[x].name, mydbfield_context)) {
 							strncpy(p->contexts->context, rowval[x], sizeof(p->contexts->context) - 1);
-						} else if (!strcasecmp(fields[x].name, "accountcode")) {
+						} else if (!strcasecmp(fields[x].name, mydbfield_accountcode)) {
 							strncpy(p->accountcode, rowval[x], sizeof(p->accountcode) - 1);
 						}
 					}
@@ -6702,6 +6718,23 @@
 			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, "dbfield_secret")) {
+             strncpy(mydbfield_secret, v->value, sizeof(mydbfield_secret) - 1);
+        } else if (!strcasecmp(v->name, "dbfield_user")) {
+             strncpy(mydbfield_peername, v->value, sizeof(mydbfield_peername) - 1);
+        } else if (!strcasecmp(v->name, "dbtable")) {
+             strncpy(mydbtable, v->value, sizeof(mydbtable) - 1);
+			 ast_log(LOG_NOTICE, "   Table name: '%s'\n", v->value);
+        } else if (!strcasecmp(v->name, "dbfield_ipaddr")) {
+             strncpy(mydbfield_ipaddr, v->value, sizeof(mydbfield_ipaddr) - 1);
+        } else if (!strcasecmp(v->name, "dbfield_port")) {
+             strncpy(mydbfield_port, v->value, sizeof(mydbfield_port) - 1);
+        } else if (!strcasecmp(v->name, "dbfield_regseconds")) {
+             strncpy(mydbfield_regseconds, v->value, sizeof(mydbfield_regseconds) - 1);
+        } else if (!strcasecmp(v->name, "dbfield_context")) {
+             strncpy(mydbfield_context, v->value, sizeof(mydbfield_context) - 1);
+        } else if (!strcasecmp(v->name, "dbfield_accountcode")) {
+             strncpy(mydbfield_accountcode, v->value, sizeof(mydbfield_accountcode) - 1);
 #endif
 		} else if (!strcasecmp(v->name, "language")) {
                         strncpy(language, v->value, sizeof(language) - 1);
