mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-07-07 10:43:54 +02:00
extract params from std::string_view
This commit is contained in:
parent
88375bf9c0
commit
1862f28a98
2 changed files with 19 additions and 15 deletions
|
@ -968,24 +968,28 @@ namespace client
|
||||||
SendMessageReply (m_Buffer, l, false);
|
SendMessageReply (m_Buffer, l, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::map<std::string_view, std::string_view> SAMSocket::ExtractParams (char * buf)
|
const std::map<std::string_view, std::string_view> SAMSocket::ExtractParams (std::string_view buf)
|
||||||
{
|
{
|
||||||
std::map<std::string_view, std::string_view> params;
|
std::map<std::string_view, std::string_view> params;
|
||||||
char * separator;
|
size_t pos = 0;
|
||||||
do
|
while (pos < buf.length ())
|
||||||
{
|
{
|
||||||
separator = strchr (buf, ' ');
|
std::string_view field;
|
||||||
if (separator) *separator = 0;
|
auto separator = buf.find (' ', pos);
|
||||||
char * value = strchr (buf, '=');
|
if (separator != std::string_view::npos)
|
||||||
if (value)
|
|
||||||
{
|
{
|
||||||
*value = 0;
|
field = buf.substr (pos, separator - pos);
|
||||||
value++;
|
pos = separator + 1;
|
||||||
params.emplace (buf, value);
|
|
||||||
}
|
}
|
||||||
buf = separator + 1;
|
else
|
||||||
|
{
|
||||||
|
field = buf.substr (pos);
|
||||||
|
pos = buf.length ();
|
||||||
|
}
|
||||||
|
auto value = field.find ('=');
|
||||||
|
if (value != std::string_view::npos)
|
||||||
|
params.emplace (field.substr (0, value), field.substr (value + 1));
|
||||||
}
|
}
|
||||||
while (separator);
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ namespace client
|
||||||
void SendStreamI2PError(const std::string & msg);
|
void SendStreamI2PError(const std::string & msg);
|
||||||
void SendStreamCantReachPeer(const std::string & msg);
|
void SendStreamCantReachPeer(const std::string & msg);
|
||||||
size_t ProcessDatagramSend (char * buf, size_t len, const char * data); // from SAM 1.0
|
size_t ProcessDatagramSend (char * buf, size_t len, const char * data); // from SAM 1.0
|
||||||
const std::map<std::string_view, std::string_view> ExtractParams (char * buf);
|
const std::map<std::string_view, std::string_view> ExtractParams (std::string_view buf);
|
||||||
|
|
||||||
void Connect (std::shared_ptr<const i2p::data::LeaseSet> remote, std::shared_ptr<SAMSession> session = nullptr);
|
void Connect (std::shared_ptr<const i2p::data::LeaseSet> remote, std::shared_ptr<SAMSession> session = nullptr);
|
||||||
void HandleConnectLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet);
|
void HandleConnectLeaseSetRequestComplete (std::shared_ptr<i2p::data::LeaseSet> leaseSet);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue