Squid Web Cache master
Loading...
Searching...
No Matches
Host.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9#ifndef SQUID_SRC_ANYP_HOST_H
10#define SQUID_SRC_ANYP_HOST_H
11
12#include "dns/forward.h"
13#include "ip/Address.h"
14#include "sbuf/SBuf.h"
15
16#include <iosfwd>
17#include <optional>
18#include <variant>
19
20namespace AnyP
21{
22
24class Host
25{
26public:
28 static std::optional<Host> ParseIp(const Ip::Address &);
29
32 static std::optional<Host> ParseSimpleDomainName(const SBuf &);
33
36 static std::optional<Host> ParseWildDomainName(const SBuf &);
37
38 // Accessor methods below are mutually exclusive: Exactly one method is
39 // guaranteed to return a result other than std::nullopt.
40
45 auto ip() const { return std::get_if<Ip::Address>(&raw_); }
46
48 auto domainName() const { return std::get_if<SBuf>(&raw_); }
49
50private:
51 using Storage = std::variant<Ip::Address, Dns::DomainName>;
52
53 static std::optional<Host> ParseDomainName(const SBuf &);
54
55 // use a Parse*() function to create Host objects
56 Host(const Storage &raw): raw_(raw) {}
57
59};
60
64{
65public:
66 explicit Bracketed(const Host &aHost): host(aHost) {}
67 const Host &host;
68};
69
72std::ostream &operator <<(std::ostream &, const Host &);
73
76std::ostream &operator <<(std::ostream &, const Bracketed &);
77
78} // namespace Anyp
79
80#endif /* SQUID_SRC_ANYP_HOST_H */
81
Bracketed(const Host &aHost)
Definition Host.h:66
const Host & host
Definition Host.h:67
either a domain name (as defined in DNS RFC 1034) or an IP address
Definition Host.h:25
static std::optional< Host > ParseIp(const Ip::Address &)
converts an already parsed IP address to a Host object
Definition Host.cc:15
static std::optional< Host > ParseSimpleDomainName(const SBuf &)
Definition Host.cc:49
auto domainName() const
stored domain name (if any)
Definition Host.h:48
Storage raw_
the host we are providing access to
Definition Host.h:58
static std::optional< Host > ParseWildDomainName(const SBuf &)
Definition Host.cc:59
std::variant< Ip::Address, Dns::DomainName > Storage
Definition Host.h:51
Host(const Storage &raw)
Definition Host.h:56
auto ip() const
Definition Host.h:45
static std::optional< Host > ParseDomainName(const SBuf &)
common parts of FromSimpleDomain() and FromWildDomain()
Definition Host.cc:24
Definition SBuf.h:94
Definition forward.h:15
std::ostream & operator<<(std::ostream &, const Host &)
Definition Host.cc:80