Skip to content
Permalink
Browse files
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/qgis@5605 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Jul 16, 2006
1 parent 4744b7b commit fc5e7d51923d2877cf7cca51a09faa8035e7ec78
@@ -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
*/
@@ -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() ) )
{
@@ -384,7 +385,8 @@ void QgsServerSourceSelect::on_btnConnect_clicked()
connStringParts += part;
}
}
}
}
*/

m_connName = cmbConnections->currentText();
// setup 'url ( + " " + proxyhost + " " + proxyport + " " + proxyuser + " " + proxypass)'
@@ -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);
@@ -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;
@@ -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();

@@ -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;
@@ -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;
@@ -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 () ),
@@ -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
}

@@ -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
@@ -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("?");
@@ -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)
{
@@ -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.
*
*/
@@ -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
*
@@ -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())
@@ -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();

0 comments on commit fc5e7d5

Please sign in to comment.