mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 04:02:15 +02:00
URL::Parse: made is_valid_uri_char() standalone and moved to validate_uri.hpp
In validate_uri.hpp, added these new methods: * HTTP::is_valid_uri_char() * HTTP::validate_uri() Signed-off-by: James Yonan <james@openvpn.net>
This commit is contained in:
parent
2dcb18993c
commit
1502cf6946
@ -29,6 +29,7 @@
|
||||
#include <openvpn/common/string.hpp>
|
||||
#include <openvpn/common/hostport.hpp>
|
||||
#include <openvpn/common/format.hpp>
|
||||
#include <openvpn/http/validate_uri.hpp>
|
||||
#include <openvpn/http/parseutil.hpp>
|
||||
|
||||
namespace openvpn {
|
||||
@ -130,7 +131,7 @@ namespace openvpn {
|
||||
port += c;
|
||||
break;
|
||||
case URI:
|
||||
if (!is_valid_uri_char(c) && !loose_validation)
|
||||
if (!HTTP::is_valid_uri_char(c) && !loose_validation)
|
||||
throw url_parse_error("bad URI char");
|
||||
uri += c;
|
||||
break;
|
||||
@ -253,11 +254,6 @@ namespace openvpn {
|
||||
{
|
||||
return (c >= 'a' && c <= 'z') || c == '_';
|
||||
}
|
||||
|
||||
bool is_valid_uri_char(const char c)
|
||||
{
|
||||
return !HTTP::Util::is_ctl(c) && c != ' ';
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
52
openvpn/http/validate_uri.hpp
Normal file
52
openvpn/http/validate_uri.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
// OpenVPN -- An application to securely tunnel IP networks
|
||||
// over a single port, with support for SSL/TLS-based
|
||||
// session authentication and key exchange,
|
||||
// packet encryption, packet authentication, and
|
||||
// packet compression.
|
||||
//
|
||||
// Copyright (C) 2012-2017 OpenVPN Technologies, Inc.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License Version 3
|
||||
// as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program in the COPYING file.
|
||||
// If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <openvpn/common/exception.hpp>
|
||||
|
||||
namespace openvpn {
|
||||
namespace HTTP {
|
||||
inline bool is_valid_uri_char(const unsigned char c)
|
||||
{
|
||||
return c >= 0x21 && c <= 0x7E;
|
||||
}
|
||||
|
||||
inline bool is_valid_uri_char(const char c)
|
||||
{
|
||||
return is_valid_uri_char((unsigned char)c);
|
||||
}
|
||||
|
||||
inline void validate_uri(const std::string& uri, const std::string& title)
|
||||
{
|
||||
if (uri.empty())
|
||||
throw Exception(title + " : URI is empty");
|
||||
if (uri[0] != '/')
|
||||
throw Exception(title + " : URI must begin with '/'");
|
||||
for (auto &c : uri)
|
||||
{
|
||||
if (!is_valid_uri_char(c))
|
||||
throw Exception(title + " : URI contains illegal character");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user