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 
59 {
60 public:
61  typedef size_t size_type ;
62  typedef ssize_t ssize_type ;
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 
148 {
149 public:
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
void(* LogFn)(int, const std::string &)
Definition: gssl.h:64
static Library * instance()
Returns a pointer to a library object, if any.
An SSL protocol class.
Definition: gssl.h:58
static std::string str(Result result)
Converts a result enumeration into a printable string.
A private pimple class used by GSsl::Library.
~Library()
Destructor. Cleans up the underlying ssl library.
Result connect(int fd)
Starts the protocol actively.
std::pair< std::string, bool > peerCertificate(int format=0)
Returns the peer certificate and a verified flag.
Library()
Constructor.
Result stop()
Initiates the protocol shutdown.
size_t size_type
Definition: gssl.h:61
A private pimple class used by GSsl::Protocol.
static std::string credit(const std::string &prefix, const std::string &eol, const std::string &final)
Returns a credit string.
Protocol::LogFn LogFn
Definition: gssl.h:150
Protocol(const Library &)
Constructor.
ssize_t ssize_type
Definition: gssl.h:62
Result read(char *buffer, size_type buffer_size_in, ssize_type &data_size_out)
Reads user data into the supplied buffer.
A RAII class for initialising the underlying ssl library.
Definition: gssl.h:147
~Protocol()
Destructor.
bool enabled(bool for_serving=false) const
Returns true if this is a real and enabled ssl library.
TLS/SSL transport layer security classes.
Result write(const char *buffer, size_type data_size_in, ssize_type &data_size_out)
Writes user data.
Result accept(int fd)
Starts the protocol passively.