示例#1
0
bool
ConnectHandouts::try_insert (beast::IP::Endpoint const& endpoint)
{
    if (full ())
        return false;

    // Make sure the address isn't already in our list
    if (std::any_of (m_list.begin(), m_list.end(),
        [&endpoint](beast::IP::Endpoint const& other)
        {
            // Ignore port for security reasons
            return other.address() ==
                endpoint.address();
        }))
    {
        return false;
    }

    // Add to squelch list so we don't try it too often.
    // If its already there, then make try_insert fail.
    auto const result (m_squelches.insert (
        endpoint.address()));
    if (! result.second)
        return false;
    
    m_list.push_back (endpoint);

    return true;
}
示例#2
0
Role
requestRole (Role const& required, HTTP::Port const& port,
             Json::Value const& params, beast::IP::Endpoint const& remoteIp)
{
    Role role (Role::GUEST);
    if (isAdmin(port, params, remoteIp.address ()))
        role = Role::ADMIN;
    if (required == Role::ADMIN && role != required)
        role = Role::FORBID;
    return role;
}