annotate libervia/backend/plugins/plugin_xep_0033.py @ 4332:71c939e34ca6

XEP-0373 (OX): Adjust to gpgme updates: generate with explicit algorithm and subkeys
author Syndace <me@syndace.dev>
date Sat, 13 Jul 2024 18:28:28 +0200
parents 530f86f078cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
2
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
3 # Libervia plugin for Extended Stanza Addressing (XEP-0033)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1552
diff changeset
5 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
6
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # (at your option) any later version.
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
11
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
16
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
19
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
20 from typing import Iterator, Literal, Self
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
21
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
22 from pydantic import BaseModel, model_validator
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
23 from twisted.internet import defer
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
24 from twisted.words.protocols.jabber import jid
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
25 from twisted.words.protocols.jabber.xmlstream import XMPPHandler
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
26 from twisted.words.xish import domish
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from wokkel import disco, iwokkel
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
28 from zope.interface import implementer
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
29
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
30 from libervia.backend.core import exceptions
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
31 from libervia.backend.core.constants import Const as C
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
32 from libervia.backend.core.core_types import SatXMPPEntity
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
33 from libervia.backend.core.i18n import _
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
34 from libervia.backend.core.log import getLogger
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
35 from libervia.backend.models.core import MessageData
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
36 from libervia.backend.models.types import JIDType
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
37 from libervia.backend.tools import trigger
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
38 from libervia.backend.tools.xml_tools import element_copy
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
39
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
40 log = getLogger(__name__)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
41
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
42
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
43 # TODO: fix Prosody "addressing" plugin to leave the concerned bcc according to the spec:
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
44 # http://xmpp.org/extensions/xep-0033.html#addr-type-bcc "This means that the server
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
45 # MUST remove these addresses before the stanza is delivered to anyone other than the
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
46 # given bcc addressee or the multicast service of the bcc addressee."
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
47 #
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
48 # http://xmpp.org/extensions/xep-0033.html#multicast "Each 'bcc' recipient MUST receive
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
49 # only the <address type='bcc'/> associated with that addressee."
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
50
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
51 # TODO: fix Prosody "addressing" plugin to determine itself if remote servers supports
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
52 # this XEP
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
53
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
54
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
55 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
56 C.PI_NAME: "Extended Stanza Addressing Protocol Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
57 C.PI_IMPORT_NAME: "XEP-0033",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
58 C.PI_TYPE: "XEP",
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
59 C.PI_MODES: C.PLUG_MODE_BOTH,
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
60 C.PI_PROTOCOLS: ["XEP-0033"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
61 C.PI_DEPENDENCIES: [],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
62 C.PI_MAIN: "XEP_0033",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
63 C.PI_HANDLER: "yes",
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
64 C.PI_DESCRIPTION: _(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
65 "Efficiently send messages to several recipients, using metadata to transmit "
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
66 "them with main recipients (to), carbon copies (cc), and blind carbon copies "
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
67 "(bcc) fields in a similar manner as for email."
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
68 ),
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
69 }
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
70
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
71 NS_ADDRESS = "http://jabber.org/protocol/address"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
72 RECIPIENT_FIELDS = ("to", "cc", "bcc")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
73
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
74
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
75 class AddressType(BaseModel):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
76 jid: JIDType | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
77 desc: str | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
78 delivered: bool | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
79
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
80 def set_attribute(self, address_elt: domish.Element) -> None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
81 """Set <address> element attribute from this instance's data."""
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
82 if self.jid:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
83 address_elt["jid"] = str(self.jid)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
84 if self.desc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
85 address_elt["desc"] = self.desc
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
86 if self.delivered is not None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
87 address_elt["delivered"] = "true" if self.delivered else "false"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
88
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
89 @classmethod
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
90 def from_element(cls, address_elt: domish.Element) -> Self:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
91 """Create an AddressType instance from an <address> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
92
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
93 @param address_elt: The <address> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
94 @return: AddressType instance.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
95 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
96 if address_elt.uri != NS_ADDRESS or address_elt.name != "address":
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
97 raise ValueError("Element is not an <address> element")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
98
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
99 kwargs = {}
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
100 if address_elt.hasAttribute("jid"):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
101 kwargs["jid"] = jid.JID(address_elt["jid"])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
102 if address_elt.hasAttribute("desc"):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
103 kwargs["desc"] = address_elt["desc"]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
104 if address_elt.hasAttribute("delivered"):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
105 kwargs["delivered"] = address_elt["delivered"] == "true"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
106 return cls(**kwargs)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
107
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
108 def to_element(self) -> domish.Element:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
109 """Build the <address> element from this instance's data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
110
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
111 @return: <address> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
112 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
113 address_elt = domish.Element((NS_ADDRESS, "address"))
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
114 self.set_attribute(address_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
115 return address_elt
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
116
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
117
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
118 class AddressesData(BaseModel):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
119 to: list[AddressType] | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
120 cc: list[AddressType] | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
121 bcc: list[AddressType] | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
122 replyto: list[AddressType] | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
123 replyroom: list[AddressType] | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
124 noreply: bool | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
125 ofrom: JIDType | None = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
126
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
127 @model_validator(mode="after")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
128 def check_minimal_data(self) -> Self:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
129 assert self.to or self.cc or self.bcc, "At least one recipent must be set"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
130 if self.noreply and (self.replyto is not None or self.replyroom is not None):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
131 log.warning(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
132 '"noreply" can\'t be used with "replyto" or "replyroom". Ignoring reply '
4313
530f86f078cc plugin XEP-0033: formatting.
Goffi <goffi@goffi.org>
parents: 4306
diff changeset
133 f"fields ({self.replyto=}, {self.replyroom=})."
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
134 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
135 # We reset instead of raising a ValueError, because this can happen in
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
136 # incoming messages and we should not discard them.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
137 self.replyto = self.replyroom = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
138 return self
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
139
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
140 @property
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
141 def addresses(self) -> Iterator[AddressType]:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
142 """Iterator over all recipient addresses."""
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
143 for field in RECIPIENT_FIELDS:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
144 addresses = getattr(self, field)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
145 if not addresses:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
146 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
147 yield from addresses
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
148
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
149 @staticmethod
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
150 def add_address_element(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
151 addresses_elt: domish.Element, type_: str, address: AddressType | None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
152 ) -> None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
153 """Add <address> element to parent <addresses> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
154
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
155 @param addresses_elt: Parent <addresses> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
156 @param type_: Value of "type" attribute.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
157 @param address: Address data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
158 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
159
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
160 address_elt = addresses_elt.addElement("address")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
161 address_elt["type"] = type_
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
162 if address is not None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
163 address.set_attribute(address_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
164
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
165 @classmethod
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
166 def from_element(cls, addresses_elt: domish.Element) -> Self:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
167 """Create an AddressesData instance from an <addresses> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
168
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
169 @param addresses_elt: The <addresses> element or its direct parent.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
170 @return: AddressesData instance.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
171 @raise NotFound: No <addresses> element found.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
172 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
173 if addresses_elt.uri != NS_ADDRESS or addresses_elt.name != "addresses":
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
174 child_addresses_elt = next(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
175 addresses_elt.elements(NS_ADDRESS, "addresses"), None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
176 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
177 if child_addresses_elt is None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
178 raise exceptions.NotFound("<addresses> element not found")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
179 else:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
180 addresses_elt = child_addresses_elt
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
181
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
182 kwargs = {}
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
183 for address_elt in addresses_elt.elements(NS_ADDRESS, "address"):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
184 address_type = address_elt.getAttribute("type")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
185 if address_type in ("to", "cc", "bcc", "replyto", "replyroom"):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
186 try:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
187 address = AddressType.from_element(address_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
188 except Exception as e:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
189 log.warning(f"Invalid <address> element: {e}\n{address_elt.toXml()}")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
190 else:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
191 kwargs.setdefault(address_type, []).append(address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
192 elif address_type == "noreply":
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
193 kwargs["noreply"] = True
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
194 elif address_type == "ofrom":
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
195 kwargs["ofrom"] = jid.JID(address_elt["jid"])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
196 else:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
197 log.warning(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
198 f"Invalid <address> element: unknonwn type {address_type!r}\n"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
199 f"{address_elt.toXml()}"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
200 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
201 return cls(**kwargs)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
202
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
203 def to_element(self) -> domish.Element:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
204 """Build the <addresses> element from this instance's data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
205
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
206 @return: <addresses> element.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
207 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
208 addresses_elt = domish.Element((NS_ADDRESS, "addresses"))
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
209
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
210 if self.to:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
211 for address in self.to:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
212 self.add_address_element(addresses_elt, "to", address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
213 if self.cc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
214 for address in self.cc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
215 self.add_address_element(addresses_elt, "cc", address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
216 if self.bcc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
217 for address in self.bcc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
218 self.add_address_element(addresses_elt, "bcc", address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
219 if self.replyto:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
220 for address in self.replyto:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
221 self.add_address_element(addresses_elt, "replyto", address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
222 if self.replyroom:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
223 for address in self.replyroom:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
224 self.add_address_element(addresses_elt, "replyroom", address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
225 if self.noreply:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
226 self.add_address_element(addresses_elt, "noreply", None)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
227 if self.ofrom is not None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
228 address_elt = addresses_elt.addElement("address")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
229 address_elt["type"] = "ofrom"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
230 address_elt["jid"] = self.ofrom.full()
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
231
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
232 return addresses_elt
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
233
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
234
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
235 class XEP_0033:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
236 """
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
237 Implementation for XEP-0033
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
238 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
240 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 922
diff changeset
241 log.info(_("Extended Stanza Addressing plugin initialization"))
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
242 self.host = host
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
243 host.register_namespace("address", NS_ADDRESS)
749
192b804ee446 plugin XEP-0033: bug fix for sending messages with the addressing feature to several servers
souliane <souliane@mailoo.org>
parents: 742
diff changeset
244 self.internal_data = {}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
245 host.trigger.add(
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
246 "sendMessage",
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
247 self.send_message_trigger,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
248 # We want this trigger to be the last one, as it may send messages.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
249 trigger.TriggerManager.MIN_PRIORITY,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
250 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
251 host.trigger.add(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
252 "sendMessageComponent",
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
253 self.send_message_trigger,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
254 # We want this trigger to be the last one, as it may send messages.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
255 trigger.TriggerManager.MIN_PRIORITY,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256 )
4051
c23cad65ae99 core: renamed `messageReceived` trigger to `message_received`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
257 host.trigger.add("message_received", self.message_received_trigger)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
258
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
259 async def _stop_if_all_delivered(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
260 self, client: SatXMPPEntity, mess_data: MessageData, addr_data: AddressesData
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
261 ) -> None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
262 """Check if all message have been delivered, and stop workflow in this case.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
263
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
264 If workflow is stopped, message will be added to history and a signal will be sent
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
265 to bridge.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
266 @param client: Client session.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
267 @param mess_data: Message data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
268 @param addr_data: Addresses data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
269
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
270 @raise exceptions.CancelError: All message have been delivered and workflow is
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
271 terminated.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
272 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
273 if all(a.delivered for a in addr_data.addresses):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
274 await client.message_add_to_history(mess_data)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
275 await client.message_send_to_bridge(mess_data)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
276 raise exceptions.CancelError(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
277 f"Message has been delivered by {PLUGIN_INFO['C.PI_NAME']}."
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
278 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
279
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
280 async def _handle_addresses(self, client, mess_data: MessageData) -> MessageData:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
281 """Handle Extended Stanza Addressing metadata for outgoing messages."""
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
282 if not "addresses" in mess_data["extra"]:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
283 return mess_data
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
284
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
285 if mess_data["extra"].get(C.MESS_KEY_ENCRYPTED, False):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
286 # TODO: Message must be encrypted for all recipients, and "to" correspond to
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
287 # multicast service in this case.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
288 raise NotImplementedError(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
289 "End-to-end encryption is not supported yet with multicast addressing."
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
290 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
291
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
292 data = AddressesData(**mess_data["extra"]["addresses"])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
293 recipients = set()
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
294 domains: dict[str, list[AddressType]] = {}
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
295 for address in data.addresses:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
296 if address.jid is None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
297 raise NotImplementedError("Non JID addresses are not supported yet.")
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
298 recipients.add(address.jid)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
299 try:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
300 domains[address.jid.host].append(address)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
301 except KeyError:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
302 domains[address.jid.host] = [address]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
303
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
304 to_recipient_jid = mess_data["to"]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
305
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
306 if to_recipient_jid.user and to_recipient_jid not in recipients:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
307 # If the main recipient is not a service (i.e. it has a "user" part), we want
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
308 # to move it to the XEP-0033's "to" addresses, so we can use the multicast
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
309 # service for <message> "to" attribute.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
310 to_recipient_addr = AddressType(jid=to_recipient_jid)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
311 if data.to is None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
312 data.to = [to_recipient_addr]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
313 else:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
314 data.to.insert(0, to_recipient_addr)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
315 recipients.add(to_recipient_jid)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
316 domains.setdefault(to_recipient_jid.host, []).append(to_recipient_addr)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
317
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
318 # XXX: If our server doesn't handle multicast, we don't check sub-services as
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
319 # requested in §2.2, because except if there is a special arrangement with the
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
320 # server, a service at a sub-domain can't send message in the name of the main
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
321 # domain (e.g. "multicast.example.org" can't send message from
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
322 # "juliet@example.org"). So the specification is a bit dubious here, and we only
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
323 # use the main server multicast feature if it's present.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
324 if not await self.host.memory.disco.has_feature(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
325 client, NS_ADDRESS, client.server_jid
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
326 ):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
327 # No multicast service
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
328 log.warning(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
329 _(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
330 f"Server of {client.profile} does not support XEP-0033 "
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
331 f"({PLUGIN_INFO[C.PI_IMPORT_NAME]}). We will send all messages ourselves."
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
332 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
333 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
334 await self.deliver_messages(client, mess_data, data, domains)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
335 await self._stop_if_all_delivered(client, mess_data, data)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
336 else:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
337 # XXX: We delived ourself to multicast services because it's not correctly
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
338 # handled by some multicast services, notably by Prosody mod_addresses.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
339 # FIXME: Only do this workaround for known incomplete implementations.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
340 # TODO: remove this workaround when known implementations have been completed.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
341 if mess_data["to"] != client.server_jid:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
342 # We send the message to our server which will distribute it to the right
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
343 # locations. The initial ``to`` jid has been moved to ``data.to`` above.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
344 # FIXME: When sub-services issue is properly handler, a sub-service JID
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
345 # supporting multicast should be allowed here.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
346 mess_data["to"] = client.server_jid
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
347 await self.deliver_messages(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
348 client, mess_data, data, domains, multicast_only=True
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
349 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
350 await self._stop_if_all_delivered(client, mess_data, data)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
351
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
352 message_elt = mess_data["xml"]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
353 message_elt["to"] = str(mess_data["to"])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
354 message_elt.addChild(data.to_element())
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
355 return mess_data
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
356
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
357 async def deliver_messages(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
358 self,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
359 client,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
360 mess_data: MessageData,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
361 addr_data: AddressesData,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
362 domains: dict[str, list[AddressType]],
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
363 multicast_only: bool = False,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
364 ) -> None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
365 """Send messages to requested recipients.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
366
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
367 If a domain handles multicast, a single message will be send there.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
368 @param client: Client session.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
369 @param mess_data: Messsa data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
370 @param addr_data: XEP-0033 addresses data.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
371 @param domains: Domain to addresses map.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
372 Note that that the addresses instances in this argument must be the same as in
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
373 ``addr_data`` (There ``delivered`` status will be manipulated).
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
374 @param multicast_only: if True, only multicast domain will be delivered.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
375 """
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
376 # We'll modify delivered status, so we keep track here of addresses which have
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
377 # already be delivered.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
378 already_delivered = [a for a in addr_data.addresses if a.delivered]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
379 multicast_domains = set()
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
380 for domain, domain_addresses in domains.items():
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
381 if domain == client.server_jid.host:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
382
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
383 # ``client.server_jid`` is discarded to avoid sending twice the same
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
384 # message. ``multicast_only`` flag is set when the server supports
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
385 # multicast, so the message will be sent to it at the end of the workflow.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
386 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
387 if len(domain_addresses) > 1:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
388 # For domains with multiple recipients, we check if we they support
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
389 # multicast and so if we can deliver to them directly.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
390 if await self.host.memory.disco.has_feature(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
391 client, NS_ADDRESS, jid.JID(domain)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
392 ):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
393 multicast_domains.add(domain)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
394
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
395 # We remove bcc, they have a special handling.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
396 bcc = addr_data.bcc or []
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
397 addr_data.bcc = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
398
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
399 # Mark all addresses as "delivered" upfront, even if some won't actually be sent
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
400 # by us (when multicast_only is set). This flag signals to multicast services that
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
401 # they shouldn't handle these addresses. We'll remove the "delivered" status from
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
402 # undelivered addresses post-delivery.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
403 for address in addr_data.addresses:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
404 address.delivered = True
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
405
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
406 # First, we send multicast messages.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
407 for domain in multicast_domains:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
408 something_to_deliver = False
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
409 for address in domains[domain]:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
410 if address in already_delivered:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
411 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
412 # We need to mark as non delivered, so the multicast service will deliver
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
413 # itself.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
414 address.delivered = False
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
415 something_to_deliver = True
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
416
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
417 if not something_to_deliver:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
418 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
419
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
420 domain_bcc = [a for a in bcc if a.jid and a.jid.host == domain]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
421 message_elt = element_copy(mess_data["xml"])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
422 # The service must only see BCC from its own domain.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
423 addr_data.bcc = domain_bcc
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
424 message_elt.addChild(addr_data.to_element())
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
425 message_elt["to"] = domain
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
426 await client.a_send(message_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
427 for address in domains[domain] + domain_bcc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
428 # Those addresses have now been delivered.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
429 address.delivered = True
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
430
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
431 if multicast_only:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
432 # Only addresses from multicast domains must be marked as delivered.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
433 for address in addr_data.addresses:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
434 if (
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
435 address.jid is not None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
436 and address.jid.host not in multicast_domains
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
437 and address not in already_delivered
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
438 ):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
439 address.delivered = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
440
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
441 # We have delivered to all multicast services, we stop here.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
442 # But first we need to restore BCC, without the delivered ones.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
443 addr_data.bcc = [a for a in bcc if not a.delivered]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
444 return
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
445
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
446 # Then BCC
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
447 for address in bcc:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
448 if address in already_delivered:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
449 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
450 if address.jid is None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
451 raise NotImplementedError(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
452 f"Sending to non JID address is not supported yet"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
453 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
454 if address.jid.host in multicast_domains:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
455 # Address has already be handled by a multicast domain
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
456 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
457 message_elt = element_copy(mess_data["xml"])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
458 # The recipient must only get its own BCC
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
459 addr_data.bcc = [address]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
460 message_elt.addChild(addr_data.to_element())
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
461 message_elt["to"] = address.jid.full()
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
462 await client.a_send(message_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
463
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
464 # BCC address must be removed.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
465 addr_data.bcc = None
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
466
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
467 # and finally, other ones.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
468 message_elt = mess_data["xml"]
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
469 message_elt.addChild(addr_data.to_element())
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
470 non_bcc_addresses = (addr_data.to or []) + (addr_data.cc or [])
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
471 for address in non_bcc_addresses:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
472 if address in already_delivered:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
473 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
474 if address.jid is None:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
475 raise NotImplementedError(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
476 f"Sending to non JID address is not supported yet"
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
477 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
478 if address.jid.host in multicast_domains:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
479 # Multicast domains have already been delivered.
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
480 continue
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
481 message_elt["to"] = address.jid.full()
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
482 await client.a_send(message_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
483
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3913
diff changeset
484 def send_message_trigger(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
485 self, client, mess_data, pre_xml_treatments, post_xml_treatments
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
486 ) -> Literal[True]:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
487 """Process the XEP-0033 related data to be sent"""
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
488 post_xml_treatments.addCallback(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
489 lambda mess_data: defer.ensureDeferred(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
490 self._handle_addresses(client, mess_data)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
491 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
492 )
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
493 return True
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
494
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
495 def message_received_trigger(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
496 self,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
497 client: SatXMPPEntity,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
498 message_elt: domish.Element,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
499 post_treat: defer.Deferred,
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
500 ) -> Literal[True]:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
501 """Parse addresses information and add them to message data."""
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
502
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
503 try:
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
504 addresses = AddressesData.from_element(message_elt)
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
505 except exceptions.NotFound:
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
506 pass
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
507 else:
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
508
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
509 def post_treat_addr(mess_data: MessageData):
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
510 mess_data["extra"]["addresses"] = addresses.model_dump(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
511 mode="json", exclude_none=True
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
512 )
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
513 return mess_data
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
514
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
515 post_treat.addCallback(post_treat_addr)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
516 return True
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
517
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3913
diff changeset
518 def get_handler(self, client):
4313
530f86f078cc plugin XEP-0033: formatting.
Goffi <goffi@goffi.org>
parents: 4306
diff changeset
519 return XEP_0033_handler()
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
520
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
521
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
522 @implementer(iwokkel.IDisco)
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
523 class XEP_0033_handler(XMPPHandler):
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
524
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
525 def getDiscoInfo(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
526 self, requestor: jid.JID, target: jid.JID, nodeIdentifier: str = ""
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
527 ) -> list[disco.DiscoFeature]:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
528 return [disco.DiscoFeature(NS_ADDRESS)]
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
529
4306
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
530 def getDiscoItems(
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
531 self, requestor: jid.JID, target: jid.JID, nodeIdentifier: str = ""
94e0968987cd plugin XEP-0033: code modernisation, improve delivery, data validation:
Goffi <goffi@goffi.org>
parents: 4270
diff changeset
532 ) -> list[disco.DiscoItem]:
742
03744d9ebc13 plugin XEP-0033: implementation of the addressing feature:
souliane <souliane@mailoo.org>
parents:
diff changeset
533 return []