6eacdcdb29afdeefa7ba7a5ec1e52e13e86680f9 hiram Wed Apr 10 14:45:45 2019 -0700 better layout for selection menus and now returning errors properly refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index 40b1708..a81f253 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -1,1385 +1,1432 @@ /* hubApi - access mechanism to hub data resources. */ #include "dataApi.h" #include "botDelay.h" #include "jsHelper.h" /* +------------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+------------------+------+-----+---------+-------+ | hubUrl | longblob | NO | PRI | NULL | | | shortLabel | varchar(255) | NO | | NULL | | | longLabel | varchar(255) | NO | | NULL | | | registrationTime | varchar(255) | NO | | NULL | | | dbCount | int(10) unsigned | NO | | NULL | | | dbList | blob | YES | | NULL | | | descriptionUrl | longblob | YES | | NULL | | +------------------+------------------+------+-----+---------+-------+ */ /* Global Variables for all modules */ int maxItemsOutput = 1000; /* can be set in URL maxItemsOutput=N */ static int maxItemLimit = 1000000; /* maximum of 1,000,000 items returned */ /* for debugging purpose, current bot delay value */ int botDelay = 0; boolean debug = FALSE; /* can be set in URL debug=1, to turn off: debug=0 */ #define delayFraction 0.03 /* default is to list all trackDb entries, composite containers too. * This option will limit to only the actual track entries with data */ boolean trackLeavesOnly = FALSE; /* set by CGI parameter 'trackLeavesOnly' */ /* Global only to this one source file */ static struct cart *cart; /* CGI and other variables */ static struct hash *oldVars = NULL; static struct hash *trackCounter = NULL; static long totalTracks = 0; static boolean measureTiming = FALSE; /* set by CGI parameters */ static boolean allTrackSettings = FALSE; /* checkbox setting */ static char **shortLabels = NULL; /* public hub short labels in array */ -// struct hubPublic *publicHubList = NULL; static int publicHubCount = 0; static char *defaultHub = "Plants"; -// static char *defaultHubUrl = " http://genome-test.gi.ucsc.edu/~hiram/hubs/Plants/hub.txt"; static char *defaultDb = "ce11"; static long enteredMainTime = 0; /* will become = clock1000() on entry */ /* to allow calculation of when to bail out, taking too long */ static long timeOutSeconds = 100; static boolean timedOut = FALSE; static char *urlPrefix = ""; /* initalized to support self references */ + + /* supportedTypes will be initialized to a known supported set */ static struct slName *supportedTypes = NULL; - /* will be initialized to a known supported set */ + static void initSupportedTypes() /* initalize the list of supported track types */ { struct slName *el = newSlName("bed"); slAddHead(&supportedTypes, el); el = newSlName("wig"); slAddHead(&supportedTypes, el); el = newSlName("broadPeak"); slAddHead(&supportedTypes, el); el = newSlName("narrowPeak"); slAddHead(&supportedTypes, el); el = newSlName("bigBed"); slAddHead(&supportedTypes, el); el = newSlName("bigWig"); slAddHead(&supportedTypes, el); el = newSlName("bigNarrowPeak"); slAddHead(&supportedTypes, el); el = newSlName("bigGenePred"); slAddHead(&supportedTypes, el); el = newSlName("genePred"); slAddHead(&supportedTypes, el); el = newSlName("psl"); slAddHead(&supportedTypes, el); el = newSlName("rmsk"); slAddHead(&supportedTypes, el); el = newSlName("bigPsl"); slAddHead(&supportedTypes, el); // el = newSlName("bigBarChart"); // slAddHead(&supportedTypes, el); // el = newSlName("bigInteract"); // slAddHead(&supportedTypes, el); // el = newSlName("bigMaf"); // slAddHead(&supportedTypes, el); // el = newSlName("bigChain"); // slAddHead(&supportedTypes, el); slNameSort(&supportedTypes); } static boolean isSupportedType(char *type) /* is given type in the supportedTypes list ? */ { boolean ret = FALSE; if (startsWith("wigMaf", type)) /* not wigMaf at this time */ return ret; struct slName *el; for (el = supportedTypes; el; el = el->next) { if (startsWith(el->name, type)) { ret = TRUE; break; } } return ret; } static int publicHubCmpCase(const void *va, const void *vb) /* Compare two shortLabels, ignore case. */ { const struct hubPublic *a = *((struct hubPublic **)va); const struct hubPublic *b = *((struct hubPublic **)vb); return strcasecmp(a->shortLabel, b->shortLabel); } static void publicHubSortCase(struct hubPublic **pList) /* Sort slName list, ignore case. */ { slSort(pList, publicHubCmpCase); } struct hubPublic *hubPublicDbLoadAll() /* read entire hubPublic table in hgcentral and return resulting list */ { char query[1024]; struct hubPublic *list = NULL; struct sqlConnection *conn = hConnectCentral(); sqlSafef(query, sizeof(query), "select * from %s", hubPublicTableName()); struct sqlResult *sr = sqlGetResult(conn, query); char **row; while ((row = sqlNextRow(sr)) != NULL) { struct hubPublic *el = hubPublicLoad(row); slAddHead(&list, el); } sqlFreeResult(&sr); hDisconnectCentral(&conn); publicHubSortCase(&list); int listSize = slCount(list); AllocArray(shortLabels, listSize); struct hubPublic *el = list; int i = 0; for ( ; el != NULL; el = el->next ) { shortLabels[i++] = el->shortLabel; ++publicHubCount; } return list; } static boolean timeOutReached() /* see if the timeout has been reached to determine if an exit * is appropriate at this time */ { long nowTime = clock1000(); timedOut = FALSE; if ((nowTime - enteredMainTime) > (1000 * timeOutSeconds)) timedOut= TRUE; return timedOut; } static void hashCountTrack(struct trackDb *tdb, struct hash *countTracks) /* this is counting up track types into the hash countTracks */ { char *stripType = cloneString(tdb->type); if (startsWith("chain ", tdb->type)) stripType = cloneString("chain"); else if (startsWith("netAlign ", tdb->type)) stripType = cloneString("netAlign"); else if (startsWith("genePred ", tdb->type)) stripType = cloneString("genePred"); else if (startsWith("bigWig ", tdb->type)) stripType = cloneString("bigWig"); else if (startsWith("wigMaf ", tdb->type)) stripType = cloneString("wigMaf"); else if (startsWith("wig ", tdb->type)) stripType = cloneString("wig"); else stripType = cloneString(tdb->type); boolean compositeContainer = tdbIsComposite(tdb); boolean compositeView = tdbIsCompositeView(tdb); boolean superChild = tdbIsSuperTrackChild(tdb); if (compositeContainer) hashIncInt(countTracks, "composite container"); else if (compositeView) hashIncInt(countTracks, "composite view"); else if (superChild) { hashIncInt(countTracks, "superTrack child"); hashIncInt(countTracks, stripType); hashIncInt(countTracks, "track count"); } else if (isEmpty(tdb->type)) hashIncInt(countTracks, "no type specified"); else { hashIncInt(countTracks, stripType); hashIncInt(countTracks, "track count"); } freeMem(stripType); } static void sampleUrl(struct trackHub *hub, char *db, struct trackDb *tdb, char *chrom, unsigned chromSize, char *errorString) /* print out a sample getData URL */ { char errorPrint[2048]; errorPrint[0] = 0; if (isNotEmpty(errorString)) { safef(errorPrint, sizeof(errorPrint), " ERROR: %s", errorString); } boolean superChild = tdbIsSuperTrackChild(tdb); unsigned start = chromSize / 4; unsigned end = start + 10000; if (end > chromSize) end = chromSize; char *genome = NULL; if (hub) genome = hub->genomeList->name; if (db) { if (hub) { char urlReference[2048]; - safef(urlReference, sizeof(urlReference), " (sample getData)%s\n", urlPrefix, hub->url, genome, tdb->track, chrom, start, end, errorPrint); + safef(urlReference, sizeof(urlReference), " (sample data)%s\n", urlPrefix, hub->url, genome, tdb->track, chrom, start, end, errorPrint); if (tdb->parent) hPrintf("
\n"); cartDump(cart); hPrintf("\n"); } static void sendJsonHogMessage(char *hogHost) { -apiErrAbort("Your host, %s, has been sending too many requests lately and is " +apiErrAbort(429, "Too Many Requests", "Your host, %s, has been sending too many requests lately and is " "unfairly loading our site, impacting performance for other users. " "Please contact genome@soe.ucsc.edu to ask that your site " "be reenabled. Also, please consider downloading sequence and/or " "annotations in bulk -- see http://genome.ucsc.edu/downloads.html.", hogHost); } static void sendHogMessage(char *hogHost) { +puts("Content-Type:text/html"); +puts("Status: 429 Too Many Requests"); +puts("Retry-After: 30"); +puts("\n"); + hPrintf("\n"); hPrintf("\n"); hPrintf("\n"); hPrintf("\n"); hPrintf("
\n"); hPrintf("Your host, %s, has been sending too many requests lately and is " "unfairly loading our site, impacting performance for other users. " "Please contact genome@soe.ucsc.edu to ask that your site " "be reenabled. Also, please consider downloading sequence and/or " "annotations in bulk -- see http://genome.ucsc.edu/downloads.html.", hogHost); hPrintf("
\n"); exit(0); } static void hogExit() /* bottleneck server requests exit */ { char *hogHost = getenv("REMOTE_ADDR"); char *pathInfo = getenv("PATH_INFO"); /* nothing on incoming path, then display the WEB page instead */ if (sameOk("/",pathInfo)) pathInfo = NULL; if (isNotEmpty(pathInfo)) { - puts("Content-Type:application/json"); - puts("Status: 459 Too Many Requests"); - /* maybe a Retry-After: 3600 statement here ? */ - puts("\n"); sendJsonHogMessage(hogHost); } else { - puts("Content-Type:text/html"); - puts("Status: 459 Too Many Requests"); - /* maybe a Retry-After: 3600 statement here ? */ - puts("\n"); sendHogMessage(hogHost); } +} /* static void hogExit() */ + +/* name of button group */ +#define RADIO_GROUP "selectRadio" +/* button functions */ +#define RADIO_PUBHUB "pubHub" +#define RADIO_OTHERHUB "otherHub" +#define RADIO_UCSCDB "ucscDb" + +static void selectionForm() +/* setup the selection pull-downs for source */ +{ +char *hubDropDown = cartUsualString(cart, "publicHubs", defaultHub); +char *urlDropDown = urlFromShortLabel(hubDropDown); +char *otherHubUrl = cartUsualString(cart, "urlHub", ""); +char *ucscDb = cartUsualString(cart, "ucscGenome", defaultDb); + +if (isEmpty(otherHubUrl)) + otherHubUrl = urlDropDown; + +char *radioOn = cartUsualString(cart, RADIO_GROUP, RADIO_PUBHUB); + +/* create border around table, but not inside the table with the data */ +hPrintf("\n"); -if (sameWord("go", goUcscDb)) /* requested UCSC db track list */ +if (sameWord(RADIO_UCSCDB, selectRadio)) /* requested UCSC db track list */ { tracksForUcscDb(ucscDb); } else { - hPrintf("