2011-03-10 18:48:02 +08:00
|
|
|
/***************************************************************************
|
2011-03-05 06:32:58 +08:00
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2017-09-10 05:55:08 +08:00
|
|
|
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2016-02-03 07:19:02 +08:00
|
|
|
* are also available at https://curl.haxx.se/docs/copyright.html.
|
2011-03-10 18:48:02 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2011-05-21 19:22:11 +08:00
|
|
|
#include "curlcheck.h"
|
2011-03-05 06:32:58 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
# include <netdb.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
#include "curlx.h"
|
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "hash.h"
|
|
|
|
#include "hostip.h"
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2013-01-04 09:50:28 +08:00
|
|
|
#include "memdebug.h" /* LAST include file */
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2016-06-21 21:47:12 +08:00
|
|
|
static struct Curl_easy *data;
|
2015-05-12 15:46:53 +08:00
|
|
|
static struct curl_hash hp;
|
2011-03-05 06:32:58 +08:00
|
|
|
static char *data_key;
|
|
|
|
static struct Curl_dns_entry *data_node;
|
|
|
|
|
2016-04-04 02:28:34 +08:00
|
|
|
static CURLcode unit_setup(void)
|
2011-03-05 06:32:58 +08:00
|
|
|
{
|
2015-05-12 15:46:53 +08:00
|
|
|
int rc;
|
2011-03-05 06:32:58 +08:00
|
|
|
data = curl_easy_init();
|
2016-04-03 22:21:10 +08:00
|
|
|
if(!data)
|
2011-03-05 06:32:58 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
|
2015-05-12 15:46:53 +08:00
|
|
|
rc = Curl_mk_dnscache(&hp);
|
|
|
|
if(rc) {
|
2011-03-05 06:32:58 +08:00
|
|
|
curl_easy_cleanup(data);
|
|
|
|
curl_global_cleanup();
|
|
|
|
return CURLE_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return CURLE_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-04 02:28:34 +08:00
|
|
|
static void unit_stop(void)
|
2011-03-05 06:32:58 +08:00
|
|
|
{
|
2016-04-03 22:21:10 +08:00
|
|
|
if(data_node) {
|
2011-03-05 06:32:58 +08:00
|
|
|
Curl_freeaddrinfo(data_node->addr);
|
|
|
|
free(data_node);
|
|
|
|
}
|
2015-03-12 00:41:01 +08:00
|
|
|
free(data_key);
|
2015-05-03 02:49:55 +08:00
|
|
|
Curl_hash_destroy(&hp);
|
2011-03-05 06:32:58 +08:00
|
|
|
|
|
|
|
curl_easy_cleanup(data);
|
|
|
|
curl_global_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
static Curl_addrinfo *fake_ai(void)
|
|
|
|
{
|
2011-03-20 23:03:25 +08:00
|
|
|
static Curl_addrinfo *ai;
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2016-12-14 08:29:44 +08:00
|
|
|
ai = calloc(1, sizeof(Curl_addrinfo));
|
|
|
|
if(!ai)
|
2011-03-20 23:03:25 +08:00
|
|
|
return NULL;
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2016-12-14 08:29:44 +08:00
|
|
|
ai->ai_canonname = strdup("dummy");
|
|
|
|
if(!ai->ai_canonname) {
|
2011-03-20 23:03:25 +08:00
|
|
|
free(ai);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2017-05-05 17:44:22 +08:00
|
|
|
ai->ai_addr = calloc(1, sizeof(struct sockaddr_in));
|
2016-12-14 08:29:44 +08:00
|
|
|
if(!ai->ai_addr) {
|
2011-03-20 23:03:25 +08:00
|
|
|
free(ai->ai_canonname);
|
|
|
|
free(ai);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
ai->ai_family = AF_INET;
|
2017-05-05 17:44:22 +08:00
|
|
|
ai->ai_addrlen = sizeof(struct sockaddr_in);
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
return ai;
|
2011-03-05 06:32:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static CURLcode create_node(void)
|
|
|
|
{
|
2011-03-20 23:03:25 +08:00
|
|
|
data_key = aprintf("%s:%d", "dummy", 0);
|
2016-04-03 22:21:10 +08:00
|
|
|
if(!data_key)
|
2011-03-20 23:03:25 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
data_node = calloc(1, sizeof(struct Curl_dns_entry));
|
2016-04-03 22:21:10 +08:00
|
|
|
if(!data_node)
|
2011-03-20 23:03:25 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
data_node->addr = fake_ai();
|
2016-04-03 22:21:10 +08:00
|
|
|
if(!data_node->addr)
|
2011-03-20 23:03:25 +08:00
|
|
|
return CURLE_OUT_OF_MEMORY;
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
return CURLE_OK;
|
2011-03-05 06:32:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
UNITTEST_START
|
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
struct Curl_dns_entry *nodep;
|
|
|
|
size_t key_len;
|
2011-03-05 06:32:58 +08:00
|
|
|
|
2011-03-20 23:03:25 +08:00
|
|
|
/* Test 1305 exits without adding anything to the hash */
|
2016-04-03 22:21:10 +08:00
|
|
|
if(strcmp(arg, "1305") != 0) {
|
2011-03-20 23:03:25 +08:00
|
|
|
CURLcode rc = create_node();
|
|
|
|
abort_unless(rc == CURLE_OK, "data node creation failed");
|
|
|
|
key_len = strlen(data_key);
|
2011-03-05 07:13:12 +08:00
|
|
|
|
2015-03-17 16:09:43 +08:00
|
|
|
data_node->inuse = 1; /* hash will hold the reference */
|
2017-09-10 05:55:08 +08:00
|
|
|
nodep = Curl_hash_add(&hp, data_key, key_len + 1, data_node);
|
2011-03-20 23:03:25 +08:00
|
|
|
abort_unless(nodep, "insertion into hash failed");
|
|
|
|
/* Freeing will now be done by Curl_hash_destroy */
|
|
|
|
data_node = NULL;
|
|
|
|
}
|
2011-03-05 06:32:58 +08:00
|
|
|
|
|
|
|
UNITTEST_STOP
|