as requestCreate() and requestDestroy() and fixed up the clean/reset mess.
/*
- * $Id: HttpRequest.cc,v 1.56 2006/01/09 19:59:37 wessels Exp $
+ * $Id: HttpRequest.cc,v 1.57 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 73 HTTP Request
* AUTHOR: Duane Wessels
#include "HttpHeaderRange.h"
#include "MemBuf.h"
-HttpRequest::HttpRequest() : HttpMsg(hoRequest)
+HttpRequest::HttpRequest() : HttpMsg(hoRequest), link_count(0)
{
+ init();
+}
+
+HttpRequest::HttpRequest(method_t aMethod, protocol_t aProtocol, const char *aUrlpath) : HttpMsg(hoRequest),link_count(0)
+{
+ init();
+ initXX(aMethod, aProtocol, aUrlpath);
+}
+
+HttpRequest::~HttpRequest()
+{
+ assert(link_count == 0);
+ clean();
+}
+
+void
+HttpRequest::initXX(method_t aMethod, protocol_t aProtocol, const char *aUrlpath)
+{
+ method = aMethod;
+ protocol = aProtocol;
+ urlpath = aUrlpath;
+}
+
+void
+HttpRequest::init()
+{
+ /*
+ * NOTE: init() and clean() do NOT touch link_count!
+ */
method = METHOD_NONE;
+ protocol = PROTO_NONE;
+ urlpath = NULL;
login[0] = '\0';
host[0] = '\0';
auth_user_request = NULL;
port = 0;
canonical = NULL;
- link_count = 0;
memset(&flags, '\0', sizeof(flags));
range = NULL;
ims = -1;
imslen = 0;
- max_forwards = 0;
- client_addr.s_addr = no_addr.s_addr;
- my_addr.s_addr = no_addr.s_addr;
+ lastmod = -1;
+ max_forwards = -1;
+ client_addr = no_addr;
+ my_addr = no_addr;
my_port = 0;
client_port = 0;
body_connection = NULL;
// hier
errType = ERR_NONE;
- peer_login = NULL;
- lastmod = -1;
+ peer_login = NULL; // not allocated/deallocated by this class
+ peer_domain = NULL; // not allocated/deallocated by this class
vary_headers = NULL;
- peer_domain = NULL;
- tag = "";
- extacl_user = "";
- extacl_passwd = "";
- extacl_log = "";
-}
-
-HttpRequest *
-requestCreate(method_t method, protocol_t protocol, const char *aUrlpath)
-{
- HttpRequest *req = new HttpRequest;
- req->method = method;
- req->protocol = protocol;
-
- if (aUrlpath)
- req->urlpath = aUrlpath;
-
- req->max_forwards = -1;
-
- req->lastmod = -1;
-
- req->client_addr = no_addr;
-
- req->my_addr = no_addr;
-
- return req;
-}
-
-void HttpRequest::reset()
-{
- int lc = link_count;
- clean();
- *this = HttpRequest(); // XXX: ugly; merge with clean()
- link_count = lc;
+ tag = null_string;
+ extacl_user = null_string;
+ extacl_passwd = null_string;
+ extacl_log = null_string;
}
void
-requestDestroy(HttpRequest * req)
+HttpRequest::clean()
{
- assert(req);
- req->clean();
- delete req;
-}
+ /*
+ * NOTE: init() and clean() do NOT touch link_count!
+ */
-// note: this is a very low-level method that leaves us in inconsistent state
-// suitable for deletion or assignment only; XXX: should be merged with reset()
-void HttpRequest::clean()
-{
if (body_connection.getRaw() != NULL)
fatal ("request being destroyed with body connection intact\n");
- if (auth_user_request)
+ if (auth_user_request) {
auth_user_request->unlock();
+ auth_user_request = NULL;
+ }
safe_free(canonical);
cache_control = NULL;
}
- if (range)
+ if (range) {
delete range;
+ range = NULL;
+ }
tag.clean();
extacl_log.clean();
}
+void
+HttpRequest::reset()
+{
+ clean();
+ init();
+}
+
bool HttpRequest::sanityCheckStartLine(MemBuf *buf, http_status *error)
{
/*
return true;
}
-
HttpRequest *
requestLink(HttpRequest * request)
{
if (--request->link_count > 0)
return;
- requestDestroy(request);
+ delete request;
}
int
/* swaps out request using httpRequestPack */
void
-httpRequestSwapOut(const HttpRequest * req, StoreEntry * e)
+HttpRequest::swapOut(StoreEntry * e)
{
Packer p;
- assert(req && e);
+ assert(e);
packerToStoreInit(&p, e);
- httpRequestPack(req, &p);
+ pack(&p);
packerClean(&p);
}
/* packs request-line and headers, appends <crlf> terminator */
void
-httpRequestPack(const HttpRequest * req, Packer * p)
+HttpRequest::pack(Packer * p)
{
- assert(req && p);
+ assert(p);
/* pack request-line */
packerPrintf(p, "%s %s HTTP/1.0\r\n",
- RequestMethodStr[req->method], req->urlpath.buf());
+ RequestMethodStr[method], urlpath.buf());
/* headers */
- httpHeaderPackInto(&req->header, p);
+ httpHeaderPackInto(&header, p);
/* trailer */
packerAppend(p, "\r\n", 2);
}
-#if UNUSED_CODE
+/*
+ * A wrapper for debugObj()
+ */
void
-httpRequestSetHeaders(HttpRequest * req, method_t method, const char *uri, const char *header_str)
+httpRequestPack(void *obj, Packer *p)
{
- assert(req && uri && header_str);
- assert(!req->header.len);
- httpHeaderParse(&req->header, header_str, header_str + strlen(header_str));
+ HttpRequest *request = static_cast<HttpRequest*>(obj);
+ request->pack(p);
}
-#endif
-
/* returns the length of request line + headers + crlf */
int
-httpRequestPrefixLen(const HttpRequest * req)
+HttpRequest::prefixLen()
{
- assert(req);
- return strlen(RequestMethodStr[req->method]) + 1 +
- req->urlpath.size() + 1 +
+ return strlen(RequestMethodStr[method]) + 1 +
+ urlpath.size() + 1 +
4 + 1 + 3 + 2 +
- req->header.len + 2;
+ header.len + 2;
}
/*
/*
- * $Id: HttpRequest.h,v 1.15 2005/11/21 22:50:16 wessels Exp $
+ * $Id: HttpRequest.h,v 1.16 2006/01/19 18:40:28 wessels Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
#include "HierarchyLogEntry.h"
/* Http Request */
-extern HttpRequest *requestCreate(method_t, protocol_t, const char *urlpath);
-extern void requestDestroy(HttpRequest *);
extern HttpRequest *requestLink(HttpRequest *);
extern void requestUnlink(HttpRequest *);
-extern void httpRequestSwapOut(const HttpRequest * req, StoreEntry * e);
-extern void httpRequestPack(const HttpRequest * req, Packer * p);
-extern int httpRequestPrefixLen(const HttpRequest * req);
extern int httpRequestHdrAllowed(const HttpHeaderEntry * e, String * strConnection);
extern int httpRequestHdrAllowedByName(http_hdr_type id);
+extern void httpRequestPack(void *obj, Packer *p);
+
class HttpHdrRange;
public:
MEMPROXY_CLASS(HttpRequest);
HttpRequest();
-
+ HttpRequest(method_t aMethod, protocol_t aProtocol, const char *aUrlpath);
+ ~HttpRequest();
virtual void reset();
- bool multipartRangeRequest() const;
+protected:
+ void initXX(method_t aMethod, protocol_t aProtocol, const char *aUrlpath);
+ void clean();
+ void init();
+
+public:
+ int link_count; /* free when zero */
+public:
method_t method;
char login[MAX_LOGIN_SZ];
char host[SQUIDHOSTNAMELEN + 1];
u_short port;
String urlpath;
char *canonical;
- int link_count; /* free when zero */
request_flags flags;
HttpHdrRange *range;
time_t ims;
String extacl_log; /* String to be used for access.log purposes */
public:
+ bool multipartRangeRequest() const;
bool parseFirstLine(const char *start, const char *end);
int parseHeader(const char *parse_start);
virtual bool expectingBody(method_t unused, ssize_t&) const;
+ int prefixLen();
+ void swapOut(StoreEntry * e);
+ void pack(Packer * p);
+ static void httpRequestPack(void *obj, Packer *p);
private:
const char *packableURI(bool full_uri) const;
virtual bool sanityCheckStartLine(MemBuf *buf, http_status *error);
virtual void hdrCacheInit();
-public: // should be private
- void clean(); // low-level; treat as private
};
MEMPROXY_CLASS_INLINE(HttpRequest)
/*
- * $Id: client_side_reply.cc,v 1.92 2006/01/03 17:22:30 wessels Exp $
+ * $Id: client_side_reply.cc,v 1.93 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 88 Client-side Reply Routines
* AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c)
rep = new HttpReply;
HttpVersion version(1,0);
rep->setHeaders(version, HTTP_OK, NULL, "text/plain",
- httpRequestPrefixLen(http->request), 0, squid_curtime);
+ http->request->prefixLen(), 0, squid_curtime);
rep->swapOut(http->storeEntry());
- httpRequestSwapOut(http->request, http->storeEntry());
+ http->request->swapOut(http->storeEntry());
http->storeEntry()->complete();
}
*/
if (http->request == NULL)
- http->request = requestLink(requestCreate(m, PROTO_NONE, null_string));
+ http->request = requestLink(new HttpRequest(m, PROTO_NONE, null_string));
StoreEntry *e = storeCreateEntry(http->uri, http->log_uri, flags, m);
/*
- * $Id: htcp.cc,v 1.61 2006/01/04 17:19:41 wessels Exp $
+ * $Id: htcp.cc,v 1.62 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 31 Hypertext Caching Protocol
* AUTHOR: Duane Wesssels
if (!httpHeaderParse(&checkHitRequest->header, req_hdrs, blk_end)) {
debug(31, 3) ("htcpCheckHit: NO; failed to parse request headers\n");
- requestDestroy(checkHitRequest);
+ delete checkHitRequest;
checkHitRequest = NULL;
checkedHit(NullStoreEntry::getInstance());
return;
hit = e;
miss:
- requestDestroy(checkHitRequest);
+ delete checkHitRequest;
checkedHit (hit);
}
/*
- * $Id: http.cc,v 1.481 2006/01/09 20:42:35 wessels Exp $
+ * $Id: http.cc,v 1.482 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
else
url = storeUrl(entry);
- HttpRequest * proxy_req = requestCreate(orig_request->method,
- orig_request->protocol, url);
+ HttpRequest * proxy_req = new HttpRequest(orig_request->method,
+ orig_request->protocol, url);
xstrncpy(proxy_req->host, _peer->host, SQUIDHOSTNAMELEN);
/*
- * $Id: icp_v2.cc,v 1.88 2005/12/08 20:08:47 wessels Exp $
+ * $Id: icp_v2.cc,v 1.89 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 12 Internet Cache Protocol
* AUTHOR: Duane Wessels
safe_free(url);
if (request)
- requestDestroy(request);
+ delete request;
}
/*
- * $Id: icp_v3.cc,v 1.39 2003/08/10 11:00:43 robertc Exp $
+ * $Id: icp_v3.cc,v 1.40 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 12 Internet Cache Protocol
* AUTHOR: Duane Wessels
if (!icpAccessAllowed(&from, icp_request))
{
icpDenyAccess (&from, url, header.reqnum, fd);
- requestDestroy(icp_request);
+ delete icp_request;
return;
}
/*
- * $Id: url.cc,v 1.148 2005/11/11 17:45:15 wessels Exp $
+ * $Id: url.cc,v 1.149 2006/01/19 18:40:28 wessels Exp $
*
* DEBUG: section 23 URL Parsing
* AUTHOR: Duane Wessels
}
if (NULL == request)
- request = requestCreate(method, protocol, urlpath);
+ request = new HttpRequest(method, protocol, urlpath);
else {
request->method = method;
request->protocol = protocol;
urnParse(method_t method, char *urn)
{
debug(50, 5) ("urnParse: %s\n", urn);
- return requestCreate(method, PROTO_URN, urn + 4);
+ return new HttpRequest(method, PROTO_URN, urn + 4);
}
const char *