-// returns 0 if the message will not be chopped by the irc server or number of chopped bytes if message is too long
-int CoreUserInputHandler::lastParamOverrun(const QString &cmd, const QList<QByteArray> ¶ms) {
- // the server will pass our message truncated to 512 bytes including CRLF with the following format:
- // ":prefix COMMAND param0 param1 :lastparam"
- // where prefix = "nickname!user@host"
- // that means that the last message can be as long as:
- // 512 - nicklen - userlen - hostlen - commandlen - sum(param[0]..param[n-1])) - 2 (for CRLF) - 4 (":!@" + 1space between prefix and command) - max(paramcount - 1, 0) (space for simple params) - 2 (space and colon for last param)
- IrcUser *me = network()->me();
- int maxLen = 480 - cmd.toAscii().count(); // educated guess in case we don't know us (yet?)
-
- if(me)
- maxLen = 512 - serverEncode(me->nick()).count() - serverEncode(me->user()).count() - serverEncode(me->host()).count() - cmd.toAscii().count() - 6;
-
- if(!params.isEmpty()) {
- for(int i = 0; i < params.count() - 1; i++) {
- maxLen -= (params[i].count() + 1);
- }
- maxLen -= 2; // " :" last param separator;
-
- if(params.last().count() > maxLen) {
- return params.last().count() - maxLen;
- } else {
- return 0;
- }
- } else {
- return 0;
- }
-}
-
-void CoreUserInputHandler::timerEvent(QTimerEvent *event) {
- if(!_delayedCommands.contains(event->timerId())) {
- QObject::timerEvent(event);
- return;
- }
- BufferInfo bufferInfo = _delayedCommands[event->timerId()].bufferInfo;
- QString rawCommand = _delayedCommands[event->timerId()].command;
- _delayedCommands.remove(event->timerId());
- event->accept();
-
- // the stored command might be the result of an alias expansion, so we need to split it up again
- QStringList commands = rawCommand.split(QRegExp("; ?"));
- foreach(QString command, commands) {
- handleUserInput(bufferInfo, command);
- }
+#ifdef HAVE_QCA2
+QByteArray CoreUserInputHandler::encrypt(const QString& target, const QByteArray& message_, bool* didEncrypt) const
+{
+ if (didEncrypt)
+ *didEncrypt = false;
+
+ if (message_.isEmpty())
+ return message_;
+
+ if (!Cipher::neededFeaturesAvailable())
+ return message_;
+
+ Cipher* cipher = network()->cipher(target);
+ if (!cipher || cipher->key().isEmpty())
+ return message_;
+
+ QByteArray message = message_;
+ bool result = cipher->encrypt(message);
+ if (didEncrypt)
+ *didEncrypt = result;
+
+ return message;
+}
+
+#endif
+
+void CoreUserInputHandler::timerEvent(QTimerEvent* event)
+{
+ if (!_delayedCommands.contains(event->timerId())) {
+ QObject::timerEvent(event);
+ return;
+ }
+ BufferInfo bufferInfo = _delayedCommands[event->timerId()].bufferInfo;
+ QString rawCommand = _delayedCommands[event->timerId()].command;
+ _delayedCommands.remove(event->timerId());
+ event->accept();
+
+ // the stored command might be the result of an alias expansion, so we need to split it up again
+ QStringList commands = rawCommand.split(QRegExp("; ?"));
+ for (const QString& command : commands) {
+ handleUserInput(bufferInfo, command);
+ }