Skip to content
Snippets Groups Projects
Commit 23fb59a8 authored by Xavier Jouslin de Noray's avatar Xavier Jouslin de Noray
Browse files

Author: add logic to fetch author from plugin

Change-Id: Ieaf7be990fd5f0b150212aa3b0c2f14026ca3029
parent 3a5ee70f
Branches
Tags
No related merge requests found
......@@ -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;
}
......
......@@ -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);
......
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment