changeset 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 94e4ede2a357
files idavoll/pubsub.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/pubsub.py	Wed Nov 03 15:55:13 2004 +0000
+++ b/idavoll/pubsub.py	Wed Nov 03 16:15:10 2004 +0000
@@ -204,8 +204,12 @@
         if iq.pubsub.options:
             raise SubscribeOptionsUnavailable
 
-        node_id = iq.pubsub.subscribe["node"]
-        subscriber = jid.JID(iq.pubsub.subscribe["jid"])
+        try:
+            node_id = iq.pubsub.subscribe["node"]
+            subscriber = jid.JID(iq.pubsub.subscribe["jid"])
+        except KeyError:
+            raise BadRequest
+
         requestor = jid.JID(iq["from"]).userhostJID()
         d = self.backend.subscribe(node_id, subscriber, requestor)
         d.addCallback(self.return_subscription)
@@ -216,7 +220,7 @@
         entity = reply.addElement("entity")
         entity["node"] = result["node"]
         entity["jid"] = result["jid"].full()
-        entity["affiliation"] = result["affiliation"]
+        entity["affiliation"] = result["affiliation"] or 'none'
         entity["subscription"] = result["subscription"]
         return [reply]
 
@@ -226,11 +230,10 @@
     def _onUnsubscribe(self, iq):
         try:
             node_id = iq.pubsub.unsubscribe["node"]
-            jid = iq.pubsub.unsubscribe["jid"]
+            subscriber = jid.JID(iq.pubsub.unsubscribe["jid"])
         except KeyError:
             raise BadRequest
 
-        subscriber = jid.JID(jid)
         requestor = jid.JID(iq["from"]).userhostJID()
         return self.backend.unsubscribe(node_id, subscriber, requestor)