aria2/test/UtilTest1.cc

1381 lines
53 KiB
C++
Raw Normal View History

#include "util.h"
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <cppunit/extensions/HelperMacros.h>
#include "FixedNumberRandomizer.h"
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Don't connect server before checking file integrity at startup, if filesize and output file path are known. * src/AbstractCommand.cc * src/StreamFileAllocationEntry.cc * src/Metalink2RequestGroup.cc * src/RequestGroup.{h, cc} * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc Added DownloadFailureException. If it is thrown, RequestGroup should halt. * src/AbstractCommand.cc * src/DownloadFailureException.h * src/RequestGroup.cc Catch RecoverableException, instead of DlAbortEx. * src/RequestGroupMan.cc * src/FillRequestGroupCommand.cc * src/MetaFileUtil.cc * src/IteratableChunkChecksumValidator.cc Now first parameter of MSG_DOWNLOAD_ABORTED is gid(RequestGroup:: getGID()) * src/CheckIntegrityCommand.cc * src/message.h Print gid instead of idx. * src/RequestGroupMan.cc Removed exception throwers declaration. * src/DirectDiskAdaptor.{h, cc} * src/SocketCore.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/HttpConnection.{h, cc} * src/HttpResponse.{h, cc} * src/DiskAdaptor.{h, cc} * src/CopyDiskAdaptor.{h, cc} * src/MultiDiskAdaptor.{h, cc} * src/HttpHeaderProcessor.{h, cc} * src/AbstractSingleDiskAdaptor.{h, cc} * src/Util.{h, cc} * test/UtilTest.cc * src/DefaultDiskWriter.{h, cc} * src/FtpConnection.{h, cc} * src/AbstractDiskWriter.{h, cc} Removed duplicate code. * src/StreamCheckIntegrityEntry.cc Removed unnecessary include. * src/DiskWriter.h Included Exception.h * src/option_processing.cc Included 2 files and added doc * src/TrackerWatcherCommand.cc * src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
#include "DlAbortEx.h"
#include "BitfieldMan.h"
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Rewritten to add content-type support. * src/DownloadHandler.{h, cc} * src/BtPostDownloadHandler.{h, cc} * test/BtPostDownloadHandlerTest.cc * src/MetalinkPostDownloadHandler.{h, cc} * test/MetalinkPostDownloadHandlerTest.cc * src/PostDownloadHandler.{h, cc} * src/DownloadHandlerConstants.{h, cc} * src/RequestGroup.cc * src/HttpResponseCommand.cc * src/FtpNegotiationCommand.cc * src/SingleFileDownloadContext.{h, cc} * src/RequestGroup.h * src/RequestGroupCriteria.h * src/ContentTypeRequestGroupCriteria.h Added 'mem' option value for --follow-metalink, --follow-torrent. If it is give, metalink/torrent file is not written to the disk, but just is kept in memory. Parsing is occurred on memory. * src/MetalinkHelper.{h, cc} * src/MetalinkProcessor.h * src/Xml2MetalinkProcessor.{h, cc} * test/Xml2MetalinkProcessorTest.cc * src/DownloadHandlerFactory.{h, cc} * test/DownloadHandlerFactoryTest.cc * src/PreDownloadHandler.{h, cc} * src/OptionHandlerFactory.cc * src/DefaultBtContext.{h, cc} * test/DefaultBtContextTest.cc * src/version_usage.cc * src/Metalink2RequestGroup.{h, cc} * src/RequestGroup.{h, cc} * src/a2functional.h * test/a2functionalTest.cc * src/MemoryBufferPreDownloadHandler.{h, cc} * src/OptionHandlerImpl.h * src/prefs.h * src/Util.{h, cc} * test/UtilTest.cc Keep DownloadResult rather than RequestGroup after downloads to reduce memory usage. * src/RequestGroupMan.{h, cc} * src/DownloadEngine.cc * src/BtDependency.{h, cc}: Changed the type of dependee from WeakHandle to SharedHandle because WeakHandle could be null. * src/RequestGroup.{h, cc} * src/DownloadEngineFactory.cc * src/DownloadResult.h Set totalLength after download finished * src/UnknownLengthPieceStorage.{h, cc} Keep torrent file specified in metalink in memory. * src/Metalink2RequestGroup.cc * src/BtDependency.cc * src/TrueRequestGroupCriteria.h Fixed the bug: seekg is used where seekp should be used. * src/ByteArrayDiskWriter.cc * test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
#include "ByteArrayDiskWriter.h"
#include "FileEntry.h"
#include "File.h"
#include "array_fun.h"
#include "BufferedFile.h"
#include "TestUtil.h"
#include "SocketCore.h"
2006-02-17 13:35:04 +00:00
namespace aria2 {
2006-02-17 13:35:04 +00:00
class UtilTest1:public CppUnit::TestFixture {
2006-02-17 13:35:04 +00:00
CPPUNIT_TEST_SUITE(UtilTest1);
CPPUNIT_TEST(testStrip);
CPPUNIT_TEST(testStripIter);
CPPUNIT_TEST(testLstripIter);
CPPUNIT_TEST(testLstripIter_char);
CPPUNIT_TEST(testDivide);
2006-02-17 13:35:04 +00:00
CPPUNIT_TEST(testSplit);
CPPUNIT_TEST(testSplitIter);
CPPUNIT_TEST(testSplitIterM);
CPPUNIT_TEST(testStreq);
CPPUNIT_TEST(testStrieq);
CPPUNIT_TEST(testStrifind);
2006-02-21 12:27:17 +00:00
CPPUNIT_TEST(testEndsWith);
CPPUNIT_TEST(testIendsWith);
2006-02-21 15:01:05 +00:00
CPPUNIT_TEST(testReplace);
CPPUNIT_TEST(testStartsWith);
2011-11-04 15:33:35 +00:00
CPPUNIT_TEST(testIstartsWith);
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
// may be moved to other helper class in the future.
CPPUNIT_TEST(testGetContentDispositionFilename);
CPPUNIT_TEST(testParseContentDisposition1);
CPPUNIT_TEST(testParseContentDisposition2);
2006-02-17 13:35:04 +00:00
CPPUNIT_TEST_SUITE_END();
private:
public:
void setUp() {
}
void testStrip();
void testStripIter();
void testLstripIter();
void testLstripIter_char();
void testDivide();
2006-02-17 13:35:04 +00:00
void testSplit();
void testSplitIter();
void testSplitIterM();
void testStreq();
void testStrieq();
void testStrifind();
2006-02-21 12:27:17 +00:00
void testEndsWith();
void testIendsWith();
2006-02-21 15:01:05 +00:00
void testReplace();
void testStartsWith();
2011-11-04 15:33:35 +00:00
void testIstartsWith();
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
// may be moved to other helper class in the future.
void testGetContentDispositionFilename();
void testParseContentDisposition1();
void testParseContentDisposition2();
2006-02-17 13:35:04 +00:00
};
CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest1 );
2006-02-17 13:35:04 +00:00
void UtilTest1::testStrip()
{
std::string str1 = "aria2";
CPPUNIT_ASSERT_EQUAL(str1, util::strip("aria2"));
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2"));
CPPUNIT_ASSERT_EQUAL(str1, util::strip("aria2 "));
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2 "));
CPPUNIT_ASSERT_EQUAL(str1, util::strip(" aria2 "));
std::string str2 = "aria2 debut";
CPPUNIT_ASSERT_EQUAL(str2, util::strip("aria2 debut"));
CPPUNIT_ASSERT_EQUAL(str2, util::strip(" aria2 debut "));
std::string str3 = "";
CPPUNIT_ASSERT_EQUAL(str3, util::strip(""));
CPPUNIT_ASSERT_EQUAL(str3, util::strip(" "));
CPPUNIT_ASSERT_EQUAL(str3, util::strip(" "));
std::string str4 = "A";
CPPUNIT_ASSERT_EQUAL(str4, util::strip("A"));
CPPUNIT_ASSERT_EQUAL(str4, util::strip(" A "));
CPPUNIT_ASSERT_EQUAL(str4, util::strip(" A "));
}
void UtilTest1::testStripIter()
{
Scip p;
std::string str1 = "aria2";
std::string s = "aria2";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
s = " aria2";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
s = "aria2 ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
s = " aria2 ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
s = " aria2 ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str1, std::string(p.first, p.second));
std::string str2 = "aria2 debut";
s = "aria2 debut";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str2, std::string(p.first, p.second));
s = " aria2 debut ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str2, std::string(p.first, p.second));
std::string str3 = "";
s = "";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str3, std::string(p.first, p.second));
s = " ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str3, std::string(p.first, p.second));
s = " ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str3, std::string(p.first, p.second));
std::string str4 = "A";
s = "A";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str4, std::string(p.first, p.second));
s = " A ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str4, std::string(p.first, p.second));
s = " A ";
p = util::stripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(str4, std::string(p.first, p.second));
}
void UtilTest1::testLstripIter()
{
std::string::iterator r;
std::string s = "foo";
r = util::lstripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(r, s.end()));
2012-10-01 14:52:22 +00:00
s = " foo bar ";
r = util::lstripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(std::string("foo bar "), std::string(r, s.end()));
s = "f";
r = util::lstripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(std::string("f"), std::string(r, s.end()));
s = "foo ";
r = util::lstripIter(s.begin(), s.end());
CPPUNIT_ASSERT_EQUAL(std::string("foo "), std::string(r, s.end()));
}
void UtilTest1::testLstripIter_char()
{
std::string::iterator r;
std::string s = "foo";
r = util::lstripIter(s.begin(), s.end(), '$');
CPPUNIT_ASSERT_EQUAL(std::string("foo"), std::string(r, s.end()));
2012-10-01 14:52:22 +00:00
s = "$$foo$bar$$";
r = util::lstripIter(s.begin(), s.end(), '$');
CPPUNIT_ASSERT_EQUAL(std::string("foo$bar$$"), std::string(r, s.end()));
s = "f";
r = util::lstripIter(s.begin(), s.end(), '$');
CPPUNIT_ASSERT_EQUAL(std::string("f"), std::string(r, s.end()));
s = "foo$$";
r = util::lstripIter(s.begin(), s.end(), '$');
CPPUNIT_ASSERT_EQUAL(std::string("foo$$"), std::string(r, s.end()));
}
void UtilTest1::testDivide() {
std::string s = "name=value";
2013-06-24 15:07:15 +00:00
auto p1 = util::divide(std::begin(s), std::end(s), '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"),
std::string(p1.first.first, p1.first.second));
CPPUNIT_ASSERT_EQUAL(std::string("value"),
std::string(p1.second.first, p1.second.second));
s = " name = value ";
2013-06-24 15:07:15 +00:00
p1 = util::divide(std::begin(s), std::end(s), '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"),
std::string(p1.first.first, p1.first.second));
CPPUNIT_ASSERT_EQUAL(std::string("value"),
std::string(p1.second.first, p1.second.second));
s = "=value";
2013-06-24 15:07:15 +00:00
p1 = util::divide(std::begin(s), std::end(s), '=');
CPPUNIT_ASSERT_EQUAL(std::string(""),
std::string(p1.first.first, p1.first.second));
CPPUNIT_ASSERT_EQUAL(std::string("value"),
std::string(p1.second.first, p1.second.second));
s = "name=";
2013-06-24 15:07:15 +00:00
p1 = util::divide(std::begin(s), std::end(s), '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"),
std::string(p1.first.first, p1.first.second));
CPPUNIT_ASSERT_EQUAL(std::string(""),
std::string(p1.second.first, p1.second.second));
s = "name";
2013-06-24 15:07:15 +00:00
p1 = util::divide(std::begin(s), std::end(s), '=');
CPPUNIT_ASSERT_EQUAL(std::string("name"),
std::string(p1.first.first, p1.first.second));
CPPUNIT_ASSERT_EQUAL(std::string(""),
std::string(p1.second.first, p1.second.second));
2006-02-17 13:35:04 +00:00
}
void UtilTest1::testSplit() {
std::vector<std::string> v;
std::string s = "k1; k2;; k3";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', true);
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
std::vector<std::string>::iterator itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k3"), *itr++);
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To divide TorrentMan into 6 classes: BtContext, BtRuntime, PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile * src/TrackerWatcherComand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.cc: Use pieceStorage, btRuntime * src/PeerAbstractCommand.h: Made subclass of BtContextAwareCommand. * src/PeerAbstractCommand.cc: Use btRuntime. * src/BtContextAwareCommand.h: New class. * src/FileEntry.h: Added accessor methods for following variables. (path): Made private. (length): Made private. (offset): Made private. (extracted): Made private. (requested): Made private. (FileEntries): New definition. (FileEntryHandle): New definition. * src/FileEntry.cc: New file. * src/HaveEraseCommand.h: Made subclass of BtContextAwareCommand. * src/HaveEraseCommand.cc: Use btRuntime, pieceStorage. * src/PeerChokeCommand.h: Made subclass of BtContextAwareCommand. * src/PeerChokeCommand.cc: Use btRuntime, peerStorage, pieceStorage. * src/PieceStorage.h: New file. * src/PeerInteractionCommand.h: Use btContext. * src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage, btRuntime. * src/DefaultBtProgressInfoFile.h: New file. * src/DefaultBtProgressInfoFile.cc: New file. * src/File.cc (Util.h): New include. (mkdirs): New function. * src/MultiDiskAdaptor.h (mkdir): New function. * src/PeerListProcessor.h (Peers): Removed. * src/PeerInteraction.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (btAnnounce): New variable. (getTorrentMan): Removed. (getBtContext): New function. * src/PeerInteraction.cc: Use btContext, peerStorage, pieceStorage, btAnnounce. * src/HandshakeMessage.h (TorrentMan.h): Removed. * src/HandshakeMessage.cc: Use btContext. * src/DefaultBtAnnounce.cc: New file. * src/MultiDiskWriter.cc: Use the accessor methods of FileEntry. * src/DefaultPieceStorage.cc: New file. * src/DefaultBtContext.h: New file. * src/TorrentRequestInfo.cc: Use btContext, pieceStorage. Use the accessor methods of FileEntry. * src/CookieBox.cc: Updated to use Util::slice(). * src/PieceMessage.cc: Use btContext, pieceStorage. * src/common.h (SharedHandle.h): New include. * src/PeerMessage.cc (PeerMessage): Added btContext, peerStorage, pieceStorage. * src/TorrentAutoSaveCommand.h: Made subclass of BtContextAwareCommand. * src/DiskAdaptor.h (topDir): Removed. (getFileEntryFromPath): Changed the return type to FileEntryHandle. (setTopDir): Removed. (getTopDir): Removed. * src/BtContext.h: New file. * src/DefaultPeerStorage.h: New file. * src/PieceMessage.h (TorrentMan.h): Removed. * src/RequestMessage.h (TorrentMan.h): Removed. * src/TorrentDownloadEngine.h (uploadLength): New variable. (btContext): New variable. (btRuntime): New variable. (pieceStorage): New variable. (peerStorage): New variable. (btAnnounce): New variable. (btProgressInfoFile): New variable. (torrentMan): Removed. (setBtContext): New function. * src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime, pieceStorage, peerStorage, btAnnounce, btProgressInfoFile. * src/Piece.h (toString): New function. (Pieces): New type definition. * src/Peer.h (active): New variable. (Peer): Added active. (activate): Set active to true. (deactivate): Set active to false. (isActive): New function. (Peers): New type definition. * src/DirectDiskAdaptor.cc (getFilePath): Use the accessor methods of FileEntry. * src/TorrentConsoleDownloadEngine.h (afterEachIteration): New function. * src/TorrentConsoleDownloadEngine.cc (haltRequested): New variable. (sendStatistics): Use pieceStorage, btRuntime. (afterEachIteration): New function. * src/AnnounceList: AnnounceTier->AnnounceTierHandle. * src/Directry.h (Directory): New function. (DirectoryHandle): New type definition. * src/BtProgressInfoFile.h: New file. * src/RequestMessage.cc: Use pieceStorage. * src/BtRuntime.h: New file. * src/DefaultBtContext.cc: New file. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/MultiDiskAdaptor.cc (mkdir): New function. (openFile): Call mkdir(). (initAndOpenFile): Call mkdir(). * src/CancelMessage.h (TorrentMan.h): Removed. * src/RejectMessage.h (TorrentMan.h): Removed. * src/DownloadEngineFactory.cc (DefaultPieceStorage.h): New include. (DefaultPeerStorage.h): New include. (DefaultBtAnnounce.h): New include. (DefaultBtProgressInfoFile.h): New include. (newTorrentConsoleEngine): Rewritten. * src/ShareRatioSeedCriteria.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (btRuntime): New variable. (evaluate): Use btContext, btRuntime, peerStorage. * src/AnnounceTier.h: New file. * src/BtAnnounce.h: New file. * src/BtRegistry.h: New file. * src/PeerInitiateConnectionCommand.h: Added btContext. * src/PeerConnection.h (TorrentMan.h): Removed. * src/PeerMessageFactory.cc: Use btContext, pieceStorage. * src/Util.h (slice): Added an argument. * src/Util.cc (slice): Added an argument to control whether trim is made or not. * src/PeerStorage.h: New file. * src/BtRegistry.cc: New file. * src/TrackerUpdateCommand.h: Made subclass of BtContextAwareCommand. * src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry. * src/MultiDiskWriter.h: FileEntry -> FileEntryHandle * src/PeerListenCommand.cc: Use btRuntime, peerStorage, btContext. * src/TorrentRequestInfo.h (e): Removed. (showFileEntry): Added an argument. (getDownloadEngine): Return 0. * src/DefaultBtAnnounce.h: New file. * src/TorrentAutoSaveCommand.cc: Use btRuntime, btProgressInfoFile. * src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce, * src/PeerMessageFactory.h (btContext): New variable. (pieceStorage): New variable. * src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage, btContext, btAnnounce. * src/DiskAdaptor.cc (DiskAdaptor): Removed topDir. (~DiskAdaptor): Removed topDir. * src/PeerListenCommand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.h: Made subclass of BtContextAwareCommand. * src/File.h (mkdirs): New function. * src/DefaultPeerStorage): New file. * src/DownloadEngineFactory.h (newTorrentConsoleEngine): Use btContext. * src/BtContextAwareCommand.cc: New file. * src/PeerInitiateConnectionCommand.cc: Use btRuntime, peerStorage. * src/PeerMessage.h (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (setBtContext): New function. * src/Directry.cc (Directory): New function. (createDir): Do nothing if name.size() == 0. * src/AnnounceList.h (AnnounceTier): Removed. (AnnounceTiers): Removed. * src/DefaultPieceStorage.h: New file. * src/Piece.cc (toString): New function. To fix typo: * src/main.cc (showVersion): Fixed typo. To fix compile warning: * src/DelegatingPeerListProcessor.cc (canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
v.clear();
2006-11-05 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To divide TorrentMan into 6 classes: BtContext, BtRuntime, PeerStorage, PieceStorage, BtAnnounce and BtProgressInfoFile * src/TrackerWatcherComand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.cc: Use pieceStorage, btRuntime * src/PeerAbstractCommand.h: Made subclass of BtContextAwareCommand. * src/PeerAbstractCommand.cc: Use btRuntime. * src/BtContextAwareCommand.h: New class. * src/FileEntry.h: Added accessor methods for following variables. (path): Made private. (length): Made private. (offset): Made private. (extracted): Made private. (requested): Made private. (FileEntries): New definition. (FileEntryHandle): New definition. * src/FileEntry.cc: New file. * src/HaveEraseCommand.h: Made subclass of BtContextAwareCommand. * src/HaveEraseCommand.cc: Use btRuntime, pieceStorage. * src/PeerChokeCommand.h: Made subclass of BtContextAwareCommand. * src/PeerChokeCommand.cc: Use btRuntime, peerStorage, pieceStorage. * src/PieceStorage.h: New file. * src/PeerInteractionCommand.h: Use btContext. * src/PeerInteractionCommand.cc: Use pieceStorage, peerStorage, btRuntime. * src/DefaultBtProgressInfoFile.h: New file. * src/DefaultBtProgressInfoFile.cc: New file. * src/File.cc (Util.h): New include. (mkdirs): New function. * src/MultiDiskAdaptor.h (mkdir): New function. * src/PeerListProcessor.h (Peers): Removed. * src/PeerInteraction.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (btAnnounce): New variable. (getTorrentMan): Removed. (getBtContext): New function. * src/PeerInteraction.cc: Use btContext, peerStorage, pieceStorage, btAnnounce. * src/HandshakeMessage.h (TorrentMan.h): Removed. * src/HandshakeMessage.cc: Use btContext. * src/DefaultBtAnnounce.cc: New file. * src/MultiDiskWriter.cc: Use the accessor methods of FileEntry. * src/DefaultPieceStorage.cc: New file. * src/DefaultBtContext.h: New file. * src/TorrentRequestInfo.cc: Use btContext, pieceStorage. Use the accessor methods of FileEntry. * src/CookieBox.cc: Updated to use Util::slice(). * src/PieceMessage.cc: Use btContext, pieceStorage. * src/common.h (SharedHandle.h): New include. * src/PeerMessage.cc (PeerMessage): Added btContext, peerStorage, pieceStorage. * src/TorrentAutoSaveCommand.h: Made subclass of BtContextAwareCommand. * src/DiskAdaptor.h (topDir): Removed. (getFileEntryFromPath): Changed the return type to FileEntryHandle. (setTopDir): Removed. (getTopDir): Removed. * src/BtContext.h: New file. * src/DefaultPeerStorage.h: New file. * src/PieceMessage.h (TorrentMan.h): Removed. * src/RequestMessage.h (TorrentMan.h): Removed. * src/TorrentDownloadEngine.h (uploadLength): New variable. (btContext): New variable. (btRuntime): New variable. (pieceStorage): New variable. (peerStorage): New variable. (btAnnounce): New variable. (btProgressInfoFile): New variable. (torrentMan): Removed. (setBtContext): New function. * src/TorrentDownloadEngine.cc: Use BtContext, BtRuntime, pieceStorage, peerStorage, btAnnounce, btProgressInfoFile. * src/Piece.h (toString): New function. (Pieces): New type definition. * src/Peer.h (active): New variable. (Peer): Added active. (activate): Set active to true. (deactivate): Set active to false. (isActive): New function. (Peers): New type definition. * src/DirectDiskAdaptor.cc (getFilePath): Use the accessor methods of FileEntry. * src/TorrentConsoleDownloadEngine.h (afterEachIteration): New function. * src/TorrentConsoleDownloadEngine.cc (haltRequested): New variable. (sendStatistics): Use pieceStorage, btRuntime. (afterEachIteration): New function. * src/AnnounceList: AnnounceTier->AnnounceTierHandle. * src/Directry.h (Directory): New function. (DirectoryHandle): New type definition. * src/BtProgressInfoFile.h: New file. * src/RequestMessage.cc: Use pieceStorage. * src/BtRuntime.h: New file. * src/DefaultBtContext.cc: New file. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/BitfieldMan.h (getCompletedLength): New function(private). (getCompletedLength): New function. (getFilteredCompletedLength): New function. * src/MultiDiskAdaptor.cc (mkdir): New function. (openFile): Call mkdir(). (initAndOpenFile): Call mkdir(). * src/CancelMessage.h (TorrentMan.h): Removed. * src/RejectMessage.h (TorrentMan.h): Removed. * src/DownloadEngineFactory.cc (DefaultPieceStorage.h): New include. (DefaultPeerStorage.h): New include. (DefaultBtAnnounce.h): New include. (DefaultBtProgressInfoFile.h): New include. (newTorrentConsoleEngine): Rewritten. * src/ShareRatioSeedCriteria.h (torrentMan): Removed. (btContext): New variable. (peerStorage): New variable. (btRuntime): New variable. (evaluate): Use btContext, btRuntime, peerStorage. * src/AnnounceTier.h: New file. * src/BtAnnounce.h: New file. * src/BtRegistry.h: New file. * src/PeerInitiateConnectionCommand.h: Added btContext. * src/PeerConnection.h (TorrentMan.h): Removed. * src/PeerMessageFactory.cc: Use btContext, pieceStorage. * src/Util.h (slice): Added an argument. * src/Util.cc (slice): Added an argument to control whether trim is made or not. * src/PeerStorage.h: New file. * src/BtRegistry.cc: New file. * src/TrackerUpdateCommand.h: Made subclass of BtContextAwareCommand. * src/CopyDiskAdaptor.cc: Use the accessor methods of FileEntry. * src/MultiDiskWriter.h: FileEntry -> FileEntryHandle * src/PeerListenCommand.cc: Use btRuntime, peerStorage, btContext. * src/TorrentRequestInfo.h (e): Removed. (showFileEntry): Added an argument. (getDownloadEngine): Return 0. * src/DefaultBtAnnounce.h: New file. * src/TorrentAutoSaveCommand.cc: Use btRuntime, btProgressInfoFile. * src/TrackerWatcherComand.cc: Use btRuntime, btAnnounce, * src/PeerMessageFactory.h (btContext): New variable. (pieceStorage): New variable. * src/TrackerUpdateCommand.cc: Use btRuntime, peerStorage, btContext, btAnnounce. * src/DiskAdaptor.cc (DiskAdaptor): Removed topDir. (~DiskAdaptor): Removed topDir. * src/PeerListenCommand.h: Made subclass of BtContextAwareCommand. * src/SeedCheckCommand.h: Made subclass of BtContextAwareCommand. * src/File.h (mkdirs): New function. * src/DefaultPeerStorage): New file. * src/DownloadEngineFactory.h (newTorrentConsoleEngine): Use btContext. * src/BtContextAwareCommand.cc: New file. * src/PeerInitiateConnectionCommand.cc: Use btRuntime, peerStorage. * src/PeerMessage.h (btContext): New variable. (peerStorage): New variable. (pieceStorage): New variable. (setBtContext): New function. * src/Directry.cc (Directory): New function. (createDir): Do nothing if name.size() == 0. * src/AnnounceList.h (AnnounceTier): Removed. (AnnounceTiers): Removed. * src/DefaultPieceStorage.h: New file. * src/Piece.cc (toString): New function. To fix typo: * src/main.cc (showVersion): Fixed typo. To fix compile warning: * src/DelegatingPeerListProcessor.cc (canHandle): Added "return false".
2006-11-05 15:04:17 +00:00
s = "k1; k2; k3";
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(" k2"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(" k3"), *itr++);
v.clear();
s = "k=v";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k=v"), *itr++);
v.clear();
s = ";;k1;;k2;";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
v.clear();
s = ";;k1;;k2;";
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k1"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string("k2"), *itr++);
v.clear();
s = "k; ";
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string("k"), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(" "), *itr++);
v.clear();
s = " ";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', true, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), v[0]);
v.clear();
s = " ";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', true);
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
s = " ";
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(" "), v[0]);
v.clear();
s = ";";
util::split(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
s = ";";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
itr = v.begin();
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
CPPUNIT_ASSERT_EQUAL(std::string(""), *itr++);
v.clear();
s = "";
util::split(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), v[0]);
2006-02-17 13:35:04 +00:00
}
2006-02-21 12:27:17 +00:00
void UtilTest1::testSplitIter() {
std::vector<Scip> v;
std::string s = "k1; k2;; k3";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', true);
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[2].first, v[2].second));
v.clear();
s = "k1; k2; k3";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(" k2"),
std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string(" k3"),
std::string(v[2].first, v[2].second));
v.clear();
s = "k=v";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k=v"),
std::string(v[0].first, v[0].second));
v.clear();
s = ";;k1;;k2;";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[2].first, v[2].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[3].first, v[3].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[4].first, v[4].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[5].first, v[5].second));
v.clear();
s = ";;k1;;k2;";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
v.clear();
s = "k; ";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[1].first, v[1].second));
v.clear();
s = " ";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', true, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
v.clear();
s = " ";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', true);
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
s = " ";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[0].first, v[0].second));
v.clear();
s = ";";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';');
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
s = ";";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
v.clear();
s = "";
util::splitIter(s.begin(), s.end(), std::back_inserter(v), ';', false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
}
void UtilTest1::testSplitIterM() {
const char d[] = ";";
const char md[] = "; ";
std::vector<Scip> v;
std::string s = "k1; k2;; k3";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, true);
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[2].first, v[2].second));
v.clear();
s = "k1; k2; k3";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(" k2"),
std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string(" k3"),
std::string(v[2].first, v[2].second));
v.clear();
s = "k1; k2; k3";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), md);
CPPUNIT_ASSERT_EQUAL((size_t)3, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[2].first, v[2].second));
v.clear();
s = "k1; k2; k3;";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), md, false, true);
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[2].first, v[2].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[3].first, v[3].second));
CPPUNIT_ASSERT_EQUAL(std::string("k3"), std::string(v[4].first, v[4].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[5].first, v[5].second));
v.clear();
s = "k=v";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k=v"),
std::string(v[0].first, v[0].second));
v.clear();
s = ";;k1;;k2;";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
CPPUNIT_ASSERT_EQUAL((size_t)6, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[2].first, v[2].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[3].first, v[3].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[4].first, v[4].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[5].first, v[5].second));
v.clear();
s = ";;k1;;k2;";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k1"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string("k2"), std::string(v[1].first, v[1].second));
v.clear();
s = "k; ";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
CPPUNIT_ASSERT_EQUAL(std::string("k"), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[1].first, v[1].second));
v.clear();
s = " ";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, true, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
v.clear();
s = " ";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, true);
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
s = " ";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(" "), std::string(v[0].first, v[0].second));
v.clear();
s = ";";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d);
CPPUNIT_ASSERT_EQUAL((size_t)0, v.size());
v.clear();
s = ";";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
CPPUNIT_ASSERT_EQUAL((size_t)2, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[1].first, v[1].second));
v.clear();
s = "";
util::splitIterM(s.begin(), s.end(), std::back_inserter(v), d, false, true);
CPPUNIT_ASSERT_EQUAL((size_t)1, v.size());
CPPUNIT_ASSERT_EQUAL(std::string(""), std::string(v[0].first, v[0].second));
}
void UtilTest1::testEndsWith() {
std::string target = "abcdefg";
std::string part = "fg";
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "abdefg";
part = "g";
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "abdefg";
part = "eg";
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "g";
part = "eg";
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "g";
part = "g";
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "g";
part = "";
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "";
part = "";
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
2006-02-21 12:27:17 +00:00
target = "";
part = "g";
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
part.begin(), part.end()));
}
void UtilTest1::testIendsWith() {
std::string target = "abcdefg";
std::string part = "Fg";
CPPUNIT_ASSERT(util::iendsWith(target.begin(), target.end(),
part.begin(), part.end()));
target = "abdefg";
part = "ef";
CPPUNIT_ASSERT(!util::iendsWith(target.begin(), target.end(),
part.begin(), part.end()));
}
void UtilTest1::testStreq()
{
std::string s1, s2;
s1 = "foo";
s2 = "foo";
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.c_str()));
s2 = "fooo";
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.c_str()));
s2 = "fo";
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.c_str()));
s2 = "";
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(!util::streq(s1.begin(), s1.end(), s2.c_str()));
s1 = "";
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(util::streq(s1.begin(), s1.end(), s2.c_str()));
}
void UtilTest1::testStrieq()
{
std::string s1, s2;
s1 = "foo";
s2 = "foo";
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.c_str()));
s1 = "FoO";
s2 = "fOo";
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.c_str()));
s2 = "fooo";
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.c_str()));
s2 = "fo";
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.c_str()));
s2 = "";
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(!util::strieq(s1.begin(), s1.end(), s2.c_str()));
s1 = "";
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.begin(), s2.end()));
CPPUNIT_ASSERT(util::strieq(s1.begin(), s1.end(), s2.c_str()));
2006-02-21 12:27:17 +00:00
}
2006-02-21 15:01:05 +00:00
void UtilTest1::testStrifind()
{
std::string s1, s2;
s1 = "yamagakani mukashi wo toheba hARU no tuki";
s2 = "HaRu";
CPPUNIT_ASSERT(util::strifind(s1.begin(), s1.end(), s2.begin(), s2.end())
!= s1.end());
s2 = "aki";
CPPUNIT_ASSERT(util::strifind(s1.begin(), s1.end(), s2.begin(), s2.end())
== s1.end());
s1 = "h";
s2 = "HH";
CPPUNIT_ASSERT(util::strifind(s1.begin(), s1.end(), s2.begin(), s2.end())
== s1.end());
}
void UtilTest1::testReplace() {
CPPUNIT_ASSERT_EQUAL(std::string("abc\n"), util::replace("abc\r\n", "\r", ""));
CPPUNIT_ASSERT_EQUAL(std::string("abc"), util::replace("abc\r\n", "\r\n", ""));
CPPUNIT_ASSERT_EQUAL(std::string(""), util::replace("", "\r\n", ""));
CPPUNIT_ASSERT_EQUAL(std::string("abc"), util::replace("abc", "", "a"));
CPPUNIT_ASSERT_EQUAL(std::string("xbc"), util::replace("abc", "a", "x"));
2006-02-21 15:01:05 +00:00
}
void UtilTest1::testStartsWith() {
std::string target;
std::string part;
target = "abcdefg";
part = "abc";
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
target = "abcdefg";
part = "abx";
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(), part.c_str()));
target = "abcdefg";
part = "bcd";
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(), part.c_str()));
target = "";
part = "a";
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(!util::startsWith(target.begin(), target.end(), part.c_str()));
target = "";
part = "";
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
2012-10-01 14:52:22 +00:00
target = "a";
part = "";
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
target = "a";
part = "a";
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(util::startsWith(target.begin(), target.end(), part.c_str()));
}
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
void UtilTest1::testIstartsWith() {
2011-11-04 15:33:35 +00:00
std::string target;
std::string part;
target = "abcdefg";
part = "aBc";
CPPUNIT_ASSERT(util::istartsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(util::istartsWith(target.begin(), target.end(), part.c_str()));
2011-11-04 15:33:35 +00:00
target = "abcdefg";
part = "abx";
CPPUNIT_ASSERT(!util::istartsWith(target.begin(), target.end(),
part.begin(), part.end()));
CPPUNIT_ASSERT(!util::istartsWith(target.begin(), target.end(), part.c_str()));
2011-11-04 15:33:35 +00:00
}
void UtilTest1::testGetContentDispositionFilename() {
std::string val;
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
val = "attachment; filename=\"aria2.tar.bz2\"";
CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"),
util::getContentDispositionFilename(val));
val = "attachment; filename=\"\"";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=\"";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename= \" aria2.tar.bz2 \"";
CPPUNIT_ASSERT_EQUAL(std::string(" aria2.tar.bz2 "),
util::getContentDispositionFilename(val));
val = "attachment; filename=dir/file";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=dir\\file";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=\"dir/file\"";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=\"dir\\\\file\"";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=\"/etc/passwd\"";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=\"..\"";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
val = "attachment; filename=..";
CPPUNIT_ASSERT_EQUAL(std::string(""),
util::getContentDispositionFilename(val));
// Unescaping %2E%2E%2F produces "../". But since we won't unescape,
// we just accept it as is.
val = "attachment; filename=\"%2E%2E%2Ffoo.html\"";
CPPUNIT_ASSERT_EQUAL(std::string("%2E%2E%2Ffoo.html"),
util::getContentDispositionFilename(val));
// iso-8859-1 string will be converted to utf-8.
val = "attachment; filename*=iso-8859-1''foo-%E4.html";
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
util::getContentDispositionFilename(val));
val = "attachment; filename*= UTF-8''foo-%c3%a4.html";
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
util::getContentDispositionFilename(val));
// iso-8859-1 string will be converted to utf-8.
val = "attachment; filename=\"foo-%E4.html\"";
val = util::percentDecode(val.begin(), val.end());
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
util::getContentDispositionFilename(val));
}
void UtilTest1::testParseContentDisposition1() {
char dest[1_k];
size_t destlen = sizeof(dest);
const char *cs;
size_t cslen;
std::string val;
// test cases from http://greenbytes.de/tech/tc2231/
// inlonly
val = "inline";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// inlonlyquoted
val = "\"inline\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// inlwithasciifilename
val = "inline; filename=\"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// inlwithfnattach
val = "inline; filename=\"Not an attachment!\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)18, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("Not an attachment!"),
std::string(&dest[0], &dest[18]));
// inlwithasciifilenamepdf
val = "inline; filename=\"foo.pdf\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)7, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.pdf"),
std::string(&dest[0], &dest[7]));
// attwithasciifilename25
val = "attachment; filename=\"0000000000111111111122222\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)25, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("0000000000111111111122222"),
std::string(&dest[0], &dest[25]));
// attwithasciifilename35
val = "attachment; filename=\"00000000001111111111222222222233333\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)35, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("00000000001111111111222222222233333"),
std::string(&dest[0], &dest[35]));
// attwithasciifnescapedchar
val = "attachment; filename=\"f\\oo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attwithasciifnescapedquote
val = "attachment; filename=\"\\\"quoting\\\" tested.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)21, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("\"quoting\" tested.html"),
std::string(&dest[0], &dest[21]));
// attwithquotedsemicolon
val = "attachment; filename=\"Here's a semicolon;.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)24, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("Here's a semicolon;.html"),
std::string(&dest[0], &dest[24]));
// attwithfilenameandextparam
val = "attachment; foo=\"bar\"; filename=\"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attwithfilenameandextparamescaped
val = "attachment; foo=\"\\\"\\\\\";filename=\"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attwithasciifilenameucase
val = "attachment; FILENAME=\"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attwithasciifilenamenq
val = "attachment; filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attwithtokfncommanq
val = "attachment; filename=foo,bar.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithasciifilenamenqs
val = "attachment; filename=foo.html ;";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attemptyparam
val = "attachment; ;filename=foo";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithasciifilenamenqws
val = "attachment; filename=foo bar.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfntokensq
val = "attachment; filename='foo.bar'";
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("'foo.bar'"),
std::string(&dest[0], &dest[9]));
// attwithisofnplain
// attachment; filename="foo-ä.html"
val = "attachment; filename=\"foo-%E4.html\"";
val = util::percentDecode(val.begin(), val.end());
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
// attwithutf8fnplain
// attachment; filename="foo-ä.html"
val = "attachment; filename=\"foo-%C3%A4.html\"";
val = util::percentDecode(val.begin(), val.end());
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[11])));
// attwithfnrawpctenca
val = "attachment; filename=\"foo-%41.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-%41.html"),
std::string(&dest[0], &dest[12]));
// attwithfnusingpct
val = "attachment; filename=\"50%.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("50%.html"),
std::string(&dest[0], &dest[8]));
// attwithfnrawpctencaq
val = "attachment; filename=\"foo-%\\41.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-%41.html"),
std::string(&dest[0], &dest[12]));
// attwithnamepct
val = "attachment; name=\"foo-%41.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfilenamepctandiso
// attachment; filename="ä-%41.html"
val = "attachment; filename=\"%E4-%2541.html\"";
val = util::percentDecode(val.begin(), val.end());
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("ä-%41.html"),
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
// attwithfnrawpctenclong
val = "attachment; filename=\"foo-%c3%a4-%e2%82%ac.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)25, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-%c3%a4-%e2%82%ac.html"),
std::string(&dest[0], &dest[25]));
// attwithasciifilenamews1
val = "attachment; filename =\"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attwith2filenames
val = "attachment; filename=\"foo.html\"; filename=\"bar.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attfnbrokentoken
val = "attachment; filename=foo[1](2).html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attfnbrokentokeniso
val = "attachment; filename=foo-%E4.html";
val = util::percentDecode(val.begin(), val.end());
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attfnbrokentokenutf
// attachment; filename=foo-ä.html
val = "attachment; filename=foo-ä.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmissingdisposition
val = "filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmissingdisposition2
val = "x=y; filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmissingdisposition3
val = "\"foo; filename=bar;baz\"; filename=qux";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmissingdisposition4
val = "filename=foo.html, filename=bar.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// emptydisposition
val = "; filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// doublecolon
val = ": inline; attachment; filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attandinline
val = "inline; attachment; filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attandinline2
val = "attachment; inline; filename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attbrokenquotedfn
val = "attachment; filename=\"foo.html\".txt";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attbrokenquotedfn2
val = "attachment; filename=\"bar";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attbrokenquotedfn3
val = "attachment; filename=foo\"bar;baz\"qux";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmultinstances
val = "attachment; filename=foo.html, attachment; filename=bar.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
}
void UtilTest1::testParseContentDisposition2() {
char dest[1_k];
size_t destlen = sizeof(dest);
const char *cs;
size_t cslen;
std::string val;
// test cases from http://greenbytes.de/tech/tc2231/
// attmissingdelim
val = "attachment; foo=foo filename=bar";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmissingdelim2
val = "attachment; filename=bar foo=foo ";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attmissingdelim3
val = "attachment filename=bar";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attreversed
val = "filename=foo.html; attachment";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attconfusedparam
val = "attachment; xfilename=foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attabspath
val = "attachment; filename=\"/foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("/foo.html"),
std::string(&dest[0], &dest[9]));
// attabspathwin
val = "attachment; filename=\"\\\\foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("\\foo.html"),
std::string(&dest[0], &dest[9]));
// attcdate
val = "attachment; creation-date=\"Wed, 12 Feb 1997 16:29:51 -0500\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// dispext
val = "foobar";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// dispextbadfn
val = "attachment; example=\"filename=example.txt\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithisofn2231iso
val = "attachment; filename*=iso-8859-1''foo-%E4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("iso-8859-1"), std::string(cs, cslen));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[10])));
// attwithfn2231utf8
val = "attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)15, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä-€.html"),
std::string(&dest[0], &dest[15]));
// attwithfn2231noc
val = "attachment; filename*=''foo-%c3%a4-%e2%82%ac.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231utf8comp
val = "attachment; filename*=UTF-8''foo-a%cc%88.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)12, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
val = "foo-a%cc%88.html";
CPPUNIT_ASSERT_EQUAL(std::string(util::percentDecode(val.begin(),
val.end())),
std::string(&dest[0], &dest[12]));
// attwithfn2231utf8-bad
val = "attachment; filename*=iso-8859-1''foo-%c3%a4-%e2%82%ac.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231iso-bad
val = "attachment; filename*=utf-8''foo-%E4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231ws1
val = "attachment; filename *=UTF-8''foo-%c3%a4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231ws2
val = "attachment; filename*= UTF-8''foo-%c3%a4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
std::string(&dest[0], &dest[11]));
// attwithfn2231ws3
val = "attachment; filename* =UTF-8''foo-%c3%a4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
std::string(&dest[0], &dest[11]));
// attwithfn2231quot
val = "attachment; filename*=\"UTF-8''foo-%c3%a4.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231quot2
val = "attachment; filename*=\"foo%20bar.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231singleqmissing
val = "attachment; filename*=UTF-8'foo-%c3%a4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231nbadpct1
val = "attachment; filename*=UTF-8''foo%";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231nbadpct2
val = "attachment; filename*=UTF-8''f%oo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attwithfn2231dpct
val = "attachment; filename*=UTF-8''A-%2541.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("A-%41.html"),
std::string(&dest[0], &dest[10]));
// attwithfn2231abspathdisguised
val = "attachment; filename*=UTF-8''%5cfoo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)9, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("\\foo.html"),
std::string(&dest[0], &dest[9]));
// attfnboth
val = "attachment; filename=\"foo-ae.html\"; filename*=UTF-8''foo-%c3%a4.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
std::string(&dest[0], &dest[11]));
// attfnboth2
val = "attachment; filename*=UTF-8''foo-%c3%a4.html; filename=\"foo-ae.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)11, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo-ä.html"),
std::string(&dest[0], &dest[11]));
// attfnboth3
val = "attachment; filename*0*=ISO-8859-15''euro-sign%3d%a4; filename*=ISO-8859-1''currency-sign%3d%a4";
CPPUNIT_ASSERT_EQUAL((ssize_t)15, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("ISO-8859-1"), std::string(cs, cslen));
CPPUNIT_ASSERT_EQUAL(std::string("currency-sign=¤"),
util::iso8859p1ToUtf8(std::string(&dest[0], &dest[15])));
// attnewandfn
val = "attachment; foobar=x; filename=\"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// attrfc2047token
val = "attachment; filename==?ISO-8859-1?Q?foo-=E4.html?=";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// attrfc2047quoted
val = "attachment; filename=\"=?ISO-8859-1?Q?foo-=E4.html?=\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)29, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("=?ISO-8859-1?Q?foo-=E4.html?="),
std::string(&dest[0], &dest[29]));
// aria2 original testcases
// zero-length filename. token cannot be empty, so this is invalid.
val = "attachment; filename=";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// zero-length filename. quoted-string can be empty string, so this
// is ok.
val = "attachment; filename=\"\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// empty value is not allowed
val = "attachment; filename=;";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// / is not valid char in token.
val = "attachment; filename=dir/file";
CPPUNIT_ASSERT_EQUAL((ssize_t)-1, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
// value-chars is *(pct-encoded / attr-char), so empty string is
// allowed.
val = "attachment; filename*=UTF-8''";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
val = "attachment; filename*=UTF-8''; filename=foo";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
val = "attachment; filename*=UTF-8'' ; filename=foo";
CPPUNIT_ASSERT_EQUAL((ssize_t)0, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("UTF-8"), std::string(cs, cslen));
// with language
val = "attachment; filename*=UTF-8'japanese'konnichiwa";
CPPUNIT_ASSERT_EQUAL((ssize_t)10, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("konnichiwa"),
std::string(&dest[0], &dest[10]));
// lws before and after "="
val = "attachment; filename = foo.html";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// lws before and after "=" with quoted-string
val = "attachment; filename = \"foo.html\"";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
// lws after parm
val = "attachment; filename=foo.html ";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
val = "attachment; filename=foo.html ; hello=world";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
val = "attachment; filename=\"foo.html\" ";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
val = "attachment; filename=\"foo.html\" ; hello=world";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
val = "attachment; filename*=UTF-8''foo.html ; hello=world";
CPPUNIT_ASSERT_EQUAL((ssize_t)8, util::parse_content_disposition
(dest, destlen, &cs, &cslen, val.c_str(), val.size()));
CPPUNIT_ASSERT_EQUAL(std::string("foo.html"),
std::string(&dest[0], &dest[8]));
2006-05-09 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> Each peer message has its own class. * src/PendingMessages.h: Removed. * src/PendingMessages.cc: Removed. The sending process was moved to each message class. * src/RequestSlotMan.h: Removed. * src/RequestSlotMan.cc: Removed. All functionarities were moved to SendMessageQueue. * src/RequestMessage.h: New class. * src/RequestMessage.cc: New class. * src/CancelMessage.h: New class. * src/CancelMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/ChokeMessage.h: New class. * src/ChokeMessage.cc: New class. * src/KeepAliveMessage.h: New class. * src/KeepAliveMessage.cc: New class. * src/PortMessage.h: New class. * src/UnchokeMessage.h: New class. * src/UnchokeMessage.cc: New class. * src/PieceMessage.h: New class. * src/PieceMessage.cc: New class. * src/HaveMessage.h: New class. * src/HaveMessage.cc: New class. * src/BitfieldMessage.h: New class. * src/BitfieldMessage.cc: New class. * src/NotInterestedMessage.h: New class. * src/NotInterestedMessage.cc: New class. * src/InterestedMessage.h: New class. * src/InterestedMessage.cc: New class. * src/HandshakeMessage.h (sendMessageQueue): New variable. (getSendMessageQueue): New function. (setSendMessageQueue): New function. * src/HandshakeMessage.cc: New class. * src/PeerConnection.h (receiveMessage): Changed return value and arguments. (receiveHandshake): Changed return value and arguments. * src/PeerConnection.cc (receiveMessage): Do not create message class here. (receiveHandshake): Do not create handshake class here. * src/PeerInteractionCommand.h (peerConnection): Removed. (piece): Removed. (syncPiece): Removed. (sendInterest): Removed. (sendMessages): Removed. (createRequestPendingMessage): Removed. (checkPieceHash): Removed. (erasePieceOnDisk): Removed. (getNewPieceAndSendInterest): Removed. (onGotNewPice): Removed. (onGotWrongPiece): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Removed peerConnection, piece. (~PeerInteractionCommand): Removed peerConnection. (executeInternal): Use sendMessageQueue instead of peerConnection. (syncPiece): Moved to SendMessageQueue. (decideChoking): Removed PendingMessage. (receiveMessage): Use sendMessageQueue instead of peerConnection. The action after receiving peer message was moved to each message class. (onGotNewPice): Moved to SendMessageQueue. (onGotWrongPiece): Moved to SendMessageQueue. (getNewPieceAndSendInterest): Moved to SendMessageQueue. (sendInterest): Moved to SendMessageQueue. (createRequestPendingMessage): Removed. (sendMessages): Moved to SendMessageQueue. (onAbort): Use SendMessageQueue::abortPiece() (keepAlive): Use sendMessageQueue instead of peerConnection. (beforeSocketCheck): Use sendMessageQueue instead of peerConnection. (checkPieceHash): Moved to SendMessageQueue. (erasePieceOnDisk): Moved to SendMessageQueue. * src/PeerMessageUtil.h (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessageUtil.cc (createBitfieldMessage): Removed. (createHaveMessage): Changed return value and arguments. (createBitfieldMessage): Changed return value and arguments. (createRequestCancelMessage): Removed. (createPieceMessage): Changed return value and arguments. (getShortIntParam): New function. (checkIndex): Changed arguments. (checkBegin): Changed arguments. (checkLength): Changed arguments. (checkPieceOffset): Removed. (checkRange): New function. (checkBitfield): Changed arguments. (createPeerMessage): Removed. (checkIntegrity): Removed. (createHandshakeMessage): Changed arguments. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPortMessage): New function. * src/PeerMessage.h (id): Removed. (index): Removed. (begin): Removed. (length): Removed. (bitfield): Removed. (bitfieldLength): Removed. (block): Removed. (blockLength): Removed. (inProgress): New variable. (cuid): New variable. (peer): New variable. (sendMessageQueue): New variable. (logger): New variable. (setBitfield): Removed. (getBitfield): Removed. (setBlock): Removed. (getBlock): Removed. (getBitfieldLength): Removed. (getBlockLength): Removed. (isInProgress): New function. (toString): Made pure virtual. (check): New function. (send): New function. (receivedAction): New function. (getId): Made pure virtual. (setId): Removed. (getIndex): Removed. (setIndex): Removed. (getBegin): Removed. (setBegin): Removed. (getLength): Removed. (setLength): Removed. (getCuid): New function. (setCuid): New function. (getPeer): New function. (setPeer): New function. (getSendMessageQueue): New function. (setSendMessageQueue): New function. (ID): Removed. * src/PeerMessage.cc (setBitfield): Removed. (setBlock): Removed. (toString): Removed. * src/TorrentMan.h (getPieceLength): New function. (getPieceLength): New function. * src/SendMessageQueue.h (REQUEST_TIME_OUT): New definition. (RequestSlots): New definition. (MessageQueue): New definition. (requestSlotMan): Removed. (pendingMessages): Removed. (requestSlots): New variable. (messageQueue): New variable. (torrentMan): New variable. (peerConnection): New variable. (peer): New variable. (piece): New variable. (getNewPieceAndSendInterest): New function. (createPeerMessage): New function. (createHandshakeMessage): New function. (send): Made private. (setPeerMessageCommonProperty): New function. (deleteAllRequestSlot): New function. (deleteRequestMessageInQueue): New function. (cancelAllRequest): Made private. (cancelAllRequest): Made private. (countRequestSlot): Made private. (addPendingMessage): Removed. (deletePendingPieceMessage): Removed. (deletePendingRequestMessage): Removed. (addMessage): New function. (deletePieceMessageInQueue): New function. (deleteTimeoutRequestSlot): Changed argument. (deleteCompletedRequestSlot): Changed argument. (getCorrespoindingRequestSlot): Renamed to getCorrespondingRequestSlot. (getCorrespondingRequestSlot): New function. (countPendingMessage): Removed. (countMessageInQueue): New function. (getTorrentMan): New function. (getPeerConnection): New function. (hasDownloadPiece): New function. (getDownloadPiece): New function. (setDownloadPiece): New function. (syncPiece): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (abortPiece): New function. (sendHandshake): New function. (receiveMessage): New function. (receiveHandshake): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. * src/SendMessageQueue.cc (SendMessageQueue): Removed requestSlotMan. Instantiated peerConnection here. (~SendMessageQueue): Removed requestSlotMan. Added deletion of peerConnection and the contents of messageQueue. (send): Updated according to the change of messageQueue. (addPendingMessage): Renamed to addMessage. (addMessage): New function. (deletePendingPieceMessage): Renamed to deletePieceMessageInQueue. (deletePieceMessageInQueue): New function. (deletePendingRequestMessage): Renamed to deleteRequestMessageInQueue. (deleteRequestMessageInQueue): New function. (deleteRequestSlot): RequestSlotMan::deleteRequestSlot(...) was moved here. (deleteTimeoutRequestSlot): RequestSlotMan::deleteTimeoutRequestSlot (...) was moved here. (deleteAllRequestSlot): RequestSlotMan::deleteAllRequestSlot(...) was moved here. (deleteCompletedRequestSlot): RequestSlotMan::deleteCompletedRequestSlot(...) was moved here. (getCorrespondingRequestSlot): RequestSlotMan::getCorrespoindingRequestSlot(...) was moved here. And renamed to getCorrespondingRequestSlot, correcting a typo. (countPendingMessage): Renamed to countMessageInQueue. (countMessageInQueue): New function. (countRequestSlot): RequestSlotMan::countRequestSlot() was moved here. (receiveHandshake): New function. (createHandshakeMessage): New function. (receiveMessage): New function. (createPeerMessage): New function. (syncPiece): New function. (getNewPieceAndSendInterest): New function. (sendMessages): New function. (sendNow): New function. (trySendNow): New function. (sendHandshake): New function. (abortPiece): New function. (getDownloadPiece): New function. (getPeerMessageCommonProperty): New function. (createRequestMessage): New function. (createCancelMessage): New function. (createPieceMessage): New function. (createHaveMessage): New function. (createChokeMessage): New function. (createUnchokeMessage): New function. (createInterestedMessage): New function. (createNotInterestedMessage): New function. (createBitfieldMessage): New function. (createKeepAliveMessage): New function. To add simple Content-Disposition support: * src/HttpResponseCommand.h (determinFilename): New function. * src/HttpResponseCommand.cc (executeInternal): Use determinFilename(headers) instead of req->getFile() when comparing filename. (determinFilename): New function. (handleDefaultEncoding): Use determinFilename(headers) instead of req->getFile(). (handleOtherEncoding): Use determinFilename(headers) instead of req->getFile(). * src/Util.h (getContentDispositionFilename): New function. * src/Util.cc (getContentDispositionFilename): New function. * src/LogFactory.h (release): New function. * src/LogFactory.cc (release): New function. To fix a bug that causes out-of-bound exception when HTTP status line is wrong: * src/HttpConnection.cc (receiveResponse): Added a check for header size. * src/common.h (Deleter): New class. * src/SegmentMan.cc (~SegmentMan): Added deletion of splitter and diskWriter. * src/DownloadEngine.h (Commands): Use deque. (clearQueue): New function. * src/DownloadEngine.cc (~DownloadEngine): Added deletion of segmentMan. (cleanQueue): New function. * src/TorrentDownloadEngine.h (TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. (~TorrentDownloadEngine): The implementation was moved to TorrentDownloadEngine.cc. * src/TorrentDownloadEngine.cc (~TorrentDownloadEngine): Added deletion of torrentMan. * src/main.cc (clearRequest): Removed. (handler): Added deletion of e. (torrentHandler): Added deletion of te. (main): Do not share splitter. Use Deleter instead of clearRequest. Deletion of classes were updated.
2006-05-09 15:54:14 +00:00
}
2006-05-18 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> To remove a wait from download loop: * src/DownloadEngine.cc (run): Comment out shortSleep. To rewrite the message handling: * src/CancelMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/CancelMessage.cc (create): New function. (receivedAction): Replaced deleteRequestMessageInQueue with rejectPieceMessageInQueue. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/BitfieldMessage.h: Derived from SimplePeerMessage. (msg): New variable. (msgLength): New variable. (~BitfieldMessage): Deleted msg. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/BitfieldMessage.cc (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/ChokeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. (create): New function. * src/ChokeMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/KeepAliveMessage.h: Derived from SimplePeerMessage. (msg): New variable. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/KeepAliveMessage.cc (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/PortMessage.h (create): New function. (receivedAction): Updated log message. * src/PortMessage.cc: New file. * src/UnchokeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/UnchokeMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/PieceMessage.h (leftPieceDataLength): Removed. (leftDataLength): New variable. (headerSend): New variable. (pendingCount): New variable. (msgHeader): New variable. (sendPieceData): New function. (incrementPendingCount): New function. (isPendingCountMax): New function. (create): New function. (getMessageHeader): New function. (getMessageHeaderLength): New function. * src/PieceMessage.cc (create): New function. (getMessageHeader): New function. (getMessageHeaderLength): New function. (send): Rewritten. (sendPieceData): New function. * src/HaveMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (getMessage): New function. (getMessageLength): New function. * src/HaveMessage.cc (create): New function. (send): Removed. (sendPieceData): New function. (getMessage): New function. (getMessageLength): New function. * src/RequestMessage.h: Derived from SimplePeerMessage. (msg): New variable. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/RequestMessage.cc (create): New function. (receivedAction): Added the handling of fast extension. Deleted torrentMan->addUploadLength, torrentMan->addDeltaUploadLength. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/InterestedMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPredicate): New function. (onSendComplete): New function. (create): New function. (getMessage): New function. (getMessageLength): New function. * src/InterestedMessage.cc (create): New function. (send): Removed. (sendPieceData): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/NotInterestedMessage.h: Derived from SimplePeerMessage. (msg): New variable. (sendPieceData): New function. (onSendComplete): New function. (create): New function. (send): Removed. (getMessage): New function. (getMessageLength): New function. * src/NotInterestedMessage.cc (create): New function. (send): Removed. (sendPredicate): New function. (getMessage): New function. (getMessageLength): New function. (onSendComplete): New function. * src/AllowedFastMessage.h: New class. * src/AllowedFastMessage.cc: New class. * src/RejectMessage.h: New class. * src/RejectMessage.cc: New class. * src/SuggestPieceMessage.h: New class. * src/SuggestPieceMessage.cc: New class. * src/HaveAllMessage.h: New class. * src/HaveAllMessage.cc: New class. * src/HaveNoneMessage.h: New class. * src/HaveNoneMessage.cc: New class. * src/HandshakeMessage.h: Derived from SimplePeerMessage. (msg): New variable. (reserved): New variable. (create): New function. (getId): New function. (receivedAction): New function. (getMessage): New function. (getMessageLength): New function. (isFastExtensionSupported): New function. * src/HandshakeMessage.cc (HandshakeMessage): Moved here from HandshakeMessage.h. (create): New function. (getMessage): New function. (getMessageLength): New function. (toString): Added the output of reserved field. (check): Added const qualifier. (isFastExtensionSupported): New function. * src/PeerMessageUtil.h (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createPortMessage): Removed. (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createKeepAliveMessage): Removed. (createHandshakeMessage): Removed. (setIntParam): New function. (createPeerMessageString): New function. * src/PeerMessageUtil.cc (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createHaveMessage): Removed. (createBitfieldMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createPortMessage): Removed. (createRequestMessage): Removed. (createCancelMessage): Removed. (createPieceMessage): Removed. (createHaveMessage): Removed. (createChokeMessage): Removed. (createUnchokeMessage): Removed. (createInterestedMessage): Removed. (createNotInterestedMessage): Removed. (createBitfieldMessage): Removed. (createKeepAliveMessage): Removed. (createHandshakeMessage): Removed. (setIntParam): New function. (createPeerMessageString): New function. * src/PeerConnection.h (peer): Removed. (torrentMan): Removed. (createNLengthMessage): Removed. (setIntParam): Removed. (writeOutgoingMessageLog): Removed all overloaded functions. (PeerConnection): Deleted peer and torrentMan from its arguments. (sendMessage): New function. (sendHandshake): Removed. (sendKeepAlive): Removed. (sendChoke): Removed. (sendUnchoke): Removed. (sendInterested): Removed. (sendNotInterested): Removed. (sendHave): Removed. (sendBitfield): Removed. (sendRequest): Removed. (sendPiece): Removed. (sendPieceHeader): Removed. (sendPieceData): Removed. (sendCancel): Removed. (getPeer): Removed. * src/PeerConnection.cc (PeerConnection): Deleted peer and torrentMan from its arguments. (sendHandshake): Removed. (sendKeepAlive): Removed. (createNLengthMessage): Removed. (setIntParam): Removed. (writeOutgoingMessageLog): Removed all overloaded functions. (sendChoke): Removed. (sendUnchoke): Removed. (sendInterested): Removed. (sendNotInterested): Removed. (sendHave): Removed. (sendBitfield): Removed. (sendRequest): Removed. (sendPiece): Removed. (sendPieceHeader): Removed. (sendPieceData): Removed. (sendMessage): New function. (sendCancel): Removed. * src/PeerInteractionCommand.cc (PeerInteractionCommand): Call setUploadLimit. (executeInternal): Call setUploadLimit. Added the handling of "inProgress" state of handshake message. Call sendBitfield() or sendAllowdFast() instead of deprecated sendNow(). (keepAlive): Call addMessage and sendMessage instead of deprecated sendNow(). (beforeSocketCheck): Call addMessage instead of deprecated trySendNow() * src/TorrentMan.h (PEER_ID_LENGTH): New definition. (hasAllPieces): New function. * src/TorrentMan.cc (getMissingPiece): Added the handling of fast extension. (cancelPiece): Call updatePiece(). (hasAllPieces): New function. * src/PeerInteraction.h (fastSet): New variable. (getNewPieceAndSendInterest): Changed the return type to void. (send): Renamed as sendMessages. (deleteAllRequestSlot): Removed. (deleteRequestMessageInQueue): Renamed as rejectPieceMessageInQueue. (cancelAllRequest): Removed all overloaded functions. (deleteAllRequestSlot): Removed. (deletePieceMessageInQueue): Renamed as rejectAllPieceMessageInQueue. (rejectPieceMessageInQueue): New function. (rejectAllPieceMessageInQueue): New function. (onChoked): New function. (isSendingMessageInProgress): New function. (getCorrespondingRequestSlot): Changed its arguments. (isInFastSet): New function. (addFastSetIndex): New function. (addRequests): New function. (sendNow): Removed. (trySendNow): Removed. (sendBitfield): New function. (sendAllowdFast): New function. (createHaveAllMessage): New function. (createHaveNoneMessage): New function. (createRejectMessage): New function. (createAllowedFastMessage): New function. * src/PeerInteraction.cc (send): Renamed as sendMessages. (sendMessages): New function. (MsgPushBack): New class. (isSendingMessageInProgress): New function. (deletePieceMessageInQueue): Renamed as rejectAllPieceMessageInQueue. (rejectAllPieceMessageInQueue): New function. Added the handling of fast extension. (deleteRequestMessageInQueue): Renamed as rejectPieceMessageInQueue. (rejectPieceMessageInQueue): New function. Added the handling of fast extension. (deleteRequestSlot): Replaced for loop with std::find. (onChoked): New function. (deleteAllRequestSlot): Removed. (abortPiece): Rewirtten. (deleteTimeoutRequestSlot): Updated log messages. (getCorrespondingRequestSlot): Changed its arguments. (cancelAllRequest): Removed all overloaded functions. (receiveHandshake): Added the check to see whether an incoming peer supports fast extension. (createHandshakeMessage): Use HandshakeMessage::create instead of PeerMessageUtil. (createPeerMessage): Use create() of each message class instead of PeerMessageUtil. HaveAllMessage, HaveNoneMessage, RejectMessage, SuggestPieceMessage, AllowedFastMessage were added. (getNewPieceAndSendInterest): Changed its return value type to void. Added the handling of fast extension. (addRequests): New function. (sendNow): Removed. (sendHandshake): Rewritten. (trySendNow): Removed. (sendBitfield): New function. (sendAllowdFast): New function. (isInFastSet): New function. (addFastSetIndex): New function. (createRequestMessage): Use RequestMessage::create instead of PeerMessageUtil. (createCancelMessage): Use CancelMessage::create instead of PeerMessageUtil. (createPieceMessage): Use PieceMessage::create instead of PeerMessageUtil. (createHaveMessage): Use HaveMessage::create instead of PeerMessageUtil. (createChokeMessage): Use ChokeMessage::create instead of PeerMessageUtil. (createUnchokeMessage): Use UnchokeMessage::create instead of PeerMessageUtil. (createInterestedMessage): Use InterestedMessage::create instead of PeerMessageUtil. (createNotInterestedMessage): Use NotInterestedMessage::create instead of PeerMessageUtil. (createBitfieldMessage): Use BitfieldMessage::create instead of PeerMessageUtil. (createKeepAliveMessage): Use KeepAliveMessage::create instead of PeerMessageUtil. (createHaveAllMessage): New function. (createHaveNoneMessage): New function. (createRejectMessage): New function. (createAllowedFastMessage: New function. * src/Util.h (sha1Sum): New function. (computeFastSet): New function. * src/Util.cc (sha1Sum): New function. (computeFastSet): New function. * src/Peer.h (fastExtensionEnabled): New variable. (fastSet): New variable. (setAllBitfield): New function. (setFastExtensionEnabled): New function. (isFastExtensionEnabled): New function. (addFastSetIndex): New function. (getFastSet): New function. (isInFastSet): New function. (countFastSet): New function. * src/Peer.cc (isInFastSet): New function. (addFastSetIndex): New function. (setAllBitfield): New function. * src/AbstractCommand.cc (execute): Changed the procedure of checking sockets. * src/PeerAbstractCommand.cc (PeerAbstractCommand): Added the initialization for uploadLimitCheck and uploadLimit. (execute): Changed the procedure of checking sockets. The upload speed checking were added. (setUploadLimit): New function. (setUploadLimitCheck): New function. * src/PeerAbstractCommand.h (setUploadLimit): New function. (setUploadLimitCheck): New function. (uploadLimit): New variable. (uploadLimitCheck): New variable. To contact a tracker regularly: * src/TrackerWatcherCommand.h (interval): New variable. (checkPoint): New variable. (TrackerWatcherCommand): Added interval argument. * src/TrackerWatcherCommand.cc (TrackerWatcherCommand): Initialized checkPoint. (execute): Now a tracker is contacted in every specified period. If peer list is not needed, send request with numwant=0. * src/TrackerUpdateCommand.cc (execute): Updated log messages. * src/DownloadEngine.cc (~DownloadEngine): Removed two asserts. (waitData): Uncommented wfds. May be a bug fix.
2006-05-18 17:08:29 +00:00
} // namespace aria2