static void send_announce(const ipcache_addrs * ia, void *junk) { LOCAL_ARRAY(char, tbuf, 256); LOCAL_ARRAY(char, sndbuf, BUFSIZ); struct sockaddr_in S; char *host = Config.Announce.host; char *file = NULL; u_short port = Config.Announce.port; int l; int n; int fd; int x; cbdataFree(junk); if (ia == NULL) { debug(27, 1) ("send_announce: Unknown host '%s'\n", host); return; } debug(27, 1) ("Sending Announcement to %s\n", host); sndbuf[0] = '\0'; snprintf(tbuf, 256, "cache_version SQUID/%s\n", version_string); strcat(sndbuf, tbuf); assert(Config.Sockaddr.http); snprintf(tbuf, 256, "Running on %s %d %d\n", getMyHostname(), (int) ntohs(Config.Sockaddr.http->s.sin_port), (int) Config.Port.icp); strcat(sndbuf, tbuf); if (Config.adminEmail) { snprintf(tbuf, 256, "cache_admin: %s\n", Config.adminEmail); strcat(sndbuf, tbuf); } snprintf(tbuf, 256, "generated %d [%s]\n", (int) squid_curtime, mkhttpdlogtime(&squid_curtime)); strcat(sndbuf, tbuf); l = strlen(sndbuf); if ((file = Config.Announce.file) != NULL) { fd = file_open(file, O_RDONLY); if (fd > -1 && (n = read(fd, sndbuf + l, BUFSIZ - l - 1)) > 0) { fd_bytes(fd, n, FD_READ); l += n; sndbuf[l] = '\0'; file_close(fd); } else { debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror()); } } memset(&S, '\0', sizeof(S)); S.sin_family = AF_INET; S.sin_port = htons(port); S.sin_addr = ia->in_addrs[0]; assert(theOutIcpConnection > 0); x = comm_udp_sendto(theOutIcpConnection, &S, sizeof(S), sndbuf, strlen(sndbuf) + 1); if (x < 0) debug(27, 1) ("send_announce: FD %d: %s\n", theOutIcpConnection, xstrerror()); }
void logUserAgent(const char *client, const char *agent) { #if USE_USERAGENT_LOG static time_t last_time = 0; static char time_str[128]; const char *s; if (!cache_useragent_log) return; if (squid_curtime != last_time) { s = mkhttpdlogtime(&squid_curtime); strcpy(time_str, s); last_time = squid_curtime; } fprintf(cache_useragent_log, "%s [%s] \"%s\"\n", client, time_str, agent); if (!Config.onoff.buffered_logs) fflush(cache_useragent_log); #endif }
static const char * errorConvert(char token, ErrorState * err) { request_t *r = err->request; static MemBuf mb = MemBufNULL; const char *p = NULL; /* takes priority over mb if set */ int do_quote = 1; memBufReset(&mb); switch (token) { case 'a': if (r && r->auth_user_request) p = authenticateUserRequestUsername(r->auth_user_request); if (!p) p = "-"; break; case 'B': p = r ? ftpUrlWith2f(r) : "[no URL]"; break; case 'c': p = errorPageName(err->type); break; case 'e': memBufPrintf(&mb, "%d", err->xerrno); break; case 'E': if (err->xerrno) memBufPrintf(&mb, "(%d) %s", err->xerrno, strerror(err->xerrno)); else memBufPrintf(&mb, "[No Error]"); break; case 'f': /* FTP REQUEST LINE */ if (err->ftp.request) p = err->ftp.request; else p = "nothing"; break; case 'F': /* FTP REPLY LINE */ if (err->ftp.request) p = err->ftp.reply; else p = "nothing"; break; case 'g': /* FTP SERVER MESSAGE */ wordlistCat(err->ftp.server_msg, &mb); break; case 'h': memBufPrintf(&mb, "%s", getMyHostname()); break; case 'H': if (r) { if (r->hier.host) p = r->hier.host; else p = r->host; } else p = "[unknown host]"; break; case 'i': memBufPrintf(&mb, "%s", inet_ntoa(err->src_addr)); break; case 'I': if (r && r->hier.host) { memBufPrintf(&mb, "%s", r->hier.host); } else p = "[unknown]"; break; case 'L': if (Config.errHtmlText) { memBufPrintf(&mb, "%s", Config.errHtmlText); do_quote = 0; } else p = "[not available]"; break; case 'm': p = authenticateAuthUserRequestMessage(err->auth_user_request) ? authenticateAuthUserRequestMessage(err->auth_user_request) : "[not available]"; break; case 'M': p = r ? RequestMethods[r->method].str : "[unknown method]"; break; case 'o': p = external_acl_message; if (!p) p = "[not available]"; break; case 'p': if (r) { memBufPrintf(&mb, "%d", (int) r->port); } else { p = "[unknown port]"; } break; case 'P': p = r ? ProtocolStr[r->protocol] : "[unkown protocol]"; break; case 'R': if (NULL != r) { Packer p; memBufPrintf(&mb, "%s %s HTTP/%d.%d\n", RequestMethods[r->method].str, strLen(r->urlpath) ? strBuf(r->urlpath) : "/", r->http_ver.major, r->http_ver.minor); packerToMemInit(&p, &mb); httpHeaderPackInto(&r->header, &p); packerClean(&p); } else if (err->request_hdrs) { p = err->request_hdrs; } else { p = "[no request]"; } break; case 's': p = visible_appname_string; break; case 'S': /* signature may contain %-escapes, recursion */ if (err->page_id != ERR_SQUID_SIGNATURE) { const int saved_id = err->page_id; MemBuf sign_mb; err->page_id = ERR_SQUID_SIGNATURE; sign_mb = errorBuildContent(err); memBufPrintf(&mb, "%s", sign_mb.buf); memBufClean(&sign_mb); err->page_id = saved_id; do_quote = 0; } else { /* wow, somebody put %S into ERR_SIGNATURE, stop recursion */ p = "[%S]"; } break; case 't': memBufPrintf(&mb, "%s", mkhttpdlogtime(&squid_curtime)); break; case 'T': memBufPrintf(&mb, "%s", mkrfc1123(squid_curtime)); break; case 'U': p = r ? urlCanonicalClean(r) : err->url ? err->url : "[no URL]"; break; case 'u': p = r ? urlCanonical(r) : err->url ? err->url : "[no URL]"; break; case 'w': if (Config.adminEmail) memBufPrintf(&mb, "%s", Config.adminEmail); else p = "[unknown]"; break; case 'z': if (err->dnsserver_msg) p = err->dnsserver_msg; else p = "[unknown]"; break; case '%': p = "%"; break; default: memBufPrintf(&mb, "%%%c", token); do_quote = 0; break; } if (!p) p = mb.buf; /* do not use mb after this assignment! */ assert(p); debug(4, 3) ("errorConvert: %%%c --> '%s'\n", token, p); if (do_quote) p = html_quote(p); return p; }
static void dump_peers(StoreEntry * sentry, peer * peers) { peer *e = NULL; struct _domain_ping *d = NULL; icp_opcode op; int i; if (peers == NULL) storeAppendPrintf(sentry, "There are no neighbors installed.\n"); for (e = peers; e; e = e->next) { assert(e->host != NULL); storeAppendPrintf(sentry, "\n%-11.11s: %s\n", neighborTypeStr(e), e->name); storeAppendPrintf(sentry, "Host : %s/%d/%d\n", e->host, e->http_port, e->icp.port); storeAppendPrintf(sentry, "Flags :"); dump_peer_options(sentry, e); for (i = 0; i < e->n_addresses; i++) { storeAppendPrintf(sentry, "Address[%d] : %s\n", i, inet_ntoa(e->addresses[i])); } storeAppendPrintf(sentry, "Status : %s\n", neighborUp(e) ? "Up" : "Down"); storeAppendPrintf(sentry, "AVG RTT : %d msec\n", e->stats.rtt); storeAppendPrintf(sentry, "OPEN CONNS : %d\n", e->stats.conn_open); if (!e->options.no_query) { storeAppendPrintf(sentry, "LAST QUERY : %8d seconds ago\n", (int) (squid_curtime - e->stats.last_query)); if (e->stats.last_reply > 0) storeAppendPrintf(sentry, "LAST REPLY : %8d seconds ago\n", (int) (squid_curtime - e->stats.last_reply)); else storeAppendPrintf(sentry, "LAST REPLY : none received\n"); storeAppendPrintf(sentry, "PINGS SENT : %8d\n", e->stats.pings_sent); storeAppendPrintf(sentry, "PINGS ACKED: %8d %3d%%\n", e->stats.pings_acked, percent(e->stats.pings_acked, e->stats.pings_sent)); } storeAppendPrintf(sentry, "FETCHES : %8d %3d%%\n", e->stats.fetches, percent(e->stats.fetches, e->stats.pings_acked)); storeAppendPrintf(sentry, "IGNORED : %8d %3d%%\n", e->stats.ignored_replies, percent(e->stats.ignored_replies, e->stats.pings_acked)); if (!e->options.no_query) { storeAppendPrintf(sentry, "Histogram of PINGS ACKED:\n"); #if USE_HTCP if (e->options.htcp) { storeAppendPrintf(sentry, "\tMisses\t%8d %3d%%\n", e->htcp.counts[0], percent(e->htcp.counts[0], e->stats.pings_acked)); storeAppendPrintf(sentry, "\tHits\t%8d %3d%%\n", e->htcp.counts[1], percent(e->htcp.counts[1], e->stats.pings_acked)); } else { #endif for (op = ICP_INVALID; op < ICP_END; op++) { if (e->icp.counts[op] == 0) continue; storeAppendPrintf(sentry, " %12.12s : %8d %3d%%\n", icp_opcode_str[op], e->icp.counts[op], percent(e->icp.counts[op], e->stats.pings_acked)); } #if USE_HTCP } #endif } if (e->stats.last_connect_failure) { storeAppendPrintf(sentry, "Last failed connect() at: %s\n", mkhttpdlogtime(&(e->stats.last_connect_failure))); } if (e->peer_domain != NULL) { storeAppendPrintf(sentry, "DOMAIN LIST: "); for (d = e->peer_domain; d; d = d->next) { storeAppendPrintf(sentry, "%s%s ", d->do_ping ? null_string : "!", d->domain); } storeAppendPrintf(sentry, "\n"); } storeAppendPrintf(sentry, "keep-alive ratio: %d%%\n", percent(e->stats.n_keepalives_recv, e->stats.n_keepalives_sent)); } }