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
@@ -1,406 +1,408 @@
/* hgGateway - Human Genome Browser Gateway. */
#include "common.h"
#include "linefile.h"
#include "hash.h"
#include "cheapcgi.h"
#include "htmshell.h"
#include "obscure.h"
#include "web.h"
#include "cart.h"
#include "hdb.h"
#include "dbDb.h"
#include "hgFind.h"
#include "hCommon.h"
#include "hui.h"
#include "customTrack.h"
#include "hubConnect.h"
#include "hgConfig.h"
#include "jsHelper.h"
#include "hPrint.h"
#include "suggest.h"
#include "search.h"
#include "internet.h"
struct cart *cart = NULL;
struct hash *oldVars = NULL;
char *clade = NULL;
char *organism = NULL;
char *db = NULL;
void hgGateway()
/* hgGateway - Human Genome Browser Gateway. */
{
char *defaultPosition = hDefaultPos(db);
char *position = cloneString(cartUsualString(cart, "position", defaultPosition));
boolean gotClade = hGotClade();
char *survey = cfgOptionEnv("HGDB_SURVEY", "survey");
char *surveyLabel = cfgOptionEnv("HGDB_SURVEY_LABEL", "surveyLabel");
boolean supportsSuggest = assemblySupportsGeneSuggest(db);
/* JavaScript to copy input data on the change genome button to a hidden form
This was done in order to be able to flexibly arrange the UI HTML
*/
char *onChangeDB = "onchange=\"document.orgForm.db.value = document.mainForm.db.options[document.mainForm.db.selectedIndex].value; document.orgForm.submit();\"";
char *onChangeOrg = "onchange=\"document.orgForm.org.value = document.mainForm.org.options[document.mainForm.org.selectedIndex].value; document.orgForm.db.value = 0; document.orgForm.submit();\"";
char *onChangeClade = "onchange=\"document.orgForm.clade.value = document.mainForm.clade.options[document.mainForm.clade.selectedIndex].value; document.orgForm.org.value = 0; document.orgForm.db.value = 0; document.orgForm.submit();\"";
/*
If we are changing databases via explicit cgi request,
then remove custom track data which will
be irrelevant in this new database .
If databases were changed then use the new default position too.
*/
if (sameString(position, "genome") || sameString(position, "hgBatch"))
position = defaultPosition;
jsIncludeFile("jquery.js", NULL);
#ifdef NEW_JQUERY
webIncludeResourceFile("jquery-ui.css");
jsIncludeFile("jquery-ui.js", NULL);
printf("\n");
#else///ifndef NEW_JQUERY
webIncludeResourceFile("autocomplete.css");
jsIncludeFile("jquery.autocomplete.js", NULL);
printf("\n");
#endif///ndef NEW_JQUERY
jsIncludeFile("ajax.js", NULL);
jsIncludeFile("autocomplete.js", NULL);
jsIncludeFile("hgGateway.js", NULL);
jsIncludeFile("utils.js", NULL);
puts(
"
"
"The UCSC Genome Browser was created by the \n"
"Genome Bioinformatics Group of UC Santa Cruz.\n"
"
"
"Software Copyright (c) The Regents of the University of California.\n"
"All rights reserved.\n"
"\n"
);
puts(
"");
if (hIsPreviewHost())
{
puts(""
"WARNING: This is our preview site. It is a weekly mirror of our internal development server for public access. "
"Data and tools here are under construction, have not been quality reviewed, and are subject to change "
"at any time. We provide this site for early access, with the warning that it is less available "
"and stable than our public site. For high-quality reviewed annotations on our production server, visit "
" http://genome.ucsc.edu."
"
");
}
else if (hIsPrivateHost())
{
puts("WARNING: This is our development and test site. It usually works, but it is filled with tracks in various "
"stages of construction, and others of little interest to people outside of our local group. "
"It is usually slow because we are building databases on it. The documentation is poor. "
"More data than usual is flat out wrong. Maybe you want to go to "
"genome.ucsc.edu instead.");
}
if (hIsGsidServer())
{
webNewSection("%s", "Sequence View\n");
printf("%s",
"Sequence View is a customized version of the UCSC Genome Browser, which is specifically tailored to provide functions needed for the GSID HIV Data Browser.\n");
}
hgPositionsHelpHtml(organism, db);
puts("
");
}
void doMiddle(struct cart *theCart)
/* Set up pretty web display and save cart in global. */
{
char *scientificName = NULL;
cart = theCart;
getDbGenomeClade(cart, &db, &organism, &clade, oldVars);
if (! hDbIsActive(db))
{
db = hDefaultDb();
organism = hGenome(db);
clade = hClade(organism);
}
scientificName = hScientificName(db);
if (hIsGsidServer())
cartWebStart(theCart, db, "GSID %s Sequence View (UCSC Genome Browser) Gateway \n", organism);
else
{
char buffer[128];
/* tell html routines *not* to escape htmlOut strings*/
htmlNoEscape();
buffer[0] = 0;
if (*scientificName != 0)
{
if (sameString(clade,"ancestor"))
safef(buffer, sizeof(buffer), "(%s Ancestor) ", scientificName);
else
safef(buffer, sizeof(buffer), "(%s) ", scientificName);
}
cartWebStart(theCart, db, "%s %s%s Gateway\n", organism, buffer, hBrowserName());
htmlDoEscape();
}
hgGateway();
cartWebEnd();
}
char *excludeVars[] = {NULL};
int main(int argc, char *argv[])
/* Process command line. */
{
oldVars = hashNew(10);
cgiSpoof(&argc, argv);
#ifdef SUPPORT_EURONODE
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
// get location of redirect node
if (thisNode != defaultNode)
{
safef(query, sizeof query, "select domain from gbNode where node = %d", defaultNode);
char *newDomain = sqlQuickString(centralConn, query);
fprintf(stderr, "GALT newDomain=%s\n", newDomain); fflush(stderr); // DEBUG REMOVE
char *oldDomain = cgiServerName();
char *port = cgiServerPort();
char *uri = cgiRequestUri();
// /cgi-bin/test.cgi?x=15&y=youdog
char *sep = "?";
if (strchr(uri,'?') != 0)
sep = "&";
int newUriSize = strlen(uri)+1024;
char *newUri = needMem(newUriSize);
// TODO what about https?
safef(newUri, newUriSize, "http://%s:%s%s%sredirect=mirror&source=%s", newDomain, port, uri, sep, oldDomain);
// "set-cookie: redirect=; path=/; expires=Mon, 18-Apr-2011 21:45:28 GMT"
// the time of the set-cookie expire was immediately now()
struct dyString *dy = dyStringNew(256);
dyStringPrintf(dy,
"HTTP/1.1 302 found: \n"
"Content-Type: text/html; charset=iso-8859-1\n"
"Connection: close\n"
"Location: %s\n"
"\n"
"Redirecting to closer site\n"
"%s\n"
, newUri , newUri, newUri);
fprintf(stderr, "GALT redirect response:\n%s", dy->string); fflush(stderr); // DEBUG REMOVE
puts(dyStringContents(dy));
exit(0);
}
hDisconnectCentral(¢ralConn);
}
}
}
#endif
cartEmptyShell(doMiddle, hUserCookie(), excludeVars, oldVars);
return 0;
}