2008-10-26 04:03:29 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "test.h"
|
|
|
|
|
2008-10-30 14:45:25 +01:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
# include <netinet/in.h>
|
|
|
|
#endif
|
2008-10-26 22:40:20 +01:00
|
|
|
#ifdef HAVE_NETDB_H
|
2008-10-30 14:45:25 +01:00
|
|
|
# include <netdb.h>
|
2008-10-26 22:40:20 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
2008-10-30 14:45:25 +01:00
|
|
|
# include <arpa/inet.h>
|
2008-10-26 22:40:20 +01:00
|
|
|
#endif
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-26 22:40:20 +01:00
|
|
|
#define ENABLE_CURLX_PRINTF
|
|
|
|
#include "curlx.h"
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-26 22:40:20 +01:00
|
|
|
#include "hash.h"
|
|
|
|
#include "hostip.h"
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-26 22:40:20 +01:00
|
|
|
#include "memory.h"
|
|
|
|
#include "memdebug.h"
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-27 21:01:58 +01:00
|
|
|
/* This source file is used for test # 558 and 559 */
|
2008-10-27 04:00:47 +01:00
|
|
|
|
2008-10-27 15:02:50 +01:00
|
|
|
/*
|
|
|
|
* This hacky test bypasses the library external API,
|
|
|
|
* using internal only libcurl functions. So don't be
|
|
|
|
* surprised if we cannot run it when the library has
|
|
|
|
* been built with hidden symbols, exporting only the
|
|
|
|
* ones in the public API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(CURL_HIDDEN_SYMBOLS)
|
|
|
|
|
2008-10-27 21:01:58 +01:00
|
|
|
#ifdef LIB559
|
2008-10-27 04:00:47 +01:00
|
|
|
static Curl_addrinfo *fake_ai(void)
|
|
|
|
{
|
|
|
|
Curl_addrinfo *ai;
|
|
|
|
int ss_size;
|
|
|
|
|
|
|
|
ss_size = sizeof (struct sockaddr_in);
|
|
|
|
|
|
|
|
if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if((ai->ai_canonname = strdup("dummy")) == NULL) {
|
|
|
|
free(ai);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
|
|
|
|
free(ai->ai_canonname);
|
|
|
|
free(ai);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ai->ai_family = AF_INET;
|
|
|
|
ai->ai_addrlen = ss_size;
|
|
|
|
|
|
|
|
return ai;
|
|
|
|
}
|
2008-10-27 21:01:58 +01:00
|
|
|
#endif /* LIB559 */
|
2008-10-27 04:00:47 +01:00
|
|
|
|
|
|
|
|
2008-10-26 22:40:20 +01:00
|
|
|
int test(char *URL)
|
2008-10-26 04:03:29 +01:00
|
|
|
{
|
2008-10-31 15:46:48 +01:00
|
|
|
CURL *easyh = NULL;
|
|
|
|
struct curl_hash *hp = NULL;
|
|
|
|
int result = 0;
|
2008-10-26 22:40:20 +01:00
|
|
|
|
2008-10-27 15:02:50 +01:00
|
|
|
if(!strcmp(URL, "check")) {
|
|
|
|
/* test harness script verifying if this test can run */
|
|
|
|
return 0; /* sure, run this! */
|
|
|
|
}
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-26 22:40:20 +01:00
|
|
|
easyh = curl_easy_init();
|
|
|
|
if(!easyh) {
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "easy handle init failed\n");
|
2008-10-31 15:46:48 +01:00
|
|
|
result = TEST_ERR_MAJOR_BAD;
|
|
|
|
goto cleanup;
|
2008-10-26 04:03:29 +01:00
|
|
|
}
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "easy handle init OK\n");
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "creating hash...\n");
|
2008-10-26 22:40:20 +01:00
|
|
|
hp = Curl_mk_dnscache();
|
|
|
|
if(!hp) {
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "hash creation failed\n");
|
2008-10-31 15:46:48 +01:00
|
|
|
result = TEST_ERR_MAJOR_BAD;
|
|
|
|
goto cleanup;
|
2008-10-26 04:03:29 +01:00
|
|
|
}
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "hash creation OK\n");
|
2008-10-26 04:03:29 +01:00
|
|
|
|
2008-10-26 22:40:20 +01:00
|
|
|
/**/
|
2008-10-27 21:01:58 +01:00
|
|
|
#ifdef LIB559
|
|
|
|
{
|
|
|
|
char *data_key;
|
|
|
|
struct Curl_dns_entry *data_node;
|
|
|
|
struct Curl_dns_entry *nodep;
|
|
|
|
size_t key_len;
|
|
|
|
|
|
|
|
data_key = aprintf("%s:%d", "dummy", 0);
|
|
|
|
if(!data_key) {
|
|
|
|
fprintf(stdout, "data key creation failed\n");
|
2008-10-31 15:46:48 +01:00
|
|
|
result = TEST_ERR_MAJOR_BAD;
|
|
|
|
goto cleanup;
|
2008-10-27 21:01:58 +01:00
|
|
|
}
|
|
|
|
key_len = strlen(data_key);
|
|
|
|
|
|
|
|
data_node = calloc(1, sizeof(struct Curl_dns_entry));
|
|
|
|
if(!data_node) {
|
|
|
|
fprintf(stdout, "data node creation failed\n");
|
2008-10-31 15:46:48 +01:00
|
|
|
result = TEST_ERR_MAJOR_BAD;
|
|
|
|
free(data_key);
|
|
|
|
goto cleanup;
|
2008-10-27 21:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
data_node->addr = fake_ai();
|
|
|
|
if(!data_node->addr) {
|
|
|
|
fprintf(stdout, "actual data creation failed\n");
|
2008-10-31 15:46:48 +01:00
|
|
|
result = TEST_ERR_MAJOR_BAD;
|
|
|
|
free(data_node);
|
|
|
|
free(data_key);
|
|
|
|
goto cleanup;
|
2008-10-27 21:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
nodep = Curl_hash_add(hp, data_key, key_len+1, (void *)data_node);
|
|
|
|
if(!nodep) {
|
|
|
|
fprintf(stdout, "insertion into hash failed\n");
|
2008-10-31 15:46:48 +01:00
|
|
|
result = TEST_ERR_MAJOR_BAD;
|
|
|
|
Curl_freeaddrinfo(data_node->addr);
|
|
|
|
free(data_node);
|
|
|
|
free(data_key);
|
|
|
|
goto cleanup;
|
2008-10-27 21:01:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
free(data_key);
|
2008-10-26 04:03:29 +01:00
|
|
|
}
|
2008-10-27 21:01:58 +01:00
|
|
|
#endif /* LIB559 */
|
2008-10-26 22:40:20 +01:00
|
|
|
/**/
|
|
|
|
|
2008-10-31 15:46:48 +01:00
|
|
|
cleanup:
|
|
|
|
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "destroying hash...\n");
|
2008-10-26 22:40:20 +01:00
|
|
|
Curl_hash_destroy(hp);
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "hash destruction OK\n");
|
2008-10-26 22:40:20 +01:00
|
|
|
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "destroying easy handle...\n");
|
2008-10-26 22:40:20 +01:00
|
|
|
curl_easy_cleanup(easyh);
|
2008-10-27 15:02:50 +01:00
|
|
|
fprintf(stdout, "easy handle destruction OK\n");
|
2008-10-26 22:40:20 +01:00
|
|
|
|
|
|
|
curl_global_cleanup();
|
2008-10-26 04:03:29 +01:00
|
|
|
|
|
|
|
return 0; /* OK */
|
|
|
|
}
|
2008-10-26 22:40:20 +01:00
|
|
|
|
2008-10-27 15:02:50 +01:00
|
|
|
|
|
|
|
#else /* !defined(CURL_HIDDEN_SYMBOLS) */
|
|
|
|
|
|
|
|
|
|
|
|
int test(char *URL)
|
|
|
|
{
|
|
|
|
(void)URL;
|
|
|
|
fprintf(stdout, "libcurl built with hidden symbols");
|
|
|
|
return 1; /* skip test */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* !defined(CURL_HIDDEN_SYMBOLS) */
|