Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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@5070 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Mar 21, 2006
1 parent 681405f commit 8050a0b
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 254 deletions.
23 changes: 22 additions & 1 deletion src/gui/qgsserversourceselect.cpp
Expand Up @@ -341,10 +341,31 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
#endif
connStringParts += part;
}
else
{
connStringParts += "80"; // well-known http port
}

if ( ! ( (part = settings.readEntry(key + "/proxyuser")).isEmpty() ) )
{
#ifdef QGISDEBUG
std::cout << "QgsServerSourceSelect::serverConnect: Got a proxyuser - '" << part.toLocal8Bit().data() << "'." << std::endl;
#endif
connStringParts += part;

if ( ! ( (part = settings.readEntry(key + "/proxypass")).isEmpty() ) )
{
#ifdef QGISDEBUG
std::cout << "QgsServerSourceSelect::serverConnect: Got a proxypass - '" << part.toLocal8Bit().data() << "'." << std::endl;
#endif
connStringParts += part;
}
}
}

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

#ifdef QGISDEBUG
std::cout << "QgsServerSourceSelect::serverConnect: Connection info: '" << m_connInfo.toLocal8Bit().data() << "'." << std::endl;
Expand Down
78 changes: 48 additions & 30 deletions src/providers/wms/qgshttptransaction.cpp
Expand Up @@ -25,16 +25,23 @@
#include "qgshttptransaction.h"

#include <qapplication.h>
#include <q3url.h>
#include <QUrl>

#include <QTimer>

static int NETWORK_TIMEOUT_MSEC = (120 * 1000); // 120 seconds
static int HTTP_PORT_DEFAULT = 80;

QgsHttpTransaction::QgsHttpTransaction(QString uri, QString proxyHost, Q_UINT16 proxyPort)
QgsHttpTransaction::QgsHttpTransaction(QString uri,
QString proxyHost,
int proxyPort,
QString proxyUser,
QString proxyPass)
: httpurl(uri),
httphost(proxyHost),
httpport(proxyPort),
httpuser(proxyUser),
httppass(proxyPass),
httpresponsecontenttype(0),
mError(0)
{
Expand Down Expand Up @@ -77,40 +84,42 @@ bool QgsHttpTransaction::getSynchronously(QByteArray &respondedContent, int redi
std::cout << "QgsHttpTransaction::getSynchronously: Using '" << httpurl.toLocal8Bit().data() << "'." << std::endl;
#endif

Q3Url qurl(httpurl);
QString path;

QUrl qurl(httpurl);

http = new QHttp( qurl.host(), qurl.port(HTTP_PORT_DEFAULT) );

if (httphost.isEmpty())
{
// No proxy was specified - connect directly to host in URI
httphost = qurl.host();
path = qurl.encodedPathAndQuery();
}
httpport = qurl.port(HTTP_PORT_DEFAULT);

}
else
{
// Proxy -> send complete URL
path = httpurl;
// Insert proxy username and password authentication
http->setProxy( httphost, httpport, httpuser, httppass );
}
http = new Q3Http( httphost, httpport );

// int httpid1 = http->setHost( qurl.host(), qurl.port() );

mWatchdogTimer = new QTimer( this );

#ifdef QGISDEBUG
qWarning("QgsHttpTransaction::getSynchronously: qurl.host() is '"+qurl.host()+ "'.");
qWarning("QgsHttpTransaction::getSynchronously: qurl.encodedPathAndQuery() is '"+qurl.encodedPathAndQuery()+"'.");
std::cout << "path = " << path.ascii() << std::endl;
#endif

httpresponse.truncate(0);
httpid = http->get( path );
httpid = http->get( httpurl );

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

connect(http, SIGNAL( responseHeaderReceived( const Q3HttpResponseHeader& ) ),
this, SLOT( dataHeaderReceived( const Q3HttpResponseHeader& ) ) );
connect(http, SIGNAL( responseHeaderReceived( const QHttpResponseHeader& ) ),
this, SLOT( dataHeaderReceived( const QHttpResponseHeader& ) ) );

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

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

#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction::getSynchronously: Starting get." << std::endl;
std::cout << "QgsHttpTransaction::getSynchronously: Starting get with id " << httpid << "." << std::endl;
#endif

#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction::getSynchronously: Setting httpactive = TRUE" << std::endl;
#endif
httpactive = TRUE;

// A little trick to make this function blocking
while ( httpactive )
{
// Do something else, maybe even network processing events
qApp->processEvents();

// TODO: Implement a network timeout
}

Expand Down Expand Up @@ -207,7 +219,7 @@ void QgsHttpTransaction::dataStarted( int id )
}


void QgsHttpTransaction::dataHeaderReceived( const Q3HttpResponseHeader& resp )
void QgsHttpTransaction::dataHeaderReceived( const QHttpResponseHeader& resp )
{

#ifdef QGISDEBUG
Expand Down Expand Up @@ -241,7 +253,7 @@ void QgsHttpTransaction::dataHeaderReceived( const Q3HttpResponseHeader& resp )
}


void QgsHttpTransaction::dataReceived( const Q3HttpResponseHeader& resp )
void QgsHttpTransaction::dataReceived( const QHttpResponseHeader& resp )
{
// TODO: Match 'resp' with 'http' if we move to multiple http connections

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

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

#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction::getSynchronously: Setting httpactive = FALSE" << std::endl;
#endif
httpactive = FALSE;

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

switch (state)
{
case Q3Http::Unconnected:
case QHttp::Unconnected:
#ifdef QGISDEBUG
std::cout << "There is no connection to the host." << std::endl;
#endif

emit setStatus( QString("Not connected") );
break;

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

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

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

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

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

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

#ifdef QGISDEBUG
std::cout << "QgsHttpTransaction::getSynchronously: Setting httpactive = FALSE" << std::endl;
#endif
httpactive = FALSE;

#ifdef QGISDEBUG
Expand Down
29 changes: 22 additions & 7 deletions src/providers/wms/qgshttptransaction.h
Expand Up @@ -22,7 +22,8 @@
#ifndef QGSHTTPTRANSACTION_H
#define QGSHTTPTRANSACTION_H

#include <q3http.h>
#include <QHttp>
#include <QTimer>
#include <qstring.h>

/**
Expand All @@ -46,7 +47,11 @@ class QgsHttpTransaction : public QObject
/**
* Constructor.
*/
QgsHttpTransaction( QString uri, QString proxyHost = 0, Q_UINT16 proxyPort = 80 );
QgsHttpTransaction( QString uri,
QString proxyHost = QString(),
int proxyPort = 80,
QString proxyUser = QString(),
QString proxyPass = QString() );

//! Destructor
virtual ~QgsHttpTransaction();
Expand Down Expand Up @@ -79,9 +84,9 @@ public slots:

void dataStarted( int id );

void dataHeaderReceived( const Q3HttpResponseHeader& resp );
void dataHeaderReceived( const QHttpResponseHeader& resp );

void dataReceived( const Q3HttpResponseHeader& resp );
void dataReceived( const QHttpResponseHeader& resp );

void dataProgress( int done, int total );

Expand Down Expand Up @@ -109,7 +114,7 @@ public slots:
* but strange things were happening with the signals -
* therefore we use the "pointer to" instead.
*/
Q3Http* http;
QHttp* http;

/**
* Indicates the QHttp ID
Expand Down Expand Up @@ -144,8 +149,18 @@ public slots:
/**
* The port being used for this transaction
*/
Q_UINT16 httpport;

int httpport;

/**
* The username being used for this transaction
*/
QString httpuser;

/**
* The password being used for this transaction
*/
QString httppass;

/**
* If not empty, indicates that the QHttp is a redirect
* to the contents of this variable
Expand Down

0 comments on commit 8050a0b

Please sign in to comment.