-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OMEMO-encrypted MUC logging functionality #94
Changes from 9 commits
170b5ee
641a446
c3a7991
09b4626
71a5e0a
55b6939
5d138f0
78801f0
05db402
ecdd025
fbc9d89
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -235,6 +235,26 @@ bool OMEMOPlugin::decryptMessageElement(int account, QDomElement &message) | |||||
processEncryptedFile(account, message); | ||||||
} | ||||||
|
||||||
// logging functionality for OMEMO-encrypted groupchats | ||||||
if (message.attribute("type") == "groupchat") { | ||||||
QString from = message.attribute("from"); | ||||||
QStringList List = from.split("/"); | ||||||
QString room = List.takeFirst(); | ||||||
if (!List.isEmpty()) { | ||||||
from = List.join("/"); | ||||||
} | ||||||
if (from != m_mucNicks[room]) { | ||||||
QString Stamp = message.firstChildElement("x").attribute("stamp"); | ||||||
QDomElement body = message.firstChildElement("body"); | ||||||
if (!body.isNull()) { | ||||||
QString Text = body.text(); | ||||||
QString MyJid = m_accountInfo->getJid(account); | ||||||
MyJid = MyJid.replace("@", "_at_"); | ||||||
logMuc(room, from, MyJid, Text, Stamp); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
taking into account my previous suggestion |
||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return true; | ||||||
} | ||||||
|
||||||
|
@@ -313,8 +333,16 @@ bool OMEMOPlugin::outgoingStanza(int account, QDomElement &xml) | |||||
return false; | ||||||
} | ||||||
|
||||||
if (xml.nodeName() == "presence" && !xml.hasAttributes()) { | ||||||
m_omemo->accountConnected(account, m_accountInfo->getJid(account)); | ||||||
if (xml.nodeName() == "presence") { | ||||||
if (!xml.hasAttributes()) | ||||||
m_omemo->accountConnected(account, m_accountInfo->getJid(account)); | ||||||
// get all MUC nicks of the current account for groupchat logging | ||||||
// functionality | ||||||
else { | ||||||
QStringList room_nick = xml.attribute("to").split("/"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this thing may interfere with some non-muc presences. Like for example when we send a direct presence to a single contact. |
||||||
m_mucNicks.insert(room_nick[0], room_nick[1]); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like we never clean it. |
||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
return false; | ||||||
|
@@ -330,6 +358,22 @@ bool OMEMOPlugin::encryptMessageElement(int account, QDomElement &message) | |||||
return false; | ||||||
} | ||||||
|
||||||
// logging functionality for OMEMO-encrypted groupchats | ||||||
if (message.attribute("type") == "groupchat") { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please prefer wrapping string literals with QLatin1String. This way we improve performance by avoiding string conversion from "maybe unicode" to "unicode".
|
||||||
QString room = message.attribute("to"); | ||||||
QString from = m_mucNicks[room]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
will avoid invalid empty nickname insertion if room is not there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, but wouldn't .value() also return an empty string if the room is not there (unless the second parameter of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will return empty string. that's correct. Imagine a case where you enable OMEMO plugin already after joining. So you missed the initial presence and have to live with this somehow. (drop everything encrypted / force rejoin / ask user what to do) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd go with the easiest way improving the stuff with consequent MRs :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, so I changed the behavior to logging the full jid instead of the nick in case the nick is empty. Would that be fine for now? Can't think of any elegant solution to the problem yet There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep. should be good for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, there is a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's fine to modify plugin interfaces if anything is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, okay. I'll see what can be done, would be great to remove the presence tracking hack as a whole There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||||||
if (m_omemo->isEnabledForUser(account, room)) { // only log if encryption is enabled | ||||||
QString Stamp = message.firstChildElement("x").attribute("stamp"); | ||||||
QDomElement body = message.firstChildElement("body"); | ||||||
if (!body.isNull()) { | ||||||
QString Text = body.text(); | ||||||
QString MyJid = m_accountInfo->getJid(account); | ||||||
MyJid = MyJid.replace("@", "_at_"); | ||||||
logMuc(room, from, MyJid, Text, Stamp); | ||||||
} | ||||||
} | ||||||
} | ||||||
|
||||||
return m_omemo->encryptMessage(m_accountInfo->getJid(account), account, message); | ||||||
} | ||||||
|
||||||
|
@@ -544,4 +588,30 @@ bool OMEMOPlugin::execute(int account, const QHash<QString, QVariant> &args, QHa | |||||
|
||||||
return false; | ||||||
} | ||||||
|
||||||
// the code partly taken from the Conference Logger plugin | ||||||
void OMEMOPlugin::logMuc(QString room, const QString &from, const QString &myJid, | ||||||
const QString &text, QString stamp) | ||||||
{ | ||||||
room = room.replace("@", "_at_"); | ||||||
room = "_in_" + room; | ||||||
if (stamp.isEmpty()) { | ||||||
stamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); | ||||||
} else { | ||||||
stamp.insert(4, "-"); | ||||||
stamp.insert(7, "-"); | ||||||
stamp.replace("T", " "); | ||||||
} | ||||||
QFile file(m_applicationInfo->appHistoryDir() + QDir::separator() + myJid + room + ".conferencehistory"); | ||||||
if (file.open(QIODevice::WriteOnly | QIODevice::Append)) { | ||||||
QTextStream out(&file); | ||||||
out.setCodec("UTF-8"); | ||||||
out.setGenerateByteOrderMark(false); | ||||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) | ||||||
out << stamp << " " << from << ": " << text << Qt::endl; | ||||||
#else | ||||||
out << stamp << " " << from << ": " << text << endl; | ||||||
#endif | ||||||
} | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prevent empty insertions if for some reason room is not in the map.