mirror of https://github.com/aria2/aria2
2010-09-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Removed ChunkedDecoder. Moved GZipDecodingStreamFilter to under 'if HAVE_LIBZ'. * src/ChunkedDecoder.cc * src/ChunkedDecoder.h * src/Makefile.am * test/ChunkedDecoderTest.cc * test/Makefile.ampull/1/head
parent
7f9e70e5c8
commit
6b6e6bc495
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2010-09-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Removed ChunkedDecoder. Moved GZipDecodingStreamFilter to under
|
||||
'if HAVE_LIBZ'.
|
||||
* src/ChunkedDecoder.cc
|
||||
* src/ChunkedDecoder.h
|
||||
* src/Makefile.am
|
||||
* test/ChunkedDecoderTest.cc
|
||||
* test/Makefile.am
|
||||
|
||||
2010-09-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Updated doc
|
||||
|
|
|
@ -1,152 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "ChunkedDecoder.h"
|
||||
#include "util.h"
|
||||
#include "message.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include "StringFormat.h"
|
||||
#include "A2STR.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string ChunkedDecoder::NAME("ChunkedDecoder");
|
||||
|
||||
ChunkedDecoder::ChunkedDecoder():chunkSize_(0), state_(READ_SIZE) {}
|
||||
|
||||
ChunkedDecoder::~ChunkedDecoder() {}
|
||||
|
||||
void ChunkedDecoder::init() {}
|
||||
|
||||
static bool readChunkSize(uint64_t& chunkSize, std::string& in)
|
||||
{
|
||||
std::string::size_type crlfPos = in.find(A2STR::CRLF);
|
||||
if(crlfPos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
std::string::size_type extPos = in.find(A2STR::SEMICOLON_C);
|
||||
if(extPos == std::string::npos || crlfPos < extPos) {
|
||||
extPos = crlfPos;
|
||||
}
|
||||
chunkSize = util::parseULLInt(in.substr(0, extPos), 16);
|
||||
in.erase(0, crlfPos+2);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool readTrailer(std::string& in)
|
||||
{
|
||||
std::string::size_type crlfPos = in.find(A2STR::CRLF);
|
||||
if(crlfPos == std::string::npos) {
|
||||
return false;
|
||||
}
|
||||
if(crlfPos == 0) {
|
||||
return true;
|
||||
} else {
|
||||
if(in.size() > crlfPos+3) {
|
||||
if(in[crlfPos+2] == '\r' && in[crlfPos+3] == '\n') {
|
||||
return true;
|
||||
} else {
|
||||
throw DL_ABORT_EX("No CRLF at the end of chunk stream.");
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool readData(std::string& out, uint64_t& chunkSize, std::string& in)
|
||||
{
|
||||
uint64_t readlen = std::min(chunkSize, static_cast<uint64_t>(in.size()));
|
||||
out.append(in.begin(), in.begin()+readlen);
|
||||
in.erase(0, readlen);
|
||||
chunkSize -= readlen;
|
||||
if(chunkSize == 0 && in.size() >= 2) {
|
||||
if(in.find(A2STR::CRLF) == 0) {
|
||||
in.erase(0, 2);
|
||||
return true;
|
||||
} else {
|
||||
throw DL_ABORT_EX(EX_INVALID_CHUNK_SIZE);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string ChunkedDecoder::decode(const unsigned char* inbuf, size_t inlen)
|
||||
{
|
||||
buf_.append(&inbuf[0], &inbuf[inlen]);
|
||||
|
||||
std::string outbuf;
|
||||
while(1) {
|
||||
if(state_ == READ_SIZE) {
|
||||
if(readChunkSize(chunkSize_, buf_)) {
|
||||
if(chunkSize_ == 0) {
|
||||
state_ = READ_TRAILER;
|
||||
} else {
|
||||
state_ = READ_DATA;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if(state_ == READ_DATA) {
|
||||
if(readData(outbuf, chunkSize_, buf_)) {
|
||||
state_ = READ_SIZE;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else if(state_ == READ_TRAILER) {
|
||||
if(readTrailer(buf_)) {
|
||||
state_ = STREAM_END;
|
||||
break;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
bool ChunkedDecoder::finished()
|
||||
{
|
||||
return state_ == STREAM_END;
|
||||
}
|
||||
|
||||
void ChunkedDecoder::release() {}
|
||||
|
||||
const std::string& ChunkedDecoder::getName() const
|
||||
{
|
||||
return NAME;
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -1,77 +0,0 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_CHUNKED_DECODER_H_
|
||||
#define _D_CHUNKED_DECODER_H_
|
||||
|
||||
#include "Decoder.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ChunkedDecoder : public Decoder {
|
||||
private:
|
||||
enum STATE {
|
||||
READ_SIZE,
|
||||
READ_DATA,
|
||||
READ_TRAILER,
|
||||
STREAM_END
|
||||
};
|
||||
|
||||
std::string buf_;
|
||||
|
||||
uint64_t chunkSize_;
|
||||
|
||||
STATE state_;
|
||||
|
||||
static const std::string NAME;
|
||||
|
||||
public:
|
||||
ChunkedDecoder();
|
||||
|
||||
virtual ~ChunkedDecoder();
|
||||
|
||||
virtual void init();
|
||||
|
||||
virtual std::string decode(const unsigned char* inbuf, size_t inlen);
|
||||
|
||||
virtual bool finished();
|
||||
|
||||
virtual void release();
|
||||
|
||||
virtual const std::string& getName() const;
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_DECODER_H_
|
|
@ -175,7 +175,6 @@ SRCS = Socket.h\
|
|||
A2STR.cc A2STR.h\
|
||||
RarestPieceSelector.cc RarestPieceSelector.h\
|
||||
Decoder.h\
|
||||
ChunkedDecoder.cc ChunkedDecoder.h\
|
||||
Signature.cc Signature.h\
|
||||
ServerStat.cc ServerStat.h\
|
||||
ServerStatMan.cc ServerStatMan.h\
|
||||
|
@ -209,7 +208,6 @@ SRCS = Socket.h\
|
|||
AdaptiveFileAllocationIterator.cc AdaptiveFileAllocationIterator.h\
|
||||
StreamFilter.cc StreamFilter.h\
|
||||
SinkStreamFilter.cc SinkStreamFilter.h\
|
||||
GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h\
|
||||
ChunkedDecodingStreamFilter.cc ChunkedDecodingStreamFilter.h\
|
||||
NullSinkStreamFilter.cc NullSinkStreamFilter.h\
|
||||
uri.cc uri.h
|
||||
|
@ -264,7 +262,8 @@ endif # HAVE_LIBSSL
|
|||
|
||||
if HAVE_LIBZ
|
||||
SRCS += GZipDecoder.cc GZipDecoder.h\
|
||||
GZipEncoder.cc GZipEncoder.h
|
||||
GZipEncoder.cc GZipEncoder.h\
|
||||
GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h
|
||||
endif # HAVE_LIBZ
|
||||
|
||||
if HAVE_SQLITE3
|
||||
|
|
|
@ -62,7 +62,8 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
|||
@HAVE_LIBGNUTLS_TRUE@am__append_7 = LibgnutlsTLSContext.cc LibgnutlsTLSContext.h
|
||||
@HAVE_LIBSSL_TRUE@am__append_8 = LibsslTLSContext.cc LibsslTLSContext.h
|
||||
@HAVE_LIBZ_TRUE@am__append_9 = GZipDecoder.cc GZipDecoder.h\
|
||||
@HAVE_LIBZ_TRUE@ GZipEncoder.cc GZipEncoder.h
|
||||
@HAVE_LIBZ_TRUE@ GZipEncoder.cc GZipEncoder.h\
|
||||
@HAVE_LIBZ_TRUE@ GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h
|
||||
|
||||
@HAVE_SQLITE3_TRUE@am__append_10 = Sqlite3CookieParser.cc Sqlite3CookieParser.h\
|
||||
@HAVE_SQLITE3_TRUE@ Sqlite3CookieParserImpl.cc Sqlite3CookieParserImpl.h
|
||||
|
@ -425,9 +426,9 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
InitiateConnectionCommand.h FtpFinishDownloadCommand.cc \
|
||||
FtpFinishDownloadCommand.h A2STR.cc A2STR.h \
|
||||
RarestPieceSelector.cc RarestPieceSelector.h Decoder.h \
|
||||
ChunkedDecoder.cc ChunkedDecoder.h Signature.cc Signature.h \
|
||||
ServerStat.cc ServerStat.h ServerStatMan.cc ServerStatMan.h \
|
||||
URISelector.h AdaptiveURISelector.cc AdaptiveURISelector.h \
|
||||
Signature.cc Signature.h ServerStat.cc ServerStat.h \
|
||||
ServerStatMan.cc ServerStatMan.h URISelector.h \
|
||||
AdaptiveURISelector.cc AdaptiveURISelector.h \
|
||||
InOrderURISelector.cc InOrderURISelector.h \
|
||||
FeedbackURISelector.cc FeedbackURISelector.h NsCookieParser.cc \
|
||||
NsCookieParser.h CookieStorage.cc CookieStorage.h \
|
||||
|
@ -444,7 +445,6 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
TorrentAttribute.h AdaptiveFileAllocationIterator.cc \
|
||||
AdaptiveFileAllocationIterator.h StreamFilter.cc \
|
||||
StreamFilter.h SinkStreamFilter.cc SinkStreamFilter.h \
|
||||
GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h \
|
||||
ChunkedDecodingStreamFilter.cc ChunkedDecodingStreamFilter.h \
|
||||
NullSinkStreamFilter.cc NullSinkStreamFilter.h uri.cc uri.h \
|
||||
XmlRpcRequestParserController.cc \
|
||||
|
@ -467,6 +467,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
LibgnutlsTLSContext.cc LibgnutlsTLSContext.h \
|
||||
LibsslTLSContext.cc LibsslTLSContext.h GZipDecoder.cc \
|
||||
GZipDecoder.h GZipEncoder.cc GZipEncoder.h \
|
||||
GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h \
|
||||
Sqlite3CookieParser.cc Sqlite3CookieParser.h \
|
||||
Sqlite3CookieParserImpl.cc Sqlite3CookieParserImpl.h \
|
||||
AsyncNameResolver.cc AsyncNameResolver.h \
|
||||
|
@ -644,7 +645,8 @@ am__objects_6 =
|
|||
@HAVE_LIBGNUTLS_TRUE@am__objects_7 = LibgnutlsTLSContext.$(OBJEXT)
|
||||
@HAVE_LIBSSL_TRUE@am__objects_8 = LibsslTLSContext.$(OBJEXT)
|
||||
@HAVE_LIBZ_TRUE@am__objects_9 = GZipDecoder.$(OBJEXT) \
|
||||
@HAVE_LIBZ_TRUE@ GZipEncoder.$(OBJEXT)
|
||||
@HAVE_LIBZ_TRUE@ GZipEncoder.$(OBJEXT) \
|
||||
@HAVE_LIBZ_TRUE@ GZipDecodingStreamFilter.$(OBJEXT)
|
||||
@HAVE_SQLITE3_TRUE@am__objects_10 = Sqlite3CookieParser.$(OBJEXT) \
|
||||
@HAVE_SQLITE3_TRUE@ Sqlite3CookieParserImpl.$(OBJEXT)
|
||||
@ENABLE_ASYNC_DNS_TRUE@am__objects_11 = AsyncNameResolver.$(OBJEXT)
|
||||
|
@ -876,19 +878,18 @@ am__objects_32 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
|
|||
HttpSkipResponseCommand.$(OBJEXT) \
|
||||
InitiateConnectionCommand.$(OBJEXT) \
|
||||
FtpFinishDownloadCommand.$(OBJEXT) A2STR.$(OBJEXT) \
|
||||
RarestPieceSelector.$(OBJEXT) ChunkedDecoder.$(OBJEXT) \
|
||||
Signature.$(OBJEXT) ServerStat.$(OBJEXT) \
|
||||
ServerStatMan.$(OBJEXT) AdaptiveURISelector.$(OBJEXT) \
|
||||
InOrderURISelector.$(OBJEXT) FeedbackURISelector.$(OBJEXT) \
|
||||
NsCookieParser.$(OBJEXT) CookieStorage.$(OBJEXT) \
|
||||
SocketBuffer.$(OBJEXT) OptionHandlerException.$(OBJEXT) \
|
||||
URIResult.$(OBJEXT) SelectEventPoll.$(OBJEXT) \
|
||||
RarestPieceSelector.$(OBJEXT) Signature.$(OBJEXT) \
|
||||
ServerStat.$(OBJEXT) ServerStatMan.$(OBJEXT) \
|
||||
AdaptiveURISelector.$(OBJEXT) InOrderURISelector.$(OBJEXT) \
|
||||
FeedbackURISelector.$(OBJEXT) NsCookieParser.$(OBJEXT) \
|
||||
CookieStorage.$(OBJEXT) SocketBuffer.$(OBJEXT) \
|
||||
OptionHandlerException.$(OBJEXT) URIResult.$(OBJEXT) \
|
||||
SelectEventPoll.$(OBJEXT) \
|
||||
LongestSequencePieceSelector.$(OBJEXT) bitfield.$(OBJEXT) \
|
||||
CreateRequestCommand.$(OBJEXT) download_helper.$(OBJEXT) \
|
||||
MetadataInfo.$(OBJEXT) SessionSerializer.$(OBJEXT) \
|
||||
ValueBase.$(OBJEXT) AdaptiveFileAllocationIterator.$(OBJEXT) \
|
||||
StreamFilter.$(OBJEXT) SinkStreamFilter.$(OBJEXT) \
|
||||
GZipDecodingStreamFilter.$(OBJEXT) \
|
||||
ChunkedDecodingStreamFilter.$(OBJEXT) \
|
||||
NullSinkStreamFilter.$(OBJEXT) uri.$(OBJEXT) $(am__objects_1) \
|
||||
$(am__objects_2) $(am__objects_3) $(am__objects_4) \
|
||||
|
@ -1217,9 +1218,9 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
|
|||
InitiateConnectionCommand.h FtpFinishDownloadCommand.cc \
|
||||
FtpFinishDownloadCommand.h A2STR.cc A2STR.h \
|
||||
RarestPieceSelector.cc RarestPieceSelector.h Decoder.h \
|
||||
ChunkedDecoder.cc ChunkedDecoder.h Signature.cc Signature.h \
|
||||
ServerStat.cc ServerStat.h ServerStatMan.cc ServerStatMan.h \
|
||||
URISelector.h AdaptiveURISelector.cc AdaptiveURISelector.h \
|
||||
Signature.cc Signature.h ServerStat.cc ServerStat.h \
|
||||
ServerStatMan.cc ServerStatMan.h URISelector.h \
|
||||
AdaptiveURISelector.cc AdaptiveURISelector.h \
|
||||
InOrderURISelector.cc InOrderURISelector.h \
|
||||
FeedbackURISelector.cc FeedbackURISelector.h NsCookieParser.cc \
|
||||
NsCookieParser.h CookieStorage.cc CookieStorage.h \
|
||||
|
@ -1236,7 +1237,6 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
|
|||
TorrentAttribute.h AdaptiveFileAllocationIterator.cc \
|
||||
AdaptiveFileAllocationIterator.h StreamFilter.cc \
|
||||
StreamFilter.h SinkStreamFilter.cc SinkStreamFilter.h \
|
||||
GZipDecodingStreamFilter.cc GZipDecodingStreamFilter.h \
|
||||
ChunkedDecodingStreamFilter.cc ChunkedDecodingStreamFilter.h \
|
||||
NullSinkStreamFilter.cc NullSinkStreamFilter.h uri.cc uri.h \
|
||||
$(am__append_1) $(am__append_2) $(am__append_3) \
|
||||
|
@ -1407,7 +1407,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CheckIntegrityDispatcherCommand.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CheckIntegrityEntry.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChecksumCheckIntegrityEntry.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedDecoder.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedDecodingStreamFilter.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Command.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ConsoleStatCalc.Po@am__quote@
|
||||
|
|
|
@ -1,179 +0,0 @@
|
|||
#include "ChunkedDecoder.h"
|
||||
#include "DlAbortEx.h"
|
||||
#include <iostream>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class ChunkedDecoderTest:public CppUnit::TestFixture {
|
||||
|
||||
CPPUNIT_TEST_SUITE(ChunkedDecoderTest);
|
||||
CPPUNIT_TEST(testDecode);
|
||||
CPPUNIT_TEST(testDecode_withoutTrailer);
|
||||
CPPUNIT_TEST(testDecode_tooLargeChunkSize);
|
||||
CPPUNIT_TEST(testDecode_chunkSizeMismatch);
|
||||
CPPUNIT_TEST(testGetName);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
void setUp() {}
|
||||
|
||||
void testDecode();
|
||||
void testDecode_withoutTrailer();
|
||||
void testDecode_tooLargeChunkSize();
|
||||
void testDecode_chunkSizeMismatch();
|
||||
void testGetName();
|
||||
};
|
||||
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( ChunkedDecoderTest );
|
||||
|
||||
void ChunkedDecoderTest::testDecode()
|
||||
{
|
||||
ChunkedDecoder decoder;
|
||||
decoder.init();
|
||||
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("a\r\n1234567890\r\n");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1234567890"),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// Feed extension; see it is ignored.
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>
|
||||
("3;extensionIgnored\r\n123\r\n");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("123"),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// Not all chunk size is available
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("1");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("0\r\n1234567890123456\r\n");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1234567890123456"),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// Not all chunk data is available
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("10\r\n1234567890");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1234567890"),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("123456\r\n");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("123456"),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// no trailing CR LF.
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>
|
||||
("10\r\n1234567890123456");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("1234567890123456"),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// feed only CR
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>
|
||||
("\r");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// feed next LF
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>
|
||||
("\n");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// feed 0 CR LF.
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>
|
||||
("0\r\n");
|
||||
CPPUNIT_ASSERT_EQUAL(std::string(),
|
||||
decoder.decode(msg.c_str(), msg.size()));
|
||||
}
|
||||
// feed trailer
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string(),
|
||||
decoder.decode
|
||||
(reinterpret_cast<const unsigned char*>("trailer\r\n"), 9));
|
||||
}
|
||||
// feed final CRLF
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string(),
|
||||
decoder.decode(reinterpret_cast<const unsigned char*>("\r\n"), 2));
|
||||
}
|
||||
// input is over
|
||||
CPPUNIT_ASSERT(decoder.finished());
|
||||
|
||||
decoder.release();
|
||||
}
|
||||
|
||||
void ChunkedDecoderTest::testDecode_withoutTrailer()
|
||||
{
|
||||
ChunkedDecoder decoder;
|
||||
decoder.init();
|
||||
CPPUNIT_ASSERT_EQUAL
|
||||
(std::string(),
|
||||
decoder.decode(reinterpret_cast<const unsigned char*>("0\r\n\r\n"), 5));
|
||||
CPPUNIT_ASSERT(decoder.finished());
|
||||
}
|
||||
|
||||
void ChunkedDecoderTest::testDecode_tooLargeChunkSize()
|
||||
{
|
||||
// chunkSize should be under 2^64-1
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("ffffffffffffffff\r\n");
|
||||
ChunkedDecoder decoder;
|
||||
decoder.decode(msg.c_str(), msg.size());
|
||||
}
|
||||
// chunkSize 2^64 causes error
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("10000000000000000\r\n");
|
||||
ChunkedDecoder decoder;
|
||||
try {
|
||||
decoder.decode(msg.c_str(), msg.size());
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(DlAbortEx& e) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkedDecoderTest::testDecode_chunkSizeMismatch()
|
||||
{
|
||||
std::basic_string<unsigned char> msg =
|
||||
reinterpret_cast<const unsigned char*>("3\r\n1234\r\n");
|
||||
|
||||
ChunkedDecoder decoder;
|
||||
try {
|
||||
decoder.decode(msg.c_str(), msg.size());
|
||||
CPPUNIT_FAIL("exception must be thrown.");
|
||||
} catch(DlAbortEx& e) {
|
||||
// success
|
||||
}
|
||||
}
|
||||
|
||||
void ChunkedDecoderTest::testGetName()
|
||||
{
|
||||
ChunkedDecoder decoder;
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("ChunkedDecoder"), decoder.getName());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
|
@ -48,7 +48,6 @@ aria2c_SOURCES = AllTest.cc\
|
|||
StringFormatTest.cc\
|
||||
ExceptionTest.cc\
|
||||
DownloadHandlerFactoryTest.cc\
|
||||
ChunkedDecoderTest.cc\
|
||||
SignatureTest.cc\
|
||||
ServerStatManTest.cc\
|
||||
FeedbackURISelectorTest.cc\
|
||||
|
|
|
@ -202,16 +202,16 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \
|
|||
MultiDiskAdaptorTest.cc MultiFileAllocationIteratorTest.cc \
|
||||
FixedNumberRandomizer.h ProtocolDetectorTest.cc \
|
||||
StringFormatTest.cc ExceptionTest.cc \
|
||||
DownloadHandlerFactoryTest.cc ChunkedDecoderTest.cc \
|
||||
SignatureTest.cc ServerStatManTest.cc \
|
||||
FeedbackURISelectorTest.cc InOrderURISelectorTest.cc \
|
||||
ServerStatTest.cc NsCookieParserTest.cc \
|
||||
DirectDiskAdaptorTest.cc CookieTest.cc CookieStorageTest.cc \
|
||||
TimeTest.cc FtpConnectionTest.cc OptionParserTest.cc \
|
||||
DNSCacheTest.cc DownloadHelperTest.cc SequentialPickerTest.cc \
|
||||
RarestPieceSelectorTest.cc PieceStatManTest.cc \
|
||||
InOrderPieceSelector.h LongestSequencePieceSelectorTest.cc \
|
||||
a2algoTest.cc bitfieldTest.cc DownloadContextTest.cc \
|
||||
DownloadHandlerFactoryTest.cc SignatureTest.cc \
|
||||
ServerStatManTest.cc FeedbackURISelectorTest.cc \
|
||||
InOrderURISelectorTest.cc ServerStatTest.cc \
|
||||
NsCookieParserTest.cc DirectDiskAdaptorTest.cc CookieTest.cc \
|
||||
CookieStorageTest.cc TimeTest.cc FtpConnectionTest.cc \
|
||||
OptionParserTest.cc DNSCacheTest.cc DownloadHelperTest.cc \
|
||||
SequentialPickerTest.cc RarestPieceSelectorTest.cc \
|
||||
PieceStatManTest.cc InOrderPieceSelector.h \
|
||||
LongestSequencePieceSelectorTest.cc a2algoTest.cc \
|
||||
bitfieldTest.cc DownloadContextTest.cc \
|
||||
SessionSerializerTest.cc ValueBaseTest.cc \
|
||||
ChunkedDecodingStreamFilterTest.cc \
|
||||
GZipDecodingStreamFilterTest.cc UriTest.cc MockSegment.h \
|
||||
|
@ -394,8 +394,8 @@ am_aria2c_OBJECTS = AllTest.$(OBJEXT) TestUtil.$(OBJEXT) \
|
|||
MultiFileAllocationIteratorTest.$(OBJEXT) \
|
||||
ProtocolDetectorTest.$(OBJEXT) StringFormatTest.$(OBJEXT) \
|
||||
ExceptionTest.$(OBJEXT) DownloadHandlerFactoryTest.$(OBJEXT) \
|
||||
ChunkedDecoderTest.$(OBJEXT) SignatureTest.$(OBJEXT) \
|
||||
ServerStatManTest.$(OBJEXT) FeedbackURISelectorTest.$(OBJEXT) \
|
||||
SignatureTest.$(OBJEXT) ServerStatManTest.$(OBJEXT) \
|
||||
FeedbackURISelectorTest.$(OBJEXT) \
|
||||
InOrderURISelectorTest.$(OBJEXT) ServerStatTest.$(OBJEXT) \
|
||||
NsCookieParserTest.$(OBJEXT) DirectDiskAdaptorTest.$(OBJEXT) \
|
||||
CookieTest.$(OBJEXT) CookieStorageTest.$(OBJEXT) \
|
||||
|
@ -634,16 +634,16 @@ aria2c_SOURCES = AllTest.cc TestUtil.cc TestUtil.h SocketCoreTest.cc \
|
|||
MultiDiskAdaptorTest.cc MultiFileAllocationIteratorTest.cc \
|
||||
FixedNumberRandomizer.h ProtocolDetectorTest.cc \
|
||||
StringFormatTest.cc ExceptionTest.cc \
|
||||
DownloadHandlerFactoryTest.cc ChunkedDecoderTest.cc \
|
||||
SignatureTest.cc ServerStatManTest.cc \
|
||||
FeedbackURISelectorTest.cc InOrderURISelectorTest.cc \
|
||||
ServerStatTest.cc NsCookieParserTest.cc \
|
||||
DirectDiskAdaptorTest.cc CookieTest.cc CookieStorageTest.cc \
|
||||
TimeTest.cc FtpConnectionTest.cc OptionParserTest.cc \
|
||||
DNSCacheTest.cc DownloadHelperTest.cc SequentialPickerTest.cc \
|
||||
RarestPieceSelectorTest.cc PieceStatManTest.cc \
|
||||
InOrderPieceSelector.h LongestSequencePieceSelectorTest.cc \
|
||||
a2algoTest.cc bitfieldTest.cc DownloadContextTest.cc \
|
||||
DownloadHandlerFactoryTest.cc SignatureTest.cc \
|
||||
ServerStatManTest.cc FeedbackURISelectorTest.cc \
|
||||
InOrderURISelectorTest.cc ServerStatTest.cc \
|
||||
NsCookieParserTest.cc DirectDiskAdaptorTest.cc CookieTest.cc \
|
||||
CookieStorageTest.cc TimeTest.cc FtpConnectionTest.cc \
|
||||
OptionParserTest.cc DNSCacheTest.cc DownloadHelperTest.cc \
|
||||
SequentialPickerTest.cc RarestPieceSelectorTest.cc \
|
||||
PieceStatManTest.cc InOrderPieceSelector.h \
|
||||
LongestSequencePieceSelectorTest.cc a2algoTest.cc \
|
||||
bitfieldTest.cc DownloadContextTest.cc \
|
||||
SessionSerializerTest.cc ValueBaseTest.cc \
|
||||
ChunkedDecodingStreamFilterTest.cc \
|
||||
GZipDecodingStreamFilterTest.cc UriTest.cc MockSegment.h \
|
||||
|
@ -780,7 +780,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtSuggestPieceMessageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtUnchokeMessageTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ByteArrayDiskWriterTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedDecoderTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ChunkedDecodingStreamFilterTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieParserTest.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/CookieStorageTest.Po@am__quote@
|
||||
|
|
Loading…
Reference in New Issue