Changeset 286:f89643c5ff59
- Timestamp:
- 06/22/2008 06:53:57 PM (4 years ago)
- Author:
- Dmitry Nezhevenko <dion@…>
- Branch:
- default
- Message:
-
ALists: version matchers
- Location:
- src/plugins/muc
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r283
|
r286
|
|
| 64 | 64 | { |
| 65 | 65 | case AListItem::MatcherUnknown: |
| 66 | | flags+="?"; |
| | 66 | flags+="? "; |
| 67 | 67 | break; |
| 68 | 68 | case AListItem::MatcherNick: |
| 69 | | flags+="N"; |
| | 69 | flags+="N "; |
| 70 | 70 | break; |
| 71 | 71 | case AListItem::MatcherJid: |
| 72 | | flags+="J"; |
| | 72 | flags+="J "; |
| 73 | 73 | break; |
| 74 | 74 | case AListItem::MatcherBody: |
| 75 | | flags+="B"; |
| | 75 | flags+="B "; |
| 76 | 76 | break; |
| 77 | 77 | case AListItem::MatcherResource: |
| 78 | | flags+="R"; |
| | 78 | flags+="R "; |
| | 79 | break; |
| | 80 | case AListItem::MatcherVersion: |
| | 81 | flags+="V "; |
| | 82 | break; |
| | 83 | case AListItem::MatcherVersionName: |
| | 84 | flags+="Vn"; |
| | 85 | break; |
| | 86 | case AListItem::MatcherVersionClient: |
| | 87 | flags+="Vn"; |
| | 88 | break; |
| | 89 | case AListItem::MatcherVersionOs: |
| | 90 | flags+="Vo"; |
| 79 | 91 | break; |
| 80 | 92 | }; |
-
|
r283
|
r286
|
|
| 29 | 29 | enum MatcherType |
| 30 | 30 | { |
| | 31 | MatcherAll=-1, |
| 31 | 32 | MatcherUnknown=0, |
| 32 | 33 | MatcherNick=1, |
| 33 | 34 | MatcherJid=2, |
| 34 | 35 | MatcherBody=3, |
| 35 | | MatcherResource=4 |
| | 36 | MatcherResource=4, |
| | 37 | MatcherVersion=5, |
| | 38 | MatcherVersionName=6, |
| | 39 | MatcherVersionClient=7, |
| | 40 | MatcherVersionOs=8 |
| 36 | 41 | }; |
| 37 | 42 | |
| … |
… |
|
| 41 | 46 | TestExact=1, |
| 42 | 47 | TestRegExp=2, |
| 43 | | TestSubstring=3 |
| | 48 | TestSubstring=3 |
| 44 | 49 | }; |
| 45 | 50 | |
-
|
r285
|
r286
|
|
| 993 | 993 | delete req; |
| 994 | 994 | bot()->asyncRequests()->removeAll(req); |
| | 995 | nick->setVersionStored(true); |
| | 996 | checkMember(0L, conf, nick, AListItem::MatcherVersion); |
| 995 | 997 | return true; |
| 996 | 998 | } |
| … |
… |
|
| 1033 | 1035 | |
| 1034 | 1036 | AListItem* item=0; |
| 1035 | | if (item=aFind(conf->aban(), n, 0L)) |
| | 1037 | if (item=aFind(conf->aban(), n, 0L, AListItem::MatcherAll)) |
| 1036 | 1038 | answer+=QString("\"%1\" is in aban list: %2\n").arg(arg2.toLower()).arg(item->toString()); |
| 1037 | | if (item=aFind(conf->akick(), n, 0L)) |
| | 1039 | if (item=aFind(conf->akick(), n, 0L, AListItem::MatcherAll)) |
| 1038 | 1040 | answer+=QString("\"%1\" is in akick list: %2\n").arg(arg2.toLower()).arg(item->toString()); |
| 1039 | | if (item=aFind(conf->avisitor(), n, 0L)) |
| | 1041 | if (item=aFind(conf->avisitor(), n, 0L, AListItem::MatcherAll)) |
| 1040 | 1042 | answer+=QString("\"%1\" is in avisitor list: %2\n").arg(arg2.toLower()).arg(item->toString()); |
| 1041 | | if (item=aFind(conf->amoderator(), n, 0L)) |
| | 1043 | if (item=aFind(conf->amoderator(), n, 0L, AListItem::MatcherAll)) |
| 1042 | 1044 | answer+=QString("\"%1\" is in amoderator list: %2\n").arg(arg2.toLower()).arg(item->toString()); |
| 1043 | | if (item=aFind(conf->acommand(), n, 0L)) |
| | 1045 | if (item=aFind(conf->acommand(), n, 0L, AListItem::MatcherAll)) |
| 1044 | 1046 | answer+=QString("\"%1\" is in acmd list: %2\n").arg(arg2.toLower()).arg(item->toString()); |
| 1045 | 1047 | if (answer.endsWith("\n")) |
| … |
… |
|
| 1167 | 1169 | qDebug() << "1: " << arg2; |
| 1168 | 1170 | |
| 1169 | | if (arg2=="NICK" || arg2=="BODY" || arg2=="RES") |
| | 1171 | if (arg2=="NICK" || arg2=="BODY" || arg2=="RES" |
| | 1172 | || arg2=="VERSION" || arg2=="VERSION.NAME" |
| | 1173 | || arg2=="VERSION.CLIENT" || arg2=="VERSION.OS") |
| 1170 | 1174 | { |
| 1171 | 1175 | if (arg2=="NICK") |
| … |
… |
|
| 1175 | 1179 | else if (arg2=="RES") |
| 1176 | 1180 | item.setMatcherType(AListItem::MatcherResource); |
| | 1181 | else if (arg2=="VERSION") |
| | 1182 | item.setMatcherType(AListItem::MatcherVersion); |
| | 1183 | else if (arg2=="VERSION.NAME") |
| | 1184 | item.setMatcherType(AListItem::MatcherVersionName); |
| | 1185 | else if (arg2=="VERSION.CLIENT") |
| | 1186 | item.setMatcherType(AListItem::MatcherVersionClient); |
| | 1187 | else if (arg2=="VERSION.OS") |
| | 1188 | item.setMatcherType(AListItem::MatcherVersionOs); |
| 1177 | 1189 | |
| 1178 | 1190 | arg2=parser.nextToken().toUpper(); |
| … |
… |
|
| 1275 | 1287 | |
| 1276 | 1288 | // Stanza can be null here |
| 1277 | | AListItem* MucPlugin::aFind(AList* list, Nick* nick, gloox::Stanza* s) |
| | 1289 | AListItem* MucPlugin::aFind(AList* list, Nick* nick, gloox::Stanza* s, AListItem::MatcherType matcher) |
| 1278 | 1290 | { |
| 1279 | 1291 | int cnt=list->count(); |
| … |
… |
|
| 1285 | 1297 | if (s) |
| 1286 | 1298 | lBody=QString::fromStdString(s->body()).toLower(); |
| | 1299 | QString version; |
| | 1300 | if (nick->isVersionStored()) |
| | 1301 | version=nick->versionName()+" "+nick->versionClient()+" // "+nick->versionOs(); |
| 1287 | 1302 | |
| 1288 | 1303 | bool isPresence=!s || (s->type()==gloox::StanzaPresence); |
| … |
… |
|
| 1291 | 1306 | { |
| 1292 | 1307 | AListItem* item=list->at(i); |
| | 1308 | |
| | 1309 | if (matcher!=AListItem::MatcherUnknown && matcher!=AListItem::MatcherAll && |
| | 1310 | !item->matcherType()!=matcher) |
| | 1311 | { |
| | 1312 | if (matcher=AListItem::MatcherVersion) |
| | 1313 | { |
| | 1314 | if (!(item->matcherType()==AListItem::MatcherVersionName |
| | 1315 | || item->matcherType()==AListItem::MatcherVersionClient |
| | 1316 | || item->matcherType()==AListItem::MatcherVersionOs)) |
| | 1317 | continue; |
| | 1318 | } |
| | 1319 | else |
| | 1320 | continue; |
| | 1321 | } |
| 1293 | 1322 | |
| 1294 | 1323 | QString testValue; |
| … |
… |
|
| 1297 | 1326 | continue; |
| 1298 | 1327 | |
| | 1328 | if (item->matcherType() == AListItem::MatcherVersion |
| | 1329 | || item->matcherType()==AListItem::MatcherVersionName |
| | 1330 | || item->matcherType()==AListItem::MatcherVersionClient |
| | 1331 | || item->matcherType()==AListItem::MatcherVersionOs) |
| | 1332 | { |
| | 1333 | if (matcher!=AListItem::MatcherVersion && matcher!=AListItem::MatcherAll) |
| | 1334 | continue; |
| | 1335 | if (!nick || !nick->isVersionStored()) |
| | 1336 | continue; |
| | 1337 | } |
| | 1338 | |
| 1299 | 1339 | switch (item->matcherType()) |
| 1300 | 1340 | { |
| … |
… |
|
| 1304 | 1344 | case AListItem::MatcherResource: testValue=lResource; break; |
| 1305 | 1345 | case AListItem::MatcherBody: testValue=lBody; break; |
| 1306 | | } |
| | 1346 | case AListItem::MatcherVersion: testValue=version; break; |
| | 1347 | case AListItem::MatcherVersionName: testValue=nick->versionName(); break; |
| | 1348 | case AListItem::MatcherVersionClient: testValue=nick->versionClient(); break; |
| | 1349 | case AListItem::MatcherVersionOs: testValue=nick->versionOs(); break; |
| | 1350 | default: continue; |
| | 1351 | } |
| | 1352 | |
| 1307 | 1353 | if (testValue.isEmpty()) |
| 1308 | 1354 | continue; |
| … |
… |
|
| 1328 | 1374 | case AListItem::TestSubstring: |
| 1329 | 1375 | { |
| 1330 | | if (item->isInvert() ^ (testValue.indexOf(item->value())>=0)) |
| | 1376 | if (item->isInvert() ^ (testValue.toLower().indexOf(item->value().toLower())>=0)) |
| 1331 | 1377 | return item; |
| 1332 | 1378 | break; |
| … |
… |
|
| 1337 | 1383 | } |
| 1338 | 1384 | |
| 1339 | | void MucPlugin::checkMember(gloox::Stanza* s, Conference*c, Nick* n) |
| | 1385 | void MucPlugin::checkMember(gloox::Stanza* s, Conference*c, Nick* n, AListItem::MatcherType matcher) |
| 1340 | 1386 | { |
| 1341 | 1387 | if (!n || !c) |
| … |
… |
|
| 1354 | 1400 | if (((aff!="OWNER") && !aff.startsWith("ADMIN") && aff!="MEMBER")|| c->configurator()->isApplyAlistsToMembers()) |
| 1355 | 1401 | { |
| 1356 | | if (item=aFind(c->aban(), n, s)) |
| | 1402 | if (item=aFind(c->aban(), n, s, matcher)) |
| 1357 | 1403 | { |
| 1358 | 1404 | if (s && warnImOwner(s)) |
| … |
… |
|
| 1365 | 1411 | } |
| 1366 | 1412 | |
| 1367 | | if (item=aFind(c->akick(), n, s)) |
| | 1413 | if (item=aFind(c->akick(), n, s, matcher)) |
| 1368 | 1414 | { |
| 1369 | 1415 | QString reason=item->reason(); |
| … |
… |
|
| 1373 | 1419 | return; |
| 1374 | 1420 | } |
| 1375 | | if (item=aFind(c->avisitor(), n, s)) |
| | 1421 | if (item=aFind(c->avisitor(), n, s, matcher)) |
| 1376 | 1422 | { |
| 1377 | 1423 | QString reason=item->reason(); |
| … |
… |
|
| 1382 | 1428 | } |
| 1383 | 1429 | } |
| 1384 | | if (item=aFind(c->amoderator(), n, s)) |
| | 1430 | if (item=aFind(c->amoderator(), n, s, matcher)) |
| 1385 | 1431 | { |
| 1386 | 1432 | QString reason=item->reason(); |
| … |
… |
|
| 1391 | 1437 | } |
| 1392 | 1438 | |
| 1393 | | if (item=aFind(c->acommand(), n, s)) |
| | 1439 | if (item=aFind(c->acommand(), n, s, matcher)) |
| 1394 | 1440 | { |
| 1395 | 1441 | QString action=item->reason(); |
-
|
r285
|
r286
|
|
| 4 | 4 | #include "base/baseplugin.h" |
| 5 | 5 | #include "conferencelist.h" |
| | 6 | #include "alistitem.h" |
| 6 | 7 | |
| 7 | 8 | class MessageParser; |
| … |
… |
|
| 54 | 55 | void setAffiliation(Conference* conf, const QString& jid, const QString& affiliation, const QString& reason=QString::null); |
| 55 | 56 | QString getIqError(gloox::Stanza* s); |
| 56 | | AListItem* aFind(AList* list, Nick *n, gloox::Stanza* s); |
| | 57 | AListItem* aFind(AList* list, Nick *n, gloox::Stanza* s, AListItem::MatcherType matcher=AListItem::MatcherUnknown); |
| 57 | 58 | // Advanced commands |
| 58 | 59 | bool autoLists(gloox::Stanza* s, MessageParser& parser); |
| 59 | | void checkMember(gloox::Stanza* s, Conference* c, Nick*); |
| | 60 | void checkMember(gloox::Stanza* s, Conference* c, Nick*, AListItem::MatcherType matcher=AListItem::MatcherUnknown); |
| 60 | 61 | void recheckJIDs(Conference* c); |
| 61 | 62 | void sendMessage(Conference* conf, const QString&msg); |
-
|
r271
|
r286
|
|
| 18 | 18 | myLazyLeave=false; |
| 19 | 19 | myJoined=QDateTime::currentDateTime(); |
| | 20 | versionStored_=false; |
| 20 | 21 | qDebug() << "[NICK] created: " << myNick; |
| 21 | 22 | |
| … |
… |
|
| 83 | 84 | myId=id; |
| 84 | 85 | myValidateRequired=false; |
| 85 | | |
| | 86 | versionStored_=false; |
| 86 | 87 | |
| 87 | 88 | QSqlQuery query=DataStorage::instance() |
-
|
r284
|
r286
|
|
| 25 | 25 | Jid* jid() const { return myJid; }; |
| 26 | 26 | bool validateRequired() const { return myValidateRequired; }; |
| | 27 | bool isVersionStored() const { return versionStored_; } |
| 27 | 28 | QString versionName() const { return versionName_; } |
| 28 | 29 | QString versionOs() const { return versionOs_; } |
| … |
… |
|
| 43 | 44 | static void setAllOffline (Conference* conf); |
| 44 | 45 | bool isDevoicedNoVCard() const {return devoicedNoVCard_; } |
| | 46 | bool setVersionStored(bool v) { versionStored_=v; } |
| 45 | 47 | void setDevoicedNoVCard(bool v) { devoicedNoVCard_ = v; } |
| 46 | 48 | void setVersionName(const QString& name) { versionName_=name; }; |
| … |
… |
|
| 63 | 65 | QString myStatus; |
| 64 | 66 | bool devoicedNoVCard_; |
| | 67 | bool versionStored_; |
| 65 | 68 | QString versionName_; |
| 66 | 69 | QString versionOs_; |