}
}
-struct curl_hash *
-Curl_hash_alloc(int slots,
- hash_function hfunc,
- comp_function comparator,
- curl_hash_dtor dtor)
-{
- struct curl_hash *h;
-
- if(!slots || !hfunc || !comparator ||!dtor) {
- return NULL; /* failure */
- }
-
- h = malloc(sizeof(struct curl_hash));
- if(h) {
- if(Curl_hash_init(h, slots, hfunc, comparator, dtor)) {
- /* failure */
- free(h);
- h = NULL;
- }
- }
-
- return h;
-}
-
-
-
static struct curl_hash_element *
mk_hash_element(const void *key, size_t key_len, const void *p)
{
}
}
-void
-Curl_hash_destroy(struct curl_hash *h)
-{
- if(!h)
- return;
-
- Curl_hash_clean(h);
-
- free(h);
-}
-
size_t Curl_hash_str(void* key, size_t key_length, size_t slots_num)
{
const char* key_str = (const char *) key;
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
comp_function comparator,
curl_hash_dtor dtor);
-struct curl_hash *Curl_hash_alloc(int slots,
- hash_function hfunc,
- comp_function comparator,
- curl_hash_dtor dtor);
-
void *Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p);
int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len);
void *Curl_hash_pick(struct curl_hash *, void * key, size_t key_len);
void Curl_hash_clean(struct curl_hash *h);
void Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
int (*comp)(void *, void *));
-void Curl_hash_destroy(struct curl_hash *h);
-
size_t Curl_hash_str(void* key, size_t key_length, size_t slots_num);
size_t Curl_str_key_compare(void*k1, size_t key1_len, void*k2,
size_t key2_len);
}
/*
- * Curl_mk_dnscache() creates a new DNS cache and returns the handle for it.
+ * Curl_mk_dnscache() inits a new DNS cache and returns success/failure.
*/
-struct curl_hash *Curl_mk_dnscache(void)
+int Curl_mk_dnscache(struct curl_hash *hash)
{
- return Curl_hash_alloc(7, Curl_hash_str, Curl_str_key_compare, freednsentry);
+ return Curl_hash_init(hash, 7, Curl_hash_str, Curl_str_key_compare,
+ freednsentry);
}
/*
/* for debugging purposes only: */
void Curl_scan_cache_used(void *user, void *ptr);
-/* make a new dns cache and return the handle */
-struct curl_hash *Curl_mk_dnscache(void);
+/* init a new dns cache and return success */
+int Curl_mk_dnscache(struct curl_hash *hash);
/* prune old entries from the DNS cache */
void Curl_hostcache_prune(struct SessionHandle *data);
multi->type = CURL_MULTI_HANDLE;
- multi->hostcache = Curl_mk_dnscache();
- if(!multi->hostcache)
+ if(Curl_mk_dnscache(&multi->hostcache))
goto error;
if(sh_init(&multi->sockhash, hashsize))
error:
Curl_hash_clean(&multi->sockhash);
- Curl_hash_destroy(multi->hostcache);
- multi->hostcache = NULL;
+ Curl_hash_clean(&multi->hostcache);
Curl_conncache_destroy(&multi->conn_cache);
Curl_close(multi->closure_handle);
multi->closure_handle = NULL;
easy handle's one is currently not set. */
else if(!data->dns.hostcache ||
(data->dns.hostcachetype == HCACHE_NONE)) {
- data->dns.hostcache = multi->hostcache;
+ data->dns.hostcache = &multi->hostcache;
data->dns.hostcachetype = HCACHE_MULTI;
}
sigpipe_ignore(multi->closure_handle, &pipe_st);
restore_pipe = TRUE;
- multi->closure_handle->dns.hostcache = multi->hostcache;
+ multi->closure_handle->dns.hostcache = &multi->hostcache;
Curl_hostcache_clean(multi->closure_handle,
multi->closure_handle->dns.hostcache);
data = nextdata;
}
- Curl_hash_destroy(multi->hostcache);
+ Curl_hash_clean(&multi->hostcache);
/* Free the blacklists by setting them to NULL */
Curl_pipeline_set_site_blacklist(NULL, &multi->pipelining_site_bl);
void *socket_userp;
/* Hostname cache */
- struct curl_hash *hostcache;
+ struct curl_hash hostcache;
/* timetree points to the splay-tree of time nodes to figure out expire
times of all currently set timers */
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
if(share)
share->specifier |= (1<<CURL_LOCK_DATA_SHARE);
+ if(Curl_mk_dnscache(&share->hostcache)) {
+ free(share);
+ return NULL;
+ }
+
return share;
}
share->specifier |= (1<<type);
switch( type ) {
case CURL_LOCK_DATA_DNS:
- if(!share->hostcache) {
- share->hostcache = Curl_mk_dnscache();
- if(!share->hostcache)
- res = CURLSHE_NOMEM;
- }
break;
case CURL_LOCK_DATA_COOKIE:
share->specifier &= ~(1<<type);
switch( type ) {
case CURL_LOCK_DATA_DNS:
- if(share->hostcache) {
- Curl_hash_destroy(share->hostcache);
- share->hostcache = NULL;
- }
break;
case CURL_LOCK_DATA_COOKIE:
return CURLSHE_IN_USE;
}
- if(share->hostcache) {
- Curl_hash_destroy(share->hostcache);
- share->hostcache = NULL;
- }
+ Curl_hash_clean(&share->hostcache);
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
Curl_cookie_cleanup(share->cookies);
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
curl_unlock_function unlockfunc;
void *clientdata;
- struct curl_hash *hostcache;
+ struct curl_hash hostcache;
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
struct CookieInfo *cookies;
#endif
data->share->dirty++;
- if(data->share->hostcache) {
+ if(data->share->specifier & (1<< CURL_LOCK_DATA_DNS)) {
/* use shared host cache */
- data->dns.hostcache = data->share->hostcache;
+ data->dns.hostcache = &data->share->hostcache;
data->dns.hostcachetype = HCACHE_SHARED;
}
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
#include "memdebug.h" /* LAST include file */
static struct SessionHandle *data;
-static struct curl_hash *hp;
+static struct curl_hash hp;
static char *data_key;
static struct Curl_dns_entry *data_node;
static CURLcode unit_setup( void )
{
+ int rc;
data = curl_easy_init();
if (!data)
return CURLE_OUT_OF_MEMORY;
- hp = Curl_mk_dnscache();
- if(!hp) {
+ rc = Curl_mk_dnscache(&hp);
+ if(rc) {
curl_easy_cleanup(data);
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
free(data_node);
}
free(data_key);
- Curl_hash_destroy(hp);
+ Curl_hash_clean(&hp);
curl_easy_cleanup(data);
curl_global_cleanup();
key_len = strlen(data_key);
data_node->inuse = 1; /* hash will hold the reference */
- nodep = Curl_hash_add(hp, data_key, key_len+1, data_node);
+ nodep = Curl_hash_add(&hp, data_key, key_len+1, data_node);
abort_unless(nodep, "insertion into hash failed");
/* Freeing will now be done by Curl_hash_destroy */
data_node = NULL;