lib1512.c 2.8 KB

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