void ServerConfigurationDialog::on_loadButton_clicked(bool) { QString filePath(QDir::homePath()); filePath = QFileDialog::getOpenFileName(this, tr("Open Server Configuration"), filePath, tr("Configuration Files (*.cfg)")); if (filePath.isEmpty()) return; try { Parser::ParseFile parser(filePath); parser.start(); parser.wait(); QStringList errors(parser.errors()); if (!errors.isEmpty()) { QMsgBox::warning(this, "IQmol", errors.join("\n")); } Data::Bank& bank(parser.data()); QList<Data::YamlNode*> yaml(bank.findData<Data::YamlNode>()); if (yaml.first()) { yaml.first()->dump(); m_currentConfiguration = ServerConfiguration(*(yaml.first())); blockUpdate(true); copyFrom(m_currentConfiguration); blockUpdate(false); } } catch (YAML::Exception& err) { QString msg(QString::fromStdString(err.what())); QMsgBox::warning(this, "IQmol", msg); } }
ServerConfiguration ServerConfiguration::fromFile(QString const& filename) { if (!QFile::exists(filename)) { throw IllegalArgumentException() << "Could not open ServerConfiguration file, file does not exist: " << filename.toStdString(); } QFile inputFile(filename); if (!inputFile.open(QFile::ReadOnly)) { throw IllegalArgumentException() << "Could not open ServerConfiguration file for reading: " << filename.toStdString(); } inputFile.close(); QSettings serverSettings(filename, QSettings::IniFormat); if (!serverSettings.contains("serverHost")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing serverHost in " << filename.toStdString(); } if (!serverSettings.contains("serverPort")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing serverPort in " << filename.toStdString(); } bool ok = false; int port = serverSettings.value("serverPort").toInt(&ok); if (!ok || (port < 1) || (port > 65535)) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Invalid serverPort in " << filename.toStdString(); } if (!serverSettings.contains("serverLongTermPublicKey")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing serverLongTermPublicKey in " << filename.toStdString(); } if (!serverSettings.contains("identityRequestUrl")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing identityRequestUrl in " << filename.toStdString(); } if (!serverSettings.contains("identityRequestAgent")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing identityRequestAgent in " << filename.toStdString(); } if (!serverSettings.contains("identityServerCertificate")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing identityServerCertificate in " << filename.toStdString(); } if (!serverSettings.contains("imageRequestDownloadUrl")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing imageRequestDownloadUrl in " << filename.toStdString(); } if (!serverSettings.contains("imageRequestDownloadFinishedUrl")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing imageRequestDownloadFinishedUrl in " << filename.toStdString(); } if (!serverSettings.contains("imageRequestUploadUrl")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing imageRequestUploadUrl in " << filename.toStdString(); } if (!serverSettings.contains("imageRequestAgent")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing imageRequestAgent in " << filename.toStdString(); } if (!serverSettings.contains("imageServerCertificate")) { throw IllegalArgumentException() << "Invalid ServerConfiguration: Missing imageServerCertificate in " << filename.toStdString(); } return ServerConfiguration(serverSettings.value("serverHost").toString(), port, PublicKey::fromHexString(serverSettings.value("serverLongTermPublicKey").toString()), serverSettings.value("identityRequestUrl").toString(), serverSettings.value("identityRequestAgent").toString(), serverSettings.value("identityServerCertificate").toString(), serverSettings.value("imageRequestDownloadUrl").toString(), serverSettings.value("imageRequestDownloadFinishedUrl").toString(), serverSettings.value("imageRequestUploadUrl").toString(), serverSettings.value("imageRequestAgent").toString(), serverSettings.value("imageServerCertificate").toString()); }
Configuration ConfigurationBuilder::create() { std::vector<ServerConfiguration> servers; if(m_servers.size() > 0) { for(std::vector<HR_SHARED_PTR<ServerConfigurationBuilder> >::iterator it = m_servers.begin(); it < m_servers.end(); it++) { servers.push_back((*it).get()->create()); } } else { servers.push_back(ServerConfiguration("127.0.0.1", 11222)); } return Configuration(m_protocolVersion, connectionPoolConfigurationBuilder.create(), m_connectionTimeout, m_forceReturnValue, m_keySizeEstimate, m_pingOnStartup, servers, m_socketTimeout, sslConfigurationBuilder.create(), m_tcpNoDelay, m_keySizeEstimate); }