af730d9e24c0642fe39657f890bc117ed015ccbf
galt
  Wed Feb 15 01:12:26 2017 -0800
CSP code cleanup. Using new var-args versions of functions jsInlineF and jsOnEventByIdF to avoid using lots of fixed-size local javascript strings.

diff --git src/hg/hgHubConnect/hgHubConnect.c src/hg/hgHubConnect/hgHubConnect.c
index 717ec44..dc41848 100644
--- src/hg/hgHubConnect/hgHubConnect.c
+++ src/hg/hgHubConnect/hgHubConnect.c
@@ -92,52 +92,49 @@
     if (dyShort->stringSize == 0 || (dyShort->stringSize+strlen(trimmedName)<=GENLISTWIDTH))
 	dyStringPrintf(dyShort,"%s, ", trimmedName);
     }
 char *genomesString = removeLastComma( dyStringCannibalize(&dy));
 char *genomesShort = removeLastComma( dyStringCannibalize(&dyShort));
 char tempHtml[1024+strlen(genomesString)+strlen(genomesShort)];
 if (strlen(genomesShort) > GENLISTWIDTH)  // If even the first element is too long, truncate it.
     genomesShort[GENLISTWIDTH] = 0;
 if (strlen(genomesShort)==strlen(genomesString))
     {
     safef(tempHtml, sizeof tempHtml, "%s", genomesString);
     }
 else
     {
     char id[256];
-    char javascript[1024];
     safef(tempHtml, sizeof tempHtml, 
 	"<span id=Short%d>[+]&nbsp;%s...</span>"
 	"<span id=Full%d style=\"display:none\">[-]<br>%s</span>"
 	, row, genomesShort 
 	, row, genomesString);
 
     safef(id, sizeof id, "Short%d", row);
-    safef(javascript, sizeof javascript,
+    jsOnEventByIdF("click", id,
 	"document.getElementById('Short%d').style.display='none';"
 	"document.getElementById('Full%d').style.display='inline';"
 	"return false;"
 	, row, row);
-    jsOnEventById("click", id, javascript);
 
     safef(id, sizeof id, "Full%d", row);
-    safef(javascript, sizeof javascript,
+    jsOnEventByIdF("click", id, 
 	"document.getElementById('Full%d').style.display='none';"
 	"document.getElementById('Short%d').style.display='inline';"
 	"return false;"
 	, row, row);
-    jsOnEventById("click", id, javascript);
     }
 ourPrintCell(tempHtml);
 //ourPrintCell(removeLastComma( dyStringCannibalize(&dy)));
 }
 
 
 static void printGenomes(struct trackHub *thub, int row)
 /* print supported assembly names from trackHub */
 {
 /* List of associated genomes. */
 struct trackHubGenome *genomes = thub->genomeList;
 struct slName *list = NULL, *el;
 for(; genomes; genomes = genomes->next)
     {
     el = slNameNew(genomes->name);
@@ -202,78 +199,75 @@
 
 // time to output the big table.  First the header
 printf(
     "<tr> "
 	"<th>Display</th> "
 	"<th>Hub Name</th> "
 	"<th>Description</th> "
 	"<th>Assemblies</th> "
     "</tr>\n"
     "</thead>\n");
 
 // start first row
 printf("<tbody>");
 
 char id[256];
-char javascript[1024];
 int count = 0;
 for(hub = unlistedHubList; hub; hub = hub->next)
     {
     char hubName[64];
     safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, hub->id);
     if (!cartUsualBoolean(cart, hubName, FALSE))
 	continue;
 
     if (count)
 	webPrintLinkTableNewRow();  // ends last row and starts a new one
     count++;
 
     puts("<tr>");
 
     ourCellStart();
     safef(id, sizeof id, "hubDisconnectButton%d", count);
     printf("<input name=\"hubDisconnectButton\" id='%s' "
 	"class=\"hubDisconnectButton\" type=\"button\" value=\"Disconnect\">\n", id);
-    safef(javascript, sizeof javascript,
+    jsOnEventByIdF("click", id, 
 	"document.disconnectHubForm.elements['hubId'].value='%d';"
 	"document.disconnectHubForm.submit(); return true;", hub->id);
-    jsOnEventById("click", id, javascript);
     ourCellEnd();
 
     if (hub->trackHub != NULL)
 	{
 	ourPrintCellLink(hub->trackHub->shortLabel, hub->hubUrl);
 	}
     else
 	ourPrintCell("");
 
     if (!isEmpty(hub->errorMessage))
 	{
 	ourCellStart();
 	printf("<span class=\"hubError\">ERROR: %s </span>"
 	    "<a TARGET=_BLANK href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug Help</a>\n", 
 	    hub->errorMessage);
 	
 	safef(id, sizeof id, "hubClearButton%d", count);
 	// give people a chance to clear the error 
 	printf("<input name=\"hubClearButton\"  id='%s' "
 		"class=\"hubButton\" type=\"button\" value=\"Retry Hub\">"
 		, id);
-	safef(javascript, sizeof javascript,
+	jsOnEventByIdF("click", id,
 	    "document.resetHubForm.elements['hubCheckUrl'].value='%s';"
 	    "document.resetHubForm.submit(); return true;", hub->hubUrl);
-	jsOnEventById("click", id, javascript);
 	ourCellEnd();
 	}
     else if (hub->trackHub != NULL)
 	{
 	if (hub->trackHub->descriptionUrl != NULL)
 	    ourPrintCellLink(hub->trackHub->longLabel, hub->trackHub->descriptionUrl);
 	else
 	    ourPrintCell(hub->trackHub->longLabel);
 	}
     else
 	ourPrintCell("");
 
     if (hub->trackHub != NULL)
 	printGenomes(hub->trackHub, count);
     else
@@ -365,31 +359,30 @@
 struct hash *publicHash = newHash(5);
 char query[512];
 bool hasDescription = sqlColumnExists(conn, publicTable, "descriptionUrl");
 if (hasDescription)
     sqlSafef(query, sizeof(query), "select p.hubUrl,p.shortLabel,p.longLabel,p.dbList,s.errorMessage,s.id,p.descriptionUrl from %s p,%s s where p.hubUrl = s.hubUrl", 
 	  publicTable, statusTable); 
 else
     sqlSafef(query, sizeof(query), "select p.hubUrl,p.shortLabel,p.longLabel,p.dbList,s.errorMessage,s.id from %s p,%s s where p.hubUrl = s.hubUrl", 
 	 publicTable, statusTable); 
 
 struct sqlResult *sr = sqlGetResult(conn, query);
 char **row;
 int count = 0;
 boolean gotAnyRows = FALSE;
 char jsId[256];
-char javascript[1024];
 while ((row = sqlNextRow(sr)) != NULL)
     {
     ++count;
     char *url = row[0], *shortLabel = row[1], *longLabel = row[2], 
     	  *dbList = row[3], *errorMessage = row[4], *descriptionUrl = row[6];
     int id = atoi(row[5]);
 
     hashStore(publicHash, url);
     if ((urlSearchHash != NULL) && (hashLookup(urlSearchHash, url) == NULL))
 	continue;
 
     struct slName *dbListNames = slNameListFromComma(dbList);
 
     if (gotAnyRows)
 	webPrintLinkTableNewRow();
@@ -409,88 +402,85 @@
 	// start first row
 	printf("<tbody> <tr>");
 	gotAnyRows = TRUE;
 	}
 
     if (id != 0)
 	{
 	ourCellStart();
 	char hubName[32];
 	safef(hubName, sizeof(hubName), "%s%u", hgHubConnectHubVarPrefix, id);
 	if (cartUsualBoolean(cart, hubName, FALSE))
 	    {
 	    safef(jsId, sizeof jsId, "hubDisconnectButton%d", count);
 	    printf("<input name=\"hubDisconnectButton\" id='%s' "
 		"class=\"hubDisconnectButton\" type=\"button\" value=\"Disconnect\">\n", jsId);
-	    safef(javascript, sizeof javascript,
+	    jsOnEventByIdF("click", jsId, 
 		"document.disconnectHubForm.elements['hubId'].value= '%d';"
 		"document.disconnectHubForm.submit();return true;", id);
-	    jsOnEventById("click", jsId, javascript);
 	    }
 	else
 	    {
 	    // get first name off of list of supported databases
 	    char * name = dbListNames->name;
 
 	    // if the name isn't currently loaded, we assume it's a hub
 	    if (!hDbExists(name))
 		{
 		char buffer[512];
 
 		safef(buffer, sizeof buffer, "hub_%d_%s",  id, name);
 		name = cloneString(buffer);
 		}
 
 	    safef(jsId, sizeof jsId, "hubConnectButton%d", count);
 	    printf("<input name=\"hubConnectButton\" id='%s' "
 		"class=\"hubButton\" type=\"button\" value=\"Connect\">\n", jsId);
-	    safef(javascript, sizeof javascript,
+	    jsOnEventByIdF("click", jsId, 
 		"document.connectHubForm.elements['hubUrl'].value= '%s';"
 		"document.connectHubForm.elements['db'].value= '%s';"
 		"document.connectHubForm.submit();return true;", url,name);
-	    jsOnEventById("click", jsId, javascript);
 	    }
 
 	ourCellEnd();
 	}
     else
 	errAbort("cannot get id for hub with url %s\n", url);
 
     ourPrintCellLink(shortLabel, url);
 
     if (isEmpty(errorMessage))
 	{
 	if (hasDescription && !isEmpty(descriptionUrl))
 	    ourPrintCellLink(longLabel, descriptionUrl);
 	else
 	    ourPrintCell(longLabel);
 	}
     else
 	{
 	ourCellStart();
 	printf("<span class=\"hubError\">ERROR: %s </span>"
 	    "<a href=\"../goldenPath/help/hgTrackHubHelp.html#Debug\">Debug Help</a>", 
 	    errorMessage);
 	safef(jsId, sizeof jsId, "hubClearButton%d", count);
 	printf(
 	"<input name=\"hubClearButton\" id='%s' "
 		"class=\"hubButton\" type=\"button\" value=\"Retry Hub\">"
 		, jsId);
-	safef(javascript, sizeof javascript,
+	jsOnEventByIdF("click", jsId, 
 	    "document.resetHubForm.elements['hubCheckUrl'].value='%s';"
 	    "document.resetHubForm.submit();return true;", url);
-	jsOnEventById("click", jsId, javascript);
 	ourCellEnd();
 	}
 
     printGenomeList(dbListNames, count); 
     }
 sqlFreeResult(&sr);
 
 if (gotAnyRows)
     printf("</TR></tbody></TABLE>\n");
 
 printf("</div>");
 *pHash = publicHash;
 return gotAnyRows;
 }