blob: e13c0875d34c823853299cf1c043c243abcc77ab [file] [log] [blame]
Paul Bakker0a597072012-09-25 21:55:46 +00001/**
2 * \file ssl_cache.h
3 *
4 * \brief SSL session cache implementation
5 *
6 * Copyright (C) 2006-2012, Brainspark B.V.
7 *
8 * This file is part of PolarSSL (http://www.polarssl.org)
9 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
10 *
11 * All rights reserved.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 */
27#ifndef POLARSSL_SSL_CACHE_H
28#define POLARSSL_SSL_CACHE_H
29
30#include "ssl.h"
31
32#define SSL_CACHE_DEFAULT_TIMEOUT 86400 /*!< 1 day */
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38typedef struct _ssl_cache_context ssl_cache_context;
39typedef struct _ssl_cache_entry ssl_cache_entry;
40
41/**
42 * \brief This structure is used for storing cache entries
43 */
44struct _ssl_cache_entry
45{
46 time_t timestamp; /*!< entry timestamp */
47 ssl_session session; /*!< entry session */
48 ssl_cache_entry *next; /*!< chain pointer */
49};
50
51/**
52 * \brief Cache context
53 */
54struct _ssl_cache_context
55{
56 ssl_cache_entry *chain; /*!< start of the chain */
57 int timeout; /*!< cache timeout */
58};
59
60/**
61 * \brief Initialize an SSL cache context
62 *
63 * \param cache SSL cache context
64 */
65void ssl_cache_init( ssl_cache_context *cache );
66
67/**
68 * \brief Cache get callback implementation
69 *
70 * \param data SSL cache context
71 * \param session session to retrieve entry for
72 */
73int ssl_cache_get( void *data, ssl_session *session );
74
75/**
76 * \brief Cache set callback implementation
77 *
78 * \param data SSL cache context
79 * \param session session to store entry for
80 */
81int ssl_cache_set( void *data, const ssl_session *session );
82
83/**
84 * \brief Set the cache timeout
85 * (Default: SSL_CACHE_DEFAULT_TIMEOUT (1 day))
86 *
87 * A timeout of 0 indicates no timeout.
88 *
89 * \param cache SSL cache context
90 * \param timeout cache entry timeout
91 */
92void ssl_cache_set_timeout( ssl_cache_context *cache, int timeout );
93
94/**
95 * \brief Free referenced items in a cache context and clear memory
96 *
97 * \param cache SSL cache context
98 */
99void ssl_cache_free( ssl_cache_context *cache );
100
101#ifdef __cplusplus
102}
103#endif
104
105#endif /* ssl_cache.h */