File indexing completed on 2025-01-05 04:37:08
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTBDECODER_H 0007 #define BTBDECODER_H 0008 0009 #include <ktorrent_export.h> 0010 #include <qstring.h> 0011 #include <util/constants.h> 0012 0013 namespace bt 0014 { 0015 class BNode; 0016 class BListNode; 0017 class BDictNode; 0018 class BValueNode; 0019 0020 /** 0021 * @author Joris Guisson 0022 * @brief Decodes b-encoded data 0023 * 0024 * Class to decode b-encoded data. 0025 */ 0026 class KTORRENT_EXPORT BDecoder 0027 { 0028 QByteArray data; 0029 Uint32 pos; 0030 bool verbose; 0031 int level; 0032 0033 public: 0034 /** 0035 * Constructor, passes in the data to decode. 0036 * @param ptr Pointer to the data 0037 * @param size Size of the data 0038 * @param verbose Verbose output to the log 0039 * @param off Offset to start parsing 0040 */ 0041 BDecoder(const Uint8 *ptr, Uint32 size, bool verbose, Uint32 off = 0); 0042 0043 /** 0044 * Constructor, passes in the data to decode. 0045 * @param data The data 0046 * @param verbose Verbose output to the log 0047 * @param off Offset to start parsing 0048 */ 0049 BDecoder(const QByteArray &data, bool verbose, Uint32 off = 0); 0050 virtual ~BDecoder(); 0051 0052 /** 0053 * Decode the data, the root node gets 0054 * returned. (Note that the caller must delete this node) 0055 * @return The root node 0056 */ 0057 BNode *decode(); 0058 0059 /** 0060 * Decode the data, the root list node gets 0061 * returned. (Note that the caller must delete this node) 0062 * @return The root node 0063 */ 0064 BListNode *decodeList(); 0065 0066 /** 0067 * Decode the data, the root dict node gets 0068 * returned. (Note that the caller must delete this node) 0069 * @return The root node 0070 */ 0071 BDictNode *decodeDict(); 0072 0073 /// Get the current position in the data 0074 Uint32 position() const 0075 { 0076 return pos; 0077 } 0078 0079 private: 0080 void debugMsg(const QString &msg); 0081 0082 private: 0083 BDictNode *parseDict(); 0084 BListNode *parseList(); 0085 BValueNode *parseInt(); 0086 BValueNode *parseString(); 0087 }; 0088 0089 } 0090 0091 #endif