From: Francesco Chemolli Date: Wed, 11 Feb 2009 17:08:24 +0000 (+0100) Subject: defined printf-helping macros, X-Git-Tag: SQUID_3_2_0_1~1189^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb7907027442f83ae89b12a93dc1a6239c6a837a;p=thirdparty%2Fsquid.git defined printf-helping macros, reverted some unnecessary renamings further unsafeBuf conversions. --- diff --git a/src/CommonPool.h b/src/CommonPool.h index 281025e218..fb24c43bde 100644 --- a/src/CommonPool.h +++ b/src/CommonPool.h @@ -59,7 +59,7 @@ public: void *operator new(size_t); void operator delete (void *); static CommonPool *Factory (unsigned char _class, CompositePoolNode::Pointer&); - char const* theClassTypeLabel() const {return typeLabel.unsafeBuf();} + char const* theClassTypeLabel() const {return typeLabel.termedBuf();} protected: CommonPool(); diff --git a/src/DelayTagged.cc b/src/DelayTagged.cc index a5c08e6041..377c2f6584 100644 --- a/src/DelayTagged.cc +++ b/src/DelayTagged.cc @@ -77,7 +77,7 @@ int DelayTaggedCmp(DelayTaggedBucket::Pointer const &left, DelayTaggedBucket::Pointer const &right) { /* for rate limiting, case insensitive */ - return left->tag.caseCmp(right->tag.unsafeBuf()); + return left->tag.caseCmp(right->tag); } void @@ -195,7 +195,7 @@ DelayTaggedBucket::~DelayTaggedBucket() void DelayTaggedBucket::stats (StoreEntry *entry) const { - storeAppendPrintf(entry, " %s:", tag.unsafeBuf()); + storeAppendPrintf(entry, " " SQUIDSTRINGPH , SQUIDSTRINGPRINT(tag)); theBucket.stats (entry); } diff --git a/src/DiskIO/AIO/AIODiskFile.cc b/src/DiskIO/AIO/AIODiskFile.cc index 1a2c801366..3ed4d48eb0 100644 --- a/src/DiskIO/AIO/AIODiskFile.cc +++ b/src/DiskIO/AIO/AIODiskFile.cc @@ -129,7 +129,7 @@ AIODiskFile::read(ReadRequest *request) fatal("Aiee! out of aiocb slots! - FIXME and wrap file_read\n"); debugs(79, 1, "WARNING: out of aiocb slots!"); /* fall back to blocking method */ - // file_read(fd, request->unsafeBuf, request->len, request->offset, callback, data); + // file_read(fd, request->buf, request->len, request->offset, callback, data); return; } @@ -166,7 +166,7 @@ AIODiskFile::read(ReadRequest *request) fatalf("Aiee! aio_read() returned error (%d) FIXME and wrap file_read !\n", errno); debugs(79, 1, "WARNING: aio_read() returned error: " << xstrerror()); /* fall back to blocking method */ - // file_read(fd, request->unsafeBuf, request->len, request->offset, callback, data); + // file_read(fd, request->buf, request->len, request->offset, callback, data); } } @@ -187,7 +187,7 @@ AIODiskFile::write(WriteRequest *request) fatal("Aiee! out of aiocb slots FIXME and wrap file_write !\n"); debugs(79, 1, "WARNING: out of aiocb slots!"); /* fall back to blocking method */ - // file_write(fd, offset, unsafeBuf, len, callback, data, freefunc); + // file_write(fd, offset, buf, len, callback, data, freefunc); return; } @@ -224,7 +224,7 @@ AIODiskFile::write(WriteRequest *request) fatalf("Aiee! aio_write() returned error (%d) FIXME and wrap file_write !\n", errno); debugs(79, 1, "WARNING: aio_write() returned error: " << xstrerror()); /* fall back to blocking method */ - // file_write(fd, offset, unsafeBuf, len, callback, data, freefunc); + // file_write(fd, offset, buf, len, callback, data, freefunc); } } diff --git a/src/ESI.cc b/src/ESI.cc index dda16d5056..875e8b25df 100644 --- a/src/ESI.cc +++ b/src/ESI.cc @@ -2430,7 +2430,7 @@ esiEnableProcessing (HttpReply *rep) */ return 0; - if (strstr (sctusable->content.unsafeBuf(), "ESI/1.0")) + if (sctusable->content.pos("ESI/1.0") != NULL) rv = 1; httpHdrScTargetDestroy (sctusable); diff --git a/src/ESIAssign.cc b/src/ESIAssign.cc index 496bdfa8a4..3efc390638 100644 --- a/src/ESIAssign.cc +++ b/src/ESIAssign.cc @@ -89,7 +89,7 @@ ESIAssign::evaluateVariable() variable = NULL; if (unevaluatedVariable.size()) { - varState->feedData(unevaluatedVariable.unsafeBuf(), unevaluatedVariable.size()); + varState->feedData(unevaluatedVariable.rawBuf(), unevaluatedVariable.size()); char const *result = varState->extractChar (); /* Consider activating this, when we want to evaluate variables to a @@ -123,7 +123,7 @@ ESIAssign::process (int dovars) if (!value) return ESI_PROCESS_COMPLETE; - varState->addVariable (name.unsafeBuf(), name.size(), value); + varState->addVariable (name.rawBuf(), name.size(), value); value = NULL; @@ -194,7 +194,7 @@ void ESIVariableExpression::eval (ESIVarState &state, char const *subref, char const *defaultOnEmpty) const { /* XXX: Implement evaluation of the expression */ - ESISegment::ListAppend (state.getOutput(), expression.unsafeBuf(), expression.size()); + ESISegment::ListAppend (state.getOutput(), expression.rawBuf(), expression.size()); } #endif /* USE_SQUID_ESI == 1 */ diff --git a/src/ICAP/ICAPModXact.cc b/src/ICAP/ICAPModXact.cc index bbb0d85d3c..0a919f5c7d 100644 --- a/src/ICAP/ICAPModXact.cc +++ b/src/ICAP/ICAPModXact.cc @@ -1111,7 +1111,7 @@ void ICAPModXact::makeRequestHeaders(MemBuf &buf) if (TheICAPConfig.send_client_username && request) makeUsernameHeader(request, buf); - // fprintf(stderr, "%s\n", unsafeBuf.content()); + // fprintf(stderr, "%s\n", buf.content()); buf.append(ICAP::crlf, 2); // terminate ICAP header @@ -1272,7 +1272,7 @@ void ICAPModXact::finishNullOrEmptyBodyPreview(MemBuf &buf) Must(!preview.ad()); // do not add last-chunk because our Encapsulated header says null-body - // addLastRequestChunk(unsafeBuf); + // addLastRequestChunk(buf); preview.wrote(0, true); Must(preview.done()); diff --git a/src/ICAP/ICAPXaction.cc b/src/ICAP/ICAPXaction.cc index 9bf529eddd..dcf864c208 100644 --- a/src/ICAP/ICAPXaction.cc +++ b/src/ICAP/ICAPXaction.cc @@ -295,7 +295,7 @@ void ICAPXaction::scheduleRead() /* * See comments in ICAPXaction.h about why we use commBuf - * here instead of reading directly into readBuf.unsafeBuf. + * here instead of reading directly into readBuf.buf. */ typedef CommCbMemFunT Dialer; reader = asyncCall(93,3, "ICAPXaction::noteCommRead", @@ -320,7 +320,7 @@ void ICAPXaction::noteCommRead(const CommIoCbParams &io) /* * See comments in ICAPXaction.h about why we use commBuf - * here instead of reading directly into readBuf.unsafeBuf. + * here instead of reading directly into readBuf.buf. */ if (io.size > 0) { diff --git a/src/SquidString.h b/src/SquidString.h index 7fe23b112e..0aac98957b 100644 --- a/src/SquidString.h +++ b/src/SquidString.h @@ -40,6 +40,12 @@ /** todo checks to wrap this include properly */ #include +/* squid string placeholder (for printf) */ +#ifndef SQUIDSTRINGPH +#define SQUIDSTRINGPH "%.*s" +#define SQUIDSTRINGPRINT(s) s.psize(),s.rawBuf() +#endif /* SQUIDSTRINGPH */ + #define DEBUGSTRINGS 0 #if DEBUGSTRINGS diff --git a/src/client_side.cc b/src/client_side.cc index 98d2924712..6a2af2bf73 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -489,7 +489,7 @@ ClientHttpRequest::logRequest() al.http.content_type = al.reply->content_type.termedBuf(); } else if (loggingEntry() && loggingEntry()->mem_obj) { al.http.code = loggingEntry()->mem_obj->getReply()->sline.status; - al.http.content_type = loggingEntry()->mem_obj->getReply()->content_type.unsafeBuf(); + al.http.content_type = loggingEntry()->mem_obj->getReply()->content_type.termedBuf(); } debugs(33, 9, "clientLogRequest: http.code='" << al.http.code << "'"); @@ -890,7 +890,7 @@ clientPackRangeHdr(const HttpReply * rep, const HttpHdrRangeSpec * spec, String } /** - * extracts a "range" from *unsafeBuf and appends them to mb, updating + * extracts a "range" from *buf and appends them to mb, updating * all offsets and such. */ void @@ -1924,7 +1924,7 @@ parseHttpRequest(ConnStateData *conn, HttpParser *hp, HttpRequestMethod * method req_sz = HttpParserReqSz(hp); } - /* We know the whole request is in hp->unsafeBuf now */ + /* We know the whole request is in hp->buf now */ assert(req_sz <= (size_t) hp->bufsiz); @@ -2623,7 +2623,7 @@ ConnStateData::handleReadData(char *buf, size_t size) } /** - * called when new request body data has been buffered in in.unsafeBuf + * called when new request body data has been buffered in in.buf * may close the connection if we were closing and piped everything out */ void diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 0b2b0858ff..cb359f406d 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1671,7 +1671,7 @@ clientReplyDetach(clientStreamNode * node, ClientHttpRequest * http) } /* - * accepts chunk of a http message in unsafeBuf, parses prefix, filters headers and + * accepts chunk of a http message in buf, parses prefix, filters headers and * such, writes processed message to the message recipient */ void diff --git a/src/client_side_request.cc b/src/client_side_request.cc index e49ed3ddba..781e7dcab3 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -426,7 +426,7 @@ clientFollowXForwardedForCheck(int answer, void *data) const char *asciiaddr; int l; struct in_addr addr; - p = request->x_forwarded_for_iterator.unsafeBuf(); + p = request->x_forwarded_for_iterator.termedBuf(); l = request->x_forwarded_for_iterator.size(); /* @@ -897,7 +897,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http) } #if FORW_VIA_DB - fvdbCountVia(s.unsafeBuf()); + fvdbCountVia(s.termedBuf()); #endif @@ -923,7 +923,7 @@ clientInterpretRequestHeaders(ClientHttpRequest * http) if (req_hdr->has(HDR_X_FORWARDED_FOR)) { String s = req_hdr->getList(HDR_X_FORWARDED_FOR); - fvdbCountForw(s.unsafeBuf()); + fvdbCountForw(s.termedBuf()); s.clean(); } diff --git a/src/eCAP/MessageRep.cc b/src/eCAP/MessageRep.cc index b8069bb44c..f3b8b298ec 100644 --- a/src/eCAP/MessageRep.cc +++ b/src/eCAP/MessageRep.cc @@ -192,7 +192,7 @@ Ecap::RequestLineRep::uri(const Area &aUri) Ecap::RequestLineRep::Area Ecap::RequestLineRep::uri() const { - return Area::FromTempBuffer(theMessage.urlpath.unsafeBuf(), + return Area::FromTempBuffer(theMessage.urlpath.rawBuf(), theMessage.urlpath.size()); } diff --git a/src/errorpage.cc b/src/errorpage.cc index f5657778da..20e2c48c39 100644 --- a/src/errorpage.cc +++ b/src/errorpage.cc @@ -556,9 +556,16 @@ ErrorState::Dump(MemBuf * mb) if (NULL != request) { Packer p; - str.Printf("%s %s HTTP/%d.%d\n", + String urlpath_or_slash; + + if (request->urlpath.size() != 0) + urlpath_or_slash = request->urlpath; + else + urlpath_or_slash = "/"; + + str.Printf("%s " SQUIDSTRINGPH " HTTP/%d.%d\n", RequestMethodStr(request->method), - request->urlpath.size() ? request->urlpath.unsafeBuf() : "/", + SQUIDSTRINGPRINT(urlpath_or_slash), request->http_ver.major, request->http_ver.minor); packerToMemInit(&p, &str); request->header.packInto(&p); @@ -734,9 +741,16 @@ ErrorState::Convert(char token) if (NULL != request) { Packer p; - mb.Printf("%s %s HTTP/%d.%d\n", + String urlpath_or_slash; + + if (request->urlpath.size() != 0) + urlpath_or_slash = request->urlpath; + else + urlpath_or_slash = "/"; + + mb.Printf("%s " SQUIDSTRINGPH " HTTP/%d.%d\n", RequestMethodStr(request->method), - request->urlpath.size() ? request->urlpath.unsafeBuf() : "/", + SQUIDSTRINGPRINT(urlpath_or_slash), request->http_ver.major, request->http_ver.minor); packerToMemInit(&p, &mb); request->header.packInto(&p); @@ -928,7 +942,7 @@ ErrorState::BuildContent() */ if (!Config.errorDirectory && request && request->header.getList(HDR_ACCEPT_LANGUAGE, &hdr) ) { - const char *unsafeBuf = hdr.unsafeBuf(); // raw header string for parsing + const char *raw_hdr = hdr.termedBuf(); // raw header string for parsing size_t pos = 0; // current parsing position in header string char *reset = NULL; // where to reset the p pointer for each new tag file char *dt = NULL; @@ -950,12 +964,12 @@ ErrorState::BuildContent() * - IFF a tag contains only two characters we can wildcard ANY translations matching: '-'? .* * with preference given to an exact match. */ - while (pos < hdr.size() && unsafeBuf[pos] != ';' && unsafeBuf[pos] != ',' && !xisspace(unsafeBuf[pos]) && dt < (dir+256) ) { - *dt++ = xtolower(unsafeBuf[pos++]); + while (pos < hdr.size() && raw_hdr[pos] != ';' && raw_hdr[pos] != ',' && !xisspace(raw_hdr[pos]) && dt < (dir+256) ) { + *dt++ = xtolower(raw_hdr[pos++]); } *dt++ = '\0'; // nul-terminated the filename content string before system use. - debugs(4, 9, HERE << "STATE: dt='" << dt << "', reset='" << reset << "', reset[1]='" << reset[1] << "', pos=" << pos << ", buf='" << &unsafeBuf[pos] << "'"); + debugs(4, 9, HERE << "STATE: dt='" << dt << "', reset='" << reset << "', reset[1]='" << reset[1] << "', pos=" << pos << ", buf='" << &raw_hdr[pos] << "'"); /* if we found anything we might use, try it. */ if (*reset != '\0') { @@ -983,8 +997,8 @@ ErrorState::BuildContent() dt = reset; // reset for next tag testing. we replace the failed name instead of cloning. // IFF we terminated the tag on ';' we need to skip the 'q=' bit to the next ',' or end. - while (pos < hdr.size() && unsafeBuf[pos] != ',') pos++; - if (unsafeBuf[pos] == ',') pos++; + while (pos < hdr.size() && raw_hdr[pos] != ',') pos++; + if (raw_hdr[pos] == ',') pos++; } } #endif /* USE_ERR_LOCALES */ diff --git a/src/gopher.cc b/src/gopher.cc index 6d86a34d8c..015f34a6d5 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -853,7 +853,7 @@ gopherReadReply(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void do_next_read = 0; } else if (len == 0) { /* Connection closed; retrieval done. */ - /* flush the rest of data in temp unsafeBuf if there is one. */ + /* flush the rest of data in temp buf if there is one. */ if (gopherState->conversion != gopher_ds::NORMAL) gopherEndHTML(gopherState); diff --git a/src/peer_digest.cc b/src/peer_digest.cc index 450a0bff91..d8b510bb7d 100644 --- a/src/peer_digest.cc +++ b/src/peer_digest.cc @@ -231,7 +231,7 @@ peerDigestSetCheck(PeerDigest * pd, time_t delay) { eventAdd("peerDigestCheck", peerDigestCheck, pd, (double) delay, 1); pd->times.next_check = squid_curtime + delay; - debugs(72, 3, "peerDigestSetCheck: will check peer " << pd->host.unsafeBuf() << " in " << delay << " secs"); + debugs(72, 3, "peerDigestSetCheck: will check peer " << pd->host << " in " << delay << " secs"); } /* @@ -241,10 +241,10 @@ void peerDigestNotePeerGone(PeerDigest * pd) { if (pd->flags.requested) { - debugs(72, 2, "peerDigest: peer " << pd->host.unsafeBuf() << " gone, will destroy after fetch."); + debugs(72, 2, "peerDigest: peer " << pd->host << " gone, will destroy after fetch."); /* do nothing now, the fetching chain will notice and take action */ } else { - debugs(72, 2, "peerDigest: peer " << pd->host.unsafeBuf() << " is gone, destroying now."); + debugs(72, 2, "peerDigest: peer " << pd->host << " is gone, destroying now."); peerDigestDestroy(pd); } }