/usr/include/libktorrent/bcodec/bencoder.h is in libktorrent-dev 1.3.1-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | /***************************************************************************
* Copyright (C) 2005 by Joris Guisson *
* joris.guisson@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef BTBENCODER_H
#define BTBENCODER_H
#include <ktorrent_export.h>
#include <util/file.h>
class QIODevice;
namespace bt
{
class File;
/**
* @author Joris Guisson
*
* Interface for classes which wish to receive the output from a BEncoder.
*/
class KTORRENT_EXPORT BEncoderOutput
{
public:
virtual ~BEncoderOutput() {}
/**
* Write a string of characters.
* @param str The string
* @param len The length of the string
*/
virtual void write(const char* str,Uint32 len) = 0;
};
/**
* Writes the output of a bencoder to a file
*/
class KTORRENT_EXPORT BEncoderFileOutput : public BEncoderOutput
{
File* fptr;
public:
BEncoderFileOutput(File* fptr);
void write(const char* str,Uint32 len);
};
/**
* Write the output of a BEncoder to a QByteArray
*/
class KTORRENT_EXPORT BEncoderBufferOutput : public BEncoderOutput
{
QByteArray & data;
Uint32 ptr;
public:
BEncoderBufferOutput(QByteArray & data);
void write(const char* str,Uint32 len);
};
class KTORRENT_EXPORT BEncoderIODeviceOutput : public BEncoderOutput
{
QIODevice* dev;
public:
BEncoderIODeviceOutput(QIODevice* dev);
void write(const char* str,Uint32 len);
};
/**
* @author Joris Guisson
* @brief Helper class to b-encode stuff.
*
* This class b-encodes data. For more details about b-encoding, see
* the BitTorrent protocol docs. The data gets written to a BEncoderOutput
* thing.
*/
class KTORRENT_EXPORT BEncoder
{
BEncoderOutput* out;
bool del;
public:
/**
* Constructor, output gets written to a file.
* @param fptr The File to write to
*/
BEncoder(File* fptr);
/**
* Constructor, output gets written to a BEncoderOutput object.
* @param out The BEncoderOutput
*/
BEncoder(BEncoderOutput* out);
/**
* Constructor, output gets written to a QIODevice object.
* @param dev The QIODevice
*/
BEncoder(QIODevice* dev);
virtual ~BEncoder();
/**
* Begin a dictionary.Should have a corresponding end call.
*/
void beginDict();
/**
* Begin a list. Should have a corresponding end call.
*/
void beginList();
template <class T>
void write(const QString & key,T val)
{
write(key);
write(val);
}
/**
* Write a boolean (is encoded as an intÃ
* @param val
*/
void write(bool val);
/**
* Write a float
* @param val
*/
void write(float val);
/**
* Write an int
* @param val
*/
void write(Uint32 val);
/**
* Write an int64
* @param val
*/
void write(Uint64 val);
/**
* Write a string
* @param str
*/
void write(const char* str);
/**
* Write a string
* @param str
*/
void write(const QString & str);
/**
* Write a QByteArray
* @param data
*/
void write(const QByteArray & data);
/**
* Write a data array
* @param data
* @param size of data
*/
void write(const Uint8* data,Uint32 size);
/**
* End a beginDict or beginList call.
*/
void end();
};
}
#endif
|