summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Wieland Hoffmann <themineo@gmail.com> 2012-01-05 20:31:06 +0100
committerGravatar Wieland Hoffmann <themineo@gmail.com> 2012-01-05 20:31:06 +0100
commit2fc8bdf0f306297995afbbd757211ab8629092c2 (patch)
tree7fc31ecdb99a50e28b80e8ef16008ffe834ab608
parentfix post urlencode regression (diff)
downloadpyload-2fc8bdf0f306297995afbbd757211ab8629092c2.tar.xz
XMPPInterface: handle subscribe requests
Owners get a subscription, other people don't This could probably be extended to unsubscribe people deleted from the owner list
-rw-r--r--module/plugins/hooks/XMPPInterface.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/module/plugins/hooks/XMPPInterface.py b/module/plugins/hooks/XMPPInterface.py
index a96adf524..fad98beb7 100644
--- a/module/plugins/hooks/XMPPInterface.py
+++ b/module/plugins/hooks/XMPPInterface.py
@@ -19,7 +19,7 @@
"""
from pyxmpp import streamtls
-from pyxmpp.all import JID, Message
+from pyxmpp.all import JID, Message, Presence
from pyxmpp.jabber.client import JabberClient
from pyxmpp.interface import implements
from pyxmpp.interfaces import *
@@ -121,7 +121,26 @@ class XMPPInterface(IRCInterface, JabberClient):
in a client session."""
return [
("normal", self.message),
- ]
+ ]
+
+ def presence_control(self, stanza):
+ from_jid = unicode(stanza.get_from_jid())
+ stanza_type = stanza.get_type()
+ self.log.debug("pyLoad XMPP: %s stanza from %s" % (stanza_type,
+ from_jid))
+
+ if from_jid in self.getConfig("owners"):
+ return stanza.make_accept_response()
+
+ return stanza.make_deny_response()
+
+ def session_started(self):
+ self.stream.send(Presence())
+
+ self.stream.set_presence_handler("subscribe", self.presence_control)
+ self.stream.set_presence_handler("subscribed", self.presence_control)
+ self.stream.set_presence_handler("unsubscribe", self.presence_control)
+ self.stream.set_presence_handler("unsubscribed", self.presence_control)
def message(self, stanza):
"""Message handler for the component."""
@@ -248,4 +267,4 @@ class VersionHandler(object):
q.newTextChild(q.ns(), "name", "Echo component")
q.newTextChild(q.ns(), "version", "1.0")
return iq
- \ No newline at end of file
+