mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-23 18:32:55 +00:00
implement QHostInfo::localHostName() via getdomainname() instead of resolv
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
9d45d0998a
commit
494386d8f5
6 changed files with 19 additions and 124 deletions
|
@ -128,9 +128,6 @@ add_feature_info(postgresql WITH_POSTGRESQL "build PostgreSQL support")
|
|||
option(WITH_MYSQL "Build MySQL database plugin" ON)
|
||||
add_feature_info(mysql WITH_MYSQL "build MySQL support")
|
||||
|
||||
option(WITH_RESOLV "Build resolv support" ON)
|
||||
add_feature_info(resolv WITH_RESOLV "build resolv support")
|
||||
|
||||
option(WITH_INTL "Build Intl support" ON)
|
||||
add_feature_info(intl WITH_INTL "build Intl support")
|
||||
|
||||
|
@ -242,14 +239,6 @@ set_package_properties(Sqlite PROPERTIES
|
|||
TYPE REQUIRED
|
||||
)
|
||||
|
||||
find_package(Resolv)
|
||||
set_package_properties(Resolv PROPERTIES
|
||||
PURPOSE "Required for domain resolving support"
|
||||
DESCRIPTION "Standard C library specific resolv implementation"
|
||||
URL ""
|
||||
TYPE RECOMMENDED
|
||||
)
|
||||
|
||||
find_package(JPEG)
|
||||
set_package_properties(JPEG PROPERTIES
|
||||
PURPOSE "JPEG format handler"
|
||||
|
@ -383,6 +372,7 @@ katie_check_function(kevent "sys/event.h")
|
|||
katie_check_function(pipe2 "unistd.h")
|
||||
katie_check_function(accept4 "sys/socket.h")
|
||||
katie_check_function(paccept "sys/socket.h")
|
||||
katie_check_function(getdomainname "unistd.h")
|
||||
katie_check_struct(tm tm_gmtoff "time.h")
|
||||
katie_check_struct(tm tm_zone "time.h")
|
||||
katie_check_struct(sockaddr_ll sll_addr "netpacket/packet.h")
|
||||
|
@ -464,10 +454,6 @@ if(NOT WITH_CUPS OR NOT CUPS_FOUND)
|
|||
katie_definition(-DQT_NO_CUPS)
|
||||
endif()
|
||||
|
||||
if(NOT WITH_RESOLV OR NOT RESOLV_FOUND)
|
||||
katie_definition(-DQT_NO_RESOLV)
|
||||
endif()
|
||||
|
||||
if(NOT WITH_JPEG OR NOT JPEG_FOUND)
|
||||
katie_definition(-DQT_NO_IMAGEFORMAT_JPEG)
|
||||
endif()
|
||||
|
|
3
README
3
README
|
@ -14,7 +14,7 @@ There are several things you should be aware before considering Katie:
|
|||
- QMake build system replaced with CMake
|
||||
- zlib, zstd, OpenSSL, PCRE, Freetype, ICU, X11, libpng and SQLite are
|
||||
required for building
|
||||
- OpenSSL, D-Bus, CUPS and resolv must be linked to during build
|
||||
- OpenSSL, D-Bus and CUPS must be linked to during build
|
||||
- QtUiTools is build as shared library by default
|
||||
- moc, uic, rcc, etc. are linked to components
|
||||
- updated bundled Harfbuzz from upstream (not Harfbuzz-NG)
|
||||
|
@ -51,7 +51,6 @@ There are several things you should be aware before considering Katie:
|
|||
- building with OpenSSL v1.1+ is possible
|
||||
- building with IODBC instead of unixODBC is possible
|
||||
- building with LTO is possible and supported, if the toolchain can handle it
|
||||
- building without resolv is possible
|
||||
- alternative libc implementations support
|
||||
- additional text codecs via ICU converter
|
||||
- Unicode v5.0+ characters and partial scripts support
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
# - Try to find resolv
|
||||
# Once done this will define
|
||||
#
|
||||
# RESOLV_FOUND - system has resolv
|
||||
# RESOLV_INCLUDES - the resolv include directory
|
||||
# RESOLV_LIBRARIES - the libraries needed to use resolv
|
||||
# RESOLV_THREAD_SAFE - resolv has thread-safe functions (res_ninit/res_nclose)
|
||||
#
|
||||
# Copyright (c) 2016-2020, Ivailo Monev, <xakepa10@gmail.com>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
|
||||
# resolv does not provide pkg-config files
|
||||
|
||||
include(CMakePushCheckState)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
set(RESOLV_NAMES c resolv)
|
||||
|
||||
find_path(RESOLV_INCLUDES
|
||||
NAMES resolv.h
|
||||
HINTS $ENV{RESOLVDIR}/include
|
||||
)
|
||||
|
||||
set(RESOLV_LIBRARIES)
|
||||
foreach(name ${RESOLV_NAMES})
|
||||
if(NOT RESOLV_LIBRARIES)
|
||||
unset(HAVE_res_ninit CACHE)
|
||||
cmake_reset_check_state()
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${name})
|
||||
katie_check_defined(res_ninit "netinet/in.h;resolv.h")
|
||||
cmake_reset_check_state()
|
||||
if(NOT HAVE_res_ninit)
|
||||
unset(HAVE_res_init CACHE)
|
||||
cmake_reset_check_state()
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${name})
|
||||
katie_check_defined(res_init "netinet/in.h;resolv.h")
|
||||
cmake_reset_check_state()
|
||||
endif()
|
||||
if(HAVE_res_ninit OR HAVE_res_init)
|
||||
find_library(RESOLV_LIBRARIES
|
||||
NAMES ${name}
|
||||
HINTS $ENV{RESOLVDIR}/lib
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
find_package_handle_standard_args(Resolv
|
||||
REQUIRED_VARS RESOLV_LIBRARIES RESOLV_INCLUDES
|
||||
)
|
||||
|
||||
set(RESOLV_THREAD_SAFE "${HAVE_res_ninit}" CACHE BOOL "resolv has thread-safe functions (res_ninit/res_nclose)")
|
||||
|
||||
mark_as_advanced(RESOLV_INCLUDES RESOLV_LIBRARIES RESOLV_THREAD_SAFE)
|
|
@ -108,6 +108,7 @@
|
|||
#define QT_NO_NAS
|
||||
#define QT_NO_IMAGEFORMAT_MNG
|
||||
#define QT_NO_TEXTODFWRITER
|
||||
#define QT_NO_RESOLV
|
||||
|
||||
// Not supported, used to bootstrap
|
||||
#cmakedefine QT_NO_QOBJECT
|
||||
|
@ -140,7 +141,6 @@
|
|||
#cmakedefine QT_NO_FONTCONFIG
|
||||
#cmakedefine QT_NO_IMAGEFORMAT_JPEG
|
||||
#cmakedefine QT_NO_IMAGEFORMAT_TIFF
|
||||
#cmakedefine QT_NO_RESOLV
|
||||
#cmakedefine QT_NO_SESSIONMANAGER
|
||||
#cmakedefine QT_NO_TRANSLATION
|
||||
#cmakedefine QT_NO_XCURSOR
|
||||
|
|
|
@ -202,17 +202,6 @@ set(NETWORK_SOURCES
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/ssl/qsslsocket_openssl.cpp
|
||||
)
|
||||
|
||||
if(WITH_RESOLV AND RESOLV_FOUND)
|
||||
set(EXTRA_NETWORK_LIBS
|
||||
${EXTRA_NETWORK_LIBS}
|
||||
${RESOLV_LIBRARIES}
|
||||
)
|
||||
include_directories(${RESOLV_INCLUDES})
|
||||
if(RESOLV_THREAD_SAFE)
|
||||
add_definitions(-DQT_HAVE_RES_NINIT)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
katie_generate_misc("${NETWORK_HEADERS}" QtNetwork)
|
||||
katie_generate_public("${NETWORK_PUBLIC_HEADERS}" QtNetwork)
|
||||
katie_generate_package(KtNetwork "KtCore")
|
||||
|
|
|
@ -47,10 +47,6 @@
|
|||
#include <netdb.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#ifndef QT_NO_RESOLV
|
||||
#include <resolv.h>
|
||||
#endif // QT_NO_RESOLV
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
#if !defined(QT_HAVE_GETADDRINFO)
|
||||
|
@ -67,11 +63,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
|
|||
hostName.toLatin1().constData());
|
||||
#endif
|
||||
|
||||
#ifndef QT_NO_RESOLV
|
||||
// If res_init is available, poll it.
|
||||
res_init();
|
||||
#endif // QT_NO_RESOLV
|
||||
|
||||
QHostAddress address;
|
||||
if (address.setAddress(hostName)) {
|
||||
// Reverse lookup
|
||||
|
@ -272,43 +263,28 @@ QString QHostInfo::localHostName()
|
|||
static long size_max = sysconf(_SC_HOST_NAME_MAX);
|
||||
if (size_max == -1)
|
||||
size_max = _POSIX_HOST_NAME_MAX;
|
||||
char gethostbuffer[size_max];
|
||||
if (Q_LIKELY(::gethostname(gethostbuffer, size_max) == 0)) {
|
||||
gethostbuffer[size_max - 1] = '\0';
|
||||
return QString::fromLocal8Bit(gethostbuffer);
|
||||
char gethostbuff[size_max];
|
||||
if (Q_LIKELY(::gethostname(gethostbuff, size_max) == 0)) {
|
||||
gethostbuff[size_max - 1] = '\0';
|
||||
return QString::fromLocal8Bit(gethostbuff);
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString QHostInfo::localDomainName()
|
||||
{
|
||||
//support both thread-safe and unsafe versions
|
||||
#if !defined(QT_NO_RESOLV) && defined(QT_HAVE_RES_NINIT)
|
||||
// using thread-safe version
|
||||
struct __res_state state;
|
||||
res_ninit(&state);
|
||||
QString domainName = QUrl::fromAce(state.defdname);
|
||||
if (domainName.isEmpty())
|
||||
domainName = QUrl::fromAce(state.dnsrch[0]);
|
||||
res_nclose(&state);
|
||||
|
||||
return domainName;
|
||||
#elif !defined(QT_NO_RESOLV)
|
||||
// using thread-unsafe version
|
||||
|
||||
#if !defined(QT_HAVE_GETADDRINFO)
|
||||
// We have to call res_init to be sure that _res was initialized
|
||||
// So, for systems without getaddrinfo (which is thread-safe), we lock the mutex too
|
||||
QMutexLocker locker(getHostByNameMutex());
|
||||
#endif
|
||||
res_init();
|
||||
QString domainName = QUrl::fromAce(_res.defdname);
|
||||
if (domainName.isEmpty())
|
||||
domainName = QUrl::fromAce(_res.dnsrch[0]);
|
||||
return domainName;
|
||||
#if defined(QT_HAVE_GETDOMAINNAME)
|
||||
// thread-safe
|
||||
static long size_max = sysconf(_SC_HOST_NAME_MAX);
|
||||
if (size_max == -1)
|
||||
size_max = _POSIX_HOST_NAME_MAX;
|
||||
char getdomainbuff[size_max];
|
||||
if (Q_LIKELY(::getdomainname(getdomainbuff, size_max) == 0)) {
|
||||
return QUrl::fromAce(getdomainbuff);
|
||||
}
|
||||
return QString();
|
||||
#else
|
||||
|
||||
// nothing worked, try doing it by ourselves:
|
||||
// doing it by ourselves
|
||||
#if defined(_PATH_RESCONF)
|
||||
QFile resolvconf(QFile::decodeName(_PATH_RESCONF));
|
||||
#else
|
||||
|
@ -335,7 +311,7 @@ QString QHostInfo::localDomainName()
|
|||
|
||||
// return the fallen-back-to searched domain
|
||||
return domainName;
|
||||
#endif // QT_NO_RESOLV
|
||||
#endif // QT_HAVE_GETDOMAINNAME
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
Loading…
Add table
Reference in a new issue