/*
- * $Id: HttpHdrRange.cc,v 1.31 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpHdrRange.cc,v 1.32 2003/03/06 06:21:36 robertc Exp $
*
* DEBUG: section 64 HTTP Range Header
* AUTHOR: Alex Rousskov
debug(64, 8) ("parsing range field: '%s'\n", range_spec->buf());
/* check range type */
- if (range_spec->nCaseCmp("bytes=", 6))
+ if (range_spec->caseCmp("bytes=", 6))
return 0;
/* skip "bytes="; hack! */
/*
- * $Id: HttpHeader.cc,v 1.85 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpHeader.cc,v 1.86 2003/03/06 06:21:36 robertc Exp $
*
* DEBUG: section 55 HTTP Header
* AUTHOR: Alex Rousskov
debug(55, 7) ("deleting '%s' fields in hdr %p\n", name, hdr);
while ((e = httpHeaderGetEntry(hdr, &pos))) {
- if (!strCaseCmp(e->name, name)) {
+ if (!e->name.caseCmp(name)) {
httpHeaderDelAt(hdr, pos);
count++;
} else
String
httpHeaderGetList(const HttpHeader * hdr, http_hdr_type id)
{
- String s = StringNull;
HttpHeaderEntry *e;
HttpHeaderPos pos = HttpHeaderInitPos;
debug(55, 6) ("%p: joining for id %d\n", hdr, id);
assert(CBIT_TEST(ListHeadersMask, id));
if (!CBIT_TEST(hdr->mask, id))
- return s;
+ return String();
+
+ String s;
while ((e = httpHeaderGetEntry(hdr, &pos))) {
if (e->id == id)
if ((e = httpHeaderFindEntry(hdr, id)))
return e->value;
- return String::Null;
+ return String();
}
/*
http_hdr_type id;
HttpHeaderPos pos = HttpHeaderInitPos;
HttpHeaderEntry *e;
- String result = StringNull;
assert(hdr);
assert(name);
if (id != -1)
return httpHeaderGetStrOrList(hdr, id);
+ String result;
+
/* Sorry, an unknown header name. Do linear search */
while ((e = httpHeaderGetEntry(hdr, &pos))) {
- if (e->id == HDR_OTHER && strCaseCmp(e->name, name) == 0) {
+ if (e->id == HDR_OTHER && e->name.caseCmp(name) == 0) {
strListAdd(&result, e->value.buf(), ',');
}
}
String
httpHeaderGetByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator)
{
- String result = StringNull;
String header;
const char *pos = NULL;
const char *item;
header = httpHeaderGetByName(hdr, name);
+ String result;
+
while (strListGetItem(&header, separator, &item, &ilen, &pos)) {
if (strncmp(item, member, mlen) == 0 && item[mlen] == '=') {
result.append(item + mlen + 1, ilen - mlen - 1);
String
httpHeaderGetListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator)
{
- String result = StringNull;
String header;
const char *pos = NULL;
const char *item;
assert(id >= 0);
header = httpHeaderGetStrOrList(hdr, id);
+ String result;
while (strListGetItem(&header, separator, &item, &ilen, &pos)) {
if (strncmp(item, member, mlen) == 0 && item[mlen] == '=') {
/*
- * $Id: HttpHeaderTools.cc,v 1.38 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpHeaderTools.cc,v 1.39 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 66 HTTP Header Tools
* AUTHOR: Alex Rousskov
strListIsSubstr(const String * list, const char *s, char del)
{
assert(list && del);
- return strStr(*list, s) != 0;
+ return list->pos(s) != 0;
/*
* Note: the original code with a loop is broken because it uses strstr()
/*
- * $Id: HttpReply.cc,v 1.54 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpReply.cc,v 1.55 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 58 HTTP Reply (Response)
* AUTHOR: Alex Rousskov
httpHeaderPutStr(hdr, HDR_CONTENT_TYPE, ctype);
reply->content_type = ctype;
} else
- reply->content_type = StringNull;
+ reply->content_type = String();
if (clen >= 0)
httpHeaderPutInt(hdr, HDR_CONTENT_LENGTH, clen);
if (str)
rep->content_type.limitInit(str, strcspn(str, ";\t "));
else
- rep->content_type = StringNull;
+ rep->content_type = String();
rep->cache_control = httpHeaderGetCc(hdr);
/*
- * $Id: HttpRequest.cc,v 1.35 2003/02/21 22:50:05 robertc Exp $
+ * $Id: HttpRequest.cc,v 1.36 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 73 HTTP Request
* AUTHOR: Duane Wessels
if (str)
stringLimitInit(&req->content_type, str, strcspn(str, ";\t "));
else
- req->content_type = StringNull;
+ req->content_type = String();
#endif
/*
- * $Id: SquidString.h,v 1.2 2003/02/21 22:50:06 robertc Exp $
+ * $Id: SquidString.h,v 1.3 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 67 String
* AUTHOR: Duane Wessels
{
public:
- static const String Null;
_SQUID_INLINE_ String();
String (char const *);
String (String const &);
_SQUID_INLINE_ int size() const;
_SQUID_INLINE_ char const * buf() const;
+ void buf(char *);
void init (char const *);
void initBuf(size_t sz);
void limitInit(const char *str, int len);
void append(char const *buf);
void append (String const &);
void absorb(String &old);
- _SQUID_INLINE_ int nCaseCmp (char const *aString, int aLen) const;
+ _SQUID_INLINE_ const char * pos(char const *) const;
+ _SQUID_INLINE_ const char * pos(char const ch) const;
+ _SQUID_INLINE_ const char * rpos(char const ch) const;
+ _SQUID_INLINE_ int cmp (char const *) const;
+ _SQUID_INLINE_ int cmp (char const *, size_t count) const;
+ _SQUID_INLINE_ int caseCmp (char const *) const;
+ _SQUID_INLINE_ int caseCmp (char const *, size_t count) const;
+
+ _SQUID_INLINE_ void set
+ (char const *loc, char const ch);
+
+ _SQUID_INLINE_ void cut (size_t newLength);
+
+ _SQUID_INLINE_ void cutPointer (char const *loc);
private:
/* never reference these directly! */
unsigned short int size_; /* buffer size; 64K limit */
-public:
unsigned short int len_; /* current length */
+
char *buf_;
};
-#define StringNull String::Null;
-/* String */
-#define strChr(s,ch) ((const char*)strchr((s).buf(), (ch)))
-#define strRChr(s,ch) ((const char*)strrchr((s).buf(), (ch)))
-#define strStr(s,str) ((const char*)strstr((s).buf(), (str)))
-#define strCmp(s,str) strcmp((s).buf(), (str))
-#define strNCmp(s,str,n) strncmp((s).buf(), (str), (n))
-#define strCaseCmp(s,str) strcasecmp((s).buf(), (str))
-#define strSet(s,ptr,ch) (s).buf_[ptr-(s).buf_] = (ch)
-#define strCut(s,pos) (((s).len_ = pos) , ((s).buf_[pos] = '\0'))
-#define strCutPtr(s,ptr) (((s).len_ = (ptr)-(s).buf_) , ((s).buf_[(s).len_] = '\0'))
-
#ifdef _USE_INLINE_
#include "String.cci"
#endif
/*
- * $Id: String.cc,v 1.13 2003/02/21 22:50:06 robertc Exp $
+ * $Id: String.cc,v 1.14 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 67 String
* AUTHOR: Duane Wessels
#include "squid.h"
-String const String::Null;
-
void
String::initBuf(size_t sz)
{
old.len_ = 0;
}
+void
+String::buf(char *newBuf)
+{
+ assert (buf_ == NULL);
+ buf_ = newBuf;
+}
+
#ifndef _USE_INLINE_
#include "String.cci"
#endif
/*
- * $Id: String.cci,v 1.1 2003/01/23 00:37:15 robertc Exp $
+ * $Id: String.cci,v 1.2 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 67 String
* AUTHOR: Duane Wessels
*/
String::String() : size_(0), len_(0), buf_ (NULL)
-{
-}
+{}
int
String::size() const
return buf_;
}
+const char *
+String::pos(char const *aString) const
+{
+ return strstr(buf(), aString);
+}
+
+const char *
+String::pos(char const ch) const
+{
+ return strchr(buf(), ch);
+}
+
+const char *
+String::rpos(char const ch) const
+{
+ return strrchr(buf(), (ch));
+}
+
+int
+String::cmp (char const *aString) const
+{
+ return strcmp(buf(), aString);
+}
+
+int
+String::cmp (char const *aString, size_t count) const
+{
+ return strncmp(buf(), aString, count);
+}
+
int
-String::nCaseCmp (char const *aString, int aLen) const
+String::caseCmp (char const *aString) const
{
- return strncasecmp(buf(), aString, aLen);
+ return strcasecmp(buf(), aString);
}
+
+int
+String::caseCmp (char const *aString, size_t count) const
+{
+ return strncasecmp(buf(), aString, count);
+}
+
+void
+
+String::set
+ (char const *loc, char const ch)
+{
+ buf_[loc-buf_] = ch;
+}
+
+void
+String::cut (size_t newLength)
+{
+ len_ = newLength;
+ buf_[newLength] = '\0';
+}
+
+void
+String::cutPointer (char const *loc)
+{
+ len_ = loc-buf_;
+ buf_[len_] = '\0';
+}
+
/*
- * $Id: SwapDir.h,v 1.3 2003/02/21 22:50:06 robertc Exp $
+ * $Id: SwapDir.h,v 1.4 2003/03/06 06:21:37 robertc Exp $
*
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
public:
static SwapDir *Factory (_storefs_entry const &fs);
- SwapDir() : max_objsize (-1)
+ SwapDir() : cur_size (0), low_size(0), max_size(0), max_objsize (-1)
{
fs.blksize = 1024;
}
int removals;
int scanned;
- struct
+ struct Flags
{
+ Flags() : selected(0), read_only(0){}
unsigned int selected:
1;
/*
- * $Id: asn.cc,v 1.91 2003/02/25 12:24:34 robertc Exp $
+ * $Id: asn.cc,v 1.92 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 53 AS Number handling
* AUTHOR: Duane Wessels, Kostas Anagnostakis
while (data) {
prev = data;
data = data->next;
- xfree(prev);
+ prev->deleteSelf();
}
- xfree(data);
+ data->deleteSelf();
}
static int
/*
- * $Id: external_acl.cc,v 1.33 2003/03/04 01:40:27 robertc Exp $
+ * $Id: external_acl.cc,v 1.34 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 82 External ACL
* AUTHOR: Henrik Nordstrom, MARA Systems AB
wordlist *arg;
external_acl_format *format;
request_t *request = ch->request;
- String sb = StringNull;
memBufReset(&mb);
for (format = acl_data->def->format; format; format = format->next) {
const char *str = NULL;
+ String sb;
switch (format->type) {
/*
- * $Id: store_dir_ufs.cc,v 1.56 2003/02/21 22:50:45 robertc Exp $
+ * $Id: store_dir_ufs.cc,v 1.57 2003/03/06 06:21:41 robertc Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
void
UFSSwapDir::maintainfs()
{
+ /* We can't delete objects while rebuilding swap */
+
+ if (store_dirs_rebuilding)
+ return;
+
StoreEntry *e = NULL;
+
int removed = 0;
- int max_scan;
- int max_remove;
- double f;
+
RemovalPurgeWalker *walker;
- /* We can't delete objects while rebuilding swap */
- if (store_dirs_rebuilding) {
- return;
- } else {
- f = (double) (cur_size - low_size) / (max_size - low_size);
- f = f < 0.0 ? 0.0 : f > 1.0 ? 1.0 : f;
- max_scan = (int) (f * 400.0 + 100.0);
- max_remove = (int) (f * 70.0 + 10.0);
- /*
- * This is kinda cheap, but so we need this priority hack?
- */
- }
+ double f = (double) (cur_size - low_size) / (max_size - low_size);
+
+ f = f < 0.0 ? 0.0 : f > 1.0 ? 1.0 : f;
+
+ int max_scan = (int) (f * 400.0 + 100.0);
+
+ int max_remove = (int) (f * 70.0 + 10.0);
+
+ /*
+ * This is kinda cheap, but so we need this priority hack?
+ */
debug(47, 3) ("storeMaintainSwapSpace: f=%f, max_scan=%d, max_remove=%d\n",
f, max_scan, max_remove);
+
walker = repl->PurgeInit(repl, max_scan);
while (1) {
/*
- * $Id: ftp.cc,v 1.346 2003/03/04 01:40:27 robertc Exp $
+ * $Id: ftp.cc,v 1.347 2003/03/06 06:21:37 robertc Exp $
*
* DEBUG: section 9 File Transfer Protocol (FTP)
* AUTHOR: Harvest Derived
int l;
const char *t;
- if ((t = strRChr(request->urlpath, ';')) != NULL) {
+ if ((t = request->urlpath.rpos(';')) != NULL) {
if (strncasecmp(t + 1, "type=", 5) == 0) {
ftpState->typecode = (char) toupper((int) *(t + 6));
- strCutPtr(request->urlpath, t);
+ request->urlpath.cutPointer(t);
}
}
if (!l) {
ftpState->flags.isdir = 1;
ftpState->flags.root_dir = 1;
- } else if (!strCmp(request->urlpath, "/%2f/")) {
+ } else if (!request->urlpath.cmp("/%2f/")) {
/* UNIX root directory */
ftpState->flags.need_base_href = 0;
ftpState->flags.isdir = 1;
if (ftpState->flags.isdir) {
mode = 'A';
} else {
- t = strRChr(ftpState->request->urlpath, '/');
+ t = ftpState->request->urlpath.rpos('/');
filename = t ? t + 1 : ftpState->request->urlpath.buf();
mode = mimeGetTransferMode(filename);
}
if (!ftpState->flags.isdir && /* Not a directory */
!ftpState->flags.try_slash_hack && /* Not in slash hack */
ftpState->mdtm <= 0 && ftpState->size < 0 && /* Not known as a file */
- ftpState->request->urlpath.nCaseCmp("/%2f", 4) != 0) { /* No slash encoded */
+ ftpState->request->urlpath.caseCmp("/%2f", 4) != 0) { /* No slash encoded */
switch (ftpState->state) {
EBIT_CLR(e->flags, ENTRY_FWD_HDR_WAIT);
- filename = (t = strRChr(urlpath, '/')) ? t + 1 : urlpath.buf();
+ filename = (t = urlpath.rpos('/')) ? t + 1 : urlpath.buf();
if (ftpState->flags.isdir) {
mime_type = "text/html";
/*
- * $Id: gopher.cc,v 1.181 2003/03/04 01:40:28 robertc Exp $
+ * $Id: gopher.cc,v 1.182 2003/03/06 06:21:38 robertc Exp $
*
* DEBUG: section 10 Gopher
* AUTHOR: Harvest Derived
char *tline = NULL;
LOCAL_ARRAY(char, line, TEMP_BUF_SIZE);
LOCAL_ARRAY(char, tmpbuf, TEMP_BUF_SIZE);
- String outbuf = StringNull;
char *name = NULL;
char *selector = NULL;
char *host = NULL;
}
inbuf[len] = '\0';
+ String outbuf;
if (!gopherState->HTML_header_added) {
if (gopherState->conversion == gopher_ds::HTML_CSO_RESULT)
/*
- * $Id: http.cc,v 1.411 2003/03/04 01:40:28 robertc Exp $
+ * $Id: http.cc,v 1.412 2003/03/06 06:21:38 robertc Exp $
*
* DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
* AUTHOR: Harvest Derived
/* building buffer for complex strings */
#define BBUF_SZ (MAX_URL+32)
LOCAL_ARRAY(char, bbuf, BBUF_SZ);
- String strConnection = StringNull;
const HttpHeader *hdr_in = &orig_request->header;
const HttpHeaderEntry *e;
String strFwd;
bool we_do_ranges = decideIfWeDoRanges (orig_request);
- strConnection = httpHeaderGetList(hdr_in, HDR_CONNECTION);
+ String strConnection (httpHeaderGetList(hdr_in, HDR_CONNECTION));
while ((e = httpHeaderGetEntry(hdr_in, &pos)))
copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, orig_request, hdr_out, we_do_ranges, flags);
/*
- * $Id: urn.cc,v 1.82 2003/02/21 22:50:13 robertc Exp $
+ * $Id: urn.cc,v 1.83 2003/03/06 06:21:38 robertc Exp $
*
* DEBUG: section 52 URN Parsing
* AUTHOR: Kostas Anagnostakis
char * result;
char const *t;
- if ((t = strChr(urlpath, ':')) != NULL) {
- strSet(urlpath, t, '\0');
+ if ((t = urlpath.pos(':')) != NULL) {
+ urlpath.set(t, '\0');
result = xstrdup(urlpath.buf());
- strSet(urlpath, t, ':');
+ urlpath.set(t, ':');
} else {
result = xstrdup(urlpath.buf());
}