mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-15 17:59:58 +00:00
use std::string_view instead const std::string&
This commit is contained in:
parent
634ceceb1c
commit
08a680b53d
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -60,7 +60,7 @@ namespace proxy {
|
|||||||
"</head>\r\n"
|
"</head>\r\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
static bool str_rmatch(std::string & str, const char *suffix)
|
static bool str_rmatch(std::string_view str, const char *suffix)
|
||||||
{
|
{
|
||||||
auto pos = str.rfind (suffix);
|
auto pos = str.rfind (suffix);
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
@ -84,16 +84,16 @@ namespace proxy {
|
|||||||
void SentHTTPFailed(const boost::system::error_code & ecode);
|
void SentHTTPFailed(const boost::system::error_code & ecode);
|
||||||
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
|
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
/* error helpers */
|
/* error helpers */
|
||||||
void GenericProxyError(const std::string& title, const std::string& description);
|
void GenericProxyError(std::string_view title, std::string_view description);
|
||||||
void GenericProxyInfo(const std::string& title, const std::string& description);
|
void GenericProxyInfo(std::string_view title, std::string_view description);
|
||||||
void HostNotFound(const std::string& host);
|
void HostNotFound(std::string_view host);
|
||||||
void SendProxyError(const std::string& content);
|
void SendProxyError(std::string_view content);
|
||||||
void SendRedirect(const std::string& address);
|
void SendRedirect(const std::string& address);
|
||||||
|
|
||||||
void ForwardToUpstreamProxy();
|
void ForwardToUpstreamProxy();
|
||||||
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
||||||
void HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec);
|
void HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec);
|
||||||
void HTTPConnect(const std::string & host, uint16_t port);
|
void HTTPConnect(std::string_view host, uint16_t port);
|
||||||
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
|
|
||||||
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
||||||
@ -162,23 +162,23 @@ namespace proxy {
|
|||||||
Done(shared_from_this());
|
Done(shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::GenericProxyError(const std::string& title, const std::string& description) {
|
void HTTPReqHandler::GenericProxyError(std::string_view title, std::string_view description)
|
||||||
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "<h1>" << tr("Proxy error") << ": " << title << "</h1>\r\n";
|
ss << "<h1>" << tr("Proxy error") << ": " << title << "</h1>\r\n";
|
||||||
ss << "<p>" << description << "</p>\r\n";
|
ss << "<p>" << description << "</p>\r\n";
|
||||||
std::string content = ss.str();
|
SendProxyError(ss.str ());
|
||||||
SendProxyError(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::GenericProxyInfo(const std::string& title, const std::string& description) {
|
void HTTPReqHandler::GenericProxyInfo(std::string_view title, std::string_view description)
|
||||||
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "<h1>" << tr("Proxy info") << ": " << title << "</h1>\r\n";
|
ss << "<h1>" << tr("Proxy info") << ": " << title << "</h1>\r\n";
|
||||||
ss << "<p>" << description << "</p>\r\n";
|
ss << "<p>" << description << "</p>\r\n";
|
||||||
std::string content = ss.str();
|
SendProxyError(ss.str ());
|
||||||
SendProxyError(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::HostNotFound(const std::string& host)
|
void HTTPReqHandler::HostNotFound(std::string_view host)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "<h1>" << tr("Proxy error: Host not found") << "</h1>\r\n"
|
ss << "<h1>" << tr("Proxy error: Host not found") << "</h1>\r\n"
|
||||||
@ -192,11 +192,10 @@ namespace proxy {
|
|||||||
ss << " <li><a href=\"" << js->second << host << "\">" << js->first << "</a></li>\r\n";
|
ss << " <li><a href=\"" << js->second << host << "\">" << js->first << "</a></li>\r\n";
|
||||||
}
|
}
|
||||||
ss << "</ul>\r\n";
|
ss << "</ul>\r\n";
|
||||||
std::string content = ss.str();
|
SendProxyError(ss.str ());
|
||||||
SendProxyError(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::SendProxyError(const std::string& content)
|
void HTTPReqHandler::SendProxyError(std::string_view content)
|
||||||
{
|
{
|
||||||
i2p::http::HTTPRes res;
|
i2p::http::HTTPRes res;
|
||||||
res.code = 500;
|
res.code = 500;
|
||||||
@ -473,7 +472,7 @@ namespace proxy {
|
|||||||
if (dest_host != "")
|
if (dest_host != "")
|
||||||
{
|
{
|
||||||
/* absolute url, replace 'Host' header */
|
/* absolute url, replace 'Host' header */
|
||||||
std::string h = dest_host;
|
std::string h (dest_host);
|
||||||
if (dest_port != 0 && dest_port != 80)
|
if (dest_port != 0 && dest_port != 80)
|
||||||
h += ":" + std::to_string(dest_port);
|
h += ":" + std::to_string(dest_port);
|
||||||
m_ClientRequest.UpdateHeader("Host", h);
|
m_ClientRequest.UpdateHeader("Host", h);
|
||||||
@ -513,7 +512,7 @@ namespace proxy {
|
|||||||
GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings"));
|
GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings"));
|
||||||
} else {
|
} else {
|
||||||
LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled");
|
LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled");
|
||||||
std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host.c_str());
|
std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host.c_str ());
|
||||||
GenericProxyError(tr("Outproxy failure"), ss.str());
|
GenericProxyError(tr("Outproxy failure"), ss.str());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -653,11 +652,10 @@ namespace proxy {
|
|||||||
Terminate();
|
Terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::HTTPConnect(const std::string & host, uint16_t port)
|
void HTTPReqHandler::HTTPConnect(std::string_view host, uint16_t port)
|
||||||
{
|
{
|
||||||
LogPrint(eLogDebug, "HTTPProxy: CONNECT ",host, ":", port);
|
LogPrint(eLogDebug, "HTTPProxy: CONNECT ",host, ":", port);
|
||||||
std::string hostname(host);
|
if(str_rmatch(host, ".i2p"))
|
||||||
if(str_rmatch(hostname, ".i2p"))
|
|
||||||
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
||||||
shared_from_this(), std::placeholders::_1), host, port);
|
shared_from_this(), std::placeholders::_1), host, port);
|
||||||
else
|
else
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -107,7 +107,7 @@ namespace client
|
|||||||
m_ReadyTimerTriggered = false;
|
m_ReadyTimerTriggered = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, uint16_t port) {
|
void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, std::string_view dest, uint16_t port) {
|
||||||
assert(streamRequestComplete);
|
assert(streamRequestComplete);
|
||||||
auto address = i2p::client::context.GetAddressBook ().GetAddress (dest);
|
auto address = i2p::client::context.GetAddressBook ().GetAddress (dest);
|
||||||
if (address)
|
if (address)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -59,7 +59,7 @@ namespace client
|
|||||||
if (dest) dest->Acquire ();
|
if (dest) dest->Acquire ();
|
||||||
m_LocalDestination = dest;
|
m_LocalDestination = dest;
|
||||||
}
|
}
|
||||||
void CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, uint16_t port = 0);
|
void CreateStream (StreamRequestComplete streamRequestComplete, std::string_view dest, uint16_t port = 0);
|
||||||
void CreateStream(StreamRequestComplete complete, std::shared_ptr<const Address> address, uint16_t port);
|
void CreateStream(StreamRequestComplete complete, std::shared_ptr<const Address> address, uint16_t port);
|
||||||
auto& GetService () { return m_LocalDestination->GetService (); }
|
auto& GetService () { return m_LocalDestination->GetService (); }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user