Mercurial > libervia-backend
annotate sat/plugins/plugin_xep_0329.py @ 3314:5887fb414758
component file sharing: add/parse affiliation when possible
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jul 2020 13:00:10 +0200 |
parents | 9d0df638c8b4 |
children | bb92085720c8 |
rev | line source |
---|---|
3028 | 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) |
3136 | 4 # Copyright (C) 2009-2020 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 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 from sat.core.i18n import _ |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 from sat.core import exceptions |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from sat.core.constants import Const as C |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.log import getLogger |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
23 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 log = getLogger(__name__) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat.tools import stream |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from sat.tools.common import regex |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from wokkel import disco, iwokkel |
3028 | 28 from zope.interface import implementer |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from twisted.words.protocols.jabber import xmlstream |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from twisted.words.protocols.jabber import jid |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 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
|
32 from twisted.internet import defer |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 import mimetypes |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 import json |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 import os |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
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 PLUGIN_INFO = { |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 C.PI_NAME: "File Information Sharing", |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 C.PI_IMPORT_NAME: "XEP-0329", |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 C.PI_TYPE: "XEP", |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 C.PI_MODES: C.PLUG_MODE_BOTH, |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 C.PI_PROTOCOLS: ["XEP-0329"], |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
44 C.PI_DEPENDENCIES: ["XEP-0234", "XEP-0300", "XEP-0106"], |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 C.PI_MAIN: "XEP_0329", |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 C.PI_HANDLER: "yes", |
3028 | 47 C.PI_DESCRIPTION: _("""Implementation of File Information Sharing"""), |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 } |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
50 NS_FIS = "urn:xmpp:fis:0" |
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 IQ_FIS_REQUEST = C.IQ_GET + '/query[@xmlns="' + NS_FIS + '"]' |
3028 | 53 SINGLE_FILES_DIR = "files" |
54 TYPE_VIRTUAL = "virtual" | |
55 TYPE_PATH = "path" | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
56 SHARE_TYPES = (TYPE_PATH, TYPE_VIRTUAL) |
3028 | 57 KEY_TYPE = "type" |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 class ShareNode(object): |
2909
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
61 """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
|
62 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 host = None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 def __init__(self, name, parent, type_, access, path=None): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 assert type_ in SHARE_TYPES |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 if name is not None: |
3028 | 68 if name == ".." or "/" in name or "\\" in name: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
69 log.warning( |
3028 | 70 _("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
|
71 name=name |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
72 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
73 ) |
3028 | 74 if name == "..": |
75 name = "--" | |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 else: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 name = regex.pathEscape(name) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 self.name = name |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self.children = {} |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 self.type = type_ |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 self.access = {} if access is None else access |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 assert isinstance(self.access, dict) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 self.parent = None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 if parent is not None: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 assert name |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 parent.addChild(self) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 else: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 assert name is None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 if path is not None: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 if type_ != TYPE_PATH: |
3028 | 91 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
|
92 self._path = path |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 @property |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def path(self): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 return self._path |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 def __getitem__(self, key): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 return self.children[key] |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 def __contains__(self, item): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 return self.children.__contains__(item) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 def __iter__(self): |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
105 return self.children.__iter__() |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 |
3032
95e2fd14a761
plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
107 def items(self): |
95e2fd14a761
plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
108 return self.children.items() |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 |
3032
95e2fd14a761
plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
110 def values(self): |
95e2fd14a761
plugin XEP-0329: fixed ShareNode item() and values after Python 3 port
Goffi <goffi@goffi.org>
parents:
3028
diff
changeset
|
111 return self.children.values() |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 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
|
114 """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
|
115 if access is None: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 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
|
117 try: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 return self.children[name] |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 except KeyError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 node = ShareNode(name, self, type_=type_, access=access) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 return node |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 def addChild(self, node): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 if node.parent is not None: |
3028 | 125 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
|
126 node.parent = self |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 self.children[node.name] = node |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 def removeFromParent(self): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 try: |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
131 del self.parent.children[self.name] |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 except TypeError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
133 raise exceptions.InternalError( |
3028 | 134 "trying to remove a node from inexisting parent" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
135 ) |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 except KeyError: |
3028 | 137 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
|
138 self.parent = None |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 def _checkNodePermission(self, client, node, perms, peer_jid): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 """Check access to this node for peer_jid |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 @param node(SharedNode): node to check access |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 @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
|
145 @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
|
146 @return (bool): True if entity can access |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 """ |
3028 | 148 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
|
149 try: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 self.host.memory.checkFilePermission(file_data, peer_jid, perms) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 except exceptions.PermissionError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 return False |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 else: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 return True |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
156 def checkPermissions( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
157 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
|
158 ): |
2909
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
159 """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
|
160 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 @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
|
162 @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
|
163 @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
|
164 checked too |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 @return (bool): True if entity can access this node |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 """ |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 peer_jid = peer_jid.userhostJID() |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 if peer_jid == client.jid.userhostJID(): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 return True |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 parent = self |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 while parent != None: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 if not self._checkNodePermission(client, parent, perms, peer_jid): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 return False |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 parent = parent.parent |
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 return True |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 @staticmethod |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 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
|
181 """find node corresponding to a path |
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 @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
|
184 @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
|
185 used to check permission |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 @return (dict, unicode): shared data, remaining path |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 @raise exceptions.PermissionError: user can't access this file |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 @raise exceptions.DataError: path is invalid |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 @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
|
190 """ |
3028 | 191 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
|
192 |
3028 | 193 if ".." in path_elts: |
2909
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
194 log.warning(_( |
3028 | 195 'parent dir ("..") found in path, hack attempt? path is {path} ' |
196 '[{profile}]').format(path=path, profile=client.profile)) | |
197 raise exceptions.PermissionError("illegal path elements") | |
2503
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 if not path_elts: |
3028 | 200 raise exceptions.DataError(_("path is invalid: {path}").format(path=path)) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 node = client._XEP_0329_root_node |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 while path_elts: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 if node.type == TYPE_VIRTUAL: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 try: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 node = node[path_elts.pop(0)] |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 except KeyError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 raise exceptions.NotFound |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 elif node.type == TYPE_PATH: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 break |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
213 if not node.checkPermissions(client, peer_jid, perms=perms): |
3028 | 214 raise exceptions.PermissionError("permission denied") |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
3028 | 216 return node, "/".join(path_elts) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
218 def findByLocalPath(self, path): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 """retrieve nodes linking to local path |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 @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
|
222 @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
|
223 """ |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 shared_paths = self.getSharedPaths() |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
225 try: |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 return shared_paths[path] |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 except KeyError: |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 raise exceptions.NotFound |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
230 def _getSharedPaths(self, node, paths): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 if node.type == TYPE_VIRTUAL: |
3028 | 232 for node in node.values(): |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 self._getSharedPaths(node, paths) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 elif node.type == TYPE_PATH: |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
235 paths.setdefault(node.path, []).append(node) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
236 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
237 raise exceptions.InternalError( |
3028 | 238 "unknown node type: {type}".format(type=node.type) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
239 ) |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
240 |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
241 def getSharedPaths(self): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
242 """retrieve nodes by shared path |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
243 |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
244 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
|
245 @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
|
246 """ |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 if self.type == TYPE_PATH: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
248 raise exceptions.InternalError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
249 "getSharedPaths must be used on a virtual node" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
250 ) |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
251 paths = {} |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
252 self._getSharedPaths(self, paths) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
253 return paths |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 class XEP_0329(object): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 def __init__(self, host): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 log.info(_("File Information Sharing initialization")) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 self.host = host |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 ShareNode.host = host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
261 self._h = host.plugins["XEP-0300"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
262 self._jf = host.plugins["XEP-0234"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
263 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
264 "FISList", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
265 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
266 in_sign="ssa{ss}s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
267 out_sign="aa{ss}", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
268 method=self._listFiles, |
3028 | 269 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
270 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
271 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
272 "FISLocalSharesGet", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
273 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
274 in_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
275 out_sign="as", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
276 method=self._localSharesGet, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
277 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
278 host.bridge.addMethod( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
279 "FISSharePath", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
280 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
281 in_sign="ssss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
282 out_sign="s", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
283 method=self._sharePath, |
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 "FISUnsharePath", |
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="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
289 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
290 method=self._unsharePath, |
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.addSignal("FISSharedPathNew", ".plugin", signature="sss") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
293 host.bridge.addSignal("FISSharedPathRemoved", ".plugin", signature="ss") |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 host.trigger.add("XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
295 host.registerNamespace("fis", NS_FIS) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 def getHandler(self, client): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 return XEP_0329_handler(self) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 def profileConnected(self, client): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 if not client.is_component: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
302 client._XEP_0329_root_node = ShareNode( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
303 None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
304 None, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
305 TYPE_VIRTUAL, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
306 {C.ACCESS_PERM_READ: {KEY_TYPE: C.ACCESS_TYPE_PUBLIC}}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
307 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
308 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
|
309 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
310 def _fileSendingRequestTrigger( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
311 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
|
312 ): |
2909
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
313 """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
|
314 |
2909
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
315 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
|
316 with known names |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 """ |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 if client.is_component: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 return True, None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 try: |
3028 | 322 name = file_data["name"] |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 except KeyError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 return True, None |
3028 | 325 assert "/" not in name |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 |
3028 | 327 path = file_data.get("path") |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 if path is not None: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 # 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
|
330 try: |
3028 | 331 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
|
332 except (exceptions.PermissionError, exceptions.NotFound): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
333 # 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
|
334 return True, None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 except exceptions.DataError: |
3028 | 336 log.warning(_("invalid path: {path}").format(path=path)) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 return True, None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
339 if node.type == TYPE_VIRTUAL: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
340 # 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
|
341 try: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 path = node[name].path |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 except KeyError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
344 return True, None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 elif node.type == TYPE_PATH: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 # 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
|
347 path = os.path.join(node.path, rem_path, name) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
348 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
349 raise exceptions.InternalError( |
3028 | 350 "unknown type: {type}".format(type=node.type) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
351 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 if not os.path.exists(path): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 return True, None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 size = os.path.getsize(path) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 else: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 # 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
|
357 try: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 name_data = client._XEP_0329_names_data[name] |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 except KeyError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 return True, None |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 |
3028 | 362 for path, shared_file in name_data.items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
363 if True: # FIXME: filters are here |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 break |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 else: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 return True, None |
3028 | 367 parent_node = shared_file["parent"] |
368 if not parent_node.checkPermissions(client, session["peer_jid"]): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
369 log.warning( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
370 _( |
3028 | 371 "{peer_jid} requested a file (s)he can't access [{profile}]" |
372 ).format(peer_jid=session["peer_jid"], profile=client.profile) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
373 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 return True, None |
3028 | 375 size = shared_file["size"] |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
376 |
3028 | 377 file_data["size"] = size |
378 file_elt.addElement("size", content=str(size)) | |
379 hash_algo = file_data["hash_algo"] = self._h.getDefaultAlgo() | |
380 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
|
381 file_elt.addChild(self._h.buildHashUsedElt(hash_algo)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
382 content_data["stream_object"] = stream.FileStreamObject( |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 self.host, |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 client, |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 path, |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 uid=self._jf.getProgressId(session, content_name), |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 size=size, |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 data_cb=lambda data: hasher.update(data), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
389 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
390 return False, True |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
391 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 # common methods |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 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
|
395 iq_elt.handled = True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
396 node = iq_elt.query.getAttribute("node") |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
397 if not node: |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
398 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
|
399 else: |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
400 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
|
401 d.addErrback( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
402 lambda failure_: log.error( |
3028 | 403 _("error while retrieving files: {msg}").format(msg=failure_) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
404 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
405 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 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
|
408 error_elt = jabber_error.StanzaError(condition).toResponse(iq_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 client.send(error_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
410 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
411 # client |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 def _addPathData(self, client, query_elt, path, parent_node): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 """Fill query_elt with files/directories found in path""" |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 name = os.path.basename(path) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 if os.path.isfile(path): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 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
|
418 mime_type = mimetypes.guess_type(path, strict=False)[0] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
419 file_elt = self._jf.buildFileElement( |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
420 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
|
421 modified=os.path.getmtime(path) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
422 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 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
|
425 # 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
|
426 # it for all files. |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 # 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
|
428 name_data = client._XEP_0329_names_data.setdefault(name, {}) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 if path not in name_data: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
430 name_data[path] = { |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
431 "size": size, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
432 "mime_type": mime_type, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
433 "parent": parent_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
434 } |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 else: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 # we have a directory |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
437 directory_elt = query_elt.addElement("directory") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
438 directory_elt["name"] = name |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
439 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
440 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
|
441 """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
|
442 path = os.path.join(node.path, path) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 if not os.path.exists(path): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 # 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
|
446 return self._iqError(client, iq_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 elif os.path.isfile(path): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 self._addPathData(client, query_elt, path, node) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
450 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
|
451 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
452 name = name.decode("utf-8", "strict") |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 except UnicodeDecodeError as e: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
454 log.warning( |
3028 | 455 _("ignoring invalid unicode name ({name}): {msg}").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
456 name=name.decode("utf-8", "replace"), msg=e |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
457 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
458 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 continue |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
460 full_path = os.path.join(path, name) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
461 self._addPathData(client, query_elt, full_path, node) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 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
|
464 """Fill query_elt for virtual nodes""" |
3028 | 465 for name, child_node in node.items(): |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 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
|
467 continue |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 node_type = child_node.type |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 if node_type == TYPE_VIRTUAL: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
470 directory_elt = query_elt.addElement("directory") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
471 directory_elt["name"] = name |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 elif node_type == TYPE_PATH: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 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
|
474 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
475 raise exceptions.InternalError( |
3028 | 476 _("unexpected type: {type}").format(type=node_type) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
477 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
479 def _getRootNodesCb(self, client, iq_elt): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
480 peer_jid = jid.JID(iq_elt["from"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
481 iq_result_elt = xmlstream.toResponse(iq_elt, "result") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
482 query_elt = iq_result_elt.addElement((NS_FIS, "query")) |
3028 | 483 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
|
484 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
|
485 continue |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
486 directory_elt = query_elt.addElement("directory") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
487 directory_elt["name"] = name |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 client.send(iq_result_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
490 def _getFilesFromNodeCb(self, client, iq_elt, node_path): |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
491 """Main method to retrieve files/directories from a node_path""" |
3028 | 492 peer_jid = jid.JID(iq_elt["from"]) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 try: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 node, path = ShareNode.find(client, node_path, peer_jid) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 except (exceptions.PermissionError, exceptions.NotFound): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 return self._iqError(client, iq_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 except exceptions.DataError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
498 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
|
499 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 node_type = node.type |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
501 peer_jid = jid.JID(iq_elt["from"]) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
502 iq_result_elt = xmlstream.toResponse(iq_elt, "result") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
503 query_elt = iq_result_elt.addElement((NS_FIS, "query")) |
3028 | 504 query_elt["node"] = node_path |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 # we now fill query_elt according to node_type |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 if node_type == TYPE_PATH: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
508 # it's a physical path |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 self._pathNodeHandler(client, iq_elt, query_elt, node, path) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 elif node_type == TYPE_VIRTUAL: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 assert not path |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 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
|
513 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
514 raise exceptions.InternalError( |
3028 | 515 _("unknown node type: {type}").format(type=node_type) |
2624
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 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 client.send(iq_result_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
519 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
520 def onRequest(self, iq_elt, client): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
521 return self._requestHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
522 client, iq_elt, self._getRootNodesCb, self._getFilesFromNodeCb |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
523 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
524 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
525 # Component |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
526 |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
527 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
|
528 """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
|
529 |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
530 @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
|
531 @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
|
532 """ |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
533 to_jid = jid.JID(iq_elt['to']) |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
534 if to_jid.user: |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
535 user = self.host.plugins['XEP-0106'].unescape(to_jid.user) |
3028 | 536 if '@' in user: |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
537 # a full jid is specified |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
538 owner = jid.JID(user) |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
539 else: |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
540 # only user part is specified, we use our own host to build the full jid |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
541 owner = jid.JID(None, (user, client.host, None)) |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
542 else: |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
543 owner = jid.JID(iq_elt["from"]).userhostJID() |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
544 |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
545 peer_jid = jid.JID(iq_elt["from"]) |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
546 return peer_jid, owner |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
547 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
548 @defer.inlineCallbacks |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
549 def _compGetRootNodesCb(self, client, iq_elt): |
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
550 peer_jid, owner = self._compParseJids(client, iq_elt) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
551 files_data = yield self.host.memory.getFiles( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
552 client, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
553 peer_jid=peer_jid, |
3028 | 554 parent="", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
555 type_=C.FILE_TYPE_DIRECTORY, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
556 owner=owner, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
557 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
558 iq_result_elt = xmlstream.toResponse(iq_elt, "result") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
559 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
|
560 for file_data in files_data: |
3028 | 561 name = file_data["name"] |
562 directory_elt = query_elt.addElement("directory") | |
563 directory_elt["name"] = name | |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
564 client.send(iq_result_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
565 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
566 @defer.inlineCallbacks |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
567 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
|
568 """Retrieve files from local files repository according to permissions |
2528
65e278997715
component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
569 |
65e278997715
component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
570 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
|
571 @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
|
572 files_data): |
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
573 can be used to add data/elements |
2528
65e278997715
component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
574 """ |
2923
1fd3ecb3351a
plugin XEP-0329: use local part of jid for components:
Goffi <goffi@goffi.org>
parents:
2909
diff
changeset
|
575 peer_jid, owner = self._compParseJids(client, iq_elt) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
576 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
577 files_data = yield self.host.memory.getFiles( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
578 client, peer_jid=peer_jid, path=node_path, owner=owner |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
579 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
580 except exceptions.NotFound: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
581 self._iqError(client, iq_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
582 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
|
583 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
|
584 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
|
585 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
|
586 except Exception as e: |
3028 | 587 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
|
588 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
|
589 return |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
590 iq_result_elt = xmlstream.toResponse(iq_elt, "result") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
591 query_elt = iq_result_elt.addElement((NS_FIS, "query")) |
3028 | 592 query_elt["node"] = node_path |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
593 if not self.host.trigger.point( |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
594 "XEP-0329_compGetFilesFromNode", |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
595 client, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
596 iq_elt, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
597 iq_result_elt, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
598 owner, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
599 node_path, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
600 files_data |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
601 ): |
2528
65e278997715
component file sharing: comments metadata:
Goffi <goffi@goffi.org>
parents:
2527
diff
changeset
|
602 return |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
603 for file_data in files_data: |
3040 | 604 if file_data['type'] == C.FILE_TYPE_DIRECTORY: |
605 directory_elt = query_elt.addElement("directory") | |
606 directory_elt['name'] = file_data['name'] | |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
607 self.host.trigger.point( |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
608 "XEP-0329_compGetFilesFromNode_build_directory", |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
609 client, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
610 file_data, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
611 directory_elt, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
612 owner, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
613 node_path, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
614 ) |
3040 | 615 else: |
616 file_elt = self._jf.buildFileElementFromDict( | |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
617 client, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
618 file_data, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
619 modified=file_data.get("modified", file_data["created"]) |
3040 | 620 ) |
621 query_elt.addChild(file_elt) | |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
622 client.send(iq_result_elt) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
623 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
624 def onComponentRequest(self, iq_elt, client): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
625 return self._requestHandler( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
626 client, iq_elt, self._compGetRootNodesCb, self._compGetFilesFromNodeCb |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
627 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
628 |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
629 def _parseResult(self, iq_elt, client): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
630 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
|
631 files = [] |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
632 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
633 for elt in query_elt.elements(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
634 if elt.name == "file": |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
635 # we have a file |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
636 try: |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
637 file_data = self._jf.parseFileElement(client, elt) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
638 except exceptions.DataError: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
639 continue |
3028 | 640 file_data["type"] = C.FILE_TYPE_FILE |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
641 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
|
642 # we have a directory |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
643 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
644 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
|
645 self.host.trigger.point( |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
646 "XEP-0329_parseResult_directory", |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
647 client, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
648 elt, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
649 file_data, |
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
650 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
651 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
652 log.warning( |
3040 | 653 _(f"unexpected element, ignoring: {elt.toXml()}") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
654 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
655 continue |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
656 files.append(file_data) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
657 return files |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
658 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
659 # file methods # |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
660 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
661 def _serializeData(self, files_data): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
662 for file_data in files_data: |
3028 | 663 for key, value in file_data.items(): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
664 file_data[key] = ( |
3028 | 665 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
|
666 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
667 return files_data |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
668 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
669 def _listFiles(self, target_jid, path, extra, profile): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
670 client = self.host.getClient(profile) |
3040 | 671 target_jid = client.jid if not target_jid else jid.JID(target_jid) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
672 d = self.listFiles(client, target_jid, path or None) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
673 d.addCallback(self._serializeData) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
674 return d |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
675 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
676 def listFiles(self, client, target_jid, path=None, extra=None): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
677 """List file shared by an entity |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
678 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
679 @param target_jid(jid.JID): jid of the sharing entity |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
680 @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
|
681 None to get root directories |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
682 @param extra(dict, None): extra data |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
683 @return list(dict): shared files |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
684 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
685 iq_elt = client.IQ("get") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
686 iq_elt["to"] = target_jid.full() |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
687 query_elt = iq_elt.addElement((NS_FIS, "query")) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
688 if path: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
689 query_elt["node"] = path |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
690 d = iq_elt.send() |
3314
5887fb414758
component file sharing: add/parse affiliation when possible
Goffi <goffi@goffi.org>
parents:
3136
diff
changeset
|
691 d.addCallback(self._parseResult, client) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
692 return d |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
693 |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
694 def _localSharesGet(self, profile): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
695 client = self.host.getClient(profile) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
696 return self.localSharesGet(client) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
697 |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
698 def localSharesGet(self, client): |
3028 | 699 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
|
700 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
701 def _sharePath(self, name, path, access, profile): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
702 client = self.host.getClient(profile) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
703 access = json.loads(access) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
704 return self.sharePath(client, name or None, path, access) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
705 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
706 def sharePath(self, client, name, path, access): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
707 if client.is_component: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
708 raise exceptions.ClientTypeError |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
709 if not os.path.exists(path): |
3028 | 710 raise ValueError(_("This path doesn't exist!")) |
711 if not path or not path.strip(" /"): | |
712 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
|
713 if not isinstance(access, dict): |
3028 | 714 raise ValueError(_("access must be a dict")) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
715 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
716 node = client._XEP_0329_root_node |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
717 node_type = TYPE_PATH |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
718 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
|
719 # 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
|
720 # files in the same dir |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
721 node = node.getOrCreate(SINGLE_FILES_DIR) |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
722 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
723 if not name: |
3028 | 724 name = os.path.basename(path.rstrip(" /")) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
725 if not name: |
3028 | 726 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
|
727 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
728 if name in node or name == SINGLE_FILES_DIR: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
729 idx = 1 |
3028 | 730 new_name = name + "_" + str(idx) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
731 while new_name in node: |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
732 idx += 1 |
3028 | 733 new_name = name + "_" + str(idx) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
734 name = new_name |
2909
90146552cde5
core (memory), plugin XEP-0329, plugin invitation: minor style improvments
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
735 log.info(_( |
3028 | 736 "A directory with this name is already shared, renamed to {new_name} " |
737 "[{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
|
738 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
739 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
|
740 self.host.bridge.FISSharedPathNew(path, name, client.profile) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
741 return name |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
742 |
2589
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
743 def _unsharePath(self, path, profile): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
744 client = self.host.getClient(profile) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
745 return self.unsharePath(client, path) |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
746 |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
747 def unsharePath(self, client, path): |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
748 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
|
749 for node in nodes: |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
750 node.removeFromParent() |
282d1314d574
plugin XEP-0329: new methods/signals to handle shares:
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
751 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
|
752 |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
753 |
3028 | 754 @implementer(iwokkel.IDisco) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
755 class XEP_0329_handler(xmlstream.XMPPHandler): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
756 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
757 def __init__(self, plugin_parent): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
758 self.plugin_parent = plugin_parent |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
759 self.host = plugin_parent.host |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
760 |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
761 def connectionInitialized(self): |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
762 if self.parent.is_component: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
763 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
764 IQ_FIS_REQUEST, self.plugin_parent.onComponentRequest, client=self.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
765 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
766 else: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
767 self.xmlstream.addObserver( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
768 IQ_FIS_REQUEST, self.plugin_parent.onRequest, client=self.parent |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
769 ) |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
770 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
771 def getDiscoInfo(self, requestor, target, nodeIdentifier=""): |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
772 return [disco.DiscoFeature(NS_FIS)] |
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
773 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2589
diff
changeset
|
774 def getDiscoItems(self, requestor, target, nodeIdentifier=""): |
2503
c0bec8bac2b5
XEP-0329: implementation of File Information Sharing:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
775 return [] |