Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/libtest/lib1512.c
2066 views
1
/***************************************************************************
2
* _ _ ____ _
3
* Project ___| | | | _ \| |
4
* / __| | | | |_) | |
5
* | (__| |_| | _ <| |___
6
* \___|\___/|_| \_\_____|
7
*
8
* Copyright (C) Linus Nielsen Feltzing <[email protected]>
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.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
* SPDX-License-Identifier: curl
22
*
23
***************************************************************************/
24
25
/*
26
* Use global DNS cache (while deprecated it should still work), populate it
27
* with CURLOPT_RESOLVE in the first request and then make sure a subsequent
28
* easy transfer finds and uses the populated stuff.
29
*/
30
31
#include "test.h"
32
33
#include "memdebug.h"
34
35
#define NUM_HANDLES 2
36
37
CURLcode test(char *URL)
38
{
39
CURLcode res = CURLE_OK;
40
CURL *curl[NUM_HANDLES] = {NULL, NULL};
41
char *port = libtest_arg3;
42
char *address = libtest_arg2;
43
char dnsentry[256];
44
struct curl_slist *slist = NULL;
45
int i;
46
char target_url[256];
47
(void)URL; /* URL is setup in the code */
48
49
if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
50
curl_mfprintf(stderr, "curl_global_init() failed\n");
51
return TEST_ERR_MAJOR_BAD;
52
}
53
54
curl_msnprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",
55
port, address);
56
curl_mprintf("%s\n", dnsentry);
57
slist = curl_slist_append(slist, dnsentry);
58
59
/* get NUM_HANDLES easy handles */
60
for(i = 0; i < NUM_HANDLES; i++) {
61
/* get an easy handle */
62
easy_init(curl[i]);
63
/* specify target */
64
curl_msnprintf(target_url, sizeof(target_url),
65
"http://server.example.curl:%s/path/1512%04i",
66
port, i + 1);
67
target_url[sizeof(target_url) - 1] = '\0';
68
easy_setopt(curl[i], CURLOPT_URL, target_url);
69
/* go verbose */
70
easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
71
/* include headers */
72
easy_setopt(curl[i], CURLOPT_HEADER, 1L);
73
74
easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
75
}
76
77
/* make the first one populate the GLOBAL cache */
78
easy_setopt(curl[0], CURLOPT_RESOLVE, slist);
79
80
/* run NUM_HANDLES transfers */
81
for(i = 0; (i < NUM_HANDLES) && !res; i++) {
82
res = curl_easy_perform(curl[i]);
83
if(res)
84
goto test_cleanup;
85
}
86
87
test_cleanup:
88
89
curl_easy_cleanup(curl[0]);
90
curl_easy_cleanup(curl[1]);
91
curl_slist_free_all(slist);
92
curl_global_cleanup();
93
94
return res;
95
}
96
97