comparison src/plugins/plugin_xep_0060.py @ 283:68cd30d982a5

core: added plugins for PubSub et PEP (first drafts) - plugin for XEP 0060, 0163 and 0107, based on Wokkel's pubsub - XEP 0115 plugin has been fixed, so generateHash can be called when features have changed (can be usefull to filter PEP)
author Goffi <goffi@goffi.org>
date Thu, 03 Feb 2011 18:06:25 +0100
parents
children 3b382fa0ac28
comparison
equal deleted inserted replaced
282:6a0c6d8e119d 283:68cd30d982a5
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 SAT plugin for Publish-Subscribe (xep-0060)
6 Copyright (C) 2009, 2010, 2011 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22 from logging import debug, info, error
23 from twisted.internet import protocol
24 from twisted.words.protocols.jabber import client, jid
25 from twisted.words.protocols.jabber import error as jab_error
26 import twisted.internet.error
27
28 from wokkel import disco, iwokkel, pubsub
29
30 from zope.interface import implements
31
32 PLUGIN_INFO = {
33 "name": "Publish-Subscribe",
34 "import_name": "XEP_0060",
35 "type": "XEP",
36 "protocols": ["XEP-0060"],
37 "dependencies": [],
38 "main": "XEP_0060",
39 "handler": "yes",
40 "description": _("""Implementation of PubSub Protocol""")
41 }
42
43 class XEP_0060():
44
45 def __init__(self, host):
46 info(_("PubSub plugin initialization"))
47 self.host = host
48 self.managedNodes=[]
49 self.clients={}
50
51 def getHandler(self, profile):
52 self.clients[profile] = SatPubSubClient(self.host, self)
53 return self.clients[profile]
54
55 def addManagedNode(self, node_name, callback):
56 """Add a handler for a namespace
57 @param namespace: NS of the handler (will appear in disco info)
58 @param callback: method to call when the handler is found
59 @param profile: profile which manage this handler"""
60 self.managedNodes.append((node_name, callback))
61
62
63 class SatPubSubClient(pubsub.PubSubClient):
64 implements(disco.IDisco)
65
66 def __init__(self, host, parent_plugin):
67 self.host=host
68 self.parent_plugin = parent_plugin
69 pubsub.PubSubClient.__init__(self)
70
71 def connectionInitialized(self):
72 pubsub.PubSubClient.connectionInitialized(self)
73
74 def itemsReceived(self, event):
75 for node in self.parent_plugin.managedNodes:
76 if event.nodeIdentifier == node[0]:
77 return node[1](event, self.parent.profile)
78
79 def deleteReceived(self, event):
80 import pdb
81 pdb.set_trace()
82
83 def purgeReceived(self, event):
84 import pdb
85 pdb.set_trace()
86
87 def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
88 _disco_info = []
89 self.host.trigger.point("PubSub Disco Info", _disco_info, self.parent.profile)
90 return _disco_info
91
92 def getDiscoItems(self, requestor, target, nodeIdentifier=''):
93 return []
94