00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef CONNECTION_H__
00015 #define CONNECTION_H__
00016
00017 #ifdef WIN32
00018 # include "../config.h.win"
00019 #else
00020 # include "config.h"
00021 #endif
00022
00023 #include "gloox.h"
00024 #include "logsink.h"
00025
00026 #include <string>
00027
00028 #if defined( HAVE_OPENSSL )
00029 # define USE_OPENSSL
00030 # include <openssl/ssl.h>
00031 # define HAVE_TLS
00032 #elif defined( HAVE_GNUTLS )
00033 # define USE_GNUTLS
00034 # include <gnutls/gnutls.h>
00035 # include <gnutls/x509.h>
00036 # define HAVE_TLS
00037 #endif
00038
00039 namespace gloox
00040 {
00041
00042 class Compression;
00043 class Packet;
00044 class Parser;
00045
00052 class GLOOX_API Connection
00053 {
00054 public:
00064 Connection( Parser *parser, const LogSink& logInstance, const std::string& server,
00065 int port = -1 );
00066
00070 virtual ~Connection();
00071
00076 ConnectionState connect();
00077
00083 ConnectionError recv( int timeout = -1 );
00084
00090 void send( const std::string& data );
00091
00096 ConnectionError receive();
00097
00103 void disconnect( ConnectionError e );
00104
00109 bool isSecure() const { return m_secure; };
00110
00115 ConnectionState state() const { return m_state; };
00116
00123 int fileDescriptor();
00124
00125 #ifdef HAVE_ZLIB
00126
00133 bool initCompression( StreamFeature method );
00134
00139 void enableCompression();
00140 #endif
00141
00142 #ifdef HAVE_TLS
00143
00146 bool tlsHandshake();
00147
00153 void setCACerts( const StringList& cacerts ) { m_cacerts = cacerts; };
00154
00159 const CertInfo& fetchTLSInfo() const { return m_certInfo; };
00160
00172 void setClientCert( const std::string& clientKey, const std::string& clientCerts );
00173 #endif
00174
00175 private:
00176 void cancel();
00177 void cleanup();
00178
00179 #if defined( USE_GNUTLS )
00180
00181 bool verifyAgainstCAs( gnutls_x509_crt_t cert, gnutls_x509_crt_t *CAList, int CAListSize );
00182 bool verifyAgainst( gnutls_x509_crt_t cert, gnutls_x509_crt_t issuer );
00183
00184 gnutls_session_t m_session;
00185 gnutls_certificate_credentials m_credentials;
00186
00187 #elif defined( USE_OPENSSL )
00188 SSL *m_ssl;
00189 #endif
00190
00191 StringList m_cacerts;
00192 std::string m_clientKey;
00193 std::string m_clientCerts;
00194
00195 Parser *m_parser;
00196 ConnectionState m_state;
00197 CertInfo m_certInfo;
00198 ConnectionError m_disconnect;
00199 const LogSink& m_logInstance;
00200 Compression *m_compression;
00201
00202 char *m_buf;
00203 std::string m_server;
00204 int m_port;
00205 int m_socket;
00206 const int m_bufsize;
00207 bool m_cancel;
00208 bool m_secure;
00209 bool m_fdRequested;
00210 bool m_enableCompression;
00211 };
00212
00213 }
00214
00215 #endif // CONNECTION_H__