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