From: wessels <> Date: Mon, 19 Sep 2005 23:30:23 +0000 (+0000) Subject: Added an implementation of parseFirstLine() for class HttpRequest X-Git-Tag: SQUID_3_0_PRE4~607 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=863d85ee0444590909c991dc54da448c61f67365;p=thirdparty%2Fsquid.git Added an implementation of parseFirstLine() for class HttpRequest --- diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index c926f8ddc7..90696661d6 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpRequest.cc,v 1.52 2005/09/17 04:53:44 wessels Exp $ + * $Id: HttpRequest.cc,v 1.53 2005/09/19 17:30:23 wessels Exp $ * * DEBUG: section 73 HTTP Request * AUTHOR: Duane Wessels @@ -162,8 +162,48 @@ bool HttpRequest::sanityCheckStartLine(MemBuf *buf, http_status *error) bool HttpRequest::parseFirstLine(const char *start, const char *end) { - fatal("HttpRequest::parseFirstLine not implemented yet"); - return false; + const char *t = start + strcspn(start, w_space); + method = urlParseMethod(start, t); + + if (METHOD_NONE == method) + return false; + + start = t + strspn(t, w_space); + + const char *ver = findTrailingHTTPVersion(start, end); + + if (ver) { + end = ver - 1; + + while (xisspace(*end)) // find prev non-space + end--; + + end++; // back to space + + if (2 != sscanf(ver + 5, "%d.%d", &http_ver.major, &http_ver.minor)) { + debug(73, 1) ("parseRequestLine: Invalid HTTP identifier.\n"); + return false; + } + } else { + http_ver.major = 0; + http_ver.minor = 9; + } + + if (end < start) // missing URI + return false; + + char save = *end; + + * (char *) end = '\0'; // temp terminate URI, XXX dangerous? + + HttpRequest *tmp = urlParse(method, (char *) start, this); + + * (char *) end = save; + + if (NULL == tmp) + return false; + + return true; } HttpRequest *