15 #include "tlsgnutlsbase.h"
27 :
TLSBase( th, server ), m_session( new gnutls_session_t ), m_buf( 0 ), m_bufsize( 17000 )
29 m_buf = (
char*)calloc( m_bufsize + 1,
sizeof(
char ) );
53 std::string::size_type sum = 0;
56 ret = gnutls_record_send( *m_session, data.c_str() + sum, data.length() - sum );
59 while( ( ret == GNUTLS_E_AGAIN ) || ( ret == GNUTLS_E_INTERRUPTED ) || sum < data.length() );
70 return static_cast<int>( data.length() );
77 ret =
static_cast<int>( gnutls_record_recv( *m_session, m_buf, m_bufsize ) );
79 if( ret > 0 && m_handler )
97 gnutls_bye( *m_session, GNUTLS_SHUT_RDWR );
98 gnutls_db_remove_session( *m_session );
99 gnutls_credentials_clear( *m_session );
101 gnutls_deinit( *m_session );
108 m_session =
new gnutls_session_t;
119 int ret = gnutls_handshake( *m_session );
120 if( ret < 0 && gnutls_error_is_fatal( ret ) )
122 gnutls_perror( ret );
123 gnutls_db_remove_session( *m_session );
124 gnutls_deinit( *m_session );
130 else if( ret == GNUTLS_E_AGAIN )
143 ssize_t GnuTLSBase::pullFunc(
void* data,
size_t len )
145 ssize_t cpy = ( len > m_recvBuffer.length() ) ? ( m_recvBuffer.length() ) : ( len );
148 memcpy( data, (
const void*)m_recvBuffer.c_str(), cpy );
149 m_recvBuffer.erase( 0, cpy );
155 return GNUTLS_E_AGAIN;
159 ssize_t GnuTLSBase::pullFunc( gnutls_transport_ptr_t ptr,
void* data,
size_t len )
161 return static_cast<GnuTLSBase*
>( ptr )->pullFunc( data, len );
164 ssize_t GnuTLSBase::pushFunc(
const void* data,
size_t len )
172 ssize_t GnuTLSBase::pushFunc( gnutls_transport_ptr_t ptr,
const void* data,
size_t len )
174 return static_cast<GnuTLSBase*
>( ptr )->pushFunc( data, len );
179 #endif // HAVE_GNUTLS