Skip to content

Commit

Permalink
fix qgis mapserver on windows
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14345 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Oct 6, 2010
1 parent f64d602 commit 2e43a95
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/mapserver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ADD_DEFINITIONS(-DQGIS_LIB_DIR="\\"${QGIS_LIB_DIR}\\"")
#MH: for this we need to locate the headers of the diagram and interpolation plugin
#ADD_DEFINITIONS(-DDIAGRAMSERVER=1)

IF (CMAKE_BUILD_TYPE MATCHES Debug)
IF (CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
ADD_DEFINITIONS(-DQGSMSDEBUG=1)
ENDIF (CMAKE_BUILD_TYPE MATCHES Debug)
########################################################
Expand Down
27 changes: 6 additions & 21 deletions src/mapserver/qgis_map_serv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ map service syntax for SOAP/HTTP POST
#include <QDomDocument>
#include <QImage>
#include <QSettings>
#include <iostream>
#include <stdlib.h>
#include <QDateTime>

//for CMAKE_INSTALL_PREFIX
#include "qgsconfig.h"


#ifdef WIN32
#include <fcntl.h>
#endif //WIN32
#include <fcgi_stdio.h>


Expand All @@ -54,13 +49,7 @@ void printRequestInfos()
#ifdef QGSMSDEBUG
//print out some infos about the request
QgsMSDebugMsg( "************************new request**********************" )
time_t t;
struct tm *currentTime;
time( &t );
currentTime = localtime( &t );
QgsMSDebugMsg( QString::number( currentTime->tm_year + 1900 ) + "/" \
+ QString::number( currentTime->tm_mon + 1 ) + "/" + QString::number( currentTime->tm_mday ) + ", " \
+ QString::number( currentTime->tm_hour ) + ":" + QString::number( currentTime->tm_min ) )
QgsMSDebugMsg( QDateTime::currentDateTime().toString( "yyyy-mm-dd hh:mm:ss" ) );

if ( getenv( "REMOTE_ADDR" ) != NULL )
{
Expand Down Expand Up @@ -96,6 +85,8 @@ void printRequestInfos()
QFileInfo defaultProjectFile()
{
QDir currentDir;
QgsMSDebugMsg( "current directory: " + currentDir.absolutePath() );
fprintf( FCGI_stderr, "current directory: %s\n", currentDir.absolutePath().toUtf8().constData() );
QStringList nameFilterList;
nameFilterList << "*.qgs";
QFileInfoList projectFiles = currentDir.entryInfoList( nameFilterList, QDir::Files, QDir::Name );
Expand All @@ -115,12 +106,6 @@ QFileInfo defaultAdminSLD()

int main( int argc, char * argv[] )
{
//#ifdef WIN32 //not needed any more since the QGIS mapserver uses a modified version of libfcgi
//_setmode(_fileno(FCGI_stdout->stdio_stream),_O_BINARY); //we need binary mode to print images to stdout on windows
//#endif

//close disturbing output chanels
fclose( FCGI_stderr );
qInstallMsgHandler( dummyMessageHandler );

QgsApplication qgsapp( argc, argv, false );
Expand All @@ -131,13 +116,13 @@ int main( int argc, char * argv[] )
{
QgsApplication::setPrefixPath( prefixPath, TRUE );
}
#if !defined(Q_OS_WIN)
else
{
// init QGIS's paths - true means that all path will be inited from prefix
QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE );
}


#endif

// Instantiate the plugin directory so that providers are loaded
QgsProviderRegistry::instance( QgsApplication::pluginPath() );
Expand Down
8 changes: 0 additions & 8 deletions src/mapserver/qgshttprequesthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@

#include "qgshttprequesthandler.h"
#include <QByteArray>
#ifdef WIN32 //don't use fast cgi on windows
#include <stdio.h>
#else
#include <fcgi_stdio.h>
#endif //WIN32

QgsHttpRequestHandler::QgsHttpRequestHandler(): QgsRequestHandler()
{
Expand Down Expand Up @@ -50,9 +46,5 @@ void QgsHttpRequestHandler::sendHttpResponse( QByteArray* ba, const QString& for
printf( "\n" );
printf( "Content-Length: %d\n", ba->size() );
printf( "\n" );
#ifdef WIN32
fwrite( ba->data(), ba->size(), 1, stdout );
#else
fwrite( ba->data(), ba->size(), 1, FCGI_stdout );
#endif //WIN32
}
19 changes: 4 additions & 15 deletions src/mapserver/qgsmslayerbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,14 @@ QString QgsMSLayerBuilder::createTempFile() const
int randomNumber = rand();
QString tempFileName = QString::number( randomNumber );
QString tempFilePath;
//on windows, store the temporary file in current_path/tmp directory,
//on unix, store it in /tmp/qgis_wms_serv
#ifndef WIN32
QDir tempFileDir( "/tmp/qgis_wms_serv" );
// store temporary file in temporary qgis_wms_serv in temporary directory
QDir tempFileDir( QDir::tempPath() + "/qgis_wms_serv" );
if ( !tempFileDir.exists() ) //make sure the directory exists
{
QDir tmpDir( "/tmp" );
QDir tmpDir( QDir::tempPath() );
tmpDir.mkdir( "qgis_wms_serv" );
}
tempFilePath = "/tmp/qgis_wms_serv/" + tempFileName;
#else
QDir tempFileDir( QDir::currentPath() + "/tmp" );
if ( !tempFileDir.exists() )
{
QDir currentDir( QDir::currentPath() );
currentDir.mkdir( "tmp" );
}
tempFilePath = QDir::currentPath() + "/tmp" + "/" + tempFileName;
#endif //WIN32
tempFilePath = QDir::tempPath() + "/qgis_wms_serv/" + tempFileName;
return tempFilePath;
}

Expand Down
3 changes: 2 additions & 1 deletion src/mapserver/qgssldparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <time.h>
#include "qgslabel.h"
#include <stdlib.h>
#include <fcgi_stdio.h>


//layer builders
Expand Down Expand Up @@ -1350,7 +1351,7 @@ QgsVectorLayer* QgsSLDParser::contourLayerFromRaster( const QDomElement& userSty

if ( hDriver == NULL )
{
fprintf( stderr, "Unable to find format driver named %s.\n",
fprintf( FCGI_stderr, "Unable to find format driver named %s.\n",
pszFormat );
exit( 10 );
}
Expand Down
12 changes: 0 additions & 12 deletions src/mapserver/qgssoaprequesthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
#include <QImage>
#include <QTextStream>
#include <time.h>
#ifdef WIN32 //don't use fast cgi on windows
#include <stdio.h>
#else
#include <fcgi_stdio.h>
#endif //WIN32

QgsSOAPRequestHandler::QgsSOAPRequestHandler()
{
Expand Down Expand Up @@ -736,11 +732,7 @@ int QgsSOAPRequestHandler::sendSOAPWithAttachments( QImage* img ) const
printf( "Content-ID: <xml@mapservice>\n" );
printf( "\n" );
printf( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" );
#ifdef WIN32
fwrite( xmlByteArray.data(), xmlByteArray.size(), 1, stdout );
#else
fwrite( xmlByteArray.data(), xmlByteArray.size(), 1, FCGI_stdout );
#endif //WIN32
printf( "\n" );
printf( "\r\n" );
printf( "--MIME_boundary\r\n" );
Expand All @@ -755,11 +747,7 @@ int QgsSOAPRequestHandler::sendSOAPWithAttachments( QImage* img ) const
printf( "Content-Transfer-Encoding: binary\n" );
printf( "Content-ID: <image@mapservice>\n" );
printf( "\n" );
#ifdef WIN32
fwrite( ba.data(), ba.size(), 1, stdout );
#else
fwrite( ba.data(), ba.size(), 1, FCGI_stdout );
#endif //WIN32
printf( "\r\n" );
printf( "--MIME_boundary\r\n" );

Expand Down
3 changes: 2 additions & 1 deletion src/mapserver/qgswmsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <QPainter>
#include <QStringList>
#include <QTextStream>
#include <QDir>

QgsWMSServer::QgsWMSServer( std::map<QString, QString> parameters, QgsMapRenderer* renderer ): mParameterMap( parameters ), mConfigParser( 0 ), mMapRenderer( renderer )
{
Expand Down Expand Up @@ -213,7 +214,7 @@ QDomDocument QgsWMSServer::getCapabilities()
QgsMSDebugMsg( "Entering layersAndStylesCapabilities" )

//for debugging: save the document to disk
QFile capabilitiesFile( "/tmp/capabilities.txt" );
QFile capabilitiesFile( QDir::tempPath() + "/capabilities.txt" );
if ( capabilitiesFile.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
QTextStream capabilitiesStream( &capabilitiesFile );
Expand Down

0 comments on commit 2e43a95

Please sign in to comment.