1
1
/* **************************************************************************
2
2
qgs_map_serv.cpp
3
- A server application supporting WMS/SLD syntax for HTTP GET and Orchestra
4
- map service syntax for SOAP/HTTP POST
3
+ A server application supporting WMS / WFS / WCS
5
4
-------------------
6
5
begin : July 04, 2006
7
6
copyright : (C) 2006 by Marco Hugentobler & Ionut Iosifescu Enescu
@@ -50,8 +49,6 @@ map service syntax for SOAP/HTTP POST
50
49
51
50
void dummyMessageHandler ( QtMsgType type, const char *msg )
52
51
{
53
- Q_UNUSED ( type );
54
- Q_UNUSED ( msg );
55
52
#ifdef QGSMSDEBUG
56
53
QString output;
57
54
@@ -76,6 +73,9 @@ void dummyMessageHandler( QtMsgType type, const char *msg )
76
73
77
74
if ( type == QtFatalMsg )
78
75
abort ();
76
+ #else
77
+ Q_UNUSED ( type );
78
+ Q_UNUSED ( msg );
79
79
#endif
80
80
}
81
81
@@ -133,12 +133,10 @@ void printRequestInfos()
133
133
QFileInfo defaultProjectFile ()
134
134
{
135
135
QDir currentDir;
136
- QgsDebugMsg ( " current directory: " + currentDir.absolutePath () );
137
136
fprintf ( FCGI_stderr, " current directory: %s\n " , currentDir.absolutePath ().toUtf8 ().constData () );
138
137
QStringList nameFilterList;
139
138
nameFilterList << " *.qgs" ;
140
139
QFileInfoList projectFiles = currentDir.entryInfoList ( nameFilterList, QDir::Files, QDir::Name );
141
- QgsDebugMsg ( " Project files found:" );
142
140
for ( int x = 0 ; x < projectFiles.size (); x++ )
143
141
{
144
142
QgsDebugMsg ( projectFiles.at ( x ).absoluteFilePath () );
@@ -167,6 +165,69 @@ int fcgi_accept()
167
165
#endif
168
166
}
169
167
168
+ void setupNetworkAccessManager ()
169
+ {
170
+ QSettings settings;
171
+ QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance ();
172
+ QNetworkDiskCache *cache = new QNetworkDiskCache ( 0 );
173
+ QString cacheDirectory = settings.value ( " cache/directory" , QgsApplication::qgisSettingsDirPath () + " cache" ).toString ();
174
+ qint64 cacheSize = settings.value ( " cache/size" , 50 * 1024 * 1024 ).toULongLong ();
175
+ QgsDebugMsg ( QString ( " setCacheDirectory: %1" ).arg ( cacheDirectory ) );
176
+ QgsDebugMsg ( QString ( " setMaximumCacheSize: %1" ).arg ( cacheSize ) );
177
+ cache->setCacheDirectory ( cacheDirectory );
178
+ cache->setMaximumCacheSize ( cacheSize );
179
+ QgsDebugMsg ( QString ( " cacheDirectory: %1" ).arg ( cache->cacheDirectory () ) );
180
+ QgsDebugMsg ( QString ( " maximumCacheSize: %1" ).arg ( cache->maximumCacheSize () ) );
181
+ nam->setCache ( cache );
182
+ }
183
+
184
+ QgsRequestHandler* createRequestHandler ()
185
+ {
186
+ QgsRequestHandler* requestHandler = 0 ;
187
+ char * requestMethod = getenv ( " REQUEST_METHOD" );
188
+ if ( requestMethod != NULL )
189
+ {
190
+ if ( strcmp ( requestMethod, " POST" ) == 0 )
191
+ {
192
+ // requestHandler = new QgsSOAPRequestHandler();
193
+ requestHandler = new QgsPostRequestHandler ();
194
+ }
195
+ else
196
+ {
197
+ requestHandler = new QgsGetRequestHandler ();
198
+ }
199
+ }
200
+ else
201
+ {
202
+ requestHandler = new QgsGetRequestHandler ();
203
+ }
204
+ return requestHandler;
205
+ }
206
+
207
+ QString configPath ( const QString& defaultConfigPath, const QMap<QString, QString>& parameters )
208
+ {
209
+ QString cfPath ( defaultConfigPath );
210
+ QString projectFile = getenv ( " QGIS_PROJECT_FILE" );
211
+ if ( !projectFile.isEmpty () )
212
+ {
213
+ cfPath = projectFile;
214
+ }
215
+ else
216
+ {
217
+ QMap<QString, QString>::const_iterator paramIt = parameters.find ( " MAP" );
218
+ if ( paramIt == parameters.constEnd () )
219
+ {
220
+ QgsDebugMsg ( QString ( " Using default configuration file path: %1" ).arg ( defaultConfigPath ) );
221
+ }
222
+ else
223
+ {
224
+ cfPath = paramIt.value ();
225
+ }
226
+ }
227
+ return cfPath;
228
+ }
229
+
230
+
170
231
int main ( int argc, char * argv[] )
171
232
{
172
233
#ifndef _MSC_VER
@@ -188,22 +249,7 @@ int main( int argc, char * argv[] )
188
249
QgsApplication::skipGdalDriver ( " JP2ECW" );
189
250
#endif
190
251
191
- QSettings settings;
192
-
193
- QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance ();
194
- QNetworkDiskCache *cache = new QNetworkDiskCache ( 0 );
195
-
196
- QString cacheDirectory = settings.value ( " cache/directory" , QgsApplication::qgisSettingsDirPath () + " cache" ).toString ();
197
- qint64 cacheSize = settings.value ( " cache/size" , 50 * 1024 * 1024 ).toULongLong ();
198
- QgsDebugMsg ( QString ( " setCacheDirectory: %1" ).arg ( cacheDirectory ) );
199
- QgsDebugMsg ( QString ( " setMaximumCacheSize: %1" ).arg ( cacheSize ) );
200
- cache->setCacheDirectory ( cacheDirectory );
201
- cache->setMaximumCacheSize ( cacheSize );
202
- QgsDebugMsg ( QString ( " cacheDirectory: %1" ).arg ( cache->cacheDirectory () ) );
203
- QgsDebugMsg ( QString ( " maximumCacheSize: %1" ).arg ( cache->maximumCacheSize () ) );
204
-
205
- nam->setCache ( cache );
206
-
252
+ setupNetworkAccessManager ();
207
253
QDomImplementation::setInvalidDataPolicy ( QDomImplementation::DropInvalidChars );
208
254
209
255
// Instantiate the plugin directory so that providers are loaded
@@ -216,8 +262,6 @@ int main( int argc, char * argv[] )
216
262
QgsDebugMsg ( qgsapp.applicationDirPath () + " /qgis_wms_server.log" );
217
263
QgsApplication::createDB (); // init qgis.db (e.g. necessary for user crs)
218
264
219
- // create config cache and search for config files in the current directory.
220
- // These configurations are used if no mapfile parameter is present in the request
221
265
QString defaultConfigFilePath;
222
266
QFileInfo projectFileInfo = defaultProjectFile (); // try to find a .qgs file in the server directory
223
267
if ( projectFileInfo.exists () )
@@ -245,37 +289,13 @@ int main( int argc, char * argv[] )
245
289
QgsFontUtils::loadStandardTestFonts ( QStringList () << " Roman" << " Bold" );
246
290
#endif
247
291
248
-
249
- // for( int i = 0; i < 2; ++i )
250
292
while ( fcgi_accept () >= 0 )
251
293
{
252
294
printRequestInfos (); // print request infos if in debug mode
253
295
254
- // use QgsGetRequestHandler in case of HTTP GET and QgsSOAPRequestHandler in case of HTTP POST
255
- QgsRequestHandler* theRequestHandler = 0 ;
256
- char * requestMethod = getenv ( " REQUEST_METHOD" );
257
- if ( requestMethod != NULL )
258
- {
259
- if ( strcmp ( requestMethod, " POST" ) == 0 )
260
- {
261
- // QgsDebugMsg( "Creating QgsSOAPRequestHandler" );
262
- // theRequestHandler = new QgsSOAPRequestHandler();
263
- theRequestHandler = new QgsPostRequestHandler ();
264
- }
265
- else
266
- {
267
- QgsDebugMsg ( " Creating QgsGetRequestHandler" );
268
- theRequestHandler = new QgsGetRequestHandler ();
269
- }
270
- }
271
- else
272
- {
273
- QgsDebugMsg ( " Creating QgsGetRequestHandler" );
274
- theRequestHandler = new QgsGetRequestHandler ();
275
- }
276
-
296
+ // Request handler
297
+ QgsRequestHandler* theRequestHandler = createRequestHandler ();
277
298
QMap<QString, QString> parameterMap;
278
-
279
299
try
280
300
{
281
301
parameterMap = theRequestHandler->parseInput ();
@@ -289,51 +309,27 @@ int main( int argc, char * argv[] )
289
309
290
310
QMap<QString, QString>::const_iterator paramIt;
291
311
292
- // set admin config file to wms server object
293
- QString configFilePath ( defaultConfigFilePath );
294
-
295
- QString projectFile = getenv ( " QGIS_PROJECT_FILE" );
296
- if ( !projectFile.isEmpty () )
297
- {
298
- configFilePath = projectFile;
299
- }
300
- else
301
- {
302
- paramIt = parameterMap.find ( " MAP" );
303
- if ( paramIt == parameterMap.constEnd () )
304
- {
305
- QgsDebugMsg ( QString ( " Using default configuration file path: %1" ).arg ( defaultConfigFilePath ) );
306
- }
307
- else
308
- {
309
- configFilePath = paramIt.value ();
310
- }
311
- }
312
+ // Config file path
313
+ QString configFilePath = configPath ( defaultConfigFilePath, parameterMap );
312
314
315
+ // Admin config parser
313
316
QgsConfigParser* adminConfigParser = QgsConfigCache::instance ()->searchConfiguration ( configFilePath );
314
317
if ( !adminConfigParser )
315
318
{
316
319
QgsDebugMsg ( " parse error on config file " + configFilePath );
317
320
theRequestHandler->sendServiceException ( QgsMapServiceException ( " " , " Configuration file problem : perhaps you left off the .qgs extension?" ) );
318
321
continue ;
319
322
}
320
-
321
- // sld parser might need information about request parameters
322
323
adminConfigParser->setParameterMap ( parameterMap );
323
324
324
- // request to WMS?
325
+ // Service parameter
325
326
QString serviceString;
326
327
paramIt = parameterMap.find ( " SERVICE" );
327
328
if ( paramIt == parameterMap.constEnd () )
328
329
{
329
- #ifndef QGISDEBUG
330
- serviceString = parameterMap.value ( " SERVICE" , " WMS" );
331
- #else
332
- QgsDebugMsg ( " unable to find 'SERVICE' parameter, exiting..." );
333
330
theRequestHandler->sendServiceException ( QgsMapServiceException ( " ServiceNotSpecified" , " Service not specified. The SERVICE parameter is mandatory" ) );
334
331
delete theRequestHandler;
335
332
continue ;
336
- #endif
337
333
}
338
334
else
339
335
{
@@ -344,7 +340,6 @@ int main( int argc, char * argv[] )
344
340
{
345
341
QgsWCSServer wcsServer ( configFilePath, parameterMap, adminConfigParser, theRequestHandler );
346
342
wcsServer.executeRequest ();
347
-
348
343
}
349
344
else if ( serviceString == " WFS" )
350
345
{
@@ -360,7 +355,6 @@ int main( int argc, char * argv[] )
360
355
}
361
356
362
357
delete theMapRenderer;
363
- QgsDebugMsg ( " ************* all done ***************" );
364
358
return 0 ;
365
359
}
366
360
0 commit comments