69e67f69bea818d977ea3db5f97e58a77abdab4c galt Mon Apr 11 16:34:20 2016 -0700 Fixes #17163. It is now using regular hgBotDelay() in htmlOpen() and calling new function hgBotDelayNoWarn() in textOpen(). diff --git src/hg/lib/botDelay.c src/hg/lib/botDelay.c index 83d7de6..a42ae07 100644 --- src/hg/lib/botDelay.c +++ src/hg/lib/botDelay.c @@ -73,50 +73,53 @@ return user; } static char *getBotCheckString(char *ip) /* compose user.ip string for bot check */ { char *user = getCookieUser(); char *botCheckString = needMem(256); if (user) safef(botCheckString, 256, "%s.%s", user, ip); else safef(botCheckString, 256, "%s", ip); return botCheckString; } -void botDelayCgi(char *host, int port) +void botDelayCgi(char *host, int port, boolean noWarn) /* Connect with bottleneck server and sleep the * amount it suggests for IP address calling CGI script. */ { int millis; char *ip = getenv("REMOTE_ADDR"); if (ip != NULL) { char *botCheckString = getBotCheckString(ip); millis = botDelayTime(host, port, botCheckString); freeMem(botCheckString); if (millis > 0) { if (millis > 10000) { if (millis > 20000) botTerminateMessage(ip, millis); else + { + if (!noWarn) botDelayMessage(ip, millis); } + } sleep1000(millis); } } } boolean botException() /* check if the remote ip address is on the exceptions list */ { char *exceptIps = cfgOption("bottleneck.except"); if (exceptIps) { char *remoteAddr = getenv("REMOTE_ADDR"); if (remoteAddr) { char *s = exceptIps; @@ -126,42 +129,55 @@ char *e = strchr(s, ' '); if (e) *e = 0; if (sameString(remoteAddr, s)) found = TRUE; if (e) *e++ = ' '; s = e; } if (found) return TRUE; } } return FALSE; } -void hgBotDelay() + +static void hgBotDelayExt(boolean noWarn) /* High level bot delay call - looks up bottleneck server * in hg.conf. */ { if (botException()) return; char *host = cfgOption("bottleneck.host"); char *port = cfgOption("bottleneck.port"); if (host != NULL && port != NULL) - botDelayCgi(host, atoi(port)); + botDelayCgi(host, atoi(port), noWarn); +} + +void hgBotDelay() +/* High level bot delay call - for use with regular webpage output */ +{ +hgBotDelayExt(FALSE); +} + +void hgBotDelayNoWarn() +/* High level bot delay call without warning - for use with non-webpage outputs */ +{ +hgBotDelayExt(TRUE); } int hgBotDelayTime() /* Get suggested delay time from cgi. */ { char *ip = getenv("REMOTE_ADDR"); char *host = cfgOption("bottleneck.host"); char *port = cfgOption("bottleneck.port"); int delay = 0; if (host != NULL && port != NULL && ip != NULL) { char *botCheckString = getBotCheckString(ip); delay = botDelayTime(host, atoi(port), botCheckString); freeMem(botCheckString);