Skip to content

Commit 838b262

Browse files
author
morb_au
committed
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
1 parent 300c6e6 commit 838b262

8 files changed

+156
-64
lines changed

src/core/qgsrasterdataprovider.h

+15
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ class QgsRasterDataProvider : public QgsDataProvider
6161

6262
virtual ~QgsRasterDataProvider() {};
6363

64+
/**
65+
*
66+
* Sets a proxy for the URL given in the constructor
67+
*
68+
*
69+
* \retval TRUE if proxy setting is successful (if indeed it is supported)
70+
*/
71+
virtual bool setProxy(QString const & host,
72+
int port,
73+
QString const & user,
74+
QString const & pass)
75+
{
76+
return FALSE;
77+
}
78+
6479
/**
6580
* Add the list of WMS layer names to be rendered by this server
6681
*/

src/gui/qgsserversourceselect.cpp

+40-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
348348
QString part;
349349

350350
connStringParts += settings.readEntry(key + "/url");
351-
351+
352+
/*
352353
// Add the proxy host and port if any are defined.
353354
if ( ! ( (part = settings.readEntry(key + "/proxyhost")).isEmpty() ) )
354355
{
@@ -384,7 +385,8 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
384385
connStringParts += part;
385386
}
386387
}
387-
}
388+
}
389+
*/
388390

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

412+
// Collect and set HTTP proxy on WMS provider
413+
414+
m_connProxyHost = settings.readEntry(key + "/proxyhost"),
415+
m_connProxyPort = settings.readEntry(key + "/proxyport").toInt(),
416+
m_connProxyUser = settings.readEntry(key + "/proxyuser"),
417+
m_connProxyPass = settings.readEntry(key + "/proxypass"),
418+
419+
mWmsProvider->setProxy(
420+
m_connProxyHost,
421+
m_connProxyPort,
422+
m_connProxyUser,
423+
m_connProxyPass
424+
);
425+
426+
// WMS Provider all set up; let's get some layers
427+
410428
if (!populateLayerList(mWmsProvider))
411429
{
412430
showError(mWmsProvider);
@@ -577,6 +595,26 @@ QString QgsServerSourceSelect::connInfo()
577595
return m_connInfo;
578596
}
579597

598+
QString QgsServerSourceSelect::connProxyHost()
599+
{
600+
return m_connProxyHost;
601+
}
602+
603+
int QgsServerSourceSelect::connProxyPort()
604+
{
605+
return m_connProxyPort;
606+
}
607+
608+
QString QgsServerSourceSelect::connProxyUser()
609+
{
610+
return m_connProxyUser;
611+
}
612+
613+
QString QgsServerSourceSelect::connProxyPass()
614+
{
615+
return m_connProxyPass;
616+
}
617+
580618
QStringList QgsServerSourceSelect::selectedLayers()
581619
{
582620
return m_selectedLayers;

src/gui/qgsserversourceselect.h

+30-1
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,25 @@ class QgsServerSourceSelect : public QDialog, private Ui::QgsServerSourceSelectB
5252

5353
//! Connection name
5454
QString connName();
55+
5556
//! Connection info (uri)
5657
QString connInfo();
5758

59+
//! Connection Proxy Host
60+
QString connProxyHost();
61+
62+
//! Connection Proxy Port
63+
int connProxyPort();
64+
65+
//! Connection Proxy User
66+
QString connProxyUser();
67+
68+
//! Connection Proxy Pass
69+
QString connProxyPass();
70+
5871
//! String list containing the selected layers
5972
QStringList selectedLayers();
73+
6074
//! String list containing the visual styles selected for the selected layers - this corresponds with the output from selectedLayers()
6175
QStringList selectedStylesForSelectedLayers();
6276

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

129-
143+
//! Name for selected connection
130144
QString m_connName;
145+
146+
//! URI for selected connection
131147
QString m_connInfo;
148+
149+
//! Proxy Host for selected connection
150+
QString m_connProxyHost;
151+
152+
//! Proxy Port for selected connection
153+
int m_connProxyPort;
154+
155+
//! Proxy User for selected connection
156+
QString m_connProxyUser;
157+
158+
//! Proxy Pass for selected connection
159+
QString m_connProxyPass;
160+
132161
QStringList m_selectedLayers;
133162
QStringList m_selectedStylesForSelectedLayers;
134163
long m_Epsg;

src/providers/wms/qgshttptransaction.cpp

+13-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ QgsHttpTransaction::QgsHttpTransaction(QString uri,
4747
#ifdef QGISDEBUG
4848
std::cout << "QgsHttpTransaction: constructing." << std::endl;
4949
#endif
50-
50+
51+
#ifdef QGISDEBUG
52+
std::cout << " QgsHttpTransaction: proxyHost = " << proxyHost.toLocal8Bit().data() << "." << std::endl;
53+
std::cout << " QgsHttpTransaction: proxyPort = " << proxyPort << "." << std::endl;
54+
std::cout << " QgsHttpTransaction: proxyUser = " << proxyUser.toLocal8Bit().data() << "." << std::endl;
55+
std::cout << " QgsHttpTransaction: proxyPass = " << proxyPass.toLocal8Bit().data() << "." << std::endl;
56+
#endif
57+
5158

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

126133
connect(http, SIGNAL( readyRead( const QHttpResponseHeader& ) ),
127-
this, SLOT( dataReceived( const QHttpResponseHeader& ) ) );
134+
this, SLOT( dataReceived( const QHttpResponseHeader& ) ) );
128135

129136
connect(http, SIGNAL( dataReadProgress ( int, int ) ),
130-
this, SLOT( dataProgress ( int, int ) ) );
137+
this, SLOT( dataProgress ( int, int ) ) );
131138

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

135142
connect(http, SIGNAL( stateChanged ( int ) ),
136-
this, SLOT( dataStateChanged ( int ) ) );
143+
this, SLOT( dataStateChanged ( int ) ) );
137144

138145
// Set up the watchdog timer
139146
connect(mWatchdogTimer, SIGNAL( timeout () ),
@@ -156,6 +163,7 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
156163
{
157164
// Do something else, maybe even network processing events
158165
qApp->processEvents();
166+
159167
// TODO: Implement a network timeout
160168
}
161169

@@ -282,7 +290,7 @@ void QgsHttpTransaction::dataProgress( int done, int total )
282290
{
283291

284292
#ifdef QGISDEBUG
285-
std::cout << "QgsHttpTransaction::dataProgress: got " << done << " of " << total << std::endl;
293+
// std::cout << "QgsHttpTransaction::dataProgress: got " << done << " of " << total << std::endl;
286294
#endif
287295

288296
// We saw something come back, therefore restart the watchdog timer

src/providers/wms/qgswmsprovider.cpp

+14-54
Original file line numberDiff line numberDiff line change
@@ -75,67 +75,15 @@ QgsWmsProvider::QgsWmsProvider(QString const & uri)
7575
// assume this is a valid layer until we determine otherwise
7676
valid = true;
7777

78-
// URI is in form: URL[ proxyhost[ proxyport[ proxyuser[ proxypass]]]
79-
80-
// Split proxy from the provider-encoded uri
81-
QStringList drawuriparts = QStringList::split(" ", httpuri, TRUE);
82-
83-
baseUrl = drawuriparts.front();
84-
drawuriparts.pop_front();
85-
86-
if (drawuriparts.count())
87-
{
88-
mHttpProxyHost = drawuriparts.front();
89-
drawuriparts.pop_front();
90-
91-
if (drawuriparts.count())
92-
{
93-
bool conversionOK;
94-
mHttpProxyPort = drawuriparts.front().toInt(&conversionOK);
95-
if (!conversionOK)
96-
{
97-
mHttpProxyPort = 80; // standard HTTP port
98-
}
99-
100-
drawuriparts.pop_front();
101-
102-
if (drawuriparts.count())
103-
{
104-
bool conversionOK;
105-
mHttpProxyUser = drawuriparts.front();
106-
107-
drawuriparts.pop_front();
108-
109-
if (drawuriparts.count())
110-
{
111-
bool conversionOK;
112-
mHttpProxyPass = drawuriparts.front();
113-
114-
drawuriparts.pop_front();
115-
116-
}
117-
else
118-
{
119-
mHttpProxyPass = QString(); // none
120-
}
121-
}
122-
else
123-
{
124-
mHttpProxyUser = QString(); // anonymous
125-
}
126-
}
127-
else
128-
{
129-
mHttpProxyPort = 80; // standard HTTP port
130-
}
131-
}
13278

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

13884
// Prepare the URI so that we can later simply append param=value
85+
baseUrl = httpuri;
86+
13987
if ( !(baseUrl.contains("?")) )
14088
{
14189
baseUrl.append("?");
@@ -198,6 +146,18 @@ QgsWmsProvider::~QgsWmsProvider()
198146

199147
}
200148

149+
bool QgsWmsProvider::setProxy(QString const & host,
150+
int port,
151+
QString const & user,
152+
QString const & pass)
153+
{
154+
mHttpProxyHost = host;
155+
mHttpProxyPort = port;
156+
mHttpProxyUser = user;
157+
mHttpProxyPass = pass;
158+
159+
return TRUE;
160+
}
201161

202162
bool QgsWmsProvider::supportedLayers(std::vector<QgsWmsLayerProperty> & layers)
203163
{

src/providers/wms/qgswmsprovider.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ class QgsWmsProvider : public QgsRasterDataProvider
347347
/**
348348
* Constructor for the provider.
349349
*
350-
* \param uri HTTP URL of the Web Server, optionally followed by a space then the proxy host name,
351-
* another space, and the proxy host port. If no proxy is declared then we will
350+
* \param uri HTTP URL of the Web Server. If setProxy() is not also called then we will
352351
* contact the host directly.
353352
*
354353
*/
@@ -357,6 +356,16 @@ class QgsWmsProvider : public QgsRasterDataProvider
357356
//! Destructor
358357
virtual ~QgsWmsProvider();
359358

359+
/**
360+
*
361+
* Sets an HTTP proxy for the URL given in the constructor
362+
*
363+
*/
364+
virtual bool setProxy(QString const & host = 0,
365+
int port = 80,
366+
QString const & user = 0,
367+
QString const & pass = 0);
368+
360369
/**
361370
* \brief Returns a list of the supported layers of the WMS server
362371
*

src/raster/qgsrasterlayer.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -5091,6 +5091,29 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
50915091
} // QgsRasterLayer::setDataProvider
50925092

50935093

5094+
bool QgsRasterLayer::setProxy(QString const & host,
5095+
int port,
5096+
QString const & user,
5097+
QString const & pass)
5098+
{
5099+
if (!dataProvider)
5100+
{
5101+
return FALSE;
5102+
}
5103+
else
5104+
{
5105+
#ifdef QGISDEBUG
5106+
std::cout << " QgsRasterLayer::setProxy: host = " << host.toLocal8Bit().data() << "." << std::endl;
5107+
std::cout << " QgsRasterLayer::setProxy: port = " << port << "." << std::endl;
5108+
std::cout << " QgsRasterLayer::setProxy: user = " << user.toLocal8Bit().data() << "." << std::endl;
5109+
std::cout << " QgsRasterLayer::setProxy: pass = " << pass.toLocal8Bit().data() << "." << std::endl;
5110+
#endif
5111+
return dataProvider->setProxy(host, port, user, pass);
5112+
}
5113+
}
5114+
5115+
5116+
50945117
bool QgsRasterLayer::usesProvider()
50955118
{
50965119
if (mProviderKey.isEmpty())

src/raster/qgsrasterlayer.h

+10
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,16 @@ public slots:
10621062
//! Does this layer use a provider for setting/retrieving data?
10631063
bool usesProvider();
10641064

1065+
/**
1066+
* Sets a proxy for the path given in the constructor
1067+
*
1068+
* \retval TRUE if proxy setting is successful (if indeed it is supported)
1069+
*/
1070+
bool setProxy(QString const & host = 0,
1071+
int port = 80,
1072+
QString const & user = 0,
1073+
QString const & pass = 0);
1074+
10651075
//! Which provider is being used for this Raster Layer?
10661076
QString providerKey();
10671077

0 commit comments

Comments
 (0)