libiqxmlrpc  0.12.4
 All Classes Namespaces Files Functions Typedefs Enumerations
ssl_lib.h
1 // Libiqxmlrpc - an object-oriented XML-RPC solution.
2 // Copyright (C) 2011 Anton Dedov
3 
4 #ifndef _libiqnet_ssl_lib_h_
5 #define _libiqnet_ssl_lib_h_
6 
7 #include "api_export.h"
8 
9 #include <openssl/ssl.h>
10 
11 #include <stdexcept>
12 
13 namespace iqnet {
14 namespace ssl {
15 
16 class Ctx;
17 
19 
23 extern LIBIQXMLRPC_API Ctx* ctx;
24 
26 void LIBIQXMLRPC_API throw_io_exception( SSL*, int ret );
27 
29 
36 class LIBIQXMLRPC_API Ctx {
37  SSL_CTX* ctx;
38 
39 public:
40  static Ctx* client_server( const std::string& cert_path, const std::string& key_path );
41  static Ctx* server_only( const std::string& cert_path, const std::string& key_path );
42  static Ctx* client_only();
43 
44  ~Ctx();
45 
46  SSL_CTX* context() { return ctx; }
47 
48 private:
49  Ctx( const std::string&, const std::string&, bool init_client );
50  Ctx();
51 };
52 
53 #ifdef _MSC_VER
54 #pragma warning(disable: 4251)
55 #endif
56 
58 class LIBIQXMLRPC_API exception: public std::exception {
59  unsigned long ssl_err;
60  std::string msg;
61 
62 public:
63  exception() throw();
64  explicit exception( unsigned long ssl_err ) throw();
65  exception( const std::string& msg ) throw();
66  virtual ~exception() throw() {}
67 
68  const char* what() const throw() { return msg.c_str(); }
69  unsigned long code() const throw() { return ssl_err; }
70 };
71 
72 class LIBIQXMLRPC_API not_initialized: public ssl::exception {
73 public:
75  exception( "Libiqnet::ssl not initialized." ) {}
76 };
77 
78 class LIBIQXMLRPC_API connection_close: public ssl::exception {
79  bool clean;
80 public:
81  connection_close( bool clean_ ):
82  exception( "Connection has been closed." ),
83  clean(clean_) {}
84 
85  bool is_clean() const { return clean; }
86 };
87 
88 class LIBIQXMLRPC_API io_error: public ssl::exception {
89 public:
90  io_error( int err ):
91  exception( err ) {}
92 };
93 
94 class LIBIQXMLRPC_API need_write: public ssl::io_error {
95 public:
96  need_write():
97  io_error( SSL_ERROR_WANT_WRITE ) {}
98 };
99 
100 class LIBIQXMLRPC_API need_read: public ssl::io_error {
101 public:
102  need_read():
103  io_error( SSL_ERROR_WANT_READ ) {}
104 };
105 
106 } // namespace ssl
107 } // namespace iqnet
108 
109 #endif