Protocols::BitTorrent::Torrents::TorrentParser Class Reference

#include <TorrentParser.h> [code]

List of all members.


Detailed Description

Torrent files (raw data) parser.

This class provides Torrent files parsing.

Torrent file structure must comply for suit to these specifications: http://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure .

Optional tracker announce list must comply for suit to these specifications: http://home.elp.rr.com/tur/multitracker-spec.txt (this is an extention to the official specification, which is also backwards compatible).

Optional field 'private' must comply for suit to these specifications: http://www.azureuswiki.com/index.php/Secure_Torrents (this field is used in practice but it is not part of the official specification).

Todo:
Implement getting and computing the hashed value of the info key from the torrent metainfo file. This will definitely require some addings to some of the classes from the Bencoding package and also some class that provides hashing.

Definition at line 61 of file TorrentParser.h.

Static Public Member Functions

static bool parseAndLoadTorrent (const QByteArray &rawTorrentData, Torrent &torrent)
 Parses rawTorrentData into the torrent object.

Private Member Functions

 TorrentParser ()
 ~TorrentParser ()
 TorrentParser (const TorrentParser &)
TorrentParseroperator= (const TorrentParser &)

Static Private Member Functions

static bool loadAllTorrentData (const QByteArray &rawData, Torrent &torrent)
 Parses and loads torrent data from rawData into torrent.
static bool loadTorrentBasicData (const BDictionary *bBasicData, Torrent &torrent)
 Loads basic torrent data from bBasicData into torrent.
static bool loadTorrentFilesInfo (const BDictionary *bInfo, Torrent &torrent)
 Loads info about files and their properties from bInfo into torrent.
static bool getAndLoadAnnounce (const BDictionary *bBasicData, Torrent &torrent)
 Loads the tracker announce URL from bBasicData into torrent.
static bool getAndLoadAnnounceList (const BDictionary *bBasicData, Torrent &torrent)
 Loads the list of announce URLs from bBasicData into torrent.
static bool getAndLoadCreationDate (const BDictionary *bBasicData, Torrent &torrent)
 Loads the creation date of the torrent from bBasicData into torrent.
static bool getAndLoadComment (const BDictionary *bBasicData, Torrent &torrent)
 Loads the torrent comment from bBasicData into torrent.
static bool getAndLoadCreatedBy (const BDictionary *bBasicData, Torrent &torrent)
 Loads the torrent creator name/version from bBasicData into torrent.
static bool getAndLoadPieceLength (const BDictionary *bInfo, Torrent &torrent)
 Loads the number of bytes in each piece from bInfo into torrent.
static bool getAndLoadPieces (const BDictionary *bInfo, Torrent &torrent)
 Loads the list of all hash values from bInfo into torrent.
static bool getAndLoadPrivate (const BDictionary *bInfo, Torrent &torrent)
 Loads the private flag from bInfo into torrent.
static bool getAndLoadSingleModeFileInfo (const BDictionary *bInfo, Torrent &torrent)
 Loads single file mode information from bInfo into torrent.
static bool getAndLoadMultipleModeFileInfo (const BDictionary *bInfo, Torrent &torrent)
 Loads multiple file mode information from bInfo into torrent.
static bool getAndLoadDirectoryName (const BDictionary *bFileInfo, QString &directoryName)
 Loads the directory name from bFileInfo into directoryName.
static bool getAndLoadFileName (const BDictionary *bFileInfo, QString &fileName)
 Loads the file name from bFileInfo into fileName.
static bool getAndLoadFilePath (const BDictionary *bFileInfo, QString &filePath)
 Loads the file path from bFileInfo into filePath.
static bool getAndLoadFileLength (const BDictionary *bFileInfo, Torrent::FileInfo &fileInfo)
 Loads the file length from bFileInfo into fileInfo.
static bool getAndLoadFileChecksum (const BDictionary *bFileInfo, Torrent::FileInfo &fileInfo)
 Loads the file checksum from bFileInfo into fileInfo.
static bool getAndLoadFileInfoList (const BList *bFileInfoList, Torrent::FileInfoList &fileInfoList)
 Loads the file info list from bFileInfoList into fileInfoList.
static bool getAndLoadFileInfo (const BDictionary *bFileInfo, Torrent::FileInfo &fileInfo)
 Loads file information from bFileInfo into fileInfo.
static bool isValidAnnounceUrl (const Uri &announceUrl)
 Announce URL (announceUrl) validity test.
static bool isValidCreationDate (int creationDate)
 Creation date (creationDate) validity test.
static bool isValidPieceLength (int pieceLength)
 Piece length (pieceLength) validity test.
static bool isValidPieces (const QByteArray &pieces)
 Pieces (pieces) validity test.
static bool isValidPrivate (int privateFlag)
 Private flag (privateFlag) validity test.
static bool isValidFileLength (qint64 fileLength)
 File length (fileLength) validity test.
static bool isValidFileChecksum (const QByteArray &fileChecksum)
 File checksum (fileChecksum) validity test.
static bool convertBTierToTier (const BList *bTier, QList< Uri > &tier)
 Converts bTier containing announce-list tier into tier.
static bool convertPiecesToPieceList (const QByteArray &pieces, Torrent::PieceList &pieceList)
 Converts selected pieces into pieceList.
static bool convertBFilePathToFilePath (const BList *bFilePath, const QString &delimiter, QString &filePath)
 Converts bFilePath containing file path into filePath.
static bool convertPrivateFlagToBool (int privateFlag)
 Returns converted privateFlag into bool.
static void appendDirectoryName (const QString &directoryName, const QString &delimiter, Torrent::FileInfoList &fileInfoList)
 Appends directoryName before each file path in fileInfoList.

Static Private Attributes

static const char * InfoKeyName = "info"
static const char * AnnounceKeyName = "announce"
static const char * AnnounceListKeyName = "announce-list"
static const char * CreationDateKeyName = "creation date"
static const char * CommentKeyName = "comments"
static const char * CreatedByKeyName = "created by"
static const char * PieceLengthKeyName = "piece length"
static const char * PiecesKeyName = "pieces"
static const char * PrivateKeyName = "private"
static const char * FileNameKeyName = "name"
static const char * FileLengthKeyName = "length"
static const char * ChecksumKeyName = "md5sum"
static const char * FilesKeyName = "files"
static const char * PathKeyName = "path"
static const char * DirectoryDelimiter = "/"
 Directory delimiter (like "/").


Constructor & Destructor Documentation

Protocols::BitTorrent::Torrents::TorrentParser::TorrentParser  )  [private]
 

Protocols::BitTorrent::Torrents::TorrentParser::~TorrentParser  )  [private]
 

Protocols::BitTorrent::Torrents::TorrentParser::TorrentParser const TorrentParser  )  [private]
 


Member Function Documentation

void TorrentParser::appendDirectoryName const QString &  directoryName,
const QString &  delimiter,
Torrent::FileInfoList fileInfoList
[static, private]
 

Appends directoryName before each file path in fileInfoList.

Each file path will then have the following format: directoryName delimiter originalFilePath If there is no file info in the fileInfoList it will do nothing.

Definition at line 734 of file TorrentParser.cpp.

bool TorrentParser::convertBFilePathToFilePath const BList bFilePath,
const QString &  delimiter,
QString &  filePath
[static, private]
 

Converts bFilePath containing file path into filePath.

Returns true if the conversion went ok, false otherwise (filePath will be left unchanged). filePath will be in the following format: dir1 delimiter dir2 delimiter ... delimiter fileName If bFilePath has no elements before the conversion it returns true.

Definition at line 688 of file TorrentParser.cpp.

bool TorrentParser::convertBTierToTier const BList bTier,
QList< Uri > &  tier
[static, private]
 

Converts bTier containing announce-list tier into tier.

Returns true if the conversion went ok, false otherwise (tier will be left unchanged).

Definition at line 629 of file TorrentParser.cpp.

bool TorrentParser::convertPiecesToPieceList const QByteArray &  pieces,
Torrent::PieceList pieceList
[static, private]
 

Converts selected pieces into pieceList.

Returns true if the conversion went ok, false otherwise (and pieceList will be left unchanged).

Definition at line 661 of file TorrentParser.cpp.

bool TorrentParser::convertPrivateFlagToBool int  privateFlag  )  [static, private]
 

Returns converted privateFlag into bool.

Precondition:
Expects privateFlag to be valid.
See also:
isValidPrivate()

Definition at line 721 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadAnnounce const BDictionary bBasicData,
Torrent torrent
[static, private]
 

Loads the tracker announce URL from bBasicData into torrent.

Returns true if the announce was loaded successfully, false otherwise.

Definition at line 151 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadAnnounceList const BDictionary bBasicData,
Torrent torrent
[static, private]
 

Loads the list of announce URLs from bBasicData into torrent.

Returns true if the announce list was loaded successfully, false otherwise. This piece of information is only optional.

Definition at line 173 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadComment const BDictionary bBasicData,
Torrent torrent
[static, private]
 

Loads the torrent comment from bBasicData into torrent.

Returns true if the comment was loaded successfully, false otherwise. This piece of information is only optional.

Definition at line 241 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadCreatedBy const BDictionary bBasicData,
Torrent torrent
[static, private]
 

Loads the torrent creator name/version from bBasicData into torrent.

Returns true if the name/version was loaded successfully, false otherwise. This piece of information is only optional.

Definition at line 259 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadCreationDate const BDictionary bBasicData,
Torrent torrent
[static, private]
 

Loads the creation date of the torrent from bBasicData into torrent.

Returns true if the creation date was loaded successfully, false otherwise. This piece of information is only optional.

See also:
isValidCreationDate()

Definition at line 221 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadDirectoryName const BDictionary bFileInfo,
QString &  directoryName
[static, private]
 

Loads the directory name from bFileInfo into directoryName.

Returns true if the directory name was loaded successfully, false otherwise.

See also:
getAndLoadFileName()

Definition at line 406 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadFileChecksum const BDictionary bFileInfo,
Torrent::FileInfo fileInfo
[static, private]
 

Loads the file checksum from bFileInfo into fileInfo.

Returns true if the the file checksum was loaded successfully, false otherwise. This piece of information is only optional.

See also:
isValidFileChecksum()

Definition at line 482 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadFileInfo const BDictionary bFileInfo,
Torrent::FileInfo fileInfo
[static, private]
 

Loads file information from bFileInfo into fileInfo.

Returns true if the file information was loaded successfully, false otherwise.

Definition at line 530 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadFileInfoList const BList bFileInfoList,
Torrent::FileInfoList fileInfoList
[static, private]
 

Loads the file info list from bFileInfoList into fileInfoList.

Returns true if the the file info list was loaded successfully, false otherwise.

Definition at line 502 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadFileLength const BDictionary bFileInfo,
Torrent::FileInfo fileInfo
[static, private]
 

Loads the file length from bFileInfo into fileInfo.

Returns true if the the file length was loaded successfully, false otherwise.

See also:
isValidFileLength()

Definition at line 460 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadFileName const BDictionary bFileInfo,
QString &  fileName
[static, private]
 

Loads the file name from bFileInfo into fileName.

Returns true if the the file name was loaded successfully, false otherwise.

See also:
getAndLoadDirectoryName()

Definition at line 421 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadFilePath const BDictionary bFileInfo,
QString &  filePath
[static, private]
 

Loads the file path from bFileInfo into filePath.

Returns true if the the file path was loaded successfully, false otherwise.

Definition at line 439 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadMultipleModeFileInfo const BDictionary bInfo,
Torrent torrent
[static, private]
 

Loads multiple file mode information from bInfo into torrent.

Returns true if the file information was loaded successfully, false otherwise.

Definition at line 374 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadPieceLength const BDictionary bInfo,
Torrent torrent
[static, private]
 

Loads the number of bytes in each piece from bInfo into torrent.

Returns true if the number of bytes in each piece was loaded successfully, false otherwise.

See also:
isValidPieceLength()

Definition at line 279 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadPieces const BDictionary bInfo,
Torrent torrent
[static, private]
 

Loads the list of all hash values from bInfo into torrent.

Returns true if the list was loaded successfully, false otherwise.

See also:
isValidPieces()

Definition at line 300 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadPrivate const BDictionary bInfo,
Torrent torrent
[static, private]
 

Loads the private flag from bInfo into torrent.

Returns true if the private flag was loaded successfully, false otherwise. This piece of information is only optional.

See also:
isValidPrivate()

Definition at line 325 of file TorrentParser.cpp.

bool TorrentParser::getAndLoadSingleModeFileInfo const BDictionary bInfo,
Torrent torrent
[static, private]
 

Loads single file mode information from bInfo into torrent.

Returns true if the file information was loaded successfully, false otherwise.

Definition at line 346 of file TorrentParser.cpp.

bool TorrentParser::isValidAnnounceUrl const Uri announceUrl  )  [static, private]
 

Announce URL (announceUrl) validity test.

Returns true if the selected announceUrl value is valid, false otherwise. An URL is considered valid if it contains the scheme and authority URI components at minimum.

Definition at line 557 of file TorrentParser.cpp.

bool TorrentParser::isValidCreationDate int  creationDate  )  [static, private]
 

Creation date (creationDate) validity test.

Returns true if the selected creationDate value is valid, false otherwise.

Definition at line 567 of file TorrentParser.cpp.

bool TorrentParser::isValidFileChecksum const QByteArray &  fileChecksum  )  [static, private]
 

File checksum (fileChecksum) validity test.

Returns true if the selected fileChecksum value is valid, false otherwise.

Definition at line 618 of file TorrentParser.cpp.

bool TorrentParser::isValidFileLength qint64  fileLength  )  [static, private]
 

File length (fileLength) validity test.

Returns true if the selected fileLength value is valid, false otherwise.

Definition at line 608 of file TorrentParser.cpp.

bool TorrentParser::isValidPieceLength int  pieceLength  )  [static, private]
 

Piece length (pieceLength) validity test.

Returns true if the selected pieceLength value is valid, false otherwise.

Definition at line 577 of file TorrentParser.cpp.

bool TorrentParser::isValidPieces const QByteArray &  pieces  )  [static, private]
 

Pieces (pieces) validity test.

Returns true if the selected pieces value is valid, false otherwise.

Definition at line 587 of file TorrentParser.cpp.

bool TorrentParser::isValidPrivate int  privateFlag  )  [static, private]
 

Private flag (privateFlag) validity test.

Returns true if the selected privateFlag value is valid, false otherwise.

Definition at line 598 of file TorrentParser.cpp.

bool TorrentParser::loadAllTorrentData const QByteArray &  rawData,
Torrent torrent
[static, private]
 

Parses and loads torrent data from rawData into torrent.

Returns true if parsing went ok, false otherwise.

Definition at line 60 of file TorrentParser.cpp.

bool TorrentParser::loadTorrentBasicData const BDictionary bBasicData,
Torrent torrent
[static, private]
 

Loads basic torrent data from bBasicData into torrent.

Returns true if parsing went ok, false otherwise.

Definition at line 96 of file TorrentParser.cpp.

bool TorrentParser::loadTorrentFilesInfo const BDictionary bInfo,
Torrent torrent
[static, private]
 

Loads info about files and their properties from bInfo into torrent.

Returns true if parsing went ok, false otherwise.

Definition at line 119 of file TorrentParser.cpp.

TorrentParser& Protocols::BitTorrent::Torrents::TorrentParser::operator= const TorrentParser  )  [private]
 

bool TorrentParser::parseAndLoadTorrent const QByteArray &  rawTorrentData,
Torrent torrent
[static]
 

Parses rawTorrentData into the torrent object.

Parameters:
rawTorrentData a buffer containing a bencoded dictionary in the format of a torrent file (see links to specs in the docs of Torrent).
[out] torrent will contain the parsed Torrent object if parsing succeeded (i.e. the return value is true).
Returns:
true if the parsing went ok (only in this case the torrent object will be changed).

false otherwise (torrent object data will be left unchanged).

If an exception gets thrown indirectly by the function, then no side effects will be produced on the environment. Thus, the function meets the strong guarantee of exception safety.

Definition at line 43 of file TorrentParser.cpp.


Member Data Documentation

const char * TorrentParser::AnnounceKeyName = "announce" [static, private]
 

Definition at line 134 of file TorrentParser.h.

const char * TorrentParser::AnnounceListKeyName = "announce-list" [static, private]
 

Definition at line 135 of file TorrentParser.h.

const char * TorrentParser::ChecksumKeyName = "md5sum" [static, private]
 

Definition at line 144 of file TorrentParser.h.

const char * TorrentParser::CommentKeyName = "comments" [static, private]
 

Definition at line 137 of file TorrentParser.h.

const char * TorrentParser::CreatedByKeyName = "created by" [static, private]
 

Definition at line 138 of file TorrentParser.h.

const char * TorrentParser::CreationDateKeyName = "creation date" [static, private]
 

Definition at line 136 of file TorrentParser.h.

const char * TorrentParser::DirectoryDelimiter = "/" [static, private]
 

Directory delimiter (like "/").

Definition at line 148 of file TorrentParser.h.

const char * TorrentParser::FileLengthKeyName = "length" [static, private]
 

Definition at line 143 of file TorrentParser.h.

const char * TorrentParser::FileNameKeyName = "name" [static, private]
 

Definition at line 142 of file TorrentParser.h.

const char * TorrentParser::FilesKeyName = "files" [static, private]
 

Definition at line 145 of file TorrentParser.h.

const char * TorrentParser::InfoKeyName = "info" [static, private]
 

Definition at line 133 of file TorrentParser.h.

const char * TorrentParser::PathKeyName = "path" [static, private]
 

Definition at line 146 of file TorrentParser.h.

const char * TorrentParser::PieceLengthKeyName = "piece length" [static, private]
 

Definition at line 139 of file TorrentParser.h.

const char * TorrentParser::PiecesKeyName = "pieces" [static, private]
 

Definition at line 140 of file TorrentParser.h.

const char * TorrentParser::PrivateKeyName = "private" [static, private]
 

Definition at line 141 of file TorrentParser.h.


The documentation for this class was generated from the following files: