1/*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
3 *
4 * Author: Nikos Mavrogiannopoulos
5 *
6 * This file is part of GnuTLS.
7 *
8 * The GnuTLS 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.
12 *
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.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
20 *
21 */
22#ifndef GNUTLS_BUFFERS_H
23#define GNUTLS_BUFFERS_H
24
25#define MBUFFER_FLUSH 1
26
27int
28_gnutls_record_buffer_put (gnutls_session_t session,
29 content_type_t type, uint64* seq, mbuffer_st* bufel);
30
31inline static int
32_gnutls_record_buffer_get_size (gnutls_session_t session)
33{
34 return session->internals.record_buffer.byte_length;
35}
36
37/*-
38 * record_check_unprocessed:
39 * @session: is a #gnutls_session_t structure.
40 *
41 * This function checks if there are unprocessed data
42 * in the gnutls record buffers. Those data might not
43 * be complete records.
44 *
45 * Returns: Returns the size of the data or zero.
46 -*/
47inline static size_t
48record_check_unprocessed (gnutls_session_t session)
49{
50 return session->internals.record_recv_buffer.byte_length;
51}
52
53int _gnutls_record_buffer_get (content_type_t type,
54 gnutls_session_t session, uint8_t * data,
55 size_t length, uint8_t seq[8]);
56ssize_t _gnutls_io_read_buffered (gnutls_session_t, size_t n, content_type_t, unsigned int *ms);
57int _gnutls_io_clear_peeked_data (gnutls_session_t session);
58
59ssize_t _gnutls_io_write_buffered (gnutls_session_t session,
60 mbuffer_st * bufel, unsigned int mflag);
61
62int _gnutls_handshake_io_cache_int (gnutls_session_t,
63 gnutls_handshake_description_t,
64 mbuffer_st * bufel);
65
66ssize_t
67_gnutls_handshake_io_recv_int (gnutls_session_t session,
68 gnutls_handshake_description_t htype,
69 handshake_buffer_st * hsk, unsigned int optional);
70
71ssize_t _gnutls_io_write_flush (gnutls_session_t session);
72int
73_gnutls_io_check_recv (gnutls_session_t session, unsigned int ms);
74ssize_t _gnutls_handshake_io_write_flush (gnutls_session_t session);
75
76inline static void _gnutls_handshake_buffer_clear(handshake_buffer_st* hsk)
77{
78 _gnutls_buffer_clear(&hsk->data);
79 hsk->htype = -1;
80}
81
82inline static void _gnutls_handshake_buffer_init(handshake_buffer_st* hsk)
83{
84 memset(hsk, 0, sizeof(*hsk));
85 _gnutls_buffer_init(&hsk->data);
86 hsk->htype = -1;
87}
88
89inline static void _gnutls_handshake_recv_buffer_clear(gnutls_session_t session)
90{
91int i;
92 for (i=0;i<session->internals.handshake_recv_buffer_size;i++)
93 _gnutls_handshake_buffer_clear(&session->internals.handshake_recv_buffer[i]);
94 session->internals.handshake_recv_buffer_size = 0;
95}
96
97inline static void _gnutls_handshake_recv_buffer_init(gnutls_session_t session)
98{
99int i;
100 for (i=0;i<MAX_HANDSHAKE_MSGS;i++)
101 {
102 _gnutls_handshake_buffer_init(&session->internals.handshake_recv_buffer[i]);
103 }
104 session->internals.handshake_recv_buffer_size = 0;
105}
106
107int
108_gnutls_parse_record_buffered_msgs (gnutls_session_t session);
109
110ssize_t
111_gnutls_recv_in_buffers (gnutls_session_t session, content_type_t type,
112 gnutls_handshake_description_t htype, unsigned int ms);
113
114#define _gnutls_handshake_io_buffer_clear( session) \
115 _mbuffer_head_clear( &session->internals.handshake_send_buffer); \
116 _gnutls_handshake_recv_buffer_clear( session);
117
118#endif
119