cmCurl.cxx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2015 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmCurl.h"
  11. #include "cmSystemTools.h"
  12. #define check_curl_result(result, errstr) \
  13. if (result != CURLE_OK) \
  14. { \
  15. e += e.empty()? "" : "\n"; \
  16. e += errstr; \
  17. e += ::curl_easy_strerror(result); \
  18. }
  19. //----------------------------------------------------------------------------
  20. std::string cmCurlSetCAInfo(::CURL *curl, const char* cafile)
  21. {
  22. std::string e;
  23. if(cafile && *cafile)
  24. {
  25. ::CURLcode res = ::curl_easy_setopt(curl, CURLOPT_CAINFO, cafile);
  26. check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
  27. }
  28. #if !defined(CMAKE_USE_SYSTEM_CURL) && \
  29. !defined(_WIN32) && !defined(__APPLE__) && \
  30. !defined(CURL_CA_BUNDLE) && !defined(CURL_CA_PATH)
  31. # define CMAKE_CAFILE_FEDORA "/etc/pki/tls/certs/ca-bundle.crt"
  32. else if(cmSystemTools::FileExists(CMAKE_CAFILE_FEDORA, true))
  33. {
  34. ::CURLcode res =
  35. ::curl_easy_setopt(curl, CURLOPT_CAINFO, CMAKE_CAFILE_FEDORA);
  36. check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
  37. }
  38. # undef CMAKE_CAFILE_FEDORA
  39. else
  40. {
  41. # define CMAKE_CAFILE_COMMON "/etc/ssl/certs/ca-certificates.crt"
  42. if(cmSystemTools::FileExists(CMAKE_CAFILE_COMMON, true))
  43. {
  44. ::CURLcode res =
  45. ::curl_easy_setopt(curl, CURLOPT_CAINFO, CMAKE_CAFILE_COMMON);
  46. check_curl_result(res, "Unable to set TLS/SSL Verify CAINFO: ");
  47. }
  48. # undef CMAKE_CAFILE_COMMON
  49. # define CMAKE_CAPATH_COMMON "/etc/ssl/certs"
  50. if(cmSystemTools::FileIsDirectory(CMAKE_CAPATH_COMMON))
  51. {
  52. ::CURLcode res =
  53. ::curl_easy_setopt(curl, CURLOPT_CAPATH, CMAKE_CAPATH_COMMON);
  54. check_curl_result(res, "Unable to set TLS/SSL Verify CAPATH: ");
  55. }
  56. # undef CMAKE_CAPATH_COMMON
  57. }
  58. #endif
  59. return e;
  60. }