diff options
| author | 2021-05-10 15:13:47 +0100 | |
|---|---|---|
| committer | 2021-05-10 15:15:51 +0100 | |
| commit | af023bead14b3306c0f7223848f9fd76dd83aae4 (patch) | |
| tree | 8dc7ec7f1d035a2a4a4403a380d270552b893021 /src/modules/m_spanningtree/utils.cpp | |
| parent | Fix the to_string implementation of ConvToStr. (diff) | |
| download | inspircd++-af023bead14b3306c0f7223848f9fd76dd83aae4.tar.gz inspircd++-af023bead14b3306c0f7223848f9fd76dd83aae4.tar.bz2 inspircd++-af023bead14b3306c0f7223848f9fd76dd83aae4.zip | |
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.
Diffstat (limited to 'src/modules/m_spanningtree/utils.cpp')
| -rw-r--r-- | src/modules/m_spanningtree/utils.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
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<unsigned char>(chr); + if (isalnum(uchr)) + buffer << uchr; + else + buffer << '%' << hextable[uchr >> 4] << hextable[uchr & 15]; + } + } + } + + return buffer.str(); +} |
