Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0280.py @ 4351:6a0a081485b8
plugin autocrypt: Autocrypt protocol implementation:
Implementation of autocrypt: `autocrypt` header is checked, and if present and no public
key is known for the peer, the key is imported.
`autocrypt` header is also added to outgoing message (only if an email gateway is
detected).
For the moment, the JID is use as identifier, but the real email used by gateway should be
used in the future.
rel 456
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 28 Feb 2025 09:23:35 +0100 |
parents | 0d7bb4df2343 |
children |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # SAT plugin for managing xep-0280 |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
20 from libervia.backend.core.i18n import _, D_ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
21 from libervia.backend.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
22 |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 log = getLogger(__name__) |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
24 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4051
diff
changeset
|
25 from libervia.backend.core.constants import Const as C |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from twisted.words.protocols.jabber.error import StanzaError |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from twisted.internet import defer |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
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 |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 try: |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from twisted.words.protocols.xmlstream import XMPPHandler |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 except ImportError: |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 from wokkel.subprotocols import XMPPHandler |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 PARAM_CATEGORY = "Misc" |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 PARAM_NAME = "carbon" |
3028 | 39 PARAM_LABEL = D_("Message carbons") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
40 NS_CARBONS = "urn:xmpp:carbons:2" |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 PLUGIN_INFO = { |
3028 | 43 C.PI_NAME: "XEP-0280 Plugin", |
44 C.PI_IMPORT_NAME: "XEP-0280", | |
45 C.PI_TYPE: "XEP", | |
46 C.PI_PROTOCOLS: ["XEP-0280"], | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
47 C.PI_DEPENDENCIES: [], |
3028 | 48 C.PI_MAIN: "XEP_0280", |
49 C.PI_HANDLER: "yes", | |
50 C.PI_DESCRIPTION: D_("""Implementation of Message Carbons"""), | |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 } |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 class XEP_0280(object): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 # TODO: param is only checked at profile connection |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 # activate carbons on param change even after profile connection |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 # TODO: chat state notifications are not handled yet (and potentially other XEPs?) |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 params = """ |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 <params> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 <individual> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 <category name="{category_name}" label="{category_label}"> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 <param name="{param_name}" label="{param_label}" value="true" type="bool" security="0" /> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 </category> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 </individual> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 </params> |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 """.format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 category_name=PARAM_CATEGORY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 category_label=D_(PARAM_CATEGORY), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
70 param_name=PARAM_NAME, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 param_label=PARAM_LABEL, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
72 ) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 def __init__(self, host): |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 log.info(_("Plugin XEP_0280 initialization")) |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
77 host.memory.update_params(self.params) |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
78 host.trigger.add( |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
79 "message_received", self.message_received_trigger, priority=200000 |
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
80 ) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
82 def get_handler(self, client): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 return XEP_0280_handler() |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
85 def set_private(self, message_elt): |
2133
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
86 """Add a <private/> element to a message |
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
87 |
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
88 this method is intented to be called on final domish.Element by other plugins |
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
89 (in particular end 2 end encryption plugins) |
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
90 @param message_elt(domish.Element): <message> stanza |
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
91 """ |
3028 | 92 if message_elt.name != "message": |
93 log.error("addPrivateElt must be used with <message> stanzas") | |
2133
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
94 return |
3028 | 95 message_elt.addElement((NS_CARBONS, "private")) |
2133
7de291c3cd0c
plugin XEP-0280: new setPrivate method to tell server not to carbon copy it.
Goffi <goffi@goffi.org>
parents:
2099
diff
changeset
|
96 |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 @defer.inlineCallbacks |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
98 def profile_connected(self, client): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 """activate message carbons on connection if possible and activated in config""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
100 activate = self.host.memory.param_get_a( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 PARAM_NAME, PARAM_CATEGORY, profile_key=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
102 ) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 if not activate: |
3028 | 104 log.info(_("Not activating message carbons as requested in params")) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 return |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
107 yield self.host.check_features(client, (NS_CARBONS,)) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 except exceptions.FeatureNotFound: |
3028 | 109 log.warning(_("server doesn't handle message carbons")) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 else: |
3028 | 111 log.info(_("message carbons available, enabling it")) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 iq_elt = client.IQ() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 iq_elt.addElement((NS_CARBONS, "enable")) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 try: |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 yield iq_elt.send() |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 except StanzaError as e: |
3028 | 117 log.warning("Can't activate message carbons: {}".format(e)) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 else: |
3028 | 119 log.info(_("message carbons activated")) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
121 def message_received_trigger(self, client, message_elt, post_treat): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 """get message and handle it if carbons namespace is present""" |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 for e in message_elt.elements(): |
4153
9162d3480b9e
plugin XEP-0280: minor parsing improvement.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
124 if e.uri == NS_CARBONS and e.name in ("received", "sent"): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 carbons_elt = e |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 break |
4153
9162d3480b9e
plugin XEP-0280: minor parsing improvement.
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
127 else: |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 # this is not a message carbons, |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 # we continue normal behaviour |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 return True |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 if message_elt["from"] != client.jid.userhost(): |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 log.warning( |
3028 | 134 "The message carbon received is not from our server, hack attempt?\n{xml}".format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 xml=message_elt.toXml() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 ) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 forwarded_elt = next(carbons_elt.elements(C.NS_FORWARD, "forwarded")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
140 cc_message_elt = next(forwarded_elt.elements(C.NS_CLIENT, "message")) |
2816
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
141 |
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
142 # we replace the wrapping message with the CCed one |
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
143 # and continue the normal behaviour |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
144 message_elt["type"] = cc_message_elt.getAttribute("type", C.MESS_TYPE_NORMAL) |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
145 mess_id = cc_message_elt.getAttribute("id") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
146 if mess_id: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
147 message_elt[mess_id] = mess_id |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 if carbons_elt.name == "received": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 message_elt["from"] = cc_message_elt["from"] |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
150 lang = cc_message_elt.getAttribute("xml:lang") |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
151 if lang: |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
152 message_elt["xml:lang"] = lang |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 elif carbons_elt.name == "sent": |
4231
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
154 # the cc_message_elt is the full JID, so we copy it |
e11b13418ba6
plugin XEP-0353, XEP-0234, jingle: WebRTC data channel signaling implementation:
Goffi <goffi@goffi.org>
parents:
4153
diff
changeset
|
155 message_elt["from"] = cc_message_elt["from"] |
3141
49962f9a238a
plugin XEP-0280: handle CCed messages without "to"
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
156 try: |
49962f9a238a
plugin XEP-0280: handle CCed messages without "to"
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
157 message_elt["to"] = cc_message_elt["to"] |
49962f9a238a
plugin XEP-0280: handle CCed messages without "to"
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
158 except KeyError: |
49962f9a238a
plugin XEP-0280: handle CCed messages without "to"
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
159 # we may not have "to" in case of message from ourself (from an other |
49962f9a238a
plugin XEP-0280: handle CCed messages without "to"
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
160 # device) |
49962f9a238a
plugin XEP-0280: handle CCed messages without "to"
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
161 pass |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 log.warning( |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
164 "invalid message carbons received:\n{xml}".format(xml=message_elt.toXml()) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
165 ) |
2816
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
166 return False |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
2816
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
168 del message_elt.children[:] |
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
169 for c in cc_message_elt.children: |
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
170 message_elt.addChild(c) |
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
171 |
114cdde9ff96
plugin XEP-0280: priority and "sent" fixes:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
172 return True |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 |
4270
0d7bb4df2343
Reformatted code base using black.
Goffi <goffi@goffi.org>
parents:
4231
diff
changeset
|
174 |
3028 | 175 @implementer(iwokkel.IDisco) |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 class XEP_0280_handler(XMPPHandler): |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 return [disco.DiscoFeature(NS_CARBONS)] |
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
181 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2099
ad88808591ef
plugin XEP-0280: Message Carbons first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 return [] |