TrackerResponseParser.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef PROTOCOLS__BIT_TORRENT__TRACKERS__TRACKER_RESPONSE_PARSER_H
00024 #define PROTOCOLS__BIT_TORRENT__TRACKERS__TRACKER_RESPONSE_PARSER_H
00025
00026 #include "Imports.h"
00027 #include "PeerInfo.h"
00028 #include "TrackerResponse.h"
00029
00030 FORWARD_DECLARE3 (Protocols, BitTorrent, Trackers, class TrackerResponse)
00031
00032 namespace Protocols {
00033 namespace BitTorrent {
00034 namespace Trackers {
00035
00037
00048 class TrackerResponseParser
00049 {
00050 STATIC_HELPER (TrackerResponseParser)
00051
00052 public:
00053 static bool parseAndLoadTrackerResponse (
00054 const QByteArray &rawTrackerResponseData,
00055 TrackerResponse &trackerResponse);
00056 private:
00057 static bool loadAllResponseData (const QByteArray &rawData,
00058 TrackerResponse &response);
00059 static bool loadFailureReason (const BDictionary *bData,
00060 TrackerResponse &response);
00061 static bool loadWarningMessage (const BDictionary *bData,
00062 TrackerResponse &response);
00063 static bool loadInterval (const BDictionary *bData,
00064 TrackerResponse &response);
00065 static bool loadMinInterval (const BDictionary *bData,
00066 TrackerResponse &response);
00067 static bool loadTrackerId (const BDictionary *bData,
00068 TrackerResponse &response);
00069 static bool loadComplete (const BDictionary *bData,
00070 TrackerResponse &response);
00071 static bool loadIncomplete (const BDictionary *bData,
00072 TrackerResponse &response);
00073 static bool loadPeers (const BDictionary *bData,
00074 TrackerResponse &response);
00075 static bool loadPeersBinaryModel (const BString *bPeers,
00076 TrackerResponse::PeerInfoList &peerInfoList);
00077 static PeerInfo parseRawPeerInfo (const QByteArray &rawPeerInfo);
00078 static bool loadPeersDictionaryModel (const BList *bPeers,
00079 TrackerResponse::PeerInfoList &peerInfoList);
00080 static bool loadPeerInfo (const BDictionary *bPeerInfo,
00081 PeerInfo &peerInfo);
00082 static bool loadPeerInfoPeerId (const BDictionary *bPeerInfo,
00083 PeerInfo::PeerId &peerId);
00084 static bool loadPeerInfoHostAddress (const BDictionary *bPeerInfo,
00085 QByteArray &hostAddress);
00086 static bool loadPeerInfoPort (const BDictionary *bPeerInfo,
00087 quint16 &port);
00088
00089 static bool isValidInterval (qint64 interval);
00090 static bool isValidNumberOfPeers (qint64 numOfPeers);
00091 static bool isValidPeerId (const QByteArray &peerId);
00092 static bool isValidPort (qint64 port);
00093
00094 static const char *FailureReasonKeyName;
00095 static const char *WarningMessageKeyName;
00096 static const char *IntervalKeyName;
00097 static const char *MinIntervalKeyName;
00098 static const char *TrackerIdKeyName;
00099 static const char *CompleteKeyName;
00100 static const char *IncompleteKeyName;
00101 static const char *PeersKeyName;
00102 static const char *PeersPeerIdKeyName;
00103 static const char *PeersIpKeyName;
00104 static const char *PeersPortKeyName;
00105 static const int OnePeerStringSizeBinaryModel;
00106 };
00107
00108 }
00109 }
00110 }
00111
00112 #endif // PROTOCOLS__BIT_TORRENT__TRACKERS__TRACKER_RESPONSE_PARSER_H