Skip to content

Commit

Permalink
Formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzmbrzl committed Mar 7, 2024
1 parent accfc46 commit 2877543
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 50 deletions.
5 changes: 3 additions & 2 deletions src/database/ConversionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ namespace db {
case soci::dt_unsigned_long_long:
return row.get< unsigned long long >(columnIndex);
case soci::dt_blob: {
soci::blob blob = row.move_as<soci::blob>(columnIndex);
soci::blob blob = row.move_as< soci::blob >(columnIndex);
const std::size_t dataSize = blob.get_len();

std::vector< std::uint8_t > dataContainer;
dataContainer.resize(dataSize);

const std::size_t bytesRead = blob.read_from_start(reinterpret_cast<char *>(dataContainer.data()), dataSize);
const std::size_t bytesRead =
blob.read_from_start(reinterpret_cast< char * >(dataContainer.data()), dataSize);
assert(bytesRead == dataSize);
(void) bytesRead;

Expand Down
21 changes: 12 additions & 9 deletions src/murmur/DBWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ std::vector< Ban > DBWrapper::getBans(unsigned int serverID) {

ban.iDuration = static_cast< unsigned int >(currentBan.duration.count());
ban.iMask = currentBan.prefixLength;
ban.qdtStart = QDateTime::fromSecsSinceEpoch(static_cast< qint64 >(::msdb::toEpochSeconds(currentBan.startDate)));
ban.qdtStart =
QDateTime::fromSecsSinceEpoch(static_cast< qint64 >(::msdb::toEpochSeconds(currentBan.startDate)));
ban.haAddress = HostAddress(currentBan.baseAddress);
if (currentBan.reason) {
ban.qsReason = QString::fromStdString(currentBan.reason.get());
Expand Down Expand Up @@ -1020,8 +1021,8 @@ void DBWrapper::loadChannelListenersOf(unsigned int serverID, const ServerUserIn
assertValidID(serverID);
assertValidID(userInfo.iId);

for (const ::msdb::DBChannelListener &currentListener :
m_serverDB.getChannelListenerTable().getListenersForUser(serverID, static_cast< unsigned int >(userInfo.iId))) {
for (const ::msdb::DBChannelListener &currentListener : m_serverDB.getChannelListenerTable().getListenersForUser(
serverID, static_cast< unsigned int >(userInfo.iId))) {
if (currentListener.enabled) {
manager.addListener(userInfo.uiSession, currentListener.channelID);
manager.setListenerVolumeAdjustment(userInfo.uiSession, currentListener.channelID,
Expand Down Expand Up @@ -1218,9 +1219,10 @@ void DBWrapper::addAllRegisteredUserInfoTo(std::vector< UserInfo > &userInfo, un
::msdb::DBUserData userData = m_serverDB.getUserTable().getData(currentUser);

UserInfo info;
info.name = QString::fromStdString(userData.name);
info.user_id = static_cast< int >(currentUser.registeredUserID);
info.last_active = QDateTime::fromSecsSinceEpoch(static_cast< qint64 >(::msdb::toEpochSeconds(userData.lastActive)));
info.name = QString::fromStdString(userData.name);
info.user_id = static_cast< int >(currentUser.registeredUserID);
info.last_active =
QDateTime::fromSecsSinceEpoch(static_cast< qint64 >(::msdb::toEpochSeconds(userData.lastActive)));
info.last_channel = userData.lastChannelID;

userInfo.push_back(std::move(info));
Expand Down Expand Up @@ -1286,8 +1288,9 @@ void DBWrapper::storeRegisteredUserPassword(unsigned int serverID, unsigned int
pwData.passwordHash = getLegacyPasswordHash(password).toStdString();
} else {
assert(Meta::mp.kdfIterations >= 0);
pwData.kdfIterations = kdfIterations > 0 ? kdfIterations : static_cast< unsigned int >(Meta::mp.kdfIterations);
pwData.salt = PBKDF2::getSalt().toStdString();
pwData.kdfIterations =
kdfIterations > 0 ? kdfIterations : static_cast< unsigned int >(Meta::mp.kdfIterations);
pwData.salt = PBKDF2::getSalt().toStdString();
pwData.passwordHash = PBKDF2::getHash(QString::fromStdString(pwData.salt), QString::fromStdString(password),
static_cast< int >(pwData.kdfIterations))
.toStdString();
Expand Down Expand Up @@ -1343,7 +1346,7 @@ void DBWrapper::setLastChannel(unsigned int serverID, unsigned int userID, unsig
}

unsigned int DBWrapper::getLastChannelID(unsigned int serverID, unsigned int userID, unsigned int maxRememberDuration,
std::size_t serverUptimeSecs) {
std::size_t serverUptimeSecs) {
WRAPPER_BEGIN

assertValidID(serverID);
Expand Down
5 changes: 3 additions & 2 deletions src/murmur/DBus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const QDBusArgument &operator>>(const QDBusArgument &a, RegisteredPlayer &s) {

QDBusArgument &operator<<(QDBusArgument &a, const LogEntry &s) {
a.beginStructure();
a << static_cast<quint64>(s.timestamp) << s.txt;
a << static_cast< quint64 >(s.timestamp) << s.txt;
a.endStructure();
return a;
}
Expand Down Expand Up @@ -923,7 +923,8 @@ void MetaDBus::setConf(int server_id, const QString &key, const QString &value,
if (server_id < 0 || !meta->dbWrapper.serverExists(static_cast< unsigned int >(server_id))) {
MurmurDBus::qdbc->send(msg.createErrorReply("net.sourceforge.mumble.Error.server", "Invalid server id"));
} else {
meta->dbWrapper.setConfiguration(static_cast< unsigned int >(server_id), key.toStdString(), value.toStdString());
meta->dbWrapper.setConfiguration(static_cast< unsigned int >(server_id), key.toStdString(),
value.toStdString());
Server *s = meta->qhServers.value(static_cast< unsigned int >(server_id));
if (s)
s->setLiveConf(key, value);
Expand Down
8 changes: 4 additions & 4 deletions src/murmur/Messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,9 @@ void Server::msgAuthenticate(ServerUser *uSource, MumbleProto::Authenticate &msg
Channel *lc = nullptr;
if (uSource->iId >= 0) {
unsigned int lastChannelID = m_dbWrapper.getLastChannelID(iServerNum, static_cast< unsigned int >(uSource->iId),
static_cast< unsigned int >(iRememberChanDuration),
get_elapsed_seconds(tUptime));
lc = qhChannels.value(lastChannelID);
static_cast< unsigned int >(iRememberChanDuration),
get_elapsed_seconds(tUptime));
lc = qhChannels.value(lastChannelID);
}

if (!lc || !hasPermission(uSource, lc, ChanACL::Enter) || isChannelFull(lc, uSource)) {
Expand Down Expand Up @@ -2001,7 +2001,7 @@ void Server::msgQueryUsers(ServerUser *uSource, MumbleProto::QueryUsers &msg) {
MumbleProto::QueryUsers reply;

for (int i = 0; i < msg.ids_size(); ++i) {
unsigned int id = msg.ids(i);
unsigned int id = msg.ids(i);
const QString &name = getRegisteredUserName(static_cast< int >(id));
if (!name.isEmpty()) {
reply.add_ids(id);
Expand Down
9 changes: 6 additions & 3 deletions src/murmur/Meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,8 @@ const ::mumble::db::ConnectionParameter &Meta::getConnectionParameter() {
qFatal("SQLite WAL = 1 option no longer supported. Either enable fully (WAL = 2) or disable (WAL = 0)");
}
#ifdef MUMBLE_DISABLE_SQLITE
qFatal("Your version of the Mumble server has been compiled without support for SQLite - choose a different DB backend");
qFatal("Your version of the Mumble server has been compiled without support for SQLite - choose a different DB "
"backend");
#endif

static ::mumble::db::SQLiteConnectionParameter sqliteConnection(Meta::mp.qsDatabase.toStdString(),
Expand All @@ -745,7 +746,8 @@ const ::mumble::db::ConnectionParameter &Meta::getConnectionParameter() {
} else if (boost::iequals(Meta::mp.qsDBDriver.toStdString(), "qmysql")
|| boost::iequals(Meta::mp.qsDBDriver.toStdString(), "mysql")) {
#ifdef MUMBLE_DISABLE_MYSQL
qFatal("Your version of the Mumble server has been compiled without support for MySQL - choose a different DB backend");
qFatal("Your version of the Mumble server has been compiled without support for MySQL - choose a different DB "
"backend");
#endif
static ::mumble::db::MySQLConnectionParameter mysqlConnection(Meta::mp.qsDatabase.toStdString());

Expand All @@ -766,7 +768,8 @@ const ::mumble::db::ConnectionParameter &Meta::getConnectionParameter() {
|| boost::iequals(Meta::mp.qsDBDriver.toStdString(), "psql")
|| boost::iequals(Meta::mp.qsDBDriver.toStdString(), "postgresql")) {
#ifdef MUMBLE_DISABLE_POSTGRESQL
qFatal("Your version of the Mumble server has been compiled without support for PostgreSQL - choose a different DB backend");
qFatal("Your version of the Mumble server has been compiled without support for PostgreSQL - choose a "
"different DB backend");
#endif
static ::mumble::db::PostgreSQLConnectionParameter postgresqlConnection(Meta::mp.qsDatabase.toStdString());

Expand Down
13 changes: 7 additions & 6 deletions src/murmur/MumbleServerIce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ void MumbleServerIce::contextAction(const ::User *pSrc, const QString &action, u
if (!qmServerContextCallbacks.contains(s->iServerNum))
return;

QMap< int, QMap< QString, ::MumbleServer::ServerContextCallbackPrx > > &qmServer = qmServerContextCallbacks[s->iServerNum];
QMap< int, QMap< QString, ::MumbleServer::ServerContextCallbackPrx > > &qmServer =
qmServerContextCallbacks[s->iServerNum];
if (!qmServer.contains(static_cast< int >(pSrc->uiSession)))
return;

Expand Down Expand Up @@ -868,11 +869,11 @@ Ice::ObjectPtr ServerLocator::locate(const Ice::Current &, Ice::LocalObjectPtr &

#define FIND_SERVER ::Server *server = meta->qhServers.value(static_cast< unsigned int >(server_id));

#define NEED_SERVER_EXISTS \
FIND_SERVER \
if (!server && !meta->dbWrapper.serverExists(static_cast< unsigned int >(server_id))) { \
cb->ice_exception(::Ice::ObjectNotExistException(__FILE__, __LINE__)); \
return; \
#define NEED_SERVER_EXISTS \
FIND_SERVER \
if (!server && !meta->dbWrapper.serverExists(static_cast< unsigned int >(server_id))) { \
cb->ice_exception(::Ice::ObjectNotExistException(__FILE__, __LINE__)); \
return; \
}

#define NEED_SERVER \
Expand Down
3 changes: 2 additions & 1 deletion src/murmur/MumbleServerIce.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class MumbleServerIce : public QObject {
void badAuthenticator(::Server *);
QList<::MumbleServer::MetaCallbackPrx > qlMetaCallbacks;
QMap< unsigned int, QList<::MumbleServer::ServerCallbackPrx > > qmServerCallbacks;
QMap< unsigned int, QMap< int, QMap< QString, ::MumbleServer::ServerContextCallbackPrx > > > qmServerContextCallbacks;
QMap< unsigned int, QMap< int, QMap< QString, ::MumbleServer::ServerContextCallbackPrx > > >
qmServerContextCallbacks;
QMap< unsigned int, ::MumbleServer::ServerAuthenticatorPrx > qmServerAuthenticator;
QMap< unsigned int, ::MumbleServer::ServerUpdatingAuthenticatorPrx > qmServerUpdatingAuthenticator;

Expand Down
31 changes: 18 additions & 13 deletions src/murmur/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,7 @@ void Server::connectionClosed(QAbstractSocket::SocketError err, const QString &r
log(u, QString("Connection closed: %1 [%2]").arg(reason).arg(err));

if (u->iId >= 0) {
m_dbWrapper.updateLastDisconnect(iServerNum, static_cast<unsigned int >(u->iId));
m_dbWrapper.updateLastDisconnect(iServerNum, static_cast< unsigned int >(u->iId));
}

if (u->sState == ServerUser::Authenticated) {
Expand Down Expand Up @@ -2613,7 +2613,8 @@ int Server::authenticate(QString &name, const QString &password, int sessionId,
}

// Ensure that the user will use the name exactly as we have stored it in our DB. For password
::mumble::server::db::DBUserData userData = m_dbWrapper.getRegisteredUserData(iServerNum, static_cast< unsigned int >(userID));
::mumble::server::db::DBUserData userData =
m_dbWrapper.getRegisteredUserData(iServerNum, static_cast< unsigned int >(userID));

// Make sure the user name uses the same casing that is stored in the DB
name = QString::fromStdString(userData.name);
Expand All @@ -2622,13 +2623,13 @@ int Server::authenticate(QString &name, const QString &password, int sessionId,
// If provided, store this user's certificate hash
const bool isSuperUser = static_cast< unsigned int >(userID) == Mumble::SUPERUSER_ID;
if (!isSuperUser && !certhash.isEmpty()) {
m_dbWrapper.storeUserProperty(iServerNum, static_cast< unsigned int >(userID), ::mumble::server::db::UserProperty::CertificateHash,
certhash.toStdString());
m_dbWrapper.storeUserProperty(iServerNum, static_cast< unsigned int >(userID),
::mumble::server::db::UserProperty::CertificateHash, certhash.toStdString());
}
// If provided, store this user's email
if (!isSuperUser && !emails.isEmpty()) {
m_dbWrapper.storeUserProperty(iServerNum, static_cast< unsigned int >(userID), ::mumble::server::db::UserProperty::Email,
emails[0].toStdString());
m_dbWrapper.storeUserProperty(iServerNum, static_cast< unsigned int >(userID),
::mumble::server::db::UserProperty::Email, emails[0].toStdString());
}
}

Expand Down Expand Up @@ -2720,7 +2721,8 @@ bool Server::setComment(ServerUser &user, const QString &comment) {
return (res > 0);
}

m_dbWrapper.storeUserProperty(iServerNum, static_cast< unsigned int >(user.iId), ::mumble::server::db::UserProperty::Comment,
m_dbWrapper.storeUserProperty(iServerNum, static_cast< unsigned int >(user.iId),
::mumble::server::db::UserProperty::Comment,
info[static_cast< int >(::mumble::server::db::UserProperty::Comment)].toStdString());

return true;
Expand All @@ -2747,8 +2749,8 @@ void Server::loadComment(ServerUser &user) {

comment = std::move(info[static_cast< int >(::mumble::server::db::UserProperty::Comment)]);
} else {
comment = QString::fromStdString(
m_dbWrapper.getUserProperty(iServerNum, static_cast< unsigned int >(user.iId), ::mumble::server::db::UserProperty::Comment));
comment = QString::fromStdString(m_dbWrapper.getUserProperty(iServerNum, static_cast< unsigned int >(user.iId),
::mumble::server::db::UserProperty::Comment));
}

hashAssign(user.qsComment, user.qbaCommentHash, comment);
Expand All @@ -2766,7 +2768,8 @@ void Server::addChannelListener(const ServerUser &user, const Channel &channel)
// we want to make sure to load
m_channelListenerManager.setListenerVolumeAdjustment(
user.uiSession, channel.iId,
VolumeAdjustment::fromFactor(m_dbWrapper.getChannelListenerVolume(iServerNum, static_cast< unsigned int >(user.iId), channel.iId)));
VolumeAdjustment::fromFactor(
m_dbWrapper.getChannelListenerVolume(iServerNum, static_cast< unsigned int >(user.iId), channel.iId)));
}

m_channelListenerManager.addListener(user.uiSession, channel.iId);
Expand All @@ -2777,9 +2780,11 @@ void Server::setChannelListenerVolume(const ServerUser &user, const Channel &cha
// we expect this check to return true for most cases in which this function is called.
// However, sometimes the DB really is the only entity knowing about a given listener.
if (m_channelListenerManager.isListening(user.uiSession, channel.iId)
|| (user.iId >= 0 && m_dbWrapper.channelListenerExists(iServerNum, static_cast< unsigned int >(user.iId), channel.iId))) {
|| (user.iId >= 0
&& m_dbWrapper.channelListenerExists(iServerNum, static_cast< unsigned int >(user.iId), channel.iId))) {
if (user.iId >= 0 && !channel.bTemporary) {
m_dbWrapper.storeChannelListenerVolume(iServerNum, static_cast< unsigned int >(user.iId), channel.iId, volume);
m_dbWrapper.storeChannelListenerVolume(iServerNum, static_cast< unsigned int >(user.iId), channel.iId,
volume);
}

m_channelListenerManager.setListenerVolumeAdjustment(user.uiSession, channel.iId,
Expand Down Expand Up @@ -2926,7 +2931,7 @@ int Server::registerUser(const ServerUserInfo &userInfo) {
if (id < 0) {
// Get available user ID via internal method
unsigned int nextID = m_dbWrapper.getNextAvailableUserID(iServerNum);
assert(nextID < static_cast< unsigned int >(std::numeric_limits<int>::max()));
assert(nextID < static_cast< unsigned int >(std::numeric_limits< int >::max()));
id = static_cast< int >(nextID);
}

Expand Down
8 changes: 4 additions & 4 deletions src/murmur/database/BanTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ namespace server {
void BanTable::addBan(const DBBan &ban) {
try {
std::string baseAddress = DBBan::ipv6ToString(ban.baseAddress);
auto startEpoch = static_cast< unsigned int >(toEpochSeconds(ban.startDate));
auto duration = static_cast< unsigned int >(ban.duration.count());
auto startEpoch = static_cast< unsigned int >(toEpochSeconds(ban.startDate));
auto duration = static_cast< unsigned int >(ban.duration.count());
std::string userName;
std::string userCert;
std::string reason;
Expand Down Expand Up @@ -327,8 +327,8 @@ namespace server {
assert(currentBan.serverID == serverID);

std::string baseAddress = DBBan::ipv6ToString(currentBan.baseAddress);
auto startEpoch = static_cast< unsigned int >(toEpochSeconds(currentBan.startDate));
auto duration = static_cast< unsigned int >(currentBan.duration.count());
auto startEpoch = static_cast< unsigned int >(toEpochSeconds(currentBan.startDate));
auto duration = static_cast< unsigned int >(currentBan.duration.count());
std::string userName;
std::string userCert;
std::string reason;
Expand Down
2 changes: 1 addition & 1 deletion src/murmur/database/ChronoUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#ifndef MUMBLE_SERVER_DATABASE_CHRONOUTILS_H_
#define MUMBLE_SERVER_DATABASE_CHRONOUTILS_H_

#include <chrono>
#include <cassert>
#include <chrono>

namespace mumble {
namespace server {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/TestDatabase/DefaultTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace db {
std::string DefaultTable::select(const std::string &key) {
try {
std::string value;
m_sql << "SELECT \"DefaultColValue\" FROM \"" + getName() + "\" WHERE \"DefaultColKey\" = :key", soci::use(key),
soci::into(value);
m_sql << "SELECT \"DefaultColValue\" FROM \"" + getName() + "\" WHERE \"DefaultColKey\" = :key",
soci::use(key), soci::into(value);

::mumble::db::utils::verifyQueryResultedInData(m_sql);

Expand Down
7 changes: 4 additions & 3 deletions src/tests/TestDatabase/server/ServerDatabaseTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ void print_exception_message(const std::exception &e) {
* Helper function to convert a std::chrono::timepoint to seconds since epoch
*/
template< typename TimePoint > std::size_t toSeconds(const TimePoint &tp) {
return static_cast< std::size_t >(std::chrono::duration_cast< std::chrono::seconds >(tp.time_since_epoch()).count());
return static_cast< std::size_t >(
std::chrono::duration_cast< std::chrono::seconds >(tp.time_since_epoch()).count());
}


Expand Down Expand Up @@ -368,8 +369,8 @@ void ServerDatabaseTest::logTable_general() {

for (std::size_t maxEntries = 0; maxEntries < entries.size() + 2; ++maxEntries) {
for (std::size_t offset = 0; offset < entries.size() + 2; ++offset) {
std::vector<::msdb::DBLogEntry > fetchedEntries =
db.getLogTable().getLogs(existingServerID, static_cast< unsigned int >(maxEntries), static_cast< unsigned int >(offset));
std::vector<::msdb::DBLogEntry > fetchedEntries = db.getLogTable().getLogs(
existingServerID, static_cast< unsigned int >(maxEntries), static_cast< unsigned int >(offset));

const int totalEntryCount = static_cast< int >(entries.size());
int maxPossibleEntries = totalEntryCount - std::min(static_cast< int >(offset), totalEntryCount);
Expand Down

0 comments on commit 2877543

Please sign in to comment.