mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
permission: mark const functions as such
Otherwise, non-mutating functions such as is_tree_granted unnecessarily require pointers to mutable data structures. PR-URL: https://github.com/nodejs/node/pull/50705 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
This commit is contained in:
@@ -15,7 +15,7 @@ void ChildProcessPermission::Apply(const std::vector<std::string>& allow,
|
||||
}
|
||||
|
||||
bool ChildProcessPermission::is_granted(PermissionScope perm,
|
||||
const std::string_view& param) {
|
||||
const std::string_view& param) const {
|
||||
return deny_all_ == false;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class ChildProcessPermission final : public PermissionBase {
|
||||
void Apply(const std::vector<std::string>& allow,
|
||||
PermissionScope scope) override;
|
||||
bool is_granted(PermissionScope perm,
|
||||
const std::string_view& param = "") override;
|
||||
const std::string_view& param = "") const override;
|
||||
|
||||
private:
|
||||
bool deny_all_;
|
||||
|
||||
@@ -50,8 +50,9 @@ void FreeRecursivelyNode(
|
||||
delete node;
|
||||
}
|
||||
|
||||
bool is_tree_granted(node::permission::FSPermission::RadixTree* granted_tree,
|
||||
const std::string_view& param) {
|
||||
bool is_tree_granted(
|
||||
const node::permission::FSPermission::RadixTree* granted_tree,
|
||||
const std::string_view& param) {
|
||||
#ifdef _WIN32
|
||||
// is UNC file path
|
||||
if (param.rfind("\\\\", 0) == 0) {
|
||||
@@ -147,7 +148,7 @@ void FSPermission::GrantAccess(PermissionScope perm, const std::string& res) {
|
||||
}
|
||||
|
||||
bool FSPermission::is_granted(PermissionScope perm,
|
||||
const std::string_view& param = "") {
|
||||
const std::string_view& param = "") const {
|
||||
switch (perm) {
|
||||
case PermissionScope::kFileSystem:
|
||||
return allow_all_in_ && allow_all_out_;
|
||||
@@ -171,7 +172,7 @@ FSPermission::RadixTree::~RadixTree() {
|
||||
}
|
||||
|
||||
bool FSPermission::RadixTree::Lookup(const std::string_view& s,
|
||||
bool when_empty_return = false) {
|
||||
bool when_empty_return = false) const {
|
||||
FSPermission::RadixTree::Node* current_node = root_node_;
|
||||
if (current_node->children.size() == 0) {
|
||||
return when_empty_return;
|
||||
|
||||
@@ -17,7 +17,8 @@ class FSPermission final : public PermissionBase {
|
||||
public:
|
||||
void Apply(const std::vector<std::string>& allow,
|
||||
PermissionScope scope) override;
|
||||
bool is_granted(PermissionScope perm, const std::string_view& param) override;
|
||||
bool is_granted(PermissionScope perm,
|
||||
const std::string_view& param) const override;
|
||||
|
||||
struct RadixTree {
|
||||
struct Node {
|
||||
@@ -72,7 +73,7 @@ class FSPermission final : public PermissionBase {
|
||||
return wildcard_child;
|
||||
}
|
||||
|
||||
Node* NextNode(const std::string& path, size_t idx) {
|
||||
Node* NextNode(const std::string& path, size_t idx) const {
|
||||
if (idx >= path.length()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -115,7 +116,7 @@ class FSPermission final : public PermissionBase {
|
||||
// ---> '\000' ASCII (0) || \0
|
||||
// ---> er
|
||||
// ---> n
|
||||
bool IsEndNode() {
|
||||
bool IsEndNode() const {
|
||||
if (children.size() == 0) {
|
||||
return true;
|
||||
}
|
||||
@@ -126,8 +127,8 @@ class FSPermission final : public PermissionBase {
|
||||
RadixTree();
|
||||
~RadixTree();
|
||||
void Insert(const std::string& s);
|
||||
bool Lookup(const std::string_view& s) { return Lookup(s, false); }
|
||||
bool Lookup(const std::string_view& s, bool when_empty_return);
|
||||
bool Lookup(const std::string_view& s) const { return Lookup(s, false); }
|
||||
bool Lookup(const std::string_view& s, bool when_empty_return) const;
|
||||
|
||||
private:
|
||||
Node* root_node_;
|
||||
|
||||
@@ -14,7 +14,7 @@ void InspectorPermission::Apply(const std::vector<std::string>& allow,
|
||||
}
|
||||
|
||||
bool InspectorPermission::is_granted(PermissionScope perm,
|
||||
const std::string_view& param) {
|
||||
const std::string_view& param) const {
|
||||
return deny_all_ == false;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class InspectorPermission final : public PermissionBase {
|
||||
void Apply(const std::vector<std::string>& allow,
|
||||
PermissionScope scope) override;
|
||||
bool is_granted(PermissionScope perm,
|
||||
const std::string_view& param = "") override;
|
||||
const std::string_view& param = "") const override;
|
||||
|
||||
private:
|
||||
bool deny_all_;
|
||||
|
||||
@@ -42,7 +42,7 @@ class PermissionBase {
|
||||
virtual void Apply(const std::vector<std::string>& allow,
|
||||
PermissionScope scope) = 0;
|
||||
virtual bool is_granted(PermissionScope perm,
|
||||
const std::string_view& param = "") = 0;
|
||||
const std::string_view& param = "") const = 0;
|
||||
};
|
||||
|
||||
} // namespace permission
|
||||
|
||||
@@ -15,7 +15,7 @@ void WorkerPermission::Apply(const std::vector<std::string>& allow,
|
||||
}
|
||||
|
||||
bool WorkerPermission::is_granted(PermissionScope perm,
|
||||
const std::string_view& param) {
|
||||
const std::string_view& param) const {
|
||||
return deny_all_ == false;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class WorkerPermission final : public PermissionBase {
|
||||
void Apply(const std::vector<std::string>& allow,
|
||||
PermissionScope scope) override;
|
||||
bool is_granted(PermissionScope perm,
|
||||
const std::string_view& param = "") override;
|
||||
const std::string_view& param = "") const override;
|
||||
|
||||
private:
|
||||
bool deny_all_;
|
||||
|
||||
Reference in New Issue
Block a user