multi: add multi->proto_hash, a key-value store for protocol data

- add `Curl_hash_add2()` that passes a destructor function for
  the element added. Call element destructor instead of hash
  destructor if present.
- multi: add `proto_hash` for protocol related information,
  remove `struct multi_ssl_backend_data`.
- openssl: use multi->proto_hash to keep x509 shared store
- schannel: use multi->proto_hash to keep x509 shared store
- vtls: remove Curl_free_multi_ssl_backend_data() and its
  equivalents in the TLS backends

Closes #13345
This commit is contained in:
Stefan Eissing 2024-04-11 12:34:40 +02:00 committed by Daniel Stenberg
parent 74e0bb1e7a
commit e101a7a8b0
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
17 changed files with 191 additions and 132 deletions

View file

@ -370,6 +370,17 @@ static void sh_init(struct Curl_hash *hash, size_t hashsize)
sh_freeentry);
}
/* multi->proto_hash destructor. Should never be called as elements
* MUST be added with their own destructor */
static void ph_freeentry(void *p)
{
(void)p;
/* Will always be FALSE. Cannot use a 0 assert here since compilers
* are not in agreement if they then want a NORETURN attribute or
* not. *sigh* */
DEBUGASSERT(p == NULL);
}
/*
* multi_addmsg()
*
@ -396,6 +407,9 @@ struct Curl_multi *Curl_multi_handle(size_t hashsize, /* socket hash */
sh_init(&multi->sockhash, hashsize);
Curl_hash_init(&multi->proto_hash, 23,
Curl_hash_str, Curl_str_key_compare, ph_freeentry);
if(Curl_conncache_init(&multi->conn_cache, chashsize))
goto error;
@ -431,6 +445,7 @@ struct Curl_multi *Curl_multi_handle(size_t hashsize, /* socket hash */
error:
sockhash_destroy(&multi->sockhash);
Curl_hash_destroy(&multi->proto_hash);
Curl_hash_destroy(&multi->hostcache);
Curl_conncache_destroy(&multi->conn_cache);
free(multi);
@ -2856,6 +2871,7 @@ CURLMcode curl_multi_cleanup(struct Curl_multi *multi)
Curl_conncache_close_all_connections(&multi->conn_cache);
sockhash_destroy(&multi->sockhash);
Curl_hash_destroy(&multi->proto_hash);
Curl_conncache_destroy(&multi->conn_cache);
Curl_hash_destroy(&multi->hostcache);
Curl_psl_destroy(&multi->psl);
@ -2869,10 +2885,6 @@ CURLMcode curl_multi_cleanup(struct Curl_multi *multi)
#endif
#endif
#ifdef USE_SSL
Curl_free_multi_ssl_backend_data(multi->ssl_backend_data);
#endif
multi_xfer_bufs_free(multi);
free(multi);