/*
- * $Id: Array.h,v 1.14 2003/07/12 12:42:19 robertc Exp $
+ * $Id: Array.h,v 1.15 2003/07/15 06:50:38 robertc Exp $
*
* AUTHOR: Alex Rousskov
*
#ifndef SQUID_ARRAY_H
#define SQUID_ARRAY_H
-/* see Array.c for more documentation */
-#ifndef __cplusplus
-typedef struct {
- int capacity;
- int count;
- void **items;
-} Array;
-#endif
+/* iterator support */
-#ifdef __cplusplus
+template <class C>
-/* iterator support */
-template <class C> class VectorIteratorBase {
- public:
+class VectorIteratorBase
+{
+
+public:
VectorIteratorBase();
VectorIteratorBase(C &);
VectorIteratorBase(size_t, C &);
VectorIteratorBase & operator ++();
VectorIteratorBase operator ++(int);
typename C::value_type & operator *() const
- {
- return theVector->items[pos];
- }
- typename C::value_type * operator -> () const
- {
- return &theVector->items[pos];
- }
+ {
+ return theVector->items[pos];
+ }
+
+ typename C::value_type * operator -> () const
+ {
+ return &theVector->items[pos];
+ }
+
ssize_t operator - (VectorIteratorBase const &rhs) const;
bool incrementable() const;
- private:
+
+private:
size_t pos;
C * theVector;
};
-
+
template<class E>
-class Vector {
+
+class Vector
+{
+
public:
typedef E value_type;
typedef E* pointer;
typedef VectorIteratorBase<Vector<E> > iterator;
typedef VectorIteratorBase<Vector<E> const> const_iterator;
-
+
void *operator new (size_t);
void operator delete (void *);
-
+
Vector();
~Vector();
Vector(Vector const &);
const_iterator begin () const;
iterator end();
const_iterator end () const;
-
+
/* Do not change these, until the entry C struct is removed */
size_t capacity;
size_t count;
E *items;
};
-typedef Vector<void *> Array;
-
-#endif
-
-SQUIDCEXTERN Array *arrayCreate(void);
-SQUIDCEXTERN void arrayInit(Array * s);
-SQUIDCEXTERN void arrayClean(Array * s);
-SQUIDCEXTERN void arrayDestroy(Array * s);
-SQUIDCEXTERN void arrayAppend(Array * s, void *obj);
-SQUIDCEXTERN void arrayPreAppend(Array * s, int app_count);
-
-#ifdef __cplusplus
-
template<class E>
void *
Vector<E>::operator new(size_t size)
template<class E>
Vector<E>::Vector() : capacity (0), count(0), items (NULL)
-{
-}
+{}
template<class E>
-Vector<E>::~Vector()
+Vector<E>::~Vector()
{
clean();
}
{
const int min_delta = 16;
int delta;
+
if (capacity >= min_capacity)
- return;
+ return;
+
delta = min_capacity;
+
/* make delta a multiple of min_delta */
delta += min_delta - 1;
+
delta /= min_delta;
+
delta *= min_delta;
+
/* actual grow */
if (delta < 0)
- delta = min_capacity - capacity;
+ delta = min_capacity - capacity;
+
E*newitems = new E[capacity + delta];
+
for (size_t counter = 0; counter < size(); ++counter) {
- newitems[counter] = items[counter];
+ newitems[counter] = items[counter];
}
+
capacity += delta;
delete[]items;
items = newitems;
Vector<E>::push_back(E obj)
{
if (size() >= capacity)
- reserve (size() + 1);
+ reserve (size() + 1);
+
items[count++] = obj;
}
Vector<E>::preAppend(int app_count)
{
if (size() + app_count > capacity)
- reserve(size() + app_count);
+ reserve(size() + app_count);
}
template<class E>
{
clean();
reserve (old.size());
+
for (size_t counter = 0; counter < old.size(); ++counter)
- push_back (old.items[counter]);
+ push_back (old.items[counter]);
+
return *this;
}
template<class C>
VectorIteratorBase<C>::VectorIteratorBase() : pos(0), theVector(NULL)
-{
-}
+{}
template<class C>
VectorIteratorBase<C>::VectorIteratorBase(C &container) : pos(container.begin()), theVector(&container)
-{
-}
+{}
template<class C>
VectorIteratorBase<C>::VectorIteratorBase(size_t aPos, C &container) : pos(aPos), theVector(&container) {}
}
template<class C>
-bool
+bool
VectorIteratorBase<C>::incrementable() const
{
assert (theVector);
VectorIteratorBase<C> & VectorIteratorBase<C>:: operator ++()
{
assert (theVector);
+
if (!incrementable())
- fatal ("domain error");
+ fatal ("domain error");
+
++pos;
+
return *this;
}
template<class C>
VectorIteratorBase<C>&
-VectorIteratorBase<C>::operator =(VectorIteratorBase const &old) {
+VectorIteratorBase<C>::operator =(VectorIteratorBase const &old)
+{
pos = old.pos;
theVector = old.theVector;
return *this;
assert(theVector == rhs.theVector);
return pos - rhs.pos;
}
-#endif
#endif /* SQUID_ARRAY_H */
## Process this file with automake to produce Makefile.in
#
-# $Id: Makefile.am,v 1.11 2003/06/19 13:12:00 robertc Exp $
+# $Id: Makefile.am,v 1.12 2003/07/15 06:50:38 robertc Exp $
#
SUBDIRS = libTrie
snprintf.c
libmiscutil_a_SOURCES = \
MemPool.c \
- Array.cc \
base64.c \
getfullhostname.c \
hash.c \
/*
- * $Id: HttpHeader.cc,v 1.92 2003/07/14 14:15:56 robertc Exp $
+ * $Id: HttpHeader.cc,v 1.93 2003/07/15 06:50:39 robertc Exp $
*
* DEBUG: section 55 HTTP Header
* AUTHOR: Alex Rousskov
* HttpHeader Implementation
*/
-void
-httpHeaderInit(HttpHeader * hdr, http_hdr_owner_type owner)
+HttpHeader::HttpHeader() : owner (hoNone), len (0)
{
- assert(hdr);
- assert(owner > hoNone && owner <= hoReply);
- debug(55, 7) ("init-ing hdr: %p owner: %d\n", hdr, owner);
- memset(hdr, 0, sizeof(*hdr));
- hdr->owner = owner;
- arrayInit(&hdr->entries);
+ httpHeaderMaskInit(&mask, 0);
+}
+
+HttpHeader::HttpHeader(http_hdr_owner_type const &anOwner) : owner (anOwner), len (0)
+{
+ assert(this);
+ assert(anOwner > hoNone && anOwner <= hoReply);
+ debug(55, 7) ("init-ing hdr: %p owner: %d\n", this, owner);
+ httpHeaderMaskInit(&mask, 0);
+}
+
+HttpHeader::~HttpHeader()
+{
+ httpHeaderClean (this);
}
void
}
}
- arrayClean(&hdr->entries);
+ hdr->entries.clean();
}
/* append entries (also see httpHeaderUpdate) */
assert(hdr);
ho = hdr->owner;
httpHeaderClean(hdr);
- httpHeaderInit(hdr, ho);
+ *hdr = HttpHeader(ho);
return 0;
}
else
CBIT_SET(hdr->mask, e->id);
- arrayAppend(&hdr->entries, e);
+ hdr->entries.push_back(e);
/* increment header length, allow for ": " and crlf */
hdr->len += e->name.size() + 2 + e->value.size() + 2;
/*
- * $Id: HttpHeader.h,v 1.5 2003/07/14 14:15:56 robertc Exp $
+ * $Id: HttpHeader.h,v 1.6 2003/07/15 06:50:39 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
{
public:
+ HttpHeader();
+ HttpHeader(http_hdr_owner_type const &owner);
+ ~HttpHeader();
/* Interface functions */
void update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask);
void removeConnectionHeaderEntries();
/* protected, do not use these, use interface functions instead */
- Array entries; /* parsed fields in raw format */
+ Vector<HttpHeaderEntry *> entries; /* parsed fields in raw format */
HttpHeaderMask mask; /* bit set <=> entry present */
http_hdr_owner_type owner; /* request or reply */
int len; /* length when packed, not counting terminating '\0' */
/*
- * $Id: HttpReply.cc,v 1.61 2003/07/14 08:21:56 robertc Exp $
+ * $Id: HttpReply.cc,v 1.62 2003/07/15 06:50:39 robertc Exp $
*
* DEBUG: section 58 HTTP Reply (Response)
* AUTHOR: Alex Rousskov
/* local routines */
-static void httpReplyInit(HttpReply * rep);
static void httpReplyClean(HttpReply * rep);
static void httpReplyDoDestroy(HttpReply * rep);
static void httpReplyHdrCacheInit(HttpReply * rep);
{
HttpReply *rep = new HttpReply;
debug(58, 7) ("creating rep: %p\n", rep);
- httpReplyInit(rep);
return rep;
}
-static void
-httpReplyInit(HttpReply * rep)
+HttpReply::HttpReply() : hdr_sz (0), content_length (0), date (0), last_modified (0), expires (0), cache_control (NULL), surrogate_control (NULL), content_range (NULL), keep_alive (0), pstate(psReadyToParseStartLine), header (hoReply)
{
- assert(rep);
- rep->hdr_sz = 0;
- rep->pstate = psReadyToParseStartLine;
- httpBodyInit(&rep->body);
- httpHeaderInit(&rep->header, hoReply);
- httpReplyHdrCacheInit(rep);
- httpStatusLineInit(&rep->sline);
+ assert(this);
+ httpBodyInit(&body);
+ httpReplyHdrCacheInit(this);
+ httpStatusLineInit(&sline);
+
}
static void
httpReplyReset(HttpReply * rep)
{
httpReplyClean(rep);
- httpReplyInit(rep);
+ *rep = HttpReply();
}
/* absorb: copy the contents of a new reply to the old one, destroy new one */
/*
- * $Id: HttpReply.h,v 1.4 2003/07/14 14:15:56 robertc Exp $
+ * $Id: HttpReply.h,v 1.5 2003/07/15 06:50:39 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
public:
void *operator new (size_t);
void operator delete (void *);
+ HttpReply();
/* unsupported, writable, may disappear/change in the future */
int hdr_sz; /* sums _stored_ status-line, headers, and <CRLF> */
/*
- * $Id: HttpRequest.cc,v 1.39 2003/07/11 01:40:34 robertc Exp $
+ * $Id: HttpRequest.cc,v 1.40 2003/07/15 06:50:41 robertc Exp $
*
* DEBUG: section 73 HTTP Request
* AUTHOR: Duane Wessels
static void httpRequestHdrCacheInit(request_t * req);
+void *
+HttpRequest::operator new(size_t amount)
+{
+ // Todo: assign private pool.
+ return static_cast<request_t *>(memAllocate(MEM_REQUEST_T));
+}
+
+void
+HttpRequest::operator delete(void *address)
+{
+ memFree(address, MEM_REQUEST_T);
+}
+
+void
+HttpRequest::deleteSelf() const
+{
+ delete this;
+}
+
+HttpRequest::HttpRequest() : header(hoRequest)
+{
+ /* We should initialise these ... */
+#if 0
+ method_t method;
+ protocol_t protocol;
+ char login[MAX_LOGIN_SZ];
+ char host[SQUIDHOSTNAMELEN + 1];
+ auth_user_request_t *auth_user_request;
+ u_short port;
+ String urlpath;
+ char *canonical;
+ int link_count; /* free when zero */
+ request_flags flags;
+ HttpHdrCc *cache_control;
+ HttpHdrRange *range;
+ http_version_t http_ver;
+ time_t ims;
+ int imslen;
+ int max_forwards;
+ /* these in_addr's could probably be sockaddr_in's */
+
+ struct in_addr client_addr;
+
+ struct in_addr my_addr;
+ unsigned short my_port;
+ unsigned short client_port;
+ HttpHeader header;
+ ConnStateData::Pointer body_connection; /* used by clientReadBody() */
+ int content_length;
+ HierarchyLogEntry hier;
+ err_type errType;
+ char *peer_login; /* Configured peer login:password */
+ time_t lastmod; /* Used on refreshes */
+ const char *vary_headers; /* Used when varying entities are detected. Changes how the store key is calculated */
+ char *peer_domain; /* Configured peer forceddomain */
+#endif
+}
+
request_t *
requestCreate(method_t method, protocol_t protocol, const char *aUrlpath)
{
- request_t *req = static_cast<request_t *>(memAllocate(MEM_REQUEST_T));
+ request_t *req = new HttpRequest;
req->method = method;
req->protocol = protocol;
req->my_addr = no_addr;
- httpHeaderInit(&req->header, hoRequest);
-
httpRequestHdrCacheInit(req);
return req;
req->extacl_log.clean();
- memFree(req, MEM_REQUEST_T);
+ req->deleteSelf();
}
request_t *
/*
- * $Id: HttpRequest.h,v 1.3 2003/07/14 14:15:56 robertc Exp $
+ * $Id: HttpRequest.h,v 1.4 2003/07/15 06:50:41 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
class HttpHdrRange;
-class request_t
+class HttpRequest
{
public:
+ void *operator new(size_t);
+ void operator delete(void *);
+ virtual void deleteSelf() const;
+ HttpRequest();
+ virtual ~HttpRequest() {}
+
bool multipartRangeRequest() const;
method_t method;
String extacl_log; /* String to be used for access.log purposes */
};
+typedef HttpRequest request_t;
#endif /* SQUID_HTTPREQUEST_H */
/*
- * $Id: client_side.cc,v 1.650 2003/07/13 23:00:09 robertc Exp $
+ * $Id: client_side.cc,v 1.651 2003/07/15 06:50:41 robertc Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
static void
clientPackRangeHdr(const HttpReply * rep, const HttpHdrRangeSpec * spec, String boundary, MemBuf * mb)
{
- HttpHeader hdr;
+ HttpHeader hdr(hoReply);
Packer p;
assert(rep);
assert(spec);
memBufPrintf(mb, "\r\n--%s\r\n", boundary.buf());
/* stuff the header with required entries and pack it */
- httpHeaderInit(&hdr, hoReply);
if (httpHeaderHas(&rep->header, HDR_CONTENT_TYPE))
httpHeaderPutStr(&hdr, HDR_CONTENT_TYPE, httpHeaderGetStr(&rep->header, HDR_CONTENT_TYPE));
/*
- * $Id: fde.h,v 1.4 2003/06/23 14:13:03 robertc Exp $
+ * $Id: fde.h,v 1.5 2003/07/15 06:50:42 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
{
public:
+ /* NOTE: memset is used on fdes today. 20030715 RBC */
static void DumpStats (StoreEntry *);
char const *remoteAddr() const;
/*
- * $Id: htcp.cc,v 1.53 2003/07/14 14:16:00 robertc Exp $
+ * $Id: htcp.cc,v 1.54 2003/07/15 06:50:42 robertc Exp $
*
* DEBUG: section 31 Hypertext Caching Protocol
* AUTHOR: Duane Wesssels
{
htcpStuff stuff;
char *pkt;
- HttpHeader hdr;
+ HttpHeader hdr(hoHtcpReply);
MemBuf mb;
Packer p;
ssize_t pktlen;
{
memBufDefInit(&mb);
packerToMemInit(&p, &mb);
- httpHeaderInit(&hdr, hoHtcpReply);
stuff.S.method = spec->method;
stuff.S.uri = spec->uri;
stuff.S.version = spec->version;
htcpHandleTstResponse(hdr, buf, sz, from);
}
+HtcpReplyData::HtcpReplyData() : hdr(hoHtcpReply)
+{}
+
static void
htcpHandleTstResponse(htcpDataHeader * hdr, char *buf, int sz, struct sockaddr_in *from)
return;
}
- memset(&htcpReply, '\0', sizeof(htcpReply));
- httpHeaderInit(&htcpReply.hdr, hoHtcpReply);
htcpReply.msg_id = hdr->msg_id;
debug(31, 3) ("htcpHandleTstResponse: msg_id = %d\n", (int) htcpReply.msg_id);
htcpReply.hit = hdr->response ? 0 : 1;
ssize_t pktlen;
char vbuf[32];
htcpStuff stuff;
- HttpHeader hdr;
+ HttpHeader hdr(hoRequest);
Packer pa;
MemBuf mb;
http_state_flags flags;
/*
- * $Id: htcp.h,v 1.3 2003/07/14 14:16:00 robertc Exp $
+ * $Id: htcp.h,v 1.4 2003/07/15 06:50:42 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
#if USE_HTCP
#include "HttpHeader.h"
-struct _htcpReplyData
+class HtcpReplyData
{
+
+public:
+ HtcpReplyData();
int hit;
HttpHeader hdr;
u_int32_t msg_id;
cto;
};
+typedef class HtcpReplyData htcpReplyData;
+
+SQUIDCEXTERN void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct sockaddr_in *);
+SQUIDCEXTERN void htcpInit(void);
+SQUIDCEXTERN void htcpQuery(StoreEntry * e, request_t * req, peer * p);
+SQUIDCEXTERN void htcpSocketShutdown(void);
+SQUIDCEXTERN void htcpSocketClose(void);
+
#endif
#endif /* SQUID_HTCP_H */
/*
- * $Id: http.cc,v 1.419 2003/07/14 14:16:00 robertc Exp $
+ * $Id: http.cc,v 1.420 2003/07/15 06:50:42 robertc Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
const HttpHeaderEntry *e;
String strFwd;
HttpHeaderPos pos = HttpHeaderInitPos;
- httpHeaderInit(hdr_out, hoRequest);
+ assert (hdr_out->owner == hoRequest);
/* append our IMS header */
if (request->lastmod > -1 && request->method == METHOD_GET)
httpver.major,httpver.minor);
/* build and pack headers */
{
- HttpHeader hdr;
+ HttpHeader hdr(hoRequest);
Packer p;
httpBuildRequestHeader(request, orig_request, entry, &hdr, flags);
packerToMemInit(&p, mb);
/*
- * $Id: main.cc,v 1.383 2003/07/06 15:30:42 hno Exp $
+ * $Id: main.cc,v 1.384 2003/07/15 06:50:42 robertc Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
#include "Mem.h"
#include "ACLASN.h"
#include "ACL.h"
+#include "htcp.h"
#if USE_WIN32_SERVICE
/*
- * $Id: protos.h,v 1.482 2003/07/14 14:16:01 robertc Exp $
+ * $Id: protos.h,v 1.483 2003/07/15 06:50:42 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
SQUIDCEXTERN void httpHeaderInitModule(void);
SQUIDCEXTERN void httpHeaderCleanModule(void);
/* init/clean */
-SQUIDCEXTERN void httpHeaderInit(HttpHeader * hdr, http_hdr_owner_type owner);
SQUIDCEXTERN void httpHeaderClean(HttpHeader * hdr);
/* append/update */
SQUIDCEXTERN void httpHeaderAppend(HttpHeader * dest, const HttpHeader * src);
SQUIDCEXTERN int peerHTTPOkay(const peer *, request_t *);
SQUIDCEXTERN peer *whichPeer(const struct sockaddr_in *from);
-#if USE_HTCP
-
-SQUIDCEXTERN void neighborsHtcpReply(const cache_key *, htcpReplyData *, const struct sockaddr_in *);
-#endif
SQUIDCEXTERN void netdbInit(void);
SQUIDCEXTERN char *strwordtok(char *buf, char **t);
SQUIDCEXTERN void strwordquote(MemBuf * mb, const char *str);
-#if USE_HTCP
-SQUIDCEXTERN void htcpInit(void);
-SQUIDCEXTERN void htcpQuery(StoreEntry * e, request_t * req, peer * p);
-SQUIDCEXTERN void htcpSocketShutdown(void);
-SQUIDCEXTERN void htcpSocketClose(void);
-#endif
/*
/*
- * $Id: structs.h,v 1.472 2003/07/14 14:16:02 robertc Exp $
+ * $Id: structs.h,v 1.473 2003/07/15 06:50:42 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
struct _AccessLogEntry
{
+ /* NB: memset is used on AccessLogEntries as at 20030715 RBC */
const char *url;
struct
/*
- * $Id: tunnel.cc,v 1.142 2003/07/10 11:04:07 robertc Exp $
+ * $Id: tunnel.cc,v 1.143 2003/07/15 06:50:43 robertc Exp $
*
* DEBUG: section 26 Secure Sockets Layer Proxy
* AUTHOR: Duane Wessels
{
SslStateData *sslState = (SslStateData *)data;
MemBuf mb;
- HttpHeader hdr_out;
+ HttpHeader hdr_out(hoRequest);
Packer p;
http_state_flags flags;
debug(26, 3) ("sslProxyConnected: FD %d sslState=%p\n", fd, sslState);
/*
- * $Id: typedefs.h,v 1.165 2003/07/14 14:16:02 robertc Exp $
+ * $Id: typedefs.h,v 1.166 2003/07/15 06:50:43 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
typedef struct _body_size body_size;
-class request_t;
+typedef struct HttpRequest request_t;
typedef struct _AccessLogEntry AccessLogEntry;
/* a common objPackInto interface; used by debugObj */
typedef void (*ObjPackMethod) (void *obj, Packer * p);
-#if USE_HTCP
-
-typedef struct _htcpReplyData htcpReplyData;
-#endif
-
typedef RemovalPolicy *REMOVALPOLICYCREATE(wordlist * args);
typedef int STDIRSELECT(const StoreEntry *);