]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/HttpHdrRange.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / HttpHdrRange.cc
index 3d14063fbe19f14ec79762ef49fb80886c41f895..e35bfec69e36f48d3267f23683897e390774bc2a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
  *
  * Squid software is distributed under GPLv2+ license and includes
  * contributions from numerous individuals and organizations.
@@ -10,6 +10,7 @@
 
 #include "squid.h"
 #include "client_side_request.h"
+#include "http/Stream.h"
 #include "HttpHeaderRange.h"
 #include "HttpHeaderTools.h"
 #include "HttpReply.h"
@@ -54,7 +55,7 @@ HttpHdrRangeSpec::Create(const char *field, int flen)
     HttpHdrRangeSpec spec;
 
     if (!spec.parseInit(field, flen))
-        return NULL;
+        return nullptr;
 
     return new HttpHdrRangeSpec(spec);
 }
@@ -155,7 +156,7 @@ HttpHdrRangeSpec::canonize(int64_t clen)
     return length > 0;
 }
 
-/* merges recepient with donor if possible; returns true on success
+/* merges recipient with donor if possible; returns true on success
  * both specs must be canonized prior to merger, of course */
 bool
 HttpHdrRangeSpec::mergeWith(const HttpHdrRangeSpec * donor)
@@ -187,11 +188,13 @@ HttpHdrRangeSpec::mergeWith(const HttpHdrRangeSpec * donor)
         assert(rhs > offset);
         length = rhs - offset;
     } else {
-        /* does recepient contain donor? */
+        /* does recipient contain donor? */
         merged =
             offset <= donor->offset && donor->offset < rhs;
     }
 
+#else
+    (void)donor;
 #endif
     return merged;
 }
@@ -210,7 +213,7 @@ HttpHdrRange::ParseCreate(const String * range_spec)
 
     if (!r->parseInit(range_spec)) {
         delete r;
-        r = NULL;
+        r = nullptr;
     }
 
     return r;
@@ -221,11 +224,11 @@ bool
 HttpHdrRange::parseInit(const String * range_spec)
 {
     const char *item;
-    const char *pos = NULL;
+    const char *pos = nullptr;
     int ilen;
     assert(range_spec);
     ++ParsedCount;
-    debugs(64, 8, "parsing range field: '" << range_spec << "'");
+    debugs(64, 8, "parsing range field: '" << *range_spec << "'");
     /* check range type */
 
     if (range_spec->caseCmp("bytes=", 6))
@@ -246,7 +249,7 @@ HttpHdrRange::parseInit(const String * range_spec)
                 delete specs.back();
                 specs.pop_back();
             }
-            debugs(64, 2, "ignoring invalid range field: '" << range_spec << "'");
+            debugs(64, 2, "ignoring invalid range field: '" << *range_spec << "'");
             break;
         }
 
@@ -371,8 +374,8 @@ HttpHdrRange::canonize(HttpReply *rep)
 {
     assert(rep);
 
-    if (rep->content_range)
-        clen = rep->content_range->elength;
+    if (rep->contentRange())
+        clen = rep->contentRange()->elength;
     else
         clen = rep->content_length;
 
@@ -390,7 +393,7 @@ HttpHdrRange::canonize (int64_t newClen)
     merge (goods);
     debugs(64, 3, "HttpHdrRange::canonize: finished with " << specs.size() <<
            " specs");
-    return specs.size() > 0; // fixme, should return bool
+    return specs.size() > 0; // TODO: should return bool
 }
 
 /* hack: returns true if range specs are too "complex" for Squid to handle */
@@ -525,30 +528,13 @@ HttpHdrRange::offsetLimitExceeded(const int64_t limit) const
     return true;
 }
 
-bool
-HttpHdrRange::contains(HttpHdrRangeSpec& r) const
-{
-    assert(r.length >= 0);
-    HttpHdrRangeSpec::HttpRange rrange(r.offset, r.offset + r.length);
-
-    for (const_iterator i = begin(); i != end(); ++i) {
-        HttpHdrRangeSpec::HttpRange irange((*i)->offset, (*i)->offset + (*i)->length);
-        HttpHdrRangeSpec::HttpRange intersection = rrange.intersection(irange);
-
-        if (intersection.start == irange.start && intersection.size() == irange.size())
-            return true;
-    }
-
-    return false;
-}
-
 const HttpHdrRangeSpec *
 HttpHdrRangeIter::currentSpec() const
 {
     if (pos != end)
         return *pos;
 
-    return NULL;
+    return nullptr;
 }
 
 void