void Server::externalResponseReceived(const Response &resp, qint64 sessionId) { // This function is always called from the main thread via signal/slot. QReadLocker usersLocker(&clientsLock); Server_ProtocolHandler *client = usersBySessionId.value(sessionId); if (!client) { qDebug() << "externalResponseReceived: session" << sessionId << "not found"; return; } client->sendProtocolItem(resp); }
void Chat::receiveMessage(QSharedPointer<const User> participant, const sdc::ByteSeq &encMsg) { QMutexLocker usersLocker(&usersMutex); if (!users.contains(participant->getName())) { QLOG_ERROR() << QString("Received message for chat '%1' from user '%2', " "who is not in the chat").arg(chatID) .arg(participant->getName()); return; } usersLocker.unlock(); QString msg; try { sdc::Security s; sdc::ByteSeq decMsg = s.decryptAES(key, encMsg); msg = QString::fromUtf8(sdc::sdcHelper::getBinaryString(decMsg).c_str()); QLOG_TRACE() << "Received message: " << msg; struct sdc::LogMessage logEntry = { participant->getName().toStdString(), QDateTime::currentDateTimeUtc().toTime_t(), msg.toStdString() }; QMutexLocker logLocker(&logMutex); log.push_back(logEntry); } catch (const sdc::SecurityException &e) { // TODO: Workaround cause I don't know how to report generic errors... msg = "<received message but could not decrypt it>"; } // TODO: What if we receive invalid UTF8 code points? QString doesn't // give us any information on this. This should only occur if other clients // encode their messages differently though. emit messageReceived(participant, msg); }