summaryrefslogtreecommitdiffstats
path: root/kpf/src/ByteRange.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /kpf/src/ByteRange.cpp
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpf/src/ByteRange.cpp')
-rw-r--r--kpf/src/ByteRange.cpp176
1 files changed, 176 insertions, 0 deletions
diff --git a/kpf/src/ByteRange.cpp b/kpf/src/ByteRange.cpp
new file mode 100644
index 00000000..cdd0624b
--- /dev/null
+++ b/kpf/src/ByteRange.cpp
@@ -0,0 +1,176 @@
+/*
+ KPF - Public fileserver for KDE
+
+ Copyright 2001 Rik Hemsley (rikkus) <rik@kde.org>
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to
+ deal in the Software without restriction, including without limitation the
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <qstringlist.h>
+
+#include "Defines.h"
+#include "ByteRange.h"
+
+namespace KPF
+{
+ ByteRange::ByteRange()
+ : first_ (0L),
+ last_ (0L),
+ haveLast_ (false)
+ {
+ // Empty.
+ }
+
+ ByteRange::ByteRange(ulong first)
+ : first_ (first),
+ last_ (0L),
+ haveLast_ (false)
+ {
+ // Empty.
+ }
+
+
+ ByteRange::ByteRange(ulong first, ulong last)
+ : first_ (first),
+ last_ (last),
+ haveLast_ (true)
+ {
+ }
+
+ ulong
+ ByteRange::first() const
+ {
+ return first_;
+ }
+
+ ulong
+ ByteRange::last() const
+ {
+ return last_;
+ }
+
+ bool
+ ByteRange::haveLast() const
+ {
+ return haveLast_;
+ }
+
+ void
+ ByteRange::setFirst(ulong l)
+ {
+ first_ = l;
+ }
+
+ void
+ ByteRange::setLast(ulong l)
+ {
+ last_ = l;
+ haveLast_ = true;
+ }
+
+ bool
+ ByteRange::valid() const
+ {
+ return haveLast_ ? (first_ < last_) : true;
+ }
+
+ void
+ ByteRange::clear()
+ {
+ first_ = last_ = 0L;
+ haveLast_ = false;
+ }
+
+ ByteRangeList::ByteRangeList()
+ {
+ // Empty.
+ }
+
+ ByteRangeList::ByteRangeList(const QString & _s, float /* protocol */)
+ {
+ kpfDebug << "ByteRangeList parsing `" << _s << "'" << endl;
+
+ // Hey, parsing time :)
+
+ QString s(_s);
+
+ if ("bytes=" == s.left(6))
+ {
+ s.remove(0, 6);
+ s = s.stripWhiteSpace();
+ }
+
+ QStringList byteRangeSpecList(QStringList::split(',', s));
+
+ QStringList::ConstIterator it;
+
+ for (it = byteRangeSpecList.begin(); it != byteRangeSpecList.end(); ++it)
+ addByteRange(*it);
+ }
+
+ void
+ ByteRangeList::addByteRange(const QString & s)
+ {
+ kpfDebug << "addByteRange(" << s << ")" << endl;
+
+ int dashPos = s.find('-');
+
+ if (-1 == dashPos)
+ {
+ kpfDebug << "No dash" << endl;
+ return;
+ }
+
+ QString firstByte(s.left(dashPos).stripWhiteSpace());
+
+ QString lastByte(s.mid(dashPos + 1).stripWhiteSpace());
+
+ ulong first;
+
+ if (firstByte.isEmpty())
+ first = 0L;
+ else
+ first = firstByte.toULong();
+
+ ulong last;
+
+ bool haveLast = !lastByte.isEmpty();
+
+ if (haveLast)
+ last = lastByte.toULong();
+ else
+ last = 0L;
+
+ if (haveLast)
+ {
+ if (first < last)
+ {
+ kpfDebug << "range: " << first << "d - " << last << "d" << endl;
+ append(ByteRange(first, last));
+ }
+ }
+ else
+ {
+ kpfDebug << "range: " << first << "d - end" << endl;
+ append(ByteRange(first));
+ }
+ }
+
+} // End namespace KPF
+
+// vim:ts=2:sw=2:tw=78:et