comparison src/plugins/plugin_xep_0077.py @ 538:2c4016921403

core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles - added profile argument to askConfirmation, actionResult, actionResultExt, entityDataUpdated, confirmationAnswer, getProgress - core, frontends: fixed calls/signals according to new bridge API - user of proper profile namespace for progression indicators and dialogs - memory: getParam* now return bool when param type is bool - memory: added getStringParam* to return string instead of typed value - core, memory, storage, quick_frontend: getHistory now manage properly multi-profiles - plugins XEP-0047, XEP-0054, XEP-0065, XEP-0077, XEP-0096; multi-profiles proper handling
author Goffi <goffi@goffi.org>
date Sat, 10 Nov 2012 16:38:16 +0100
parents 2a072735e459
children caad23285a38
comparison
equal deleted inserted replaced
537:28cddc96c4ed 538:2c4016921403
52 52
53 def addTrigger(self, target, cb, profile): 53 def addTrigger(self, target, cb, profile):
54 """Add a callback which is called when registration to target is successful""" 54 """Add a callback which is called when registration to target is successful"""
55 self.triggers[target] = (cb, profile) 55 self.triggers[target] = (cb, profile)
56 56
57 def reg_ok(self, answer): 57 def reg_ok(self, answer, profile):
58 """Called after the first get IQ""" 58 """Called after the first get IQ"""
59 try: 59 try:
60 x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form) 60 x_elem = filter (lambda x:x.name == "x", answer.firstChildElement().elements())[0] #We only want the "x" element (data form)
61 except IndexError: 61 except IndexError:
62 info(_("No data form found")) 62 info(_("No data form found"))
63 #TODO: manage registration without data form 63 #TODO: manage registration without data form
64 answer_data={"reason": "unmanaged", "message":_("This gateway can't be managed by SàT, sorry :(")} 64 answer_data={"reason": "unmanaged", "message":_("This gateway can't be managed by SàT, sorry :(")}
65 answer_type = "ERROR" 65 answer_type = "ERROR"
66 self.host.bridge.actionResult(answer_type, answer['id'], answer_data) 66 self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
67 return 67 return
68 68
69 form = data_form.Form.fromElement(x_elem) 69 form = data_form.Form.fromElement(x_elem)
70 xml_data = dataForm2xml(form) 70 xml_data = dataForm2xml(form)
71 self.host.bridge.actionResult("XMLUI", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}) 71 self.host.bridge.actionResult("XMLUI", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}, profile)
72 72
73 def reg_err(self, failure): 73 def reg_err(self, failure, profile):
74 """Called when something is wrong with registration""" 74 """Called when something is wrong with registration"""
75 info (_("Registration failure: %s") % str(failure.value)) 75 info (_("Registration failure: %s") % str(failure.value))
76 answer_data = {} 76 answer_data = {}
77 answer_data['reason'] = 'unknown' 77 answer_data['reason'] = 'unknown'
78 answer_data={"message":"%s [code: %s]" % (failure.value.condition, unicode(failure.value))} 78 answer_data={"message":"%s [code: %s]" % (failure.value.condition, unicode(failure.value))}
79 answer_type = "ERROR" 79 answer_type = "ERROR"
80 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 80 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
81 81
82 def unregistrationAnswer(self, answer): 82 def unregistrationAnswer(self, answer, profile):
83 debug (_("registration answer: %s") % answer.toXml()) 83 debug (_("registration answer: %s") % answer.toXml())
84 answer_type = "SUCCESS" 84 answer_type = "SUCCESS"
85 answer_data={"message":_("Your are now unregistred")} 85 answer_data={"message":_("Your are now unregistred")}
86 self.host.bridge.actionResult(answer_type, answer['id'], answer_data) 86 self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
87 87
88 def unregistrationFailure(self, failure): 88 def unregistrationFailure(self, failure, profile):
89 info (_("Unregistration failure: %s") % str(failure.value)) 89 info (_("Unregistration failure: %s") % str(failure.value))
90 answer_type = "ERROR" 90 answer_type = "ERROR"
91 answer_data = {} 91 answer_data = {}
92 answer_data['reason'] = 'unknown' 92 answer_data['reason'] = 'unknown'
93 answer_data={"message":_("Unregistration failed: %s") % failure.value.condition} 93 answer_data={"message":_("Unregistration failed: %s") % failure.value.condition}
94 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 94 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
95 95
96 def registrationAnswer(self, answer): 96 def registrationAnswer(self, answer, profile):
97 debug (_("registration answer: %s") % answer.toXml()) 97 debug (_("registration answer: %s") % answer.toXml())
98 answer_type = "SUCCESS" 98 answer_type = "SUCCESS"
99 answer_data={"message":_("Registration successfull")} 99 answer_data={"message":_("Registration successfull")}
100 self.host.bridge.actionResult(answer_type, answer['id'], answer_data) 100 self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
101 if self.triggers.has_key(answer["from"]): 101 if self.triggers.has_key(answer["from"]):
102 callback,profile = self.triggers[answer["from"]] 102 callback,profile = self.triggers[answer["from"]]
103 callback(answer["from"], profile) 103 callback(answer["from"], profile)
104 del self.triggers[answer["from"]] 104 del self.triggers[answer["from"]]
105 105
106 def registrationFailure(self, failure): 106 def registrationFailure(self, failure, profile):
107 info (_("Registration failure: %s") % str(failure.value)) 107 info (_("Registration failure: %s") % str(failure.value))
108 print failure.value.stanza.toXml() 108 print failure.value.stanza.toXml()
109 answer_type = "ERROR" 109 answer_type = "ERROR"
110 answer_data = {} 110 answer_data = {}
111 if failure.value.condition == 'conflict': 111 if failure.value.condition == 'conflict':
112 answer_data['reason'] = 'conflict' 112 answer_data['reason'] = 'conflict'
113 answer_data={"message":_("Username already exists, please choose an other one")} 113 answer_data={"message":_("Username already exists, please choose an other one")}
114 else: 114 else:
115 answer_data['reason'] = 'unknown' 115 answer_data['reason'] = 'unknown'
116 answer_data={"message":_("Registration failed")} 116 answer_data={"message":_("Registration failed")}
117 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data) 117 self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
118 if self.triggers.has_key(answer["from"]): 118 if self.triggers.has_key(answer["from"]):
119 del self.triggers[answer["from"]] 119 del self.triggers[answer["from"]]
120 120
121 def in_band_submit(self, action, target, fields, profile): 121 def in_band_submit(self, action, target, fields, profile):
122 """Submit a form for registration, using data_form""" 122 """Submit a form for registration, using data_form"""
123 id, deferred = self.host.submitForm(action, target, fields, profile) 123 id, deferred = self.host.submitForm(action, target, fields, profile)
124 if action == 'CANCEL': 124 if action == 'CANCEL':
125 deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure) 125 deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure, callbackArgs=[profile], errbackArgs=[profile])
126 else: 126 else:
127 deferred.addCallbacks(self.registrationAnswer, self.registrationFailure) 127 deferred.addCallbacks(self.registrationAnswer, self.registrationFailure, callbackArgs=[profile], errbackArgs=[profile])
128 return id 128 return id
129 129
130 def in_band_register(self, target, profile_key='@DEFAULT@'): 130 def in_band_register(self, target, profile_key='@DEFAULT@'):
131 """register to a target JID""" 131 """register to a target JID"""
132 current_jid, xmlstream = self.host.getJidNStream(profile_key) 132 client = self.host.getClient(profile_key)
133 if not xmlstream: 133 if not client:
134 error (_('Asking for an non-existant or not connected profile')) 134 error (_('Asking for an non-existant or not connected profile'))
135 return "" 135 return ""
136 to_jid = jid.JID(target) 136 to_jid = jid.JID(target)
137 debug(_("Asking registration for [%s]") % to_jid.full()) 137 debug(_("Asking registration for [%s]") % to_jid.full())
138 reg_request=IQ(xmlstream,'get') 138 reg_request=IQ(client.xmlstream,'get')
139 reg_request["from"]=current_jid.full() 139 reg_request["from"]=client.jid.full()
140 reg_request["to"] = to_jid.full() 140 reg_request["to"] = to_jid.full()
141 query=reg_request.addElement('query', NS_REG) 141 query=reg_request.addElement('query', NS_REG)
142 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err) 142 reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err, callbackArgs=[profile], errbackArgs=[profile])
143 return reg_request["id"] 143 return reg_request["id"]