Add http proxy support for GDAL

This commit is contained in:
Emil Axelsson
2016-10-07 20:42:32 +02:00
parent 0a47931b4b
commit 5e2ea10bcd
5 changed files with 107 additions and 3 deletions
@@ -106,6 +106,19 @@ public:
/// The key that stores the switch for enabling/disabling the rendering on a master
/// computer
static const std::string KeyRenderingMethod;
/// The key that stores the http proxy settings for the downloadmanager
static const std::string KeyHttpProxy;
/// The key that stores the address of the http proxy
static const std::string ConfigurationManager::PartHttpProxyAddress;
/// The key that stores the port of the http proxy
static const std::string ConfigurationManager::PartHttpProxyPort;
/// The key that stores the authentication method of the http proxy
static const std::string ConfigurationManager::PartHttpProxyAuthentication;
/// The key that stores the username to use for authentication to access the http proxy
static const std::string ConfigurationManager::PartHttpProxyUser;
/// The key that stores the password to use for authentication to access the http proxy
static const std::string ConfigurationManager::PartHttpProxyPassword;
/**
* Iteratively walks the directory structure starting with \p filename to find the
+47 -2
View File
@@ -41,8 +41,8 @@
#include <algorithm>
#include <gdal_priv.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/configurationmanager.h>
namespace {
@@ -170,10 +170,55 @@ namespace openspace {
if (!GdalHasBeenInitialized) {
GDALAllRegister();
CPLSetConfigOption("GDAL_DATA", absPath("${MODULE_GLOBEBROWSING}/gdal_data").c_str());
setGdalProxyConfiguration();
GdalHasBeenInitialized = true;
}
}
void TileDataset::setGdalProxyConfiguration() {
ghoul::Dictionary proxySettings;
bool proxyEnabled = OsEng.configurationManager().getValue(ConfigurationManager::KeyHttpProxy, proxySettings);
if (proxyEnabled) {
std::string proxyAddress, proxyPort, proxyUser, proxyPassword, proxyAuth;
bool success = proxySettings.getValue(ConfigurationManager::PartHttpProxyAddress, proxyAddress);
success &= proxySettings.getValue(ConfigurationManager::PartHttpProxyPort, proxyPort);
proxySettings.getValue(ConfigurationManager::PartHttpProxyAuthentication, proxyAuth);
std::string proxyAuthString = "BASIC";
if (proxyAuth == "basic" || proxyAuth == "") {
proxyAuthString = "BASIC";
} else if (proxyAuth == "ntlm") {
proxyAuthString = "NTLM";
} else if (proxyAuth == "digest") {
proxyAuthString = "DIGEST";
} else if (proxyAuth == "any") {
proxyAuthString = "ANY";
} else {
success = false;
}
bool userAndPassword = proxySettings.getValue(ConfigurationManager::PartHttpProxyUser, proxyUser);
userAndPassword &= proxySettings.getValue(ConfigurationManager::PartHttpProxyPassword, proxyPassword);
if (success) {
std::string proxy = proxyAddress + ":" + proxyPort;
CPLSetConfigOption("GDAL_HTTP_PROXY", proxy.c_str());
LDEBUG("Using proxy server " << proxy);
if (userAndPassword) {
std::string proxyUserPwd = proxyUser + ":" + proxyPassword;
CPLSetConfigOption("GDAL_HTTP_PROXYUSERPWD", proxyUserPwd.c_str());
CPLSetConfigOption("GDAL_HTTP_PROXYAUTH", proxyAuthString.c_str());
LDEBUG("Using authentication method: " << proxyAuthString);
}
} else {
LERROR("Invalid proxy settings for GDAL");
}
} else {
LDEBUG("Setting up GDAL without proxy server");
}
}
GDALDataset* TileDataset::gdalDataset(const std::string& gdalDatasetDesc) {
GDALDataset* dataset = (GDALDataset *)GDALOpen(gdalDatasetDesc.c_str(), GA_ReadOnly);
if (!dataset) {
+1
View File
@@ -136,6 +136,7 @@ namespace openspace {
//////////////////////////////////////////////////////////////////////////////////
void gdalEnsureInitialized();
void setGdalProxyConfiguration();
GDALDataset* gdalDataset(const std::string& gdalDatasetDesc);
bool gdalHasOverviews() const;
int gdalOverview(const PixelRange& baseRegionSize) const;
+7
View File
@@ -72,6 +72,13 @@ const string ConfigurationManager::KeyDisableMasterRendering = "DisableRendering
const string ConfigurationManager::KeyDownloadRequestURL = "DownloadRequestURL";
const string ConfigurationManager::KeyRenderingMethod = "RenderingMethod";
const string ConfigurationManager::KeyHttpProxy = "HttpProxy";
const string ConfigurationManager::PartHttpProxyAddress = "Address";
const string ConfigurationManager::PartHttpProxyPort = "Port";
const string ConfigurationManager::PartHttpProxyAuthentication = "Authentication";
const string ConfigurationManager::PartHttpProxyUser = "User";
const string ConfigurationManager::PartHttpProxyPassword = "Password";
string ConfigurationManager::findConfiguration(const string& filename) {
using ghoul::filesystem::Directory;
+39 -1
View File
@@ -325,7 +325,45 @@ Documentation ConfigurationManager::Documentation() {
"or just managing the state of the network. This is desired in cases where "
"the master computer does not have the resources to render a scene.",
Optional::Yes
}
},
{
ConfigurationManager::KeyHttpProxy,
new TableVerifier({
{
ConfigurationManager::PartHttpProxyAddress,
new StringVerifier,
"The address of the http proxy"
},
{
ConfigurationManager::PartHttpProxyPort,
new StringVerifier,
"The port of the http proxy"
},
{
ConfigurationManager::PartHttpProxyAuthentication,
new StringInListVerifier(
{ "basic", "ntlm", "digest", "any" }
),
"The authentication method of the http proxy",
Optional::Yes
},
{
ConfigurationManager::PartHttpProxyUser,
new StringVerifier,
"The user of the http proxy",
Optional::Yes
},
{
ConfigurationManager::PartHttpProxyPassword,
new StringVerifier,
"The password of the http proxy",
Optional::Yes
}
}),
"This defines the use for a proxy when fetching data over http."
"No proxy will be used if this is left out.",
Optional::Yes
}
}
};
};