2
* Copyright (C) 2009 Free Software Foundation
4
* Author: Jonathan Bastien-Filiatrault
6
* This file is part of GNUTLS.
8
* The GNUTLS library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public License
10
* as published by the Free Software Foundation; either version 2.1 of
11
* the License, or (at your option) any later version.
13
* This library is distributed in the hope that it will be useful, but
14
* WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
25
#ifndef GNUTLS_MBUFFERS_H
26
#define GNUTLS_MBUFFERS_H
28
#include <gnutls_int.h>
29
#include <gnutls_errors.h>
31
void _mbuffer_init (mbuffer_head_st * buf);
32
void _mbuffer_clear (mbuffer_head_st * buf);
33
void _mbuffer_enqueue (mbuffer_head_st * buf, mbuffer_st * bufel);
34
int _mbuffer_remove_bytes (mbuffer_head_st * buf, size_t bytes);
35
mbuffer_st *_mbuffer_alloc (size_t payload_size, size_t maximum_size);
37
mbuffer_st *_mbuffer_get_first (mbuffer_head_st * buf, gnutls_datum_t * msg);
38
mbuffer_st *_mbuffer_get_next (mbuffer_st * cur, gnutls_datum_t * msg);
40
/* This is dangerous since it will replace bufel with a new
43
int _mbuffer_append_data (mbuffer_st * bufel, void *newdata,
45
int _mbuffer_linearize (mbuffer_head_st * buf);
48
/* For "user" use. One can have buffer data and header.
52
_mbuffer_set_udata (mbuffer_st * bufel, void *data, size_t data_size)
54
memcpy (bufel->msg.data + bufel->user_mark, data, data_size);
58
_mbuffer_get_uhead_ptr (mbuffer_st * bufel)
60
return bufel->msg.data;
64
_mbuffer_get_udata_ptr (mbuffer_st * bufel)
66
return bufel->msg.data + bufel->user_mark;
70
_mbuffer_set_udata_size (mbuffer_st * bufel, size_t size)
72
bufel->msg.size = size + bufel->user_mark;
76
_mbuffer_get_udata_size (mbuffer_st * bufel)
78
return bufel->msg.size - bufel->user_mark;
82
_mbuffer_get_uhead_size (mbuffer_st * bufel)
84
return bufel->user_mark;
88
_mbuffer_set_uhead_size (mbuffer_st * bufel, size_t size)
90
bufel->user_mark = size;
95
inline static mbuffer_st *
96
_gnutls_handshake_alloc (size_t size, size_t maximum)
98
mbuffer_st *ret = _mbuffer_alloc (HANDSHAKE_HEADER_SIZE + size,
99
HANDSHAKE_HEADER_SIZE + maximum);
104
_mbuffer_set_uhead_size (ret, HANDSHAKE_HEADER_SIZE);
109
/* Free a segment, if the pointer is not NULL
111
* We take a ** to detect and fix double free bugs (the dangling
112
* pointer case). It also makes sure the pointer has a known value
116
_mbuffer_xfree (mbuffer_st ** bufel)
119
gnutls_free (*bufel);