summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJonathan Bastien-Filiatrault <joe@x2a.org>2009-08-15 14:32:38 -0400
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2010-06-03 19:38:33 +0200
commitdf68b8d5f97bdb9ac6557236bf727762f19881bb (patch)
tree4f286459d40cead7028ea1a44612b06a93924c5a /lib
parent3404a413106394af03ceee9cf11dfd3e9c0789a3 (diff)
downloadgnutls-df68b8d5f97bdb9ac6557236bf727762f19881bb.tar.gz
Allocate data buffer with mbuffer_st structure as suggested by Nikos.
Diffstat (limited to 'lib')
-rw-r--r--lib/gnutls_buffers.c13
-rw-r--r--lib/gnutls_buffers.h2
-rw-r--r--lib/gnutls_mbuffers.c2
-rw-r--r--lib/gnutls_record.c39
4 files changed, 24 insertions, 32 deletions
diff --git a/lib/gnutls_buffers.c b/lib/gnutls_buffers.c
index d64c1d955c..29121d2b01 100644
--- a/lib/gnutls_buffers.c
+++ b/lib/gnutls_buffers.c
@@ -666,22 +666,15 @@ _gnutls_io_read_buffered (gnutls_session_t session, opaque ** iptr,
*/
ssize_t
_gnutls_io_write_buffered (gnutls_session_t session,
- const gnutls_datum_t *msg)
+ mbuffer_st *bufel)
{
mbuffer_head_st * const send_buffer = &session->internals.record_send_buffer;
- int ret;
- ret = _gnutls_mbuffer_enqueue (send_buffer, msg);
- if (ret < 0)
- {
- gnutls_assert ();
- gnutls_free (msg->data);
- return ret;
- }
+ _gnutls_mbuffer_enqueue_mbuffer (send_buffer, bufel);
_gnutls_write_log
("WRITE: enqueued %d bytes for %p. Total %d bytes.\n",
- (int)msg->size, session->internals.transport_recv_ptr,
+ (int)bufel->msg.size, session->internals.transport_recv_ptr,
(int)send_buffer->byte_length);
return _gnutls_io_write_flush (session);
diff --git a/lib/gnutls_buffers.h b/lib/gnutls_buffers.h
index 4c5dae4572..2e0b7de767 100644
--- a/lib/gnutls_buffers.h
+++ b/lib/gnutls_buffers.h
@@ -37,7 +37,7 @@ void _gnutls_io_clear_read_buffer (gnutls_session_t);
int _gnutls_io_clear_peeked_data (gnutls_session_t session);
ssize_t _gnutls_io_write_buffered (gnutls_session_t session,
- const gnutls_datum_t *msg);
+ mbuffer_st *bufel);
int _gnutls_handshake_buffer_get_size (gnutls_session_t session);
int _gnutls_handshake_buffer_put (gnutls_session_t session, opaque * data,
diff --git a/lib/gnutls_mbuffers.c b/lib/gnutls_mbuffers.c
index 32980f0f09..4401304a6e 100644
--- a/lib/gnutls_mbuffers.c
+++ b/lib/gnutls_mbuffers.c
@@ -45,7 +45,6 @@ _gnutls_mbuffer_clear (mbuffer_head_st *buf)
for(bufel = buf->head; bufel != NULL; bufel = next)
{
next = bufel->next;
- gnutls_free(bufel->msg.data);
gnutls_free(bufel);
}
@@ -135,7 +134,6 @@ remove_front (mbuffer_head_st *buf)
buf->byte_length -= (bufel->msg.size - bufel->mark);
buf->length -= 1;
- gnutls_free(bufel->msg.data);
gnutls_free(bufel);
if (!buf->head)
diff --git a/lib/gnutls_record.c b/lib/gnutls_record.c
index 20de1c41a3..ba4b88e5b1 100644
--- a/lib/gnutls_record.c
+++ b/lib/gnutls_record.c
@@ -32,6 +32,7 @@
#include "gnutls_compress.h"
#include "gnutls_cipher.h"
#include "gnutls_buffers.h"
+#include "gnutls_mbuffers.h"
#include "gnutls_handshake.h"
#include "gnutls_hash_int.h"
#include "gnutls_cipher_int.h"
@@ -336,7 +337,8 @@ _gnutls_send_int (gnutls_session_t session, content_type_t type,
gnutls_handshake_description_t htype, const void *_data,
size_t sizeofdata)
{
- gnutls_datum_t cipher;
+ mbuffer_st *bufel;
+ size_t cipher_size;
int retval, ret;
int data2send_size;
uint8_t headers[5];
@@ -386,11 +388,9 @@ _gnutls_send_int (gnutls_session_t session, content_type_t type,
{
ret = _gnutls_io_write_flush (session);
if (ret > 0)
- cipher.size = ret;
+ cipher_size = ret;
else
- cipher.size = 0;
-
- cipher.data = NULL;
+ cipher_size = 0;
retval = session->internals.record_send_buffer.byte_length;
}
@@ -399,26 +399,26 @@ _gnutls_send_int (gnutls_session_t session, content_type_t type,
/* now proceed to packet encryption
*/
- cipher.size = data2send_size + MAX_RECORD_OVERHEAD;
- cipher.data = gnutls_malloc (cipher.size);
- if (cipher.data == NULL)
+ cipher_size = data2send_size + MAX_RECORD_OVERHEAD;
+ bufel = _gnutls_mbuffer_alloc (cipher_size);
+ if (bufel == NULL)
{
gnutls_assert ();
return GNUTLS_E_MEMORY_ERROR;
}
- cipher.size =
+ cipher_size =
_gnutls_encrypt (session, headers, RECORD_HEADER_SIZE, data,
- data2send_size, cipher.data, cipher.size, type,
+ data2send_size, bufel->msg.data, cipher_size, type,
(session->internals.priorities.no_padding ==
0) ? 1 : 0);
- if (cipher.size <= 0)
+ if (cipher_size <= 0)
{
gnutls_assert ();
- if (cipher.size == 0)
- cipher.size = GNUTLS_E_ENCRYPTION_FAILED;
- gnutls_free (cipher.data);
- return cipher.size; /* error */
+ if (cipher_size == 0)
+ cipher_size = GNUTLS_E_ENCRYPTION_FAILED;
+ gnutls_free (bufel);
+ return cipher_size; /* error */
}
retval = data2send_size;
@@ -430,14 +430,15 @@ _gnutls_send_int (gnutls_session_t session, content_type_t type,
{
session_invalidate (session);
gnutls_assert ();
- gnutls_free (cipher.data);
+ gnutls_free (bufel);
return GNUTLS_E_RECORD_LIMIT_REACHED;
}
- ret = _gnutls_io_write_buffered (session, &cipher);
+ bufel->msg.size = cipher_size;
+ ret = _gnutls_io_write_buffered (session, bufel);
}
- if (ret != cipher.size)
+ if (ret != cipher_size)
{
if (ret < 0 && gnutls_error_is_fatal (ret) == 0)
{
@@ -464,7 +465,7 @@ _gnutls_send_int (gnutls_session_t session, content_type_t type,
(int)
_gnutls_uint64touint32
(&session->connection_state.write_sequence_number),
- _gnutls_packet2str (type), type, cipher.size);
+ _gnutls_packet2str (type), type, cipher_size);
return retval;
}