Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
In WMS, use a more robust method of passing the WMS proxy information…
… to the provider. For instance if there is a space in the proxy password, it should now pass-through OK.

Unfortunately I don't have access to a proxy to test, so if I could get some independent verification it would be appreciated.



git-svn-id: http://svn.osgeo.org/qgis/trunk@5605 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 16, 2006
1 parent 300c6e6 commit 838b262
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 64 deletions.
15 changes: 15 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -61,6 +61,21 @@ class QgsRasterDataProvider : public QgsDataProvider

virtual ~QgsRasterDataProvider() {};

/**
*
* Sets a proxy for the URL given in the constructor
*
*
* \retval TRUE if proxy setting is successful (if indeed it is supported)
*/
virtual bool setProxy(QString const & host,
int port,
QString const & user,
QString const & pass)
{
return FALSE;
}

/**
* Add the list of WMS layer names to be rendered by this server
*/
Expand Down
42 changes: 40 additions & 2 deletions src/gui/qgsserversourceselect.cpp
Expand Up @@ -348,7 +348,8 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
QString part;

connStringParts += settings.readEntry(key + "/url");


/*
// Add the proxy host and port if any are defined.
if ( ! ( (part = settings.readEntry(key + "/proxyhost")).isEmpty() ) )
{
Expand Down Expand Up @@ -384,7 +385,8 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
connStringParts += part;
}
}
}
}
*/

m_connName = cmbConnections->currentText();
// setup 'url ( + " " + proxyhost + " " + proxyport + " " + proxyuser + " " + proxypass)'
Expand All @@ -407,6 +409,22 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
{
connect(mWmsProvider, SIGNAL(setStatus(QString)), this, SLOT(showStatusMessage(QString)));

// Collect and set HTTP proxy on WMS provider

m_connProxyHost = settings.readEntry(key + "/proxyhost"),
m_connProxyPort = settings.readEntry(key + "/proxyport").toInt(),
m_connProxyUser = settings.readEntry(key + "/proxyuser"),
m_connProxyPass = settings.readEntry(key + "/proxypass"),

mWmsProvider->setProxy(
m_connProxyHost,
m_connProxyPort,
m_connProxyUser,
m_connProxyPass
);

// WMS Provider all set up; let's get some layers

if (!populateLayerList(mWmsProvider))
{
showError(mWmsProvider);
Expand Down Expand Up @@ -577,6 +595,26 @@ QString QgsServerSourceSelect::connInfo()
return m_connInfo;
}

QString QgsServerSourceSelect::connProxyHost()
{
return m_connProxyHost;
}

int QgsServerSourceSelect::connProxyPort()
{
return m_connProxyPort;
}

QString QgsServerSourceSelect::connProxyUser()
{
return m_connProxyUser;
}

QString QgsServerSourceSelect::connProxyPass()
{
return m_connProxyPass;
}

QStringList QgsServerSourceSelect::selectedLayers()
{
return m_selectedLayers;
Expand Down
31 changes: 30 additions & 1 deletion src/gui/qgsserversourceselect.h
Expand Up @@ -52,11 +52,25 @@ class QgsServerSourceSelect : public QDialog, private Ui::QgsServerSourceSelectB

//! Connection name
QString connName();

//! Connection info (uri)
QString connInfo();

//! Connection Proxy Host
QString connProxyHost();

//! Connection Proxy Port
int connProxyPort();

//! Connection Proxy User
QString connProxyUser();

//! Connection Proxy Pass
QString connProxyPass();

//! String list containing the selected layers
QStringList selectedLayers();

//! String list containing the visual styles selected for the selected layers - this corresponds with the output from selectedLayers()
QStringList selectedStylesForSelectedLayers();

Expand Down Expand Up @@ -126,9 +140,24 @@ public slots:
//! Returns a textual description for the EPSG number
QString descriptionForEpsg(long epsg);


//! Name for selected connection
QString m_connName;

//! URI for selected connection
QString m_connInfo;

//! Proxy Host for selected connection
QString m_connProxyHost;

//! Proxy Port for selected connection
int m_connProxyPort;

//! Proxy User for selected connection
QString m_connProxyUser;

//! Proxy Pass for selected connection
QString m_connProxyPass;

QStringList m_selectedLayers;
QStringList m_selectedStylesForSelectedLayers;
long m_Epsg;
Expand Down
18 changes: 13 additions & 5 deletions src/providers/wms/qgshttptransaction.cpp
Expand Up @@ -47,7 +47,14 @@ QgsHttpTransaction::QgsHttpTransaction(QString uri,
#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction: constructing." << std::endl;
#endif


#ifdef QGISDEBUG
std::cout << " QgsHttpTransaction: proxyHost = " << proxyHost.toLocal8Bit().data() << "." << std::endl;
std::cout << " QgsHttpTransaction: proxyPort = " << proxyPort << "." << std::endl;
std::cout << " QgsHttpTransaction: proxyUser = " << proxyUser.toLocal8Bit().data() << "." << std::endl;
std::cout << " QgsHttpTransaction: proxyPass = " << proxyPass.toLocal8Bit().data() << "." << std::endl;
#endif


#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction: exiting constructor." << std::endl;
Expand Down Expand Up @@ -124,16 +131,16 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
this, SLOT( dataHeaderReceived( const QHttpResponseHeader& ) ) );

connect(http, SIGNAL( readyRead( const QHttpResponseHeader& ) ),
this, SLOT( dataReceived( const QHttpResponseHeader& ) ) );
this, SLOT( dataReceived( const QHttpResponseHeader& ) ) );

connect(http, SIGNAL( dataReadProgress ( int, int ) ),
this, SLOT( dataProgress ( int, int ) ) );
this, SLOT( dataProgress ( int, int ) ) );

connect(http, SIGNAL( requestFinished ( int, bool ) ),
this, SLOT( dataFinished ( int, bool ) ) );

connect(http, SIGNAL( stateChanged ( int ) ),
this, SLOT( dataStateChanged ( int ) ) );
this, SLOT( dataStateChanged ( int ) ) );

// Set up the watchdog timer
connect(mWatchdogTimer, SIGNAL( timeout () ),
Expand All @@ -156,6 +163,7 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
{
// Do something else, maybe even network processing events
qApp->processEvents();

// TODO: Implement a network timeout
}

Expand Down Expand Up @@ -282,7 +290,7 @@ void QgsHttpTransaction::dataProgress( int done, int total )
{

#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction::dataProgress: got " << done << " of " << total << std::endl;
// std::cout << "QgsHttpTransaction::dataProgress: got " << done << " of " << total << std::endl;
#endif

// We saw something come back, therefore restart the watchdog timer
Expand Down
68 changes: 14 additions & 54 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -75,67 +75,15 @@ QgsWmsProvider::QgsWmsProvider(QString const & uri)
// assume this is a valid layer until we determine otherwise
valid = true;

// URI is in form: URL[ proxyhost[ proxyport[ proxyuser[ proxypass]]]

// Split proxy from the provider-encoded uri
QStringList drawuriparts = QStringList::split(" ", httpuri, TRUE);

baseUrl = drawuriparts.front();
drawuriparts.pop_front();

if (drawuriparts.count())
{
mHttpProxyHost = drawuriparts.front();
drawuriparts.pop_front();

if (drawuriparts.count())
{
bool conversionOK;
mHttpProxyPort = drawuriparts.front().toInt(&conversionOK);
if (!conversionOK)
{
mHttpProxyPort = 80; // standard HTTP port
}

drawuriparts.pop_front();

if (drawuriparts.count())
{
bool conversionOK;
mHttpProxyUser = drawuriparts.front();

drawuriparts.pop_front();

if (drawuriparts.count())
{
bool conversionOK;
mHttpProxyPass = drawuriparts.front();

drawuriparts.pop_front();

}
else
{
mHttpProxyPass = QString(); // none
}
}
else
{
mHttpProxyUser = QString(); // anonymous
}
}
else
{
mHttpProxyPort = 80; // standard HTTP port
}
}

// URL can be in 3 forms:
// 1) http://xxx.xxx.xx/yyy/yyy
// 2) http://xxx.xxx.xx/yyy/yyy?
// 3) http://xxx.xxx.xx/yyy/yyy?zzz=www

// Prepare the URI so that we can later simply append param=value
baseUrl = httpuri;

if ( !(baseUrl.contains("?")) )
{
baseUrl.append("?");
Expand Down Expand Up @@ -198,6 +146,18 @@ QgsWmsProvider::~QgsWmsProvider()

}

bool QgsWmsProvider::setProxy(QString const & host,
int port,
QString const & user,
QString const & pass)
{
mHttpProxyHost = host;
mHttpProxyPort = port;
mHttpProxyUser = user;
mHttpProxyPass = pass;

return TRUE;
}

bool QgsWmsProvider::supportedLayers(std::vector<QgsWmsLayerProperty> & layers)
{
Expand Down
13 changes: 11 additions & 2 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -347,8 +347,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
/**
* Constructor for the provider.
*
* \param uri HTTP URL of the Web Server, optionally followed by a space then the proxy host name,
* another space, and the proxy host port. If no proxy is declared then we will
* \param uri HTTP URL of the Web Server. If setProxy() is not also called then we will
* contact the host directly.
*
*/
Expand All @@ -357,6 +356,16 @@ class QgsWmsProvider : public QgsRasterDataProvider
//! Destructor
virtual ~QgsWmsProvider();

/**
*
* Sets an HTTP proxy for the URL given in the constructor
*
*/
virtual bool setProxy(QString const & host = 0,
int port = 80,
QString const & user = 0,
QString const & pass = 0);

/**
* \brief Returns a list of the supported layers of the WMS server
*
Expand Down
23 changes: 23 additions & 0 deletions src/raster/qgsrasterlayer.cpp
Expand Up @@ -5091,6 +5091,29 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
} // QgsRasterLayer::setDataProvider


bool QgsRasterLayer::setProxy(QString const & host,
int port,
QString const & user,
QString const & pass)
{
if (!dataProvider)
{
return FALSE;
}
else
{
#ifdef QGISDEBUG
std::cout << " QgsRasterLayer::setProxy: host = " << host.toLocal8Bit().data() << "." << std::endl;
std::cout << " QgsRasterLayer::setProxy: port = " << port << "." << std::endl;
std::cout << " QgsRasterLayer::setProxy: user = " << user.toLocal8Bit().data() << "." << std::endl;
std::cout << " QgsRasterLayer::setProxy: pass = " << pass.toLocal8Bit().data() << "." << std::endl;
#endif
return dataProvider->setProxy(host, port, user, pass);
}
}



bool QgsRasterLayer::usesProvider()
{
if (mProviderKey.isEmpty())
Expand Down
10 changes: 10 additions & 0 deletions src/raster/qgsrasterlayer.h
Expand Up @@ -1062,6 +1062,16 @@ public slots:
//! Does this layer use a provider for setting/retrieving data?
bool usesProvider();

/**
* Sets a proxy for the path given in the constructor
*
* \retval TRUE if proxy setting is successful (if indeed it is supported)
*/
bool setProxy(QString const & host = 0,
int port = 80,
QString const & user = 0,
QString const & pass = 0);

//! Which provider is being used for this Raster Layer?
QString providerKey();

Expand Down

0 comments on commit 838b262

Please sign in to comment.