lib536.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  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. #include "test.h"
  25. #include "memdebug.h"
  26. #define WITH_PROXY "http://usingproxy.com/"
  27. #define WITHOUT_PROXY libtest_arg2
  28. static void proxystat(CURL *curl)
  29. {
  30. long wasproxy;
  31. if(!curl_easy_getinfo(curl, CURLINFO_USED_PROXY, &wasproxy)) {
  32. printf("This %sthe proxy\n", wasproxy ? "used ":
  33. "DID NOT use ");
  34. }
  35. }
  36. CURLcode test(char *URL)
  37. {
  38. CURLcode res = CURLE_OK;
  39. CURL *curl;
  40. struct curl_slist *host = NULL;
  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. curl = curl_easy_init();
  46. if(!curl) {
  47. fprintf(stderr, "curl_easy_init() failed\n");
  48. curl_global_cleanup();
  49. return TEST_ERR_MAJOR_BAD;
  50. }
  51. host = curl_slist_append(NULL, libtest_arg3);
  52. if(!host)
  53. goto test_cleanup;
  54. test_setopt(curl, CURLOPT_RESOLVE, host);
  55. test_setopt(curl, CURLOPT_PROXY, URL);
  56. test_setopt(curl, CURLOPT_URL, WITH_PROXY);
  57. test_setopt(curl, CURLOPT_NOPROXY, "goingdirect.com");
  58. test_setopt(curl, CURLOPT_VERBOSE, 1L);
  59. res = curl_easy_perform(curl);
  60. if(!res) {
  61. proxystat(curl);
  62. test_setopt(curl, CURLOPT_URL, WITHOUT_PROXY);
  63. res = curl_easy_perform(curl);
  64. if(!res)
  65. proxystat(curl);
  66. }
  67. test_cleanup:
  68. curl_easy_cleanup(curl);
  69. curl_slist_free_all(host);
  70. curl_global_cleanup();
  71. return res;
  72. }