diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2010-11-16 00:31:43 -0500 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2010-11-16 00:31:43 -0500 |
| commit | d4d8353b27bd499da8c1790f786a263bbf33600b (patch) | |
| tree | aa7d4547e34f6a0f3dcdba2c069151b9f9e550ad | |
| parent | 50ffed97de46dd5d3367703bd5e14c36ee3fb583 (diff) | |
| parent | 59f44cc48166589846401d609c0cac3f454b8e5f (diff) | |
| download | alias-d4d8353b27bd499da8c1790f786a263bbf33600b.tar.gz | |
Merge branch 'master' of alias.fr.nf:alias
| -rw-r--r-- | plugin.py | 32 | ||||
| -rw-r--r-- | server.py | 4 |
2 files changed, 35 insertions, 1 deletions
diff --git a/plugin.py b/plugin.py new file mode 100644 index 0000000..a88d244 --- /dev/null +++ b/plugin.py @@ -0,0 +1,32 @@ +from sleekxmpp.xmlstream.stanzabase import ElementBase, registerStanzaPlugin +from sleekxmpp.plugins import base +from sleekxmpp.xmlstream.handler.callback import Callback +from sleekxmpp.xmlstream.matcher.xpath import MatchXPath +from sleekxmpp.stanza.iq import Iq +import logging + +class AliasQuery(ElementBase) : + namespace = 'alias:query' + name = 'query' + plugin_attrib = 'query' + interfaces = set(('node', 'type', 'items','object')) + sub_interfaces = set(('items')) + + +class AliasPlugin(base.base_plugin) : + + def plugin_init(self) : + self.description = 'Plugin to handle alias queries' + registerStanzaPlugin(Iq, AliasQuery) + + self.xmpp.registerHandler( + Callback('Alias queries', + MatchXPath('{%s}iq/{%s}query' % (self.xmpp.default_ns, + AliasQuery.namespace)), + self.handle_alias_query)) + + def handle_alias_query(self, iq) : + iq.reply().send() + + + @@ -8,6 +8,7 @@ class ObjectComponent(ComponentXMPP): def __init__(self, jid, secret, server, port, root): ComponentXMPP.__init__(self, jid, secret, server, port) + self.register_plugin("AliasPlugin", module = "plugin" ) self.add_event_handler("session_start", self.start) self.add_event_handler("presence_probe", self.presenceProbe) self.add_event_handler("message", self.message) @@ -22,6 +23,7 @@ class ObjectComponent(ComponentXMPP): for user in self.userHandler.getUserList() : self.sendPresence(pto = user, ptype = "unavailable") XMLStream.disconnect(self, reconnect) + logging.info('Component %s disconnected' % self.boundjid.bare) def message(self, msg): msg.reply("Thanks for sending\n%(body)s" % msg).send() @@ -64,7 +66,7 @@ if __name__ == '__main__' : component = ObjectComponent(args.name, args.secret, args.host, args.port, args.root) if component.connect() : - print 'Component', args.name, 'connected to', args.host + ':' + str(args.port) + logging.info('Component %s connected' % args.name ) component.process(False) else : print "Couldn't connect" |
