InternUpdater::InternUpdater(QWidget* parent) : QObject(parent), _running(false), _checkVersionTimer(NULL), _trayIcon(NULL), _server(NULL), _sevenZipReply(NULL), _checkVersionReply(NULL), _netManager(NULL) { setupNetworkAccessManager(); download7zipIfNeeded(); replaceUpdaterBinaryIfNeeded(); this->_server = new QLocalServer(this); connect(this->_server, SIGNAL(newConnection()), SIGNAL(quitApplication())); if (!this->_server->listen("QNetSoul")) { if (QLocalServer::removeServer("QNetSoul")) { #ifndef QT_NO_DEBUG qDebug() << "[InternUpdater::InternUpdater]" << "QLocalServer removed and listened again."; #endif this->_running = this->_server->listen("QNetSoul"); } } else this->_running = true; // Periodic version checking if (this->_running == true) { this->_checkVersionTimer = new QTimer(this); connect(this->_checkVersionTimer, SIGNAL(timeout()), this, SLOT(checkLastVersion())); this->_checkVersionTimer->start(OneHour); } #ifndef QT_NO_DEBUG qDebug() << "[InternUpdater::InternUpdater]" << (this->_running? "QLocalServer is running." : "QLocalServer is not running."); #endif }
bool QgsServer::init() { if ( sInitialized ) { return false; } QCoreApplication::setOrganizationName( QgsApplication::QGIS_ORGANIZATION_NAME ); QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN ); QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME ); QgsApplication::init(); #if defined(SERVER_SKIP_ECW) QgsMessageLog::logMessage( "Skipping GDAL ECW drivers in server.", "Server", Qgis::Info ); QgsApplication::skipGdalDriver( "ECW" ); QgsApplication::skipGdalDriver( "JP2ECW" ); #endif // reload settings to take into account QCoreApplication and QgsApplication // configuration sSettings.load(); // init and configure logger QgsServerLogger::instance(); QgsServerLogger::instance()->setLogLevel( sSettings.logLevel() ); if ( ! sSettings.logFile().isEmpty() ) { QgsServerLogger::instance()->setLogFile( sSettings.logFile() ); } else if ( sSettings.logStderr() ) { QgsServerLogger::instance()->setLogStderr(); } // log settings currently used sSettings.logSummary(); setupNetworkAccessManager(); QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars ); // Instantiate the plugin directory so that providers are loaded QgsProviderRegistry::instance( QgsApplication::pluginPath() ); QgsMessageLog::logMessage( "Prefix PATH: " + QgsApplication::prefixPath(), QStringLiteral( "Server" ), Qgis::Info ); QgsMessageLog::logMessage( "Plugin PATH: " + QgsApplication::pluginPath(), QStringLiteral( "Server" ), Qgis::Info ); QgsMessageLog::logMessage( "PkgData PATH: " + QgsApplication::pkgDataPath(), QStringLiteral( "Server" ), Qgis::Info ); QgsMessageLog::logMessage( "User DB PATH: " + QgsApplication::qgisUserDatabaseFilePath(), QStringLiteral( "Server" ), Qgis::Info ); QgsMessageLog::logMessage( "Auth DB PATH: " + QgsApplication::qgisAuthDatabaseFilePath(), QStringLiteral( "Server" ), Qgis::Info ); QgsMessageLog::logMessage( "SVG PATHS: " + QgsApplication::svgPaths().join( QDir::separator() ), QStringLiteral( "Server" ), Qgis::Info ); QgsApplication::createDatabase(); //init qgis.db (e.g. necessary for user crs) // Initialize the authentication system // creates or uses qgis-auth.db in ~/.qgis3/ or directory defined by QGIS_AUTH_DB_DIR_PATH env variable // set the master password as first line of file defined by QGIS_AUTH_PASSWORD_FILE env variable // (QGIS_AUTH_PASSWORD_FILE variable removed from environment after accessing) QgsApplication::authManager()->init( QgsApplication::pluginPath(), QgsApplication::qgisAuthDatabaseFilePath() ); QString defaultConfigFilePath; QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs/.qgz file in the server directory if ( projectFileInfo.exists() ) { defaultConfigFilePath = projectFileInfo.absoluteFilePath(); QgsMessageLog::logMessage( "Using default project file: " + defaultConfigFilePath, QStringLiteral( "Server" ), Qgis::Info ); } else { QFileInfo adminSLDFileInfo = defaultAdminSLD(); if ( adminSLDFileInfo.exists() ) { defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath(); } } // Store the config file path sConfigFilePath = new QString( defaultConfigFilePath ); //create cache for capabilities XML sCapabilitiesCache = new QgsCapabilitiesCache(); #ifdef ENABLE_MS_TESTS QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Roman" ) << QStringLiteral( "Bold" ) ); #endif sServiceRegistry = new QgsServiceRegistry(); sServerInterface = new QgsServerInterfaceImpl( sCapabilitiesCache, sServiceRegistry, &sSettings ); // Load service module QString modulePath = QgsApplication::libexecPath() + "server"; qDebug() << "Initializing server modules from " << modulePath << endl; sServiceRegistry->init( modulePath, sServerInterface ); sInitialized = true; QgsMessageLog::logMessage( QStringLiteral( "Server initialized" ), QStringLiteral( "Server" ), Qgis::Info ); return true; }
int main( int argc, char * argv[] ) { #ifndef _MSC_VER qInstallMsgHandler( dummyMessageHandler ); #endif QString optionsPath = getenv( "QGIS_OPTIONS_PATH" ); if ( !optionsPath.isEmpty() ) { QgsDebugMsg( "Options PATH: " + optionsPath ); QSettings::setDefaultFormat( QSettings::IniFormat ); QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionsPath ); } QgsApplication qgsapp( argc, argv, getenv( "DISPLAY" ) ); QCoreApplication::setOrganizationName( QgsApplication::QGIS_ORGANIZATION_NAME ); QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN ); QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME ); //Default prefix path may be altered by environment variable QgsApplication::init(); #if !defined(Q_OS_WIN) // init QGIS's paths - true means that all path will be inited from prefix QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE ); #endif #if defined(SERVER_SKIP_ECW) QgsDebugMsg( "Skipping GDAL ECW drivers in server." ); QgsApplication::skipGdalDriver( "ECW" ); QgsApplication::skipGdalDriver( "JP2ECW" ); #endif setupNetworkAccessManager(); QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars ); // Instantiate the plugin directory so that providers are loaded QgsProviderRegistry::instance( QgsApplication::pluginPath() ); QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() ); QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() ); QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() ); QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() ); QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) ); QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs) QString defaultConfigFilePath; QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory if ( projectFileInfo.exists() ) { defaultConfigFilePath = projectFileInfo.absoluteFilePath(); QgsDebugMsg( "Using default project file: " + defaultConfigFilePath ); } else { QFileInfo adminSLDFileInfo = defaultAdminSLD(); if ( adminSLDFileInfo.exists() ) { defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath(); } } //create cache for capabilities XML QgsCapabilitiesCache capabilitiesCache; //creating QgsMapRenderer is expensive (access to srs.db), so we do it here before the fcgi loop QScopedPointer< QgsMapRenderer > theMapRenderer( new QgsMapRenderer ); theMapRenderer->setLabelingEngine( new QgsPalLabeling() ); #ifdef QGSMSDEBUG QgsFontUtils::loadStandardTestFonts( QStringList() << "Roman" << "Bold" ); #endif int logLevel = QgsServerLogger::instance()->logLevel(); QTime time; //used for measuring request time if loglevel < 1 #ifdef HAVE_SERVER_PYTHON_PLUGINS // Create the interface QgsServerInterfaceImpl serverIface( &capabilitiesCache ); // Init plugins if ( ! QgsServerPlugins::initPlugins( &serverIface ) ) { QgsMessageLog::logMessage( "No server python plugins are available", "Server", QgsMessageLog::INFO ); } else { QgsMessageLog::logMessage( "Server python plugins loaded", "Server", QgsMessageLog::INFO ); } // Store plugin filters for faster access QMultiMap<int, QgsServerFilter*> pluginFilters = serverIface.filters(); #endif QgsEditorWidgetRegistry::initEditors(); while ( fcgi_accept() >= 0 ) { QgsMapLayerRegistry::instance()->removeAllMapLayers(); qgsapp.processEvents(); if ( logLevel < 1 ) { time.start(); printRequestInfos(); } //Request handler QScopedPointer<QgsRequestHandler> theRequestHandler( createRequestHandler() ); try { // TODO: split parse input into plain parse and processing from specific services theRequestHandler->parseInput(); } catch ( QgsMapServiceException& e ) { QgsMessageLog::logMessage( "Parse input exception: " + e.message(), "Server", QgsMessageLog::CRITICAL ); theRequestHandler->setServiceException( e ); } #ifdef HAVE_SERVER_PYTHON_PLUGINS // Set the request handler into the interface for plugins to manipulate it serverIface.setRequestHandler( theRequestHandler.data() ); // Iterate filters and call their requestReady() method QgsServerFiltersMap::const_iterator filtersIterator; for ( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator ) { filtersIterator.value()->requestReady(); } //Pass the filters to the requestHandler, this is needed for the following reasons: // 1. allow core services to access plugin filters and implement thir own plugin hooks // 2. allow requestHandler to call sendResponse plugin hook //TODO: implement this in the requestHandler ctor (far easier if we will get rid of // HAVE_SERVER_PYTHON_PLUGINS theRequestHandler->setPluginFilters( pluginFilters ); #endif // Copy the parameters map QMap<QString, QString> parameterMap( theRequestHandler->parameterMap() ); printRequestParameters( parameterMap, logLevel ); QMap<QString, QString>::const_iterator paramIt; //Config file path QString configFilePath = configPath( defaultConfigFilePath, parameterMap ); //Service parameter QString serviceString = theRequestHandler->parameter( "SERVICE" ); if ( serviceString.isEmpty() ) { // SERVICE not mandatory for WMS 1.3.0 GetMap & GetFeatureInfo QString requestString = theRequestHandler->parameter( "REQUEST" ); if ( requestString == "GetMap" || requestString == "GetFeatureInfo" ) { serviceString = "WMS"; } } // Enter core services main switch if ( !theRequestHandler->exceptionRaised() ) { if ( serviceString == "WCS" ) { QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration( configFilePath ); if ( !p ) { theRequestHandler->setServiceException( QgsMapServiceException( "Project file error", "Error reading the project file" ) ); } else { QgsWCSServer wcsServer( configFilePath, parameterMap, p, theRequestHandler.data() ); wcsServer.executeRequest(); } } else if ( serviceString == "WFS" ) { QgsWFSProjectParser* p = QgsConfigCache::instance()->wfsConfiguration( configFilePath ); if ( !p ) { theRequestHandler->setServiceException( QgsMapServiceException( "Project file error", "Error reading the project file" ) ); } else { QgsWFSServer wfsServer( configFilePath, parameterMap, p, theRequestHandler.data() ); wfsServer.executeRequest(); } } else if ( serviceString == "WMS" ) { QgsWMSConfigParser* p = QgsConfigCache::instance()->wmsConfiguration( configFilePath, parameterMap ); if ( !p ) { theRequestHandler->setServiceException( QgsMapServiceException( "WMS configuration error", "There was an error reading the project file or the SLD configuration" ) ); } else { QgsWMSServer wmsServer( configFilePath, parameterMap, p, theRequestHandler.data(), theMapRenderer.data(), &capabilitiesCache ); wmsServer.executeRequest(); } } else { theRequestHandler->setServiceException( QgsMapServiceException( "Service configuration error", "Service unknown or unsupported" ) ); } // end switch } // end if not exception raised #ifdef HAVE_SERVER_PYTHON_PLUGINS // Iterate filters and call their responseComplete() method for ( filtersIterator = pluginFilters.constBegin(); filtersIterator != pluginFilters.constEnd(); ++filtersIterator ) { filtersIterator.value()->responseComplete(); } #endif theRequestHandler->sendResponse(); if ( logLevel < 1 ) { QgsMessageLog::logMessage( "Request finished in " + QString::number( time.elapsed() ) + " ms", "Server", QgsMessageLog::INFO ); } } return 0; }
/** * Server initialization */ bool QgsServer::init( int & argc, char ** argv ) { if ( mInitialised ) { return FALSE; } #ifndef _MSC_VER qInstallMsgHandler( dummyMessageHandler ); #endif QString optionsPath = getenv( "QGIS_OPTIONS_PATH" ); if ( !optionsPath.isEmpty() ) { QgsDebugMsg( "Options PATH: " + optionsPath ); QSettings::setDefaultFormat( QSettings::IniFormat ); QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, optionsPath ); } mQgsApplication = new QgsApplication( argc, argv, getenv( "DISPLAY" ) ); QCoreApplication::setOrganizationName( QgsApplication::QGIS_ORGANIZATION_NAME ); QCoreApplication::setOrganizationDomain( QgsApplication::QGIS_ORGANIZATION_DOMAIN ); QCoreApplication::setApplicationName( QgsApplication::QGIS_APPLICATION_NAME ); //Default prefix path may be altered by environment variable QgsApplication::init(); #if !defined(Q_OS_WIN) // init QGIS's paths - true means that all path will be inited from prefix QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE ); #endif #if defined(SERVER_SKIP_ECW) QgsDebugMsg( "Skipping GDAL ECW drivers in server." ); QgsApplication::skipGdalDriver( "ECW" ); QgsApplication::skipGdalDriver( "JP2ECW" ); #endif setupNetworkAccessManager(); QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars ); // Instantiate the plugin directory so that providers are loaded QgsProviderRegistry::instance( QgsApplication::pluginPath() ); QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() ); QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() ); QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() ); QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() ); QgsDebugMsg( "SVG PATHS: " + QgsApplication::svgPaths().join( ":" ) ); QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs) QString defaultConfigFilePath; QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory if ( projectFileInfo.exists() ) { defaultConfigFilePath = projectFileInfo.absoluteFilePath(); QgsDebugMsg( "Using default project file: " + defaultConfigFilePath ); } else { QFileInfo adminSLDFileInfo = defaultAdminSLD(); if ( adminSLDFileInfo.exists() ) { defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath(); } } //create cache for capabilities XML mCapabilitiesCache = new QgsCapabilitiesCache(); mMapRenderer = new QgsMapRenderer; mMapRenderer->setLabelingEngine( new QgsPalLabeling() ); #ifdef ENABLE_MS_TESTS QgsFontUtils::loadStandardTestFonts( QStringList() << "Roman" << "Bold" ); #endif #ifdef HAVE_SERVER_PYTHON_PLUGINS mServerInterface = new QgsServerInterfaceImpl( mCapabilitiesCache ); if ( mInitPython ) { // Init plugins if ( ! QgsServerPlugins::initPlugins( mServerInterface ) ) { QgsMessageLog::logMessage( "No server python plugins are available", "Server", QgsMessageLog::INFO ); } else { QgsMessageLog::logMessage( "Server python plugins loaded", "Server", QgsMessageLog::INFO ); } } #endif QgsServerLogger::instance(); QgsEditorWidgetRegistry::initEditors(); mInitialised = TRUE; QgsMessageLog::logMessage( "Server intialised", "Server", QgsMessageLog::INFO ); return TRUE; }
int main( int argc, char * argv[] ) { #ifndef _MSC_VER qInstallMsgHandler( dummyMessageHandler ); #endif QgsApplication qgsapp( argc, argv, getenv( "DISPLAY" ) ); //Default prefix path may be altered by environment variable QgsApplication::init(); #if !defined(Q_OS_WIN) // init QGIS's paths - true means that all path will be inited from prefix QgsApplication::setPrefixPath( CMAKE_INSTALL_PREFIX, TRUE ); #endif #if defined(MAPSERVER_SKIP_ECW) QgsDebugMsg( "Skipping GDAL ECW drivers in server." ); QgsApplication::skipGdalDriver( "ECW" ); QgsApplication::skipGdalDriver( "JP2ECW" ); #endif setupNetworkAccessManager(); QDomImplementation::setInvalidDataPolicy( QDomImplementation::DropInvalidChars ); // Instantiate the plugin directory so that providers are loaded QgsProviderRegistry::instance( QgsApplication::pluginPath() ); QgsDebugMsg( "Prefix PATH: " + QgsApplication::prefixPath() ); QgsDebugMsg( "Plugin PATH: " + QgsApplication::pluginPath() ); QgsDebugMsg( "PkgData PATH: " + QgsApplication::pkgDataPath() ); QgsDebugMsg( "User DB PATH: " + QgsApplication::qgisUserDbFilePath() ); QgsDebugMsg( qgsapp.applicationDirPath() + "/qgis_wms_server.log" ); QgsApplication::createDB(); //init qgis.db (e.g. necessary for user crs) QString defaultConfigFilePath; QFileInfo projectFileInfo = defaultProjectFile(); //try to find a .qgs file in the server directory if ( projectFileInfo.exists() ) { defaultConfigFilePath = projectFileInfo.absoluteFilePath(); QgsDebugMsg( "Using default project file: " + defaultConfigFilePath ); } else { QFileInfo adminSLDFileInfo = defaultAdminSLD(); if ( adminSLDFileInfo.exists() ) { defaultConfigFilePath = adminSLDFileInfo.absoluteFilePath(); } } //create cache for capabilities XML QgsCapabilitiesCache capabilitiesCache; //creating QgsMapRenderer is expensive (access to srs.db), so we do it here before the fcgi loop QgsMapRenderer* theMapRenderer = new QgsMapRenderer(); theMapRenderer->setLabelingEngine( new QgsPalLabeling() ); printRequestInfos(); #ifdef QGSMSDEBUG QgsFontUtils::loadStandardTestFonts( QStringList() << "Roman" << "Bold" ); #endif while ( fcgi_accept() >= 0 ) { printRequestInfos(); //print request infos if in debug mode //Request handler QgsRequestHandler* theRequestHandler = createRequestHandler(); QMap<QString, QString> parameterMap; try { parameterMap = theRequestHandler->parseInput(); } catch ( QgsMapServiceException& e ) { QgsDebugMsg( "An exception was thrown during input parsing" ); theRequestHandler->sendServiceException( e ); continue; } QMap<QString, QString>::const_iterator paramIt; //Config file path QString configFilePath = configPath( defaultConfigFilePath, parameterMap ); //Service parameter QString serviceString; paramIt = parameterMap.find( "SERVICE" ); if ( paramIt == parameterMap.constEnd() ) { theRequestHandler->sendServiceException( QgsMapServiceException( "ServiceNotSpecified", "Service not specified. The SERVICE parameter is mandatory" ) ); delete theRequestHandler; continue; } else { serviceString = paramIt.value(); } if ( serviceString == "WCS" ) { QgsWCSProjectParser* p = QgsConfigCache::instance()->wcsConfiguration( configFilePath ); if ( !p ) { //error handling } QgsWCSServer wcsServer( configFilePath, parameterMap, p, theRequestHandler ); wcsServer.executeRequest(); } else if ( serviceString == "WFS" ) { QgsWFSProjectParser* p = QgsConfigCache::instance()->wfsConfiguration( configFilePath ); if ( !p ) { //error handling } QgsWFSServer wfsServer( configFilePath, parameterMap, p, theRequestHandler ); wfsServer.executeRequest(); } else //WMS else { QgsWMSConfigParser* p = QgsConfigCache::instance()->wmsConfiguration( configFilePath, parameterMap ); if ( !p ) { //error handling } //adminConfigParser->loadLabelSettings( theMapRenderer->labelingEngine() ); QgsWMSServer wmsServer( configFilePath, parameterMap, p, theRequestHandler, theMapRenderer, &capabilitiesCache ); wmsServer.executeRequest(); } } delete theMapRenderer; return 0; }