/*
- * 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.
#include "squid.h"
#include "client_side_request.h"
+#include "http/Stream.h"
#include "HttpHeaderRange.h"
#include "HttpHeaderTools.h"
#include "HttpReply.h"
HttpHdrRangeSpec spec;
if (!spec.parseInit(field, flen))
- return NULL;
+ return nullptr;
return new HttpHdrRangeSpec(spec);
}
}
void
-HttpHdrRangeSpec::packInto(Packer * packer) const
+HttpHdrRangeSpec::packInto(Packable * p) const
{
if (!known_spec(offset)) /* suffix */
- packerPrintf(packer, "-%" PRId64, length);
+ p->appendf("-%" PRId64, length);
else if (!known_spec(length)) /* trailer */
- packerPrintf(packer, "%" PRId64 "-", offset);
+ p->appendf("%" PRId64 "-", offset);
else /* range */
- packerPrintf(packer, "%" PRId64 "-%" PRId64,
- offset, offset + length - 1);
+ p->appendf("%" PRId64 "-%" PRId64, offset, offset + length - 1);
}
void
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)
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;
}
if (!r->parseInit(range_spec)) {
delete r;
- r = NULL;
+ r = nullptr;
}
return r;
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))
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;
}
}
void
-HttpHdrRange::packInto(Packer * packer) const
+HttpHdrRange::packInto(Packable * packer) const
{
const_iterator pos = begin();
{
assert(rep);
- if (rep->content_range)
- clen = rep->content_range->elength;
+ if (rep->contentRange())
+ clen = rep->contentRange()->elength;
else
clen = rep->content_length;
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 */
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