lib1512.c 2.9 KB

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