comparison sat/plugins/plugin_comp_file_sharing.py @ 4021:412b99c29d83

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.
author Goffi <goffi@goffi.org>
date Thu, 23 Mar 2023 15:38:07 +0100
parents 7af29260ecb8
children 524856bd7b19
comparison
equal deleted inserted replaced
4020:d8a1219e913f 4021:412b99c29d83
353 self._f = self.host.plugins["FILE"] 353 self._f = self.host.plugins["FILE"]
354 self._jf = self.host.plugins["XEP-0234"] 354 self._jf = self.host.plugins["XEP-0234"]
355 self._h = self.host.plugins["XEP-0300"] 355 self._h = self.host.plugins["XEP-0300"]
356 self._t = self.host.plugins["XEP-0264"] 356 self._t = self.host.plugins["XEP-0264"]
357 self._hu = self.host.plugins["XEP-0363"] 357 self._hu = self.host.plugins["XEP-0363"]
358 self._hu.registerHandler(self._onHTTPUpload) 358 self._hu.registerHandler(self._on_http_upload)
359 self.host.trigger.add("FILE_getDestDir", self._getDestDirTrigger) 359 self.host.trigger.add("FILE_getDestDir", self._getDestDirTrigger)
360 self.host.trigger.add( 360 self.host.trigger.add(
361 "XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000 361 "XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000
362 ) 362 )
363 self.host.trigger.add("XEP-0234_buildFileElement", self._addFileMetadataElts) 363 self.host.trigger.add("XEP-0234_buildFileElement", self._addFileMetadataElts)
391 391
392 def getHandler(self, client): 392 def getHandler(self, client):
393 return Comments_handler(self) 393 return Comments_handler(self)
394 394
395 def profileConnecting(self, client): 395 def profileConnecting(self, client):
396 # we activate HTTP upload
397 client.enabled_features.add("XEP-0363")
398
396 self.init() 399 self.init()
397 public_base_url = self.host.memory.getConfig( 400 public_base_url = self.host.memory.getConfig(
398 'component file-sharing', 'http_upload_public_facing_url') 401 'component file-sharing', 'http_upload_public_facing_url')
399 if public_base_url is None: 402 if public_base_url is None:
400 client._file_sharing_base_url = f"https://{client.host}:{self.http_port}" 403 client._file_sharing_base_url = f"https://{client.host}:{self.http_port}"
630 try: 633 try:
631 del self.expected_uploads[upload_id] 634 del self.expected_uploads[upload_id]
632 except KeyError: 635 except KeyError:
633 log.error(f"trying to purge an inexisting upload slot ({upload_id})") 636 log.error(f"trying to purge an inexisting upload slot ({upload_id})")
634 637
635 async def _onHTTPUpload(self, client, request): 638 async def _on_http_upload(self, client, request):
636 # filename should be already cleaned, but it's better to double check 639 # filename should be already cleaned, but it's better to double check
637 assert '/' not in request.filename 640 assert '/' not in request.filename
638 # client._file_sharing_allowed_hosts is set in plugin XEP-0329 641 # client._file_sharing_allowed_hosts is set in plugin XEP-0329
639 if request.from_.host not in client._file_sharing_allowed_hosts: 642 if request.from_.host not in client._file_sharing_allowed_hosts:
640 raise error.StanzaError("forbidden") 643 raise error.StanzaError("forbidden")