comparison idavoll/pubsub.py @ 48:671ead538758

Check for malformed subscription request. Fix conversion of affiliation field when returning current subscription.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 03 Nov 2004 16:15:10 +0000
parents 31eb00734cc5
children 55fa890ef60b
comparison
equal deleted inserted replaced
47:31eb00734cc5 48:671ead538758
202 202
203 def _onSubscribe(self, iq): 203 def _onSubscribe(self, iq):
204 if iq.pubsub.options: 204 if iq.pubsub.options:
205 raise SubscribeOptionsUnavailable 205 raise SubscribeOptionsUnavailable
206 206
207 node_id = iq.pubsub.subscribe["node"] 207 try:
208 subscriber = jid.JID(iq.pubsub.subscribe["jid"]) 208 node_id = iq.pubsub.subscribe["node"]
209 subscriber = jid.JID(iq.pubsub.subscribe["jid"])
210 except KeyError:
211 raise BadRequest
212
209 requestor = jid.JID(iq["from"]).userhostJID() 213 requestor = jid.JID(iq["from"]).userhostJID()
210 d = self.backend.subscribe(node_id, subscriber, requestor) 214 d = self.backend.subscribe(node_id, subscriber, requestor)
211 d.addCallback(self.return_subscription) 215 d.addCallback(self.return_subscription)
212 return d 216 return d
213 217
214 def return_subscription(self, result): 218 def return_subscription(self, result):
215 reply = domish.Element((NS_PUBSUB, "pubsub"), NS_PUBSUB) 219 reply = domish.Element((NS_PUBSUB, "pubsub"), NS_PUBSUB)
216 entity = reply.addElement("entity") 220 entity = reply.addElement("entity")
217 entity["node"] = result["node"] 221 entity["node"] = result["node"]
218 entity["jid"] = result["jid"].full() 222 entity["jid"] = result["jid"].full()
219 entity["affiliation"] = result["affiliation"] 223 entity["affiliation"] = result["affiliation"] or 'none'
220 entity["subscription"] = result["subscription"] 224 entity["subscription"] = result["subscription"]
221 return [reply] 225 return [reply]
222 226
223 def onUnsubscribe(self, iq): 227 def onUnsubscribe(self, iq):
224 self.handler_wrapper(self._onUnsubscribe, iq) 228 self.handler_wrapper(self._onUnsubscribe, iq)
225 229
226 def _onUnsubscribe(self, iq): 230 def _onUnsubscribe(self, iq):
227 try: 231 try:
228 node_id = iq.pubsub.unsubscribe["node"] 232 node_id = iq.pubsub.unsubscribe["node"]
229 jid = iq.pubsub.unsubscribe["jid"] 233 subscriber = jid.JID(iq.pubsub.unsubscribe["jid"])
230 except KeyError: 234 except KeyError:
231 raise BadRequest 235 raise BadRequest
232 236
233 subscriber = jid.JID(jid)
234 requestor = jid.JID(iq["from"]).userhostJID() 237 requestor = jid.JID(iq["from"]).userhostJID()
235 return self.backend.unsubscribe(node_id, subscriber, requestor) 238 return self.backend.unsubscribe(node_id, subscriber, requestor)
236 239
237 def onOptionsGet(self, iq): 240 def onOptionsGet(self, iq):
238 self.handler_wrapper(self._onOptionsGet, iq) 241 self.handler_wrapper(self._onOptionsGet, iq)