1d8785d66ed85fd0bff3ed301a7cd5a7692265c4
braney
  Wed Apr 8 13:05:43 2015 -0700
allow for different names for the sessionDb and userDb tables

diff --git src/hg/lib/cartDb.c src/hg/lib/cartDb.c
index 6b28608..e6c0341 100644
--- src/hg/lib/cartDb.c
+++ src/hg/lib/cartDb.c
@@ -30,43 +30,43 @@
 #include <sys/time.h>
 
 extern DbConnector cartDefaultConnector;
 extern DbDisconnect cartDefaultDisconnector;
 
 static boolean userDbInitialized = FALSE;
 static boolean sessionDbInitialized = FALSE;
 
 struct dyString *dyUpgradeError = NULL;
 
 boolean cartDbHasSessionKey(struct sqlConnection *conn, char *table)
 /* Check to see if the table has the sessionKey field */
 {
 static boolean userDbHasSessionKey = FALSE;
 static boolean sessionDbHasSessionKey = FALSE;
-if (sameString(table, "userDb"))
+if (sameString(table, userDbTable()))
     {
     if (!userDbInitialized)
 	{
 	userDbInitialized = TRUE;
 	if (sqlFieldIndex(conn, table, "sessionKey") >= 0)
 	    {
 	    userDbHasSessionKey = TRUE;
 	    } 
 	}
     return userDbHasSessionKey;
     }
-else if (sameString(table, "sessionDb"))
+else if (sameString(table, sessionDbTable()))
     {
     if (!sessionDbInitialized)
 	{
 	sessionDbInitialized = TRUE;
 	if (sqlFieldIndex(conn, table, "sessionKey") >= 0)
 	    {
 	    sessionDbHasSessionKey = TRUE;
 	    } 
 	}
     return sessionDbHasSessionKey;
     }
 else
     errAbort("Unknown table %s", table);
 return FALSE;
 }
@@ -198,47 +198,47 @@
 boolean cartDbUseSessionKey()
 /* Check settings and and state to determine if sessionKey is in use */
 {
 static boolean initialized = FALSE;
 static boolean useSessionKey = FALSE;
 if (!initialized)
     {
     initialized = TRUE;
     char *sessionKey = cfgOption2("browser", "sessionKey");
     if (!sessionKey)
 	sessionKey = "on";  // DEFAULT but this might change to another value
     if (sameString(sessionKey, "on"))
 	{
 	useSessionKey = TRUE;
 	struct sqlConnection *conn = cartDefaultConnector();
-	boolean userDbHasSessionKey = cartDbHasSessionKey(conn, "userDb");
-	boolean sessionDbHasSessionKey = cartDbHasSessionKey(conn, "sessionDb");
+	boolean userDbHasSessionKey = cartDbHasSessionKey(conn, userDbTable());
+	boolean sessionDbHasSessionKey = cartDbHasSessionKey(conn, sessionDbTable());
 	if ( ! (userDbHasSessionKey && sessionDbHasSessionKey) )
 	    {
     	    //errAbort("brower.sessionKey=on but userDb and sessionDb are missing the sessionKey field.");
 	    // AUTO-UPGRADE tables to add missing sessionKey field here.
 	    if (!userDbHasSessionKey)
 		{
-		autoUpgradeTableAddSessionKey(conn, "userDb");
+		autoUpgradeTableAddSessionKey(conn, userDbTable());
 		userDbInitialized = FALSE;
-		userDbHasSessionKey = cartDbHasSessionKey(conn, "userDb");
+		userDbHasSessionKey = cartDbHasSessionKey(conn, userDbTable());
 		}
     	    if (!sessionDbHasSessionKey)
 		{
-		autoUpgradeTableAddSessionKey(conn, "sessionDb");
+		autoUpgradeTableAddSessionKey(conn, sessionDbTable());
 		sessionDbInitialized = FALSE;
-		sessionDbHasSessionKey = cartDbHasSessionKey(conn, "sessionDb");
+		sessionDbHasSessionKey = cartDbHasSessionKey(conn, sessionDbTable());
 		}
 	    if ( ! (userDbHasSessionKey && sessionDbHasSessionKey) )
 		useSessionKey = FALSE;
 	    }
 	cartDefaultDisconnector(&conn);
 	}
     else if (sameString(sessionKey, "off"))
 	{
 	useSessionKey = FALSE;
 	}
     else if (sameString(sessionKey, "autodetect"))
 	{
 	errAbort("brower.sessionKey=autodetect has not implemented yet."); // TODO
 	}
     }
@@ -445,15 +445,35 @@
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 if (sep == ',') fputc('"',f);
 fprintf(f, "%s", el->lastUse);
 if (sep == ',') fputc('"',f);
 fputc(sep,f);
 fprintf(f, "%d", el->useCount);
 if (cartDbUseSessionKey())
     {
     fputc(sep,f);
     fprintf(f, "%s", el->sessionKey);
     }
 fputc(lastSep,f);
 }
 
+char *userDbTable()
+/* Return the name of the userDb table. */
+{
+static char *userDbTable = NULL;
+if (userDbTable == NULL)
+    userDbTable = cfgOptionEnvDefault("HGDB_USERDBTABLE",
+	    userDbTableConfVariable, defaultUserDbTableName);
+return userDbTable;
+}
+
+char *sessionDbTable()
+/* Return the name of the sessionDb table. */
+{
+static char *sessionDbTable = NULL;
+if (sessionDbTable == NULL)
+    sessionDbTable = cfgOptionEnvDefault("HGDB_SESSIONDBTABLE",
+	    sessionDbTableConfVariable, defaultSessionDbTableName);
+return sessionDbTable;
+}
+