Commit 7439dc9a authored by Philipp Hörist's avatar Philipp Hörist

Register: Remove unused methods

parent 9d0ffffc
Pipeline #7292 canceled with stages
in 5 minutes and 15 seconds
......@@ -14,14 +14,10 @@
# XEP-0077: In-Band Registration
import weakref
import nbxmpp
from nbxmpp.namespaces import Namespace
from gajim.common import app
from gajim.common.modules.base import BaseModule
from gajim.common.modules.bits_of_binary import parse_bob_data
class Register(BaseModule):
......@@ -38,96 +34,11 @@ class Register(BaseModule):
def __init__(self, con):
BaseModule.__init__(self, con)
self.agent_registrations = {}
self.supported = False
def pass_disco(self, info):
self.supported = Namespace.REGISTER in info.features
def register_agent(self, agent, form, is_form, success_cb, error_cb):
if not app.account_is_available(self._account):
return
weak_success_cb = weakref.WeakMethod(success_cb)
weak_error_cb = weakref.WeakMethod(error_cb)
iq = nbxmpp.Iq('set', Namespace.REGISTER, to=agent)
if is_form:
query = iq.setQuery()
form.setAttr('type', 'submit')
query.addChild(node=form)
else:
for field in form.keys():
iq.setTag('query').setTagData(field, form[field])
self._con.connection.SendAndCallForResponse(
iq, self._register_agent_response, {'agent': agent,
'success_cb': weak_success_cb,
'error_cb': weak_error_cb})
def _register_agent_response(self, _nbxmpp_client, stanza, agent,
success_cb, error_cb):
if not nbxmpp.isResultNode(stanza):
error = stanza.getErrorMsg()
self._log.info('Error: %s', error)
if error_cb() is not None:
form = is_form = None
if stanza.getErrorType() == 'modify':
form, is_form = self._get_register_form(stanza)
error_cb()(error, form, is_form)
return
self._con.get_module('Presence').subscribe(agent, auto_auth=True)
if success_cb() is not None:
success_cb()()
def get_register_form(self, jid, success_cb, error_cb):
if not app.account_is_available(self._account):
return
weak_success_cb = weakref.WeakMethod(success_cb)
weak_error_cb = weakref.WeakMethod(error_cb)
iq = nbxmpp.Iq('get', Namespace.REGISTER, to=jid)
self._con.connection.SendAndCallForResponse(
iq, self._register_info_response, {'success_cb': weak_success_cb,
'error_cb': weak_error_cb})
def _register_info_response(self, _nbxmpp_client, stanza,
success_cb, error_cb):
if not nbxmpp.isResultNode(stanza):
error = stanza.getErrorMsg()
self._log.info('Error: %s', error)
if error_cb() is not None:
error_cb()(error)
else:
self._log.info('Register form received')
if success_cb() is not None:
form, is_form = self._get_register_form(stanza)
success_cb()(form, is_form)
@staticmethod
def _get_register_form(stanza):
parse_bob_data(stanza.getQuery())
form = stanza.getQuery().getTag('x', namespace=Namespace.DATA)
is_form = form is not None
if not is_form:
form = {}
oob = stanza.getQuery().getTag('x', namespace=Namespace.X_OOB)
if oob is not None:
form['redirect-url'] = oob.getTagData('url')
for field in stanza.getQueryPayload():
if not isinstance(field, nbxmpp.Node):
continue
if field.getName() == 'x':
continue
form[field.getName()] = field.getData()
return form, is_form
def get_instance(*args, **kwargs):
return Register(*args, **kwargs), 'Register'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment