From: robertc <> Date: Thu, 6 Mar 2003 13:21:36 +0000 (+0000) Subject: Summary: Merge cleanup code from comms branch. X-Git-Tag: SQUID_3_0_PRE1~280 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=650c4b8809bf007414819ad6970eb83f51bf1c58;p=thirdparty%2Fsquid.git Summary: Merge cleanup code from comms branch. Keywords: Patches applied: * robertc@squid-cache.org--squid/squid--comms--3.0--patch-8 Tidyup. * robertc@squid-cache.org--squid/squid--comms--3.0--patch-7 Sync with HEAD. * robertc@squid-cache.org--squid/squid--comms--3.0--patch-6 Merge from HEAD. * robertc@squid-cache.org--squid/squid--comms--3.0--patch-5 Merge from HEAD. --- diff --git a/src/HttpHdrRange.cc b/src/HttpHdrRange.cc index 4b336d13ad..560b8c8c2f 100644 --- a/src/HttpHdrRange.cc +++ b/src/HttpHdrRange.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -304,7 +304,7 @@ HttpHdrRange::parseInit(const String * range_spec) 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! */ diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 0476ec4adc..e0ea9586a1 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -578,7 +578,7 @@ httpHeaderDelByName(HttpHeader * hdr, const char *name) 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 @@ -660,7 +660,6 @@ httpHeaderAddEntry(HttpHeader * hdr, HttpHeaderEntry * e) 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); @@ -668,7 +667,9 @@ httpHeaderGetList(const HttpHeader * hdr, http_hdr_type 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) @@ -702,7 +703,7 @@ httpHeaderGetStrOrList(const HttpHeader * hdr, http_hdr_type id) if ((e = httpHeaderFindEntry(hdr, id))) return e->value; - return String::Null; + return String(); } /* @@ -714,7 +715,6 @@ httpHeaderGetByName(const HttpHeader * hdr, const char *name) http_hdr_type id; HttpHeaderPos pos = HttpHeaderInitPos; HttpHeaderEntry *e; - String result = StringNull; assert(hdr); assert(name); @@ -725,9 +725,11 @@ httpHeaderGetByName(const HttpHeader * hdr, const char *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(), ','); } } @@ -741,7 +743,6 @@ httpHeaderGetByName(const HttpHeader * hdr, const char *name) 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; @@ -753,6 +754,8 @@ httpHeaderGetByNameListMember(const HttpHeader * hdr, const char *name, const ch 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); @@ -769,7 +772,6 @@ httpHeaderGetByNameListMember(const HttpHeader * hdr, const char *name, const ch 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; @@ -780,6 +782,7 @@ httpHeaderGetListMember(const HttpHeader * hdr, http_hdr_type id, const char *me assert(id >= 0); header = httpHeaderGetStrOrList(hdr, id); + String result; while (strListGetItem(&header, separator, &item, &ilen, &pos)) { if (strncmp(item, member, mlen) == 0 && item[mlen] == '=') { diff --git a/src/HttpHeaderTools.cc b/src/HttpHeaderTools.cc index 2bcca3ecab..5a2897a865 100644 --- a/src/HttpHeaderTools.cc +++ b/src/HttpHeaderTools.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -209,7 +209,7 @@ int 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() diff --git a/src/HttpReply.cc b/src/HttpReply.cc index 94fa4694b3..497d9435d5 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -286,7 +286,7 @@ httpReplySetHeaders(HttpReply * reply, http_version_t ver, http_status status, c 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); @@ -457,7 +457,7 @@ httpReplyHdrCacheInit(HttpReply * rep) if (str) rep->content_type.limitInit(str, strcspn(str, ";\t ")); else - rep->content_type = StringNull; + rep->content_type = String(); rep->cache_control = httpHeaderGetCc(hdr); diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index d690744d34..f989a6b8cd 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -211,7 +211,7 @@ httpRequestHdrCacheInit(request_t * req) if (str) stringLimitInit(&req->content_type, str, strcspn(str, ";\t ")); else - req->content_type = StringNull; + req->content_type = String(); #endif diff --git a/src/SquidString.h b/src/SquidString.h index 2f7340da3d..a0bf3eab22 100644 --- a/src/SquidString.h +++ b/src/SquidString.h @@ -1,6 +1,6 @@ /* - * $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 @@ -40,7 +40,6 @@ class String { public: - static const String Null; _SQUID_INLINE_ String(); String (char const *); String (String const &); @@ -51,6 +50,7 @@ public: _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); @@ -60,29 +60,30 @@ public: 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 diff --git a/src/String.cc b/src/String.cc index 124edd7b36..a962c703e2 100644 --- a/src/String.cc +++ b/src/String.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -35,8 +35,6 @@ #include "squid.h" -String const String::Null; - void String::initBuf(size_t sz) { @@ -173,6 +171,13 @@ String::absorb(String &old) old.len_ = 0; } +void +String::buf(char *newBuf) +{ + assert (buf_ == NULL); + buf_ = newBuf; +} + #ifndef _USE_INLINE_ #include "String.cci" #endif diff --git a/src/String.cci b/src/String.cci index 239ad0990b..8784518582 100644 --- a/src/String.cci +++ b/src/String.cci @@ -1,6 +1,6 @@ /* - * $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 @@ -34,8 +34,7 @@ */ String::String() : size_(0), len_(0), buf_ (NULL) -{ -} +{} int String::size() const @@ -49,8 +48,67 @@ String::buf() 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'; +} + diff --git a/src/SwapDir.h b/src/SwapDir.h index 2abd4e667b..7c78da6110 100644 --- a/src/SwapDir.h +++ b/src/SwapDir.h @@ -1,6 +1,6 @@ /* - * $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/ @@ -47,7 +47,7 @@ struct SwapDir 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; } @@ -65,8 +65,9 @@ public: int removals; int scanned; - struct + struct Flags { + Flags() : selected(0), read_only(0){} unsigned int selected: 1; diff --git a/src/asn.cc b/src/asn.cc index 85dc45655c..c46e95de64 100644 --- a/src/asn.cc +++ b/src/asn.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -496,10 +496,10 @@ destroyRadixNodeInfo(as_info * e_info) while (data) { prev = data; data = data->next; - xfree(prev); + prev->deleteSelf(); } - xfree(data); + data->deleteSelf(); } static int diff --git a/src/external_acl.cc b/src/external_acl.cc index 70f0a7b54f..00d21096f9 100644 --- a/src/external_acl.cc +++ b/src/external_acl.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -598,11 +598,11 @@ makeExternalAclKey(ACLChecklist * ch, external_acl_data * acl_data) 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) { diff --git a/src/fs/ufs/store_dir_ufs.cc b/src/fs/ufs/store_dir_ufs.cc index e720ab4da0..480c4684c5 100644 --- a/src/fs/ufs/store_dir_ufs.cc +++ b/src/fs/ufs/store_dir_ufs.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -334,28 +334,32 @@ UFSSwapDir::statfs(StoreEntry & sentry) const 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) { diff --git a/src/ftp.cc b/src/ftp.cc index fdd11ae83d..8137ebe065 100644 --- a/src/ftp.cc +++ b/src/ftp.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -1243,10 +1243,10 @@ ftpCheckUrlpath(FtpStateData * ftpState) 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); } } @@ -1257,7 +1257,7 @@ ftpCheckUrlpath(FtpStateData * ftpState) 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; @@ -1771,7 +1771,7 @@ ftpSendType(FtpStateData * ftpState) 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); } @@ -2830,7 +2830,7 @@ ftpFail(FtpStateData * ftpState) 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) { @@ -3033,7 +3033,7 @@ ftpAppendSuccessHeader(FtpStateData * ftpState) 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"; diff --git a/src/gopher.cc b/src/gopher.cc index 4b6395a3e2..e2a8859f95 100644 --- a/src/gopher.cc +++ b/src/gopher.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -328,7 +328,6 @@ gopherToHTML(GopherStateData * gopherState, char *inbuf, int len) 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; @@ -374,6 +373,7 @@ gopherToHTML(GopherStateData * gopherState, char *inbuf, int len) } inbuf[len] = '\0'; + String outbuf; if (!gopherState->HTML_header_added) { if (gopherState->conversion == gopher_ds::HTML_CSO_RESULT) diff --git a/src/http.cc b/src/http.cc index b15bbc2e3b..82eb66f080 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -1051,7 +1051,6 @@ httpBuildRequestHeader(request_t * request, /* 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; @@ -1064,7 +1063,7 @@ httpBuildRequestHeader(request_t * request, 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); diff --git a/src/urn.cc b/src/urn.cc index 3dba79d2f5..f70723cfac 100644 --- a/src/urn.cc +++ b/src/urn.cc @@ -1,6 +1,6 @@ /* - * $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 @@ -174,10 +174,10 @@ UrnState::getHost (String &urlpath) 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()); }