comparison sat/plugins/plugin_xep_0280.py @ 2816:114cdde9ff96

plugin XEP-0280: priority and "sent" fixes: - carbon prioriy must be bigger than ones of encryption plugins, because the carbon copied messages must be unwrapped to be decrypted, this patch fixes it - "sent" carbon elements was only stored and notified to frontends, it is now unwrapped and injected in normal traffic, this way other plugin can manage it, in particular encrypted elements can be decrypted
author Goffi <goffi@goffi.org>
date Thu, 28 Feb 2019 18:57:06 +0100
parents 003b8b4b56a7
children ab2696e34d29
comparison
equal deleted inserted replaced
2815:27d9d25ec3cd 2816:114cdde9ff96
73 73
74 def __init__(self, host): 74 def __init__(self, host):
75 log.info(_("Plugin XEP_0280 initialization")) 75 log.info(_("Plugin XEP_0280 initialization"))
76 self.host = host 76 self.host = host
77 host.memory.updateParams(self.params) 77 host.memory.updateParams(self.params)
78 host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=1000) 78 host.trigger.add("MessageReceived", self.messageReceivedTrigger, priority=200000)
79 79
80 def getHandler(self, client): 80 def getHandler(self, client):
81 return XEP_0280_handler() 81 return XEP_0280_handler()
82 82
83 def setPrivate(self, message_elt): 83 def setPrivate(self, message_elt):
136 ) 136 )
137 ) 137 )
138 return 138 return
139 forwarded_elt = next(carbons_elt.elements(C.NS_FORWARD, "forwarded")) 139 forwarded_elt = next(carbons_elt.elements(C.NS_FORWARD, "forwarded"))
140 cc_message_elt = next(forwarded_elt.elements(C.NS_CLIENT, "message")) 140 cc_message_elt = next(forwarded_elt.elements(C.NS_CLIENT, "message"))
141
142 # we replace the wrapping message with the CCed one
143 # and continue the normal behaviour
141 if carbons_elt.name == "received": 144 if carbons_elt.name == "received":
142 # on receive we replace the wrapping message with the CCed one
143 # and continue the normal behaviour
144 message_elt["from"] = cc_message_elt["from"] 145 message_elt["from"] = cc_message_elt["from"]
145 del message_elt.children[:]
146 for c in cc_message_elt.children:
147 message_elt.addChild(c)
148 return True
149 elif carbons_elt.name == "sent": 146 elif carbons_elt.name == "sent":
150 # on sent we parse the message and just add it to history 147 message_elt["to"] = cc_message_elt["to"]
151 # and send it to frontends (without normal sending treatments)
152 mess_data = client.messageProt.parseMessage(cc_message_elt)
153 if not mess_data["message"] and not mess_data["subject"]:
154 return False
155 client.messageAddToHistory(mess_data)
156 client.messageSendToBridge(mess_data)
157 else: 148 else:
158 log.warning( 149 log.warning(
159 u"invalid message carbons received:\n{xml}".format( 150 u"invalid message carbons received:\n{xml}".format(
160 xml=message_elt.toXml() 151 xml=message_elt.toXml()
161 ) 152 )
162 ) 153 )
163 return False 154 return False
164 155
156 del message_elt.children[:]
157 for c in cc_message_elt.children:
158 message_elt.addChild(c)
159
160 return True
165 161
166 class XEP_0280_handler(XMPPHandler): 162 class XEP_0280_handler(XMPPHandler):
167 implements(iwokkel.IDisco) 163 implements(iwokkel.IDisco)
168 164
169 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): 165 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):