Host.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 
20 namespace AnyP
21 {
22 
24 class Host
25 {
26 public:
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 
50 private:
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 
63 class Bracketed
64 {
65 public:
66  explicit Bracketed(const Host &aHost): host(aHost) {}
67  const Host &host;
68 };
69 
72 std::ostream &operator <<(std::ostream &, const Host &);
73 
76 std::ostream &operator <<(std::ostream &, const Bracketed &);
77 
78 } // namespace Anyp
79 
80 #endif /* SQUID_SRC_ANYP_HOST_H */
81 
static std::optional< Host > ParseSimpleDomainName(const SBuf &)
Definition: Host.cc:49
std::ostream & operator<<(std::ostream &, const Host &)
Definition: Host.cc:80
Definition: SBuf.h:93
std::variant< Ip::Address, Dns::DomainName > Storage
Definition: Host.h:51
const Host & host
Definition: Host.h:67
static std::optional< Host > ParseDomainName(const SBuf &)
common parts of FromSimpleDomain() and FromWildDomain()
Definition: Host.cc:24
Definition: forward.h:14
static std::optional< Host > ParseWildDomainName(const SBuf &)
Definition: Host.cc:59
static std::optional< Host > ParseIp(const Ip::Address &)
converts an already parsed IP address to a Host object
Definition: Host.cc:15
either a domain name (as defined in DNS RFC 1034) or an IP address
Definition: Host.h:24
auto domainName() const
stored domain name (if any)
Definition: Host.h:48
Bracketed(const Host &aHost)
Definition: Host.h:66
auto ip() const
Definition: Host.h:45
Storage raw_
the host we are providing access to
Definition: Host.h:58
Host(const Storage &raw)
Definition: Host.h:56

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors