Skip to content
Permalink
Browse files

[bugfix] Apply proxy configuration to OGR connections

Fixes #5212 Proxy settings ignored for layers
  • Loading branch information
elpaso committed Nov 10, 2017
1 parent d8a3c67 commit d8fc6e877bbc5645cddf43b976e018e5c854a995
Showing with 66 additions and 3 deletions.
  1. +5 −3 src/providers/ogr/CMakeLists.txt
  2. +56 −0 src/providers/ogr/qgsogrprovider.cpp
  3. +5 −0 src/providers/ogr/qgsogrprovider.h
@@ -1,4 +1,3 @@

SET (OGR_SRCS
qgsogrprovider.cpp
qgsogrdataitems.cpp
@@ -40,12 +39,14 @@ QT5_WRAP_CPP(OGR_MOC_SRCS ${OGR_MOC_HDRS})

INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/core
${CMAKE_SOURCE_DIR}/src/core/auth
${CMAKE_SOURCE_DIR}/src/core/raster
${CMAKE_SOURCE_DIR}/src/core/geometry
${CMAKE_SOURCE_DIR}/src/core/metadata
${CMAKE_SOURCE_DIR}/src/core/symbology
${CMAKE_SOURCE_DIR}/src/core/expression
${CMAKE_SOURCE_DIR}/src/gui
${CMAKE_SOURCE_DIR}/src/gui/auth

${CMAKE_BINARY_DIR}/src/core
${CMAKE_BINARY_DIR}/src/gui
@@ -54,6 +55,8 @@ INCLUDE_DIRECTORIES(
INCLUDE_DIRECTORIES(SYSTEM
${GDAL_INCLUDE_DIR}
${GEOS_INCLUDE_DIR}
${QTKEYCHAIN_INCLUDE_DIR}
${QCA_INCLUDE_DIR}
${QSCINTILLA_INCLUDE_DIR}
)

@@ -86,5 +89,4 @@ ENDIF(CLANG_TIDY_EXE)

INSTALL (TARGETS ogrprovider
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
@@ -24,6 +24,7 @@ email : sherman at mrcc.com
#include "qgsfeedback.h"
#include "qgssettings.h"
#include "qgsapplication.h"
#include "qgsauthmanager.h"
#include "qgsdataitem.h"
#include "qgsdataprovider.h"
#include "qgsfeature.h"
@@ -35,6 +36,7 @@ email : sherman at mrcc.com
#include "qgsogrdataitems.h"
#include "qgsgeopackagedataitems.h"
#include "qgswkbtypes.h"
#include "qgsnetworkaccessmanager.h"

#ifdef HAVE_GUI
#include "qgssourceselectprovider.h"
@@ -419,6 +421,10 @@ QgsOgrProvider::QgsOgrProvider( QString const &uri )
QgsSettings settings;
CPLSetConfigOption( "SHAPE_ENCODING", settings.value( QStringLiteral( "qgis/ignoreShapeEncoding" ), true ).toBool() ? "" : nullptr );
#ifndef QT_NO_NETWORKPROXY
setupProxy();
#endif
// make connection to the data source
QgsDebugMsg( "Data source uri is [" + uri + ']' );
@@ -1972,6 +1978,56 @@ bool QgsOgrProvider::doInitialActionsForEdition()
return true;
}

#ifndef QT_NO_NETWORKPROXY
void QgsOgrProvider::setupProxy()
{
// Check proxy configuration, they are application level but
// instead of adding an API and complex signal/slot connections
// given the limited cost of checking them on every provider instanciation
// we can do it here so that new settings are applied whenever a new layer
// is created.
QgsSettings settings;
// Check that proxy is enabled
if ( settings.value( QStringLiteral( "proxy/proxyEnabled" ), false ).toBool() )
{
// Get the first configured proxy
QList<QNetworkProxy> proxyes( QgsNetworkAccessManager::instance()->proxyFactory()->queryProxy( ) );
if ( ! proxyes.isEmpty() )
{
QNetworkProxy proxy( proxyes.first() );
// TODO/FIXME: check excludes (the GDAL config options are global, we need a per-connection config option)
//QStringList excludes;
//excludes = settings.value( QStringLiteral( "proxy/proxyExcludedUrls" ), "" ).toString().split( '|', QString::SkipEmptyParts );

QString proxyHost( proxy.hostName() );
qint16 proxyPort( proxy.port() );

QString proxyUser( proxy.user() );
QString proxyPassword( proxy.password() );

if ( ! proxyHost.isEmpty() )
{
QString connection( proxyHost );
if ( proxyPort )
{
connection += ':' + QString::number( proxyPort );
}
CPLSetConfigOption( "GDAL_HTTP_PROXY", connection.toUtf8() );
if ( ! proxyUser.isEmpty( ) )
{
QString credentials( proxyUser );
if ( ! proxyPassword.isEmpty( ) )
{
credentials += ':' + proxyPassword;
}
CPLSetConfigOption( "GDAL_HTTP_PROXYUSERPWD", credentials.toUtf8() );
}
}
}
}
}
#endif

QgsVectorDataProvider::Capabilities QgsOgrProvider::capabilities() const
{
return mCapabilities;
@@ -266,6 +266,11 @@ class QgsOgrProvider : public QgsVectorDataProvider
QgsVectorDataProvider::Capabilities mCapabilities;

bool doInitialActionsForEdition();

#ifndef QT_NO_NETWORKPROXY
void setupProxy();
#endif

};

/**

0 comments on commit d8fc6e8

Please sign in to comment.
You can’t perform that action at this time.