| 1623 | // --------------------------------------------------------------------------- |
| 1624 | |
| 1625 | CurlFileHandle::CurlFileHandle(PJ_CONTEXT *ctx, const char *url, CURL *handle) |
| 1626 | : m_url(url), m_handle(handle) { |
| 1627 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_URL, m_url.c_str())); |
| 1628 | |
| 1629 | if (getenv("PROJ_CURL_VERBOSE")) |
| 1630 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_VERBOSE, 1)); |
| 1631 | |
| 1632 | // CURLOPT_SUPPRESS_CONNECT_HEADERS is defined in curl 7.54.0 or newer. |
| 1633 | #if LIBCURL_VERSION_NUM >= 0x073600 |
| 1634 | CHECK_RET(ctx, |
| 1635 | curl_easy_setopt(handle, CURLOPT_SUPPRESS_CONNECT_HEADERS, 1L)); |
| 1636 | #endif |
| 1637 | |
| 1638 | // Enable following redirections. Requires libcurl 7.10.1 at least. |
| 1639 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1)); |
| 1640 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10)); |
| 1641 | |
| 1642 | if (getenv("PROJ_UNSAFE_SSL")) { |
| 1643 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0L)); |
| 1644 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0L)); |
| 1645 | } |
| 1646 | |
| 1647 | #if defined(SSL_OPTIONS) |
| 1648 | // https://curl.se/libcurl/c/CURLOPT_SSL_OPTIONS.html |
| 1649 | auto ssl_options = static_cast<long>(SSL_OPTIONS); |
| 1650 | #if CURL_AT_LEAST_VERSION(7, 71, 0) |
| 1651 | if (pj_context_get_native_ca(ctx)) { |
| 1652 | ssl_options = ssl_options | CURLSSLOPT_NATIVE_CA; |
| 1653 | } |
| 1654 | #endif |
| 1655 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_SSL_OPTIONS, ssl_options)); |
| 1656 | #else |
| 1657 | #if CURL_AT_LEAST_VERSION(7, 71, 0) |
| 1658 | if (pj_context_get_native_ca(ctx)) { |
| 1659 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_SSL_OPTIONS, |
| 1660 | (long)CURLSSLOPT_NATIVE_CA)); |
| 1661 | } |
| 1662 | #endif |
| 1663 | #endif |
| 1664 | |
| 1665 | const auto ca_bundle_path = pj_context_get_bundle_path(ctx); |
| 1666 | if (!ca_bundle_path.empty()) { |
| 1667 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_CAINFO, |
| 1668 | ca_bundle_path.c_str())); |
| 1669 | } |
| 1670 | |
| 1671 | CHECK_RET(ctx, |
| 1672 | curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, m_szCurlErrBuf)); |
| 1673 | |
| 1674 | if (getenv("PROJ_NO_USERAGENT") == nullptr) { |
| 1675 | m_useragent = "PROJ " STR(PROJ_VERSION_MAJOR) "." STR( |
| 1676 | PROJ_VERSION_MINOR) "." STR(PROJ_VERSION_PATCH); |
| 1677 | const auto exeName = GetExecutableName(); |
| 1678 | if (!exeName.empty()) { |
| 1679 | m_useragent = exeName + " using " + m_useragent; |
| 1680 | } |
| 1681 | CHECK_RET(ctx, curl_easy_setopt(handle, CURLOPT_USERAGENT, |
| 1682 | m_useragent.data())); |
nothing calls this directly
no test coverage detected