diff sat/plugins/plugin_comp_file_sharing.py @ 3291:449dfbfcdbcc

component file sharing: don't initialise the plugin if not component use it
author Goffi <goffi@goffi.org>
date Mon, 01 Jun 2020 11:15:16 +0200
parents 9057713ab124
children da443cf946ad
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_file_sharing.py	Mon Jun 01 11:14:20 2020 +0200
+++ b/sat/plugins/plugin_comp_file_sharing.py	Mon Jun 01 11:15:16 2020 +0200
@@ -293,24 +293,34 @@
 class FileSharing:
 
     def __init__(self, host):
+        self.host = host
+        self.initialised = False
+
+    def init(self):
+        # we init once on first component connection,
+        # there is not need to init this plugin if not component use it
+        # TODO: this plugin should not be loaded at all if no component uses it
+        #   and should be loaded dynamically as soon as a suitable profile is created
+        if self.initialised:
+            return
+        self.initialised = True
         log.info(_("File Sharing initialization"))
-        self.host = host
-        self._f = host.plugins["FILE"]
-        self._jf = host.plugins["XEP-0234"]
-        self._h = host.plugins["XEP-0300"]
-        self._t = host.plugins["XEP-0264"]
-        host.plugins["XEP-0363"].registerHandler(self._onHTTPUpload)
-        host.trigger.add("FILE_getDestDir", self._getDestDirTrigger)
-        host.trigger.add(
+        self._f = self.host.plugins["FILE"]
+        self._jf = self.host.plugins["XEP-0234"]
+        self._h = self.host.plugins["XEP-0300"]
+        self._t = self.host.plugins["XEP-0264"]
+        self.host.plugins["XEP-0363"].registerHandler(self._onHTTPUpload)
+        self.host.trigger.add("FILE_getDestDir", self._getDestDirTrigger)
+        self.host.trigger.add(
             "XEP-0234_fileSendingRequest", self._fileSendingRequestTrigger, priority=1000
         )
-        host.trigger.add("XEP-0234_buildFileElement", self._addFileComments)
-        host.trigger.add("XEP-0234_parseFileElement", self._getFileComments)
-        host.trigger.add("XEP-0329_compGetFilesFromNode", self._addCommentsData)
-        self.files_path = host.getLocalPath(None, C.FILES_DIR, profile=False)
-        self.http_port = host.memory.getConfig(
+        self.host.trigger.add("XEP-0234_buildFileElement", self._addFileComments)
+        self.host.trigger.add("XEP-0234_parseFileElement", self._getFileComments)
+        self.host.trigger.add("XEP-0329_compGetFilesFromNode", self._addCommentsData)
+        self.files_path = self.host.getLocalPath(None, C.FILES_DIR, profile=False)
+        self.http_port = self.host.memory.getConfig(
             'component file_sharing', 'http_upload_port', 8888)
-        connection_type = host.memory.getConfig(
+        connection_type = self.host.memory.getConfig(
             'component file_sharing', 'http_upload_connection_type', 'https')
         if connection_type not in ('http', 'https'):
             raise exceptions.ConfigError(
@@ -321,7 +331,7 @@
         if connection_type == 'http':
             reactor.listenTCP(self.http_port, self.server)
         else:
-            options = tls.getOptionsFromConfig(host.memory.config, "component file_sharing")
+            options = tls.getOptionsFromConfig(self.host.memory.config, "component file_sharing")
             tls.TLSOptionsCheck(options)
             context_factory = tls.getTLSContextFactory(options)
             reactor.listenSSL(self.http_port, self.server, context_factory)
@@ -331,6 +341,7 @@
         return Comments_handler(self)
 
     def profileConnecting(self, client):
+        self.init()
         public_base_url = self.host.memory.getConfig(
             'component file_sharing', 'http_upload_public_facing_url')
         if public_base_url is None: