- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gssl.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_SSL_H
22 #define G_SSL_H
23
24 #include "gdef.h"
25 #include <string>
26 #include <utility>
27
29 namespace GSsl
30 {
31 class Library ;
32 class Protocol ;
33 class LibraryImp ;
34 class ProtocolImp ;
35 }
36
58 class GSsl::Protocol
59 {
60 public:
61 typedef size_t size_type ;
62 typedef ssize_t ssize_type ;
63 enum Result { Result_ok , Result_read , Result_write , Result_error , Result_more } ;
64 typedef void (*LogFn)( int , const std::string & ) ;
65
66 explicit Protocol( const Library & ) ;
68
69 Protocol( const Library & , LogFn ) ;
71
72 ~Protocol() ;
74
75 Result connect( int fd ) ;
77
78 Result accept( int fd ) ;
80
81 Result stop() ;
83
84 Result read( char * buffer , size_type buffer_size_in , ssize_type & data_size_out ) ;
108
109 Result write( const char * buffer , size_type data_size_in , ssize_type & data_size_out ) ;
126
127 static std::string str( Result result ) ;
130
131 std::pair<std::string,bool> peerCertificate( int format = 0 ) ;
135
136 private:
137 Protocol( const Protocol & ) ; // not implemented
138 void operator=( const Protocol & ) ; // not implemented
139
140 private:
141 ProtocolImp * m_imp ;
142 } ;
143
147 class GSsl::Library
148 {
149 public:
150 typedef Protocol::LogFn LogFn ;
151
152 Library() ;
155
156 Library( bool active , const std::string & pem_file , unsigned int flags , LogFn = NULL ) ;
162
163 ~Library() ;
165
166 static Library * instance() ;
168
169 bool enabled( bool for_serving = false ) const ;
172
173 static std::string credit( const std::string & prefix , const std::string & eol , const std::string & final ) ;
175
176 private:
177 Library( const Library & ) ; // not implemented
178 void operator=( const Library & ) ; // not implemented
179 const LibraryImp & imp() const ;
180
181 private:
182 friend class GSsl::Protocol ;
183 static Library * m_this ;
184 LibraryImp * m_imp ;
185 } ;
186
187 #endif
GSsl::Library::instance
static Library * instance()
Returns a pointer to a library object, if any.
Definition: gssl_openssl.cpp:254
GSsl::Protocol::Result_ok
Definition: gssl.h:63
GSsl::Protocol
An SSL protocol class.
Definition: gssl.h:58
GSsl::Protocol::str
static std::string str(Result result)
Converts a result enumeration into a printable string.
Definition: gssl_openssl.cpp:398
GSsl::LibraryImp
A private pimple class used by GSsl::Library.
Definition: gssl_openssl.cpp:103
GSsl::Library::~Library
~Library()
Destructor. Cleans up the underlying ssl library.
Definition: gssl_openssl.cpp:247
GSsl::Protocol::connect
Result connect(int fd)
Starts the protocol actively.
Definition: gssl_openssl.cpp:407
GSsl::Protocol::peerCertificate
std::pair< std::string, bool > peerCertificate(int format=0)
Returns the peer certificate and a verified flag.
Definition: gssl_openssl.cpp:393
GSsl::Library::Library
Library()
Constructor.
Definition: gssl_openssl.cpp:230
GSsl::Protocol::stop
Result stop()
Initiates the protocol shutdown.
Definition: gssl_openssl.cpp:417
GSsl::Protocol::size_type
size_t size_type
Definition: gssl.h:61
GSsl::Protocol::LogFn
void(* LogFn)(int, const std::string &)
Definition: gssl.h:64
GSsl::ProtocolImp
A private pimple class used by GSsl::Protocol.
Definition: gssl_openssl.cpp:128
GSsl::Library::credit
static std::string credit(const std::string &prefix, const std::string &eol, const std::string &final)
Returns a credit string.
Definition: gssl_openssl.cpp:271
GSsl::Protocol::Result_error
Definition: gssl.h:63
GSsl::Library::LogFn
Protocol::LogFn LogFn
Definition: gssl.h:150
GSsl::Protocol::Result
Result
Definition: gssl.h:63
GSsl::Protocol::Result_read
Definition: gssl.h:63
GSsl::Protocol::Protocol
Protocol(const Library &)
Constructor.
Definition: gssl_openssl.cpp:378
GSsl::Protocol::ssize_type
ssize_t ssize_type
Definition: gssl.h:62
GSsl::Protocol::read
Result read(char *buffer, size_type buffer_size_in, ssize_type &data_size_out)
Reads user data into the supplied buffer.
Definition: gssl_openssl.cpp:422
GSsl::Protocol::Result_more
Definition: gssl.h:63
GSsl::Library
A RAII class for initialising the underlying ssl library.
Definition: gssl.h:147
GSsl::Protocol::~Protocol
~Protocol()
Destructor.
Definition: gssl_openssl.cpp:388
GSsl::Library::enabled
bool enabled(bool for_serving=false) const
Returns true if this is a real and enabled ssl library.
Definition: gssl_openssl.cpp:259
GSsl
TLS/SSL transport layer security classes.
GSsl::Protocol::write
Result write(const char *buffer, size_type data_size_in, ssize_type &data_size_out)
Writes user data.
Definition: gssl_openssl.cpp:427
GSsl::Protocol::Result_write
Definition: gssl.h:63
GSsl::Protocol::accept
Result accept(int fd)
Starts the protocol passively.
Definition: gssl_openssl.cpp:412