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
This commit is contained in:
parent
914f7da809
commit
e3a3c1e975
2 changed files with 159 additions and 39 deletions
|
|
@ -40,16 +40,21 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
class XEP_0077():
|
||||
|
||||
|
||||
def __init__(self, host):
|
||||
info("Plugin XEP_0077 initialization")
|
||||
self.host = host
|
||||
self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid
|
||||
host.bridge.addMethod("in_band_register", ".communication", in_sign='s', out_sign='s', method=self.in_band_register)
|
||||
host.bridge.addMethod("in_band_submit", ".request", in_sign='sa(ss)', out_sign='s', method=self.in_band_submit)
|
||||
|
||||
def addTrigger(self, target, cb):
|
||||
"""Add a callback which is called when registration to target is successful"""
|
||||
self.triggers[target] = cb
|
||||
|
||||
def reg_ok(self, answer):
|
||||
"""Called after the first get IQ"""
|
||||
form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement())
|
||||
pdb.set_trace()
|
||||
xml_data = XMLTools.dataForm2xml(form)
|
||||
self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})
|
||||
|
||||
|
|
@ -62,6 +67,53 @@ class XEP_0077():
|
|||
answer_type = "ERROR"
|
||||
self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
|
||||
|
||||
def unregistrationAnswer(self, answer):
|
||||
debug ("registration answer: %s" % answer.toXml())
|
||||
answer_type = "SUCCESS"
|
||||
answer_data={"message":"Your are now unregistred"}
|
||||
self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
|
||||
|
||||
def unregistrationFailure(self, failure):
|
||||
info ("Unregistration failure: %s" % str(failure.value))
|
||||
answer_type = "ERROR"
|
||||
answer_data = {}
|
||||
answer_data['reason'] = 'unknown'
|
||||
answer_data={"message":"Unregistration failed: %s" % failure.value.condition}
|
||||
self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
|
||||
|
||||
def registrationAnswer(self, answer):
|
||||
debug ("registration answer: %s" % answer.toXml())
|
||||
answer_type = "SUCCESS"
|
||||
answer_data={"message":"Registration successfull"}
|
||||
self.host.bridge.actionResult(answer_type, answer['id'], answer_data)
|
||||
if self.triggers.has_key(answer["from"]):
|
||||
self.triggers[answer["from"]](answer["from"])
|
||||
del self.triggers[answer["from"]]
|
||||
|
||||
def registrationFailure(self, failure):
|
||||
info ("Registration failure: %s" % str(failure.value))
|
||||
print failure.value.stanza.toXml()
|
||||
answer_type = "ERROR"
|
||||
answer_data = {}
|
||||
if failure.value.condition == 'conflict':
|
||||
answer_data['reason'] = 'conflict'
|
||||
answer_data={"message":"Username already exists, please choose an other one"}
|
||||
else:
|
||||
answer_data['reason'] = 'unknown'
|
||||
answer_data={"message":"Registration failed"}
|
||||
self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data)
|
||||
if self.triggers.has_key(answer["from"]):
|
||||
del self.triggers[answer["from"]]
|
||||
|
||||
def in_band_submit(self, action, target, fields):
|
||||
"""Submit a form for registration, using data_form"""
|
||||
id, deferred = self.host.submitForm(action, target, fields)
|
||||
if action == 'CANCEL':
|
||||
deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure)
|
||||
else:
|
||||
deferred.addCallbacks(self.registrationAnswer, self.registrationFailure)
|
||||
return id
|
||||
|
||||
def in_band_register(self, target):
|
||||
"""register to a target JID"""
|
||||
to_jid = jid.JID(target)
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ PLUGIN_INFO = {
|
|||
"name": "Gateways Plugin",
|
||||
"import_name": "XEP_0100",
|
||||
"type": "XEP",
|
||||
"dependencies": [],
|
||||
"dependencies": ["XEP_0077"],
|
||||
"main": "XEP_0100",
|
||||
"description": """Implementation of Gateways protocol"""
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ class XEP_0100():
|
|||
self.host = host
|
||||
self.__gateways = {} #dict used to construct the answer to findGateways. Key = target jid
|
||||
host.bridge.addMethod("findGateways", ".communication", in_sign='s', out_sign='s', method=self.findGateways)
|
||||
host.bridge.addMethod("gatewayRegister", ".request", in_sign='ssa(ss)', out_sign='s', method=self.gatewayRegister)
|
||||
|
||||
def discoInfo(self, disco, entity, request_id):
|
||||
"""Find disco infos about entity, to check if it is a gateway"""
|
||||
|
|
@ -76,6 +77,18 @@ class XEP_0100():
|
|||
debug ("item found: %s", item.name)
|
||||
self.host.disco.requestInfo(item.entity).addCallback(self.discoInfo, entity=item.entity, request_id=request_id)
|
||||
|
||||
def registrationSuccessful(self, target):
|
||||
"""Called when in_band registration is ok, we must now follow the rest of procedure"""
|
||||
print "Registration successful, doing the rest"
|
||||
self.host.addContact(target)
|
||||
self.host.setPresence(target)
|
||||
|
||||
def gatewayRegister(self, action, target, fields):
|
||||
"""Register gateway using in-band registration, then log-in to gateway"""
|
||||
if action == 'SUBMIT':
|
||||
self.host.plugins["XEP_0077"].addTrigger(target, self.registrationSuccessful)
|
||||
return self.host.plugins["XEP_0077"].in_band_submit(action, target, fields)
|
||||
|
||||
def findGateways(self, target):
|
||||
"""Find gateways in the target JID, using discovery protocol
|
||||
Return an id used for retrieving the list of gateways
|
||||
|
|
|
|||
Loading…
Reference in a new issue