1 /* resume.c --- Handle the details of TLS session resumption.
2 * Copyright (C) 2002, 2003 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 2 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 /* Note: only use syslog to report errors in this file. */
24 /* Get Shishid stuff. */
35 static CACHE
*cache_db
;
36 static size_t cache_db_ptr
= 0;
37 static size_t cache_db_size
= 0;
40 resume_db_store (void *dbf
, gnutls_datum key
, gnutls_datum data
)
42 if (cache_db_size
== 0)
45 cache_db
[cache_db_ptr
].id
= xrealloc (cache_db
[cache_db_ptr
].id
, key
.size
);
46 memcpy (cache_db
[cache_db_ptr
].id
, key
.data
, key
.size
);
47 cache_db
[cache_db_ptr
].id_size
= key
.size
;
49 cache_db
[cache_db_ptr
].data
= xrealloc (cache_db
[cache_db_ptr
].data
,
51 memcpy (cache_db
[cache_db_ptr
].data
, data
.data
, data
.size
);
52 cache_db
[cache_db_ptr
].data_size
= data
.size
;
55 cache_db_ptr
%= cache_db_size
;
61 resume_db_fetch (void *dbf
, gnutls_datum key
)
63 gnutls_datum res
= { NULL
, 0 };
66 for (i
= 0; i
< cache_db_size
; i
++)
67 if (key
.size
== cache_db
[i
].id_size
&&
68 memcmp (key
.data
, cache_db
[i
].id
, key
.size
) == 0)
70 res
.size
= cache_db
[i
].data_size
;
72 res
.data
= gnutls_malloc (res
.size
);
76 memcpy (res
.data
, cache_db
[i
].data
, res
.size
);
85 resume_db_delete (void *dbf
, gnutls_datum key
)
89 for (i
= 0; i
< cache_db_size
; i
++)
90 if (key
.size
== cache_db
[i
].id_size
&&
91 memcmp (key
.data
, cache_db
[i
].id
, key
.size
) == 0)
93 cache_db
[i
].id_size
= 0;
94 cache_db
[i
].data_size
= 0;
103 resume_db_init (size_t nconnections
)
106 cache_db
= xcalloc (nconnections
, sizeof (*cache_db
));
107 cache_db_size
= nconnections
;
111 resume_db_done (void)
115 for (i
= 0; i
< cache_db_size
; i
++)
118 free (cache_db
[i
].id
);
119 if (cache_db
[i
].data
)
120 free (cache_db
[i
].data
);