OpenVPN 3 Core Library
Loading...
Searching...
No Matches
parseutil.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// Source: pkg:github/chriskohlhoff/asio@asio-1-8-0#asio/src/examples/http
13// Adapted from code Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
14//
15// Distributed under the Boost Software License, Version 1.0. (See accompanying
16// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
17
18// Common utility methods for HTTP classes
19
20#ifndef OPENVPN_HTTP_PARSEUTIL_H
21#define OPENVPN_HTTP_PARSEUTIL_H
22
24
25// Check if a byte is an HTTP character.
26inline bool is_char(const unsigned char c)
27{
28 return c <= 127;
29}
30
31// Check if a byte is an HTTP control character.
32inline bool is_ctl(const unsigned char c)
33{
34 return (c <= 31) || (c == 127);
35}
36
37// Check if a byte is defined as an HTTP tspecial character.
38inline bool is_tspecial(const unsigned char c)
39{
40 switch (c)
41 {
42 case '(':
43 case ')':
44 case '<':
45 case '>':
46 case '@':
47 case ',':
48 case ';':
49 case ':':
50 case '\\':
51 case '"':
52 case '/':
53 case '[':
54 case ']':
55 case '?':
56 case '=':
57 case '{':
58 case '}':
59 case ' ':
60 case '\t':
61 return true;
62 default:
63 return false;
64 }
65}
66
67// Check if a byte is a digit.
68inline bool is_digit(const unsigned char c)
69{
70 return c >= '0' && c <= '9';
71}
72
73// Check if char should be URL-escaped
74inline bool is_escaped(const unsigned char c)
75{
76 if (c >= 'a' && c <= 'z')
77 return false;
78 if (c >= 'A' && c <= 'Z')
79 return false;
80 if (c >= '0' && c <= '9')
81 return false;
82 if (c == '.' || c == '-' || c == '_')
83 return false;
84 return true;
85}
86} // namespace openvpn::HTTP::Util
87
88#endif
bool is_char(const unsigned char c)
Definition parseutil.hpp:26
bool is_digit(const unsigned char c)
Definition parseutil.hpp:68
bool is_tspecial(const unsigned char c)
Definition parseutil.hpp:38
bool is_ctl(const unsigned char c)
Definition parseutil.hpp:32
bool is_escaped(const unsigned char c)
Definition parseutil.hpp:74