From 32a41b1abe1a4aab0892c9c2051be6ba5b379f1e Mon Sep 17 00:00:00 2001 From: Christoph Berg Date: Mon, 11 May 2020 22:17:58 +0200 Subject: New upstream version 2.2.0~rc1+repack --- NetworkServerLookup.cpp | 86 ------------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 NetworkServerLookup.cpp (limited to 'NetworkServerLookup.cpp') diff --git a/NetworkServerLookup.cpp b/NetworkServerLookup.cpp deleted file mode 100644 index 3e0ec34a..00000000 --- a/NetworkServerLookup.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "NetworkServerLookup.hpp" - -#include - -#include -#include - -std::tuple -network_server_lookup (QString query - , quint16 default_service_port - , QHostAddress default_host_address - , QAbstractSocket::NetworkLayerProtocol required_protocol) -{ - query = query.trimmed (); - - QHostAddress host_address {default_host_address}; - quint16 service_port {default_service_port}; - - QString host_name; - if (!query.isEmpty ()) - { - int port_colon_index {-1}; - - if ('[' == query[0]) - { - // assume IPv6 combined address/port syntax [
]: - auto close_bracket_index = query.lastIndexOf (']'); - host_name = query.mid (1, close_bracket_index - 1); - port_colon_index = query.indexOf (':', close_bracket_index); - } - else - { - port_colon_index = query.lastIndexOf (':'); - host_name = query.left (port_colon_index); - } - host_name = host_name.trimmed (); - - if (port_colon_index >= 0) - { - bool ok; - service_port = query.mid (port_colon_index + 1).trimmed ().toUShort (&ok); - if (!ok) - { - throw std::runtime_error {"network server lookup error: invalid port"}; - } - } - } - - if (!host_name.isEmpty ()) - { - auto host_info = QHostInfo::fromName (host_name); - if (host_info.addresses ().isEmpty ()) - { - throw std::runtime_error {"network server lookup error: host name lookup failed"}; - } - - bool found {false}; - for (int i {0}; i < host_info.addresses ().size () && !found; ++i) - { - host_address = host_info.addresses ().at (i); - switch (required_protocol) - { - case QAbstractSocket::IPv4Protocol: - case QAbstractSocket::IPv6Protocol: - if (required_protocol != host_address.protocol ()) - { - break; - } - // drop through - - case QAbstractSocket::AnyIPProtocol: - found = true; - break; - - default: - throw std::runtime_error {"network server lookup error: invalid required protocol"}; - } - } - if (!found) - { - throw std::runtime_error {"network server lookup error: no suitable host address found"}; - } - } - - return std::make_tuple (host_address, service_port); -} -- cgit v1.2.3