Skip to content

Commit 0718a31

Browse files
committed
Add NameValueCollection::getAll method
1 parent fd81810 commit 0718a31

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

base/poco/Net/include/Poco/Net/NameValueCollection.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ namespace Net
7979
/// Returns the value of the first name-value pair with the given name.
8080
/// If no value with the given name has been found, the defaultValue is returned.
8181

82+
const std::vector<std::reference_wrapper<const std::string>> getAll(const std::string & name) const;
83+
/// Returns all values of all name-value pairs with the given name.
84+
///
85+
/// Returns an empty vector if there are no name-value pairs with the given name.
86+
8287
bool has(const std::string & name) const;
8388
/// Returns true if there is at least one name-value pair
8489
/// with the given name.

base/poco/Net/src/NameValueCollection.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "Poco/Net/NameValueCollection.h"
1616
#include "Poco/Exception.h"
1717
#include <algorithm>
18+
#include <functional>
1819

1920

2021
using Poco::NotFoundException;
@@ -55,7 +56,7 @@ void NameValueCollection::swap(NameValueCollection& nvc)
5556
std::swap(_map, nvc._map);
5657
}
5758

58-
59+
5960
const std::string& NameValueCollection::operator [] (const std::string& name) const
6061
{
6162
ConstIterator it = _map.find(name);
@@ -65,8 +66,8 @@ const std::string& NameValueCollection::operator [] (const std::string& name) co
6566
throw NotFoundException(name);
6667
}
6768

68-
69-
void NameValueCollection::set(const std::string& name, const std::string& value)
69+
70+
void NameValueCollection::set(const std::string& name, const std::string& value)
7071
{
7172
Iterator it = _map.find(name);
7273
if (it != _map.end())
@@ -75,13 +76,13 @@ void NameValueCollection::set(const std::string& name, const std::string& value)
7576
_map.insert(HeaderMap::ValueType(name, value));
7677
}
7778

78-
79+
7980
void NameValueCollection::add(const std::string& name, const std::string& value)
8081
{
8182
_map.insert(HeaderMap::ValueType(name, value));
8283
}
8384

84-
85+
8586
const std::string& NameValueCollection::get(const std::string& name) const
8687
{
8788
ConstIterator it = _map.find(name);
@@ -101,6 +102,15 @@ const std::string& NameValueCollection::get(const std::string& name, const std::
101102
return defaultValue;
102103
}
103104

105+
const std::vector<std::reference_wrapper<const std::string>> NameValueCollection::getAll(const std::string& name) const
106+
{
107+
std::vector<std::reference_wrapper<const std::string>> values;
108+
for (ConstIterator it = _map.find(name); it != _map.end(); it++)
109+
if (it->first == name)
110+
values.push_back(it->second);
111+
return values;
112+
}
113+
104114

105115
bool NameValueCollection::has(const std::string& name) const
106116
{
@@ -113,19 +123,19 @@ NameValueCollection::ConstIterator NameValueCollection::find(const std::string&
113123
return _map.find(name);
114124
}
115125

116-
126+
117127
NameValueCollection::ConstIterator NameValueCollection::begin() const
118128
{
119129
return _map.begin();
120130
}
121131

122-
132+
123133
NameValueCollection::ConstIterator NameValueCollection::end() const
124134
{
125135
return _map.end();
126136
}
127137

128-
138+
129139
bool NameValueCollection::empty() const
130140
{
131141
return _map.empty();

src/Server/HTTPHandler.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -734,22 +734,19 @@ void HTTPHandler::processQuery(
734734
return false;
735735
};
736736

737-
auto role_params_it = params.find("role");
738-
if (role_params_it != params.end())
737+
auto roles = params.getAll("role");
738+
if (!roles.empty())
739739
{
740-
std::vector<UUID> roles_ids;
741740
const auto & access_control = context->getAccessControl();
742741
const auto & user = context->getUser();
743-
for (; role_params_it != params.end(); role_params_it++)
742+
std::vector<UUID> roles_ids(roles.size());
743+
for (size_t i = 0; i < roles.size(); i++)
744744
{
745-
if (role_params_it->first == "role")
746-
{
747-
auto role_id = access_control.getID<Role>(role_params_it->second);
748-
if (user->granted_roles.isGranted(role_id))
749-
roles_ids.push_back(role_id);
750-
else
751-
throw Exception(ErrorCodes::SET_NON_GRANTED_ROLE, "Role {} should be granted to set as a current", role_params_it->second);
752-
}
745+
auto role_id = access_control.getID<Role>(roles[i]);
746+
if (user->granted_roles.isGranted(role_id))
747+
roles_ids[i] = role_id;
748+
else
749+
throw Exception(ErrorCodes::SET_NON_GRANTED_ROLE, "Role {} should be granted to set as a current", roles[i].get());
753750
}
754751
context->setCurrentRoles(roles_ids);
755752
}

0 commit comments

Comments
 (0)