Mercurial > libervia-backend
comparison sat/plugins/plugin_sec_otr.py @ 3795:967a8e109cda
core (xmpp): adapt message workflow to components:
message workflow were not used for components so far. This patch activate it, normalise
namespace to the client one to simplify parsing, and use SatXMPPComponent.sendHistory and
SatXMPPComponent.receiveHistory to indicate if a component should store sent and received
message in database (they both default to False).
OTR plugin is deactivated for components.
rel 367
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jun 2022 14:15:23 +0200 |
parents | be6d91572633 |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
3794:a58715ffa445 | 3795:967a8e109cda |
---|---|
40 | 40 |
41 | 41 |
42 PLUGIN_INFO = { | 42 PLUGIN_INFO = { |
43 C.PI_NAME: "OTR", | 43 C.PI_NAME: "OTR", |
44 C.PI_IMPORT_NAME: "OTR", | 44 C.PI_IMPORT_NAME: "OTR", |
45 C.PI_MODES: [C.PLUG_MODE_CLIENT], | |
45 C.PI_TYPE: "SEC", | 46 C.PI_TYPE: "SEC", |
46 C.PI_PROTOCOLS: ["XEP-0364"], | 47 C.PI_PROTOCOLS: ["XEP-0364"], |
47 C.PI_DEPENDENCIES: ["XEP-0280", "XEP-0334"], | 48 C.PI_DEPENDENCIES: ["XEP-0280", "XEP-0334"], |
48 C.PI_MAIN: "OTR", | 49 C.PI_MAIN: "OTR", |
49 C.PI_HANDLER: "no", | 50 C.PI_HANDLER: "no", |
729 # Hard to avoid with decryption on Libervia though. | 730 # Hard to avoid with decryption on Libervia though. |
730 data["history"] = C.HISTORY_SKIP | 731 data["history"] = C.HISTORY_SKIP |
731 return data | 732 return data |
732 | 733 |
733 def messageReceivedTrigger(self, client, message_elt, post_treat): | 734 def messageReceivedTrigger(self, client, message_elt, post_treat): |
735 if client.is_component: | |
736 return True | |
734 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: | 737 if message_elt.getAttribute("type") == C.MESS_TYPE_GROUPCHAT: |
735 # OTR is not possible in group chats | 738 # OTR is not possible in group chats |
736 return True | 739 return True |
737 from_jid = jid.JID(message_elt['from']) | 740 from_jid = jid.JID(message_elt['from']) |
738 if not from_jid.resource or from_jid.userhostJID() == client.jid.userhostJID(): | 741 if not from_jid.resource or from_jid.userhostJID() == client.jid.userhostJID(): |
743 else: | 746 else: |
744 post_treat.addCallback(self._receivedTreatment, client) | 747 post_treat.addCallback(self._receivedTreatment, client) |
745 return True | 748 return True |
746 | 749 |
747 def _sendMessageDataTrigger(self, client, mess_data): | 750 def _sendMessageDataTrigger(self, client, mess_data): |
751 if client.is_component: | |
752 return True | |
748 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION) | 753 encryption = mess_data.get(C.MESS_KEY_ENCRYPTION) |
749 if encryption is None or encryption['plugin'].namespace != NS_OTR: | 754 if encryption is None or encryption['plugin'].namespace != NS_OTR: |
750 return | 755 return |
751 to_jid = mess_data['to'] | 756 to_jid = mess_data['to'] |
752 if not to_jid.resource: | 757 if not to_jid.resource: |
786 client.feedback(to_jid, feedback) | 791 client.feedback(to_jid, feedback) |
787 raise failure.Failure(exceptions.CancelError("Cancelled by OTR plugin")) | 792 raise failure.Failure(exceptions.CancelError("Cancelled by OTR plugin")) |
788 | 793 |
789 def sendMessageTrigger(self, client, mess_data, pre_xml_treatments, | 794 def sendMessageTrigger(self, client, mess_data, pre_xml_treatments, |
790 post_xml_treatments): | 795 post_xml_treatments): |
796 if client.is_component: | |
797 return True | |
791 if mess_data["type"] == "groupchat": | 798 if mess_data["type"] == "groupchat": |
792 return True | 799 return True |
793 | 800 |
794 if client.profile in self.skipped_profiles: | 801 if client.profile in self.skipped_profiles: |
795 # FIXME: should not be done on a per-profile basis | 802 # FIXME: should not be done on a per-profile basis |