Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0077.py @ 4278:240d8b7ad906
component Conferences: implementation of SFU component to make multi-party A/V conferences:
This component wrap `Galène` SFU and translate its signaling to XMPP Jingle in both
direction.
rel 445
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 05 Jul 2024 17:18:37 +0200 |
parents | 0d7bb4df2343 |
children | 7ded09452875 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing xep-0077 |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
20 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error |
3354
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
21 from twisted.internet import defer, reactor, ssl |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
22 from wokkel import data_form |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.core.xmpp import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
28 from libervia.backend.tools import xml_tools |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
29 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
30 log = getLogger(__name__) |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
30
diff
changeset
|
31 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 NS_REG = "jabber:iq:register" |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 C.PI_NAME: "XEP 0077 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
36 C.PI_IMPORT_NAME: "XEP-0077", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
37 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
38 C.PI_PROTOCOLS: ["XEP-0077"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
39 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
40 C.PI_MAIN: "XEP_0077", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 C.PI_DESCRIPTION: _("""Implementation of in-band registration"""), |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
44 # FIXME: this implementation is incomplete |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
45 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
47 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
48 # FIXME: request IQ is not send to check available fields, |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
49 # while XEP recommand to use it |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
50 # FIXME: doesn't handle data form or oob |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
51 namespace = "jabber:client" |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
52 |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
53 def __init__(self, jid_, password, email=None, check_certificate=True): |
3028 | 54 log.debug(_("Registration asked for {jid}").format(jid=jid_)) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
55 xmlstream.ConnectAuthenticator.__init__(self, jid_.host) |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
56 self.jid = jid_ |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
57 self.password = password |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
58 self.email = email |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
59 self.check_certificate = check_certificate |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
60 self.registered = defer.Deferred() |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
61 |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
62 def associateWithStream(self, xs): |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
63 xmlstream.ConnectAuthenticator.associateWithStream(self, xs) |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
64 xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, self.register) |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
65 |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
66 xs.initializers = [client.CheckVersionInitializer(xs)] |
3354
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
67 if self.check_certificate: |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
68 tls_required, configurationForTLS = True, None |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
69 else: |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
70 tls_required = False |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
71 configurationForTLS = ssl.CertificateOptions(trustRoot=None) |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
72 tls_init = xmlstream.TLSInitiatingInitializer( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
73 xs, required=tls_required, configurationForTLS=configurationForTLS |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
74 ) |
3354
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
75 |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
76 xs.initializers.append(tls_init) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
77 |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
78 def register(self, xmlstream): |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
79 log.debug( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
80 _( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
81 "Stream started with {server}, now registering".format( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
82 server=self.jid.host |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
83 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
84 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
85 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
86 iq = XEP_0077.build_register_iq( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
87 self.xmlstream, self.jid, self.password, self.email |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
88 ) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
89 d = iq.send(self.jid.host).addCallbacks( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
90 self.registration_cb, self.registration_eb |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
91 ) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
92 d.chainDeferred(self.registered) |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
93 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
94 def registration_cb(self, answer): |
3028 | 95 log.debug(_("Registration answer: {}").format(answer.toXml())) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
96 self.xmlstream.sendFooter() |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
97 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
98 def registration_eb(self, failure_): |
3028 | 99 log.info(_("Registration failure: {}").format(str(failure_.value))) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
100 self.xmlstream.sendFooter() |
2183 | 101 raise failure_ |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
102 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
103 |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
104 class ServerRegister(xmlstream.XmlStreamFactory): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
105 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
106 def __init__(self, *args, **kwargs): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
107 xmlstream.XmlStreamFactory.__init__(self, *args, **kwargs) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
108 self.addBootstrap(xmlstream.STREAM_END_EVENT, self._disconnected) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
109 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
110 def clientConnectionLost(self, connector, reason): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
111 connector.disconnect() |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
112 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
113 def _disconnected(self, reason): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
114 if not self.authenticator.registered.called: |
3028 | 115 err = jabber_error.StreamError("Server unexpectedly closed the connection") |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
116 try: |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
117 if reason.value.args[0][0][2] == "certificate verify failed": |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
118 err = exceptions.InvalidCertificate() |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
119 except (IndexError, TypeError): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
120 pass |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
121 self.authenticator.registered.errback(err) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
122 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
123 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
124 class XEP_0077(object): |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
126 log.info(_("Plugin XEP_0077 initialization")) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
128 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
129 "in_band_register", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
133 method=self._in_band_register, |
3028 | 134 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
136 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
137 "in_band_account_new", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 in_sign="ssssi", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
141 method=self._register_new_account, |
3028 | 142 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
143 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
144 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
145 "in_band_unregister", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 method=self._unregister, |
3028 | 150 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
151 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
152 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
153 "in_band_password_change", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
154 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
157 method=self._change_password, |
3028 | 158 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
160 |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
161 @staticmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
162 def build_register_iq(xmlstream_, jid_, password, email=None): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 iq_elt = xmlstream.IQ(xmlstream_, "set") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
164 iq_elt["to"] = jid_.host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 query_elt = iq_elt.addElement(("jabber:iq:register", "query")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
166 username_elt = query_elt.addElement("username") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
167 username_elt.addContent(jid_.user) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
168 password_elt = query_elt.addElement("password") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
169 password_elt.addContent(password) |
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
170 if email is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
171 email_elt = query_elt.addElement("email") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
172 email_elt.addContent(email) |
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
173 return iq_elt |
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
174 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
175 def _reg_cb(self, answer, client, post_treat_cb): |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 """Called after the first get IQ""" |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
177 try: |
3028 | 178 query_elt = next(answer.elements(NS_REG, "query")) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
179 except StopIteration: |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
180 raise exceptions.DataError("Can't find expected query element") |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
181 |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
182 try: |
3028 | 183 x_elem = next(query_elt.elements(data_form.NS_X_DATA, "x")) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
184 except StopIteration: |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
185 # XXX: it seems we have an old service which doesn't manage data forms |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
186 log.warning(_("Can't find data form")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
187 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
188 _("This gateway can't be managed by SàT, sorry :(") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
189 ) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
190 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
191 def submit_form(data, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
192 form_elt = xml_tools.xmlui_result_to_elt(data) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
193 |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
194 iq_elt = client.IQ() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 iq_elt["id"] = answer["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 iq_elt["to"] = answer["from"] |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
197 query_elt = iq_elt.addElement("query", NS_REG) |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
198 query_elt.addChild(form_elt) |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
199 d = iq_elt.send() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
200 d.addCallback(self._reg_success, client, post_treat_cb) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
201 d.addErrback(self._reg_failure, client) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
202 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
203 |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
204 form = data_form.Form.fromElement(x_elem) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
205 submit_reg_id = self.host.register_callback( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
206 submit_form, with_data=True, one_shot=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
208 return xml_tools.data_form_2_xmlui(form, submit_reg_id) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
210 def _reg_eb(self, failure, client): |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 """Called when something is wrong with registration""" |
3028 | 212 log.info(_("Registration failure: %s") % str(failure.value)) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
213 raise failure |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
214 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
215 def _reg_success(self, answer, client, post_treat_cb): |
3028 | 216 log.debug(_("registration answer: %s") % answer.toXml()) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
217 if post_treat_cb is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
218 post_treat_cb(jid.JID(answer["from"]), client.profile) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
219 return {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
220 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
221 def _reg_failure(self, failure, client): |
3028 | 222 log.info(_("Registration failure: %s") % str(failure.value)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
223 if failure.value.condition == "conflict": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 raise exceptions.ConflictError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 _("Username already exists, please choose an other one") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 ) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
227 raise failure |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
228 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
229 def _in_band_register(self, to_jid_s, profile_key=C.PROF_KEY_NONE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
230 return self.in_band_register, jid.JID(to_jid_s, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
231 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
232 def in_band_register(self, to_jid, post_treat_cb=None, profile_key=C.PROF_KEY_NONE): |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
233 """register to a service |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
234 |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
235 @param to_jid(jid.JID): jid of the service to register to |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
236 """ |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
237 # FIXME: this post_treat_cb arguments seems wrong, check it |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
238 client = self.host.get_client(profile_key) |
3028 | 239 log.debug(_("Asking registration for {}").format(to_jid.full())) |
240 reg_request = client.IQ("get") | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
241 reg_request["from"] = client.jid.full() |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 reg_request["to"] = to_jid.full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
243 reg_request.addElement("query", NS_REG) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
244 d = reg_request.send(to_jid.full()).addCallbacks( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
245 self._reg_cb, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
246 self._reg_eb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 callbackArgs=[client, post_treat_cb], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
248 errbackArgs=[client], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 ) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
250 return d |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
251 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
252 def _register_new_account(self, jid_, password, email, host, port): |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
253 kwargs = {} |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
254 if email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
255 kwargs["email"] = email |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
256 if host: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
257 kwargs["host"] = host |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
258 if port: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
259 kwargs["port"] = port |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
260 return self.register_new_account(jid.JID(jid_), password, **kwargs) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
261 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
262 def register_new_account( |
3426
8c25489bb79c
plugin XEP-0077: use `xmpp_domain` when set for `host`
Goffi <goffi@goffi.org>
parents:
3400
diff
changeset
|
263 self, jid_, password, email=None, host=None, port=C.XMPP_C2S_PORT |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 ): |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
265 """register a new account on a XMPP server |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
266 |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
267 @param jid_(jid.JID): request jid to register |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
268 @param password(unicode): password of the account |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
269 @param email(unicode): email of the account |
3426
8c25489bb79c
plugin XEP-0077: use `xmpp_domain` when set for `host`
Goffi <goffi@goffi.org>
parents:
3400
diff
changeset
|
270 @param host(None, unicode): host of the server to register to |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
271 @param port(int): port of the server to register to |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
272 """ |
3426
8c25489bb79c
plugin XEP-0077: use `xmpp_domain` when set for `host`
Goffi <goffi@goffi.org>
parents:
3400
diff
changeset
|
273 if host is None: |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
274 host = self.host.memory.config_get("", "xmpp_domain", "127.0.0.1") |
3028 | 275 check_certificate = host != "127.0.0.1" |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
276 authenticator = RegisteringAuthenticator( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
277 jid_, password, email, check_certificate=check_certificate |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
278 ) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
279 registered_d = authenticator.registered |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
280 server_register = ServerRegister(authenticator) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
281 reactor.connectTCP(host, port, server_register) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
282 return registered_d |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
283 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
284 def _change_password(self, new_password, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
285 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
286 return self.change_password(client, new_password) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
287 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
288 def change_password(self, client, new_password): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
289 iq_elt = self.build_register_iq(client.xmlstream, client.jid, new_password) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
290 d = iq_elt.send(client.jid.host) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
292 lambda __: self.host.memory.param_set( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
293 "Password", new_password, "Connection", profile_key=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
294 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
295 ) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
296 return d |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
297 |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
298 def _unregister(self, to_jid_s, profile_key): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
299 client = self.host.get_client(profile_key) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
300 return self.unregister(client, jid.JID(to_jid_s)) |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
301 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
302 def unregister(self, client: SatXMPPEntity, to_jid: jid.JID) -> defer.Deferred: |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
303 """remove registration from a server/service |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
304 |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
305 BEWARE! if you remove registration from profile own server, this will |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
306 DELETE THE XMPP ACCOUNT WITHOUT WARNING |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
307 @param to_jid: jid of the service or server |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
308 None to delete client's account (DANGEROUS!) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
309 """ |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
310 iq_elt = client.IQ() |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
311 if to_jid is not None: |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
312 iq_elt["to"] = to_jid.full() |
3028 | 313 query_elt = iq_elt.addElement((NS_REG, "query")) |
314 query_elt.addElement("remove") | |
3400
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
315 d = iq_elt.send() |
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
316 if not to_jid or to_jid == jid.JID(client.jid.host): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
317 d.addCallback(lambda __: client.entity_disconnect()) |
3400
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
318 return d |