Changeset View
Changeset View
Standalone View
Standalone View
src/irc/inputfilter.cpp
Show All 20 Lines | |||||
21 | #include "channel.h" | 21 | #include "channel.h" | ||
22 | #include "statuspanel.h" | 22 | #include "statuspanel.h" | ||
23 | #include "common.h" | 23 | #include "common.h" | ||
24 | #include "notificationhandler.h" | 24 | #include "notificationhandler.h" | ||
25 | #include <config-konversation.h> | 25 | #include <config-konversation.h> | ||
26 | 26 | | |||
27 | #include <QStringList> | 27 | #include <QStringList> | ||
28 | #include <QDateTime> | 28 | #include <QDateTime> | ||
29 | #include <QRegExp> | 29 | #include <QRegularExpression> | ||
30 | #include <QLocale> | 30 | #include <QLocale> | ||
31 | 31 | | |||
32 | 32 | | |||
33 | InputFilter::InputFilter() | 33 | InputFilter::InputFilter() | ||
34 | : m_server(nullptr), | 34 | : m_server(nullptr), | ||
35 | m_lagMeasuring(false) | 35 | m_lagMeasuring(false) | ||
36 | { | 36 | { | ||
37 | m_connecting = false; | 37 | m_connecting = false; | ||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 199 | if (!channel) { | |||
200 | qCritical() << "Didn't find the channel " << parameterList.value(0); | 200 | qCritical() << "Didn't find the channel " << parameterList.value(0); | ||
201 | return; | 201 | return; | ||
202 | } | 202 | } | ||
203 | 203 | | |||
204 | channel->appendAction(sourceNick, ctcpArgument, messageTags); | 204 | channel->appendAction(sourceNick, ctcpArgument, messageTags); | ||
205 | 205 | | |||
206 | if (sourceNick != m_server->getNickname()) | 206 | if (sourceNick != m_server->getNickname()) | ||
207 | { | 207 | { | ||
208 | if (hasArg && ctcpArgument.toLower().contains(QRegExp(QStringLiteral("(^|[^\\d\\w])") | 208 | const QRegularExpression re(QLatin1String("(^|[^\\d\\w])") | ||
209 | + QRegExp::escape(m_server->loweredNickname()) | 209 | + QRegularExpression::escape(m_server->loweredNickname()) | ||
210 | + QStringLiteral("([^\\d\\w]|$)")))) | 210 | + QLatin1String("([^\\d\\w]|$)")); | ||
211 | if (hasArg && ctcpArgument.toLower().contains(re)) | ||||
211 | { | 212 | { | ||
212 | konv_app->notificationHandler()->nick(channel, sourceNick, ctcpArgument); | 213 | konv_app->notificationHandler()->nick(channel, sourceNick, ctcpArgument); | ||
213 | } | 214 | } | ||
214 | else | 215 | else | ||
215 | { | 216 | { | ||
216 | konv_app->notificationHandler()->message(channel, sourceNick, ctcpArgument); | 217 | konv_app->notificationHandler()->message(channel, sourceNick, ctcpArgument); | ||
217 | } | 218 | } | ||
218 | } | 219 | } | ||
▲ Show 20 Lines • Show All 578 Lines • ▼ Show 20 Line(s) | 797 | { | |||
797 | QString command = parameterList.value(1).toLower(); | 798 | QString command = parameterList.value(1).toLower(); | ||
798 | 799 | | |||
799 | if (command == QLatin1String("ack") || command == QLatin1String("nak")) | 800 | if (command == QLatin1String("ack") || command == QLatin1String("nak")) | ||
800 | { | 801 | { | ||
801 | m_server->capReply(); | 802 | m_server->capReply(); | ||
802 | 803 | | |||
803 | QStringList capabilities = parameterList.value(2).split(QLatin1Char(' '), QString::SkipEmptyParts); | 804 | QStringList capabilities = parameterList.value(2).split(QLatin1Char(' '), QString::SkipEmptyParts); | ||
804 | 805 | | |||
806 | const QRegularExpression re(QStringLiteral("[a-z0-9]"), QRegularExpression::CaseInsensitiveOption); | ||||
805 | foreach(const QString& capability, capabilities) | 807 | foreach(const QString& capability, capabilities) | ||
806 | { | 808 | { | ||
807 | int nameStart = capability.indexOf(QRegExp(QStringLiteral("[a-z0-9]"), Qt::CaseInsensitive)); | 809 | const int nameStart = capability.indexOf(re); | ||
808 | QString modifierString = capability.left(nameStart); | 810 | QString modifierString = capability.left(nameStart); | ||
809 | QString name = capability.mid(nameStart); | 811 | QString name = capability.mid(nameStart); | ||
810 | 812 | | |||
811 | Server::CapModifiers modifiers = Server::NoModifiers; | 813 | Server::CapModifiers modifiers = Server::NoModifiers; | ||
812 | 814 | | |||
813 | if (modifierString.contains(QLatin1Char('-'))) | 815 | if (modifierString.contains(QLatin1Char('-'))) | ||
814 | { | 816 | { | ||
815 | modifiers = modifiers | Server::DisMod; | 817 | modifiers = modifiers | Server::DisMod; | ||
▲ Show 20 Lines • Show All 147 Lines • ▼ Show 20 Line(s) | 961 | { | |||
963 | // if we ever see the assert, we need the ternary | 965 | // if we ever see the assert, we need the ternary | ||
964 | return m_server? m_server->isAChannel(check) : bool(QString(QStringLiteral("#&")).contains(check.at(0))); | 966 | return m_server? m_server->isAChannel(check) : bool(QString(QStringLiteral("#&")).contains(check.at(0))); | ||
965 | } | 967 | } | ||
966 | 968 | | |||
967 | bool InputFilter::isIgnore(const QString &sender, Ignore::Type type) | 969 | bool InputFilter::isIgnore(const QString &sender, Ignore::Type type) | ||
968 | { | 970 | { | ||
969 | bool doIgnore = false; | 971 | bool doIgnore = false; | ||
970 | 972 | | |||
973 | QRegularExpression ignoreRe; | ||||
974 | ignoreRe.setPatternOptions(QRegularExpression::CaseInsensitiveOption); | ||||
971 | foreach (Ignore* item, Preferences::ignoreList()) | 975 | foreach (Ignore* item, Preferences::ignoreList()) | ||
972 | { | 976 | { | ||
973 | QRegExp ignoreItem(QRegExp::escape(item->getName()).replace(QStringLiteral("\\*"), QStringLiteral("(.*)")), Qt::CaseInsensitive); | 977 | ignoreRe.setPattern(QRegularExpression::anchoredPattern(QRegularExpression::escape( | ||
974 | if (ignoreItem.exactMatch(sender) && (item->getFlags() & type)) | 978 | item->getName()).replace(QLatin1String("\\*"), QLatin1String("(.*)")))); | ||
979 | | ||||
980 | if (ignoreRe.match(sender).hasMatch()) { | ||||
981 | if (item->getFlags() & type) { | ||||
975 | doIgnore = true; | 982 | doIgnore = true; | ||
976 | if (ignoreItem.exactMatch(sender) && (item->getFlags() & Ignore::Exception)) | 983 | } | ||
984 | | ||||
985 | if (item->getFlags() & Ignore::Exception) { | ||||
977 | return false; | 986 | return false; | ||
978 | } | 987 | } | ||
988 | } | ||||
989 | } | ||||
979 | 990 | | |||
980 | return doIgnore; | 991 | return doIgnore; | ||
981 | } | 992 | } | ||
982 | 993 | | |||
983 | void InputFilter::reset() | 994 | void InputFilter::reset() | ||
984 | { | 995 | { | ||
985 | m_automaticRequest.clear(); | 996 | m_automaticRequest.clear(); | ||
986 | m_whoRequestList.clear(); | 997 | m_whoRequestList.clear(); | ||
Show All 38 Lines | 1025 | { | |||
1025 | else | 1036 | else | ||
1026 | { | 1037 | { | ||
1027 | source = prefix; | 1038 | source = prefix; | ||
1028 | } | 1039 | } | ||
1029 | 1040 | | |||
1030 | Application* konv_app = Application::instance(); | 1041 | Application* konv_app = Application::instance(); | ||
1031 | message = konv_app->doAutoreplace(message, false).first; | 1042 | message = konv_app->doAutoreplace(message, false).first; | ||
1032 | 1043 | | |||
1044 | const QRegularExpression regexp(QLatin1String("(^|[^\\d\\w])") | ||||
1045 | + QRegularExpression::escape(m_server->loweredNickname()) | ||||
1046 | + QLatin1String("([^\\d\\w]|$)"), | ||||
1047 | QRegularExpression::CaseInsensitiveOption); | ||||
1033 | if(isAChannel(parameterList.value(0))) | 1048 | if(isAChannel(parameterList.value(0))) | ||
1034 | { | 1049 | { | ||
1035 | if(!isIgnore(prefix, Ignore::Channel)) | 1050 | if(!isIgnore(prefix, Ignore::Channel)) | ||
1036 | { | 1051 | { | ||
1037 | Channel* channel = m_server->getChannelByName(parameterList.value(0)); | 1052 | Channel* channel = m_server->getChannelByName(parameterList.value(0)); | ||
1038 | if(channel) | 1053 | if(channel) | ||
1039 | { | 1054 | { | ||
1040 | QString label; | 1055 | QString label; | ||
1041 | 1056 | | |||
1042 | if (m_server->getServerNickPrefixes().contains(parameterList.value(0).at(0))) | 1057 | if (m_server->getServerNickPrefixes().contains(parameterList.value(0).at(0))) | ||
1043 | { | 1058 | { | ||
1044 | label = parameterList.value(0); | 1059 | label = parameterList.value(0); | ||
1045 | } | 1060 | } | ||
1046 | 1061 | | |||
1047 | channel->append(source, message, messageTags, label); | 1062 | channel->append(source, message, messageTags, label); | ||
1048 | 1063 | | |||
1049 | if(source != m_server->getNickname()) | 1064 | if(source != m_server->getNickname()) | ||
1050 | { | 1065 | { | ||
1051 | QRegExp regexp(QStringLiteral("(^|[^\\d\\w])") + | | |||
1052 | QRegExp::escape(m_server->loweredNickname()) + | | |||
1053 | QStringLiteral("([^\\d\\w]|$)")); | | |||
1054 | regexp.setCaseSensitivity(Qt::CaseInsensitive); | | |||
1055 | if(message.contains(regexp)) | 1066 | if(message.contains(regexp)) | ||
1056 | { | 1067 | { | ||
1057 | konv_app->notificationHandler()->nick(channel, | 1068 | konv_app->notificationHandler()->nick(channel, | ||
1058 | source, message); | 1069 | source, message); | ||
1059 | } | 1070 | } | ||
1060 | else | 1071 | else | ||
1061 | { | 1072 | { | ||
1062 | konv_app->notificationHandler()->message(channel, | 1073 | konv_app->notificationHandler()->message(channel, | ||
Show All 21 Lines | 1083 | { | |||
1084 | // Create a new query (server will check for dupes) | 1095 | // Create a new query (server will check for dupes) | ||
1085 | Query* query = m_server->addQuery(nickinfo, false /*we didn't initiate this*/ ); | 1096 | Query* query = m_server->addQuery(nickinfo, false /*we didn't initiate this*/ ); | ||
1086 | 1097 | | |||
1087 | // send action to query | 1098 | // send action to query | ||
1088 | query->appendQuery(source, message, messageTags); | 1099 | query->appendQuery(source, message, messageTags); | ||
1089 | 1100 | | |||
1090 | if(source != m_server->getNickname() && query) | 1101 | if(source != m_server->getNickname() && query) | ||
1091 | { | 1102 | { | ||
1092 | QRegExp regexp(QStringLiteral("(^|[^\\d\\w])") + | | |||
1093 | QRegExp::escape(m_server->loweredNickname()) + | | |||
1094 | QStringLiteral("([^\\d\\w]|$)")); | | |||
1095 | regexp.setCaseSensitivity(Qt::CaseInsensitive); | | |||
1096 | if(message.contains(regexp)) | 1103 | if(message.contains(regexp)) | ||
1097 | { | 1104 | { | ||
1098 | konv_app->notificationHandler()->nick(query, | 1105 | konv_app->notificationHandler()->nick(query, | ||
1099 | source, message); | 1106 | source, message); | ||
1100 | } | 1107 | } | ||
1101 | else | 1108 | else | ||
1102 | { | 1109 | { | ||
1103 | konv_app->notificationHandler()->queryMessage(query, | 1110 | konv_app->notificationHandler()->queryMessage(query, | ||
▲ Show 20 Lines • Show All 756 Lines • ▼ Show 20 Line(s) | 1141 | { | |||
1860 | { | 1867 | { | ||
1861 | if (plHas(6)) | 1868 | if (plHas(6)) | ||
1862 | { | 1869 | { | ||
1863 | NickInfoPtr nickInfo = m_server->getNickInfo(parameterList.value(5)); | 1870 | NickInfoPtr nickInfo = m_server->getNickInfo(parameterList.value(5)); | ||
1864 | // G=away G@=away,op G+=away,voice | 1871 | // G=away G@=away,op G+=away,voice | ||
1865 | bool bAway = parameterList.value(6).toUpper().startsWith(QLatin1Char('G')); | 1872 | bool bAway = parameterList.value(6).toUpper().startsWith(QLatin1Char('G')); | ||
1866 | QString realName = trailing; | 1873 | QString realName = trailing; | ||
1867 | 1874 | | |||
1868 | if (realName.indexOf (QRegExp(QStringLiteral("\\d\\s"))) == 0) | 1875 | if (realName.indexOf(QRegularExpression(QStringLiteral("\\d\\s"))) == 0) | ||
1869 | realName = realName.mid (2); | 1876 | realName = realName.mid (2); | ||
1870 | 1877 | | |||
1871 | if (nickInfo) | 1878 | if (nickInfo) | ||
1872 | { | 1879 | { | ||
1873 | nickInfo->setHostmask(i18n("%1@%2", parameterList.value(2), parameterList.value(3))); | 1880 | nickInfo->setHostmask(i18n("%1@%2", parameterList.value(2), parameterList.value(3))); | ||
1874 | nickInfo->setRealName(realName); | 1881 | nickInfo->setRealName(realName); | ||
1875 | nickInfo->setAway(bAway); | 1882 | nickInfo->setAway(bAway); | ||
1876 | if(!bAway) | 1883 | if(!bAway) | ||
▲ Show 20 Lines • Show All 663 Lines • Show Last 20 Lines |