1//
2// Base64Decoder.h
3//
4// Library: Foundation
5// Package: Streams
6// Module: Base64
7//
8// Definition of class Base64Decoder.
9//
10// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
11// and Contributors.
12//
13// SPDX-License-Identifier: BSL-1.0
14//
15
16
17#ifndef Foundation_Base64Decoder_INCLUDED
18#define Foundation_Base64Decoder_INCLUDED
19
20
21#include "Poco/Foundation.h"
22#include "Poco/UnbufferedStreamBuf.h"
23#include <istream>
24
25
26namespace Poco {
27
28
29class Foundation_API Base64DecoderBuf: public UnbufferedStreamBuf
30 /// This streambuf base64-decodes all data read
31 /// from the istream connected to it.
32 ///
33 /// Note: For performance reasons, the characters
34 /// are read directly from the given istream's
35 /// underlying streambuf, so the state
36 /// of the istream will not reflect that of
37 /// its streambuf.
38{
39public:
40 Base64DecoderBuf(std::istream& istr, int options = 0);
41 ~Base64DecoderBuf();
42
43private:
44 int readFromDevice();
45 int readOne();
46
47 int _options;
48 unsigned char _group[3];
49 int _groupLength;
50 int _groupIndex;
51 std::streambuf& _buf;
52 const unsigned char* _pInEncoding;
53
54 static unsigned char IN_ENCODING[256];
55 static bool IN_ENCODING_INIT;
56 static unsigned char IN_ENCODING_URL[256];
57 static bool IN_ENCODING_URL_INIT;
58
59private:
60 Base64DecoderBuf(const Base64DecoderBuf&);
61 Base64DecoderBuf& operator = (const Base64DecoderBuf&);
62};
63
64
65class Foundation_API Base64DecoderIOS: public virtual std::ios
66 /// The base class for Base64Decoder.
67 ///
68 /// This class is needed to ensure the correct initialization
69 /// order of the stream buffer and base classes.
70{
71public:
72 Base64DecoderIOS(std::istream& istr, int options = 0);
73 ~Base64DecoderIOS();
74 Base64DecoderBuf* rdbuf();
75
76protected:
77 Base64DecoderBuf _buf;
78
79private:
80 Base64DecoderIOS(const Base64DecoderIOS&);
81 Base64DecoderIOS& operator = (const Base64DecoderIOS&);
82};
83
84
85class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream
86 /// This istream base64-decodes all data
87 /// read from the istream connected to it.
88 ///
89 /// Note: For performance reasons, the characters
90 /// are read directly from the given istream's
91 /// underlying streambuf, so the state
92 /// of the istream will not reflect that of
93 /// its streambuf.
94{
95public:
96 Base64Decoder(std::istream& istr, int options = 0);
97 ~Base64Decoder();
98
99private:
100 Base64Decoder(const Base64Decoder&);
101 Base64Decoder& operator = (const Base64Decoder&);
102};
103
104
105} // namespace Poco
106
107
108#endif // Foundation_Base64Decoder_INCLUDED
109