StreamBuffer.h
1/*
2 * Copyright (C) 2010-2012 by Marc Boris Duerner
3 * Copyright (C) 2010-2010 by Aloysius Indrayanto
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * As a special exception, you may use this file as part of a free
11 * software library without restriction. Specifically, if other files
12 * instantiate templates or use macros or inline functions from this
13 * file, or you compile this file and link it with other files to
14 * produce an executable, this file does not by itself cause the
15 * resulting executable to be covered by the GNU General Public
16 * License. This exception does not however invalidate any other
17 * reasons why the executable file might be covered by the GNU Library
18 * General Public License.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#ifndef PT_SSL_StreamBuffer_H
31#define PT_SSL_StreamBuffer_H
32
33#include <Pt/Ssl/Api.h>
34#include <Pt/Ssl/Context.h>
35#include <Pt/StreamBuffer.h>
36#include <ios>
37#include <cstddef>
38
39namespace Pt {
40
41namespace Ssl {
42
43class Connection;
44
72class PT_SSL_API StreamBuffer : public BasicStreamBuffer<char>
73{
74 public:
77 StreamBuffer(std::size_t bufferSize = 1024);
78
81 StreamBuffer(Context& ctx, std::ios& ios, OpenMode mode, std::size_t bufferSize = 1024);
82
85 virtual ~StreamBuffer();
86
89 void open(Context& ctx, std::ios& ios, OpenMode mode);
90
93 void setPeerName(const std::string& peerName);
94
97 const char* currentCipher() const;
98
101 void close();
102
105 bool isConnected() const;
106
115
124 bool readHandshake(std::streamsize maxRead = 0);
125
132 bool shutdown();
133
136 bool isShutdown() const;
137
140 bool isClosed() const;
141
148 std::streamsize import(std::streamsize maxImport = 0);
149
150 protected:
151 // inheritdoc
152 virtual std::streamsize showmanyc();
153
154 // inheritdoc
155 virtual std::streamsize showfull();
156
157 // inheritdoc
158 virtual int sync();
159
160 // inheritdoc
161 virtual int_type underflow();
162
163 // inheritdoc
164 virtual int_type overflow(int_type ch);
165
166 private:
167 Connection* _connection;
168 std::string _peerName;
169 std::size_t _ibufferSize;
170 char* _ibuffer;
171 std::size_t _obufferSize;
172 char* _obuffer;
173
174 static const int _pbmax = 4;
175};
176
177} // namespace Ssl
178
179} // namespace Pt
180
181#endif // PT_SSL_StreamBuffer_H
BasicStreamBuffer()
Definition StreamBuffer.h:139
Represents a connection between a Signal/Delegate and a slot.
Definition Connection.h:96
Shared configuration for SSL connections.
Definition Context.h:113
bool isShutdown() const
Returns true if a shutdown alert was received.
virtual ~StreamBuffer()
Destructor.
void setPeerName(const std::string &peerName)
Sets the name expected in the peer certificate.
bool readHandshake(std::streamsize maxRead=0)
Reads a handshake message from the underlying stream.
void close()
Closes the stream buffer without a TLS shutdown.
virtual std::streamsize showfull()
Returns the number of characters buffered for output.
bool writeHandshake()
Writes a handshake message to the underlying stream.
StreamBuffer(Context &ctx, std::ios &ios, OpenMode mode, std::size_t bufferSize=1024)
Creates an SSL stream buffer and opens it.
bool isConnected() const
Returns true if the handshake has completed.
StreamBuffer(std::size_t bufferSize=1024)
Creates a closed SSL stream buffer.
void open(Context &ctx, std::ios &ios, OpenMode mode)
Opens the stream buffer on ios using ctx and mode.
bool isClosed() const
Returns true if the connection was closed prematurely.
bool shutdown()
Completes or starts the TLS shutdown.
const char * currentCipher() const
Returns the cipher in use, or a placeholder if not connected.
OpenMode
Open mode for an SSL stream.
Definition Context.h:56
SSL/TLS streams, certificates and contexts.
Definition Client.h:50
Core module.
Definition Allocator.h:33