lib1512.c
Go to the documentation of this file.
1 /***************************************************************************
2  * _ _ ____ _
3  * Project ___| | | | _ \| |
4  * / __| | | | |_) | |
5  * | (__| |_| | _ <| |___
6  * \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 2013 - 2017, 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 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 
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 
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 
48  fprintf(stderr, "curl_global_init() failed\n");
49  return TEST_ERR_MAJOR_BAD;
50  }
51 
52  snprintf(dnsentry, sizeof(dnsentry), "server.example.curl:%s:%s",
53  port, address);
54  printf("%s\n", dnsentry);
55  slist = curl_slist_append(slist, dnsentry);
56 
57  /* get NUM_HANDLES easy handles */
58  for(i = 0; i < NUM_HANDLES; i++) {
59  /* get an easy handle */
60  easy_init(curl[i]);
61  /* specify target */
62  snprintf(target_url, sizeof(target_url),
63  "http://server.example.curl:%s/path/1512%04i",
64  port, i + 1);
65  target_url[sizeof(target_url) - 1] = '\0';
66  easy_setopt(curl[i], CURLOPT_URL, target_url);
67  /* go verbose */
68  easy_setopt(curl[i], CURLOPT_VERBOSE, 1L);
69  /* include headers */
70  easy_setopt(curl[i], CURLOPT_HEADER, 1L);
71 
72  easy_setopt(curl[i], CURLOPT_DNS_USE_GLOBAL_CACHE, 1L);
73  }
74 
75  /* make the first one populate the GLOBAL cache */
76  easy_setopt(curl[0], CURLOPT_RESOLVE, slist);
77 
78  /* run NUM_HANDLES transfers */
79  for(i = 0; (i < NUM_HANDLES) && !res; i++)
80  res = curl_easy_perform(curl[i]);
81 
82 test_cleanup:
83 
84  curl_easy_cleanup(curl[0]);
85  curl_easy_cleanup(curl[1]);
86  curl_slist_free_all(slist);
88 
89  return res;
90 }
91 
#define NUM_HANDLES
Definition: lib1512.c:33
int test(char *URL)
Definition: lib1512.c:35
#define easy_setopt(A, B, C)
Definition: test.h:190
static int res
unsigned int i
Definition: unit1303.c:79
#define TEST_ERR_MAJOR_BAD
Definition: test.h:85
char * libtest_arg2
Definition: first.c:75
CURL_EXTERN struct curl_slist * curl_slist_append(struct curl_slist *, const char *)
Definition: slist.c:89
#define printf
Definition: curl_printf.h:40
#define easy_init(A)
Definition: test.h:145
CURL_EXTERN void curl_easy_cleanup(CURL *curl)
Definition: curl.h:455
static unsigned short port
Definition: sockfilt.c:137
char * libtest_arg3
Definition: first.c:76
CURL_EXTERN CURLcode curl_global_init(long flags)
curl_global_init() globally initializes curl given a bitwise set of the different features of what to...
Definition: easy.c:271
void CURL
Definition: curl.h:102
#define fprintf
Definition: curl_printf.h:41
#define snprintf
Definition: curl_printf.h:42
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
#define CURL_GLOBAL_ALL
Definition: curl.h:2519
static CURL * curl
Definition: sessioninfo.c:35
CURL_EXTERN void curl_slist_free_all(struct curl_slist *)
Definition: slist.c:129
CURL_EXTERN CURLcode curl_easy_perform(CURL *curl)


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