@@ -817,24 +817,36 @@ bool QgsWmsProvider::downloadCapabilitiesURI(QString const & uri)
817817
818818}
819819*/
820-
820+ # include < fstream >
821821bool QgsWmsProvider::parseCapabilitiesDOM (QByteArray const & xml, QgsWmsCapabilitiesProperty& capabilitiesProperty)
822822{
823- #ifdef QGISDEBUG
823+ // #ifdef QGISDEBUG
824824 std::cout << " QgsWmsProvider::parseCapabilitiesDOM: entering." << std::endl;
825825
826- // test the content of the QByteArray
827- QString responsestring (xml);
828- qWarning (" QgsWmsProvider::parseCapabilitiesDOM, received the following data: " +responsestring);
829-
826+ // test the content of the QByteArray.
827+ // There is a bug in Qt4.1.2, due for fixing in 4.2.0, where
828+ // QString(QByteArray) uses strlen to find the length of the
829+ // QByteArray. However, there are no guarantees that the QByteArray
830+ // has a terminating \0, and hence this can cause a crash, so we supply
831+ // the qbytearray to qstring in a way that ensures that there is a
832+ // terminating \0, and just to be safe, we also give it the actual
833+ // size.
834+
835+ // Also, the Qt qWarning() function has a limit of 8192 bytes per
836+ // message, which can easily be exceeded by wms capability
837+ // documents, so we use the qgs logger stuff instead which doesn't
838+ // have that limitation.
839+
840+ QString responsestring (QString::fromAscii (xml.constData (), xml.size ()));
841+ QgsLogger::debug (" QgsWmsProvider::parseCapabilitiesDOM, received the following data: " +responsestring);
830842
831843 // QFile file( "/tmp/qgis-wmsprovider-capabilities.xml" );
832844 // if ( file.open( QIODevice::WriteOnly ) )
833845 // {
834846 // file.writeBlock(xml);
835847 // file.close();
836848 // }
837- #endif
849+ // #endif
838850
839851 // Convert completed document into a DOM
840852 QString errorMsg;
@@ -852,9 +864,7 @@ bool QgsWmsProvider::parseCapabilitiesDOM(QByteArray const & xml, QgsWmsCapabili
852864
853865 mError += " \n " + tr (" This is probably due to an incorrect WMS Server URL." );
854866
855- #ifdef QGISDEBUG
856- qWarning (" DOM Exception: " +mError );
857- #endif
867+ QgsLogger::debug (" DOM Exception: " +mError );
858868
859869 return FALSE ;
860870 }
@@ -884,9 +894,7 @@ bool QgsWmsProvider::parseCapabilitiesDOM(QByteArray const & xml, QgsWmsCapabili
884894
885895 mError += " \n " + tr (" This is probably due to an incorrect WMS Server URL." );
886896
887- #ifdef QGISDEBUG
888- qWarning (" DOM Exception: " +mError );
889- #endif
897+ QgsLogger::debug (" DOM Exception: " +mError );
890898
891899 return FALSE ;
892900 }
@@ -1676,7 +1684,7 @@ bool QgsWmsProvider::parseServiceExceptionReportDOM(QByteArray const & xml)
16761684
16771685 // test the content of the QByteArray
16781686 QString responsestring (xml);
1679- qWarning (" QgsWmsProvider::parseServiceExceptionReportDOM, received the following data: " +responsestring);
1687+ QgsLogger::debug (" QgsWmsProvider::parseServiceExceptionReportDOM, received the following data: " +responsestring);
16801688#endif
16811689
16821690 // Convert completed document into a DOM
@@ -1694,9 +1702,7 @@ bool QgsWmsProvider::parseServiceExceptionReportDOM(QByteArray const & xml)
16941702 .arg (errorLine)
16951703 .arg (errorColumn) );
16961704
1697- #ifdef QGISDEBUG
1698- qWarning (" DOM Exception: " +mError );
1699- #endif
1705+ QgsLogger::debug (" DOM Exception: " +mError );
17001706
17011707 return FALSE ;
17021708 }
0 commit comments