int QgsRemoteDataSourceBuilder::loadData( const QString& url, QByteArray& data ) const { #if QT_VERSION < 0x050000 if ( url.startsWith( "http", Qt::CaseInsensitive ) ) { QgsHttpTransaction http( url ); if ( !http.getSynchronously( data ) ) { QgsDebugMsg( "Error, loading from http failed" ); return 1; //no success } } else if ( url.startsWith( "ftp", Qt::CaseInsensitive ) ) { Q_NOWARN_DEPRECATED_PUSH; QgsFtpTransaction ftp; if ( ftp.get( url, data ) != 0 ) { return 1; } Q_NOWARN_DEPRECATED_POP; } #else Q_UNUSED( url ) Q_UNUSED( data ) QgsDebugMsg( "http and ftp remote datasources not supported with Qt5" ); #endif return 0; }
void QgsRequestHandler::setupParameters() { const QgsServerRequest::Parameters parameters = mRequest.parameters(); // SLD QString value = parameters.value( QStringLiteral( "SLD" ) ); if ( !value.isEmpty() ) { // XXX Why keeping this ???? #if QT_VERSION < 0x050000 QByteArray fileContents; if ( value.startsWith( "http", Qt::CaseInsensitive ) ) { QgsHttpTransaction http( value ); if ( !http.getSynchronously( fileContents ) ) { fileContents.clear(); } } else if ( value.startsWith( "ftp", Qt::CaseInsensitive ) ) { Q_NOWARN_DEPRECATED_PUSH; QgsFtpTransaction ftp; if ( !ftp.get( value, fileContents ) ) { fileContents.clear(); } value = QUrl::fromPercentEncoding( fileContents ); Q_NOWARN_DEPRECATED_POP; } if fileContents.size() > 0 ) { mRequest.setParameter( QStringLiteral( "SLD" ), QUrl::fromPercentEncoding( fileContents ) ); } #else QgsMessageLog::logMessage( QStringLiteral( "http and ftp methods not supported with Qt5." ) ); #endif }
int QgsRemoteDataSourceBuilder::loadData( const QString& url, QByteArray& data ) const { if ( url.startsWith( "http", Qt::CaseInsensitive ) ) { QgsHttpTransaction http( url ); if ( !http.getSynchronously( data ) ) { QgsMSDebugMsg( "Error, loading from http failed" ); return 1; //no success } } else if ( url.startsWith( "ftp", Qt::CaseInsensitive ) ) { QgsFtpTransaction ftp; if ( ftp.get( url, data ) != 0 ) { return 1; } } return 0; }
std::map<QString, QString> QgsGetRequestHandler::parseInput() { std::map<QString, QString> parameters; QString queryString; const char* qs = getenv( "QUERY_STRING" ); if ( qs ) { queryString = QString( qs ); QgsMSDebugMsg( "query string is: " + queryString ); } else { QgsMSDebugMsg( "error, no query string found" ); return parameters; //no query string? something must be wrong... } //parameters are separated by & QStringList elements = queryString.split( "&" ); QString element, key, value; //insert key and value into the map for ( QStringList::const_iterator it = elements.begin(); it != elements.end(); ++it ) { element = *it; int sepidx = element.indexOf( "=", 0, Qt::CaseSensitive ); key = element.left( sepidx ); value = element.mid( sepidx + 1 ); value = QUrl::fromPercentEncoding( value.toLocal8Bit() ); //replace encoded special caracters and utf-8 encodings if ( key.compare( "SLD_BODY", Qt::CaseInsensitive ) == 0 ) { key = "SLD"; } else if ( key.compare( "SLD", Qt::CaseInsensitive ) == 0 ) { QByteArray fileContents; if ( value.startsWith( "http", Qt::CaseInsensitive ) ) { QgsHttpTransaction http( value ); if ( !http.getSynchronously( fileContents ) ) { continue; } } else if ( value.startsWith( "ftp", Qt::CaseInsensitive ) ) { QgsFtpTransaction ftp; if ( !ftp.get( value, fileContents ) ) { continue; } value = QUrl::fromPercentEncoding( fileContents ); } else { continue; //only http and ftp supported at the moment } value = QUrl::fromPercentEncoding( fileContents ); } parameters.insert( std::make_pair( key.toUpper(), value ) ); QgsMSDebugMsg( "inserting pair " + key.toUpper() + " // " + value + " into the parameter map" ); } //feature info format? std::map<QString, QString>::const_iterator info_format_it = parameters.find( "INFO_FORMAT" ); if ( info_format_it != parameters.end() ) { mFormat = info_format_it->second; } else //capabilities format or GetMap format { std::map<QString, QString>::const_iterator formatIt = parameters.find( "FORMAT" ); if ( formatIt != parameters.end() ) { QString formatString = formatIt->second; QgsMapServerLogger::instance()->printMessage( "formatString is: " + formatString ); //remove the image/ in front of the format if ( formatString.compare( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 ) { formatString = "PNG"; } else if ( formatString.compare( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.compare( "image/jpg", Qt::CaseInsensitive ) == 0 \ || formatString.compare( "jpg", Qt::CaseInsensitive ) == 0 ) { formatString = "JPG"; } else if ( formatString.compare( "svg", Qt::CaseInsensitive ) == 0 ) { formatString = "SVG"; } else if ( formatString.compare( "pdf", Qt::CaseInsensitive ) == 0 ) { formatString = "PDF"; } mFormat = formatString; } } return parameters; }
void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request, QMap<QString, QString>& parameters ) { parameters.clear(); //insert key and value into the map (parameters are separated by &) Q_FOREACH ( const QString& element, request.split( "&" ) ) { int sepidx = element.indexOf( "=", 0, Qt::CaseSensitive ); if ( sepidx == -1 ) { continue; } QString key = element.left( sepidx ); key = QUrl::fromPercentEncoding( key.toUtf8() ); //replace encoded special characters and utf-8 encodings QString value = element.mid( sepidx + 1 ); value.replace( "+", " " ); value = QUrl::fromPercentEncoding( value.toUtf8() ); //replace encoded special characters and utf-8 encodings if ( key.compare( "SLD_BODY", Qt::CaseInsensitive ) == 0 ) { key = "SLD"; } else if ( key.compare( "SLD", Qt::CaseInsensitive ) == 0 ) { QByteArray fileContents; if ( value.startsWith( "http", Qt::CaseInsensitive ) ) { QgsHttpTransaction http( value ); if ( !http.getSynchronously( fileContents ) ) { continue; } } else if ( value.startsWith( "ftp", Qt::CaseInsensitive ) ) { QgsFtpTransaction ftp; if ( !ftp.get( value, fileContents ) ) { continue; } value = QUrl::fromPercentEncoding( fileContents ); } else { continue; //only http and ftp supported at the moment } value = QUrl::fromPercentEncoding( fileContents ); } parameters.insert( key.toUpper(), value ); QgsMessageLog::logMessage( "inserting pair " + key.toUpper() + " // " + value + " into the parameter map" ); } //feature info format? QString infoFormat = parameters.value( "INFO_FORMAT" ); if ( !infoFormat.isEmpty() ) { mFormat = infoFormat; } else //capabilities format or GetMap format { mFormatString = parameters.value( "FORMAT" ); QString formatString = mFormatString; if ( !formatString.isEmpty() ) { QgsMessageLog::logMessage( QString( "formatString is: %1" ).arg( formatString ) ); //remove the image/ in front of the format if ( formatString.contains( "image/png", Qt::CaseInsensitive ) || formatString.compare( "png", Qt::CaseInsensitive ) == 0 ) { formatString = "PNG"; } else if ( formatString.contains( "image/jpeg", Qt::CaseInsensitive ) || formatString.contains( "image/jpg", Qt::CaseInsensitive ) || formatString.compare( "jpg", Qt::CaseInsensitive ) == 0 ) { formatString = "JPG"; } else if ( formatString.compare( "svg", Qt::CaseInsensitive ) == 0 ) { formatString = "SVG"; } else if ( formatString.contains( "pdf", Qt::CaseInsensitive ) ) { formatString = "PDF"; } mFormat = formatString; } } }
void QgsHttpRequestHandler::requestStringToParameterMap( const QString& request, std::map<QString, QString>& parameters ) { parameters.clear(); //parameters are separated by & QStringList elements = request.split( "&" ); QString element, key, value; //insert key and value into the map for ( QStringList::const_iterator it = elements.begin(); it != elements.end(); ++it ) { element = *it; int sepidx = element.indexOf( "=", 0, Qt::CaseSensitive ); if ( sepidx == -1 ) { continue; } key = element.left( sepidx ); value = element.mid( sepidx + 1 ); value.replace( "+", " " ); value = QUrl::fromPercentEncoding( value.toLocal8Bit() ); //replace encoded special caracters and utf-8 encodings if ( key.compare( "SLD_BODY", Qt::CaseInsensitive ) == 0 ) { key = "SLD"; } else if ( key.compare( "SLD", Qt::CaseInsensitive ) == 0 ) { QByteArray fileContents; if ( value.startsWith( "http", Qt::CaseInsensitive ) ) { QgsHttpTransaction http( value ); if ( !http.getSynchronously( fileContents ) ) { continue; } } else if ( value.startsWith( "ftp", Qt::CaseInsensitive ) ) { QgsFtpTransaction ftp; if ( !ftp.get( value, fileContents ) ) { continue; } value = QUrl::fromPercentEncoding( fileContents ); } else { continue; //only http and ftp supported at the moment } value = QUrl::fromPercentEncoding( fileContents ); } parameters.insert( std::make_pair( key.toUpper(), value ) ); QgsDebugMsg( "inserting pair " + key.toUpper() + " // " + value + " into the parameter map" ); } //feature info format? std::map<QString, QString>::const_iterator info_format_it = parameters.find( "INFO_FORMAT" ); if ( info_format_it != parameters.end() ) { mFormat = info_format_it->second; } else //capabilities format or GetMap format { std::map<QString, QString>::const_iterator formatIt = parameters.find( "FORMAT" ); if ( formatIt != parameters.end() ) { QString formatString = formatIt->second; QgsDebugMsg( QString( "formatString is: %1" ).arg( formatString ) ); //remove the image/ in front of the format if ( formatString.compare( "image/png", Qt::CaseInsensitive ) == 0 || formatString.compare( "png", Qt::CaseInsensitive ) == 0 ) { formatString = "PNG"; } else if ( formatString.compare( "image/jpeg", Qt::CaseInsensitive ) == 0 || formatString.compare( "image/jpg", Qt::CaseInsensitive ) == 0 \ || formatString.compare( "jpg", Qt::CaseInsensitive ) == 0 ) { formatString = "JPG"; } else if ( formatString.compare( "svg", Qt::CaseInsensitive ) == 0 ) { formatString = "SVG"; } else if ( formatString.compare( "pdf", Qt::CaseInsensitive ) == 0 ) { formatString = "PDF"; } mFormat = formatString; } } }