From: wessels <> Date: Tue, 8 Nov 2005 05:00:38 +0000 (+0000) Subject: My recent HttpReply changes created an awkward situation. Both X-Git-Tag: SQUID_3_0_PRE4~535 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=59eed7dcdf1695c3c04a51e4bcc7aaaadaf02164;p=thirdparty%2Fsquid.git My recent HttpReply changes created an awkward situation. Both HttpReply and its base class HttpMsg had methods named parse() but had different number and type of arugments. This patch moves HttpReply::parse() to HttpMsg::parseCharBuf() both parse() and parseCharBuf() use httpMsgParseStep() --- diff --git a/src/HttpMsg.cc b/src/HttpMsg.cc index bee1ce4a68..07b77984d4 100644 --- a/src/HttpMsg.cc +++ b/src/HttpMsg.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpMsg.cc,v 1.18 2005/09/17 04:53:44 wessels Exp $ + * $Id: HttpMsg.cc,v 1.19 2005/11/07 22:00:38 wessels Exp $ * * DEBUG: section 74 HTTP Message * AUTHOR: Alex Rousskov @@ -201,7 +201,28 @@ bool HttpMsg::parse(MemBuf *buf, bool eof, http_status *error) return true; } - +/* + * parse() takes character buffer of HTTP headers (buf), + * which may not be NULL-terminated, and fills in an HttpMsg + * structure. The parameter 'end' specifies the offset to + * the end of the reply headers. The caller may know where the + * end is, but is unable to NULL-terminate the buffer. This function + * returns true on success. + */ +bool +HttpMsg::parseCharBuf(const char *buf, ssize_t end) +{ + MemBuf mb; + int success; + /* reset current state, because we are not used in incremental fashion */ + reset(); + mb.init(); + mb.append(buf, end); + mb.terminate(); + success = httpMsgParseStep(mb.buf, 0); + mb.clean(); + return success == 1; +} /* * parses a 0-terminating buffer into HttpMsg. diff --git a/src/HttpMsg.h b/src/HttpMsg.h index 4fbcc5ddf6..838bc21a1b 100644 --- a/src/HttpMsg.h +++ b/src/HttpMsg.h @@ -1,6 +1,6 @@ /* - * $Id: HttpMsg.h,v 1.3 2005/09/15 20:19:41 wessels Exp $ + * $Id: HttpMsg.h,v 1.4 2005/11/07 22:00:38 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -72,6 +72,7 @@ public: HttpMsgParseState pstate; /* the current parsing state */ bool parse(MemBuf *buf, bool eol, http_status *error); + bool parseCharBuf(const char *buf, ssize_t end); int httpMsgParseStep(const char *buf, int atEnd); int httpMsgParseError(); diff --git a/src/HttpReply.cc b/src/HttpReply.cc index b3f8f3ca25..6fbe9aca7c 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.cc,v 1.78 2005/11/05 00:08:32 wessels Exp $ + * $Id: HttpReply.cc,v 1.79 2005/11/07 22:00:38 wessels Exp $ * * DEBUG: section 58 HTTP Reply (Response) * AUTHOR: Alex Rousskov @@ -118,37 +118,6 @@ HttpReply::absorb(HttpReply * new_rep) delete new_rep; } -/* - * parse() takes character buffer of HTTP headers (buf), - * which may not be NULL-terminated, and fills in an HttpReply - * structure (rep). The parameter 'end' specifies the offset to - * the end of the reply headers. The caller may know where the - * end is, but is unable to NULL-terminate the buffer. This function - * returns true on success. - */ -bool -HttpReply::parse(const char *buf, ssize_t end) -{ - /* - * this extra buffer/copy will be eliminated when headers become - * meta-data in store. Currently we have to xstrncpy the buffer - * becuase somebody may feed a non NULL-terminated buffer to - * us. - */ - MemBuf mb; - int success; - /* reset current state, because we are not used in incremental fashion */ - reset(); - /* put a string terminator. s is how many bytes to touch in - * 'buf' including the terminating NULL. */ - mb.init(); - mb.append(buf, end); - mb.terminate(); - success = httpMsgParseStep(mb.buf, 0); - mb.clean(); - return success == 1; -} - void HttpReply::packHeadersInto(Packer * p) const { diff --git a/src/HttpReply.h b/src/HttpReply.h index 8e61e38c1b..35be53b92b 100644 --- a/src/HttpReply.h +++ b/src/HttpReply.h @@ -1,6 +1,6 @@ /* - * $Id: HttpReply.h,v 1.12 2005/11/05 00:08:32 wessels Exp $ + * $Id: HttpReply.h,v 1.13 2005/11/07 22:00:38 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -78,8 +78,6 @@ public: public: void updateOnNotModified(HttpReply const *other); - /* parse returns true on success */ - bool parse(const char *buf, ssize_t); /* absorb: copy the contents of a new reply to the old one, destroy new one */ void absorb(HttpReply * new_rep); /* set commonly used info with one call */ diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 2071105caa..70e05196b5 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side_reply.cc,v 1.89 2005/11/05 00:08:32 wessels Exp $ + * $Id: client_side_reply.cc,v 1.90 2005/11/07 22:00:38 wessels Exp $ * * DEBUG: section 88 Client-side Reply Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -1466,7 +1466,7 @@ clientReplyContext::buildReply(const char *buf, size_t size) holdReply(new HttpReply); - if (!holdingReply->parse(buf, k)) { + if (!holdingReply->parseCharBuf(buf, k)) { /* parsing failure, get rid of the invalid reply */ delete holdingReply; holdReply (NULL); diff --git a/src/http.cc b/src/http.cc index 7a7b387542..19473129ab 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.465 2005/11/05 00:08:32 wessels Exp $ + * $Id: http.cc,v 1.466 2005/11/07 22:00:38 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -719,7 +719,7 @@ HttpStateData::processReplyHeader(const char *buf, int size) /* Parse headers into reply structure */ /* what happens if we fail to parse here? */ - reply->parse(reply_hdr.buf, hdr_size); + reply->parseCharBuf(reply_hdr.buf, hdr_size); if (reply->sline.status >= HTTP_INVALID_HEADER) { debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << reply_hdr.buf << "'"); diff --git a/src/store_client.cc b/src/store_client.cc index 9bf06f82eb..f5b701fabb 100644 --- a/src/store_client.cc +++ b/src/store_client.cc @@ -1,6 +1,6 @@ /* - * $Id: store_client.cc,v 1.143 2005/11/05 00:08:33 wessels Exp $ + * $Id: store_client.cc,v 1.144 2005/11/07 22:00:38 wessels Exp $ * * DEBUG: section 90 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -481,7 +481,7 @@ storeClientReadBody(void *data, const char *buf, ssize_t len) /* Our structure ! */ HttpReply *rep = (HttpReply *) sc->entry->getReply(); // bypass const - if (!rep->parse(sc->copyInto.data, headersEnd(sc->copyInto.data, len))) { + if (!rep->parseCharBuf(sc->copyInto.data, headersEnd(sc->copyInto.data, len))) { debug (90,0)("Could not parse headers from on disk object\n"); } } @@ -592,7 +592,7 @@ store_client::readHeader(char const *buf, ssize_t len) /* Our structure ! */ HttpReply *rep = (HttpReply *) entry->getReply(); // bypass const - if (!rep->parse(copyInto.data, headersEnd(copyInto.data, copy_sz))) { + if (!rep->parseCharBuf(copyInto.data, headersEnd(copyInto.data, copy_sz))) { debug (90,0)("could not parse headers from on disk structure!\n"); } } diff --git a/src/urn.cc b/src/urn.cc index 7ce0c261eb..e77320098c 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -1,6 +1,6 @@ /* - * $Id: urn.cc,v 1.91 2005/11/05 00:08:33 wessels Exp $ + * $Id: urn.cc,v 1.92 2005/11/07 22:00:38 wessels Exp $ * * DEBUG: section 52 URN Parsing * AUTHOR: Kostas Anagnostakis @@ -368,7 +368,7 @@ urnHandleReply(void *data, StoreIOBuffer result) s = buf + k; assert(urlres_e->getReply()); rep = new HttpReply; - rep->parse(buf, k); + rep->parseCharBuf(buf, k); debug(52, 3) ("reply exists, code=%d.\n", rep->sline.status);