comparison plugins/plugin_xep_0077.py @ 30:d6b613764dd7

new plugin for xep 0077 (In-Band registration): first draft - wix: register in gateways manager now call the in-band registration process
author Goffi <goffi@goffi.org>
date Tue, 08 Dec 2009 04:19:41 +0100
parents
children b9bb5d8e0cc7
comparison
equal deleted inserted replaced
29:df3b0b5ac49e 30:d6b613764dd7
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 SAT plugin for managing xep-0077
6 Copyright (C) 2009 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.words.protocols.jabber import client, jid, xmlstream, error
24 from twisted.words.protocols.jabber.xmlstream import IQ
25 from twisted.internet import reactor
26 import pdb
27
28 NS_REG = 'jabber:iq:register'
29
30 PLUGIN_INFO = {
31 "name": "XEP 0077 Plugin",
32 "import_name": "XEP_0077",
33 "type": "XEP",
34 "dependencies": [],
35 "main": "XEP_0077",
36 "description": """Implementation of SI File Transfert"""
37 }
38
39 class XEP_0077():
40
41 def __init__(self, host):
42 info("Plugin XEP_0077 initialization")
43 self.host = host
44 host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register)
45
46 def reg_ok(self, answer):
47 """Called after the first get IQ"""
48 print "answer:",answer
49
50 def reg_err(self, failure):
51 """Called when something is wrong with registration"""
52 info ("Registration failure: %s" % str(failure.value))
53 answer_data = {}
54 answer_data['reason'] = 'unknown'
55 answer_data={"message":"%s [code: %s]" % (failure.value.condition, failure.value.code)}
56 answer_type = "ERROR"
57 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
58
59 def in_band_register(self, target):
60 """register to a target JID"""
61 to_jid = jid.JID(target)
62 debug("Asking registration for [%s]" % target)
63 reg_request=IQ(self.host.xmlstream,'get')
64 reg_request["from"]=self.host.me.full()
65 reg_request["to"] = to_jid.full()
66 query=reg_request.addElement('query', NS_REG)
67 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err)
68 return reg_request["id"]