kmime_codecs.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
#ifndef __KMIME_CODECS__
00033
#define __KMIME_CODECS__
00034
00035
#include <qasciidict.h>
00036
#if defined(QT_THREAD_SUPPORT)
00037
# include <qmutex.h>
00038
#endif
00039
00040
#include <qcstring.h>
00041
00042
#include <kdebug.h>
00043
00044
namespace KMime {
00045
00046
00047
class Encoder;
00048
class Decoder;
00049
00056 class Codec {
00057
protected:
00058
00059
static QAsciiDict<Codec> all;
00060
#if defined(QT_THREAD_SUPPORT)
00061
static QMutex dictLock;
00062
#endif
00063
00064
Codec() {}
00065
private:
00066
static void fillDictionary();
00067
00068
public:
00069
static Codec * codecForName(
const char *
name );
00070
static Codec * codecForName(
const QCString & name );
00071
00072
virtual int maxEncodedSizeFor(
int insize,
bool withCRLF=
false )
const = 0;
00073
virtual int maxDecodedSizeFor(
int insize,
bool withCRLF=
false )
const = 0;
00074
00075
virtual Encoder * makeEncoder(
bool withCRLF=
false )
const = 0;
00076
virtual Decoder * makeDecoder(
bool withCRLF=
false )
const = 0;
00077
00110
virtual bool encode(
const char* & scursor,
const char *
const send,
00111
char* & dcursor,
const char *
const dend,
00112
bool withCRLF=
false )
const;
00113
00146
virtual bool decode(
const char* & scursor,
const char *
const send,
00147
char* & dcursor,
const char *
const dend,
00148
bool withCRLF=
false )
const;
00149
00157
virtual QByteArray encode(
const QByteArray & src,
bool withCRLF=
false )
const;
00158
00170
virtual QCString encodeToQCString(
const QByteArray & src,
bool withCRLF=
false )
const;
00171
00179
virtual QByteArray decode(
const QByteArray & src,
bool withCRLF=
false )
const;
00180
00184
virtual const char *
name()
const = 0;
00185
00186
virtual ~
Codec() {}
00187
00188 };
00189
00267
class Decoder {
00268
protected:
00269
friend class Codec;
00275 Decoder(
bool withCRLF=
false )
00276 : mWithCRLF( withCRLF ) {}
00277
public:
00278
virtual ~Decoder() {}
00279
00283
virtual bool decode(
const char* & scursor,
const char *
const send,
00284
char* & dcursor,
const char *
const dend ) = 0;
00289
virtual bool finish(
char* & dcursor,
const char *
const dend ) = 0;
00290
00291
protected:
00292
const bool mWithCRLF;
00293 };
00294
00299 class Encoder {
00300
protected:
00301
friend class Codec;
00305 Encoder(
bool withCRLF=
false )
00306 : mOutputBufferCursor( 0 ), mWithCRLF( withCRLF ) {}
00307
public:
00308
virtual ~
Encoder() {}
00309
00312
virtual bool encode(
const char* & scursor,
const char *
const send,
00313
char* & dcursor,
const char *
const dend ) = 0;
00314
00318
virtual bool finish(
char* & dcursor,
const char *
const dend ) = 0;
00319
00320
protected:
00322
enum { maxBufferedChars = 8 };
00323
00327 bool write(
char ch,
char* & dcursor,
const char *
const dend ) {
00328
if ( dcursor != dend ) {
00329
00330 *dcursor++ = ch;
00331
return true;
00332 }
else {
00333
00334 kdFatal( mOutputBufferCursor >= maxBufferedChars )
00335 <<
"KMime::Encoder: internal buffer overflow!" << endl;
00336 mOutputBuffer[ mOutputBufferCursor++ ] = ch;
00337
return false;
00338 }
00339 }
00340
00345
bool flushOutputBuffer(
char* & dcursor,
const char *
const dend );
00346
00349 bool writeCRLF(
char* & dcursor,
const char *
const dend ) {
00350
if ( mWithCRLF )
00351 write(
'\r', dcursor, dend );
00352
return write(
'\n', dcursor, dend );
00353 }
00354
00355
private:
00358
char mOutputBuffer[ maxBufferedChars ];
00359
protected:
00360 uchar mOutputBufferCursor;
00361
const bool mWithCRLF;
00362 };
00363
00364 }
00365
00366
#endif // __KMIME_CODECS__
This file is part of the documentation for libkdenetwork Library Version 3.3.0.