GNU CommonC++
ssl.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2010 David Sugar, Tycho Softworks
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // Common C++. If you copy code from other releases into a copy of GNU
28 // Common C++, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU Common C++, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37 
43 #ifndef CCXX_SSL_H_
44 #define CCXX_SSL_H_
45 
46 #ifndef CCXX_CONFIG_H_
47 #include <cc++/config.h>
48 #endif
49 
50 #ifndef CCXX_THREAD_H_
51 #include <cc++/thread.h>
52 #endif
53 
54 #ifndef CCXX_SOCKET_H_
55 #include <cc++/socket.h>
56 #endif
57 
58 #ifdef CCXX_GNUTLS
59 #include <gnutls/gnutls.h>
60 typedef struct {
61  gnutls_session session;
62  gnutls_certificate_credentials xcred;
63  int result;
64 } SSL;
65 #else
66 #include <openssl/ssl.h>
67 #endif
68 
69 #ifdef CCXX_NAMESPACES
70 namespace ost {
71 #endif
72 
73 class SSLStream : public TCPStream
74 {
75 protected:
76  SSL *ssl;
77 
78 public:
79  SSLStream(Family family = IPV4, bool throwflag = true, timeout_t to = 0);
80  void disconnect(void);
81 
82  SSLStream(const IPV4Host &host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t to = 0);
83 #ifdef CCXX_IPV6
84  SSLStream(const IPV6Host &host, tpport_t port, unsigned mss = 536, bool throwflag = true, timeout_t to = 0);
85 #endif
86  SSLStream(const char *name, Family family = IPV4, unsigned mss = 536, bool throwflag = false, timeout_t to = 0);
87 
88  SSLStream(const SSLStream &ssl);
89 
90  inline bool isSSL(void)
91  {return (bool)(ssl != NULL);};
92 
93  bool getSession(void);
94  void endStream(void);
95  virtual ~SSLStream();
96 
97  ssize_t readLine(char *str, size_t max, timeout_t to = 0);
98  ssize_t readData(void *buf, size_t len, char separator = 0, timeout_t to = 0);
99  ssize_t writeData(void *buf, size_t len, timeout_t to = 0);
100 };
101 
102 #ifdef CCXX_NAMESPACES
103 }
104 #endif
105 
106 #endif
107 
Definition: socket.h:126
ssize_t readData(void *buf, size_t len, char separator=0, timeout_t to=0)
Definition: address.h:64
Family
Definition: socket.h:122
ssize_t readLine(char *str, size_t max, timeout_t to=0)
virtual ~SSLStream()
unsigned long timeout_t
Definition: thread.h:74
Family family
Definition: socket.h:1644
Synchronization and threading services.
void endStream(void)
SSLStream(Family family=IPV4, bool throwflag=true, timeout_t to=0)
ssize_t writeData(void *buf, size_t len, timeout_t to=0)
TCP streams are used to represent TCP client connections to a server by TCP protocol servers for acce...
Definition: socket.h:1631
bool getSession(void)
bool isSSL(void)
Definition: ssl.h:90
void disconnect(void)
Definition: ssl.h:73
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Definition: address.h:561
SSL * ssl
Definition: ssl.h:76
Network addresses and sockets related classes.
unsigned short tpport_t
Transport Protocol Ports.
Definition: address.h:86
This object is used to hold the actual and valid internet address of a specific host machine that wil...
Definition: address.h:948