libktorrent  2.2.0
bdecoder.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTBDECODER_H
21 #define BTBDECODER_H
22 
23 #include <qstring.h>
24 #include <util/constants.h>
25 #include <ktorrent_export.h>
26 
27 namespace bt
28 {
29 
30  class BNode;
31  class BListNode;
32  class BDictNode;
33  class BValueNode;
34 
41  class KTORRENT_EXPORT BDecoder
42  {
43  QByteArray data;
44  Uint32 pos;
45  bool verbose;
46  int level;
47  public:
55  BDecoder(const Uint8* ptr, Uint32 size, bool verbose, Uint32 off = 0);
56 
63  BDecoder(const QByteArray & data, bool verbose, Uint32 off = 0);
64  virtual ~BDecoder();
65 
71  BNode* decode();
72 
78  BListNode* decodeList();
79 
85  BDictNode* decodeDict();
86 
88  Uint32 position() const
89  {
90  return pos;
91  }
92  private:
93  void debugMsg(const QString & msg);
94 
95  private:
96  BDictNode* parseDict();
97  BListNode* parseList();
98  BValueNode* parseInt();
99  BValueNode* parseString();
100  };
101 
102 }
103 
104 #endif
bt::BValueNode
Represents a value (string,bytearray or int) in bencoded data.
Definition: bnode.h:103
bt::BListNode
Represents a list in bencoded data.
Definition: bnode.h:189
bt::BDictNode
Represents a dictionary in bencoded data.
Definition: bnode.h:119