0f20260166f55679e7abbc702d955e42e71773eb
larrym
  Tue Dec 27 14:49:59 2011 -0800
cleanup and comments
diff --git src/hg/hgGateway/hgGateway.c src/hg/hgGateway/hgGateway.c
index ad69ec5..12296f7 100644
--- src/hg/hgGateway/hgGateway.c
+++ src/hg/hgGateway/hgGateway.c
@@ -319,43 +319,45 @@
 boolean onWeb = cgiIsOnWeb();
 if (onWeb)
     {
     // check IP for redirection
     char *thisNodeStr = cfgOption("browser.node");
     if (thisNodeStr)
 	{
 	char *redirect = cgiOptionalString("redirect");
 	char *source = cgiOptionalString("source");
 	// check for the cookie called redirect (which suppress redirection)
 	char *redirectCookie = findCookieData("redirect");
 
 	fprintf(stderr, "GALT redirectCookie=%s redirect=%s source=%s\n", 
 		redirectCookie, redirect, source); fflush(stderr); // DEBUG REMOVE
 
-	if (!(redirectCookie || (redirect && !source)))
+	if (!(
+              (redirect && !source) ||   // we are on main site after user has actively choose to leave mirror and come back to the main site
+              redirectCookie             // main site after above has happened (XXXX I think)
+              ))
 	    {
-	    int thisNode = atoi(thisNodeStr);
+	    int thisNode = sqlUnsigned(thisNodeStr);
 	    struct sqlConnection *centralConn = hConnectCentral();
 	    char query[1024];
 	    char *ipStr = cgiRemoteAddr();
 	    bits32 ip = 0;
 	    internetDottedQuadToIp(ipStr, &ip);
             // we assume no overlaps in geoIpNode table, so we can use limit 1 to make query very efficient.
 	    safef(query, sizeof query, "select ipStart, ipEnd, node from geoIpNode where %u >= ipStart order by ipStart desc limit 1", ip);
 	    char **row;
-	    struct sqlResult *sr = NULL;
-	    sr = sqlGetResult(centralConn, query);
+	    struct sqlResult *sr = sqlGetResult(centralConn, query);
 	    int defaultNode = 1;
 	    if ((row = sqlNextRow(sr)) != NULL)
 		{
 		uint ipStart = sqlUnsigned(row[0]);
 		uint ipEnd = sqlUnsigned(row[1]);
 		if (ipStart <= ip && ipEnd >= ip)
 		    {
 		    defaultNode = sqlSigned(row[2]);
 		    }
 		}
 	    sqlFreeResult(&sr);
 
 	    fprintf(stderr, "GALT thisNodeStr=%s thisNode=%d ipStr=%s ip=%u defaultNode (for user) %d\n", 
 		thisNodeStr, thisNode,
 		ipStr, ip, defaultNode); fflush(stderr); // DEBUG REMOVE