090d4afcaf0482dfa3f5eaec25d915f1d4a9fa9e
max
  Thu Jun 15 13:34:32 2017 -0700
Cleanup of hgSession to make the distinction between the login server and local
server clearer in the code. Renaming and moving two functions from wikiLink to
hdb, as at least one is not necessarily wikiLink-related and it's good to keep
them together. Also adding a warning to hgSession.c (probably
useless). refs #19632 and also see related tickets there.

diff --git src/hg/lib/wikiLink.c src/hg/lib/wikiLink.c
index b2c033d..fd98553 100644
--- src/hg/lib/wikiLink.c
+++ src/hg/lib/wikiLink.c
@@ -288,32 +288,31 @@
 if (isEmpty(wikiHost) || sameString(wikiHost, "HTTPHOST"))
     wikiHost = hHttpHost();
 return cloneString(wikiHost);
 }
 
 boolean loginUseHttps()
 /* Return TRUE unless https is disabled in hg.conf. */
 {
 return cfgOptionBooleanDefault(CFG_LOGIN_USE_HTTPS, TRUE);
 }
 
 static char *loginUrl()
 /* Return the URL for the login host. */
 {
 char buf[2048];
-safef(buf, sizeof(buf), "http%s://%s/cgi-bin/hgLogin",
-      loginUseHttps() ? "s" : "", wikiLinkHost());
+safef(buf, sizeof(buf), "%s/hgLogin", hLoginHostCgiBinUrl());
 return cloneString(buf);
 }
 
 char* getHttpBasicToken()
 /* Return HTTP Basic Auth Token or NULL. Result has to be freed. */
 {
 char *auth = getenv("HTTP_AUTHORIZATION");
 // e.g. "Basic bwF4OmQxUglhanM="
 if (auth==NULL)
     return NULL;
 char *token = cloneNotFirstWord(auth);
 if (isEmpty(token))
     {
     fprintf(stderr, "wikiLinkc.: Illegal format of HTTP Authorization Header?");
     return NULL;
@@ -395,55 +394,55 @@
     char *wikiUserName = findCookieData(wikiLinkUserNameCookie());
     char *wikiLoggedIn = findCookieData(wikiLinkLoggedInCookie());
     if (isNotEmpty(wikiLoggedIn) && isNotEmpty(wikiUserName))
         return cloneString(wikiUserName);
     }
 else
     errAbort("wikiLinkUserName called when wiki is not enabled (specified "
         "in hg.conf).");
 return NULL;
 }
 
 static char *encodedHgSessionReturnUrl(char *hgsid)
 /* Return a CGI-encoded hgSession URL with hgsid.  Free when done. */
 {
 char retBuf[1024];
-char *cgiDir = cgiScriptDirUrl();
-safef(retBuf, sizeof(retBuf), "http%s://%s%shgSession?hgsid=%s",
-      cgiAppendSForHttps(), cgiServerNamePort(), cgiDir, hgsid);
+safef(retBuf, sizeof(retBuf), "%shgSession?hgsid=%s",
+      hLocalHostCgiBinUrl(), hgsid);
 return cgiEncode(retBuf);
 }
 
 
 //#*** TODO: replace all of the non-mediawiki "returnto"s here and in hgLogin.c with a #define
 
 
 char *wikiLinkUserLoginUrlReturning(char *hgsid, char *returnUrl)
 /* Return the URL for the wiki user login page. */
 {
 char buf[2048];
 if (loginSystemEnabled())
     {
     safef(buf, sizeof(buf),
         "%s?hgLogin.do.displayLoginPage=1&returnto=%s",
         loginUrl(), returnUrl);
     } 
 else 
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLoginUrl called when wiki is not enabled (specified "
             "in hg.conf).");
+    // The following line of code is not used at UCSC anymore since 2014
     safef(buf, sizeof(buf),
         "http://%s/index.php?title=Special:UserloginUCSC&returnto=%s",
         wikiLinkHost(), returnUrl);
     }   
 return(cloneString(buf));
 }
 
 char *wikiLinkUserLoginUrl(char *hgsid)
 /* Return the URL for the wiki user login page with return going to hgSessions. */
 {
 char *retUrl = encodedHgSessionReturnUrl(hgsid);
 char *result = wikiLinkUserLoginUrlReturning(hgsid, retUrl);
 freez(&retUrl);
 return result;
 }
@@ -517,46 +516,28 @@
         loginUrl(), retEnc);
     }
 else
     {
     if (! wikiLinkEnabled())
         errAbort("wikiLinkUserLogoutUrl called when wiki is not enable (specified "
             "in hg.conf).");
     safef(buf, sizeof(buf),
         "http://%s/index.php?title=Special:UserlogoutUCSC&returnto=%s",
          wikiLinkHost(), retEnc);
     }
 freez(&retEnc);
 return(cloneString(buf));
 }
 
-char *wikiServerAndCgiDir() 
-/* return the current full absolute URL up to the CGI name, like
- * http://genome.ucsc.edu/cgi-bin/. If login.relativeLink=on is
- * set, return only the empty string. Takes care of of non-root location of cgi-bin
- * and https. Result has to be free'd. */
-{
-boolean relativeLink = cfgOptionBooleanDefault(CFG_LOGIN_RELATIVE, FALSE);
-if (relativeLink)
-    return cloneString("");
-
-char *cgiDir = cgiScriptDirUrl();
-char buf[2048];
-char *hgLoginHost = cgiServerNamePort();
-safef(buf, sizeof(buf), "http%s://%s%s", cgiAppendSForHttps(), hgLoginHost, cgiDir);
-
-return cloneString(buf);
-}
-
 void wikiFixLogoutLinkWithJs()
 /* HTTP Basic Auth requires a strange hack to logout. This code prints a script 
  * that fixes an html link with id=logoutLink */
 {
 struct dyString *dy = dyStringNew(4096);
 // logoutJs.h is a stringified .js file
 #include "logoutJs.h"
 dyStringAppend(dy, cdwLogoutJs);
 dyStringPrintf(dy, "$('#logoutLink').click( function() { logout('/', 'http://cirm.ucsc.edu'); return false; });\n");
 jsInline(dy->string);
 dyStringFree(&dy);
 printf("<script src='//cdnjs.cloudflare.com/ajax/libs/bowser/1.6.1/bowser.min.js'></script>");
 }