1 /* resume.c --- Handle the details of TLS session resumption.
2 * Copyright (C) 2002, 2003, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, see http://www.gnu.org/licenses or write
18 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 * Floor, Boston, MA 02110-1301, USA
23 /* Note: only use syslog to report errors in this file. */
25 /* Get Shishid stuff. */
36 static CACHE
*cache_db
;
37 static size_t cache_db_ptr
= 0;
38 static size_t cache_db_size
= 0;
41 resume_db_store (void *dbf
, gnutls_datum key
, gnutls_datum data
)
43 if (cache_db_size
== 0)
46 cache_db
[cache_db_ptr
].id
= xrealloc (cache_db
[cache_db_ptr
].id
, key
.size
);
47 memcpy (cache_db
[cache_db_ptr
].id
, key
.data
, key
.size
);
48 cache_db
[cache_db_ptr
].id_size
= key
.size
;
50 cache_db
[cache_db_ptr
].data
= xrealloc (cache_db
[cache_db_ptr
].data
,
52 memcpy (cache_db
[cache_db_ptr
].data
, data
.data
, data
.size
);
53 cache_db
[cache_db_ptr
].data_size
= data
.size
;
56 cache_db_ptr
%= cache_db_size
;
62 resume_db_fetch (void *dbf
, gnutls_datum key
)
64 gnutls_datum res
= { NULL
, 0 };
67 for (i
= 0; i
< cache_db_size
; i
++)
68 if (key
.size
== cache_db
[i
].id_size
&&
69 memcmp (key
.data
, cache_db
[i
].id
, key
.size
) == 0)
71 res
.size
= cache_db
[i
].data_size
;
73 res
.data
= gnutls_malloc (res
.size
);
77 memcpy (res
.data
, cache_db
[i
].data
, res
.size
);
86 resume_db_delete (void *dbf
, gnutls_datum key
)
90 for (i
= 0; i
< cache_db_size
; i
++)
91 if (key
.size
== cache_db
[i
].id_size
&&
92 memcmp (key
.data
, cache_db
[i
].id
, key
.size
) == 0)
94 cache_db
[i
].id_size
= 0;
95 cache_db
[i
].data_size
= 0;
104 resume_db_init (size_t nconnections
)
107 cache_db
= xcalloc (nconnections
, sizeof (*cache_db
));
108 cache_db_size
= nconnections
;
112 resume_db_done (void)
116 for (i
= 0; i
< cache_db_size
; i
++)
119 free (cache_db
[i
].id
);
120 if (cache_db
[i
].data
)
121 free (cache_db
[i
].data
);