comparison plugins/plugin_xep_0077.py @ 37:a61beb21d16d

Gateway registration, unregistration & edition - default values added in form - DBus bridge: fixed array of struct management when adding dynamically a method - fixed doc for some methods - ugly fix for presence status - added dependency for XEP-0077 in XEP-0100 plugin - Wix: added unregister button in gateways manager - Wix: added privacy warning in gateways manager
author Goffi <goffi@goffi.org>
date Tue, 15 Dec 2009 01:27:32 +1100
parents 6491b7956c80
children 2e3411a6baad
comparison
equal deleted inserted replaced
36:6491b7956c80 37:a61beb21d16d
38 "main": "XEP_0077", 38 "main": "XEP_0077",
39 "description": """Implementation of in-band registration""" 39 "description": """Implementation of in-band registration"""
40 } 40 }
41 41
42 class XEP_0077(): 42 class XEP_0077():
43 43
44 def __init__(self, host): 44 def __init__(self, host):
45 info("Plugin XEP_0077 initialization") 45 info("Plugin XEP_0077 initialization")
46 self.host = host 46 self.host = host
47 self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid
47 host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register) 48 host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register)
49 host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit)
48 50
51 def addTrigger(self, target, cb):
52 """Add a callback which is called when registration to target is successful"""
53 self.triggers[target] = cb
54
49 def reg_ok(self, answer): 55 def reg_ok(self, answer):
50 """Called after the first get IQ""" 56 """Called after the first get IQ"""
51 form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement()) 57 form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement())
52 pdb.set_trace()
53 xml_data = XMLTools.dataForm2xml(form) 58 xml_data = XMLTools.dataForm2xml(form)
54 self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}) 59 self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})
55 60
56 def reg_err(self, failure): 61 def reg_err(self, failure):
57 """Called when something is wrong with registration""" 62 """Called when something is wrong with registration"""
60 answer_data['reason'] = 'unknown' 65 answer_data['reason'] = 'unknown'
61 answer_data={"message":"%s [code: %s]" % (failure.value.condition, failure.value.code)} 66 answer_data={"message":"%s [code: %s]" % (failure.value.condition, failure.value.code)}
62 answer_type = "ERROR" 67 answer_type = "ERROR"
63 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 68 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
64 69
70 def unregistrationAnswer(self, answer):
71 debug ("registration answer: %s" % answer.toXml())
72 answer_type = "SUCCESS"
73 answer_data={"message":"Your are now unregistred"}
74 self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
75
76 def unregistrationFailure(self, failure):
77 info ("Unregistration failure: %s" % str(failure.value))
78 answer_type = "ERROR"
79 answer_data = {}
80 answer_data['reason'] = 'unknown'
81 answer_data={"message":"Unregistration failed: %s" % failure.value.condition}
82 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
83
84 def registrationAnswer(self, answer):
85 debug ("registration answer: %s" % answer.toXml())
86 answer_type = "SUCCESS"
87 answer_data={"message":"Registration successfull"}
88 self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
89 if self.triggers.has_key(answer["from"]):
90 self.triggers[answer["from"]](answer["from"])
91 del self.triggers[answer["from"]]
92
93 def registrationFailure(self, failure):
94 info ("Registration failure: %s" % str(failure.value))
95 print failure.value.stanza.toXml()
96 answer_type = "ERROR"
97 answer_data = {}
98 if failure.value.condition == 'conflict':
99 answer_data['reason'] = 'conflict'
100 answer_data={"message":"Username already exists, please choose an other one"}
101 else:
102 answer_data['reason'] = 'unknown'
103 answer_data={"message":"Registration failed"}
104 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
105 if self.triggers.has_key(answer["from"]):
106 del self.triggers[answer["from"]]
107
108 def in_band_submit(self, action, target, fields):
109 """Submit a form for registration, using data_form"""
110 id, deferred = self.host.submitForm(action, target, fields)
111 if action == 'CANCEL':
112 deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure)
113 else:
114 deferred.addCallbacks(self.registrationAnswer, self.registrationFailure)
115 return id
116
65 def in_band_register(self, target): 117 def in_band_register(self, target):
66 """register to a target JID""" 118 """register to a target JID"""
67 to_jid = jid.JID(target) 119 to_jid = jid.JID(target)
68 debug("Asking registration for [%s]" % target) 120 debug("Asking registration for [%s]" % target)
69 reg_request=IQ(self.host.xmlstream,'get') 121 reg_request=IQ(self.host.xmlstream,'get')