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
+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;