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
00025 #include <string>
00026
00027 #if defined( HAVE_OPENSSL )
00028 # define USE_OPENSSL
00029 # include <openssl/ssl.h>
00030 # define HAVE_TLS
00031 #elif defined( HAVE_GNUTLS )
00032 # define USE_GNUTLS
00033 # include <gnutls/gnutls.h>
00034 # include <gnutls/x509.h>
00035 # define HAVE_TLS
00036 #endif
00037
00038 #ifdef HAVE_ZLIB
00039 # include <zlib.h>
00040 #endif
00041
00042 namespace gloox
00043 {
00044
00045 class Packet;
00046 class Parser;
00047
00054 class GLOOX_EXPORT Connection
00055 {
00056 public:
00065 Connection( Parser *parser, const std::string& server, 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
00132 void setCompression( bool compression );
00133
00141 bool initCompression( bool init );
00142 #endif
00143
00144 #ifdef HAVE_TLS
00145
00148 bool tlsHandshake();
00149
00155 void setCACerts( const StringList& cacerts ) { m_cacerts = cacerts; };
00156
00161 const CertInfo& fetchTLSInfo() const { return m_certInfo; };
00162 #endif
00163
00164 private:
00165 void cancel();
00166 void cleanup();
00167
00168 #ifdef HAVE_ZLIB
00169 std::string compress( const std::string& data );
00170 std::string decompress( const std::string& data );
00171 z_stream m_zinflate;
00172 #endif
00173
00174 #if defined( USE_GNUTLS )
00175
00176 bool verifyAgainstCAs( gnutls_x509_crt_t cert, gnutls_x509_crt_t *CAList, int CAListSize );
00177 bool verifyAgainst( gnutls_x509_crt_t cert, gnutls_x509_crt_t issuer );
00178
00179 gnutls_session_t m_session;
00180 gnutls_certificate_credentials m_credentials;
00181
00182 #elif defined( USE_OPENSSL )
00183 SSL *m_ssl;
00184 #endif
00185
00186 StringList m_cacerts;
00187
00188 Parser *m_parser;
00189 ConnectionState m_state;
00190 CertInfo m_certInfo;
00191 ConnectionError m_disconnect;
00192
00193 char *m_buf;
00194 std::string m_server;
00195 int m_port;
00196 int m_socket;
00197 int m_compCount;
00198 int m_decompCount;
00199 int m_dataOutCount;
00200 int m_dataInCount;
00201 bool m_cancel;
00202 bool m_secure;
00203 bool m_compression;
00204 bool m_fdRequested;
00205 bool m_compInited;
00206 };
00207
00208 }
00209
00210 #endif // CONNECTION_H__