Returns false to skip, true to process
(filter *PluginFilter, msg *ClientComMessage)
| 631 | |
| 632 | // Returns false to skip, true to process |
| 633 | func pluginDoFiltering(filter *PluginFilter, msg *ClientComMessage) bool { |
| 634 | filterByTopic := func(topic string, flt int) bool { |
| 635 | if topic == "" || flt == plgTopicCatMask { |
| 636 | return true |
| 637 | } |
| 638 | |
| 639 | tt := topic |
| 640 | if len(tt) > 3 { |
| 641 | tt = topic[:3] |
| 642 | } |
| 643 | switch tt { |
| 644 | case "me": |
| 645 | return flt&plgTopicMe != 0 |
| 646 | case "fnd": |
| 647 | return flt&plgTopicFnd != 0 |
| 648 | case "usr": |
| 649 | return flt&plgTopicP2P != 0 |
| 650 | case "grp": |
| 651 | return flt&plgTopicGrp != 0 |
| 652 | case "sys": |
| 653 | return flt&plgTopicSys != 0 |
| 654 | case "slf": |
| 655 | return flt&plgTopicSlf != 0 |
| 656 | case "new": |
| 657 | return flt&plgTopicNew != 0 |
| 658 | case "nch": |
| 659 | return flt&plgTopicNch != 0 |
| 660 | } |
| 661 | return false |
| 662 | } |
| 663 | |
| 664 | // Check if plugin has any filters for this call |
| 665 | if filter == nil || filter.byPacket == 0 { |
| 666 | return false |
| 667 | } |
| 668 | // Check if plugin wants all the messages |
| 669 | if filter.byPacket == plgClientMask && filter.byTopicType == plgTopicCatMask { |
| 670 | return true |
| 671 | } |
| 672 | // Check individual bits |
| 673 | if msg.Hi != nil { |
| 674 | return filter.byPacket&plgHi != 0 |
| 675 | } |
| 676 | if msg.Acc != nil { |
| 677 | return filter.byPacket&plgAcc != 0 |
| 678 | } |
| 679 | if msg.Login != nil { |
| 680 | return filter.byPacket&plgLogin != 0 |
| 681 | } |
| 682 | if msg.Sub != nil { |
| 683 | return filter.byPacket&plgSub != 0 && filterByTopic(msg.Sub.Topic, filter.byTopicType) |
| 684 | } |
| 685 | if msg.Leave != nil { |
| 686 | return filter.byPacket&plgLeave != 0 && filterByTopic(msg.Leave.Topic, filter.byTopicType) |
| 687 | } |
| 688 | if msg.Pub != nil { |
| 689 | return filter.byPacket&plgPub != 0 && filterByTopic(msg.Pub.Topic, filter.byTopicType) |
| 690 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…