774479fda06428280150d609bdf4052f5f35d571 hiram Wed Feb 13 14:17:16 2019 -0800 list functions moved to list.c refs #18869 diff --git src/hg/hubApi/hubApi.c src/hg/hubApi/hubApi.c index cb478e5..850fb5f 100644 --- src/hg/hubApi/hubApi.c +++ src/hg/hubApi/hubApi.c @@ -1,161 +1,101 @@ /* hubApi - access mechanism to hub data resources. */ #include "dataApi.h" -#ifdef NOT -#include "common.h" -#include "linefile.h" -#include "hash.h" -#include "options.h" -#include "jksql.h" -#include "htmshell.h" -#include "web.h" -#include "cheapcgi.h" -#include "cart.h" -#include "hui.h" -#include "udc.h" -#include "knetUdc.h" -#include "genbank.h" -#include "trackHub.h" -#include "hgConfig.h" -#include "hCommon.h" -#include "hPrint.h" -#include "bigWig.h" -#include "hubConnect.h" -#include "obscure.h" -#include "errCatch.h" -#include "vcf.h" -#include "bedTabix.h" -#include "bamFile.h" -#include "jsonParse.h" -#include "jsonWrite.h" -#include "chromInfo.h" - -#ifdef USE_HAL -#include "halBlockViz.h" -#endif - -#endif /* +------------------+------------------+------+-----+---------+-------+ | 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 | | +------------------+------------------+------+-----+---------+-------+ */ +#ifdef NOT +/*this definition should be over in hg/inc/hubPublic.h but that does not exist*/ struct hubPublic /* Table of public track data hub connections. */ { struct hubPublic *next; /* Next in singly linked list. */ char *hubUrl; /* URL to hub.ra file */ char *shortLabel; /* Hub short label. */ char *longLabel; /* Hub long label. */ char *registrationTime; /* Time first registered */ unsigned dbCount; /* Number of databases hub has data for. */ char *dbList; /* Comma separated list of databases. */ char *descriptionUrl; /* URL to description HTML */ }; +#endif /* Global Variables */ 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 *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; #ifdef NOT -/* ######################################################################### */ -static struct jsonWrite *jsonStartOutput() -/* begin json output with standard header information for all requests */ -{ -time_t timeNow = time(NULL); -// struct tm tm; -// gmtime_r(&timeNow, &tm); -struct jsonWrite *jw = jsonWriteNew(); -jsonWriteObjectStart(jw, NULL); -jsonWriteString(jw, "apiVersion", "0.1"); -jsonWriteString(jw, "source", "UCSantaCruz"); -jsonWriteDateFromUnix(jw, "downloadTime", (long long) timeNow); -jsonWriteNumber(jw, "downloadTimeStamp", (long long) timeNow); -return jw; -} - -static void jsonErrAbort(char *format, ...) -/* Issue an error message in json format, and exit(0) */ -{ -char errMsg[2048]; -va_list args; -va_start(args, format); -vsnprintf(errMsg, sizeof(errMsg), format, args); -struct jsonWrite *jw = jsonStartOutput(); -jsonWriteString(jw, "error", errMsg); -jsonWriteObjectEnd(jw); -fputs(jw->dy->string,stdout); -exit(0); -} -#endif - static void hubPublicJsonData(struct jsonWrite *jw, struct hubPublic *el) /* Print array data for one row from hubPublic table, order here * must be same as was stated in the columnName header element * TODO: need to figure out how to use the order of the columns as * they are in the 'desc' request */ { jsonWriteListStart(jw, NULL); jsonWriteString(jw, NULL, el->hubUrl); jsonWriteString(jw, NULL, el->shortLabel); jsonWriteString(jw, NULL, el->longLabel); jsonWriteString(jw, NULL, el->registrationTime); jsonWriteNumber(jw, NULL, (long long)el->dbCount); jsonWriteString(jw, NULL, el->dbList); jsonWriteString(jw, NULL, el->descriptionUrl); jsonWriteListEnd(jw); } -int trackDbTrackCmp(const void *va, const void *vb) +static int trackDbTrackCmp(const void *va, const void *vb) /* Compare to sort based on 'track' name; use shortLabel as secondary sort key. * Note: parallel code to hgTracks.c:tgCmpPriority */ { const struct trackDb *a = *((struct trackDb **)va); const struct trackDb *b = *((struct trackDb **)vb); int dif = strcmp(a->track, b->track); if (dif < 0) return -1; else if (dif == 0.0) return strcasecmp(a->shortLabel, b->shortLabel); else return 1; } +#endif + static int publicHubCmpCase(const void *va, const void *vb) /* Compare two slNames, 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); } static struct hubPublic *hubPublicLoad(char **row) @@ -166,31 +106,31 @@ AllocVar(ret); ret->hubUrl = cloneString(row[0]); ret->shortLabel = cloneString(row[1]); ret->longLabel = cloneString(row[2]); ret->registrationTime = cloneString(row[3]); ret->dbCount = sqlUnsigned(row[4]); ret->dbList = cloneString(row[5]); // if (row[6]) ret->descriptionUrl = cloneString(row[6]); // else // ret->descriptionUrl = cloneString(""); return ret; } -static struct hubPublic *hubPublicLoadAll() +struct hubPublic *hubPublicLoadAll() { 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); @@ -446,31 +386,31 @@ { hPrintf("
  • %s : %s
  • \n", hel->name, (char *)hel->val); if (sameWord("trackDb", hel->name)) /* examine the trackDb structure */ { struct trackDb *tdb = trackHubTracksForGenome(genome->trackHub, genome); retTbd = tdb; hubTrackList(tdb, genome); } if (timeOutReached()) break; } hPrintf(" \n"); return retTbd; } -static struct slName *genomeList(struct trackHub *hubTop, struct trackDb **dbTrackList, char *selectGenome) +struct slName *genomeList(struct trackHub *hubTop, struct trackDb **dbTrackList, char *selectGenome) /* follow the pointers from the trackHub to trackHubGenome and around * in a circle from one to the other to find all hub resources * return slName list of the genomes in this track hub * optionally, return the trackList from this hub for the specified genome */ { struct slName *retList = NULL; long totalAssemblyCount = 0; struct trackHubGenome *genome = hubTop->genomeList; hPrintf("

    genome sequences (and tracks) present in this track hub

    \n"); hPrintf("