aboutsummaryrefslogtreecommitdiff
path: root/src/net/parse.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/parse.h')
-rw-r--r--src/net/parse.h79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/net/parse.h b/src/net/parse.h
index 6ece931c6..68f63fdb9 100644
--- a/src/net/parse.h
+++ b/src/net/parse.h
@@ -30,14 +30,75 @@
#pragma once
#include <boost/asio/ip/tcp.hpp>
+#include <boost/optional/optional.hpp>
#include <boost/utility/string_ref.hpp>
#include <cstdint>
#include "common/expect.h"
+#include "net/fwd.h"
#include "net/net_utils_base.h"
namespace net
{
+ //! \brief Separates scheme, authority, and path sections of a URI.
+ struct scheme_and_authority
+ {
+ //! \param uri with optional scheme, authority, and optional path. No URNs.
+ explicit scheme_and_authority(boost::string_ref uri);
+
+ std::string scheme;
+ std::string authority;
+ };
+
+ //! \brief Separates the userinfo and host+port from URI authority.
+ struct userinfo_and_hostport
+ {
+ //! \param authority portion of a URI.
+ explicit userinfo_and_hostport(boost::string_ref authority);
+
+ std::string userinfo;
+ std::string hostport;
+ };
+
+ //! \brief Separates the user and pass sections from URI userinfo.
+ struct user_and_pass
+ {
+ user_and_pass()
+ : user(), pass()
+ {}
+
+ /*!
+ * \param userinfo section of a URI.
+ * \return User and pass with percent encoding removed. `boost::none`
+ * if bad percent encoding
+ */
+ static boost::optional<user_and_pass> get(boost::string_ref userinfo);
+
+ std::string user;
+ std::string pass;
+ };
+
+ //! \brief Separates scheme, user, pass, and host+port sections of a URI.
+ struct uri_components
+ {
+ uri_components()
+ : scheme(), userinfo(), hostport()
+ {}
+
+ /*!
+ * \param uri with optional scheme, optional user, optional pass,
+ * authority, and optional path. URN not supported.
+ * \return Scheme, user, pass, and host+port sections of a URI with
+ * percent encoding removed on user and pass. `boost::none` if
+ * bad percent encoding.
+ */
+ static boost::optional<uri_components> get(boost::string_ref uri);
+
+ std::string scheme;
+ user_and_pass userinfo;
+ std::string hostport;
+ };
+
/*!
* \brief Takes a valid address string (IP, Tor, I2P, or DNS name) and splits it into host and port
*
@@ -79,5 +140,21 @@ namespace net
get_ipv4_subnet_address(boost::string_ref address, bool allow_implicit_32 = false);
expect<boost::asio::ip::tcp::endpoint> get_tcp_endpoint(const boost::string_ref address);
-}
+ namespace socks
+ {
+ //! \brief Separates TCP address, user+pass, and socks version
+ struct endpoint
+ {
+ endpoint();
+ explicit endpoint(const boost::asio::ip::tcp::endpoint& address);
+
+ //! \param uri with optional scheme, optional userinfo, and host+port.
+ static expect<endpoint> get(boost::string_ref uri);
+
+ boost::asio::ip::tcp::endpoint address;
+ user_and_pass userinfo;
+ version ver;
+ };
+ }
+}