Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0070.py @ 4291:39ac821ebbdb
plugin XEP-0167: handle conferences:
- SDP can now be answered by component instead of frontend. This is useful for A/V
conferences component to handle A/V call jingle sessions.
- new `call_update` and method, and `content-add` action preparation. This is not yet used
by A/V conference, but it's a preparation for a potential future use.
- Add NS_AV_CONFERENCES to features as required by the newly proposed A/V Conferences
protoXEP.
rel 447
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 29 Jul 2024 03:31:09 +0200 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
3 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
4 # SAT plugin for managing xep-0070 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
5 # Copyright (C) 2009-2016 Geoffrey POUZET (chteufleur@kingpenguin.tk) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
6 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
10 # (at your option) any later version. |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
11 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
16 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
19 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
20 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
|
21 from libervia.backend.core.log import getLogger |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
22 from twisted.words.protocols.jabber import xmlstream |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
23 from twisted.words.protocols import jabber |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
24 |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
25 log = getLogger(__name__) |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.tools import xml_tools |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
27 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
28 from wokkel import disco, iwokkel |
3028 | 29 from zope.interface import implementer |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
30 |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
31 try: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
32 from twisted.words.protocols.xmlstream import XMPPHandler |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
33 except ImportError: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
34 from wokkel.subprotocols import XMPPHandler |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
35 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
36 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
37 NS_HTTP_AUTH = "http://jabber.org/protocol/http-auth" |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
38 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
39 IQ = "iq" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 IQ_GET = "/" + IQ + '[@type="get"]' |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
41 IQ_HTTP_AUTH_REQUEST = IQ_GET + '/confirm[@xmlns="' + NS_HTTP_AUTH + '"]' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
42 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 MSG = "message" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 MSG_GET = "/" + MSG + '[@type="normal"]' |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
45 MSG_HTTP_AUTH_REQUEST = MSG_GET + '/confirm[@xmlns="' + NS_HTTP_AUTH + '"]' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
46 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
47 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
48 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
49 C.PI_NAME: "XEP-0070 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
50 C.PI_IMPORT_NAME: "XEP-0070", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
51 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
52 C.PI_PROTOCOLS: ["XEP-0070"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
53 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
54 C.PI_MAIN: "XEP_0070", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
55 C.PI_HANDLER: "yes", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 C.PI_DESCRIPTION: _("""Implementation of HTTP Requests via XMPP"""), |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
57 } |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
58 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
59 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
60 class XEP_0070(object): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
61 """ |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
62 Implementation for XEP 0070. |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
63 """ |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
64 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
65 def __init__(self, host): |
3028 | 66 log.info(_("Plugin XEP_0070 initialization")) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
67 self.host = host |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
68 self._dictRequest = dict() |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
69 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
70 def get_handler(self, client): |
2144
1d3f73e065e1
core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents:
2129
diff
changeset
|
71 return XEP_0070_handler(self, client.profile) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
72 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
73 def on_http_auth_request_iq(self, iq_elt, client): |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
74 """This method is called on confirmation request received (XEP-0070 #4.5) |
2094
438a49dbfe87
xep-0070: fixed use of byte string instead of unicode
Goffi <goffi@goffi.org>
parents:
2014
diff
changeset
|
75 |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
76 @param iq_elt: IQ element |
2094
438a49dbfe87
xep-0070: fixed use of byte string instead of unicode
Goffi <goffi@goffi.org>
parents:
2014
diff
changeset
|
77 @param client: %(doc_client)s |
438a49dbfe87
xep-0070: fixed use of byte string instead of unicode
Goffi <goffi@goffi.org>
parents:
2014
diff
changeset
|
78 """ |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
79 log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (iq)")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
80 self._treat_http_auth_request(iq_elt, IQ, client) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
81 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
82 def on_http_auth_request_msg(self, msg_elt, client): |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
83 """This method is called on confirmation request received (XEP-0070 #4.5) |
2094
438a49dbfe87
xep-0070: fixed use of byte string instead of unicode
Goffi <goffi@goffi.org>
parents:
2014
diff
changeset
|
84 |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
85 @param msg_elt: message element |
2094
438a49dbfe87
xep-0070: fixed use of byte string instead of unicode
Goffi <goffi@goffi.org>
parents:
2014
diff
changeset
|
86 @param client: %(doc_client)s |
438a49dbfe87
xep-0070: fixed use of byte string instead of unicode
Goffi <goffi@goffi.org>
parents:
2014
diff
changeset
|
87 """ |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
88 log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (message)")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
89 self._treat_http_auth_request(msg_elt, MSG, client) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
90 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
91 def _treat_http_auth_request(self, elt, stanzaType, client): |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
92 elt.handled = True |
3028 | 93 auth_elt = next(elt.elements(NS_HTTP_AUTH, "confirm")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 auth_id = auth_elt["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 auth_method = auth_elt["method"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 auth_url = auth_elt["url"] |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
97 self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt) |
3028 | 98 title = D_("Auth confirmation") |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
99 message = D_( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
100 "{auth_url} needs to validate your identity, do you agree?\n" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
101 "Validation code : {auth_id}\n\n" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
102 "Please check that this code is the same as on {auth_url}" |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
103 ).format(auth_url=auth_url, auth_id=auth_id) |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
104 d = xml_tools.defer_confirm( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
105 self.host, message=message, title=title, profile=client.profile |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
106 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
107 d.addCallback(self._auth_request_callback, client) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
108 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
109 def _auth_request_callback(self, authorized, client): |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
110 try: |
2625
a55a14c3cbf4
plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
111 auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest.pop( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
112 client |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
113 ) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
114 except KeyError: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
115 authorized = False |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
116 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
117 if authorized: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 if stanzaType == IQ: |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
119 # iq |
3028 | 120 log.debug(_("XEP-0070 reply iq")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 iq_result_elt = xmlstream.toResponse(elt, "result") |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
2094
diff
changeset
|
122 client.send(iq_result_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 elif stanzaType == MSG: |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
124 # message |
3028 | 125 log.debug(_("XEP-0070 reply message")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 msg_result_elt = xmlstream.toResponse(elt, "result") |
3028 | 127 msg_result_elt.addChild(next(elt.elements(NS_HTTP_AUTH, "confirm"))) |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
2094
diff
changeset
|
128 client.send(msg_result_elt) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
129 else: |
3028 | 130 log.debug(_("XEP-0070 reply error")) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
131 result_elt = jabber.error.StanzaError("not-authorized").toResponse(elt) |
2129
6a66c8c5a567
core: replaced calls to client.xmlstream.send by client.send which is the right method to use. client.xmlstream should not be used directly
Goffi <goffi@goffi.org>
parents:
2094
diff
changeset
|
132 client.send(result_elt) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
133 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
134 |
3028 | 135 @implementer(iwokkel.IDisco) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
136 class XEP_0070_handler(XMPPHandler): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
137 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
138 def __init__(self, plugin_parent, profile): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
139 self.plugin_parent = plugin_parent |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
140 self.host = plugin_parent.host |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
141 self.profile = profile |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
142 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
143 def connectionInitialized(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 IQ_HTTP_AUTH_REQUEST, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
146 self.plugin_parent.on_http_auth_request_iq, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
147 client=self.parent, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
150 MSG_HTTP_AUTH_REQUEST, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
151 self.plugin_parent.on_http_auth_request_msg, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
152 client=self.parent, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 ) |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
154 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
156 return [disco.DiscoFeature(NS_HTTP_AUTH)] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
157 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
159 return [] |