OpenVPN 3 Core Library
Loading...
Searching...
No Matches
iperr.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// Called internally by IP, IPv4, and IPv6 classes
13
14#pragma once
15
16#include <string>
17
18#include <openvpn/io/io.hpp>
19
20#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
22#endif
23
25
26#ifndef OPENVPN_LEGACY_TITLE_ABSTRACTION
27
28template <typename TITLE>
29inline std::string format_error(const std::string &ipstr,
30 const TITLE &title,
31 const char *ipver,
32 const std::string &message)
33{
34 std::string err = "error parsing";
35 if (!StringTempl::empty(title))
36 {
37 err += ' ';
38 err += StringTempl::to_string(title);
39 }
40 err += " IP";
41 err += ipver;
42 err += " address '";
43 err += ipstr;
44 err += '\'';
45 if (!message.empty())
46 {
47 err += " : ";
48 err += message;
49 }
50 return err;
51}
52
53template <typename TITLE>
54inline std::string format_error(const std::string &ipstr,
55 const TITLE &title,
56 const char *ipver,
57 const openvpn_io::error_code &ec)
58{
59 return format_error(ipstr, title, ipver, ec.message());
60}
61
62#else
63
64inline std::string format_error(const std::string &ipstr, const char *title, const char *ipver, const openvpn_io::error_code &ec)
65{
66 std::string err = "error parsing";
67 if (title)
68 {
69 err += ' ';
70 err += title;
71 }
72 err += " IP";
73 err += ipver;
74 err += " address '";
75 err += ipstr;
76 err += "' : ";
77 err += ec.message();
78 return err;
79}
80
81inline std::string format_error(const std::string &ipstr, const char *title, const char *ipver, const char *message)
82{
83 std::string err = "error parsing";
84 if (title)
85 {
86 err += ' ';
87 err += title;
88 }
89 err += " IP";
90 err += ipver;
91 err += " address '";
92 err += ipstr;
93 err += '\'';
94 if (message)
95 {
96 err += " : ";
97 err += message;
98 }
99 return err;
100}
101
102#endif
103} // namespace openvpn::IP::internal
std::string format_error(const std::string &ipstr, const TITLE &title, const char *ipver, const std::string &message)
Definition iperr.hpp:29
std::string to_string(std::nullptr_t)
bool empty(std::nullptr_t)
const char message[]