annotate sat/plugins/plugin_xep_0329.py @ 3529:698579bedd6f

component file sharing (plugin management): new command to get available quota/used space.
author Goffi <goffi@goffi.org>
date Wed, 05 May 2021 15:37:33 +0200
parents e47aa1fb7b24
children 888109774673 04283582966f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1 #!/usr/bin/env python3
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # SAT plugin for File Information Sharing (XEP-0329)
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3402
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
19 import mimetypes
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
20 import json
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
21 import os
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
22 from pathlib import Path
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
23 from typing import Optional, Dict
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
24 from zope.interface import implementer
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import xmlstream
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.words.protocols.jabber import jid
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.words.protocols.jabber import error as jabber_error
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.internet import defer
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
29 from wokkel import disco, iwokkel, data_form
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
30 from sat.core.i18n import _
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
31 from sat.core.xmpp import SatXMPPEntity
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
32 from sat.core import exceptions
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
33 from sat.core.constants import Const as C
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
34 from sat.core.log import getLogger
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
35 from sat.tools import stream
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
36 from sat.tools.common import regex
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
39 log = getLogger(__name__)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
40
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 PLUGIN_INFO = {
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_NAME: "File Information Sharing",
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_IMPORT_NAME: "XEP-0329",
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 C.PI_TYPE: "XEP",
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 C.PI_MODES: C.PLUG_MODE_BOTH,
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 C.PI_PROTOCOLS: ["XEP-0329"],
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
47 C.PI_DEPENDENCIES: ["XEP-0231", "XEP-0234", "XEP-0300", "XEP-0106"],
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 C.PI_MAIN: "XEP_0329",
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 C.PI_HANDLER: "yes",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
50 C.PI_DESCRIPTION: _("""Implementation of File Information Sharing"""),
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 }
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
53 NS_FIS = "urn:xmpp:fis:0"
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
54 NS_FIS_AFFILIATION = "org.salut-a-toi.fis-affiliation"
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
55 NS_FIS_CONFIGURATION = "org.salut-a-toi.fis-configuration"
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
56 NS_FIS_CREATE = "org.salut-a-toi.fis-create"
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
58 IQ_FIS_REQUEST = f'{C.IQ_GET}/query[@xmlns="{NS_FIS}"]'
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
59 # not in the standard, but needed, and it's handy to keep it here
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
60 IQ_FIS_AFFILIATION_GET = f'{C.IQ_GET}/affiliations[@xmlns="{NS_FIS_AFFILIATION}"]'
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
61 IQ_FIS_AFFILIATION_SET = f'{C.IQ_SET}/affiliations[@xmlns="{NS_FIS_AFFILIATION}"]'
3321
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
62 IQ_FIS_CONFIGURATION_GET = f'{C.IQ_GET}/configuration[@xmlns="{NS_FIS_CONFIGURATION}"]'
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
63 IQ_FIS_CONFIGURATION_SET = f'{C.IQ_SET}/configuration[@xmlns="{NS_FIS_CONFIGURATION}"]'
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
64 IQ_FIS_CREATE_DIR = f'{C.IQ_SET}/dir[@xmlns="{NS_FIS_CREATE}"]'
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
65 SINGLE_FILES_DIR = "files"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
66 TYPE_VIRTUAL = "virtual"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
67 TYPE_PATH = "path"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
68 SHARE_TYPES = (TYPE_PATH, TYPE_VIRTUAL)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
69 KEY_TYPE = "type"
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
71
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
72 class RootPathException(Exception):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
73 """Root path is requested"""
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
74
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
75
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 class ShareNode(object):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
77 """Node containing directory or files to share, virtual or real"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
78
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 host = None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
80
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def __init__(self, name, parent, type_, access, path=None):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 assert type_ in SHARE_TYPES
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 if name is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
84 if name == ".." or "/" in name or "\\" in name:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
85 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
86 _("path change chars found in name [{name}], hack attempt?").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
87 name=name
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
88 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
89 )
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
90 if name == "..":
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
91 name = "--"
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 else:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 name = regex.pathEscape(name)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 self.name = name
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 self.children = {}
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.type = type_
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 self.access = {} if access is None else access
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 assert isinstance(self.access, dict)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 self.parent = None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 if parent is not None:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 assert name
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 parent.addChild(self)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 else:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 assert name is None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 if path is not None:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 if type_ != TYPE_PATH:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
107 raise exceptions.InternalError(_("path can only be set on path nodes"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self._path = path
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 @property
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def path(self):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 return self._path
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
113
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 def __getitem__(self, key):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 return self.children[key]
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def __contains__(self, item):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 return self.children.__contains__(item)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 def __iter__(self):
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 return self.children.__iter__()
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
122
3032
95e2fd14a761 plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
123 def items(self):
95e2fd14a761 plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
124 return self.children.items()
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
3032
95e2fd14a761 plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
126 def values(self):
95e2fd14a761 plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
127 return self.children.values()
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 def getOrCreate(self, name, type_=TYPE_VIRTUAL, access=None):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
130 """Get a node or create a virtual node and return it"""
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 if access is None:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 access = {C.ACCESS_PERM_READ: {KEY_TYPE: C.ACCESS_TYPE_PUBLIC}}
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 try:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 return self.children[name]
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 except KeyError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 node = ShareNode(name, self, type_=type_, access=access)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 return node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
138
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def addChild(self, node):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 if node.parent is not None:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
141 raise exceptions.ConflictError(_("a node can't have several parents"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 node.parent = self
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 self.children[node.name] = node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 def removeFromParent(self):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 try:
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
147 del self.parent.children[self.name]
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 except TypeError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
149 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
150 "trying to remove a node from inexisting parent"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
151 )
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
152 except KeyError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
153 raise exceptions.InternalError("node not found in parent's children")
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
154 self.parent = None
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 def _checkNodePermission(self, client, node, perms, peer_jid):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 """Check access to this node for peer_jid
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
158
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 @param node(SharedNode): node to check access
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 @param perms(unicode): permissions to check, iterable of C.ACCESS_PERM_*
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 @param peer_jid(jid.JID): entity which try to access the node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 @return (bool): True if entity can access
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
164 file_data = {"access": self.access, "owner": client.jid.userhostJID()}
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 try:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 self.host.memory.checkFilePermission(file_data, peer_jid, perms)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 except exceptions.PermissionError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 return False
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 else:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 return True
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
171
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
172 def checkPermissions(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
173 self, client, peer_jid, perms=(C.ACCESS_PERM_READ,), check_parents=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
174 ):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
175 """Check that peer_jid can access this node and all its parents
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
176
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 @param peer_jid(jid.JID): entrity trying to access the node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 @param perms(unicode): permissions to check, iterable of C.ACCESS_PERM_*
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
179 @param check_parents(bool): if True, access of all parents of this node will be
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
180 checked too
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 @return (bool): True if entity can access this node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 """
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 peer_jid = peer_jid.userhostJID()
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 if peer_jid == client.jid.userhostJID():
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 return True
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 parent = self
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 while parent != None:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 if not self._checkNodePermission(client, parent, perms, peer_jid):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 return False
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 parent = parent.parent
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
192
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 return True
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
194
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 @staticmethod
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 def find(client, path, peer_jid, perms=(C.ACCESS_PERM_READ,)):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 """find node corresponding to a path
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 @param path(unicode): path to the requested file or directory
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 @param peer_jid(jid.JID): entity trying to find the node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 used to check permission
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 @return (dict, unicode): shared data, remaining path
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 @raise exceptions.PermissionError: user can't access this file
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 @raise exceptions.DataError: path is invalid
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 @raise NotFound: path lead to a non existing file/directory
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 """
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
207 path_elts = [_f for _f in path.split("/") if _f]
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
209 if ".." in path_elts:
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
210 log.warning(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
211 'parent dir ("..") found in path, hack attempt? path is {path} '
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
212 '[{profile}]').format(path=path, profile=client.profile))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
213 raise exceptions.PermissionError("illegal path elements")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
214
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 node = client._XEP_0329_root_node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 while path_elts:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 if node.type == TYPE_VIRTUAL:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 try:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 node = node[path_elts.pop(0)]
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 except KeyError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 raise exceptions.NotFound
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 elif node.type == TYPE_PATH:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 break
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
225
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
226 if not node.checkPermissions(client, peer_jid, perms=perms):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
227 raise exceptions.PermissionError("permission denied")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
228
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
229 return node, "/".join(path_elts)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
230
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 def findByLocalPath(self, path):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 """retrieve nodes linking to local path
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 @return (list[ShareNode]): found nodes associated to path
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
235 @raise exceptions.NotFound: no node has been found with this path
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 """
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
237 shared_paths = self.getSharedPaths()
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
238 try:
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
239 return shared_paths[path]
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 except KeyError:
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
241 raise exceptions.NotFound
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
243 def _getSharedPaths(self, node, paths):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 if node.type == TYPE_VIRTUAL:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
245 for node in node.values():
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
246 self._getSharedPaths(node, paths)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
247 elif node.type == TYPE_PATH:
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
248 paths.setdefault(node.path, []).append(node)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
249 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
250 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
251 "unknown node type: {type}".format(type=node.type)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
252 )
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
253
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
254 def getSharedPaths(self):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
255 """retrieve nodes by shared path
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
256
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
257 this method will retrieve recursively shared path in children of this node
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
258 @return (dict): map from shared path to list of nodes
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
259 """
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
260 if self.type == TYPE_PATH:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
261 raise exceptions.InternalError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
262 "getSharedPaths must be used on a virtual node"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
263 )
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
264 paths = {}
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
265 self._getSharedPaths(self, paths)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
266 return paths
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
267
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
268
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 class XEP_0329(object):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 def __init__(self, host):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 log.info(_("File Information Sharing initialization"))
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 self.host = host
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 ShareNode.host = host
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
274 self._b = host.plugins["XEP-0231"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
275 self._h = host.plugins["XEP-0300"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
276 self._jf = host.plugins["XEP-0234"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
277 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
278 "FISList",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
279 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
280 in_sign="ssa{ss}s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
281 out_sign="aa{ss}",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
282 method=self._listFiles,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
283 async_=True,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
284 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
285 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
286 "FISLocalSharesGet",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
287 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
288 in_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
289 out_sign="as",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
290 method=self._localSharesGet,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
291 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
292 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
293 "FISSharePath",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
294 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
295 in_sign="ssss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
296 out_sign="s",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
297 method=self._sharePath,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
298 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
299 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
300 "FISUnsharePath",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
301 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
302 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
303 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
304 method=self._unsharePath,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
305 )
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
306 host.bridge.addMethod(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
307 "FISAffiliationsGet",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
308 ".plugin",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
309 in_sign="ssss",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
310 out_sign="a{ss}",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
311 method=self._affiliationsGet,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
312 async_=True,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
313 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
314 host.bridge.addMethod(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
315 "FISAffiliationsSet",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
316 ".plugin",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
317 in_sign="sssa{ss}s",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
318 out_sign="",
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
319 method=self._affiliationsSet,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
320 async_=True,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
321 )
3321
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
322 host.bridge.addMethod(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
323 "FISConfigurationGet",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
324 ".plugin",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
325 in_sign="ssss",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
326 out_sign="a{ss}",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
327 method=self._configurationGet,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
328 async_=True,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
329 )
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
330 host.bridge.addMethod(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
331 "FISConfigurationSet",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
332 ".plugin",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
333 in_sign="sssa{ss}s",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
334 out_sign="",
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
335 method=self._configurationSet,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
336 async_=True,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
337 )
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
338 host.bridge.addMethod(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
339 "FISCreateDir",
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
340 ".plugin",
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
341 in_sign="sssa{ss}s",
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
342 out_sign="",
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
343 method=self._createDir,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
344 async_=True,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
345 )
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
346 host.bridge.addSignal("FISSharedPathNew", ".plugin", signature="sss")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
347 host.bridge.addSignal("FISSharedPathRemoved", ".plugin", signature="ss")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 host.trigger.add("XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
349 host.registerNamespace("fis", NS_FIS)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
350
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 def getHandler(self, client):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 return XEP_0329_handler(self)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
353
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 def profileConnected(self, client):
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
355 if client.is_component:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
356 client._file_sharing_allowed_hosts = self.host.memory.getConfig(
3402
08a3e34aead1 plugin XEP-0329: minor reformatting
Goffi <goffi@goffi.org>
parents: 3366
diff changeset
357 'component file_sharing',
08a3e34aead1 plugin XEP-0329: minor reformatting
Goffi <goffi@goffi.org>
parents: 3366
diff changeset
358 'http_upload_allowed_hosts_list') or [client.host]
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
359 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
360 client._XEP_0329_root_node = ShareNode(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
361 None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
362 None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
363 TYPE_VIRTUAL,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
364 {C.ACCESS_PERM_READ: {KEY_TYPE: C.ACCESS_TYPE_PUBLIC}},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
365 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
366 client._XEP_0329_names_data = {} #  name to share map
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
367
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
368 def _fileSendingRequestTrigger(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
369 self, client, session, content_data, content_name, file_data, file_elt
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
370 ):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
371 """This trigger check that a requested file is available, and fill suitable data
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
372
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
373 Path and name are used to retrieve the file. If path is missing, we try our luck
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
374 with known names
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 """
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 if client.is_component:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 return True, None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
378
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
380 name = file_data["name"]
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 except KeyError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 return True, None
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
383 assert "/" not in name
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
384
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
385 path = file_data.get("path")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 if path is not None:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 # we have a path, we can follow it to find node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
389 node, rem_path = ShareNode.find(client, path, session["peer_jid"])
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 except (exceptions.PermissionError, exceptions.NotFound):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
391 #  no file, or file not allowed, we continue normal workflow
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 return True, None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
393 except exceptions.DataError:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
394 log.warning(_("invalid path: {path}").format(path=path))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 return True, None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
396
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
397 if node.type == TYPE_VIRTUAL:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
398 # we have a virtual node, so name must link to a path node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 try:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
400 path = node[name].path
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
401 except KeyError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 return True, None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
403 elif node.type == TYPE_PATH:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 # we have a path node, so we can retrieve the full path now
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
405 path = os.path.join(node.path, rem_path, name)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
406 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
407 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
408 "unknown type: {type}".format(type=node.type)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
409 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
410 if not os.path.exists(path):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
411 return True, None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
412 size = os.path.getsize(path)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
413 else:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 # we don't have the path, we try to find the file by its name
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
415 try:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
416 name_data = client._XEP_0329_names_data[name]
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
417 except KeyError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
418 return True, None
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
419
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
420 for path, shared_file in name_data.items():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
421 if True: #  FIXME: filters are here
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
422 break
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 else:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
424 return True, None
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
425 parent_node = shared_file["parent"]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
426 if not parent_node.checkPermissions(client, session["peer_jid"]):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
427 log.warning(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
428 _(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
429 "{peer_jid} requested a file (s)he can't access [{profile}]"
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
430 ).format(peer_jid=session["peer_jid"], profile=client.profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
431 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
432 return True, None
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
433 size = shared_file["size"]
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
434
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
435 file_data["size"] = size
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
436 file_elt.addElement("size", content=str(size))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
437 hash_algo = file_data["hash_algo"] = self._h.getDefaultAlgo()
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
438 hasher = file_data["hash_hasher"] = self._h.getHasher(hash_algo)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
439 file_elt.addChild(self._h.buildHashUsedElt(hash_algo))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
440 content_data["stream_object"] = stream.FileStreamObject(
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
441 self.host,
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
442 client,
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
443 path,
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
444 uid=self._jf.getProgressId(session, content_name),
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
445 size=size,
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
446 data_cb=lambda data: hasher.update(data),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
447 )
3516
e47aa1fb7b24 plugin XEP-0329: fix root node retrieval and `_fileSendingRequestTrigger` return value
Goffi <goffi@goffi.org>
parents: 3500
diff changeset
448 return False, defer.succeed(True)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
449
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
450 # common methods
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
451
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
452 def _requestHandler(self, client, iq_elt, root_nodes_cb, files_from_node_cb):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
453 iq_elt.handled = True
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
454 node = iq_elt.query.getAttribute("node")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
455 if not node:
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
456 d = defer.maybeDeferred(root_nodes_cb, client, iq_elt)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
457 else:
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
458 d = defer.maybeDeferred(files_from_node_cb, client, iq_elt, node)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
459 d.addErrback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
460 lambda failure_: log.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
461 _("error while retrieving files: {msg}").format(msg=failure_)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
462 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
463 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
464
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
465 def _iqError(self, client, iq_elt, condition="item-not-found"):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
466 error_elt = jabber_error.StanzaError(condition).toResponse(iq_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
467 client.send(error_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
468
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
469 #  client
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
470
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
471 def _addPathData(self, client, query_elt, path, parent_node):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
472 """Fill query_elt with files/directories found in path"""
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
473 name = os.path.basename(path)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
474 if os.path.isfile(path):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
475 size = os.path.getsize(path)
2512
025afb04c10b plugin XEP-0234: some cleaning + added triggers to allow plugins to change parsing/generation of <file> element
Goffi <goffi@goffi.org>
parents: 2503
diff changeset
476 mime_type = mimetypes.guess_type(path, strict=False)[0]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
477 file_elt = self._jf.buildFileElement(
3314
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
478 client=client, name=name, size=size, mime_type=mime_type,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
479 modified=os.path.getmtime(path)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
480 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
481
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 query_elt.addChild(file_elt)
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
483 # we don't specify hash as it would be too resource intensive to calculate
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
484 # it for all files.
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
485 # we add file to name_data, so users can request it later
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
486 name_data = client._XEP_0329_names_data.setdefault(name, {})
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 if path not in name_data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
488 name_data[path] = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
489 "size": size,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
490 "mime_type": mime_type,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
491 "parent": parent_node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
492 }
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
493 else:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
494 # we have a directory
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
495 directory_elt = query_elt.addElement("directory")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
496 directory_elt["name"] = name
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
497
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 def _pathNodeHandler(self, client, iq_elt, query_elt, node, path):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 """Fill query_elt for path nodes, i.e. physical directories"""
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 path = os.path.join(node.path, path)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
501
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
502 if not os.path.exists(path):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
503 # path may have been moved since it has been shared
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
504 return self._iqError(client, iq_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
505 elif os.path.isfile(path):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
506 self._addPathData(client, query_elt, path, node)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
508 for name in sorted(os.listdir(path.encode("utf-8")), key=lambda n: n.lower()):
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
509 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
510 name = name.decode("utf-8", "strict")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
511 except UnicodeDecodeError as e:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
512 log.warning(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
513 _("ignoring invalid unicode name ({name}): {msg}").format(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
514 name=name.decode("utf-8", "replace"), msg=e
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
515 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
516 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
517 continue
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
518 full_path = os.path.join(path, name)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 self._addPathData(client, query_elt, full_path, node)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
520
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
521 def _virtualNodeHandler(self, client, peer_jid, iq_elt, query_elt, node):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
522 """Fill query_elt for virtual nodes"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
523 for name, child_node in node.items():
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
524 if not child_node.checkPermissions(client, peer_jid, check_parents=False):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
525 continue
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
526 node_type = child_node.type
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
527 if node_type == TYPE_VIRTUAL:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
528 directory_elt = query_elt.addElement("directory")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
529 directory_elt["name"] = name
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
530 elif node_type == TYPE_PATH:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
531 self._addPathData(client, query_elt, child_node.path, child_node)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
532 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
533 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
534 _("unexpected type: {type}").format(type=node_type)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
535 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
536
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
537 def _getRootNodesCb(self, client, iq_elt):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
538 peer_jid = jid.JID(iq_elt["from"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
539 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
540 query_elt = iq_result_elt.addElement((NS_FIS, "query"))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
541 for name, node in client._XEP_0329_root_node.items():
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
542 if not node.checkPermissions(client, peer_jid, check_parents=False):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
543 continue
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
544 directory_elt = query_elt.addElement("directory")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
545 directory_elt["name"] = name
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
546 client.send(iq_result_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
547
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
548 def _getFilesFromNodeCb(self, client, iq_elt, node_path):
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
549 """Main method to retrieve files/directories from a node_path"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
550 peer_jid = jid.JID(iq_elt["from"])
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
551 try:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
552 node, path = ShareNode.find(client, node_path, peer_jid)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
553 except (exceptions.PermissionError, exceptions.NotFound):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
554 return self._iqError(client, iq_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
555 except exceptions.DataError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
556 return self._iqError(client, iq_elt, condition="not-acceptable")
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
557
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
558 node_type = node.type
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
559 peer_jid = jid.JID(iq_elt["from"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
560 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
561 query_elt = iq_result_elt.addElement((NS_FIS, "query"))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
562 query_elt["node"] = node_path
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
563
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
564 # we now fill query_elt according to node_type
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
565 if node_type == TYPE_PATH:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
566 #  it's a physical path
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
567 self._pathNodeHandler(client, iq_elt, query_elt, node, path)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
568 elif node_type == TYPE_VIRTUAL:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
569 assert not path
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
570 self._virtualNodeHandler(client, peer_jid, iq_elt, query_elt, node)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
571 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
572 raise exceptions.InternalError(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
573 _("unknown node type: {type}").format(type=node_type)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
574 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
575
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
576 client.send(iq_result_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
577
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
578 def onRequest(self, iq_elt, client):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
579 return self._requestHandler(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
580 client, iq_elt, self._getRootNodesCb, self._getFilesFromNodeCb
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
581 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
582
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
583 # Component
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
584
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
585 def _compParseJids(self, client, iq_elt):
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
586 """Retrieve peer_jid and owner to use from IQ stanza
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
587
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
588 @param iq_elt(domish.Element): IQ stanza of the FIS request
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
589 @return (tuple[jid.JID, jid.JID]): peer_jid and owner
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
590 """
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
591
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
592 @defer.inlineCallbacks
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
593 def _compGetRootNodesCb(self, client, iq_elt):
3366
e09cb08166a3 plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents: 3365
diff changeset
594 peer_jid, owner = client.getOwnerAndPeer(iq_elt)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
595 files_data = yield self.host.memory.getFiles(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
596 client,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
597 peer_jid=peer_jid,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
598 parent="",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
599 type_=C.FILE_TYPE_DIRECTORY,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
600 owner=owner,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
601 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
602 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
603 query_elt = iq_result_elt.addElement((NS_FIS, "query"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
604 for file_data in files_data:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
605 name = file_data["name"]
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
606 directory_elt = query_elt.addElement("directory")
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
607 directory_elt["name"] = name
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
608 client.send(iq_result_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
609
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
610 @defer.inlineCallbacks
2923
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
611 def _compGetFilesFromNodeCb(self, client, iq_elt, node_path):
1fd3ecb3351a plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents: 2909
diff changeset
612 """Retrieve files from local files repository according to permissions
2528
65e278997715 component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
613
65e278997715 component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
614 result stanza is then built and sent to requestor
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
615 @trigger XEP-0329_compGetFilesFromNode(client, iq_elt, owner, node_path,
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
616 files_data):
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
617 can be used to add data/elements
2528
65e278997715 component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
618 """
3366
e09cb08166a3 plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents: 3365
diff changeset
619 peer_jid, owner = client.getOwnerAndPeer(iq_elt)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
620 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
621 files_data = yield self.host.memory.getFiles(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
622 client, peer_jid=peer_jid, path=node_path, owner=owner
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
623 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
624 except exceptions.NotFound:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
625 self._iqError(client, iq_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
626 return
2937
db0890c9c7db plugin XEP-0329: correctly handle error if something is wrong when getting file from component.
Goffi <goffi@goffi.org>
parents: 2923
diff changeset
627 except exceptions.PermissionError:
db0890c9c7db plugin XEP-0329: correctly handle error if something is wrong when getting file from component.
Goffi <goffi@goffi.org>
parents: 2923
diff changeset
628 self._iqError(client, iq_elt, condition='not-allowed')
db0890c9c7db plugin XEP-0329: correctly handle error if something is wrong when getting file from component.
Goffi <goffi@goffi.org>
parents: 2923
diff changeset
629 return
db0890c9c7db plugin XEP-0329: correctly handle error if something is wrong when getting file from component.
Goffi <goffi@goffi.org>
parents: 2923
diff changeset
630 except Exception as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
631 log.error("internal server error: {e}".format(e=e))
2937
db0890c9c7db plugin XEP-0329: correctly handle error if something is wrong when getting file from component.
Goffi <goffi@goffi.org>
parents: 2923
diff changeset
632 self._iqError(client, iq_elt, condition='internal-server-error')
db0890c9c7db plugin XEP-0329: correctly handle error if something is wrong when getting file from component.
Goffi <goffi@goffi.org>
parents: 2923
diff changeset
633 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
634 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
635 query_elt = iq_result_elt.addElement((NS_FIS, "query"))
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
636 query_elt["node"] = node_path
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
637 if not self.host.trigger.point(
3314
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
638 "XEP-0329_compGetFilesFromNode",
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
639 client,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
640 iq_elt,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
641 iq_result_elt,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
642 owner,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
643 node_path,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
644 files_data
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
645 ):
2528
65e278997715 component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents: 2527
diff changeset
646 return
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
647 for file_data in files_data:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
648 if file_data['type'] == C.FILE_TYPE_DIRECTORY:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
649 directory_elt = query_elt.addElement("directory")
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
650 directory_elt['name'] = file_data['name']
3314
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
651 self.host.trigger.point(
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
652 "XEP-0329_compGetFilesFromNode_build_directory",
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
653 client,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
654 file_data,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
655 directory_elt,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
656 owner,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
657 node_path,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
658 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
659 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
660 file_elt = self._jf.buildFileElementFromDict(
3314
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
661 client,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
662 file_data,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
663 modified=file_data.get("modified", file_data["created"])
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
664 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
665 query_elt.addChild(file_elt)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
666 client.send(iq_result_elt)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
667
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
668 def onComponentRequest(self, iq_elt, client):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
669 return self._requestHandler(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
670 client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
671 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
672
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
673 async def _parseResult(self, client, peer_jid, iq_elt):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
674 query_elt = next(iq_elt.elements(NS_FIS, "query"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
675 files = []
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
676
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
677 for elt in query_elt.elements():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
678 if elt.name == "file":
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
679 # we have a file
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
680 try:
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
681 file_data = await self._jf.parseFileElement(client, elt)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
682 except exceptions.DataError:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
683 continue
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
684 file_data["type"] = C.FILE_TYPE_FILE
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
685 try:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
686 thumbs = file_data['extra'][C.KEY_THUMBNAILS]
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
687 except KeyError:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
688 log.debug(f"No thumbnail found for {file_data}")
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
689 else:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
690 for thumb in thumbs:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
691 if 'url' not in thumb and "id" in thumb:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
692 try:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
693 file_path = await self._b.getFile(client, peer_jid, thumb['id'])
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
694 except Exception as e:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
695 log.warning(f"Can't get thumbnail {thumb['id']!r} for {file_data}: {e}")
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
696 else:
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
697 thumb['filename'] = file_path.name
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
698
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
699 elif elt.name == "directory" and elt.uri == NS_FIS:
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
700 # we have a directory
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
701
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
702 file_data = {"name": elt["name"], "type": C.FILE_TYPE_DIRECTORY}
3314
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
703 self.host.trigger.point(
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
704 "XEP-0329_parseResult_directory",
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
705 client,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
706 elt,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
707 file_data,
5887fb414758 component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
708 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
709 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
710 log.warning(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
711 _(f"unexpected element, ignoring: {elt.toXml()}")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
712 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
713 continue
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
714 files.append(file_data)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
715 return files
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
716
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
717 # affiliations #
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
718
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
719 async def _parseElement(self, client, iq_elt, element, namespace):
3366
e09cb08166a3 plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents: 3365
diff changeset
720 peer_jid, owner = client.getOwnerAndPeer(iq_elt)
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
721 elt = next(iq_elt.elements(namespace, element))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
722 path = Path("/", elt['path'])
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
723 if len(path.parts) < 2:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
724 raise RootPathException
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
725 namespace = elt.getAttribute('namespace')
3360
57afccb91961 plugin XEP-0329: typo
Goffi <goffi@goffi.org>
parents: 3359
diff changeset
726 files_data = await self.host.memory.getFiles(
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
727 client,
3365
626046010a2d plugin XEP-0329: fix filtering by owner on components
Goffi <goffi@goffi.org>
parents: 3362
diff changeset
728 peer_jid=peer_jid,
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
729 path=str(path.parent),
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
730 name=path.name,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
731 namespace=namespace,
3365
626046010a2d plugin XEP-0329: fix filtering by owner on components
Goffi <goffi@goffi.org>
parents: 3362
diff changeset
732 owner=owner,
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
733 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
734 if len(files_data) != 1:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
735 client.sendError(iq_elt, 'item-not-found')
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
736 raise exceptions.CancelError
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
737 file_data = files_data[0]
3365
626046010a2d plugin XEP-0329: fix filtering by owner on components
Goffi <goffi@goffi.org>
parents: 3362
diff changeset
738 return peer_jid, elt, path, namespace, file_data
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
739
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
740 def _affiliationsGet(self, service_jid_s, namespace, path, profile):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
741 client = self.host.getClient(profile)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
742 service = jid.JID(service_jid_s)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
743 d = defer.ensureDeferred(self.affiliationsGet(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
744 client, service, namespace or None, path))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
745 d.addCallback(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
746 lambda affiliations: {
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
747 str(entity): affiliation for entity, affiliation in affiliations.items()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
748 }
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
749 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
750 return d
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
751
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
752 async def affiliationsGet(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
753 self,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
754 client: SatXMPPEntity,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
755 service: jid.JID,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
756 namespace: Optional[str],
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
757 path: str
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
758 ) -> Dict[jid.JID, str]:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
759 if not path:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
760 raise ValueError(f"invalid path: {path!r}")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
761 iq_elt = client.IQ("get")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
762 iq_elt['to'] = service.full()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
763 affiliations_elt = iq_elt.addElement((NS_FIS_AFFILIATION, "affiliations"))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
764 if namespace:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
765 affiliations_elt["namespace"] = namespace
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
766 affiliations_elt["path"] = path
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
767 iq_result_elt = await iq_elt.send()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
768 try:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
769 affiliations_elt = next(iq_result_elt.elements(NS_FIS_AFFILIATION, "affiliations"))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
770 except StopIteration:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
771 raise exceptions.DataError(f"Invalid result to affiliations request: {iq_result_elt.toXml()}")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
772
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
773 affiliations = {}
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
774 for affiliation_elt in affiliations_elt.elements(NS_FIS_AFFILIATION, 'affiliation'):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
775 try:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
776 affiliations[jid.JID(affiliation_elt['jid'])] = affiliation_elt['affiliation']
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
777 except (KeyError, RuntimeError):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
778 raise exceptions.DataError(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
779 f"invalid affiliation element: {affiliation_elt.toXml()}")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
780
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
781 return affiliations
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
782
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
783 def _affiliationsSet(self, service_jid_s, namespace, path, affiliations, profile):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
784 client = self.host.getClient(profile)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
785 service = jid.JID(service_jid_s)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
786 affiliations = {jid.JID(e): a for e, a in affiliations.items()}
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
787 return defer.ensureDeferred(self.affiliationsSet(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
788 client, service, namespace or None, path, affiliations))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
789
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
790 async def affiliationsSet(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
791 self,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
792 client: SatXMPPEntity,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
793 service: jid.JID,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
794 namespace: Optional[str],
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
795 path: str,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
796 affiliations: Dict[jid.JID, str],
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
797 ):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
798 if not path:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
799 raise ValueError(f"invalid path: {path!r}")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
800 iq_elt = client.IQ("set")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
801 iq_elt['to'] = service.full()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
802 affiliations_elt = iq_elt.addElement((NS_FIS_AFFILIATION, "affiliations"))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
803 if namespace:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
804 affiliations_elt["namespace"] = namespace
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
805 affiliations_elt["path"] = path
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
806 for entity_jid, affiliation in affiliations.items():
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
807 affiliation_elt = affiliations_elt.addElement('affiliation')
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
808 affiliation_elt['jid'] = entity_jid.full()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
809 affiliation_elt['affiliation'] = affiliation
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
810 await iq_elt.send()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
811
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
812 def _onComponentAffiliationsGet(self, iq_elt, client):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
813 iq_elt.handled = True
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
814 defer.ensureDeferred(self.onComponentAffiliationsGet(client, iq_elt))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
815
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
816 async def onComponentAffiliationsGet(self, client, iq_elt):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
817 try:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
818 (
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
819 from_jid, affiliations_elt, path, namespace, file_data
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
820 ) = await self._parseElement(client, iq_elt, "affiliations", NS_FIS_AFFILIATION)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
821 except exceptions.CancelError:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
822 return
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
823 except RootPathException:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
824 # if root path is requested, we only get owner affiliation
3366
e09cb08166a3 plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents: 3365
diff changeset
825 peer_jid, owner = client.getOwnerAndPeer(iq_elt)
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
826 is_owner = peer_jid.userhostJID() == owner
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
827 affiliations = {owner: 'owner'}
3355
33d9b38b5890 plugin XEP-0329: better error handling in `onComponentAffiliationsGet`
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
828 except exceptions.NotFound:
33d9b38b5890 plugin XEP-0329: better error handling in `onComponentAffiliationsGet`
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
829 client.sendError(iq_elt, "item-not-found")
33d9b38b5890 plugin XEP-0329: better error handling in `onComponentAffiliationsGet`
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
830 return
33d9b38b5890 plugin XEP-0329: better error handling in `onComponentAffiliationsGet`
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
831 except Exception as e:
33d9b38b5890 plugin XEP-0329: better error handling in `onComponentAffiliationsGet`
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
832 client.sendError(iq_elt, "internal-server-error", str(e))
33d9b38b5890 plugin XEP-0329: better error handling in `onComponentAffiliationsGet`
Goffi <goffi@goffi.org>
parents: 3333
diff changeset
833 return
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
834 else:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
835 from_jid_bare = from_jid.userhostJID()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
836 is_owner = from_jid_bare == file_data.get('owner')
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
837 affiliations = self.host.memory.getFileAffiliations(file_data)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
838 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
839 affiliations_elt = iq_result_elt.addElement((NS_FIS_AFFILIATION, 'affiliations'))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
840 for entity_jid, affiliation in affiliations.items():
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
841 if not is_owner and entity_jid.userhostJID() != from_jid_bare:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
842 # only onwer can get all affiliations
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
843 continue
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
844 affiliation_elt = affiliations_elt.addElement('affiliation')
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
845 affiliation_elt['jid'] = entity_jid.userhost()
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
846 affiliation_elt['affiliation'] = affiliation
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
847 client.send(iq_result_elt)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
848
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
849 def _onComponentAffiliationsSet(self, iq_elt, client):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
850 iq_elt.handled = True
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
851 defer.ensureDeferred(self.onComponentAffiliationsSet(client, iq_elt))
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
852
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
853 async def onComponentAffiliationsSet(self, client, iq_elt):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
854 try:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
855 (
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
856 from_jid, affiliations_elt, path, namespace, file_data
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
857 ) = await self._parseElement(client, iq_elt, "affiliations", NS_FIS_AFFILIATION)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
858 except exceptions.CancelError:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
859 return
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
860 except RootPathException:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
861 client.sendError(iq_elt, 'bad-request', "Root path can't be used")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
862 return
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
863
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
864 if from_jid.userhostJID() != file_data['owner']:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
865 log.warning(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
866 f"{from_jid} tried to modify {path} affiliations while the owner is "
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
867 f"{file_data['owner']}"
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
868 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
869 client.sendError(iq_elt, 'forbidden')
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
870 return
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
871
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
872 try:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
873 affiliations = {
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
874 jid.JID(e['jid']): e['affiliation']
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
875 for e in affiliations_elt.elements(NS_FIS_AFFILIATION, 'affiliation')
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
876 }
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
877 except (KeyError, RuntimeError):
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
878 log.warning(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
879 f"invalid affiliation element: {affiliations_elt.toXml()}"
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
880 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
881 client.sendError(iq_elt, 'bad-request', "invalid affiliation element")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
882 return
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
883 except Exception as e:
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
884 log.error(
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
885 f"unexepected exception while setting affiliation element: {e}\n"
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
886 f"{affiliations_elt.toXml()}"
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
887 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
888 client.sendError(iq_elt, 'internal-server-error', f"{e}")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
889 return
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
890
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
891 await self.host.memory.setFileAffiliations(client, file_data, affiliations)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
892
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
893 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
894 client.send(iq_result_elt)
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
895
3321
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
896 # configuration
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
897
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
898 def _configurationGet(self, service_jid_s, namespace, path, profile):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
899 client = self.host.getClient(profile)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
900 service = jid.JID(service_jid_s)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
901 d = defer.ensureDeferred(self.configurationGet(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
902 client, service, namespace or None, path))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
903 d.addCallback(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
904 lambda configuration: {
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
905 str(entity): affiliation for entity, affiliation in configuration.items()
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
906 }
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
907 )
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
908 return d
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
909
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
910 async def configurationGet(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
911 self,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
912 client: SatXMPPEntity,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
913 service: jid.JID,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
914 namespace: Optional[str],
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
915 path: str
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
916 ) -> Dict[str, str]:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
917 if not path:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
918 raise ValueError(f"invalid path: {path!r}")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
919 iq_elt = client.IQ("get")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
920 iq_elt['to'] = service.full()
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
921 configuration_elt = iq_elt.addElement((NS_FIS_CONFIGURATION, "configuration"))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
922 if namespace:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
923 configuration_elt["namespace"] = namespace
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
924 configuration_elt["path"] = path
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
925 iq_result_elt = await iq_elt.send()
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
926 try:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
927 configuration_elt = next(iq_result_elt.elements(NS_FIS_CONFIGURATION, "configuration"))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
928 except StopIteration:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
929 raise exceptions.DataError(f"Invalid result to configuration request: {iq_result_elt.toXml()}")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
930
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
931 form = data_form.findForm(configuration_elt, NS_FIS_CONFIGURATION)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
932 configuration = {f.var: f.value for f in form.fields.values()}
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
933
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
934 return configuration
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
935
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
936 def _configurationSet(self, service_jid_s, namespace, path, configuration, profile):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
937 client = self.host.getClient(profile)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
938 service = jid.JID(service_jid_s)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
939 return defer.ensureDeferred(self.configurationSet(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
940 client, service, namespace or None, path, configuration))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
941
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
942 async def configurationSet(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
943 self,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
944 client: SatXMPPEntity,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
945 service: jid.JID,
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
946 namespace: Optional[str],
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
947 path: str,
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
948 configuration: Dict[str, str],
3321
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
949 ):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
950 if not path:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
951 raise ValueError(f"invalid path: {path!r}")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
952 iq_elt = client.IQ("set")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
953 iq_elt['to'] = service.full()
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
954 configuration_elt = iq_elt.addElement((NS_FIS_CONFIGURATION, "configuration"))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
955 if namespace:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
956 configuration_elt["namespace"] = namespace
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
957 configuration_elt["path"] = path
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
958 form = data_form.Form(formType="submit", formNamespace=NS_FIS_CONFIGURATION)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
959 form.makeFields(configuration)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
960 configuration_elt.addChild(form.toElement())
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
961 await iq_elt.send()
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
962
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
963 def _onComponentConfigurationGet(self, iq_elt, client):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
964 iq_elt.handled = True
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
965 defer.ensureDeferred(self.onComponentConfigurationGet(client, iq_elt))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
966
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
967 async def onComponentConfigurationGet(self, client, iq_elt):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
968 try:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
969 (
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
970 from_jid, configuration_elt, path, namespace, file_data
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
971 ) = await self._parseElement(client, iq_elt, "configuration", NS_FIS_CONFIGURATION)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
972 except exceptions.CancelError:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
973 return
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
974 except RootPathException:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
975 client.sendError(iq_elt, 'bad-request', "Root path can't be used")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
976 return
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
977 try:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
978 access_type = file_data['access'][C.ACCESS_PERM_READ]['type']
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
979 except KeyError:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
980 access_model = 'whitelist'
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
981 else:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
982 access_model = 'open' if access_type == C.ACCESS_TYPE_PUBLIC else 'whitelist'
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
983
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
984 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
985 configuration_elt = iq_result_elt.addElement((NS_FIS_CONFIGURATION, 'configuration'))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
986 form = data_form.Form(formType="form", formNamespace=NS_FIS_CONFIGURATION)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
987 form.makeFields({'access_model': access_model})
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
988 configuration_elt.addChild(form.toElement())
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
989 client.send(iq_result_elt)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
990
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
991 async def _setConfiguration(self, client, configuration_elt, file_data):
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
992 form = data_form.findForm(configuration_elt, NS_FIS_CONFIGURATION)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
993 for name, value in form.items():
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
994 if name == 'access_model':
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
995 await self.host.memory.setFileAccessModel(client, file_data, value)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
996 else:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
997 # TODO: send a IQ error?
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
998 log.warning(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
999 f"Trying to set a not implemented configuration option: {name}")
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1000
3321
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1001 def _onComponentConfigurationSet(self, iq_elt, client):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1002 iq_elt.handled = True
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1003 defer.ensureDeferred(self.onComponentConfigurationSet(client, iq_elt))
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1004
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1005 async def onComponentConfigurationSet(self, client, iq_elt):
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1006 try:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1007 (
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1008 from_jid, configuration_elt, path, namespace, file_data
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1009 ) = await self._parseElement(client, iq_elt, "configuration", NS_FIS_CONFIGURATION)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1010 except exceptions.CancelError:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1011 return
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1012 except RootPathException:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1013 client.sendError(iq_elt, 'bad-request', "Root path can't be used")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1014 return
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1015
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1016 from_jid_bare = from_jid.userhostJID()
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1017 is_owner = from_jid_bare == file_data.get('owner')
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1018 if not is_owner:
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1019 log.warning(
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1020 f"{from_jid} tried to modify {path} configuration while the owner is "
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1021 f"{file_data['owner']}"
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1022 )
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1023 client.sendError(iq_elt, 'forbidden')
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1024 return
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1025
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1026 await self._setConfiguration(client, configuration_elt, file_data)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1027
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1028 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1029 client.send(iq_result_elt)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1030
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1031 # directory creation
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1032
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1033 def _createDir(self, service_jid_s, namespace, path, configuration, profile):
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1034 client = self.host.getClient(profile)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1035 service = jid.JID(service_jid_s)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1036 return defer.ensureDeferred(self.createDir(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1037 client, service, namespace or None, path, configuration or None))
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1038
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1039 async def createDir(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1040 self,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1041 client: SatXMPPEntity,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1042 service: jid.JID,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1043 namespace: Optional[str],
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1044 path: str,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1045 configuration: Optional[Dict[str, str]],
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1046 ):
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1047 if not path:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1048 raise ValueError(f"invalid path: {path!r}")
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1049 iq_elt = client.IQ("set")
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1050 iq_elt['to'] = service.full()
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1051 create_dir_elt = iq_elt.addElement((NS_FIS_CREATE, "dir"))
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1052 if namespace:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1053 create_dir_elt["namespace"] = namespace
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1054 create_dir_elt["path"] = path
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1055 if configuration:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1056 configuration_elt = create_dir_elt.addElement((NS_FIS_CONFIGURATION, "configuration"))
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1057 form = data_form.Form(formType="submit", formNamespace=NS_FIS_CONFIGURATION)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1058 form.makeFields(configuration)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1059 configuration_elt.addChild(form.toElement())
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1060 await iq_elt.send()
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1061
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1062 def _onComponentCreateDir(self, iq_elt, client):
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1063 iq_elt.handled = True
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1064 defer.ensureDeferred(self.onComponentCreateDir(client, iq_elt))
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1065
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1066 async def onComponentCreateDir(self, client, iq_elt):
3366
e09cb08166a3 plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
Goffi <goffi@goffi.org>
parents: 3365
diff changeset
1067 peer_jid, owner = client.getOwnerAndPeer(iq_elt)
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1068 if peer_jid.host not in client._file_sharing_allowed_hosts:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1069 client.sendError(iq_elt, 'forbidden')
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1070 return
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1071 create_dir_elt = next(iq_elt.elements(NS_FIS_CREATE, "dir"))
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1072 namespace = create_dir_elt.getAttribute('namespace')
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1073 path = Path("/", create_dir_elt['path'])
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1074 if len(path.parts) < 2:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1075 client.sendError(iq_elt, 'bad-request', "Root path can't be used")
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1076 return
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1077 # for root directories, we check permission here
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1078 if len(path.parts) == 2 and owner != peer_jid.userhostJID():
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1079 log.warning(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1080 f"{peer_jid} is trying to create a dir at {owner}'s repository:\n"
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1081 f"path: {path}\nnamespace: {namespace!r}"
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1082 )
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1083 client.sendError(iq_elt, 'forbidden', "You can't create a directory there")
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1084 return
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1085 # when going further into the path, the permissions will be checked by getFiles
3500
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1086 files_data = await self.host.memory.getFiles(
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1087 client,
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1088 peer_jid=peer_jid,
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1089 path=path.parent,
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1090 namespace=namespace,
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1091 owner=owner,
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1092 )
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1093 if path.name in [d['name'] for d in files_data]:
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1094 log.warning(
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1095 f"Conflict when trying to create a directory (from: {peer_jid} "
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1096 f"namespace: {namespace!r} path: {path!r})"
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1097 )
3500
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1098 client.sendError(
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1099 iq_elt, 'conflict', "there is already a file or dir at this path")
73b8a8d938be plugin XEP-0329: check files conflict also for root files
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
1100 return
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1101
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1102 try:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1103 configuration_elt = next(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1104 create_dir_elt.elements(NS_FIS_CONFIGURATION, 'configuration'))
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1105 except StopIteration:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1106 configuration_elt = None
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1107
3362
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1108 await self.host.memory.setFile(
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1109 client,
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1110 path.name,
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1111 path=path.parent,
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1112 type_=C.FILE_TYPE_DIRECTORY,
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1113 namespace=namespace,
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1114 owner=owner,
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1115 peer_jid=peer_jid
02583a401e51 plugin XEP-0329: fix conflict check + directory creation in `onComponentCreateDir`
Goffi <goffi@goffi.org>
parents: 3360
diff changeset
1116 )
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1117
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1118 if configuration_elt is not None:
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1119 file_data = (await self.host.memory.getFiles(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1120 client,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1121 peer_jid=peer_jid,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1122 path=path.parent,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1123 name=path.name,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1124 namespace=namespace,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1125 owner=owner,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1126 ))[0]
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1127
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1128 await self._setConfiguration(client, configuration_elt, file_data)
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1129
3321
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1130 iq_result_elt = xmlstream.toResponse(iq_elt, "result")
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1131 client.send(iq_result_elt)
8bbd2ed924e8 plugin XEP-0329: added way to change `access_model` using PubSub-like configuration:
Goffi <goffi@goffi.org>
parents: 3320
diff changeset
1132
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1133 # file methods #
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1134
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1135 def _serializeData(self, files_data):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1136 for file_data in files_data:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1137 for key, value in file_data.items():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1138 file_data[key] = (
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1139 json.dumps(value) if key in ("extra",) else str(value)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1140 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1141 return files_data
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1142
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1143 def _listFiles(self, target_jid, path, extra, profile):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1144 client = self.host.getClient(profile)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3032
diff changeset
1145 target_jid = client.jid if not target_jid else jid.JID(target_jid)
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
1146 d = defer.ensureDeferred(self.listFiles(client, target_jid, path or None))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1147 d.addCallback(self._serializeData)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1148 return d
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1149
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
1150 async def listFiles(self, client, peer_jid, path=None, extra=None):
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1151 """List file shared by an entity
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1152
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
1153 @param peer_jid(jid.JID): jid of the sharing entity
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1154 @param path(unicode, None): path to the directory containing shared files
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1155 None to get root directories
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1156 @param extra(dict, None): extra data
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1157 @return list(dict): shared files
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1158 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1159 iq_elt = client.IQ("get")
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
1160 iq_elt["to"] = peer_jid.full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1161 query_elt = iq_elt.addElement((NS_FIS, "query"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1162 if path:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1163 query_elt["node"] = path
3333
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
1164 iq_result_elt = await iq_elt.send()
ac9342f359e9 plugin XEP-0329: download thumbnails:
Goffi <goffi@goffi.org>
parents: 3321
diff changeset
1165 return await self._parseResult(client, peer_jid, iq_result_elt)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1166
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1167 def _localSharesGet(self, profile):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1168 client = self.host.getClient(profile)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1169 return self.localSharesGet(client)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1170
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1171 def localSharesGet(self, client):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1172 return list(client._XEP_0329_root_node.getSharedPaths().keys())
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1173
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1174 def _sharePath(self, name, path, access, profile):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1175 client = self.host.getClient(profile)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1176 access = json.loads(access)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1177 return self.sharePath(client, name or None, path, access)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1178
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1179 def sharePath(self, client, name, path, access):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1180 if client.is_component:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1181 raise exceptions.ClientTypeError
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1182 if not os.path.exists(path):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1183 raise ValueError(_("This path doesn't exist!"))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1184 if not path or not path.strip(" /"):
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1185 raise ValueError(_("A path need to be specified"))
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1186 if not isinstance(access, dict):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1187 raise ValueError(_("access must be a dict"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1188
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1189 node = client._XEP_0329_root_node
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1190 node_type = TYPE_PATH
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1191 if os.path.isfile(path):
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1192 # we have a single file, the workflow is diferrent as we store all single
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1193 # files in the same dir
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1194 node = node.getOrCreate(SINGLE_FILES_DIR)
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1195
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1196 if not name:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1197 name = os.path.basename(path.rstrip(" /"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1198 if not name:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1199 raise exceptions.InternalError(_("Can't find a proper name"))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1200
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1201 if name in node or name == SINGLE_FILES_DIR:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1202 idx = 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1203 new_name = name + "_" + str(idx)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1204 while new_name in node:
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1205 idx += 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1206 new_name = name + "_" + str(idx)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1207 name = new_name
2909
90146552cde5 core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1208 log.info(_(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1209 "A directory with this name is already shared, renamed to {new_name} "
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1210 "[{profile}]".format( new_name=new_name, profile=client.profile)))
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1211
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1212 ShareNode(name=name, parent=node, type_=node_type, access=access, path=path)
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1213 self.host.bridge.FISSharedPathNew(path, name, client.profile)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1214 return name
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1215
2589
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1216 def _unsharePath(self, path, profile):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1217 client = self.host.getClient(profile)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1218 return self.unsharePath(client, path)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1219
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1220 def unsharePath(self, client, path):
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1221 nodes = client._XEP_0329_root_node.findByLocalPath(path)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1222 for node in nodes:
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1223 node.removeFromParent()
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1224 self.host.bridge.FISSharedPathRemoved(path, client.profile)
282d1314d574 plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1225
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1226
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2937
diff changeset
1227 @implementer(iwokkel.IDisco)
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1228 class XEP_0329_handler(xmlstream.XMPPHandler):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1229
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1230 def __init__(self, plugin_parent):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1231 self.plugin_parent = plugin_parent
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1232 self.host = plugin_parent.host
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1233
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1234 def connectionInitialized(self):
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1235 if self.parent.is_component:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1236 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1237 IQ_FIS_REQUEST, self.plugin_parent.onComponentRequest, client=self.parent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1238 )
3320
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1239 self.xmlstream.addObserver(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1240 IQ_FIS_AFFILIATION_GET,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1241 self.plugin_parent._onComponentAffiliationsGet,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1242 client=self.parent
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1243 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1244 self.xmlstream.addObserver(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1245 IQ_FIS_AFFILIATION_SET,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1246 self.plugin_parent._onComponentAffiliationsSet,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1247 client=self.parent
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1248 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1249 self.xmlstream.addObserver(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1250 IQ_FIS_CONFIGURATION_GET,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1251 self.plugin_parent._onComponentConfigurationGet,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1252 client=self.parent
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1253 )
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1254 self.xmlstream.addObserver(
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1255 IQ_FIS_CONFIGURATION_SET,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1256 self.plugin_parent._onComponentConfigurationSet,
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1257 client=self.parent
bb92085720c8 plugin XEP-0329: implemented ways to get/set affiliations:
Goffi <goffi@goffi.org>
parents: 3314
diff changeset
1258 )
3359
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1259 self.xmlstream.addObserver(
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1260 IQ_FIS_CREATE_DIR,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1261 self.plugin_parent._onComponentCreateDir,
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1262 client=self.parent
000b6722bd35 plugin XEP-0329: added `FISCreateDir` method:
Goffi <goffi@goffi.org>
parents: 3355
diff changeset
1263 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1264 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1265 self.xmlstream.addObserver(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1266 IQ_FIS_REQUEST, self.plugin_parent.onRequest, client=self.parent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1267 )
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1268
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1269 def getDiscoInfo(self, requestor, target, nodeIdentifier=""):
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1270 return [disco.DiscoFeature(NS_FIS)]
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1271
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2589
diff changeset
1272 def getDiscoItems(self, requestor, target, nodeIdentifier=""):
2503
c0bec8bac2b5 XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff changeset
1273 return []