Beispiel #1
0
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, 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)
		{
                autoUpgradeTableAddColumn(conn, userDbTable(), "sessionKey",
                                          "varchar(255)", TRUE, "''");
		userDbInitialized = FALSE;
		userDbHasSessionKey = cartDbHasSessionKey(conn, userDbTable());
		}
    	    if (!sessionDbHasSessionKey)
		{
                autoUpgradeTableAddColumn(conn, sessionDbTable(), "sessionKey",
                                          "varchar(255)", TRUE, "''");
		sessionDbInitialized = FALSE;
		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
	}
    }
return useSessionKey;
}
Beispiel #2
0
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, userDbTable()))
    {
    if (!userDbInitialized)
	{
	userDbInitialized = TRUE;
	if (sqlFieldIndex(conn, table, "sessionKey") >= 0)
	    {
	    userDbHasSessionKey = TRUE;
	    } 
	}
    return userDbHasSessionKey;
    }
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;
}