Protocols::BitTorrent::Trackers::TrackerResponseParser Class Reference

#include <TrackerResponseParser.h> [code]

List of all members.


Detailed Description

Tracker responses parser.

This class provides raw tracker responses parsing. Only static parsing function can be called because this class doesn't provide instance creation.

Raw response data (structure) must comply for suit to this specification: http://wiki.theory.org/BitTorrentSpecification#Tracker_Response .

See parseAndLoadTrackerResponse() for more details about parsing.

Definition at line 48 of file TrackerResponseParser.h.

Static Public Member Functions

static bool parseAndLoadTrackerResponse (const QByteArray &rawTrackerResponseData, TrackerResponse &trackerResponse)
 Parses rawTrackerResponseData into the trackerResponse object.

Private Member Functions

 TrackerResponseParser ()
 ~TrackerResponseParser ()
 TrackerResponseParser (const TrackerResponseParser &)
TrackerResponseParseroperator= (const TrackerResponseParser &)

Static Private Member Functions

static bool loadAllResponseData (const QByteArray &rawData, TrackerResponse &response)
 Parses and loads all tracker response data from rawData to response.
static bool loadFailureReason (const BDictionary *bData, TrackerResponse &response)
 Loads 'failure reason' value from bData into response.
static bool loadWarningMessage (const BDictionary *bData, TrackerResponse &response)
 Loads 'warning message' value from bData into response.
static bool loadInterval (const BDictionary *bData, TrackerResponse &response)
 Loads 'interval' value from bData into response.
static bool loadMinInterval (const BDictionary *bData, TrackerResponse &response)
 Loads 'min interval' value from bData into response.
static bool loadTrackerId (const BDictionary *bData, TrackerResponse &response)
 Loads 'tracker id' value from bData into response.
static bool loadComplete (const BDictionary *bData, TrackerResponse &response)
 Loads 'complete' value from bData into response.
static bool loadIncomplete (const BDictionary *bData, TrackerResponse &response)
 Loads 'incomplete' value from bData into response.
static bool loadPeers (const BDictionary *bData, TrackerResponse &response)
 Loads 'peers' value from bData into response.
static bool loadPeersBinaryModel (const BString *bPeers, TrackerResponse::PeerInfoList &peerInfoList)
 Loads 'peers' value from bPeers into peerInfoList (binary model).
static PeerInfo parseRawPeerInfo (const QByteArray &rawPeerInfo)
static bool loadPeersDictionaryModel (const BList *bPeers, TrackerResponse::PeerInfoList &peerInfoList)
 Loads 'peers' value from bPeers into peerInfoList (dictionary model).
static bool loadPeerInfo (const BDictionary *bPeerInfo, PeerInfo &peerInfo)
 Loads complete peer info from bPeerInfo into peerInfo.
static bool loadPeerInfoPeerId (const BDictionary *bPeerInfo, PeerInfo::PeerId &peerId)
 Loads 'peer id' value from bPeerInfo into peerId.
static bool loadPeerInfoHostAddress (const BDictionary *bPeerInfo, QByteArray &hostAddress)
 Loads 'ip' value from bPeerInfo into hostAddress.
static bool loadPeerInfoPort (const BDictionary *bPeerInfo, quint16 &port)
 Loads 'port' value from bPeerInfo into port.
static bool isValidInterval (qint64 interval)
 Interval (interval) validity test.
static bool isValidNumberOfPeers (qint64 numOfPeers)
 Number of peers (numOfPeers) validity test.
static bool isValidPeerId (const QByteArray &peerId)
 Peer ID (peerId) validity test.
static bool isValidPort (qint64 port)
 Port (port) validity test.

Static Private Attributes

static const char * FailureReasonKeyName = "failure reason"
static const char * WarningMessageKeyName = "warning message"
static const char * IntervalKeyName = "interval"
static const char * MinIntervalKeyName = "min interval"
static const char * TrackerIdKeyName = "tracker id"
static const char * CompleteKeyName = "complete"
static const char * IncompleteKeyName = "incomplete"
static const char * PeersKeyName = "peers"
static const char * PeersPeerIdKeyName = "peer id"
static const char * PeersIpKeyName = "ip"
static const char * PeersPortKeyName = "port"
static const int OnePeerStringSizeBinaryModel = 6


Constructor & Destructor Documentation

Protocols::BitTorrent::Trackers::TrackerResponseParser::TrackerResponseParser  )  [private]
 

Protocols::BitTorrent::Trackers::TrackerResponseParser::~TrackerResponseParser  )  [private]
 

Protocols::BitTorrent::Trackers::TrackerResponseParser::TrackerResponseParser const TrackerResponseParser  )  [private]
 


Member Function Documentation

bool TrackerResponseParser::isValidInterval qint64  interval  )  [static, private]
 

Interval (interval) validity test.

Returns:
true if the selected interval is valid.

false otherwise.

This function can be used to test both 'interval' and 'min interval' values.

Definition at line 409 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::isValidNumberOfPeers qint64  numOfPeers  )  [static, private]
 

Number of peers (numOfPeers) validity test.

Returns:
true if the selected numOfPeers is valid.

false otherwise.

This function can be used to test both 'complete' and 'incomplete' values.

Definition at line 421 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::isValidPeerId const QByteArray &  peerId  )  [static, private]
 

Peer ID (peerId) validity test.

Returns:
true if the selected peerId is valid.

false otherwise.

Definition at line 431 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::isValidPort qint64  port  )  [static, private]
 

Port (port) validity test.

Returns:
true if the selected port is valid.

false otherwise.

Definition at line 441 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadAllResponseData const QByteArray &  rawData,
TrackerResponse response
[static, private]
 

Parses and loads all tracker response data from rawData to response.

Parameters:
rawData Raw buffer containing bencoded dictionary with response data.
[out] response Into this response the parsed data will be loaded.

Definition at line 78 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadComplete const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'complete' value from bData into response.

Definition at line 209 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadFailureReason const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'failure reason' value from bData into response.

Parameters:
bData Bencoded dictionary containing tracker response data.
[out] response Into this response the parsed data will be loaded.
Returns:
true if parsing went ok.

false otherwise.

Precondition:
bData is not NULL.
Note:
This description applies to nearly all following load* functions. Because these functions are private and have pretty much the same interface, it would be superfluous to have this description before each one of them. Only details (if any) will be specified.

Definition at line 132 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadIncomplete const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'incomplete' value from bData into response.

Definition at line 225 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadInterval const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'interval' value from bData into response.

Definition at line 162 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadMinInterval const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'min interval' value from bData into response.

Definition at line 178 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeerInfo const BDictionary bPeerInfo,
PeerInfo peerInfo
[static, private]
 

Loads complete peer info from bPeerInfo into peerInfo.

Definition at line 331 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeerInfoHostAddress const BDictionary bPeerInfo,
QByteArray &  hostAddress
[static, private]
 

Loads 'ip' value from bPeerInfo into hostAddress.

Definition at line 372 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeerInfoPeerId const BDictionary bPeerInfo,
PeerInfo::PeerId peerId
[static, private]
 

Loads 'peer id' value from bPeerInfo into peerId.

Definition at line 356 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeerInfoPort const BDictionary bPeerInfo,
quint16 &  port
[static, private]
 

Loads 'port' value from bPeerInfo into port.

Definition at line 387 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeers const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'peers' value from bData into response.

Definition at line 241 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeersBinaryModel const BString bPeers,
TrackerResponse::PeerInfoList peerInfoList
[static, private]
 

Loads 'peers' value from bPeers into peerInfoList (binary model).

Definition at line 268 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadPeersDictionaryModel const BList bPeers,
TrackerResponse::PeerInfoList peerInfoList
[static, private]
 

Loads 'peers' value from bPeers into peerInfoList (dictionary model).

Definition at line 287 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadTrackerId const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'tracker id' value from bData into response.

Definition at line 194 of file TrackerResponseParser.cpp.

bool TrackerResponseParser::loadWarningMessage const BDictionary bData,
TrackerResponse response
[static, private]
 

Loads 'warning message' value from bData into response.

Definition at line 147 of file TrackerResponseParser.cpp.

TrackerResponseParser& Protocols::BitTorrent::Trackers::TrackerResponseParser::operator= const TrackerResponseParser  )  [private]
 

bool TrackerResponseParser::parseAndLoadTrackerResponse const QByteArray &  rawTrackerResponseData,
TrackerResponse trackerResponse
[static]
 

Parses rawTrackerResponseData into the trackerResponse object.

Parameters:
rawTrackerResponseData a buffer containing a bencoded dictionary in the format of a tracker response (see links to specs in the description of TrackerResponseParser class).
[out] trackerResponse will contain the parsed TrackerResponse object if parsing succeeded (i.e. the return value is true).
Returns:
true if the parsing went ok (only in this case the trackerResponse object will be changed).

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

Mandatory fields are 'interval' and 'peers'. In 'peers', 'peer id', 'ip' and 'port' are mandatory fields. The rest of fields are only optional.

If the 'failure reason' field value is non-empty and there are NO other data, only failureReason() member function can be then called on the trackerResponse (other member function will return default values).

If the 'failure reason' field value is non-empty and there are also other data as well, trackerResponse will be left unchanged (it counts as an error during parsing).

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 58 of file TrackerResponseParser.cpp.

PeerInfo TrackerResponseParser::parseRawPeerInfo const QByteArray &  rawPeerInfo  )  [static, private]
 

Returns:
parsed rawPeerInfo (binary model).

Definition at line 310 of file TrackerResponseParser.cpp.


Member Data Documentation

const char * TrackerResponseParser::CompleteKeyName = "complete" [static, private]
 

Definition at line 99 of file TrackerResponseParser.h.

const char * TrackerResponseParser::FailureReasonKeyName = "failure reason" [static, private]
 

Definition at line 94 of file TrackerResponseParser.h.

const char * TrackerResponseParser::IncompleteKeyName = "incomplete" [static, private]
 

Definition at line 100 of file TrackerResponseParser.h.

const char * TrackerResponseParser::IntervalKeyName = "interval" [static, private]
 

Definition at line 96 of file TrackerResponseParser.h.

const char * TrackerResponseParser::MinIntervalKeyName = "min interval" [static, private]
 

Definition at line 97 of file TrackerResponseParser.h.

const int TrackerResponseParser::OnePeerStringSizeBinaryModel = 6 [static, private]
 

Definition at line 105 of file TrackerResponseParser.h.

const char * TrackerResponseParser::PeersIpKeyName = "ip" [static, private]
 

Definition at line 103 of file TrackerResponseParser.h.

const char * TrackerResponseParser::PeersKeyName = "peers" [static, private]
 

Definition at line 101 of file TrackerResponseParser.h.

const char * TrackerResponseParser::PeersPeerIdKeyName = "peer id" [static, private]
 

Definition at line 102 of file TrackerResponseParser.h.

const char * TrackerResponseParser::PeersPortKeyName = "port" [static, private]
 

Definition at line 104 of file TrackerResponseParser.h.

const char * TrackerResponseParser::TrackerIdKeyName = "tracker id" [static, private]
 

Definition at line 98 of file TrackerResponseParser.h.

const char * TrackerResponseParser::WarningMessageKeyName = "warning message" [static, private]
 

Definition at line 95 of file TrackerResponseParser.h.


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