Skip to content

Commit 394f45d

Browse files
author
morb_au
committed
More improvements for WMS:
* Experimental support for using a proxy username and password. I do not have access to test this so your results may vary. * WGS 84 bounding boxes are now reported in the layer properties under the Raster / Metadata tab. Bugfixes: * URLs ending in "&" do not get a second "&" appended. * WMS "LatLonBoundingBox"es now follow WMS layer inheritance rules. General programming: * QgsHttpTransaction now uses the Qt4 versions of QHttp and QUrl. git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5070 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 76b8c25 commit 394f45d

6 files changed

+368
-254
lines changed

src/gui/qgsserversourceselect.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,31 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
341341
#endif
342342
connStringParts += part;
343343
}
344+
else
345+
{
346+
connStringParts += "80"; // well-known http port
347+
}
348+
349+
if ( ! ( (part = settings.readEntry(key + "/proxyuser")).isEmpty() ) )
350+
{
351+
#ifdef QGISDEBUG
352+
std::cout << "QgsServerSourceSelect::serverConnect: Got a proxyuser - '" << part.toLocal8Bit().data() << "'." << std::endl;
353+
#endif
354+
connStringParts += part;
355+
356+
if ( ! ( (part = settings.readEntry(key + "/proxypass")).isEmpty() ) )
357+
{
358+
#ifdef QGISDEBUG
359+
std::cout << "QgsServerSourceSelect::serverConnect: Got a proxypass - '" << part.toLocal8Bit().data() << "'." << std::endl;
360+
#endif
361+
connStringParts += part;
362+
}
363+
}
344364
}
345365

346366
m_connName = cmbConnections->currentText();
347-
m_connInfo = connStringParts.join(" "); // url ( + " " + proxyhost + " " + proxyport)
367+
// setup 'url ( + " " + proxyhost + " " + proxyport + " " + proxyuser + " " + proxypass)'
368+
m_connInfo = connStringParts.join(" ");
348369

349370
#ifdef QGISDEBUG
350371
std::cout << "QgsServerSourceSelect::serverConnect: Connection info: '" << m_connInfo.toLocal8Bit().data() << "'." << std::endl;

src/providers/wms/qgshttptransaction.cpp

+48-30
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,23 @@
2525
#include "qgshttptransaction.h"
2626

2727
#include <qapplication.h>
28-
#include <q3url.h>
28+
#include <QUrl>
2929

3030
#include <QTimer>
3131

3232
static int NETWORK_TIMEOUT_MSEC = (120 * 1000); // 120 seconds
33+
static int HTTP_PORT_DEFAULT = 80;
3334

34-
QgsHttpTransaction::QgsHttpTransaction(QString uri, QString proxyHost, Q_UINT16 proxyPort)
35+
QgsHttpTransaction::QgsHttpTransaction(QString uri,
36+
QString proxyHost,
37+
int proxyPort,
38+
QString proxyUser,
39+
QString proxyPass)
3540
: httpurl(uri),
3641
httphost(proxyHost),
3742
httpport(proxyPort),
43+
httpuser(proxyUser),
44+
httppass(proxyPass),
3845
httpresponsecontenttype(0),
3946
mError(0)
4047
{
@@ -77,40 +84,42 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
7784
std::cout << "QgsHttpTransaction::getSynchronously: Using '" << httpurl.toLocal8Bit().data() << "'." << std::endl;
7885
#endif
7986

80-
Q3Url qurl(httpurl);
81-
QString path;
82-
87+
QUrl qurl(httpurl);
88+
89+
http = new QHttp( qurl.host(), qurl.port(HTTP_PORT_DEFAULT) );
90+
8391
if (httphost.isEmpty())
8492
{
8593
// No proxy was specified - connect directly to host in URI
8694
httphost = qurl.host();
87-
path = qurl.encodedPathAndQuery();
88-
}
95+
httpport = qurl.port(HTTP_PORT_DEFAULT);
96+
97+
}
8998
else
9099
{
91-
// Proxy -> send complete URL
92-
path = httpurl;
100+
// Insert proxy username and password authentication
101+
http->setProxy( httphost, httpport, httpuser, httppass );
93102
}
94-
http = new Q3Http( httphost, httpport );
103+
104+
// int httpid1 = http->setHost( qurl.host(), qurl.port() );
105+
95106
mWatchdogTimer = new QTimer( this );
96107

97108
#ifdef QGISDEBUG
98109
qWarning("QgsHttpTransaction::getSynchronously: qurl.host() is '"+qurl.host()+ "'.");
99-
qWarning("QgsHttpTransaction::getSynchronously: qurl.encodedPathAndQuery() is '"+qurl.encodedPathAndQuery()+"'.");
100-
std::cout << "path = " << path.ascii() << std::endl;
101110
#endif
102111

103112
httpresponse.truncate(0);
104-
httpid = http->get( path );
113+
httpid = http->get( httpurl );
105114

106115
connect(http, SIGNAL( requestStarted ( int ) ),
107116
this, SLOT( dataStarted ( int ) ) );
108117

109-
connect(http, SIGNAL( responseHeaderReceived( const Q3HttpResponseHeader& ) ),
110-
this, SLOT( dataHeaderReceived( const Q3HttpResponseHeader& ) ) );
118+
connect(http, SIGNAL( responseHeaderReceived( const QHttpResponseHeader& ) ),
119+
this, SLOT( dataHeaderReceived( const QHttpResponseHeader& ) ) );
111120

112-
connect(http, SIGNAL( readyRead( const Q3HttpResponseHeader& ) ),
113-
this, SLOT( dataReceived( const Q3HttpResponseHeader& ) ) );
121+
connect(http, SIGNAL( readyRead( const QHttpResponseHeader& ) ),
122+
this, SLOT( dataReceived( const QHttpResponseHeader& ) ) );
114123

115124
connect(http, SIGNAL( dataReadProgress ( int, int ) ),
116125
this, SLOT( dataProgress ( int, int ) ) );
@@ -129,17 +138,20 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
129138
mWatchdogTimer->start(NETWORK_TIMEOUT_MSEC);
130139

131140
#ifdef QGISDEBUG
132-
std::cout << "QgsHttpTransaction::getSynchronously: Starting get." << std::endl;
141+
std::cout << "QgsHttpTransaction::getSynchronously: Starting get with id " << httpid << "." << std::endl;
133142
#endif
134143

144+
#ifdef QGISDEBUG
145+
std::cout << "QgsHttpTransaction::getSynchronously: Setting httpactive = TRUE" << std::endl;
146+
#endif
135147
httpactive = TRUE;
136148

137149
// A little trick to make this function blocking
138150
while ( httpactive )
139151
{
140152
// Do something else, maybe even network processing events
141153
qApp->processEvents();
142-
154+
143155
// TODO: Implement a network timeout
144156
}
145157

@@ -207,7 +219,7 @@ void QgsHttpTransaction::dataStarted( int id )
207219
}
208220

209221

210-
void QgsHttpTransaction::dataHeaderReceived( const Q3HttpResponseHeader& resp )
222+
void QgsHttpTransaction::dataHeaderReceived( const QHttpResponseHeader& resp )
211223
{
212224

213225
#ifdef QGISDEBUG
@@ -241,7 +253,7 @@ void QgsHttpTransaction::dataHeaderReceived( const Q3HttpResponseHeader& resp )
241253
}
242254

243255

244-
void QgsHttpTransaction::dataReceived( const Q3HttpResponseHeader& resp )
256+
void QgsHttpTransaction::dataReceived( const QHttpResponseHeader& resp )
245257
{
246258
// TODO: Match 'resp' with 'http' if we move to multiple http connections
247259

@@ -295,8 +307,8 @@ void QgsHttpTransaction::dataFinished( int id, bool error )
295307
#ifdef QGISDEBUG
296308
std::cout << "QgsHttpTransaction::dataFinished with ID " << id << "." << std::endl;
297309

298-
// The signal that this slot is connected to, Q3Http::requestFinished,
299-
// appears to get called at the destruction of the Q3Http if it is
310+
// The signal that this slot is connected to, QHttp::requestFinished,
311+
// appears to get called at the destruction of the QHttp if it is
300312
// still working at the time of the destruction.
301313
//
302314
// This situation may occur when we've detected a timeout and
@@ -327,6 +339,9 @@ void QgsHttpTransaction::dataFinished( int id, bool error )
327339
// TODO
328340
httpresponse = http->readAll();
329341

342+
#ifdef QGISDEBUG
343+
std::cout << "QgsHttpTransaction::getSynchronously: Setting httpactive = FALSE" << std::endl;
344+
#endif
330345
httpactive = FALSE;
331346

332347
}
@@ -343,15 +358,15 @@ void QgsHttpTransaction::dataStateChanged( int state )
343358

344359
switch (state)
345360
{
346-
case Q3Http::Unconnected:
361+
case QHttp::Unconnected:
347362
#ifdef QGISDEBUG
348363
std::cout << "There is no connection to the host." << std::endl;
349364
#endif
350365

351366
emit setStatus( QString("Not connected") );
352367
break;
353368

354-
case Q3Http::HostLookup:
369+
case QHttp::HostLookup:
355370
#ifdef QGISDEBUG
356371
std::cout << "A host name lookup is in progress." << std::endl;
357372
#endif
@@ -360,7 +375,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
360375
.arg(httphost) );
361376
break;
362377

363-
case Q3Http::Connecting:
378+
case QHttp::Connecting:
364379
#ifdef QGISDEBUG
365380
std::cout << "An attempt to connect to the host is in progress." << std::endl;
366381
#endif
@@ -369,7 +384,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
369384
.arg(httphost) );
370385
break;
371386

372-
case Q3Http::Sending:
387+
case QHttp::Sending:
373388
#ifdef QGISDEBUG
374389
std::cout << "The client is sending its request to the server." << std::endl;
375390
#endif
@@ -378,7 +393,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
378393
.arg(httpurl) );
379394
break;
380395

381-
case Q3Http::Reading:
396+
case QHttp::Reading:
382397
#ifdef QGISDEBUG
383398
std::cout << "The client's request has been sent and the client "
384399
"is reading the server's response." << std::endl;
@@ -387,7 +402,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
387402
emit setStatus( QString("Receiving reply") );
388403
break;
389404

390-
case Q3Http::Connected:
405+
case QHttp::Connected:
391406
#ifdef QGISDEBUG
392407
std::cout << "The connection to the host is open, but the client "
393408
"is neither sending a request, nor waiting for a response." << std::endl;
@@ -396,7 +411,7 @@ void QgsHttpTransaction::dataStateChanged( int state )
396411
emit setStatus( QString("Response is complete") );
397412
break;
398413

399-
case Q3Http::Closing:
414+
case QHttp::Closing:
400415
#ifdef QGISDEBUG
401416
std::cout << "The connection is closing down, but is not yet closed. "
402417
"(The state will be Unconnected when the connection is closed.)" << std::endl;
@@ -420,6 +435,9 @@ void QgsHttpTransaction::networkTimedOut()
420435
"This may be a problem in your network connection or at the WMS server.")
421436
).arg(NETWORK_TIMEOUT_MSEC/1000);
422437

438+
#ifdef QGISDEBUG
439+
std::cout << "QgsHttpTransaction::getSynchronously: Setting httpactive = FALSE" << std::endl;
440+
#endif
423441
httpactive = FALSE;
424442

425443
#ifdef QGISDEBUG

src/providers/wms/qgshttptransaction.h

+22-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#ifndef QGSHTTPTRANSACTION_H
2323
#define QGSHTTPTRANSACTION_H
2424

25-
#include <q3http.h>
25+
#include <QHttp>
26+
#include <QTimer>
2627
#include <qstring.h>
2728

2829
/**
@@ -46,7 +47,11 @@ class QgsHttpTransaction : public QObject
4647
/**
4748
* Constructor.
4849
*/
49-
QgsHttpTransaction( QString uri, QString proxyHost = 0, Q_UINT16 proxyPort = 80 );
50+
QgsHttpTransaction( QString uri,
51+
QString proxyHost = QString(),
52+
int proxyPort = 80,
53+
QString proxyUser = QString(),
54+
QString proxyPass = QString() );
5055

5156
//! Destructor
5257
virtual ~QgsHttpTransaction();
@@ -79,9 +84,9 @@ public slots:
7984

8085
void dataStarted( int id );
8186

82-
void dataHeaderReceived( const Q3HttpResponseHeader& resp );
87+
void dataHeaderReceived( const QHttpResponseHeader& resp );
8388

84-
void dataReceived( const Q3HttpResponseHeader& resp );
89+
void dataReceived( const QHttpResponseHeader& resp );
8590

8691
void dataProgress( int done, int total );
8792

@@ -109,7 +114,7 @@ public slots:
109114
* but strange things were happening with the signals -
110115
* therefore we use the "pointer to" instead.
111116
*/
112-
Q3Http* http;
117+
QHttp* http;
113118

114119
/**
115120
* Indicates the QHttp ID
@@ -144,8 +149,18 @@ public slots:
144149
/**
145150
* The port being used for this transaction
146151
*/
147-
Q_UINT16 httpport;
148-
152+
int httpport;
153+
154+
/**
155+
* The username being used for this transaction
156+
*/
157+
QString httpuser;
158+
159+
/**
160+
* The password being used for this transaction
161+
*/
162+
QString httppass;
163+
149164
/**
150165
* If not empty, indicates that the QHttp is a redirect
151166
* to the contents of this variable

0 commit comments

Comments
 (0)