diff --git a/src/plugin/jamipluginmanager.cpp b/src/plugin/jamipluginmanager.cpp index 687138f18b57e737d31dc2a51a5cda2a19808df7..f25c5e9bbc907982fe8987bd7df00b70177dcbea 100644 --- a/src/plugin/jamipluginmanager.cpp +++ b/src/plugin/jamipluginmanager.cpp @@ -56,6 +56,17 @@ namespace jami { +std::string +JamiPluginManager::getPluginAuthor(const std::string& rootPath, const std::string& pluginId) +{ + auto cert = PluginUtils::readPluginCertificate(rootPath, pluginId); + if (!cert) { + JAMI_ERROR("Could not read plugin certificate"); + return {}; + } + return cert->getIssuerName(); +} + std::map<std::string, std::string> JamiPluginManager::getPluginDetails(const std::string& rootPath) { @@ -67,9 +78,14 @@ JamiPluginManager::getPluginDetails(const std::string& rootPath) std::map<std::string, std::string> details = PluginUtils::parseManifestFile( PluginUtils::manifestPath(rootPath)); if (!details.empty()) { - auto it = details.find("iconPath"); - it->second.insert(0, rootPath + DIR_SEPARATOR_CH + "data" + DIR_SEPARATOR_CH); + auto itIcon = details.find("iconPath"); + itIcon->second.insert(0, rootPath + DIR_SEPARATOR_CH + "data" + DIR_SEPARATOR_CH); + + auto itImage = details.find("backgroundPath"); + itImage->second.insert(0, rootPath + DIR_SEPARATOR_CH + "data" + DIR_SEPARATOR_CH); + details["soPath"] = rootPath + DIR_SEPARATOR_CH + LIB_PREFIX + details["name"] + LIB_TYPE; + details["author"] = getPluginAuthor(rootPath, details["name"]); detailsIt = pluginDetailsMap_.emplace(rootPath, std::move(details)).first; return detailsIt->second; } diff --git a/src/plugin/jamipluginmanager.h b/src/plugin/jamipluginmanager.h index 4db47d46856e96808d76199422fed9f9f02295a7..aaa10eba81592fbfeb815304a5b7014990fc7d8d 100644 --- a/src/plugin/jamipluginmanager.h +++ b/src/plugin/jamipluginmanager.h @@ -55,11 +55,19 @@ public: registerServices(); } + /** + * @brief get the plugin's author + * @param rootPath + * @param pluginId + * @return string + */ + std::string getPluginAuthor(const std::string& rootPath, const std::string& pluginId); + /** * @brief Parses a manifest file and return its content * along with other internally added values. * @param rootPath installation path - * @return Map where the keyset is {"name", "description", "version", "iconPath", "soPath"} + * @return Map where the keyset is {"id", "name", "description", "version", "iconPath", "imagePath","soPath"} */ std::map<std::string, std::string> getPluginDetails(const std::string& rootPath); diff --git a/src/plugin/pluginsutils.cpp b/src/plugin/pluginsutils.cpp index 9e870b7fbc958167296f0feaec123db5abb3bd77..b5eb85bc7711d9232a2d5b4d5669e2ac665a34d2 100644 --- a/src/plugin/pluginsutils.cpp +++ b/src/plugin/pluginsutils.cpp @@ -94,11 +94,14 @@ checkManifestJsonContentValidity(const Json::Value& root) std::string description = root.get("description", "").asString(); std::string version = root.get("version", "").asString(); std::string iconPath = root.get("iconPath", "icon.png").asString(); + std::string background = root.get("backgroundPath", "background.jpg").asString(); if (!name.empty() || !version.empty()) { return {{"name", name}, {"description", description}, {"version", version}, - {"iconPath", iconPath}}; + {"iconPath", iconPath}, + {"backgroundPath", background}, + }; } else { throw std::runtime_error("plugin manifest file: bad format"); } @@ -170,6 +173,19 @@ readPluginManifestFromArchive(const std::string& jplPath) return {}; } +std::unique_ptr<dht::crypto::Certificate> +readPluginCertificate(const std::string& rootPath, const std::string& pluginId) +{ + std::string certPath = rootPath + DIR_SEPARATOR_CH + pluginId + ".crt"; + try { + auto cert = fileutils::loadFile(certPath); + return std::make_unique<dht::crypto::Certificate>(cert); + } catch (const std::exception& e) { + JAMI_ERR() << e.what(); + } + return {}; +} + std::unique_ptr<dht::crypto::Certificate> readPluginCertificateFromArchive(const std::string& jplPath) { try { @@ -215,14 +231,14 @@ uncompressJplFunction(std::string_view relativeFileName) // manifest.json and files under data/ folder remains in the same structure // but libraries files are extracted from the folder that matches the running ABI to // the main installation path. - if (relativeFileName == "manifest.json" || std::regex_match(relativeFileName, DATA_REGEX)) { - return std::make_pair(true, relativeFileName); - } else if (std::regex_search(relativeFileName, match, SO_REGEX)) { - if (std::svsub_match_view(match[1]) == ABI) { + if (std::regex_search(relativeFileName, match, SO_REGEX)) { + if (std::svsub_match_view(match[1]) != ABI) { + return std::make_pair(false, std::string_view {}); + } else { return std::make_pair(true, std::svsub_match_view(match[2])); } } - return std::make_pair(false, std::string_view {}); + return std::make_pair(true, relativeFileName); } } // namespace PluginUtils } // namespace jami diff --git a/src/plugin/pluginsutils.h b/src/plugin/pluginsutils.h index 0f40aa871deda6378b2b7e1f3a24fe0c696bf808..adccd201bd43fa3407fee4bba252adc40f446e03 100644 --- a/src/plugin/pluginsutils.h +++ b/src/plugin/pluginsutils.h @@ -98,6 +98,13 @@ bool checkPluginValidity(const std::string& rootPath); */ std::map<std::string, std::string> readPluginManifestFromArchive(const std::string& jplPath); +/** + * @brief Read the plugin's certificate + * @param rootPath + * @param pluginId + * @return Certificate object pointer +*/ +std::unique_ptr<dht::crypto::Certificate> readPluginCertificate(const std::string& rootPath, const std::string& pluginId); /** * @brief Read plugin certificate without uncompressing the whole archive.and * return an object Certificate