From af023bead14b3306c0f7223848f9fd76dd83aae4 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 10 May 2021 15:13:47 +0100 Subject: Use the contents of the link data map when using the 1206 protocol. Still to do: - Extract URL encoding to inspstring. - Use CompareLinkData when using the 1206 protocol. - Show friendlier messages when a link compatibility is encountered. --- src/modules/m_spanningtree/utils.cpp | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/modules/m_spanningtree/utils.cpp') diff --git a/src/modules/m_spanningtree/utils.cpp b/src/modules/m_spanningtree/utils.cpp index 36eb1c51e..8d454dbc3 100644 --- a/src/modules/m_spanningtree/utils.cpp +++ b/src/modules/m_spanningtree/utils.cpp @@ -361,3 +361,46 @@ void SpanningTreeUtilities::SendChannelMessage(User* source, Channel* target, co Sock->WriteLine(msg); } } + +std::string SpanningTreeUtilities::BuildLinkString(uint16_t proto, Module* mod) +{ + std::stringstream buffer; + + Module::LinkData data; + std::string compatdata; + mod->GetLinkData(data, compatdata); + + if (proto <= PROTO_INSPIRCD_30) + { + if (compatdata.empty()) + return ""; // No link data. + + buffer << '=' << compatdata; + } + else + { + if (data.empty()) + return ""; // No link data. + + static const char* hextable = "0123456789ABCDEF"; + bool first = true; + for (const auto& [name, value] : data) + { + if (!first) + buffer << '&'; + first = false; + buffer << name << '='; + for (const auto& chr : value) + { + // TODO: extract URL encoding logic to inspstring. + unsigned char uchr = static_cast(chr); + if (isalnum(uchr)) + buffer << uchr; + else + buffer << '%' << hextable[uchr >> 4] << hextable[uchr & 15]; + } + } + } + + return buffer.str(); +} -- cgit v1.3.1-10-gc9f91