]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Verified and converted more String users.
authorFrancesco Chemolli <kinkie@squid-cache.org>
Sat, 31 Jan 2009 18:23:44 +0000 (19:23 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Sat, 31 Jan 2009 18:23:44 +0000 (19:23 +0100)
src/HttpHdrScTarget.cc
src/HttpHeader.cc
src/HttpHeaderTools.cc
src/HttpReply.cc
src/SquidString.h
src/String.cci

index 5f3906e8d28c917b14328d87676f6e10415d860b..c6382cbdddd59f31fd15187ccfceb6cf703b3f1a 100644 (file)
@@ -68,7 +68,7 @@ httpHdrScTargetDup(const HttpHdrScTarget * sc)
 {
     HttpHdrScTarget *dup;
     assert(sc);
-    dup = httpHdrScTargetCreate(sc->target.unsafeBuf());
+    dup = httpHdrScTargetCreate(sc->target.termedBuf());
     dup->mask = sc->mask;
     dup->max_age = sc->max_age;
     dup->content = sc->content;
index cad06c8f3113cd4153aa0a8e7557d965e75df98b..30407629a547efb99cb7c8ea10f82fcf35c62f02 100644 (file)
@@ -461,7 +461,7 @@ HttpHeader::update (HttpHeader const *fresh, HttpHeaderMask const *denied_mask)
         if (e->id != HDR_OTHER)
             delById(e->id);
         else
-            delByName(e->name.unsafeBuf());
+            delByName(e->name.termedBuf());
     }
 
     pos = HttpHeaderInitPos;
@@ -578,7 +578,8 @@ HttpHeader::parse(const char *header_start, const char *header_end)
         }
 
         if (e->id == HDR_CONTENT_LENGTH && (e2 = findEntry(e->id)) != NULL) {
-            if (e->value.cmp(e2->value.unsafeBuf()) != 0) {
+//            if (e->value.cmp(e2->value.termedBuf()) != 0) {
+            if (e->value != e2->value) {
                 int64_t l1, l2;
                 debugs(55, Config.onoff.relaxed_header_parser <= 0 ? 1 : 2,
                        "WARNING: found two conflicting content-length headers in {" << getStringPrefix(header_start, header_end) << "}");
@@ -588,12 +589,12 @@ HttpHeader::parse(const char *header_start, const char *header_end)
                     goto reset;
                 }
 
-                if (!httpHeaderParseOffset(e->value.unsafeBuf(), &l1)) {
-                    debugs(55, 1, "WARNING: Unparseable content-length '" << e->value.unsafeBuf() << "'");
+                if (!httpHeaderParseOffset(e->value.termedBuf(), &l1)) {
+                    debugs(55, 1, "WARNING: Unparseable content-length '" << e->value << "'");
                     delete e;
                     continue;
-                } else if (!httpHeaderParseOffset(e2->value.unsafeBuf(), &l2)) {
-                    debugs(55, 1, "WARNING: Unparseable content-length '" << e2->value.unsafeBuf() << "'");
+                } else if (!httpHeaderParseOffset(e2->value.termedBuf(), &l2)) {
+                    debugs(55, 1, "WARNING: Unparseable content-length '" << e2->value << "'");
                     delById(e2->id);
                 } else if (l1 > l2) {
                     delById(e2->id);
@@ -615,7 +616,7 @@ HttpHeader::parse(const char *header_start, const char *header_end)
             }
         }
 
-        if (e->id == HDR_OTHER && stringHasWhitespace(e->name.unsafeBuf())) {
+        if (e->id == HDR_OTHER && stringHasWhitespace(e->name.termedBuf())) {
             debugs(55, Config.onoff.relaxed_header_parser <= 0 ? 1 : 2,
                    "WARNING: found whitespace in HTTP header name {" <<
                    getStringPrefix(field_start, field_end) << "}");
@@ -875,7 +876,7 @@ HttpHeader::getList(http_hdr_type id, String *s) const
 
     while ((e = getEntry(&pos))) {
         if (e->id == id)
-            strListAdd(s, e->value.unsafeBuf(), ',');
+            strListAdd(s, e->value.termedBuf(), ',');
     }
 
     /*
@@ -909,7 +910,7 @@ HttpHeader::getList(http_hdr_type id) const
 
     while ((e = getEntry(&pos))) {
         if (e->id == id)
-            strListAdd(&s, e->value.unsafeBuf(), ',');
+            strListAdd(&s, e->value.termedBuf(), ',');
     }
 
     /*
@@ -964,7 +965,7 @@ HttpHeader::getByName(const char *name) const
     /* Sorry, an unknown header name. Do linear search */
     while ((e = getEntry(&pos))) {
         if (e->id == HDR_OTHER && e->name.caseCmp(name) == 0) {
-            strListAdd(&result, e->value.unsafeBuf(), ',');
+            strListAdd(&result, e->value.termedBuf(), ',');
         }
     }
 
@@ -1209,7 +1210,7 @@ HttpHeader::getTime(http_hdr_type id) const
     assert(Headers[id].type == ftDate_1123);   /* must be of an appropriate type */
 
     if ((e = findEntry(id))) {
-        value = parse_rfc1123(e->value.unsafeBuf());
+        value = parse_rfc1123(e->value.termedBuf());
         httpHeaderNoteParsedEntry(e->id, e->value, value < 0);
     }
 
@@ -1226,7 +1227,7 @@ HttpHeader::getStr(http_hdr_type id) const
 
     if ((e = findEntry(id))) {
         httpHeaderNoteParsedEntry(e->id, e->value, 0); /* no errors are possible */
-        return e->value.unsafeBuf();
+        return e->value.termedBuf();
     }
 
     return NULL;
@@ -1242,7 +1243,7 @@ HttpHeader::getLastStr(http_hdr_type id) const
 
     if ((e = findLastEntry(id))) {
         httpHeaderNoteParsedEntry(e->id, e->value, 0); /* no errors are possible */
-        return e->value.unsafeBuf();
+        return e->value.termedBuf();
     }
 
     return NULL;
@@ -1322,7 +1323,7 @@ HttpHeader::getContRange() const
     HttpHeaderEntry *e;
 
     if ((e = findEntry(HDR_CONTENT_RANGE))) {
-        cr = httpHdrContRangeParseCreate(e->value.unsafeBuf());
+        cr = httpHdrContRangeParseCreate(e->value.termedBuf());
         httpHeaderNoteParsedEntry(e->id, e->value, !cr);
     }
 
@@ -1367,7 +1368,7 @@ HttpHeader::getETag(http_hdr_type id) const
     assert(Headers[id].type == ftETag);                /* must be of an appropriate type */
 
     if ((e = findEntry(id)))
-        etagParseInit(&etag, e->value.unsafeBuf());
+        etagParseInit(&etag, e->value.termedBuf());
 
     return etag;
 }
@@ -1381,7 +1382,7 @@ HttpHeader::getTimeOrTag(http_hdr_type id) const
     memset(&tot, 0, sizeof(tot));
 
     if ((e = findEntry(id))) {
-        const char *str = e->value.unsafeBuf();
+        const char *str = e->value.termedBuf();
         /* try as an ETag */
 
         if (etagParseInit(&tot.tag, str)) {
@@ -1417,13 +1418,13 @@ HttpHeaderEntry::HttpHeaderEntry(http_hdr_type anId, const char *aName, const ch
 
     Headers[id].stat.aliveCount++;
 
-    debugs(55, 9, "created HttpHeaderEntry " << this << ": '" << name.unsafeBuf() << " : " << value.unsafeBuf());
+    debugs(55, 9, "created HttpHeaderEntry " << this << ": '" << name << " : " << value );
 }
 
 HttpHeaderEntry::~HttpHeaderEntry()
 {
     assert_eid(id);
-    debugs(55, 9, "destroying entry " << this << ": '" << name.unsafeBuf() << ": " << value.unsafeBuf() << "'");
+    debugs(55, 9, "destroying entry " << this << ": '" << name << ": " << value << "'");
     /* clean name if needed */
 
     if (id == HDR_OTHER)
@@ -1503,7 +1504,7 @@ HttpHeaderEntry::parse(const char *field_start, const char *field_end)
 
     if (field_end - value_start > 65534) {
         /* String must be LESS THAN 64K and it adds a terminating NULL */
-        debugs(55, 1, "WARNING: ignoring '" << name.unsafeBuf() << "' header of " << (field_end - value_start) << " bytes");
+        debugs(55, 1, "WARNING: ignoring '" << name << "' header of " << (field_end - value_start) << " bytes");
 
         if (id == HDR_OTHER)
             name.clean();
@@ -1518,24 +1519,24 @@ HttpHeaderEntry::parse(const char *field_start, const char *field_end)
 
     Headers[id].stat.aliveCount++;
 
-    debugs(55, 9, "parsed HttpHeaderEntry: '" << name.unsafeBuf() << ": " << value.unsafeBuf() << "'");
+    debugs(55, 9, "parsed HttpHeaderEntry: '" << name << ": " << value << "'");
 
-    return new HttpHeaderEntry(id, name.unsafeBuf(), value.unsafeBuf());
+    return new HttpHeaderEntry(id, name.termedBuf(), value.termedBuf());
 }
 
 HttpHeaderEntry *
 HttpHeaderEntry::clone() const
 {
-    return new HttpHeaderEntry(id, name.unsafeBuf(), value.unsafeBuf());
+    return new HttpHeaderEntry(id, name.termedBuf(), value.termedBuf());
 }
 
 void
 HttpHeaderEntry::packInto(Packer * p) const
 {
     assert(p);
-    packerAppend(p, name.unsafeBuf(), name.size());
+    packerAppend(p, name.rawBuf(), name.size());
     packerAppend(p, ": ", 2);
-    packerAppend(p, value.unsafeBuf(), value.size());
+    packerAppend(p, value.rawBuf(), value.size());
     packerAppend(p, "\r\n", 2);
 }
 
@@ -1545,7 +1546,7 @@ HttpHeaderEntry::getInt() const
     assert_eid (id);
     assert (Headers[id].type == ftInt);
     int val = -1;
-    int ok = httpHeaderParseInt(value.unsafeBuf(), &val);
+    int ok = httpHeaderParseInt(value.termedBuf(), &val);
     httpHeaderNoteParsedEntry(id, value, !ok);
     /* XXX: Should we check ok - ie
      * return ok ? -1 : value;
@@ -1559,7 +1560,7 @@ HttpHeaderEntry::getInt64() const
     assert_eid (id);
     assert (Headers[id].type == ftInt64);
     int64_t val = -1;
-    int ok = httpHeaderParseOffset(value.unsafeBuf(), &val);
+    int ok = httpHeaderParseOffset(value.termedBuf(), &val);
     httpHeaderNoteParsedEntry(id, value, !ok);
     /* XXX: Should we check ok - ie
      * return ok ? -1 : value;
@@ -1574,7 +1575,7 @@ httpHeaderNoteParsedEntry(http_hdr_type id, String const &context, int error)
 
     if (error) {
         Headers[id].stat.errCount++;
-        debugs(55, 2, "cannot parse hdr field: '" << Headers[id].name.unsafeBuf() << ": " << context.unsafeBuf() << "'");
+        debugs(55, 2, "cannot parse hdr field: '" << Headers[id].name << ": " << context << "'");
     }
 }
 
@@ -1591,7 +1592,7 @@ httpHeaderFieldStatDumper(StoreEntry * sentry, int idx, double val, double size,
 {
     const int id = (int) val;
     const int valid_id = id >= 0 && id < HDR_ENUM_END;
-    const char *name = valid_id ? Headers[id].name.unsafeBuf() : "INVALID";
+    const char *name = valid_id ? Headers[id].name.termedBuf() : "INVALID";
     int visible = count > 0;
     /* for entries with zero count, list only those that belong to current type of message */
 
@@ -1669,7 +1670,7 @@ httpHeaderStoreReport(StoreEntry * e)
     for (ht = (http_hdr_type)0; ht < HDR_ENUM_END; ++ht) {
         HttpHeaderFieldInfo *f = Headers + ht;
         storeAppendPrintf(e, "%2d\t %-25s\t %5d\t %6.3f\t %6.3f\n",
-                          f->id, f->name.unsafeBuf(), f->stat.aliveCount,
+                          f->id, f->name.termedBuf(), f->stat.aliveCount,
                           xpercent(f->stat.errCount, f->stat.parsCount),
                           xpercent(f->stat.repCount, f->stat.seenCount));
     }
@@ -1690,7 +1691,7 @@ httpHeaderIdByName(const char *name, int name_len, const HttpHeaderFieldInfo * i
         if (name_len >= 0 && name_len != info[i].name.size())
             continue;
 
-        if (!strncasecmp(name, info[i].name.unsafeBuf(),
+        if (!strncasecmp(name, info[i].name.termedBuf(),
                          name_len < 0 ? info[i].name.size() + 1 : name_len))
             return info[i].id;
     }
@@ -1715,7 +1716,7 @@ httpHeaderNameById(int id)
 
     assert(id >= 0 && id < HDR_ENUM_END);
 
-    return Headers[id].name.unsafeBuf();
+    return Headers[id].name.termedBuf();
 }
 
 int
@@ -1804,7 +1805,7 @@ HttpHeader::removeConnectionHeaderEntries()
 
         int headers_deleted = 0;
         while ((e = getEntry(&pos))) {
-            if (strListIsMember(&strConnection, e->name.unsafeBuf(), ','))
+            if (strListIsMember(&strConnection, e->name.termedBuf(), ','))
                 delAt(pos, headers_deleted);
         }
         if (headers_deleted)
index 6776898d8c09087100c92ea35b56f67944907e1b..a7c7ff7fc321cf687cfbf1b8ee07f72bed4cf07e 100644 (file)
@@ -258,7 +258,7 @@ strListGetItem(const String * str, char del, const char **item, int *ilen, const
     delim[2][1] = del;
 
     if (!*pos) {
-        *pos = str->unsafeBuf();
+        *pos = str->termedBuf();
 
         if (!*pos)
             return 0;
index ad0f3af82d42938b68b061cf0f75ceffda94ee23..7f4451a4f1eed4b92e589075e5ad2d8e4cf786f7 100644 (file)
@@ -281,7 +281,7 @@ HttpReply::validatorsMatch(HttpReply const * otherRep) const
 
     two = otherRep->header.getStrOrList(HDR_ETAG);
 
-    if (!one.unsafeBuf() || !two.unsafeBuf() || strcasecmp (one.unsafeBuf(), two.unsafeBuf())) {
+    if (one.undefined() || two.undefined() || one.caseCmp(two)!=0 ) {
         one.clean();
         two.clean();
         return 0;
@@ -295,7 +295,7 @@ HttpReply::validatorsMatch(HttpReply const * otherRep) const
 
     two = otherRep->header.getStrOrList(HDR_CONTENT_MD5);
 
-    if (!one.unsafeBuf() || !two.unsafeBuf() || strcasecmp (one.unsafeBuf(), two.unsafeBuf())) {
+    if (one.undefined() || two.undefined() || one.caseCmp(two) != 0 ) {
         one.clean();
         two.clean();
         return 0;
@@ -440,7 +440,7 @@ HttpReply::bodySize(const HttpRequestMethod& method) const
 bool HttpReply::sanityCheckStartLine(MemBuf *buf, http_status *error)
 {
     if (buf->contentSize() >= protoPrefix.size() && protoPrefix.cmp(buf->content(), protoPrefix.size()) != 0) {
-        debugs(58, 3, "HttpReply::sanityCheckStartLine: missing protocol prefix (" << protoPrefix.unsafeBuf() << ") in '" << buf->content() << "'");
+        debugs(58, 3, "HttpReply::sanityCheckStartLine: missing protocol prefix (" << protoPrefix << ") in '" << buf->content() << "'");
         *error = HTTP_INVALID_HEADER;
         return false;
     }
index c807ecbaf29a91d531a686e1c3e770acd78a0080..845a5f5a56683480d8a6bbc5baf25d5400d52cbf 100644 (file)
@@ -134,6 +134,7 @@ public:
     _SQUID_INLINE_ int cmp (String const &) const;
     _SQUID_INLINE_ int caseCmp (char const *) const;
     _SQUID_INLINE_ int caseCmp (char const *, size_t count) const;
+    _SQUID_INLINE_ int caseCmp (String const &) const;
 
     /** \deprecated Use assignment to [] position instead.
      *              ie   str[0] = 'h';
index 6c75dc628d92e9c308771a7232474dd4b70df414..a3a133e98da577af3382ce4413c6f0c88693aebe 100644 (file)
@@ -168,6 +168,13 @@ String::caseCmp(char const *aString, size_t count) const
     return strncasecmp(termedBuf(), aString, count);
 }
 
+int
+String::caseCmp(const String &str) const
+{
+    return caseCmp(str.rawBuf(),str.size());
+}
+
+
 void
 String::set(char const *loc, char const ch)
 {