OpenVPN 3 Core Library
Loading...
Searching...
No Matches
validate_uri.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12#pragma once
13
15
16namespace openvpn::HTTP {
17inline bool is_valid_uri_char(const unsigned char c)
18{
19 return c >= 0x21 && c <= 0x7E;
20}
21
22inline bool is_valid_uri_char(const char c)
23{
24 return is_valid_uri_char((unsigned char)c);
25}
26
27inline void validate_uri(const std::string &uri, const std::string &title)
28{
29 if (uri.empty())
30 throw Exception(title + " : URI is empty");
31 if (uri[0] != '/')
32 throw Exception(title + " : URI must begin with '/'");
33 for (auto &c : uri)
34 {
35 if (!is_valid_uri_char(c))
36 throw Exception(title + " : URI contains illegal character");
37 }
38}
39
40} // namespace openvpn::HTTP
bool is_valid_uri_char(const unsigned char c)
void validate_uri(const std::string &uri, const std::string &title)