From cb2144bdf49eaae78153e689d36fc8f3cbc3f1be Mon Sep 17 00:00:00 2001 From: Goffi Date: Thu, 23 Mar 2023 15:38:07 +0100 Subject: [PATCH] core (xmpp), component file sharing, plugin XEP-0363: `enabled_features` + HTTP Upload: add a mechanism to explicitely enable some features in components, and use it to enable HTTP Upload only if it's explicitely enabled. --- sat/core/xmpp.py | 1 + sat/plugins/plugin_comp_file_sharing.py | 7 +++++-- sat/plugins/plugin_xep_0363.py | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sat/core/xmpp.py b/sat/core/xmpp.py index 5a59881a..b67093f4 100644 --- a/sat/core/xmpp.py +++ b/sat/core/xmpp.py @@ -1067,6 +1067,7 @@ class SatXMPPComponent(SatXMPPEntity, component.Component): ) ) + self.enabled_features = set() self.identities = [disco.DiscoIdentity("component", "generic", C.APP_NAME)] # jid is set automatically on bind by Twisted for Client, but not for Component self.jid = component_jid diff --git a/sat/plugins/plugin_comp_file_sharing.py b/sat/plugins/plugin_comp_file_sharing.py index 4c840c1c..4a5569e8 100644 --- a/sat/plugins/plugin_comp_file_sharing.py +++ b/sat/plugins/plugin_comp_file_sharing.py @@ -355,7 +355,7 @@ class FileSharing: self._h = self.host.plugins["XEP-0300"] self._t = self.host.plugins["XEP-0264"] self._hu = self.host.plugins["XEP-0363"] - self._hu.registerHandler(self._onHTTPUpload) + self._hu.registerHandler(self._on_http_upload) self.host.trigger.add("FILE_getDestDir", self._getDestDirTrigger) self.host.trigger.add( "XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000 @@ -393,6 +393,9 @@ class FileSharing: return Comments_handler(self) def profileConnecting(self, client): + # we activate HTTP upload + client.enabled_features.add("XEP-0363") + self.init() public_base_url = self.host.memory.getConfig( 'component file-sharing', 'http_upload_public_facing_url') @@ -632,7 +635,7 @@ class FileSharing: except KeyError: log.error(f"trying to purge an inexisting upload slot ({upload_id})") - async def _onHTTPUpload(self, client, request): + async def _on_http_upload(self, client, request): # filename should be already cleaned, but it's better to double check assert '/' not in request.filename # client._file_sharing_allowed_hosts is set in plugin XEP-0329 diff --git a/sat/plugins/plugin_xep_0363.py b/sat/plugins/plugin_xep_0363.py index ff7b6929..f23e2d41 100644 --- a/sat/plugins/plugin_xep_0363.py +++ b/sat/plugins/plugin_xep_0363.py @@ -433,14 +433,19 @@ class XEP_0363_handler(xmlstream.XMPPHandler): self.plugin_parent = plugin_parent def connectionInitialized(self): - if self.parent.is_component: + if ((self.parent.is_component + and PLUGIN_INFO[C.PI_IMPORT_NAME] in self.parent.enabled_features)): self.xmlstream.addObserver( IQ_HTTP_UPLOAD_REQUEST, self.plugin_parent.onComponentRequest, client=self.parent ) def getDiscoInfo(self, requestor, target, nodeIdentifier=""): - return [disco.DiscoFeature(NS_HTTP_UPLOAD)] + if ((self.parent.is_component + and not PLUGIN_INFO[C.PI_IMPORT_NAME] in self.parent.enabled_features)): + return [] + else: + return [disco.DiscoFeature(NS_HTTP_UPLOAD)] def getDiscoItems(self, requestor, target, nodeIdentifier=""): return []