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 );
107 m_session =
new gnutls_session_t;
118 int ret = gnutls_handshake( *m_session );
119 if( ret < 0 && gnutls_error_is_fatal( ret ) )
121 gnutls_perror( ret );
122 gnutls_db_remove_session( *m_session );
123 gnutls_deinit( *m_session );
129 else if( ret == GNUTLS_E_AGAIN )
142 ssize_t GnuTLSBase::pullFunc(
void* data,
size_t len )
144 ssize_t cpy = ( len > m_recvBuffer.length() ) ? ( m_recvBuffer.length() ) : ( len );
147 memcpy( data, (
const void*)m_recvBuffer.c_str(), cpy );
148 m_recvBuffer.erase( 0, cpy );
154 return GNUTLS_E_AGAIN;
158 ssize_t GnuTLSBase::pullFunc( gnutls_transport_ptr_t ptr,
void* data,
size_t len )
160 return static_cast<GnuTLSBase*
>( ptr )->pullFunc( data, len );
163 ssize_t GnuTLSBase::pushFunc(
const void* data,
size_t len )
171 ssize_t GnuTLSBase::pushFunc( gnutls_transport_ptr_t ptr,
const void* data,
size_t len )
173 return static_cast<GnuTLSBase*
>( ptr )->pushFunc( data, len );
178 #endif // HAVE_GNUTLS