TrackerResponseParser.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 2006-2007 by Peter Dimov.
00004 
00005 This file is part of Calitko (http://www.calitko.org).
00006 
00007 Calitko is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 Calitko is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Calitko; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 } // namespace Trackers
00109 } // namespace BitTorrent
00110 } // namespace Protocols
00111 
00112 #endif // PROTOCOLS__BIT_TORRENT__TRACKERS__TRACKER_RESPONSE_PARSER_H