comparison sat_pubsub/pam.py @ 480:23a51b139024

pam: handle errors in onSubscribeResult
author Goffi <goffi@goffi.org>
date Mon, 30 May 2022 16:37:14 +0200
parents b544109ab4c4
children
comparison
equal deleted inserted replaced
479:cfa40fa108a4 480:23a51b139024
69 log.msg(f"ignoring PAM request from external user: {iq_elt.toXml()}") 69 log.msg(f"ignoring PAM request from external user: {iq_elt.toXml()}")
70 else: 70 else:
71 return jid.JID(iq_elt["from"]) 71 return jid.JID(iq_elt["from"])
72 72
73 def onSubscribeResult(self, iq_req_elt, iq_result_elt, pam_iq_elt): 73 def onSubscribeResult(self, iq_req_elt, iq_result_elt, pam_iq_elt):
74 destinee_jid = jid.JID(iq_req_elt["from"]) 74 subscription_elt = iq_result_elt.pubsub.subscription
75 sender_jid = jid.JID(iq_req_elt["to"]) 75 if subscription_elt is not None:
76 message_elt = domish.Element((None, "message")) 76 destinee_jid = jid.JID(iq_req_elt["from"])
77 message_elt["to"] = destinee_jid.userhost() 77 sender_jid = jid.JID(iq_req_elt["to"])
78 message_elt["from"] = destinee_jid.userhost() 78 message_elt = domish.Element((None, "message"))
79 # XXX: we explicitely store the notification to be sure that all clients get it 79 message_elt["to"] = destinee_jid.userhost()
80 message_elt.addElement(("urn:xmpp:hints", "store")) 80 message_elt["from"] = destinee_jid.userhost()
81 notify_elt = message_elt.addElement((NS_PAM, "notify")) 81 # XXX: we explicitely store the notification to be sure that all clients get it
82 notify_elt["service"] = sender_jid.full() 82 message_elt.addElement(("urn:xmpp:hints", "store"))
83 notify_elt.addChild(iq_result_elt.pubsub.subscription) 83 notify_elt = message_elt.addElement((NS_PAM, "notify"))
84 self.backend.privilege.sendMessage(message_elt) 84 notify_elt["service"] = sender_jid.full()
85 pam_iq_result_elt = xmlstream.toResponse(pam_iq_elt, 'result') 85 notify_elt.addChild(subscription_elt)
86 self.backend.privilege.sendMessage(message_elt)
87 pam_iq_result_elt = xmlstream.toResponse(pam_iq_elt, 'result')
88 else:
89 # no <subscription> element, this must be an error
90 error_elt = iq_result_elt.error
91 if error_elt is None:
92 log.msg(f"Invalid reply received: {iq_result_elt.toXml()}")
93 error_elt = jabber_error.StanzaError(
94 "service-unavailable",
95 "received invalid reply from external pubsub service"
96 ).getElement()
97 pam_iq_result_elt = xmlstream.toResponse(pam_iq_elt, 'error')
98 pam_iq_result_elt.addChild(error_elt)
99
86 self.xmlstream.send(pam_iq_result_elt) 100 self.xmlstream.send(pam_iq_result_elt)
87 101
88 async def onSubRequest(self, from_jid, iq_elt, subscribe=True): 102 async def onSubRequest(self, from_jid, iq_elt, subscribe=True):
89 try: 103 try:
90 service_jid = jid.JID(iq_elt.pam.getAttribute("jid")) 104 service_jid = jid.JID(iq_elt.pam.getAttribute("jid"))