LCOV - code coverage report
Current view: top level - src/plugin - jamipluginmanager.h (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 2 3 66.7 %
Date: 2024-04-23 08:02:50 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2020-2024 Savoir-faire Linux Inc.
       3             :  *
       4             :  *  Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
       5             :  *
       6             :  *  This program is free software; you can redistribute it and/or modify
       7             :  *  it under the terms of the GNU General Public License as published by
       8             :  *  the Free Software Foundation; either version 3 of the License, or
       9             :  *  (at your option) any later version.
      10             :  *
      11             :  *  This program is distributed in the hope that it will be useful,
      12             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  *  GNU General Public License for more details.
      15             :  *
      16             :  *  You should have received a copy of the GNU General Public License
      17             :  *  along with this program; if not, write to the Free Software
      18             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      19             :  */
      20             : 
      21             : #pragma once
      22             : 
      23             : #include "noncopyable.h"
      24             : #include "plugin/webviewservicesmanager.h"
      25             : #include "pluginmanager.h"
      26             : #include "pluginpreferencesutils.h"
      27             : 
      28             : #include "callservicesmanager.h"
      29             : #include "chatservicesmanager.h"
      30             : #include "preferenceservicesmanager.h"
      31             : #include <opendht/crypto.h>
      32             : #include <vector>
      33             : #include <map>
      34             : #include <list>
      35             : #include <algorithm>
      36             : 
      37             : namespace jami {
      38             : 
      39             : using PreferencesMap = std::map<std::string, std::map<std::string, std::string>>;
      40             : 
      41             : /**
      42             :  * @class  JamiPluginManager
      43             :  * @brief This class provides an interface to functions exposed to the
      44             :  * Plugin System interface for lrc and clients.
      45             :  */
      46             : class JamiPluginManager
      47             : {
      48             : public:
      49             :     JamiPluginManager();
      50             : 
      51             :     /**
      52             :      * @brief get the plugin's author
      53             :      * @param rootPath
      54             :      * @param pluginId
      55             :      * @return string
      56             :     */
      57             :     std::string getPluginAuthor(const std::string& rootPath, const std::string& pluginId);
      58             : 
      59             :     /**
      60             :      * @brief Parses a manifest file and return its content
      61             :      * along with other internally added values.
      62             :      * @param rootPath installation path
      63             :      * @param reset If true, overrides previous details values
      64             :      *              Reset is only used in the UT for now, but it can be useful
      65             :      *              if we want to reset plugins language without restarting the application
      66             :      * @return Map where the keyset is {"id", "name", "description", "version", "iconPath", "backgroundPath","soPath"}
      67             :      */
      68             :     std::map<std::string, std::string> getPluginDetails(const std::string& rootPath, bool reset = false);
      69             : 
      70             :     /**
      71             :      * @brief Returns a vector with installed plugins
      72             :      */
      73             :     std::vector<std::string> getInstalledPlugins();
      74             : 
      75             :     /**
      76             :      * @brief Check the validity of a plugin certificate
      77             :      * @param cert
      78             :      * @return true if valid
      79             :     */
      80             :     bool checkPluginCertificateValidity(dht::crypto::Certificate* cert);
      81             : 
      82             :     /**
      83             :      * @brief check if the if the public key of the certificate is the same as the public key in the new plugin
      84             :      * @param oldJplPath, newJplPath
      85             :      * return true if valid
      86             :     */
      87             :     bool checkPluginCertificatePublicKey(const std::string& oldJplPath, const std::string& newJplPath);
      88             : 
      89             :     /**
      90             :      * @brief check if all file are present in the signature file
      91             :      * @param jplPath
      92             :      * return true if valid
      93             :     */
      94             :     bool checkPluginSignatureFile(const std::string& jplPath);
      95             : 
      96             :     /**
      97             :      * @brief Check the validity of a plugin signature
      98             :      * @param jplPath
      99             :      * @param cert
     100             :      * @return true if valid
     101             :     */
     102             :     bool checkPluginSignatureValidity(const std::string& jplPath, dht::crypto::Certificate* cert);
     103             : 
     104             :     /**
     105             :      * @brief Checks if the plugin signature mechanism is valid by signature of files and each files is signed.
     106             :      * @param jplPath
     107             :      * @param
     108             :      * @return true if the plugin signature is valid
     109             :      *
     110             :     */
     111             :     bool checkPluginSignature(const std::string& jplPath, dht::crypto::Certificate* cert);
     112             : 
     113             :     /**
     114             :      * @brief Checks if the certificate mechanism is valid by checking certificate of the plugin
     115             :      * @param jplPath
     116             :      * @param force
     117             :      * @return return certificate if valid
     118             :     */
     119             :     std::unique_ptr<dht::crypto::Certificate> checkPluginCertificate(const std::string& jplPath, bool force);
     120             : 
     121             :     /**
     122             :      * @brief Checks if the plugin has a valid manifest, installs the plugin if not
     123             :      * previously installed or if installing a newer version of it.
     124             :      * @param jplPath
     125             :      * @param force If true, allows installing an older plugin version.
     126             :      * @return 0 if success
     127             :      * 100 if already installed with similar version
     128             :      * 200 if already installed with newer version
     129             :      * libarchive (mizip in apple platforms) error codes otherwise
     130             :      */
     131             :     int installPlugin(const std::string& jplPath, bool force);
     132             : 
     133             :     /**
     134             :      * @brief Checks if the plugin has a valid manifest and if the plugin is loaded,
     135             :      * tries to unload it and then removes plugin folder.
     136             :      * @param rootPath
     137             :      * @return 0 if success
     138             :      */
     139             :     int uninstallPlugin(const std::string& rootPath);
     140             : 
     141             :     /**
     142             :      * @brief Returns True if success
     143             :      * @param rootPath of the plugin folder
     144             :      */
     145             :     bool loadPlugin(const std::string& rootPath);
     146             : 
     147             :     /**
     148             :      * @brief Returns True if success
     149             :     */
     150             :     bool loadPlugins();
     151             : 
     152             :     /**
     153             :      * @brief Returns True if success
     154             :      * @param rootPath of the plugin folder
     155             :      */
     156             :     bool unloadPlugin(const std::string& rootPath);
     157             : 
     158             :     /**
     159             :      * @brief Returns vector with rootpaths of the loaded plugins
     160             :      */
     161             :     std::vector<std::string> getLoadedPlugins() const;
     162             : 
     163             :     /**
     164             :      * @brief Returns contents of plugin's preferences.json file
     165             :      * @param rootPath
     166             :      * @param accountId
     167             :      */
     168             :     std::vector<std::map<std::string, std::string>> getPluginPreferences(
     169             :         const std::string& rootPath, const std::string& accountId);
     170             : 
     171             :     /**
     172             :      * @brief Returns a Map with preferences keys and values.
     173             :      * @param rootPath
     174             :      * @param accountId
     175             :      */
     176             :     std::map<std::string, std::string> getPluginPreferencesValuesMap(const std::string& rootPath,
     177             :                                                                      const std::string& accountId);
     178             : 
     179             :     /**
     180             :      * @brief Returns a Map of platform system.
     181             :      */
     182             :     std::map<std::string, std::string> getPlatformInfo();
     183             : 
     184             :     /**
     185             :      * @brief Modifies a preference value by saving it to a preferences.msgpack.
     186             :      * Plugin is reloaded only if the preference cannot take effect immediately.
     187             :      * In other words, if we have to reload plugin so that preference may take effect.
     188             :      * @param rootPath
     189             :      * @param accountId
     190             :      * @param key
     191             :      * @param value
     192             :      * @return True if success
     193             :      */
     194             :     bool setPluginPreference(const std::filesystem::path& rootPath,
     195             :                              const std::string& accountId,
     196             :                              const std::string& key,
     197             :                              const std::string& value);
     198             : 
     199             :     /**
     200             :      * @brief Reset plugin's preferences values to their defaultValues
     201             :      * @param rootPath
     202             :      * @param accountId
     203             :      * @return True if success.
     204             :      */
     205             :     bool resetPluginPreferencesValuesMap(const std::string& rootPath, const std::string& accountId);
     206             : 
     207        1726 :     CallServicesManager& getCallServicesManager() { return callsm_; }
     208             : 
     209        2072 :     ChatServicesManager& getChatServicesManager() { return chatsm_; }
     210             : 
     211           0 :     WebViewServicesManager& getWebViewServicesManager() { return webviewsm_; }
     212             : 
     213             :     PreferenceServicesManager& getPreferenceServicesManager() { return preferencesm_; }
     214             : 
     215             : #ifdef LIBJAMI_TESTABLE
     216             :     void addPluginAuthority(const dht::crypto::Certificate& cert);
     217             : #endif
     218             : 
     219             : private:
     220             :     NON_COPYABLE(JamiPluginManager);
     221             : 
     222             :     /**
     223             :      * @brief Register services that can be called from plugin implementation side.
     224             :      */
     225             :     void registerServices();
     226             : 
     227             :     // PluginManager instance
     228             :     PluginManager pm_;
     229             :     dht::crypto::TrustList trust_;
     230             :     // Map between plugins installation path and manifest infos.
     231             :     std::map<std::string, std::map<std::string, std::string>> pluginDetailsMap_;
     232             : 
     233             :     // Services instances
     234             :     CallServicesManager callsm_;
     235             :     ChatServicesManager chatsm_;
     236             :     WebViewServicesManager webviewsm_;
     237             :     PreferenceServicesManager preferencesm_;
     238             : };
     239             : } // namespace jami

Generated by: LCOV version 1.14