CELTCodec::CELTCodec(const QString &version) { bValid = false; cmMode = NULL; qsVersion = version; qlCELT.setLoadHints(QLibrary::ResolveAllSymbolsHint); QStringList alternatives; #if defined(Q_OS_MAC) alternatives << QString::fromLatin1("libcelt0.%1.dylib").arg(version); alternatives << QString::fromLatin1("celt0.%1.dylib").arg(version); alternatives << QString::fromLatin1("libcelt.%1.dylib").arg(version); alternatives << QString::fromLatin1("celt.%1.dylib").arg(version); #elif defined(Q_OS_UNIX) alternatives << QString::fromLatin1("libcelt0.so.%1").arg(version); alternatives << QString::fromLatin1("libcelt.so.%1").arg(version); alternatives << QString::fromLatin1("celt.so.%1").arg(version); #else int cpuinfo[4]; __cpuid(cpuinfo, 1); if (cpuinfo[3] & 0x02000000) { if (cpuinfo[3] & 0x04000000) { if (cpuinfo[2] & 0x00000001) { alternatives << QString::fromLatin1("celt0.%1.sse3.dll").arg(version); } alternatives << QString::fromLatin1("celt0.%1.sse2.dll").arg(version); } alternatives << QString::fromLatin1("celt0.%1.sse.dll").arg(version); } alternatives << QString::fromLatin1("celt0.%1.dll").arg(version); #endif foreach(const QString &lib, alternatives) { qlCELT.setFileName(QApplication::instance()->applicationDirPath() + QLatin1String("/") + lib); if (qlCELT.load()) { bValid = true; break; } #ifdef Q_OS_MAC qlCELT.setFileName(QApplication::instance()->applicationDirPath() + QLatin1String("/../Codecs/") + lib); if (qlCELT.load()) { bValid = true; break; } #endif #ifdef PLUGIN_PATH qlCELT.setFileName(QLatin1String(MUMTEXT(PLUGIN_PATH) "/") + lib); if (qlCELT.load()) { bValid = true; break; } #endif qlCELT.setFileName(lib); if (qlCELT.load()) { bValid = true; break; } }
OpusCodec::OpusCodec() { bValid = false; qlOpus.setLoadHints(QLibrary::ResolveAllSymbolsHint); QStringList alternatives; #if defined(Q_OS_MAC) alternatives << QString::fromLatin1("libopus0.dylib"); alternatives << QString::fromLatin1("opus0.dylib"); alternatives << QString::fromLatin1("libopus.dylib"); alternatives << QString::fromLatin1("opus.dylib"); #elif defined(Q_OS_UNIX) alternatives << QString::fromLatin1("libopus.so.0"); alternatives << QString::fromLatin1("libopus0.so"); alternatives << QString::fromLatin1("libopus.so"); alternatives << QString::fromLatin1("opus.so"); #else alternatives << QString::fromLatin1("opus0.dll"); alternatives << QString::fromLatin1("opus.dll"); #endif foreach(const QString &lib, alternatives) { qlOpus.setFileName(MumbleApplication::instance()->applicationVersionRootPath() + QLatin1String("/") + lib); if (qlOpus.load()) { bValid = true; break; } #ifdef Q_OS_MAC qlOpus.setFileName(QApplication::instance()->applicationDirPath() + QLatin1String("/../Codecs/") + lib); if (qlOpus.load()) { bValid = true; break; } #endif #ifdef PLUGIN_PATH qlOpus.setFileName(QLatin1String(MUMTEXT(PLUGIN_PATH) "/") + lib); if (qlOpus.load()) { bValid = true; break; } #endif qlOpus.setFileName(lib); if (qlOpus.load()) { bValid = true; break; } }
void OSInfo::fillXml(QDomDocument &doc, QDomElement &root, const QString &os, const QString &osver, const QList<QHostAddress> &qlBind) { QDomElement tag; QDomText t; bool bIs64; tag=doc.createElement(QLatin1String("machash")); root.appendChild(tag); t=doc.createTextNode(OSInfo::getMacHash(qlBind)); tag.appendChild(t); tag=doc.createElement(QLatin1String("version")); root.appendChild(tag); t=doc.createTextNode(QLatin1String(MUMTEXT(MUMBLE_VERSION_STRING))); tag.appendChild(t); tag=doc.createElement(QLatin1String("release")); root.appendChild(tag); t=doc.createTextNode(QLatin1String(MUMBLE_RELEASE)); tag.appendChild(t); tag=doc.createElement(QLatin1String("os")); root.appendChild(tag); t=doc.createTextNode(os); tag.appendChild(t); tag=doc.createElement(QLatin1String("osver")); root.appendChild(tag); t=doc.createTextNode(osver); tag.appendChild(t); tag=doc.createElement(QLatin1String("qt")); root.appendChild(tag); t=doc.createTextNode(QString::fromLatin1(qVersion())); tag.appendChild(t); #if defined(Q_WS_WIN) BOOL bIsWow64 = FALSE; IsWow64Process(GetCurrentProcess(), &bIsWow64); bIs64 = bIsWow64; #else bIs64 = (QSysInfo::WordSize == 64); #endif tag=doc.createElement(QLatin1String("is64bit")); root.appendChild(tag); t=doc.createTextNode(QString::number(bIs64 ? 1 : 0)); tag.appendChild(t); }
void os_init() { __pfnDliNotifyHook2 = delayHook; __cpuid(cpuinfo, 1); #define MMXSSE 0x02800000 if ((cpuinfo[3] & MMXSSE) != MMXSSE) { ::MessageBoxA(NULL, "Mumble requires a SSE capable processor (Pentium 3 / Ahtlon-XP)", "Mumble", MB_OK | MB_ICONERROR); exit(0); } OSVERSIONINFOEXW ovi; memset(&ovi, 0, sizeof(ovi)); ovi.dwOSVersionInfoSize = sizeof(ovi); GetVersionEx(reinterpret_cast<OSVERSIONINFOW *>(&ovi)); bIsWin7 = (ovi.dwMajorVersion >= 7) || ((ovi.dwMajorVersion == 6) &&(ovi.dwBuildNumber >= 7100)); bIsVistaSP1 = (ovi.dwMajorVersion >= 7) || ((ovi.dwMajorVersion == 6) &&(ovi.dwBuildNumber >= 6001)); unsigned int currentControl = 0; _controlfp_s(¤tControl, _DN_FLUSH, _MCW_DN); SetHeapOptions(); mumble_speex_init(); #ifdef QT_NO_DEBUG QString console = g.qdBasePath.filePath(QLatin1String("Console.txt")); fConsole = _wfsopen(console.toStdWString().c_str(), L"a+", _SH_DENYWR); if (fConsole) qInstallMsgHandler(mumbleMessageOutput); QString hash; QFile f(qApp->applicationFilePath()); if (! f.open(QIODevice::ReadOnly)) { qWarning("VersionCheck: Failed to open binary"); } else { QByteArray a = f.readAll(); if (a.size() > 0) { QCryptographicHash qch(QCryptographicHash::Sha1); qch.addData(a); hash = QLatin1String(qch.result().toHex()); } } QString comment = QString::fromLatin1("%1\n%2\n%3").arg(QString::fromLatin1(MUMBLE_RELEASE), QString::fromLatin1(MUMTEXT(MUMBLE_VERSION_STRING)), hash); wcscpy_s(wcComment, PATH_MAX, comment.toStdWString().c_str()); musComment.Type = CommentStreamW; musComment.Buffer = wcComment; musComment.BufferSize = wcslen(wcComment) * sizeof(wchar_t); QString dump = g.qdBasePath.filePath(QLatin1String("mumble.dmp")); QFileInfo fi(dump); QDir::root().mkpath(fi.absolutePath()); if (wcscpy_s(wcCrashDumpPath, PATH_MAX, dump.toStdWString().c_str()) == 0) SetUnhandledExceptionFilter(MumbleUnhandledExceptionFilter); // Increase our priority class to live alongside games. if (!SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS)) qWarning("Application: Failed to set priority!"); #endif g.qdBasePath.mkpath(QLatin1String("Snapshots")); if (bIsWin7) SetCurrentProcessExplicitAppUserModelID(L"net.sourceforge.mumble.Mumble"); }
void os_init() { __cpuid(cpuinfo, 1); #define MMXSSE 0x02800000 if ((cpuinfo[3] & MMXSSE) != MMXSSE) { ::MessageBoxA(NULL, "Mumble requires a SSE capable processor (Pentium 3 / Ahtlon-XP)", "Mumble", MB_OK | MB_ICONERROR); exit(0); } OSVERSIONINFOEXW ovi; memset(&ovi, 0, sizeof(ovi)); ovi.dwOSVersionInfoSize = sizeof(ovi); GetVersionEx(reinterpret_cast<OSVERSIONINFOW *>(&ovi)); bIsWin7 = (ovi.dwMajorVersion >= 7) || ((ovi.dwMajorVersion == 6) &&(ovi.dwBuildNumber >= 7100)); bIsVistaSP1 = (ovi.dwMajorVersion >= 7) || ((ovi.dwMajorVersion == 6) &&(ovi.dwBuildNumber >= 6001)); #if _MSC_VER == 1800 && defined(_M_X64) // Disable MSVC 2013's FMA-optimized math routines on Windows // versions earlier than Windows 8 (6.2). // There are various issues on OSes that do not support the newer // instructions. // See issue mumble-voip/mumble#1615. if (ovi.dwMajorVersion < 5 || (ovi.dwMajorVersion == 6 && ovi.dwMinorVersion <= 1)) { _set_FMA3_enable(0); } #endif unsigned int currentControl = 0; _controlfp_s(¤tControl, _DN_FLUSH, _MCW_DN); SetHeapOptions(); enableCrashOnCrashes(); mumble_speex_init(); #ifdef QT_NO_DEBUG QString console = g.qdBasePath.filePath(QLatin1String("Console.txt")); fConsole = _wfsopen(console.toStdWString().c_str(), L"a+", _SH_DENYWR); if (fConsole) { #if QT_VERSION >= 0x050000 qInstallMessageHandler(mumbleMessageOutputWithContext); #else qInstallMsgHandler(mumbleMessageOutput); #endif } QString hash; QFile f(qApp->applicationFilePath()); if (! f.open(QIODevice::ReadOnly)) { qWarning("VersionCheck: Failed to open binary"); } else { QByteArray a = f.readAll(); if (a.size() > 0) { QCryptographicHash qch(QCryptographicHash::Sha1); qch.addData(a); hash = QLatin1String(qch.result().toHex()); } } QString comment = QString::fromLatin1("%1\n%2\n%3").arg(QString::fromLatin1(MUMBLE_RELEASE), QString::fromLatin1(MUMTEXT(MUMBLE_VERSION_STRING)), hash); wcscpy_s(wcComment, PATH_MAX, comment.toStdWString().c_str()); musComment.Type = CommentStreamW; musComment.Buffer = wcComment; musComment.BufferSize = static_cast<ULONG>(wcslen(wcComment) * sizeof(wchar_t)); QString dump = g.qdBasePath.filePath(QLatin1String("mumble.dmp")); QFileInfo fi(dump); QDir::root().mkpath(fi.absolutePath()); if (wcscpy_s(wcCrashDumpPath, PATH_MAX, dump.toStdWString().c_str()) == 0) SetUnhandledExceptionFilter(MumbleUnhandledExceptionFilter); #endif g.qdBasePath.mkpath(QLatin1String("Snapshots")); if (bIsWin7) SetCurrentProcessExplicitAppUserModelID(L"net.sourceforge.mumble.Mumble"); }
Database::Database() { QSqlDatabase db = QSqlDatabase::addDatabase(QLatin1String("QSQLITE")); QSettings qs; QStringList datapaths; int i; datapaths << g.qdBasePath.absolutePath(); datapaths << QDesktopServices::storageLocation(QDesktopServices::DataLocation); #if defined(Q_OS_UNIX) && ! defined(Q_OS_MAC) datapaths << QDir::homePath() + QLatin1String("/.config/Mumble"); #endif datapaths << QDir::homePath(); datapaths << QDir::currentPath(); datapaths << qApp->applicationDirPath(); datapaths << qs.value(QLatin1String("InstPath")).toString(); bool found = false; for (i = 0; (i < datapaths.size()) && ! found; i++) { if (!datapaths[i].isEmpty()) { QFile f(datapaths[i] + QLatin1String("/mumble.sqlite")); if (f.exists()) { db.setDatabaseName(f.fileName()); found = db.open(); } //TODO: If the above succeeds, but we also have a .mumble.sqlite, we open another DB!? QFile f2(datapaths[i] + QLatin1String("/.mumble.sqlite")); if (f2.exists()) { db.setDatabaseName(f2.fileName()); found = db.open(); } } } if (! found) { for (i = 0; (i < datapaths.size()) && ! found; i++) { if (!datapaths[i].isEmpty()) { QDir::root().mkpath(datapaths[i]); #ifdef Q_OS_WIN QFile f(datapaths[i] + QLatin1String("/mumble.sqlite")); #else QFile f(datapaths[i] + QLatin1String("/.mumble.sqlite")); #endif db.setDatabaseName(f.fileName()); found = db.open(); } } } if (! found) { QMessageBox::critical(NULL, QLatin1String("Mumble"), tr("Mumble failed to initialize a database in any\nof the possible locations."), QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton); qFatal("Database: Failed initialization"); } QFileInfo fi(db.databaseName()); if (! fi.isWritable()) { QMessageBox::critical(NULL, QLatin1String("Mumble"), tr("The database '%1' is read-only. Mumble cannot store server settings (i.e. SSL certificates) until you fix this problem.").arg(fi.filePath()), QMessageBox::Ok | QMessageBox::Default, QMessageBox::NoButton); qWarning("Database: Database is read-only"); } { QFile f(db.databaseName()); f.setPermissions(f.permissions() & ~(QFile::ReadGroup | QFile::WriteGroup | QFile::ExeGroup | QFile::ReadOther | QFile::WriteOther | QFile::ExeOther)); } QSqlQuery query; execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `servers` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `hostname` TEXT, `port` INTEGER DEFAULT " MUMTEXT(DEFAULT_MUMBLE_PORT) ", `username` TEXT, `password` TEXT)")); query.exec(QLatin1String("ALTER TABLE `servers` ADD COLUMN `url` TEXT")); // Upgrade path, failing this query is not noteworthy execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `comments` (`who` TEXT, `comment` BLOB, `seen` DATE)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `comments_comment` ON `comments`(`who`, `comment`)")); execQueryAndLogFailure(query, QLatin1String("CREATE INDEX IF NOT EXISTS `comments_seen` ON `comments`(`seen`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `blobs` (`hash` TEXT, `data` BLOB, `seen` DATE)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `blobs_hash` ON `blobs`(`hash`)")); execQueryAndLogFailure(query, QLatin1String("CREATE INDEX IF NOT EXISTS `blobs_seen` ON `blobs`(`seen`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `tokens` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `digest` BLOB, `token` TEXT)")); execQueryAndLogFailure(query, QLatin1String("CREATE INDEX IF NOT EXISTS `tokens_host_port` ON `tokens`(`digest`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `shortcut` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `digest` BLOB, `shortcut` BLOB, `target` BLOB, `suppress` INTEGER)")); execQueryAndLogFailure(query, QLatin1String("CREATE INDEX IF NOT EXISTS `shortcut_host_port` ON `shortcut`(`digest`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `udp` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `digest` BLOB)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `udp_host_port` ON `udp`(`digest`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `cert` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `hostname` TEXT, `port` INTEGER, `digest` TEXT)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `cert_host_port` ON `cert`(`hostname`,`port`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `friends` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `hash` TEXT)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `friends_name` ON `friends`(`name`)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `friends_hash` ON `friends`(`hash`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `ignored` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `hash` TEXT)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `ignored_hash` ON `ignored`(`hash`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `muted` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `hash` TEXT)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `muted_hash` ON `muted`(`hash`)")); execQueryAndLogFailure(query, QLatin1String("CREATE TABLE IF NOT EXISTS `pingcache` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `hostname` TEXT, `port` INTEGER, `ping` INTEGER)")); execQueryAndLogFailure(query, QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `pingcache_host_port` ON `pingcache`(`hostname`,`port`)")); execQueryAndLogFailure(query, QLatin1String("DELETE FROM `comments` WHERE `seen` < datetime('now', '-1 years')")); execQueryAndLogFailure(query, QLatin1String("DELETE FROM `blobs` WHERE `seen` < datetime('now', '-1 months')")); execQueryAndLogFailure(query, QLatin1String("VACUUM")); execQueryAndLogFailure(query, QLatin1String("PRAGMA synchronous = OFF")); #ifdef Q_OS_WIN // Windows can not handle TRUNCATE with multiple connections to the DB. Thus less performant DELETE. execQueryAndLogFailure(query, QLatin1String("PRAGMA journal_mode = DELETE")); #else execQueryAndLogFailure(query, QLatin1String("PRAGMA journal_mode = TRUNCATE")); #endif execQueryAndLogFailure(query, QLatin1String("SELECT sqlite_version()")); while (query.next()) qWarning() << "Database SQLite:" << query.value(0).toString(); }
void OSInfo::fillXml(QDomDocument &doc, QDomElement &root, const QString &os, const QString &osver, const QList<QHostAddress> &qlBind) { QDomElement tag; QDomText t; bool bIs64; bool bSSE2 = false; QString cpu_id, cpu_extid; tag=doc.createElement(QLatin1String("machash")); root.appendChild(tag); t=doc.createTextNode(OSInfo::getMacHash(qlBind)); tag.appendChild(t); tag=doc.createElement(QLatin1String("version")); root.appendChild(tag); t=doc.createTextNode(QLatin1String(MUMTEXT(MUMBLE_VERSION_STRING))); tag.appendChild(t); tag=doc.createElement(QLatin1String("release")); root.appendChild(tag); t=doc.createTextNode(QLatin1String(MUMBLE_RELEASE)); tag.appendChild(t); tag=doc.createElement(QLatin1String("os")); root.appendChild(tag); t=doc.createTextNode(os); tag.appendChild(t); tag=doc.createElement(QLatin1String("osver")); root.appendChild(tag); t=doc.createTextNode(osver); tag.appendChild(t); tag=doc.createElement(QLatin1String("qt")); root.appendChild(tag); t=doc.createTextNode(QString::fromLatin1(qVersion())); tag.appendChild(t); #if defined(Q_OS_WIN) BOOL bIsWow64 = FALSE; IsWow64Process(GetCurrentProcess(), &bIsWow64); bIs64 = bIsWow64; #elif defined(Q_OS_MAC) size_t len = sizeof(bool); sysctlbyname("hw.cpu64bit_capable", &bIs64, &len, NULL, 0); #else bIs64 = (QSysInfo::WordSize == 64); #endif tag=doc.createElement(QLatin1String("is64bit")); root.appendChild(tag); t=doc.createTextNode(QString::number(bIs64 ? 1 : 0)); tag.appendChild(t); #if defined(Q_OS_WIN) #define regstr(x) QString::fromLatin1(reinterpret_cast<const char *>(& x), 4) int chop; int cpuinfo[4]; __cpuid(cpuinfo, 1); bSSE2 = (cpuinfo[3] & 0x04000000); __cpuid(cpuinfo, 0); cpu_id = regstr(cpuinfo[1]) + regstr(cpuinfo[3]) + regstr(cpuinfo[2]); for (unsigned int j=2; j<=4;++j) { __cpuid(cpuinfo, 0x80000000 + j); cpu_extid += regstr(cpuinfo[0]) + regstr(cpuinfo[1]) + regstr(cpuinfo[2]) + regstr(cpuinfo[3]); } cpu_id = cpu_id.trimmed(); chop = cpu_id.indexOf(QLatin1Char('\0')); if (chop != -1) cpu_id.truncate(chop); cpu_extid = cpu_extid.trimmed(); chop = cpu_extid.indexOf(QLatin1Char('\0')); if (chop != -1) cpu_extid.truncate(chop); #endif tag=doc.createElement(QLatin1String("cpu_id")); root.appendChild(tag); t=doc.createTextNode(cpu_id); tag.appendChild(t); tag=doc.createElement(QLatin1String("cpu_extid")); root.appendChild(tag); t=doc.createTextNode(cpu_extid); tag.appendChild(t); tag=doc.createElement(QLatin1String("cpu_sse2")); root.appendChild(tag); t=doc.createTextNode(QString::number(bSSE2 ? 1 : 0)); tag.appendChild(t); }
void Network::prepareRequest(QNetworkRequest &req) { #if QT_VERSION >= 0x040600 req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); #endif req.setRawHeader(QString::fromLatin1("User-Agent").toUtf8(), QString::fromLatin1("Mozilla/5.0 (%1; %2) Mumble/%3 %4").arg(OSInfo::getOS(), OSInfo::getOSVersion(), QLatin1String(MUMTEXT(MUMBLE_VERSION_STRING)), QLatin1String(MUMBLE_RELEASE)).toUtf8()); }