aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan D. Snow <alansnow21@gmail.com>2020-04-20 03:03:41 -0500
committerGitHub <noreply@github.com>2020-04-20 10:03:41 +0200
commit5e3aba396b114fa4bb3cd787acfc000f6792c078 (patch)
tree8bb11317ded5f9b9ed62ccf0cdfc31f711213ae7
parentb16b966b7484efd74a7364bd455ed3015d1009d6 (diff)
downloadPROJ-5e3aba396b114fa4bb3cd787acfc000f6792c078.tar.gz
PROJ-5e3aba396b114fa4bb3cd787acfc000f6792c078.zip
Moved proj_context_get_url_endpoint & proj_context_get_user_writable_directory to proj.h (#2162)
Fixes #2028
-rw-r--r--docs/source/development/reference/functions.rst6
-rw-r--r--scripts/reference_exported_symbols.txt4
-rw-r--r--src/apps/projinfo.cpp2
-rw-r--r--src/apps/projsync.cpp4
-rw-r--r--src/filemanager.cpp89
-rw-r--r--src/networkfilemanager.cpp8
-rw-r--r--src/proj.h4
-rw-r--r--src/proj_internal.h3
-rw-r--r--test/unit/proj_context_test.cpp2
9 files changed, 70 insertions, 52 deletions
diff --git a/docs/source/development/reference/functions.rst b/docs/source/development/reference/functions.rst
index 14f8bc96..dbc0af02 100644
--- a/docs/source/development/reference/functions.rst
+++ b/docs/source/development/reference/functions.rst
@@ -753,6 +753,12 @@ Network related functionality
.. doxygenfunction:: proj_context_set_url_endpoint
:project: doxygen_api
+.. doxygenfunction:: proj_context_get_url_endpoint
+ :project: doxygen_api
+
+.. doxygenfunction:: proj_context_get_user_writable_directory
+ :project: doxygen_api
+
.. doxygenfunction:: proj_grid_cache_set_enable
:project: doxygen_api
diff --git a/scripts/reference_exported_symbols.txt b/scripts/reference_exported_symbols.txt
index 674abfed..f38d708b 100644
--- a/scripts/reference_exported_symbols.txt
+++ b/scripts/reference_exported_symbols.txt
@@ -745,8 +745,8 @@ pj_cleanup_lock
pj_clear_initcache
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)
+proj_context_get_url_endpoint(projCtx_t*)
+proj_context_get_user_writable_directory(projCtx_t*, int)
pj_context_set_user_writable_directory(projCtx_t*, std::string const&)
pj_ctx_alloc
pj_ctx_fclose
diff --git a/src/apps/projinfo.cpp b/src/apps/projinfo.cpp
index 85db14e2..ed732aaa 100644
--- a/src/apps/projinfo.cpp
+++ b/src/apps/projinfo.cpp
@@ -1074,7 +1074,7 @@ int main(int argc, char **argv) {
#ifdef CURL_ENABLED
if (proj_context_is_network_enabled(nullptr)) {
std::cout << "Status: enabled" << std::endl;
- std::cout << "URL: " << pj_context_get_url_endpoint(nullptr)
+ std::cout << "URL: " << proj_context_get_url_endpoint(nullptr)
<< std::endl;
} else {
std::cout << "Status: disabled" << std::endl;
diff --git a/src/apps/projsync.cpp b/src/apps/projsync.cpp
index 61681260..f78e3a17 100644
--- a/src/apps/projsync.cpp
+++ b/src/apps/projsync.cpp
@@ -111,7 +111,7 @@ int main(int argc, char *argv[]) {
auto ctx = pj_get_default_ctx();
std::string targetDir;
- std::string endpoint(pj_context_get_url_endpoint(ctx));
+ std::string endpoint(proj_context_get_url_endpoint(ctx));
const std::string geojsonFile("files.geojson");
std::string queriedSourceId;
std::string queriedAreaOfUse;
@@ -224,7 +224,7 @@ int main(int argc, char *argv[]) {
}
if (targetDir.empty()) {
- targetDir = pj_context_get_user_writable_directory(ctx, true);
+ targetDir = proj_context_get_user_writable_directory(ctx, true);
} else {
if (targetDir.back() == '/') {
targetDir.resize(targetDir.size() - 1);
diff --git a/src/filemanager.cpp b/src/filemanager.cpp
index 2a5678b7..e299b08f 100644
--- a/src/filemanager.cpp
+++ b/src/filemanager.cpp
@@ -1090,6 +1090,19 @@ std::string FileManager::getProjLibEnvVar(PJ_CONTEXT *ctx) {
NS_PROJ_END
+// ---------------------------------------------------------------------------
+
+static void CreateDirectoryRecursively(PJ_CONTEXT *ctx,
+ const std::string &path) {
+ if (NS_PROJ::FileManager::exists(ctx, path.c_str()))
+ return;
+ auto pos = path.find_last_of("/\\");
+ if (pos == 0 || pos == std::string::npos)
+ return;
+ CreateDirectoryRecursively(ctx, path.substr(0, pos));
+ NS_PROJ::FileManager::mkdir(ctx, path.c_str());
+}
+
//! @endcond
// ---------------------------------------------------------------------------
@@ -1165,25 +1178,16 @@ void proj_context_set_sqlite3_vfs_name(PJ_CONTEXT *ctx, const char *name) {
// ---------------------------------------------------------------------------
-//! @cond Doxygen_Suppress
-
-// ---------------------------------------------------------------------------
-
-static void CreateDirectoryRecursively(PJ_CONTEXT *ctx,
- const std::string &path) {
- if (NS_PROJ::FileManager::exists(ctx, path.c_str()))
- return;
- auto pos = path.find_last_of("/\\");
- if (pos == 0 || pos == std::string::npos)
- return;
- CreateDirectoryRecursively(ctx, path.substr(0, pos));
- NS_PROJ::FileManager::mkdir(ctx, path.c_str());
-}
-
-// ---------------------------------------------------------------------------
+/** Get the PROJ user writable directory for datumgrid files.
+ *
+ * @param ctx PROJ context, or NULL
+ * @param create If set to TRUE, create the directory if it does not exist already.
+ * @return The path to the PROJ user writable directory.
+ * @since 7.1
+*/
-std::string pj_context_get_user_writable_directory(PJ_CONTEXT *ctx,
- bool create) {
+const char *proj_context_get_user_writable_directory(PJ_CONTEXT *ctx,
+ int create) {
if (!ctx)
ctx = pj_get_default_ctx();
if (ctx->user_writable_directory.empty()) {
@@ -1234,14 +1238,36 @@ std::string pj_context_get_user_writable_directory(PJ_CONTEXT *ctx,
path += "/proj";
ctx->user_writable_directory = path;
}
- if (create) {
+ if (create != FALSE) {
CreateDirectoryRecursively(ctx, ctx->user_writable_directory);
}
- return ctx->user_writable_directory;
+ return ctx->user_writable_directory.c_str();
+}
+
+/** Get the URL endpoint to query for remote grids.
+*
+* @param ctx PROJ context, or NULL
+* @return Endpoint URL. The returned pointer would be invalidated
+* by a later call to proj_context_set_url_endpoint()
+* @since 7.1
+*/
+const char* proj_context_get_url_endpoint(PJ_CONTEXT *ctx) {
+ if (ctx == nullptr) {
+ ctx = pj_get_default_ctx();
+ }
+ if (!ctx->endpoint.empty()) {
+ return ctx->endpoint.c_str();
+ }
+ pj_load_ini(ctx);
+ return ctx->endpoint.c_str();
}
// ---------------------------------------------------------------------------
+//! @cond Doxygen_Suppress
+
+// ---------------------------------------------------------------------------
+
void pj_context_set_user_writable_directory(PJ_CONTEXT *ctx,
const std::string &path) {
if (!ctx)
@@ -1478,11 +1504,11 @@ pj_open_lib_internal(projCtx ctx, const char *name, const char *mode,
else if (!dontReadUserWritableDirectory() &&
(fid = open_file(
- ctx, (pj_context_get_user_writable_directory(ctx, false) +
+ ctx, (std::string(proj_context_get_user_writable_directory(ctx, false)) +
DIR_CHAR + name)
.c_str(),
mode)) != nullptr) {
- fname = pj_context_get_user_writable_directory(ctx, false);
+ fname = proj_context_get_user_writable_directory(ctx, false);
fname += DIR_CHAR;
fname += name;
sysname = fname.c_str();
@@ -1554,7 +1580,7 @@ std::vector<std::string> pj_get_default_searchpaths(PJ_CONTEXT *ctx) {
getenv("PROJ_SKIP_READ_USER_WRITABLE_DIRECTORY");
if (ignoreUserWritableDirectory == nullptr ||
ignoreUserWritableDirectory[0] == '\0') {
- ret.push_back(pj_context_get_user_writable_directory(ctx, false));
+ ret.push_back(proj_context_get_user_writable_directory(ctx, false));
}
const std::string envPROJ_LIB = NS_PROJ::FileManager::getProjLibEnvVar(ctx);
if (!envPROJ_LIB.empty()) {
@@ -1674,7 +1700,7 @@ NS_PROJ::FileManager::open_resource_file(projCtx ctx, const char *name) {
!is_rel_or_absolute_filename(name) && !starts_with(name, "http://") &&
!starts_with(name, "https://") &&
proj_context_is_network_enabled(ctx)) {
- std::string remote_file(pj_context_get_url_endpoint(ctx));
+ std::string remote_file(proj_context_get_url_endpoint(ctx));
if (!remote_file.empty()) {
if (remote_file.back() != '/') {
remote_file += '/';
@@ -1760,21 +1786,6 @@ int pj_find_file(projCtx ctx, const char *short_filename,
}
/************************************************************************/
-/* pj_context_get_url_endpoint() */
-/************************************************************************/
-
-std::string pj_context_get_url_endpoint(PJ_CONTEXT *ctx) {
- if (ctx == nullptr) {
- ctx = pj_get_default_ctx();
- }
- if (!ctx->endpoint.empty()) {
- return ctx->endpoint;
- }
- pj_load_ini(ctx);
- return ctx->endpoint;
-}
-
-/************************************************************************/
/* trim() */
/************************************************************************/
diff --git a/src/networkfilemanager.cpp b/src/networkfilemanager.cpp
index 28d8baa2..7cc0599e 100644
--- a/src/networkfilemanager.cpp
+++ b/src/networkfilemanager.cpp
@@ -1947,7 +1947,7 @@ static bool is_rel_or_absolute_filename(const char *name) {
static std::string build_url(PJ_CONTEXT *ctx, const char *name) {
if (!is_tilde_slash(name) && !is_rel_or_absolute_filename(name) &&
!starts_with(name, "http://") && !starts_with(name, "https://")) {
- std::string remote_file(pj_context_get_url_endpoint(ctx));
+ std::string remote_file(proj_context_get_url_endpoint(ctx));
if (!remote_file.empty()) {
if (remote_file.back() != '/') {
remote_file += '/';
@@ -2213,7 +2213,7 @@ int proj_is_download_needed(PJ_CONTEXT *ctx, const char *url_or_filename,
if (filename == nullptr)
return false;
const auto localFilename(
- pj_context_get_user_writable_directory(ctx, false) + filename);
+ std::string(proj_context_get_user_writable_directory(ctx, false)) + filename);
auto f = NS_PROJ::FileManager::open(ctx, localFilename.c_str(),
NS_PROJ::FileAccess::READ_ONLY);
@@ -2351,7 +2351,7 @@ int proj_download_file(PJ_CONTEXT *ctx, const char *url_or_filename,
const char *filename = strrchr(url.c_str(), '/');
if (filename == nullptr)
return false;
- const auto localFilename(pj_context_get_user_writable_directory(ctx, true) +
+ const auto localFilename(std::string(proj_context_get_user_writable_directory(ctx, true)) +
filename);
#ifdef _WIN32
@@ -2536,7 +2536,7 @@ std::string pj_context_get_grid_cache_filename(PJ_CONTEXT *ctx) {
if (!ctx->gridChunkCache.filename.empty()) {
return ctx->gridChunkCache.filename;
}
- const std::string path(pj_context_get_user_writable_directory(ctx, true));
+ const std::string path(proj_context_get_user_writable_directory(ctx, true));
ctx->gridChunkCache.filename = path + "/cache.db";
return ctx->gridChunkCache.filename;
}
diff --git a/src/proj.h b/src/proj.h
index 167d4de2..19a81163 100644
--- a/src/proj.h
+++ b/src/proj.h
@@ -512,6 +512,10 @@ 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);
+const char PROJ_DLL *proj_context_get_url_endpoint(PJ_CONTEXT* ctx);
+
+const char PROJ_DLL *proj_context_get_user_writable_directory(PJ_CONTEXT *ctx, int create);
+
void PROJ_DLL proj_grid_cache_set_enable(PJ_CONTEXT* ctx, int enabled);
void PROJ_DLL proj_grid_cache_set_filename(PJ_CONTEXT* ctx, const char* fullname);
diff --git a/src/proj_internal.h b/src/proj_internal.h
index 253c647b..e3f2d8db 100644
--- a/src/proj_internal.h
+++ b/src/proj_internal.h
@@ -875,15 +875,12 @@ 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
-std::string PROJ_DLL pj_context_get_url_endpoint(PJ_CONTEXT* ctx);
-
void pj_load_ini(PJ_CONTEXT* ctx);
// Exported for testing purposes only
std::string PROJ_DLL pj_context_get_grid_cache_filename(PJ_CONTEXT *ctx);
// For use by projsync
-std::string PROJ_DLL pj_context_get_user_writable_directory(PJ_CONTEXT *ctx, bool create);
void PROJ_DLL pj_context_set_user_writable_directory(PJ_CONTEXT* ctx, const std::string& path);
std::string PROJ_DLL pj_get_relative_share_proj(PJ_CONTEXT *ctx);
diff --git a/test/unit/proj_context_test.cpp b/test/unit/proj_context_test.cpp
index 92f251cd..ccd74f4a 100644
--- a/test/unit/proj_context_test.cpp
+++ b/test/unit/proj_context_test.cpp
@@ -154,7 +154,7 @@ TEST(proj_context, proj_context_set_search_paths) {
TEST(proj_context, read_grid_from_user_writable_directory) {
auto ctx = proj_context_create();
- auto path = pj_context_get_user_writable_directory(ctx, true);
+ auto path = std::string(proj_context_get_user_writable_directory(ctx, true));
EXPECT_TRUE(!path.empty());
auto filename = path + DIR_CHAR + "temp_proj_dic3";
EXPECT_TRUE(createTmpFile(filename));