MCPcopy Create free account
hub / github.com/SFML/SFML / queryTxt

Method queryTxt

src/SFML/Network/Dns.cpp:797–890  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

795
796////////////////////////////////////////////////////////////
797std::vector<std::vector<sf::String>> Dns::queryTxt(const String& hostname,
798 const std::vector<IpAddress>& servers,
799 std::optional<Time> timeout)
800{
801 std::vector<std::vector<sf::String>> txtRecords;
802
803 if (hostname.isEmpty())
804 return txtRecords;
805
806 auto encoded = encodeHostname(hostname);
807
808 // On Android the libc provided resolv API doesn't work, we will have to do the work ourselves
809#if defined(SFML_SYSTEM_ANDROID)
810 const auto& serversToQuery = servers.empty() ? getAndroidServers() : servers;
811#else
812 const auto& serversToQuery = servers;
813#endif
814
815 if (!serversToQuery.empty())
816 {
817 queryDns(
818 [&](const char* data, std::size_t length, const char*, std::uint16_t responseType, std::uint16_t responseClass)
819 {
820 // TXT, IN
821 if ((responseType != 16) || (responseClass != 1))
822 return;
823
824 auto& list = txtRecords.emplace_back();
825 const auto* begin = data;
826 const auto* const end = begin + length;
827 std::string buffer;
828 buffer.reserve(length);
829
830 while (begin < end)
831 {
832 buffer.clear();
833 std::uint8_t txtLength{};
834 std::memcpy(&txtLength, begin++, 1);
835 for (auto i = 0u; (i < txtLength) && (begin < end); ++i)
836 buffer.push_back(*begin++);
837 if (!buffer.empty())
838 list.emplace_back(buffer);
839 }
840 },
841 timeout,
842 {{serversToQuery,
843 16, // TXT
844 1, // IN
845 encoded}});
846
847 return txtRecords;
848 }
849
850#if defined(SFML_SYSTEM_WINDOWS)
851 const auto records = getRecords(encoded, DNS_TYPE_TEXT);
852 for (const auto* ptr = records.get(); ptr; ptr = ptr->pNext)
853 {
854 if (ptr->wType == DNS_TYPE_TEXT)

Callers

nothing calls this directly

Calls 6

encodeHostnameFunction · 0.85
queryDnsFunction · 0.85
getRecordsFunction · 0.85
isEmptyMethod · 0.80
getMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected