Ported servatrice
This commit is contained in:
parent
80f68306b5
commit
2953c6ba2a
2 changed files with 38 additions and 4 deletions
|
@ -93,6 +93,17 @@ void myMessageOutput2(QtMsgType /*type*/, const char *msg)
|
|||
std::cerr << msg << std::endl;
|
||||
}
|
||||
|
||||
void myMessageOutputQt5(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
|
||||
{
|
||||
logger->logMessage(msg);
|
||||
}
|
||||
|
||||
void myMessageOutput2Qt5(QtMsgType /*type*/, const QMessageLogContext &, const QString &msg)
|
||||
{
|
||||
logger->logMessage(msg);
|
||||
std::cerr << msg.toStdString() << std::endl;
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void sigSegvHandler(int sig)
|
||||
{
|
||||
|
@ -121,9 +132,12 @@ int main(int argc, char *argv[])
|
|||
bool logToConsole = args.contains("--log-to-console");
|
||||
|
||||
qRegisterMetaType<QList<int> >("QList<int>");
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
// gone in Qt5, all source files _MUST_ be utf8-encoded
|
||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||
|
||||
#endif
|
||||
|
||||
QSettings *settings = new QSettings("servatrice.ini", QSettings::IniFormat);
|
||||
|
||||
loggerThread = new QThread;
|
||||
|
@ -133,11 +147,19 @@ int main(int argc, char *argv[])
|
|||
|
||||
loggerThread->start();
|
||||
QMetaObject::invokeMethod(logger, "startLog", Qt::BlockingQueuedConnection, Q_ARG(QString, settings->value("server/logfile").toString()));
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
if (logToConsole)
|
||||
qInstallMsgHandler(myMessageOutput);
|
||||
else
|
||||
qInstallMsgHandler(myMessageOutput2);
|
||||
#else
|
||||
if (logToConsole)
|
||||
qInstallMessageHandler(myMessageOutputQt5);
|
||||
else
|
||||
qInstallMessageHandler(myMessageOutput2Qt5);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
struct sigaction hup;
|
||||
hup.sa_handler = ServerLogger::hupSignalHandler;
|
||||
|
@ -173,8 +195,12 @@ int main(int argc, char *argv[])
|
|||
if (server->initServer()) {
|
||||
std::cerr << "-------------------------" << std::endl;
|
||||
std::cerr << "Server initialized." << std::endl;
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
qInstallMsgHandler(myMessageOutput);
|
||||
#else
|
||||
qInstallMessageHandler(myMessageOutputQt5);
|
||||
#endif
|
||||
retval = app.exec();
|
||||
|
||||
std::cerr << "Server quit." << std::endl;
|
||||
|
|
|
@ -234,8 +234,16 @@ bool Servatrice::initServer()
|
|||
if (!certFile.open(QIODevice::ReadOnly))
|
||||
throw QString("Error opening certificate file: %1").arg(certFileName);
|
||||
QSslCertificate cert(&certFile);
|
||||
#if QT_VERSION < 0x050000
|
||||
if (!cert.isValid())
|
||||
throw(QString("Invalid certificate."));
|
||||
#else
|
||||
const QDateTime currentTime = QDateTime::currentDateTime();
|
||||
if(currentTime < cert.effectiveDate() ||
|
||||
currentTime > cert.expiryDate() ||
|
||||
cert.isBlacklisted())
|
||||
throw(QString("Invalid certificate."));
|
||||
#endif
|
||||
qDebug() << "Loading private key...";
|
||||
QFile keyFile(keyFileName);
|
||||
if (!keyFile.open(QIODevice::ReadOnly))
|
||||
|
|
Loading…
Reference in a new issue