Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0358.py @ 4335:430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
rel 453
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Dec 2024 00:13:07 +0100 |
parents | |
children |
rev | line source |
---|---|
4335
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia plugin to jingle session publishing. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from typing import TYPE_CHECKING, Self |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from pydantic import BaseModel, Field |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from twisted.words.protocols.jabber import jid |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from twisted.words.protocols.jabber.xmlstream import XMPPHandler |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from twisted.words.xish import domish |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from wokkel import disco, iwokkel |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from zope.interface import implementer |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from libervia.backend.core import exceptions |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from libervia.backend.core.constants import Const as C |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from libervia.backend.core.core_types import SatXMPPEntity |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from libervia.backend.core.i18n import _ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from libervia.backend.core.log import getLogger |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from libervia.backend.models.types import DomishElementType, JIDType |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 if TYPE_CHECKING: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 from libervia.backend.core.main import LiberviaBackend |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 log = getLogger(__name__) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 PLUGIN_INFO = { |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 C.PI_NAME: "Publishing Available Jingle Sessions", |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_IMPORT_NAME: "XEP-0358", |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 C.PI_TYPE: "XEP", |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 C.PI_MODES: C.PLUG_MODE_BOTH, |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 C.PI_PROTOCOLS: [], |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 C.PI_DEPENDENCIES: [ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 "XEP-0234", |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 ], |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 C.PI_RECOMMENDATIONS: [], |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 C.PI_MAIN: "XEP_0358", |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 C.PI_HANDLER: "yes", |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 C.PI_DESCRIPTION: _("""Indicate available Jingle sessions."""), |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 } |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 NS_JINGLEPUB = "urn:xmpp:jinglepub:1" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 class Meta(BaseModel): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 """Model for meta element in JinglePub element.""" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 lang: str | None = Field(None, description="The language of the meta data.") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 title: str = Field(description="The title of the meta data.") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 summary: str | None = Field(None, description="A summary of the meta data.") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def to_element(self) -> domish.Element: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 """Build the <meta> element from this instance's data. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 @return: <meta> element. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 """ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 meta_elt = domish.Element((NS_JINGLEPUB, "meta")) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 if self.lang: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 meta_elt["xml:lang"] = self.lang |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 meta_elt["title"] = self.title |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 if self.summary: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 meta_elt["summary"] = self.summary |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 return meta_elt |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 @classmethod |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 def from_element(cls, meta_elt: domish.Element) -> Self: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 """Create a Meta instance from a <meta> element. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 @param meta_elt: The <meta> element. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 @return: Meta instance. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 """ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 assert meta_elt.name == "meta" and meta_elt.uri == NS_JINGLEPUB |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 kwargs = {} |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 if meta_elt.hasAttribute("xml:lang"): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 kwargs["lang"] = meta_elt["xml:lang"] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 if meta_elt.hasAttribute("title"): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 kwargs["title"] = meta_elt["title"] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 if meta_elt.hasAttribute("summary"): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 kwargs["summary"] = meta_elt["summary"] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 return cls(**kwargs) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 class JinglePub(BaseModel): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 """Model for JinglePub element.""" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 from_jid: JIDType = Field(description="The JID of the session owner.") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 id: str = Field(description="The jinglepub identifier.") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 uri: str | None = Field( |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 default=None, description="An alternate or informational URI of the content." |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 ) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 meta: list[Meta] = Field( |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 default_factory=list, description="Human-friendly information about the session." |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 ) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 descriptions: list[DomishElementType] = Field( |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 default_factory=list, description="Application format(s) for the Jingle session." |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 ) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 def set_attributes(self, jinglepub_elt: domish.Element) -> None: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 """Set <jinglepub> element attributes from this instance's data.""" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 jinglepub_elt["from"] = str(self.from_jid) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 jinglepub_elt["id"] = self.id |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 def set_children(self, jinglepub_elt: domish.Element) -> None: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 """Set <jinglepub> element children from this instance's data.""" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 if self.uri: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 uri_elt = jinglepub_elt.addElement((NS_JINGLEPUB, "uri")) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 uri_elt.addContent(self.uri) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 for meta in self.meta: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 jinglepub_elt.addChild(meta.to_element()) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 for description in self.descriptions: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 jinglepub_elt.addChild(description) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 def to_element(self) -> domish.Element: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 """Build the <jinglepub> element from this instance's data. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 @return: <jinglepub> element. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 """ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 jinglepub_elt = domish.Element((NS_JINGLEPUB, "jinglepub")) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 self.set_attributes(jinglepub_elt) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 self.set_children(jinglepub_elt) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 return jinglepub_elt |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 @classmethod |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 def from_element(cls, element: domish.Element) -> Self: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 """Create a JinglePub instance from a <jinglepub> element. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 @param jinglepub_elt: The <jinglepub> element. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 @return: JinglePub instance. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 @raise exceptions.NotFound: If the <jinglepub> element is not found. |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 """ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 if element.uri != NS_JINGLEPUB or element.name != "jinglepub": |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 raise exceptions.NotFound("<jinglepub> element not found") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 kwargs = {} |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 try: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 kwargs["from_jid"] = jid.JID(element["from"]) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 except RuntimeError as e: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 log.warning(f"Can't parse from_jid {e}: {element.toXml()}") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 raise exceptions.NotFound("<jinglepub> element has invalid 'from' attribute") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 if element.hasAttribute("id"): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 kwargs["id"] = element["id"] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 uri_elt = next(element.elements(NS_JINGLEPUB, "uri"), None) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 if uri_elt: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 kwargs["uri"] = str(uri_elt) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 kwargs["meta"] = [ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 Meta.from_element(meta_elt) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 for meta_elt in element.elements(NS_JINGLEPUB, "meta") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 ] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 kwargs["descriptions"] = [ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 child |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 for child in element.elements() |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 if child.uri != NS_JINGLEPUB and child.name == "description" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 ] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 return cls(**kwargs) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 class XEP_0358: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 namespace = NS_JINGLEPUB |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 def __init__(self, host: "LiberviaBackend") -> None: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 log.info(f"plugin {PLUGIN_INFO[C.PI_NAME]!r} initialization") |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 self.host = host |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 host.register_namespace("jinglepub", NS_JINGLEPUB) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 def get_handler(self, client: SatXMPPEntity) -> XMPPHandler: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 return JinglePubHandler(self) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 @implementer(iwokkel.IDisco) |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 class JinglePubHandler(XMPPHandler): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 def __init__(self, plugin_parent): |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 self.plugin_parent = plugin_parent |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 def getDiscoInfo( |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 self, requestor: jid.JID, target: jid.JID, nodeIdentifier: str = "" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 ) -> list[disco.DiscoFeature]: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 return [ |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 disco.DiscoFeature(NS_JINGLEPUB), |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 ] |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 def getDiscoItems( |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 self, requestor: jid.JID, target: jid.JID, nodeIdentifier: str = "" |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 ) -> list[disco.DiscoItems]: |
430d5d99a740
plugin XEP-0358: "Publishing Available Jingle Sessions" implementation:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 return [] |