# HG changeset patch # User Sebastien Jodogne # Date 1717593835 -7200 # Node ID 55435a4dd2c687a6a37c71f453a4609cc3119013 # Parent de232f9b3a60ffdf2f4a376b69d4426e98b6acba cppcheck diff -r de232f9b3a60 -r 55435a4dd2c6 Plugin/PermissionParser.cpp --- a/Plugin/PermissionParser.cpp Wed Jun 05 15:08:41 2024 +0200 +++ b/Plugin/PermissionParser.cpp Wed Jun 05 15:23:55 2024 +0200 @@ -26,9 +26,11 @@ namespace OrthancPlugins { - PermissionPattern::PermissionPattern(const OrthancPluginHttpMethod& method, const std::string& patternRegex, const std::string& permissions) : - method(method), - pattern(patternRegex) + PermissionPattern::PermissionPattern(const OrthancPluginHttpMethod& method, + const std::string& patternRegex, + const std::string& permissions) : + method_(method), + pattern_(patternRegex) { if (!permissions.empty()) { @@ -37,7 +39,7 @@ for (size_t i = 0; i < permissionsVector.size(); ++i) { - this->permissions.insert(permissionsVector[i]); + permissions_.insert(permissionsVector[i]); } } } @@ -72,6 +74,16 @@ { } + PermissionParser::~PermissionParser() + { + for (std::list::iterator it = permissionsPattern_.begin(); + it != permissionsPattern_.begin(); ++it) + { + assert(*it != NULL); + delete *it; + } + } + void PermissionParser::Add(const Json::Value& configuration, const IAuthorizationParser* authorizationParser) { if (configuration.type() != Json::arrayValue) @@ -150,7 +162,7 @@ LOG(WARNING) << "Authorization plugin: adding a new permission pattern: " << lowerCaseMethod << " " << regex << " - " << permission; - permissionsPattern_.push_back(PermissionPattern(parsedMethod, regex, permission)); + permissionsPattern_.push_back(new PermissionPattern(parsedMethod, regex, permission)); } bool PermissionParser::Parse(std::set& permissions, @@ -163,16 +175,16 @@ boost::mutex::scoped_lock lock(mutex_); - for (std::list::const_iterator it = permissionsPattern_.begin(); - it != permissionsPattern_.end(); ++it) + for (std::list::const_iterator it = permissionsPattern_.begin(); + it != permissionsPattern_.end(); ++it) { - if (method == it->method) + if (method == (*it)->GetMethod()) { boost::smatch what; - if (boost::regex_match(uri, what, it->pattern)) + if (boost::regex_match(uri, what, (*it)->GetPattern())) { - matchedPattern = it->pattern.expression(); - permissions = it->permissions; + matchedPattern = (*it)->GetPattern().expression(); + permissions = (*it)->GetPermissions(); return true; } } diff -r de232f9b3a60 -r 55435a4dd2c6 Plugin/PermissionParser.h --- a/Plugin/PermissionParser.h Wed Jun 05 15:08:41 2024 +0200 +++ b/Plugin/PermissionParser.h Wed Jun 05 15:23:55 2024 +0200 @@ -27,20 +27,39 @@ namespace OrthancPlugins { - struct PermissionPattern + class PermissionPattern : public boost::noncopyable { - OrthancPluginHttpMethod method; - boost::regex pattern; - std::set permissions; + private: + OrthancPluginHttpMethod method_; + boost::regex pattern_; + std::set permissions_; + + public: + PermissionPattern(const OrthancPluginHttpMethod& method, + const std::string& patternRegex, + const std::string& permissions); - PermissionPattern(const OrthancPluginHttpMethod& method, const std::string& patternRegex, const std::string& permissions); + OrthancPluginHttpMethod GetMethod() const + { + return method_; + } + + const boost::regex& GetPattern() const + { + return pattern_; + } + + const std::set& GetPermissions() const + { + return permissions_; + } }; - class PermissionParser + class PermissionParser : public boost::noncopyable { private: mutable boost::mutex mutex_; - std::list permissionsPattern_; + std::list permissionsPattern_; std::string dicomWebRoot_; std::string oe2Root_; @@ -48,6 +67,8 @@ PermissionParser(const std::string& dicomWebRoot, const std::string& oe2Root); + ~PermissionParser(); + void Add(const std::string& method, const std::string& patternRegex, const std::string& permission); diff -r de232f9b3a60 -r 55435a4dd2c6 Plugin/Token.h --- a/Plugin/Token.h Wed Jun 05 15:08:41 2024 +0200 +++ b/Plugin/Token.h Wed Jun 05 15:23:55 2024 +0200 @@ -22,9 +22,11 @@ #include "Enumerations.h" +#include + namespace OrthancPlugins { - class Token + class Token : public boost::noncopyable { private: TokenType type_;