unit1305.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at https://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22 #include "curlcheck.h"
23 
24 #ifdef HAVE_NETINET_IN_H
25 # include <netinet/in.h>
26 #endif
27 #ifdef HAVE_NETDB_H
28 # include <netdb.h>
29 #endif
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
32 #endif
33 
34 #define ENABLE_CURLX_PRINTF
35 #include "curlx.h"
36 
37 #include "hash.h"
38 #include "hostip.h"
39 
40 #include "memdebug.h" /* LAST include file */
41 
42 static struct Curl_easy *data;
43 static struct curl_hash hp;
44 static char *data_key;
45 static struct Curl_dns_entry *data_node;
46 
47 static CURLcode unit_setup(void)
48 {
49  int rc;
50  data = curl_easy_init();
51  if(!data)
52  return CURLE_OUT_OF_MEMORY;
53 
54  rc = Curl_mk_dnscache(&hp);
55  if(rc) {
56  curl_easy_cleanup(data);
58  return CURLE_OUT_OF_MEMORY;
59  }
60  return CURLE_OK;
61 }
62 
63 static void unit_stop(void)
64 {
65  if(data_node) {
66  Curl_freeaddrinfo(data_node->addr);
67  free(data_node);
68  }
69  free(data_key);
71 
72  curl_easy_cleanup(data);
74 }
75 
76 static Curl_addrinfo *fake_ai(void)
77 {
78  static Curl_addrinfo *ai;
79 
80  ai = calloc(1, sizeof(Curl_addrinfo));
81  if(!ai)
82  return NULL;
83 
84  ai->ai_canonname = strdup("dummy");
85  if(!ai->ai_canonname) {
86  free(ai);
87  return NULL;
88  }
89 
90  ai->ai_addr = calloc(1, sizeof(struct sockaddr_in));
91  if(!ai->ai_addr) {
92  free(ai->ai_canonname);
93  free(ai);
94  return NULL;
95  }
96 
97  ai->ai_family = AF_INET;
98  ai->ai_addrlen = sizeof(struct sockaddr_in);
99 
100  return ai;
101 }
102 
103 static CURLcode create_node(void)
104 {
105  data_key = aprintf("%s:%d", "dummy", 0);
106  if(!data_key)
107  return CURLE_OUT_OF_MEMORY;
108 
109  data_node = calloc(1, sizeof(struct Curl_dns_entry));
110  if(!data_node)
111  return CURLE_OUT_OF_MEMORY;
112 
113  data_node->addr = fake_ai();
114  if(!data_node->addr)
115  return CURLE_OUT_OF_MEMORY;
116 
117  return CURLE_OK;
118 }
119 
120 
122 
124  size_t key_len;
125 
126  /* Test 1305 exits without adding anything to the hash */
127  if(strcmp(arg, "1305") != 0) {
128  CURLcode rc = create_node();
129  abort_unless(rc == CURLE_OK, "data node creation failed");
130  key_len = strlen(data_key);
131 
132  data_node->inuse = 1; /* hash will hold the reference */
133  nodep = Curl_hash_add(&hp, data_key, key_len + 1, data_node);
134  abort_unless(nodep, "insertion into hash failed");
135  /* Freeing will now be done by Curl_hash_destroy */
136  data_node = NULL;
137  }
138 
#define free(ptr)
Definition: curl_memory.h:130
Definition: hash.h:46
#define UNITTEST_START
Definition: curlcheck.h:86
UNITTEST_START struct Curl_dns_entry * nodep
Definition: unit1305.c:123
char * ai_canonname
Definition: curl_addrinfo.h:57
#define strdup(ptr)
Definition: curl_memory.h:122
Definition: hostip.h:66
long inuse
Definition: hostip.h:71
CURLcode
Definition: curl.h:454
void Curl_freeaddrinfo(Curl_addrinfo *cahead)
Definition: curl_addrinfo.c:78
void Curl_hash_destroy(struct curl_hash *h)
Definition: hash.c:208
static Curl_addrinfo * fake_ai(void)
Definition: unit1305.c:76
static CURLcode unit_setup(void)
Definition: unit1305.c:47
static CURLcode create_node(void)
Definition: unit1305.c:103
#define abort_unless(expr, msg)
Definition: curlcheck.h:67
struct sockaddr * ai_addr
Definition: curl_addrinfo.h:58
int Curl_mk_dnscache(struct curl_hash *hash)
Definition: hostip.c:751
UNITTEST_START int rc
Definition: unit1301.c:31
CURL_EXTERN CURL * curl_easy_init(void)
Definition: easy.c:343
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
static struct Curl_dns_entry * data_node
Definition: unit1305.c:45
Definition: curl.h:455
#define UNITTEST_STOP
Definition: curlcheck.h:95
Curl_addrinfo * addr
Definition: hostip.h:67
static struct curl_hash hp
Definition: unit1305.c:43
size_t key_len
Definition: unit1305.c:124
#define aprintf
Definition: curl_printf.h:46
static struct Curl_easy * data
Definition: unit1305.c:42
curl_socklen_t ai_addrlen
Definition: curl_addrinfo.h:56
void * Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p)
Definition: hash.c:110
CURL_EXTERN void curl_global_cleanup(void)
curl_global_cleanup() globally cleanups curl, uses the value of "init_flags" to determine what needs ...
Definition: easy.c:312
static char * data_key
Definition: unit1305.c:44
#define calloc(nbelem, size)
Definition: curl_memory.h:126
static void unit_stop(void)
Definition: unit1305.c:63


rc_tagdetect_client
Author(s): Monika Florek-Jasinska , Raphael Schaller
autogenerated on Sat Feb 13 2021 03:42:16