diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2022-02-12 19:04:02 +0100 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2022-02-12 19:04:06 +0100 |
| commit | 0f4509430517b5fd5f411e4c47e51971cbdafce3 (patch) | |
| tree | 9f5e5e679159caa91fbcf2fae9563a15ba6a203f /src/filemanager.cpp | |
| parent | a9ce8aa28f0ccf775f238b2ca1bafca0c7616bcf (diff) | |
| download | PROJ-0f4509430517b5fd5f411e4c47e51971cbdafce3.tar.gz PROJ-0f4509430517b5fd5f411e4c47e51971cbdafce3.zip | |
proj.ini: add a 'ca_bundle_path' variable
Cf thread https://lists.osgeo.org/pipermail/gdal-dev/2022-February/thread.html#55391
Diffstat (limited to 'src/filemanager.cpp')
| -rw-r--r-- | src/filemanager.cpp | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/src/filemanager.cpp b/src/filemanager.cpp index 5bc99bc5..97fedaa2 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -1789,11 +1789,37 @@ void pj_load_ini(PJ_CONTEXT *ctx) { if (ctx->iniFileLoaded) return; + // Start reading environment variables that have priority over the + // .ini file + const char *proj_network = getenv("PROJ_NETWORK"); + if (proj_network && proj_network[0] != '\0') { + ctx->networking.enabled = ci_equal(proj_network, "ON") || + ci_equal(proj_network, "YES") || + ci_equal(proj_network, "TRUE"); + } else { + proj_network = nullptr; + } + const char *endpoint_from_env = getenv("PROJ_NETWORK_ENDPOINT"); if (endpoint_from_env && endpoint_from_env[0] != '\0') { ctx->endpoint = endpoint_from_env; } + // Custom path to SSL certificates. + const char *ca_bundle_path = getenv("PROJ_CURL_CA_BUNDLE"); + if (ca_bundle_path == nullptr) { + // Name of environment variable used by the curl binary + ca_bundle_path = getenv("CURL_CA_BUNDLE"); + } + if (ca_bundle_path == nullptr) { + // Name of environment variable used by the curl binary (tested + // after CURL_CA_BUNDLE + ca_bundle_path = getenv("SSL_CERT_FILE"); + } + if (ca_bundle_path != nullptr) { + ctx->ca_bundle_path = ca_bundle_path; + } + ctx->iniFileLoaded = true; auto file = std::unique_ptr<NS_PROJ::File>( reinterpret_cast<NS_PROJ::File *>(pj_open_lib_internal( @@ -1825,13 +1851,10 @@ void pj_load_ini(PJ_CONTEXT *ctx) { trim(content.substr(equal + 1, eol - (equal + 1))); if (ctx->endpoint.empty() && key == "cdn_endpoint") { ctx->endpoint = value; - } else if (key == "network") { - const char *enabled = getenv("PROJ_NETWORK"); - if (enabled == nullptr || enabled[0] == '\0') { - ctx->networking.enabled = ci_equal(value, "ON") || - ci_equal(value, "YES") || - ci_equal(value, "TRUE"); - } + } else if (proj_network == nullptr && key == "network") { + ctx->networking.enabled = ci_equal(value, "ON") || + ci_equal(value, "YES") || + ci_equal(value, "TRUE"); } else if (key == "cache_enabled") { ctx->gridChunkCache.enabled = ci_equal(value, "ON") || ci_equal(value, "YES") || @@ -1854,6 +1877,8 @@ void pj_load_ini(PJ_CONTEXT *ctx) { ctx, PJ_LOG_ERROR, "pj_load_ini(): Invalid value for tmerc_default_algo"); } + } else if (ca_bundle_path == nullptr && key == "ca_bundle_path") { + ctx->ca_bundle_path = value; } } @@ -1957,6 +1982,7 @@ void proj_context_set_ca_bundle_path(PJ_CONTEXT *ctx, const char *path) { ctx = pj_get_default_ctx(); if (!ctx) return; + pj_load_ini(ctx); try { ctx->set_ca_bundle_path(path != nullptr ? path : ""); } catch (const std::exception &) { |
