/* Create threads and get them to sit in their wait loop */
squidaio_thread_pool = memPoolCreate("aio_thread", sizeof(squidaio_thread_t));
- assert(NUMTHREADS);
+ assert(NUMTHREADS != 0);
for (i = 0; i < NUMTHREADS; ++i) {
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
virtual void timeout(const CommTimeoutCbParams &io);
void ftpAcceptDataConnection(const CommAcceptCbParams &io);
- static HttpReply *ftpAuthRequired(HttpRequest * request, const char *realm);
- const char *ftpRealm(void);
+ static HttpReply *ftpAuthRequired(HttpRequest * request, SBuf &realm);
+ SBuf ftpRealm();
void loginFailed(void);
virtual void haveParsedReplyHeaders();
{
if (!checkAuth(&request->header)) {
/* create appropriate reply */
- HttpReply *reply = ftpAuthRequired(request, ftpRealm());
+ SBuf realm(ftpRealm()); // local copy so SBuf wont disappear too early
+ HttpReply *reply = ftpAuthRequired(request, realm);
entry->replaceHttpReply(reply);
serverComplete();
return;
#if HAVE_AUTH_MODULE_BASIC
/* add Authenticate header */
- newrep->header.putAuth("Basic", ftpRealm());
+ // XXX: performance regression. c_str() may reallocate
+ SBuf realm(ftpRealm()); // local copy so SBuf wont disappear too early
+ newrep->header.putAuth("Basic", realm.c_str());
#endif
// add it to the store entry for response....
serverComplete();
}
-const char *
+SBuf
Ftp::Gateway::ftpRealm()
{
- static char realm[8192];
+ SBuf realm;
/* This request is not fully authenticated */
- if (!request) {
- snprintf(realm, 8192, "FTP %s unknown", user);
- } else if (request->port == 21) {
- snprintf(realm, 8192, "FTP %s %s", user, request->GetHost());
- } else {
- snprintf(realm, 8192, "FTP %s %s port %d", user, request->GetHost(), request->port);
+ realm.appendf("FTP %s ", user);
+ if (!request)
+ realm.append("unknown", 7);
+ else {
+ realm.append(request->GetHost());
+ if (request->port != 21)
+ realm.appendf(" port %d", request->port);
}
return realm;
}
}
HttpReply *
-Ftp::Gateway::ftpAuthRequired(HttpRequest * request, const char *realm)
+Ftp::Gateway::ftpAuthRequired(HttpRequest * request, SBuf &realm)
{
ErrorState err(ERR_CACHE_ACCESS_DENIED, Http::scUnauthorized, request);
HttpReply *newrep = err.BuildHttpReply();
#if HAVE_AUTH_MODULE_BASIC
/* add Authenticate header */
- newrep->header.putAuth("Basic", realm);
+ // XXX: performance regression. c_str() may reallocate
+ newrep->header.putAuth("Basic", realm.c_str());
#endif
return newrep;
}
char const *
fde::remoteAddr() const
{
- LOCAL_ARRAY(char, buf, MAX_IPSTRLEN );
+ static char buf[MAX_IPSTRLEN+7]; // 7 = length of ':port' strings
if (type != FD_SOCKET)
return null_string;
if ( *ipaddr )
- snprintf( buf, MAX_IPSTRLEN, "%s:%d", ipaddr, (int)remote_port);
+ snprintf(buf, sizeof(buf), "%s:%u", ipaddr, remote_port);
else
- local_addr.toUrl(buf,MAX_IPSTRLEN); // toHostStr does not include port.
+ local_addr.toUrl(buf, sizeof(buf)); // toHostStr does not include port.
return buf;
}
}
if (0 == in_dir) { /* we need to read in a new directory */
- snprintf(fullpath, MAXPATHLEN, "%s/%02X/%02X",
+ snprintf(fullpath, sizeof(fullpath), "%s/%02X/%02X",
sd->path,
curlvl1, curlvl2);
continue;
}
- snprintf(fullfilename, MAXPATHLEN, "%s/%s",
+ snprintf(fullfilename, sizeof(fullfilename), "%s/%s",
fullpath, entry->d_name);
debugs(47, 3, HERE << "Opening " << fullfilename);
fd = file_open(fullfilename, O_RDONLY | O_BINARY);
dirent_t *entry;
DIR *td;
char fullpath[MAXPATHLEN];
- char fullfilename[MAXPATHLEN];
+ char fullfilename[MAXPATHLEN*2];
StoreRebuildData counts;
* This will be called when request write is complete. Schedule read of reply.
*/
static void
-gopherSendComplete(const Comm::ConnectionPointer &conn, char *buf, size_t size, Comm::Flag errflag, int xerrno, void *data)
+gopherSendComplete(const Comm::ConnectionPointer &conn, char *, size_t size, Comm::Flag errflag, int xerrno, void *data)
{
GopherStateData *gopherState = (GopherStateData *) data;
StoreEntry *entry = gopherState->entry;
err->url = xstrdup(entry->url());
gopherState->fwd->fail(err);
gopherState->serverConn->close();
-
- if (buf)
- memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */
-
return;
}
AsyncCall::Pointer call = commCbCall(5,5, "gopherReadReply",
CommIoCbPtrFun(gopherReadReply, gopherState));
entry->delayAwareRead(conn, gopherState->replybuf, BUFSIZ, call);
-
- if (buf)
- memFree(buf, MEM_4K_BUF); /* Allocated by gopherSendRequest. */
}
/**
gopherSendRequest(int fd, void *data)
{
GopherStateData *gopherState = (GopherStateData *)data;
- char *buf = (char *)memAllocate(MEM_4K_BUF);
+ MemBuf mb;
+ mb.init();
if (gopherState->type_id == GOPHER_CSO) {
const char *t = strchr(gopherState->request, '?');
- if (t != NULL)
+ if (t)
++t; /* skip the ? */
else
t = "";
- snprintf(buf, 4096, "query %s\r\nquit\r\n", t);
- } else if (gopherState->type_id == GOPHER_INDEX) {
- char *t = strchr(gopherState->request, '?');
-
- if (t != NULL)
- *t = '\t';
-
- snprintf(buf, 4096, "%s\r\n", gopherState->request);
+ mb.Printf("query %s\r\nquit", t);
} else {
- snprintf(buf, 4096, "%s\r\n", gopherState->request);
+ if (gopherState->type_id == GOPHER_INDEX) {
+ if (char *t = strchr(gopherState->request, '?'))
+ *t = '\t';
+ }
+ mb.append(gopherState->request, strlen(gopherState->request));
}
+ mb.append("\r\n", 2);
- debugs(10, 5, HERE << gopherState->serverConn);
+ debugs(10, 5, gopherState->serverConn);
AsyncCall::Pointer call = commCbCall(5,5, "gopherSendComplete",
CommIoCbPtrFun(gopherSendComplete, gopherState));
- Comm::Write(gopherState->serverConn, buf, strlen(buf), call, NULL);
+ Comm::Write(gopherState->serverConn, &mb, call);
gopherState->entry->makePublic();
}
pinger_LDFLAGS = $(LIBADD_DL)
pinger_LDADD=\
libicmp-core.la \
- ../ip/libip.la \
+ $(top_builddir)/src/ip/libip.la \
+ $(top_builddir)/src/base/libbase.la \
$(COMPAT_LIB) \
$(XTRA_LIBS)