diff options
| -rw-r--r-- | docs/source/development/reference/functions.rst | 3 | ||||
| -rw-r--r-- | scripts/reference_exported_symbols.txt | 2 | ||||
| -rw-r--r-- | src/4D_api.cpp | 2 | ||||
| -rw-r--r-- | src/apps/projinfo.cpp | 4 | ||||
| -rw-r--r-- | src/filemanager.cpp | 5 | ||||
| -rw-r--r-- | src/iso19111/c_api.cpp | 10 | ||||
| -rw-r--r-- | src/networkfilemanager.cpp | 48 | ||||
| -rw-r--r-- | src/proj.h | 2 | ||||
| -rw-r--r-- | src/proj_internal.h | 3 |
9 files changed, 45 insertions, 34 deletions
diff --git a/docs/source/development/reference/functions.rst b/docs/source/development/reference/functions.rst index a2a0c3ae..1c363b88 100644 --- a/docs/source/development/reference/functions.rst +++ b/docs/source/development/reference/functions.rst @@ -720,6 +720,9 @@ Network related functionality .. doxygenfunction:: proj_context_set_enable_network :project: doxygen_api +.. doxygenfunction:: proj_context_is_network_enabled + :project: doxygen_api + .. doxygenfunction:: proj_context_set_url_endpoint :project: doxygen_api diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt index 01f8204b..50be8d8a 100644 --- a/scripts/reference_exported_symbols.txt +++ b/scripts/reference_exported_symbols.txt @@ -745,7 +745,6 @@ pj_compare_datums pj_context_get_grid_cache_filename(projCtx_t*) pj_context_get_url_endpoint(projCtx_t*) pj_context_get_user_writable_directory(projCtx_t*, bool) -pj_context_is_network_enabled(projCtx_t*) pj_context_set_user_writable_directory(projCtx_t*, std::string const&) pj_ctx_alloc pj_ctx_fclose @@ -834,6 +833,7 @@ proj_context_get_database_metadata proj_context_get_database_path proj_context_get_use_proj4_init_rules proj_context_guess_wkt_dialect +proj_context_is_network_enabled proj_context_set_autoclose_database proj_context_set_database_path proj_context_set_enable_network diff --git a/src/4D_api.cpp b/src/4D_api.cpp index 91510c35..88a0ed14 100644 --- a/src/4D_api.cpp +++ b/src/4D_api.cpp @@ -1152,7 +1152,7 @@ PJ *proj_create_crs_to_crs_from_pj (PJ_CONTEXT *ctx, const PJ *source_crs, cons ctx, operation_ctx, PROJ_SPATIAL_CRITERION_PARTIAL_INTERSECTION); proj_operation_factory_context_set_grid_availability_use( ctx, operation_ctx, - pj_context_is_network_enabled(ctx) ? + proj_context_is_network_enabled(ctx) ? PROJ_GRID_AVAILABILITY_KNOWN_AVAILABLE: PROJ_GRID_AVAILABILITY_DISCARD_OPERATION_IF_MISSING_GRID); diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp index 9cd9b2ee..41a95237 100644 --- a/src/apps/projinfo.cpp +++ b/src/apps/projinfo.cpp @@ -787,7 +787,7 @@ int main(int argc, char **argv) { CoordinateOperationContext::SourceTargetCRSExtentUse::SMALLEST; bool buildBoundCRSToWGS84 = false; CoordinateOperationContext::GridAvailabilityUse gridAvailabilityUse = - pj_context_is_network_enabled(nullptr) + proj_context_is_network_enabled(nullptr) ? CoordinateOperationContext::GridAvailabilityUse::KNOWN_AVAILABLE : CoordinateOperationContext::GridAvailabilityUse::USE_FOR_SORTING; CoordinateOperationContext::IntermediateCRSUse allowUseIntermediateCRS = @@ -1071,7 +1071,7 @@ int main(int argc, char **argv) { std::exit(0); } else if (ci_equal(arg, "--remote-data")) { #ifdef CURL_ENABLED - if (pj_context_is_network_enabled(nullptr)) { + if (proj_context_is_network_enabled(nullptr)) { std::cout << "Status: enabled" << std::endl; std::cout << "URL: " << pj_context_get_url_endpoint(nullptr) << std::endl; diff --git a/src/filemanager.cpp b/src/filemanager.cpp index 165a5b15..d7c55fba 100644 --- a/src/filemanager.cpp +++ b/src/filemanager.cpp @@ -944,7 +944,7 @@ std::unique_ptr<File> FileApiAdapter::open(PJ_CONTEXT *ctx, std::unique_ptr<File> FileManager::open(PJ_CONTEXT *ctx, const char *filename, FileAccess access) { if (starts_with(filename, "http://") || starts_with(filename, "https://")) { - if (!pj_context_is_network_enabled(ctx)) { + if (!proj_context_is_network_enabled(ctx)) { pj_log( ctx, PJ_LOG_ERROR, "Attempt at accessing remote resource not authorized. Either " @@ -1672,7 +1672,8 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) { if (file == nullptr && !is_tilde_slash(name) && !is_rel_or_absolute_filename(name) && !starts_with(name, "http://") && - !starts_with(name, "https://") && pj_context_is_network_enabled(ctx)) { + !starts_with(name, "https://") && + proj_context_is_network_enabled(ctx)) { std::string remote_file(pj_context_get_url_endpoint(ctx)); if (!remote_file.empty()) { if (remote_file.back() != '/') { diff --git a/src/iso19111/c_api.cpp b/src/iso19111/c_api.cpp index 67050725..bb01889b 100644 --- a/src/iso19111/c_api.cpp +++ b/src/iso19111/c_api.cpp @@ -177,7 +177,7 @@ static PJ *pj_obj_create(PJ_CONTEXT *ctx, const IdentifiedObjectNNPtr &objIn) { auto formatter = PROJStringFormatter::create( PROJStringFormatter::Convention::PROJ_5, dbContext); auto projString = coordop->exportToPROJString(formatter.get()); - if (pj_context_is_network_enabled(ctx)) { + if (proj_context_is_network_enabled(ctx)) { ctx->defer_grid_opening = true; } auto pj = pj_create_internal(ctx, projString.c_str()); @@ -6619,8 +6619,8 @@ int proj_coordoperation_is_instantiable(PJ_CONTEXT *ctx, } auto dbContext = getDBcontextNoException(ctx, __FUNCTION__); try { - auto ret = op->isPROJInstantiable(dbContext, - pj_context_is_network_enabled(ctx)) + auto ret = op->isPROJInstantiable( + dbContext, proj_context_is_network_enabled(ctx) != false) ? 1 : 0; if (ctx->cpp_context) { @@ -6934,8 +6934,8 @@ int proj_coordoperation_get_grid_used_count(PJ_CONTEXT *ctx, try { if (!coordoperation->gridsNeededAsked) { coordoperation->gridsNeededAsked = true; - const auto gridsNeeded = - co->gridsNeeded(dbContext, pj_context_is_network_enabled(ctx)); + const auto gridsNeeded = co->gridsNeeded( + dbContext, proj_context_is_network_enabled(ctx) != false); for (const auto &gridDesc : gridsNeeded) { coordoperation->gridsNeeded.emplace_back(gridDesc); } diff --git a/src/networkfilemanager.cpp b/src/networkfilemanager.cpp index d252fd84..28d8baa2 100644 --- a/src/networkfilemanager.cpp +++ b/src/networkfilemanager.cpp @@ -2023,6 +2023,32 @@ int proj_context_set_enable_network(PJ_CONTEXT *ctx, int enable) { #endif } +// --------------------------------------------------------------------------- + +/** Return if network access is enabled. +* +* @param ctx PROJ context, or NULL +* @return TRUE if network access has been enabled +* @since 7.0 +*/ +int proj_context_is_network_enabled(PJ_CONTEXT *ctx) { + if (ctx == nullptr) { + ctx = pj_get_default_ctx(); + } + if (ctx->networking.enabled_env_variable_checked) { + return ctx->networking.enabled; + } + const char *enabled = getenv("PROJ_NETWORK"); + if (enabled && enabled[0] != '\0') { + ctx->networking.enabled = ci_equal(enabled, "ON") || + ci_equal(enabled, "YES") || + ci_equal(enabled, "TRUE"); + } + pj_load_ini(ctx); + ctx->networking.enabled_env_variable_checked = true; + return ctx->networking.enabled; +} + //! @endcond // --------------------------------------------------------------------------- @@ -2177,7 +2203,7 @@ int proj_is_download_needed(PJ_CONTEXT *ctx, const char *url_or_filename, if (ctx == nullptr) { ctx = pj_get_default_ctx(); } - if (!pj_context_is_network_enabled(ctx)) { + if (!proj_context_is_network_enabled(ctx)) { pj_log(ctx, PJ_LOG_ERROR, "Networking capabilities are not enabled"); return false; } @@ -2313,7 +2339,7 @@ int proj_download_file(PJ_CONTEXT *ctx, const char *url_or_filename, if (ctx == nullptr) { ctx = pj_get_default_ctx(); } - if (!pj_context_is_network_enabled(ctx)) { + if (!proj_context_is_network_enabled(ctx)) { pj_log(ctx, PJ_LOG_ERROR, "Networking capabilities are not enabled"); return false; } @@ -2503,24 +2529,6 @@ int proj_download_file(PJ_CONTEXT *ctx, const char *url_or_filename, //! @cond Doxygen_Suppress -bool pj_context_is_network_enabled(PJ_CONTEXT *ctx) { - if (ctx == nullptr) { - ctx = pj_get_default_ctx(); - } - if (ctx->networking.enabled_env_variable_checked) { - return ctx->networking.enabled; - } - const char *enabled = getenv("PROJ_NETWORK"); - if (enabled && enabled[0] != '\0') { - ctx->networking.enabled = ci_equal(enabled, "ON") || - ci_equal(enabled, "YES") || - ci_equal(enabled, "TRUE"); - } - pj_load_ini(ctx); - ctx->networking.enabled_env_variable_checked = true; - return ctx->networking.enabled; -} - // --------------------------------------------------------------------------- std::string pj_context_get_grid_cache_filename(PJ_CONTEXT *ctx) { @@ -490,6 +490,8 @@ int PROJ_DLL proj_context_set_network_callbacks( int PROJ_DLL proj_context_set_enable_network(PJ_CONTEXT* ctx, int enabled); +int PROJ_DLL proj_context_is_network_enabled(PJ_CONTEXT* ctx); + void PROJ_DLL proj_context_set_url_endpoint(PJ_CONTEXT* ctx, const char* url); void PROJ_DLL proj_grid_cache_set_enable(PJ_CONTEXT* ctx, int enabled); diff --git a/src/proj_internal.h b/src/proj_internal.h index 0cffb475..3f0f0e5f 100644 --- a/src/proj_internal.h +++ b/src/proj_internal.h @@ -861,9 +861,6 @@ PJ *pj_create_internal (PJ_CONTEXT *ctx, const char *definition); PJ *pj_create_argv_internal (PJ_CONTEXT *ctx, int argc, char **argv); // For use by projinfo -bool PROJ_DLL pj_context_is_network_enabled(PJ_CONTEXT* ctx); - -// For use by projinfo std::string PROJ_DLL pj_context_get_url_endpoint(PJ_CONTEXT* ctx); void pj_load_ini(PJ_CONTEXT* ctx); |
