From: Amos Jeffries Date: Mon, 20 Feb 2017 04:56:00 +0000 (+1300) Subject: SourceLayout: move HttpMsgParseState into Http::Message class X-Git-Tag: M-staged-PR71~258 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fb654382eae60a16493d525301dbc572ccef598c;p=thirdparty%2Fsquid.git SourceLayout: move HttpMsgParseState into Http::Message class --- diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 16057b7e72..a0a0abedae 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -43,7 +43,7 @@ HttpReply::init() { hdrCacheInit(); sline.init(); - pstate = psReadyToParseStartLine; + pstate = Http::Message::psReadyToParseStartLine; do_clean = true; } diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index bcd0b7fa65..9cca8cbe39 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -99,7 +99,7 @@ HttpRequest::init() #endif extacl_log = null_string; extacl_message = null_string; - pstate = psReadyToParseStartLine; + pstate = Http::Message::psReadyToParseStartLine; #if FOLLOW_X_FORWARDED_FOR indirect_client_addr.setEmpty(); #endif /* FOLLOW_X_FORWARDED_FOR */ diff --git a/src/MemStore.cc b/src/MemStore.cc index c858a851af..fed280c389 100644 --- a/src/MemStore.cc +++ b/src/MemStore.cc @@ -568,7 +568,7 @@ MemStore::copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof) // from store_client::readBody() // parse headers if needed; they might span multiple slices! HttpReply *rep = (HttpReply *)e.getReply(); - if (rep->pstate < psParsed) { + if (rep->pstate < Http::Message::psParsed) { // XXX: have to copy because httpMsgParseStep() requires 0-termination MemBuf mb; mb.init(buf.length+1, buf.length+1); @@ -576,7 +576,7 @@ MemStore::copyFromShmSlice(StoreEntry &e, const StoreIOBuffer &buf, bool eof) mb.terminate(); const int result = rep->httpMsgParseStep(mb.buf, buf.length, eof); if (result > 0) { - assert(rep->pstate == psParsed); + assert(rep->pstate == Http::Message::psParsed); EBIT_CLR(e.flags, ENTRY_FWD_HDR_WAIT); } else if (result < 0) { debugs(20, DBG_IMPORTANT, "Corrupted mem-cached headers: " << e); diff --git a/src/enums.h b/src/enums.h index f417be3192..db8a2e1d60 100644 --- a/src/enums.h +++ b/src/enums.h @@ -123,14 +123,6 @@ enum { STORE_LOG_SWAPOUTFAIL }; -/* parse state of HttpReply or HttpRequest */ -typedef enum { - psReadyToParseStartLine = 0, - psReadyToParseHeaders, - psParsed, - psError -} HttpMsgParseState; - enum { PCTILE_HTTP, PCTILE_ICP_QUERY, diff --git a/src/http/Message.cc b/src/http/Message.cc index 4ba0c98d66..b5e699b511 100644 --- a/src/http/Message.cc +++ b/src/http/Message.cc @@ -48,13 +48,6 @@ Http::Message::putCc(const HttpHdrCc *otherCc) } } -HttpMsgParseState &operator++ (HttpMsgParseState &aState) -{ - int tmp = (int)aState; - aState = (HttpMsgParseState)(++tmp); - return aState; -} - /* find first CRLF */ static int httpMsgIsolateStart(const char **parse_start, const char **blk_start, const char **blk_end) @@ -180,13 +173,13 @@ Http::Message::httpMsgParseStep(const char *buf, int len, int atEnd) const char *blk_start, *blk_end; const char **parse_end_ptr = &blk_end; assert(parse_start); - assert(pstate < psParsed); + assert(pstate < Http::Message::psParsed); *parse_end_ptr = parse_start; PROF_start(HttpMsg_httpMsgParseStep); - if (pstate == psReadyToParseStartLine) { + if (pstate == Http::Message::psReadyToParseStartLine) { if (!httpMsgIsolateStart(&parse_start, &blk_start, &blk_end)) { PROF_stop(HttpMsg_httpMsgParseStep); return 0; @@ -202,7 +195,7 @@ Http::Message::httpMsgParseStep(const char *buf, int len, int atEnd) hdr_sz = *parse_end_ptr - buf; parse_len = parse_len - hdr_sz; - ++pstate; + pstate = Http::Message::psReadyToParseHeaders; } /* @@ -210,7 +203,7 @@ Http::Message::httpMsgParseStep(const char *buf, int len, int atEnd) * this code might not actually be given parse_start at the right spot (just * after headers.) Grr. */ - if (pstate == psReadyToParseHeaders) { + if (pstate == Http::Message::psReadyToParseHeaders) { size_t hsize = 0; const int parsed = header.parse(parse_start, parse_len, atEnd, hsize); if (parsed <= 0) { @@ -219,7 +212,7 @@ Http::Message::httpMsgParseStep(const char *buf, int len, int atEnd) } hdr_sz += hsize; hdrCacheInit(); - ++pstate; + pstate = Http::Message::psParsed; } PROF_stop(HttpMsg_httpMsgParseStep); @@ -233,13 +226,13 @@ Http::Message::parseHeader(Http1::Parser &hp) // zero does not need parsing // XXX: c_str() reallocates. performance regression. if (hp.headerBlockSize() && !header.parse(hp.mimeHeader().c_str(), hp.headerBlockSize())) { - pstate = psError; + pstate = Http::Message::psError; return false; } // XXX: we are just parsing HTTP headers, not the whole message prefix here hdr_sz = hp.messageHeaderSize(); - pstate = psParsed; + pstate = Http::Message::psParsed; hdrCacheInit(); return true; } diff --git a/src/http/Message.h b/src/http/Message.h index 6c4d1a2d0f..9dcb79a520 100644 --- a/src/http/Message.h +++ b/src/http/Message.h @@ -82,8 +82,16 @@ public: int64_t content_length = 0; + /// parse state of HttpReply or HttpRequest + enum ParseState { + psReadyToParseStartLine = 0, + psReadyToParseHeaders, + psParsed, + psError + }; + /// the current parsing state - HttpMsgParseState pstate = psReadyToParseStartLine; + ParseState pstate = Http::Message::psReadyToParseStartLine; /// optional pipeline to receive message body BodyPipe::Pointer body_pipe;