char const *
fde::remoteAddr() const
{
- static char buf[MAX_IPSTRLEN];
+ static char buf[MAX_IPSTRLEN+7]; // 7 = length of ':port' strings
*buf = 0;
if (type == FD_SOCKET) {
if (*ipaddr)
- snprintf(buf, MAX_IPSTRLEN, "%s:%u", ipaddr, 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);
* 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, 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.appendf("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();
}