Mercurial > libervia-backend
annotate src/plugins/plugin_xep_0070.py @ 2009:90134b2e3dc4
primitivus, quick_frontends: show global notifications counter in contact_list + method to get these notifications in QuickApp
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 17 Jul 2016 17:32:46 +0200 |
parents | 2afd5bd781ef |
children | 0694a2611bad |
rev | line source |
---|---|
2005
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
1 #!/usr/bin/python |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
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/>. |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
19 from sat.core.i18n import _, D_ |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
20 from sat.core.constants import Const as C |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
21 from sat.core.i18n import _ |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
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.jabber import xmlstream |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
24 from twisted.words.protocols import jabber |
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__) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
26 from sat.tools import xml_tools |
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 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
29 from zope.interface import implements |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
30 try: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
31 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
|
32 except ImportError: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
33 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
|
34 |
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 NS_HTTP_AUTH = 'http://jabber.org/protocol/http-auth' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
37 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
38 IQ = 'iq' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
39 IQ_GET = '/'+IQ+'[@type="get"]' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
40 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
|
41 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
42 MSG = 'message' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
43 MSG_GET = '/'+MSG+'[@type="normal"]' |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
44 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
|
45 |
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 PLUGIN_INFO = { |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
48 "name": "XEP-0070 Plugin", |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
49 "import_name": "XEP-0070", |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
50 "type": "XEP", |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
51 "protocols": ["XEP-0070"], |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
52 "dependencies": [], |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
53 "main": "XEP_0070", |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
54 "handler": "yes", |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
55 "description": _("""Implementation of HTTP Requests via XMPP""") |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
56 } |
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 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
|
60 """ |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
61 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
|
62 """ |
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 def __init__(self, host): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
65 log.info(_("Plugin XEP_0070 initialization")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
66 self.host = host |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
67 self._dictRequest = dict() |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
68 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
69 def getHandler(self, profile): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
70 return XEP_0070_handler(self, profile) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
71 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
72 def onHttpAuthRequestIQ(self, iq_elt, client): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
73 """This method is called on confirmation request received (XEP-0070 #4.5) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
74 @param iq_elt: IQ element |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
75 @param client: %(doc_client)s""" |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
76 log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (iq)")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
77 self._treatHttpAuthRequest(iq_elt, IQ, client) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
78 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
79 def onHttpAuthRequestMsg(self, msg_elt, client): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
80 """This method is called on confirmation request received (XEP-0070 #4.5) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
81 @param msg_elt: message element |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
82 @param client: %(doc_client)s""" |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
83 log.info(_("XEP-0070 Verifying HTTP Requests via XMPP (message)")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
84 self._treatHttpAuthRequest(msg_elt, MSG, client) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
85 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
86 def _treatHttpAuthRequest(self, elt, stanzaType, client): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
87 elt.handled = True |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
88 auth_elt = elt.elements(NS_HTTP_AUTH, 'confirm').next() |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
89 auth_id = auth_elt['id'] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
90 auth_method = auth_elt['method'] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
91 auth_url = auth_elt['url'] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
92 self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
93 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
94 confirm_ui = xml_tools.XMLUI("form", title=D_("Auth confirmation"), submit_id='') |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
95 confirm_ui.addText(D_("HTTP ({}) Authorization for {} (id: {}).".format(auth_method, auth_url, auth_id))) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
96 confirm_ui.addText(D_("Submit to authorize, cancel otherwise.")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
97 d = xml_tools.deferredUI(self.host, confirm_ui, chained=False) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
98 d.addCallback(self._authRequestCallback, client.profile) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
99 self.host.actionNew({"xmlui": confirm_ui.toXml()}, profile=client.profile) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
100 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
101 def _authRequestCallback(self, result, profile): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
102 client = self.host.getClient(profile) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
103 try: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
104 cancelled = result['cancelled'] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
105 except KeyError: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
106 cancelled = False |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
107 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
108 authorized = False |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
109 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
110 if cancelled: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
111 auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[client] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
112 del self._dictRequest[client] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
113 authorized = False |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
114 else: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
115 try: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
116 auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[client] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
117 del self._dictRequest[client] |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
118 authorized = True |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
119 except KeyError: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
120 authorized = False |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
121 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
122 if authorized: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
123 if (stanzaType == IQ): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
124 # iq |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
125 log.debug(_("XEP-0070 reply iq")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
126 iq_result_elt = xmlstream.toResponse(elt, 'result') |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
127 client.xmlstream.send(iq_result_elt) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
128 elif (stanzaType == MSG): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
129 # message |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
130 log.debug(_("XEP-0070 reply message")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
131 msg_result_elt = xmlstream.toResponse(elt, 'result') |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
132 msg_result_elt.addChild(elt.elements(NS_HTTP_AUTH, 'confirm').next()) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
133 client.xmlstream.send(msg_result_elt) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
134 else: |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
135 log.debug(_("XEP-0070 reply error")) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
136 result_elt = jabber.error.StanzaError("not-authorized").toResponse(elt) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
137 client.xmlstream.send(result_elt) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
138 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
139 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
140 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
|
141 implements(iwokkel.IDisco) |
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 __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
|
144 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
|
145 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
|
146 self.profile = profile |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
147 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
148 def connectionInitialized(self): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
149 self.xmlstream.addObserver(IQ_HTTP_AUTH_REQUEST, self.plugin_parent.onHttpAuthRequestIQ, client=self.parent) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
150 self.xmlstream.addObserver(MSG_HTTP_AUTH_REQUEST, self.plugin_parent.onHttpAuthRequestMsg, client=self.parent) |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
151 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
152 def getDiscoInfo(self, requestor, target, nodeIdentifier=''): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
153 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
|
154 |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
155 def getDiscoItems(self, requestor, target, nodeIdentifier=''): |
2afd5bd781ef
plugin XEP-0070: implementation of XEP-0070 (verifying HTTP request via XMPP)
Geoffrey POUZET <chteufleur@kingpenguin.tk>
parents:
diff
changeset
|
156 return [] |