From 4391cd1518d101223e810f8e5e620c871b535245 Mon Sep 17 00:00:00 2001 From: Amos Jeffries Date: Wed, 4 Mar 2015 22:44:43 -0800 Subject: [PATCH] Rename Packable::Printf as Packable::appendf It performs append semantics not replace semantics, and this also paves the way for SBuf integration. --- src/BodyPipe.cc | 12 ++-- src/HttpHdrCc.cc | 13 ++-- src/HttpHdrContRange.cc | 9 ++- src/HttpHdrRange.cc | 8 +-- src/HttpHdrSc.cc | 8 +-- src/HttpRequest.cc | 14 ++--- src/MemBuf.cc | 2 +- src/MemObject.cc | 24 +++---- src/acl/AllOf.cc | 4 +- src/acl/Gadgets.cc | 6 +- src/adaptation/icap/ModXact.cc | 49 +++++++-------- src/adaptation/icap/OptXact.cc | 8 +-- src/adaptation/icap/ServiceRep.cc | 2 +- src/adaptation/icap/Xaction.cc | 12 ++-- src/base/AsyncJob.cc | 5 +- src/base/Packable.h | 14 ++++- src/client_side.cc | 8 +-- src/clients/FtpClient.cc | 16 ++--- src/clients/FtpGateway.cc | 6 +- src/comm/TcpAcceptor.cc | 2 +- src/errorpage.cc | 100 +++++++++++++++--------------- src/external_acl.cc | 4 +- src/format/Format.cc | 4 +- src/helper.cc | 2 +- src/http.cc | 14 ++--- src/http/StatusLine.cc | 4 +- src/ident/Ident.cc | 2 +- src/internal.cc | 9 ++- src/ipc/Inquirer.cc | 2 +- src/mime.cc | 2 +- src/servers/FtpServer.cc | 30 ++++----- src/stat.cc | 18 +++--- src/store_client.cc | 21 +++---- src/tunnel.cc | 2 +- src/urn.cc | 13 ++-- src/wordlist.cc | 2 +- 36 files changed, 217 insertions(+), 234 deletions(-) diff --git a/src/BodyPipe.cc b/src/BodyPipe.cc index 7731bf05bb..58c7d0853e 100644 --- a/src/BodyPipe.cc +++ b/src/BodyPipe.cc @@ -444,19 +444,19 @@ const char *BodyPipe::status() const outputBuffer.append(" [", 2); - outputBuffer.Printf("%" PRIu64 "<=%" PRIu64, theGetSize, thePutSize); + outputBuffer.appendf("%" PRIu64 "<=%" PRIu64, theGetSize, thePutSize); if (theBodySize >= 0) - outputBuffer.Printf("<=%" PRId64, theBodySize); + outputBuffer.appendf("<=%" PRId64, theBodySize); else outputBuffer.append("<=?", 3); - outputBuffer.Printf(" %d+%d", (int)theBuf.contentSize(), (int)theBuf.spaceSize()); + outputBuffer.appendf(" %u+%u", theBuf.contentSize(), theBuf.spaceSize()); - outputBuffer.Printf(" pipe%p", this); + outputBuffer.appendf(" pipe%p", this); if (theProducer.set()) - outputBuffer.Printf(" prod%p", theProducer.get()); + outputBuffer.appendf(" prod%p", theProducer.get()); if (theConsumer.set()) - outputBuffer.Printf(" cons%p", theConsumer.get()); + outputBuffer.appendf(" cons%p", theConsumer.get()); if (mustAutoConsume) outputBuffer.append(" A", 2); diff --git a/src/HttpHdrCc.cc b/src/HttpHdrCc.cc index 27ba1559ae..3071e30673 100644 --- a/src/HttpHdrCc.cc +++ b/src/HttpHdrCc.cc @@ -265,24 +265,24 @@ HttpHdrCc::packInto(Packable * p) const if (isSet(flag) && flag != CC_OTHER) { /* print option name for all options */ - p->Printf((pcount ? ", %s": "%s") , CcAttrs[flag].name); + p->appendf((pcount ? ", %s": "%s") , CcAttrs[flag].name); /* for all options having values, "=value" after the name */ switch (flag) { case CC_MAX_AGE: - p->Printf("=%d", (int) maxAge()); + p->appendf("=%d", maxAge()); break; case CC_S_MAXAGE: - p->Printf("=%d", (int) sMaxAge()); + p->appendf("=%d", sMaxAge()); break; case CC_MAX_STALE: /* max-stale's value is optional. If we didn't receive it, don't send it */ if (maxStale()!=MAX_STALE_ANY) - p->Printf("=%d", (int) maxStale()); + p->appendf("=%d", maxStale()); break; case CC_MIN_FRESH: - p->Printf("=%d", (int) minFresh()); + p->appendf("=%d", minFresh()); break; default: /* do nothing, directive was already printed */ @@ -294,8 +294,7 @@ HttpHdrCc::packInto(Packable * p) const } if (other.size() != 0) - p->Printf((pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH), - SQUIDSTRINGPRINT(other)); + p->appendf((pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH), SQUIDSTRINGPRINT(other)); } void diff --git a/src/HttpHdrContRange.cc b/src/HttpHdrContRange.cc index bee649c619..c89c20f0a4 100644 --- a/src/HttpHdrContRange.cc +++ b/src/HttpHdrContRange.cc @@ -104,10 +104,9 @@ httpHdrRangeRespSpecPackInto(const HttpHdrRangeSpec * spec, Packable * p) assert (spec->length >= 0); if (!known_spec(spec->offset) || !known_spec(spec->length)) - p->Printf("*"); + p->append("*", 1); else - p->Printf("bytes %" PRId64 "-%" PRId64, - spec->offset, spec->offset + spec->length - 1); + p->appendf("bytes %" PRId64 "-%" PRId64, spec->offset, spec->offset + spec->length - 1); } /* @@ -208,9 +207,9 @@ httpHdrContRangePackInto(const HttpHdrContRange * range, Packable * p) assert (range->elength >= 0); if (!known_spec(range->elength)) - p->Printf("/*"); + p->append("/*", 2); else - p->Printf("/%" PRId64, range->elength); + p->appendf("/%" PRId64, range->elength); } void diff --git a/src/HttpHdrRange.cc b/src/HttpHdrRange.cc index eea85b1544..3d14063fbe 100644 --- a/src/HttpHdrRange.cc +++ b/src/HttpHdrRange.cc @@ -105,14 +105,14 @@ HttpHdrRangeSpec::parseInit(const char *field, int flen) } void -HttpHdrRangeSpec::packInto(Packable * packer) const +HttpHdrRangeSpec::packInto(Packable * p) const { if (!known_spec(offset)) /* suffix */ - packer->Printf("-%" PRId64, length); + p->appendf("-%" PRId64, length); else if (!known_spec(length)) /* trailer */ - packer->Printf("%" PRId64 "-", offset); + p->appendf("%" PRId64 "-", offset); else /* range */ - packer->Printf("%" PRId64 "-%" PRId64, offset, offset + length - 1); + p->appendf("%" PRId64 "-%" PRId64, offset, offset + length - 1); } void diff --git a/src/HttpHdrSc.cc b/src/HttpHdrSc.cc index f165ff613c..e233bb47c6 100644 --- a/src/HttpHdrSc.cc +++ b/src/HttpHdrSc.cc @@ -245,23 +245,23 @@ HttpHdrScTarget::packInto(Packable * p) const if (isSet(flag) && flag != SC_OTHER) { /* print option name */ - p->Printf((pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH), + p->appendf((pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH), SQUIDSTRINGPRINT(ScFieldsInfo[flag].name)); /* handle options with values */ if (flag == SC_MAX_AGE) - p->Printf("=%d", (int) max_age); + p->appendf("=%d", (int) max_age); if (flag == SC_CONTENT) - p->Printf("=\"" SQUIDSTRINGPH "\"", SQUIDSTRINGPRINT(content_)); + p->appendf("=\"" SQUIDSTRINGPH "\"", SQUIDSTRINGPRINT(content_)); ++pcount; } } if (hasTarget()) - p->Printf(";" SQUIDSTRINGPH, SQUIDSTRINGPRINT(target)); + p->appendf(";" SQUIDSTRINGPH, SQUIDSTRINGPRINT(target)); } void diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index b0497b18e3..ba23573504 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -377,9 +377,9 @@ HttpRequest::pack(Packable * p) { assert(p); /* pack request-line */ - p->Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " HTTP/%d.%d\r\n", - SQUIDSBUFPRINT(method.image()), SQUIDSTRINGPRINT(urlpath), - http_ver.major, http_ver.minor); + p->appendf(SQUIDSBUFPH " " SQUIDSTRINGPH " HTTP/%d.%d\r\n", + SQUIDSBUFPRINT(method.image()), SQUIDSTRINGPRINT(urlpath), + http_ver.major, http_ver.minor); /* headers */ header.packInto(p); /* trailer */ @@ -510,10 +510,10 @@ const char *HttpRequest::packableURI(bool full_uri) const void HttpRequest::packFirstLineInto(Packable * p, bool full_uri) const { // form HTTP request-line - p->Printf(SQUIDSBUFPH " %s HTTP/%d.%d\r\n", - SQUIDSBUFPRINT(method.image()), - packableURI(full_uri), - http_ver.major, http_ver.minor); + p->appendf(SQUIDSBUFPH " %s HTTP/%d.%d\r\n", + SQUIDSBUFPRINT(method.image()), + packableURI(full_uri), + http_ver.major, http_ver.minor); } /* diff --git a/src/MemBuf.cc b/src/MemBuf.cc index 272adb9b3c..d739702c5f 100644 --- a/src/MemBuf.cc +++ b/src/MemBuf.cc @@ -387,6 +387,6 @@ void memBufReport(MemBuf * mb) { assert(mb); - mb->Printf("memBufReport is not yet implemented @?@\n"); + mb->appendf("memBufReport is not yet implemented @?@\n"); } diff --git a/src/MemObject.cc b/src/MemObject.cc index 8d62a1d31e..559269db2e 100644 --- a/src/MemObject.cc +++ b/src/MemObject.cc @@ -220,28 +220,24 @@ struct StoreClientStats : public unary_function { void MemObject::stat(MemBuf * mb) const { - mb->Printf("\t" SQUIDSBUFPH " %s\n", SQUIDSBUFPRINT(method.image()), logUri()); + mb->appendf("\t" SQUIDSBUFPH " %s\n", SQUIDSBUFPRINT(method.image()), logUri()); if (vary_headers) - mb->Printf("\tvary_headers: %s\n", vary_headers); - mb->Printf("\tinmem_lo: %" PRId64 "\n", inmem_lo); - mb->Printf("\tinmem_hi: %" PRId64 "\n", data_hdr.endOffset()); - mb->Printf("\tswapout: %" PRId64 " bytes queued\n", - swapout.queue_offset); + mb->appendf("\tvary_headers: %s\n", vary_headers); + mb->appendf("\tinmem_lo: %" PRId64 "\n", inmem_lo); + mb->appendf("\tinmem_hi: %" PRId64 "\n", data_hdr.endOffset()); + mb->appendf("\tswapout: %" PRId64 " bytes queued\n", swapout.queue_offset); if (swapout.sio.getRaw()) - mb->Printf("\tswapout: %" PRId64 " bytes written\n", - (int64_t) swapout.sio->offset()); + mb->appendf("\tswapout: %" PRId64 " bytes written\n", (int64_t) swapout.sio->offset()); if (xitTable.index >= 0) - mb->Printf("\ttransient index: %d state: %d\n", - xitTable.index, xitTable.io); + mb->appendf("\ttransient index: %d state: %d\n", xitTable.index, xitTable.io); if (memCache.index >= 0) - mb->Printf("\tmem-cache index: %d state: %d offset: %" PRId64 "\n", - memCache.index, memCache.io, memCache.offset); + mb->appendf("\tmem-cache index: %d state: %d offset: %" PRId64 "\n", memCache.index, memCache.io, memCache.offset); if (object_sz >= 0) - mb->Printf("\tobject_sz: %" PRId64 "\n", object_sz); + mb->appendf("\tobject_sz: %" PRId64 "\n", object_sz); if (smpCollapsed) - mb->Printf("\tsmp-collapsed\n"); + mb->appendf("\tsmp-collapsed\n"); StoreClientStats statsVisitor(mb); diff --git a/src/acl/AllOf.cc b/src/acl/AllOf.cc index a60dfb0fc5..e5ab27a946 100644 --- a/src/acl/AllOf.cc +++ b/src/acl/AllOf.cc @@ -62,7 +62,7 @@ Acl::AllOf::parse() MemBuf wholeCtx; wholeCtx.init(); - wholeCtx.Printf("(%s lines)", name); + wholeCtx.appendf("(%s lines)", name); wholeCtx.terminate(); Acl::OrNode *newWhole = new Acl::OrNode; @@ -79,7 +79,7 @@ Acl::AllOf::parse() MemBuf lineCtx; lineCtx.init(); - lineCtx.Printf("(%s line #%d)", name, lineId); + lineCtx.appendf("(%s line #%d)", name, lineId); lineCtx.terminate(); Acl::AndNode *line = new AndNode; diff --git a/src/acl/Gadgets.cc b/src/acl/Gadgets.cc index d42db5db9f..9d39813aac 100644 --- a/src/acl/Gadgets.cc +++ b/src/acl/Gadgets.cc @@ -172,7 +172,7 @@ aclParseAccessLine(const char *directive, ConfigParser &, acl_access **treep) const int ruleId = ((treep && *treep) ? (*treep)->childrenCount() : 0) + 1; MemBuf ctxBuf; ctxBuf.init(); - ctxBuf.Printf("%s#%d", directive, ruleId); + ctxBuf.appendf("%s#%d", directive, ruleId); ctxBuf.terminate(); Acl::AndNode *rule = new Acl::AndNode; @@ -208,7 +208,7 @@ aclParseAclList(ConfigParser &, Acl::Tree **treep, const char *label) MemBuf ctxLine; ctxLine.init(); - ctxLine.Printf("(%s %s line)", cfg_directive, label); + ctxLine.appendf("(%s %s line)", cfg_directive, label); ctxLine.terminate(); Acl::AndNode *rule = new Acl::AndNode; @@ -217,7 +217,7 @@ aclParseAclList(ConfigParser &, Acl::Tree **treep, const char *label) MemBuf ctxTree; ctxTree.init(); - ctxTree.Printf("%s %s", cfg_directive, label); + ctxTree.appendf("%s %s", cfg_directive, label); ctxTree.terminate(); // We want a cbdata-protected Tree (despite giving it only one child node). diff --git a/src/adaptation/icap/ModXact.cc b/src/adaptation/icap/ModXact.cc index a386ca60dd..4fbd474155 100644 --- a/src/adaptation/icap/ModXact.cc +++ b/src/adaptation/icap/ModXact.cc @@ -375,7 +375,7 @@ void Adaptation::Icap::ModXact::addLastRequestChunk(MemBuf &buf) void Adaptation::Icap::ModXact::openChunk(MemBuf &buf, size_t chunkSize, bool ieof) { - buf.Printf((ieof ? "%x; ieof\r\n" : "%x\r\n"), (int) chunkSize); + buf.appendf((ieof ? "%x; ieof\r\n" : "%x\r\n"), (int) chunkSize); } void Adaptation::Icap::ModXact::closeChunk(MemBuf &buf) @@ -1334,12 +1334,12 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) * XXX These should use HttpHdr interfaces instead of Printfs */ const Adaptation::ServiceConfig &s = service().cfg(); - buf.Printf("%s " SQUIDSTRINGPH " ICAP/1.0\r\n", s.methodStr(), SQUIDSTRINGPRINT(s.uri)); - buf.Printf("Host: " SQUIDSTRINGPH ":%d\r\n", SQUIDSTRINGPRINT(s.host), s.port); - buf.Printf("Date: %s\r\n", mkrfc1123(squid_curtime)); + buf.appendf("%s " SQUIDSTRINGPH " ICAP/1.0\r\n", s.methodStr(), SQUIDSTRINGPRINT(s.uri)); + buf.appendf("Host: " SQUIDSTRINGPH ":%d\r\n", SQUIDSTRINGPRINT(s.host), s.port); + buf.appendf("Date: %s\r\n", mkrfc1123(squid_curtime)); if (!TheConfig.reuse_connections) - buf.Printf("Connection: close\r\n"); + buf.appendf("Connection: close\r\n"); const HttpRequest *request = &virginRequest(); @@ -1347,12 +1347,12 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) // as ICAP headers. if (virgin.header->header.has(HDR_PROXY_AUTHENTICATE)) { String vh=virgin.header->header.getByName("Proxy-Authenticate"); - buf.Printf("Proxy-Authenticate: " SQUIDSTRINGPH "\r\n",SQUIDSTRINGPRINT(vh)); + buf.appendf("Proxy-Authenticate: " SQUIDSTRINGPH "\r\n",SQUIDSTRINGPRINT(vh)); } if (virgin.header->header.has(HDR_PROXY_AUTHORIZATION)) { String vh=virgin.header->header.getByName("Proxy-Authorization"); - buf.Printf("Proxy-Authorization: " SQUIDSTRINGPH "\r\n", SQUIDSTRINGPRINT(vh)); + buf.appendf("Proxy-Authorization: " SQUIDSTRINGPH "\r\n", SQUIDSTRINGPRINT(vh)); } else if (request->extacl_user.size() > 0 && request->extacl_passwd.size() > 0) { struct base64_encode_ctx ctx; base64_encode_init(&ctx); @@ -1361,7 +1361,7 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) resultLen += base64_encode_update(&ctx, base64buf+resultLen, 1, reinterpret_cast(":")); resultLen += base64_encode_update(&ctx, base64buf+resultLen, request->extacl_passwd.size(), reinterpret_cast(request->extacl_passwd.rawBuf())); resultLen += base64_encode_final(&ctx, base64buf+resultLen); - buf.Printf("Proxy-Authorization: Basic %.*s\r\n", (int)resultLen, base64buf); + buf.appendf("Proxy-Authorization: Basic %.*s\r\n", (int)resultLen, base64buf); } // share the cross-transactional database records if needed @@ -1370,13 +1370,12 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) if (ah != NULL) { String name, value; if (ah->getXxRecord(name, value)) { - buf.Printf(SQUIDSTRINGPH ": " SQUIDSTRINGPH "\r\n", - SQUIDSTRINGPRINT(name), SQUIDSTRINGPRINT(value)); + buf.appendf(SQUIDSTRINGPH ": " SQUIDSTRINGPH "\r\n", SQUIDSTRINGPRINT(name), SQUIDSTRINGPRINT(value)); } } } - buf.Printf("Encapsulated: "); + buf.append("Encapsulated: ", 14); MemBuf httpBuf; @@ -1401,16 +1400,16 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) encapsulateHead(buf, "res-hdr", httpBuf, prime); if (!virginBody.expected()) - buf.Printf("null-body=%d", (int) httpBuf.contentSize()); + buf.appendf("null-body=%d", (int) httpBuf.contentSize()); else if (ICAP::methodReqmod == m) - buf.Printf("req-body=%d", (int) httpBuf.contentSize()); + buf.appendf("req-body=%d", (int) httpBuf.contentSize()); else - buf.Printf("res-body=%d", (int) httpBuf.contentSize()); + buf.appendf("res-body=%d", (int) httpBuf.contentSize()); buf.append(ICAP::crlf, 2); // terminate Encapsulated line if (preview.enabled()) { - buf.Printf("Preview: %d\r\n", (int)preview.ad()); + buf.appendf("Preview: %d\r\n", (int)preview.ad()); if (!virginBody.expected()) // there is no body to preview finishNullOrEmptyBodyPreview(httpBuf); } @@ -1426,7 +1425,7 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) #endif client_addr = request->client_addr; if (!client_addr.isAnyAddr() && !client_addr.isNoAddr()) - buf.Printf("X-Client-IP: %s\r\n", client_addr.toStr(ntoabuf,MAX_IPSTRLEN)); + buf.appendf("X-Client-IP: %s\r\n", client_addr.toStr(ntoabuf,MAX_IPSTRLEN)); } if (TheConfig.send_username && request) @@ -1442,7 +1441,7 @@ void Adaptation::Icap::ModXact::makeRequestHeaders(MemBuf &buf) HttpReply *reply = dynamic_cast(virgin.header); if (const char *value = (*i)->match(r, reply, alMaster)) { - buf.Printf("%s: %s\r\n", (*i)->key.termedBuf(), value); + buf.appendf("%s: %s\r\n", (*i)->key.termedBuf(), value); Adaptation::History::Pointer ah = request->adaptHistory(false); if (ah != NULL) { if (ah->metaHeaders == NULL) @@ -1522,9 +1521,9 @@ void Adaptation::Icap::ModXact::makeUsernameHeader(const HttpRequest *request, M uint8_t base64buf[base64_encode_len(MAX_LOGIN_SZ)]; size_t resultLen = base64_encode_update(&ctx, base64buf, strlen(value), reinterpret_cast(value)); resultLen += base64_encode_final(&ctx, base64buf+resultLen); - buf.Printf("%s: %.*s\r\n", TheConfig.client_username_header, (int)resultLen, base64buf); + buf.appendf("%s: %.*s\r\n", TheConfig.client_username_header, (int)resultLen, base64buf); } else - buf.Printf("%s: %s\r\n", TheConfig.client_username_header, value); + buf.appendf("%s: %s\r\n", TheConfig.client_username_header, value); } #endif } @@ -1532,7 +1531,7 @@ void Adaptation::Icap::ModXact::makeUsernameHeader(const HttpRequest *request, M void Adaptation::Icap::ModXact::encapsulateHead(MemBuf &icapBuf, const char *section, MemBuf &httpBuf, const HttpMsg *head) { // update ICAP header - icapBuf.Printf("%s=%d, ", section, (int) httpBuf.contentSize()); + icapBuf.appendf("%s=%d, ", section, (int) httpBuf.contentSize()); // begin cloning HttpMsg::Pointer headClone; @@ -1699,21 +1698,21 @@ void Adaptation::Icap::ModXact::fillPendingStatus(MemBuf &buf) const buf.append("r", 1); if (!state.doneWriting() && state.writing != State::writingInit) - buf.Printf("w(%d)", state.writing); + buf.appendf("w(%d)", state.writing); if (preview.enabled()) { if (!preview.done()) - buf.Printf("P(%d)", (int) preview.debt()); + buf.appendf("P(%d)", (int) preview.debt()); } if (virginBodySending.active()) buf.append("B", 1); if (!state.doneParsing() && state.parsing != State::psIcapHeader) - buf.Printf("p(%d)", state.parsing); + buf.appendf("p(%d)", state.parsing); if (!doneSending() && state.sending != State::sendingUndecided) - buf.Printf("S(%d)", state.sending); + buf.appendf("S(%d)", state.sending); if (state.readyForUob) buf.append("6", 1); @@ -1737,7 +1736,7 @@ void Adaptation::Icap::ModXact::fillDoneStatus(MemBuf &buf) const if (preview.enabled()) { if (preview.done()) - buf.Printf("P%s", preview.ieof() ? "(ieof)" : ""); + buf.appendf("P%s", preview.ieof() ? "(ieof)" : ""); } if (doneReading()) diff --git a/src/adaptation/icap/OptXact.cc b/src/adaptation/icap/OptXact.cc index 103b2968fb..3400e56e07 100644 --- a/src/adaptation/icap/OptXact.cc +++ b/src/adaptation/icap/OptXact.cc @@ -54,15 +54,15 @@ void Adaptation::Icap::OptXact::makeRequest(MemBuf &buf) { const Adaptation::Service &s = service(); const String uri = s.cfg().uri; - buf.Printf("OPTIONS " SQUIDSTRINGPH " ICAP/1.0\r\n", SQUIDSTRINGPRINT(uri)); + buf.appendf("OPTIONS " SQUIDSTRINGPH " ICAP/1.0\r\n", SQUIDSTRINGPRINT(uri)); const String host = s.cfg().host; - buf.Printf("Host: " SQUIDSTRINGPH ":%d\r\n", SQUIDSTRINGPRINT(host), s.cfg().port); + buf.appendf("Host: " SQUIDSTRINGPH ":%d\r\n", SQUIDSTRINGPRINT(host), s.cfg().port); if (!TheConfig.reuse_connections) - buf.Printf("Connection: close\r\n"); + buf.append("Connection: close\r\n", 19); if (TheConfig.allow206_enable) - buf.Printf("Allow: 206\r\n"); + buf.append("Allow: 206\r\n", 12); buf.append(ICAP::crlf, 2); // XXX: HttpRequest cannot fully parse ICAP Request-Line diff --git a/src/adaptation/icap/ServiceRep.cc b/src/adaptation/icap/ServiceRep.cc index 0c8053e9da..f52be80120 100644 --- a/src/adaptation/icap/ServiceRep.cc +++ b/src/adaptation/icap/ServiceRep.cc @@ -698,7 +698,7 @@ const char *Adaptation::Icap::ServiceRep::status() const buf.append(",notif", 6); if (const int failures = theSessionFailures.remembered()) - buf.Printf(",fail%d", failures); + buf.appendf(",fail%d", failures); buf.append("]", 1); buf.terminate(); diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index ada97ce687..302b9808ac 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -591,15 +591,11 @@ const char *Adaptation::Icap::Xaction::status() const { static MemBuf buf; buf.reset(); - buf.append(" [", 2); - fillPendingStatus(buf); buf.append("/", 1); fillDoneStatus(buf); - - buf.Printf(" %s%u]", id.Prefix, id.value); - + buf.appendf(" %s%u]", id.Prefix, id.value); buf.terminate(); return buf.content(); @@ -608,7 +604,7 @@ const char *Adaptation::Icap::Xaction::status() const void Adaptation::Icap::Xaction::fillPendingStatus(MemBuf &buf) const { if (haveConnection()) { - buf.Printf("FD %d", connection->fd); + buf.appendf("FD %d", connection->fd); if (writer != NULL) buf.append("w", 1); @@ -623,10 +619,10 @@ void Adaptation::Icap::Xaction::fillPendingStatus(MemBuf &buf) const void Adaptation::Icap::Xaction::fillDoneStatus(MemBuf &buf) const { if (haveConnection() && commEof) - buf.Printf("Comm(%d)", connection->fd); + buf.appendf("Comm(%d)", connection->fd); if (stopReason != NULL) - buf.Printf("Stopped"); + buf.append("Stopped", 7); } bool Adaptation::Icap::Xaction::fillVirginHttpHeader(MemBuf &) const diff --git a/src/base/AsyncJob.cc b/src/base/AsyncJob.cc index d78a881291..f073d6c1ba 100644 --- a/src/base/AsyncJob.cc +++ b/src/base/AsyncJob.cc @@ -162,10 +162,9 @@ const char *AsyncJob::status() const buf.append(" [", 2); if (stopReason != NULL) { - buf.Printf("Stopped, reason:"); - buf.Printf("%s",stopReason); + buf.appendf("Stopped, reason:%s", stopReason); } - buf.Printf(" %s%u]", id.Prefix, id.value); + buf.appendf(" %s%u]", id.Prefix, id.value); buf.terminate(); return buf.content(); diff --git a/src/base/Packable.h b/src/base/Packable.h index a0c559b5d2..fd1dc01ad0 100644 --- a/src/base/Packable.h +++ b/src/base/Packable.h @@ -52,9 +52,16 @@ public: /// Appends a c-string to existing packed data. virtual void append(const char *buf, int size) = 0; - /** - * Append operation with printf-style arguments. - * + /// Append operation with printf-style arguments. + void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2 + { + va_list args; + va_start(args, fmt); + vappendf(fmt, args); + va_end(args); + } +#if 0 + /* * \note we use Printf instead of printf so the compiler won't * think we're calling the libc printf() */ @@ -65,6 +72,7 @@ public: vappendf(fmt, args); va_end(args); } +#endif /** Append operation, with vsprintf(3)-style arguments. * diff --git a/src/client_side.cc b/src/client_side.cc index 4bfdde95db..455e2a861f 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1032,16 +1032,16 @@ ClientSocketContext::packChunk(const StoreIOBuffer &bodyData, MemBuf &mb) static_cast(lengthToSend(bodyData.range())); noteSentBodyBytes(length); - mb.Printf("%" PRIX64 "\r\n", length); + mb.appendf("%" PRIX64 "\r\n", length); mb.append(bodyData.data, length); - mb.Printf("\r\n"); + mb.append("\r\n", 2); } /** put terminating boundary for multiparts */ static void clientPackTermBound(String boundary, MemBuf * mb) { - mb->Printf("\r\n--" SQUIDSTRINGPH "--\r\n", SQUIDSTRINGPRINT(boundary)); + mb->appendf("\r\n--" SQUIDSTRINGPH "--\r\n", SQUIDSTRINGPRINT(boundary)); debugs(33, 6, "clientPackTermBound: buf offset: " << mb->size); } @@ -1056,7 +1056,7 @@ clientPackRangeHdr(const HttpReply * rep, const HttpHdrRangeSpec * spec, String /* put boundary */ debugs(33, 5, "clientPackRangeHdr: appending boundary: " << boundary); /* rfc2046 requires to _prepend_ boundary with ! */ - mb->Printf("\r\n--" SQUIDSTRINGPH "\r\n", SQUIDSTRINGPRINT(boundary)); + mb->appendf("\r\n--" SQUIDSTRINGPH "\r\n", SQUIDSTRINGPRINT(boundary)); /* stuff the header with required entries and pack it */ diff --git a/src/clients/FtpClient.cc b/src/clients/FtpClient.cc index 4124cbe259..00caa63abb 100644 --- a/src/clients/FtpClient.cc +++ b/src/clients/FtpClient.cc @@ -587,7 +587,7 @@ Ftp::Client::sendEprt() /* RFC 2428 defines EPRT as IPv6 equivalent to IPv4 PORT command. */ /* Which can be used by EITHER protocol. */ debugs(9, 3, "Listening for FTP data connection on port" << comm_local_port(data.conn->fd) << " or port?" << data.conn->local.port()); - mb.Printf("EPRT |%d|%s|%d|%s", + mb.appendf("EPRT |%d|%s|%d|%s", ( data.conn->local.isIPv6() ? 2 : 1 ), data.conn->local.toStr(buf,MAX_IPSTRLEN), comm_local_port(data.conn->fd), Ftp::crlf ); @@ -647,7 +647,7 @@ Ftp::Client::sendPassive() case SENT_EPSV_ALL: /* EPSV ALL resulted in a bad response. Try ther EPSV methods. */ if (ctrl.conn->local.isIPv6()) { debugs(9, 5, "FTP Channel is IPv6 (" << ctrl.conn->remote << ") attempting EPSV 2 after EPSV ALL has failed."); - mb.Printf("EPSV 2%s", Ftp::crlf); + mb.appendf("EPSV 2%s", Ftp::crlf); state = SENT_EPSV_2; break; } @@ -656,7 +656,7 @@ Ftp::Client::sendPassive() case SENT_EPSV_2: /* EPSV IPv6 failed. Try EPSV IPv4 */ if (ctrl.conn->local.isIPv4()) { debugs(9, 5, "FTP Channel is IPv4 (" << ctrl.conn->remote << ") attempting EPSV 1 after EPSV ALL has failed."); - mb.Printf("EPSV 1%s", Ftp::crlf); + mb.appendf("EPSV 1%s", Ftp::crlf); state = SENT_EPSV_1; break; } else if (Config.Ftp.epsv_all) { @@ -668,7 +668,7 @@ Ftp::Client::sendPassive() case SENT_EPSV_1: /* EPSV options exhausted. Try PASV now. */ debugs(9, 5, "FTP Channel (" << ctrl.conn->remote << ") rejects EPSV connection attempts. Trying PASV instead."); - mb.Printf("PASV%s", Ftp::crlf); + mb.appendf("PASV%s", Ftp::crlf); state = SENT_PASV; break; @@ -680,21 +680,21 @@ Ftp::Client::sendPassive() } if (!doEpsv) { debugs(9, 5, "EPSV support manually disabled. Sending PASV for FTP Channel (" << ctrl.conn->remote <<")"); - mb.Printf("PASV%s", Ftp::crlf); + mb.appendf("PASV%s", Ftp::crlf); state = SENT_PASV; } else if (Config.Ftp.epsv_all) { debugs(9, 5, "EPSV ALL manually enabled. Attempting with FTP Channel (" << ctrl.conn->remote <<")"); - mb.Printf("EPSV ALL%s", Ftp::crlf); + mb.appendf("EPSV ALL%s", Ftp::crlf); state = SENT_EPSV_ALL; } else { if (ctrl.conn->local.isIPv6()) { debugs(9, 5, "FTP Channel (" << ctrl.conn->remote << "). Sending default EPSV 2"); - mb.Printf("EPSV 2%s", Ftp::crlf); + mb.appendf("EPSV 2%s", Ftp::crlf); state = SENT_EPSV_2; } if (ctrl.conn->local.isIPv4()) { debugs(9, 5, "Channel (" << ctrl.conn->remote <<"). Sending default EPSV 1"); - mb.Printf("EPSV 1%s", Ftp::crlf); + mb.appendf("EPSV 1%s", Ftp::crlf); state = SENT_EPSV_1; } } diff --git a/src/clients/FtpGateway.cc b/src/clients/FtpGateway.cc index da615bca02..97f3391d46 100644 --- a/src/clients/FtpGateway.cc +++ b/src/clients/FtpGateway.cc @@ -771,7 +771,7 @@ Ftp::Gateway::htmlifyListEntry(const char *line) if (strlen(line) > 1024) { html = new MemBuf(); html->init(); - html->Printf("%s\n", line); + html->appendf("%s\n", line); return html; } @@ -785,7 +785,7 @@ Ftp::Gateway::htmlifyListEntry(const char *line) html = new MemBuf(); html->init(); - html->Printf("%s\n", line); + html->appendf("%s\n", line); for (p = line; *p && xisspace(*p); ++p); if (*p && !xisspace(*p)) @@ -870,7 +870,7 @@ Ftp::Gateway::htmlifyListEntry(const char *line) /* construct the table row from parts. */ html = new MemBuf(); html->init(); - html->Printf("" + html->appendf("" "%s" "%s" "%s" diff --git a/src/comm/TcpAcceptor.cc b/src/comm/TcpAcceptor.cc index 17c13bb7c1..25d9304848 100644 --- a/src/comm/TcpAcceptor.cc +++ b/src/comm/TcpAcceptor.cc @@ -132,7 +132,7 @@ Comm::TcpAcceptor::status() const static MemBuf buf; buf.reset(); - buf.Printf(" FD %d, %s",conn->fd, ipbuf); + buf.appendf(" FD %d, %s",conn->fd, ipbuf); const char *jobStatus = AsyncJob::status(); buf.append(jobStatus, strlen(jobStatus)); diff --git a/src/errorpage.cc b/src/errorpage.cc index dba17cf379..fd89026847 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -204,7 +204,7 @@ errorInitialize(void) if (Config.errorStylesheet) { ErrorPageFile tmpl("StylesSheet", ERR_MAX); tmpl.loadFromFile(Config.errorStylesheet); - error_stylesheet.Printf("%s",tmpl.text()); + error_stylesheet.appendf("%s",tmpl.text()); } #if USE_OPENSSL @@ -702,39 +702,39 @@ ErrorState::Dump(MemBuf * mb) str.reset(); /* email subject line */ - str.Printf("CacheErrorInfo - %s", errorPageName(type)); - mb->Printf("?subject=%s", rfc1738_escape_part(str.buf)); + str.appendf("CacheErrorInfo - %s", errorPageName(type)); + mb->appendf("?subject=%s", rfc1738_escape_part(str.buf)); str.reset(); /* email body */ - str.Printf("CacheHost: %s\r\n", getMyHostname()); + str.appendf("CacheHost: %s\r\n", getMyHostname()); /* - Err Msgs */ - str.Printf("ErrPage: %s\r\n", errorPageName(type)); + str.appendf("ErrPage: %s\r\n", errorPageName(type)); if (xerrno) { - str.Printf("Err: (%d) %s\r\n", xerrno, strerror(xerrno)); + str.appendf("Err: (%d) %s\r\n", xerrno, strerror(xerrno)); } else { - str.Printf("Err: [none]\r\n"); + str.append("Err: [none]\r\n", 13); } #if USE_AUTH if (auth_user_request.getRaw() && auth_user_request->denyMessage()) - str.Printf("Auth ErrMsg: %s\r\n", auth_user_request->denyMessage()); + str.appendf("Auth ErrMsg: %s\r\n", auth_user_request->denyMessage()); #endif if (dnsError.size() > 0) - str.Printf("DNS ErrMsg: %s\r\n", dnsError.termedBuf()); + str.appendf("DNS ErrMsg: %s\r\n", dnsError.termedBuf()); /* - TimeStamp */ - str.Printf("TimeStamp: %s\r\n\r\n", mkrfc1123(squid_curtime)); + str.appendf("TimeStamp: %s\r\n\r\n", mkrfc1123(squid_curtime)); /* - IP stuff */ - str.Printf("ClientIP: %s\r\n", src_addr.toStr(ntoabuf,MAX_IPSTRLEN)); + str.appendf("ClientIP: %s\r\n", src_addr.toStr(ntoabuf,MAX_IPSTRLEN)); if (request && request->hier.host[0] != '\0') { - str.Printf("ServerIP: %s\r\n", request->hier.host); + str.appendf("ServerIP: %s\r\n", request->hier.host); } - str.Printf("\r\n"); + str.append("\r\n", 2); /* - HTTP stuff */ - str.Printf("HTTP Request:\r\n"); + str.append("HTTP Request:\r\n", 15); if (NULL != request) { String urlpath_or_slash; @@ -744,27 +744,27 @@ ErrorState::Dump(MemBuf * mb) else urlpath_or_slash = "/"; - str.Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n", - SQUIDSBUFPRINT(request->method.image()), - SQUIDSTRINGPRINT(urlpath_or_slash), - AnyP::ProtocolType_str[request->http_ver.protocol], - request->http_ver.major, request->http_ver.minor); + str.appendf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n", + SQUIDSBUFPRINT(request->method.image()), + SQUIDSTRINGPRINT(urlpath_or_slash), + AnyP::ProtocolType_str[request->http_ver.protocol], + request->http_ver.major, request->http_ver.minor); request->header.packInto(&str); } - str.Printf("\r\n"); + str.append("\r\n", 2); /* - FTP stuff */ if (ftp.request) { - str.Printf("FTP Request: %s\r\n", ftp.request); - str.Printf("FTP Reply: %s\r\n", (ftp.reply? ftp.reply:"[none]")); - str.Printf("FTP Msg: "); + str.appendf("FTP Request: %s\r\n", ftp.request); + str.appendf("FTP Reply: %s\r\n", (ftp.reply? ftp.reply:"[none]")); + str.append("FTP Msg: ", 9); wordlistCat(ftp.server_msg, &str); - str.Printf("\r\n"); + str.append("\r\n", 2); } - str.Printf("\r\n"); - mb->Printf("&body=%s", rfc1738_escape_part(str.buf)); + str.append("\r\n", 2); + mb->appendf("&body=%s", rfc1738_escape_part(str.buf)); str.clean(); return 0; } @@ -795,7 +795,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion break; case 'b': - mb.Printf("%d", getMyPort()); + mb.appendf("%u", getMyPort()); break; case 'B': @@ -825,18 +825,18 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion } #endif if (!mb.contentSize()) - mb.Printf("[No Error Detail]"); + mb.append("[No Error Detail]", 17); break; case 'e': - mb.Printf("%d", xerrno); + mb.appendf("%d", xerrno); break; case 'E': if (xerrno) - mb.Printf("(%d) %s", xerrno, strerror(xerrno)); + mb.appendf("(%d) %s", xerrno, strerror(xerrno)); else - mb.Printf("[No Error]"); + mb.append("[No Error]", 10); break; case 'f': @@ -869,7 +869,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion break; case 'h': - mb.Printf("%s", getMyHostname()); + mb.appendf("%s", getMyHostname()); break; case 'H': @@ -883,7 +883,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion break; case 'i': - mb.Printf("%s", src_addr.toStr(ntoabuf,MAX_IPSTRLEN)); + mb.appendf("%s", src_addr.toStr(ntoabuf,MAX_IPSTRLEN)); break; case 'I': @@ -902,7 +902,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion case 'L': if (building_deny_info_url) break; if (Config.errHtmlText) { - mb.Printf("%s", Config.errHtmlText); + mb.appendf("%s", Config.errHtmlText); do_quote = 0; } else p = "[not available]"; @@ -933,7 +933,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion case 'p': if (request) { - mb.Printf("%d", (int) request->port); + mb.appendf("%u", request->port); } else if (!building_deny_info_url) { p = "[unknown port]"; } @@ -961,11 +961,11 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion else urlpath_or_slash = "/"; - mb.Printf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n", - SQUIDSBUFPRINT(request->method.image()), - SQUIDSTRINGPRINT(urlpath_or_slash), - AnyP::ProtocolType_str[request->http_ver.protocol], - request->http_ver.major, request->http_ver.minor); + mb.appendf(SQUIDSBUFPH " " SQUIDSTRINGPH " %s/%d.%d\n", + SQUIDSBUFPRINT(request->method.image()), + SQUIDSTRINGPRINT(urlpath_or_slash), + AnyP::ProtocolType_str[request->http_ver.protocol], + request->http_ver.major, request->http_ver.minor); request->header.packInto(&mb, true); //hide authorization data } else if (request_hdrs) { p = request_hdrs; @@ -993,7 +993,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion const int saved_id = page_id; page_id = ERR_SQUID_SIGNATURE; MemBuf *sign_mb = BuildContent(); - mb.Printf("%s", sign_mb->content()); + mb.append(sign_mb->content(), sign_mb->contentSize()); sign_mb->clean(); delete sign_mb; page_id = saved_id; @@ -1005,11 +1005,11 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion break; case 't': - mb.Printf("%s", Time::FormatHttpd(squid_curtime)); + mb.appendf("%s", Time::FormatHttpd(squid_curtime)); break; case 'T': - mb.Printf("%s", mkrfc1123(squid_curtime)); + mb.appendf("%s", mkrfc1123(squid_curtime)); break; case 'U': @@ -1034,7 +1034,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion case 'w': if (Config.adminEmail) - mb.Printf("%s", Config.adminEmail); + mb.appendf("%s", Config.adminEmail); else if (!building_deny_info_url) p = "[unknown]"; break; @@ -1049,7 +1049,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion case 'x': #if USE_OPENSSL if (detail) - mb.Printf("%s", detail->errorName()); + mb.appendf("%s", detail->errorName()); else #endif if (!building_deny_info_url) @@ -1079,7 +1079,7 @@ ErrorState::Convert(char token, bool building_deny_info_url, bool allowRecursion break; default: - mb.Printf("%%%c", token); + mb.appendf("%%%c", token); do_quote = 0; break; } @@ -1113,12 +1113,12 @@ ErrorState::DenyInfoLocation(const char *name, HttpRequest *, MemBuf &result) while ((p = strchr(m, '%'))) { result.append(m, p - m); /* copy */ t = Convert(*++p, true, true); /* convert */ - result.Printf("%s", t); /* copy */ + result.appendf("%s", t); /* copy */ m = p + 1; /* advance */ } if (*m) - result.Printf("%s", m); /* copy tail */ + result.appendf("%s", m); /* copy tail */ assert((size_t)result.contentSize() == strlen(result.content())); } @@ -1272,12 +1272,12 @@ MemBuf *ErrorState::ConvertText(const char *text, bool allowRecursion) while ((p = strchr(m, '%'))) { content->append(m, p - m); /* copy */ const char *t = Convert(*++p, false, allowRecursion); /* convert */ - content->Printf("%s", t); /* copy */ + content->appendf("%s", t); /* copy */ m = p + 1; /* advance */ } if (*m) - content->Printf("%s", m); /* copy tail */ + content->appendf("%s", m); /* copy tail */ content->terminate(); diff --git a/src/external_acl.cc b/src/external_acl.cc index 7d65e67383..bb5099d410 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -1435,9 +1435,7 @@ ExternalACLLookup::Start(ACLChecklist *checklist, external_acl_data *acl, bool i MemBuf buf; buf.init(); - - buf.Printf("%s\n", key); - + buf.appendf("%s\n", key); debugs(82, 4, "externalAclLookup: looking up for '" << key << "' in '" << def->name << "'."); if (!def->theHelper->trySubmit(buf.buf, externalAclHandleReply, state)) { diff --git a/src/format/Format.cc b/src/format/Format.cc index 74a6343340..b98dd6d4c7 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -1307,9 +1307,9 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS fmt->widthMax : strlen(out); if (fmt->left) - mb.Printf("%-*.*s", minWidth, maxWidth, out); + mb.appendf("%-*.*s", minWidth, maxWidth, out); else - mb.Printf("%*.*s", minWidth, maxWidth, out); + mb.appendf("%*.*s", minWidth, maxWidth, out); } else mb.append(out, strlen(out)); } else { diff --git a/src/helper.cc b/src/helper.cc index 5add4df77a..94bbd2143f 100644 --- a/src/helper.cc +++ b/src/helper.cc @@ -1386,7 +1386,7 @@ helperDispatch(helper_server * srv, Helper::Request * r) if (hlp->childs.concurrency) { srv->requestsIndex.insert(helper_server::RequestIndex::value_type(reqId, it)); assert(srv->requestsIndex.size() == srv->requests.size()); - srv->wqueue->Printf("%" PRIu64 " %s", reqId, r->buf); + srv->wqueue->appendf("%" PRIu64 " %s", reqId, r->buf); } else srv->wqueue->append(r->buf, strlen(r->buf)); diff --git a/src/http.cc b/src/http.cc index e162552f3e..23d74fbb1e 100644 --- a/src/http.cc +++ b/src/http.cc @@ -2176,11 +2176,11 @@ HttpStateData::buildRequestPrefix(MemBuf * mb) url = urlCanonical(request); else url = request->urlpath.termedBuf(); - mb->Printf(SQUIDSBUFPH " %s %s/%d.%d\r\n", - SQUIDSBUFPRINT(request->method.image()), - url && *url ? url : "/", - AnyP::ProtocolType_str[httpver.protocol], - httpver.major,httpver.minor); + mb->appendf(SQUIDSBUFPH " %s %s/%d.%d\r\n", + SQUIDSBUFPRINT(request->method.image()), + url && *url ? url : "/", + AnyP::ProtocolType_str[httpver.protocol], + httpver.major,httpver.minor); /* build and pack headers */ { HttpHeader hdr(hoRequest); @@ -2306,9 +2306,9 @@ HttpStateData::getMoreRequestBody(MemBuf &buf) // we may need to send: hex-chunk-size CRLF raw-data CRLF last-chunk buf.init(16 + 2 + rawDataSize + 2 + 5, raw.max_capacity); - buf.Printf("%x\r\n", static_cast(rawDataSize)); + buf.appendf("%x\r\n", static_cast(rawDataSize)); buf.append(raw.content(), rawDataSize); - buf.Printf("\r\n"); + buf.append("\r\n", 2); Must(rawDataSize > 0); // we did not accidently created last-chunk above diff --git a/src/http/StatusLine.cc b/src/http/StatusLine.cc index 285aec8a2c..4671dfda5c 100644 --- a/src/http/StatusLine.cc +++ b/src/http/StatusLine.cc @@ -57,14 +57,14 @@ Http::StatusLine::packInto(Packable * p) const debugs(57, 9, "packing sline " << this << " using " << p << ":"); debugs(57, 9, "FORMAT=" << IcyStatusLineFormat ); debugs(57, 9, "ICY " << status() << " " << reason()); - p->Printf(IcyStatusLineFormat, status(), reason()); + p->appendf(IcyStatusLineFormat, status(), reason()); return; } debugs(57, 9, "packing sline " << this << " using " << p << ":"); debugs(57, 9, "FORMAT=" << Http1StatusLineFormat ); debugs(57, 9, "HTTP/" << version.major << "." << version.minor << " " << status() << " " << reason()); - p->Printf(Http1StatusLineFormat, version.major, version.minor, status(), reason()); + p->appendf(Http1StatusLineFormat, version.major, version.minor, status(), reason()); } /* diff --git a/src/ident/Ident.cc b/src/ident/Ident.cc index 77a2ab79d2..d2e752205c 100644 --- a/src/ident/Ident.cc +++ b/src/ident/Ident.cc @@ -264,7 +264,7 @@ Ident::Start(const Comm::ConnectionPointer &conn, IDCB * callback, void *data) // build our query from the original connection details state->queryMsg.init(); - state->queryMsg.Printf("%d, %d\r\n", conn->remote.port(), conn->local.port()); + state->queryMsg.appendf("%d, %d\r\n", conn->remote.port(), conn->local.port()); ClientAdd(state, callback, data); hash_join(ident_hash, &state->hash); diff --git a/src/internal.cc b/src/internal.cc index 150000c229..3c3659117b 100644 --- a/src/internal.cc +++ b/src/internal.cc @@ -105,17 +105,16 @@ internalRemoteUri(const char *host, unsigned short port, const char *dir, const static MemBuf mb; mb.reset(); - - mb.Printf("http://%s", lc_host); + mb.appendf("http://%s", lc_host); /* append port if not default */ if (port && port != urlDefaultPort(AnyP::PROTO_HTTP)) - mb.Printf(":%d", port); + mb.appendf(":%u", port); if (dir) - mb.Printf("%s", dir); + mb.append(dir, strlen(dir)); - mb.Printf("%s", name); + mb.append(name, strlen(name)); /* return a pointer to a local static buffer */ return mb.buf; diff --git a/src/ipc/Inquirer.cc b/src/ipc/Inquirer.cc index 1488d9015c..bba79a5d04 100644 --- a/src/ipc/Inquirer.cc +++ b/src/ipc/Inquirer.cc @@ -203,7 +203,7 @@ Ipc::Inquirer::status() const { static MemBuf buf; buf.reset(); - buf.Printf(" [request->requestId %u]", request->requestId); + buf.appendf(" [request->requestId %u]", request->requestId); buf.terminate(); return buf.content(); } diff --git a/src/mime.cc b/src/mime.cc index dbb282cd6a..a39f9e240b 100644 --- a/src/mime.cc +++ b/src/mime.cc @@ -165,7 +165,7 @@ mimeGetIconURL(const char *fn) if (Config.icons.use_short_names) { static MemBuf mb; mb.reset(); - mb.Printf("/squid-internal-static/icons/%s", icon); + mb.appendf("/squid-internal-static/icons/%s", icon); return mb.content(); } else { return internalLocalUri("/squid-internal-static/icons/", icon); diff --git a/src/servers/FtpServer.cc b/src/servers/FtpServer.cc index d852ab748c..98a71d10ec 100644 --- a/src/servers/FtpServer.cc +++ b/src/servers/FtpServer.cc @@ -417,7 +417,7 @@ Ftp::Server::acceptDataConnection(const CommAcceptCbParams ¶ms) Must(master->serverState == fssHandleDataRequest); MemBuf mb; mb.init(); - mb.Printf("150 Data connection opened.\r\n"); + mb.appendf("150 Data connection opened.\r\n"); Comm::Write(clientConnection, &mb, call); } } @@ -462,7 +462,7 @@ Ftp::Server::writeEarlyReply(const int code, const char *msg) MemBuf mb; mb.init(); - mb.Printf("%i %s\r\n", code, msg); + mb.appendf("%i %s\r\n", code, msg); typedef CommCbMemFunT Dialer; AsyncCall::Pointer call = JobCallback(33, 5, Dialer, this, Ftp::Server::wroteEarlyReply); @@ -497,12 +497,12 @@ Ftp::Server::writeCustomReply(const int code, const char *msg, const HttpReply * MemBuf mb; mb.init(); if (sendDetails) { - mb.Printf("%i-%s\r\n", code, msg); - mb.Printf(" Server reply:\r\n"); + mb.appendf("%i-%s\r\n", code, msg); + mb.appendf(" Server reply:\r\n"); Ftp::PrintReply(mb, reply, " "); - mb.Printf("%i \r\n", code); + mb.appendf("%i \r\n", code); } else - mb.Printf("%i %s\r\n", code, msg); + mb.appendf("%i %s\r\n", code, msg); writeReply(mb); } @@ -892,7 +892,7 @@ Ftp::Server::handlePasvReply(const HttpReply *reply, StoreIOBuffer) // versions block responses that use those alternative syntax rules! MemBuf mb; mb.init(); - mb.Printf("227 Entering Passive Mode (%s,%i,%i).\r\n", + mb.appendf("227 Entering Passive Mode (%s,%i,%i).\r\n", addr, static_cast(localPort / 256), static_cast(localPort % 256)); @@ -1063,7 +1063,7 @@ Ftp::Server::handleEpsvReply(const HttpReply *reply, StoreIOBuffer) // traffic will be redirected to us. MemBuf mb; mb.init(); - mb.Printf("229 Entering Extended Passive Mode (|||%u|)\r\n", localPort); + mb.appendf("229 Entering Extended Passive Mode (|||%u|)\r\n", localPort); debugs(9, 3, Raw("writing", mb.buf, mb.size)); writeReply(mb); @@ -1080,11 +1080,11 @@ Ftp::Server::writeErrorReply(const HttpReply *reply, const int scode) mb.init(); if (request->errType != ERR_NONE) - mb.Printf("%i-%s\r\n", scode, errorPageName(request->errType)); + mb.appendf("%i-%s\r\n", scode, errorPageName(request->errType)); if (request->errDetail > 0) { // XXX: > 0 may not always mean that this is an errno - mb.Printf("%i-Error: (%d) %s\r\n", scode, + mb.appendf("%i-Error: (%d) %s\r\n", scode, request->errDetail, strerror(request->errDetail)); } @@ -1096,9 +1096,9 @@ Ftp::Server::writeErrorReply(const HttpReply *reply, const int scode) const String info = ah->allMeta.getByName("X-Response-Info"); const String desc = ah->allMeta.getByName("X-Response-Desc"); if (info.size()) - mb.Printf("%i-Information: %s\r\n", scode, info.termedBuf()); + mb.appendf("%i-Information: %s\r\n", scode, info.termedBuf()); if (desc.size()) - mb.Printf("%i-Description: %s\r\n", scode, desc.termedBuf()); + mb.appendf("%i-Description: %s\r\n", scode, desc.termedBuf()); } #endif @@ -1107,7 +1107,7 @@ Ftp::Server::writeErrorReply(const HttpReply *reply, const int scode) reply->header.getStr(HDR_FTP_REASON): reply->sline.reason(); - mb.Printf("%i %s\r\n", scode, reason); // error terminating line + mb.appendf("%i %s\r\n", scode, reason); // error terminating line // TODO: errorpage.cc should detect FTP client and use // configurable FTP-friendly error templates which we should @@ -1197,13 +1197,13 @@ Ftp::PrintReply(MemBuf &mb, const HttpReply *reply, const char *const) if (e->id == HDR_FTP_PRE) { String raw; if (httpHeaderParseQuotedString(e->value.rawBuf(), e->value.size(), &raw)) - mb.Printf("%s\r\n", raw.termedBuf()); + mb.appendf("%s\r\n", raw.termedBuf()); } } if (header.has(HDR_FTP_STATUS)) { const char *reason = header.getStr(HDR_FTP_REASON); - mb.Printf("%i %s\r\n", header.getInt(HDR_FTP_STATUS), + mb.appendf("%i %s\r\n", header.getInt(HDR_FTP_STATUS), (reason ? reason : 0)); } } diff --git a/src/stat.cc b/src/stat.cc index 0b57d16af5..77ef7073e0 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -342,21 +342,17 @@ static void statStoreEntry(MemBuf * mb, StoreEntry * e) { MemObject *mem = e->mem_obj; - mb->Printf("KEY %s\n", e->getMD5Text()); - mb->Printf("\t%s\n", describeStatuses(e)); - mb->Printf("\t%s\n", storeEntryFlags(e)); - mb->Printf("\t%s\n", describeTimestamps(e)); - mb->Printf("\t%d locks, %d clients, %d refs\n", - (int) e->locks(), - storePendingNClients(e), - (int) e->refcount); - mb->Printf("\tSwap Dir %d, File %#08X\n", - e->swap_dirn, e->swap_filen); + mb->appendf("KEY %s\n", e->getMD5Text()); + mb->appendf("\t%s\n", describeStatuses(e)); + mb->appendf("\t%s\n", storeEntryFlags(e)); + mb->appendf("\t%s\n", describeTimestamps(e)); + mb->appendf("\t%d locks, %d clients, %d refs\n", (int) e->locks(), storePendingNClients(e), (int) e->refcount); + mb->appendf("\tSwap Dir %d, File %#08X\n", e->swap_dirn, e->swap_filen); if (mem != NULL) mem->stat (mb); - mb->Printf("\n"); + mb->append("\n", 1); } /* process objects list */ diff --git a/src/store_client.cc b/src/store_client.cc index fd677f2887..bf87633ba4 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -855,26 +855,21 @@ store_client::dumpStats(MemBuf * output, int clientNumber) const if (_callback.pending()) return; - output->Printf("\tClient #%d, %p\n", clientNumber, _callback.callback_data); - - output->Printf("\t\tcopy_offset: %" PRId64 "\n", - copyInto.offset); - - output->Printf("\t\tcopy_size: %d\n", - (int) copyInto.length); - - output->Printf("\t\tflags:"); + output->appendf("\tClient #%d, %p\n", clientNumber, _callback.callback_data); + output->appendf("\t\tcopy_offset: %" PRId64 "\n", copyInto.offset); + output->appendf("\t\tcopy_size: %d\n", copyInto.length); + output->append("\t\tflags:", 8); if (flags.disk_io_pending) - output->Printf(" disk_io_pending"); + output->append(" disk_io_pending", 16); if (flags.store_copying) - output->Printf(" store_copying"); + output->append(" store_copying", 14); if (flags.copy_event_pending) - output->Printf(" copy_event_pending"); + output->append(" copy_event_pending", 19); - output->Printf("\n"); + output->append("\n",1); } bool diff --git a/src/tunnel.cc b/src/tunnel.cc index 87f9238194..93ff6eedfa 100644 --- a/src/tunnel.cc +++ b/src/tunnel.cc @@ -1063,7 +1063,7 @@ tunnelRelayConnectRequest(const Comm::ConnectionPointer &srv, void *data) flags.proxying = tunnelState->request->flags.proxying; MemBuf mb; mb.init(); - mb.Printf("CONNECT %s HTTP/1.1\r\n", tunnelState->url); + mb.appendf("CONNECT %s HTTP/1.1\r\n", tunnelState->url); HttpStateData::httpBuildRequestHeader(tunnelState->request.getRaw(), NULL, /* StoreEntry */ tunnelState->al, /* AccessLogEntry */ diff --git a/src/urn.cc b/src/urn.cc index b66e617292..20a08d7070 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -367,7 +367,7 @@ urnHandleReply(void *data, StoreIOBuffer result) e->buffer(); mb = new MemBuf; mb->init(); - mb->Printf( "Select URL for %s\n" + mb->appendf( "Select URL for %s\n" "\n" "

Select URL for %s

\n" "\n", e->url(), e->url()); @@ -375,20 +375,19 @@ urnHandleReply(void *data, StoreIOBuffer result) for (i = 0; i < urlcnt; ++i) { u = &urls[i]; debugs(52, 3, "URL {" << u->url << "}"); - mb->Printf( + mb->appendf( "", u->url, u->url); if (urls[i].rtt > 0) - mb->Printf( + mb->appendf( "", u->rtt); else - mb->Printf(""); + mb->appendf(""); - mb->Printf( - "\n", u->flags.cached ? " [cached]" : " "); + mb->appendf("\n", u->flags.cached ? " [cached]" : " "); } - mb->Printf( + mb->appendf( "
%s%4d msUnknownUnknown%s
%s
" "
\n" "
\n" diff --git a/src/wordlist.cc b/src/wordlist.cc index ba8d24cca9..b27b4e84a8 100644 --- a/src/wordlist.cc +++ b/src/wordlist.cc @@ -69,7 +69,7 @@ void wordlistCat(const wordlist * w, MemBuf * mb) { while (NULL != w) { - mb->Printf("%s\n", w->key); + mb->appendf("%s\n", w->key); w = w->next; } } -- 2.39.2