Coverage Report

Created: 2025-12-03 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qt/qtbase/src/network/kernel/qhostinfo.h
Line
Count
Source
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#ifndef QHOSTINFO_H
6
#define QHOSTINFO_H
7
8
#include <QtNetwork/qtnetworkglobal.h>
9
#include <QtCore/qlist.h>
10
#include <QtCore/qscopedpointer.h>
11
#include <QtNetwork/qhostaddress.h>
12
13
QT_BEGIN_NAMESPACE
14
15
16
class QObject;
17
class QHostInfoPrivate;
18
19
class Q_NETWORK_EXPORT QHostInfo
20
{
21
    Q_GADGET
22
public:
23
    enum HostInfoError {
24
        NoError,
25
        HostNotFound,
26
        UnknownError
27
    };
28
29
    explicit QHostInfo(int lookupId = -1);
30
    QHostInfo(const QHostInfo &d);
31
0
    QHostInfo(QHostInfo &&other) noexcept : d_ptr(std::exchange(other.d_ptr, nullptr)) {}
32
    QHostInfo &operator=(const QHostInfo &d);
33
0
    QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
34
    ~QHostInfo();
35
36
0
    void swap(QHostInfo &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
37
38
    QString hostName() const;
39
    void setHostName(const QString &name);
40
41
    QList<QHostAddress> addresses() const;
42
    void setAddresses(const QList<QHostAddress> &addresses);
43
44
    HostInfoError error() const;
45
    void setError(HostInfoError error);
46
47
    QString errorString() const;
48
    void setErrorString(const QString &errorString);
49
50
    void setLookupId(int id);
51
    int lookupId() const;
52
53
#if QT_NETWORK_REMOVED_SINCE(6, 7)
54
    static int lookupHost(const QString &name, QObject *receiver, const char *member);
55
#endif
56
    static int lookupHost(const QString &name, const QObject *receiver, const char *member);
57
    static void abortHostLookup(int lookupId);
58
59
    static QHostInfo fromName(const QString &name);
60
    static QString localHostName();
61
    static QString localDomainName();
62
63
#ifdef Q_QDOC
64
    template<typename Functor>
65
    static int lookupHost(const QString &name, const QObject *context, Functor functor);
66
#else
67
    // lookupHost to a callable (with context)
68
    template <typename Functor>
69
    static inline int lookupHost(const QString &name,
70
                                 const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver,
71
                                 Functor &&func)
72
    {
73
        using Prototype = void(*)(QHostInfo);
74
        QtPrivate::AssertCompatibleFunctions<Prototype, Functor>();
75
        return lookupHostImpl(name, receiver,
76
                              QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)),
77
                              nullptr);
78
    }
79
#endif // Q_QDOC
80
81
#ifndef QT_NO_CONTEXTLESS_CONNECT
82
    // lookupHost to a callable (without context)
83
    template <typename Functor>
84
    static inline int lookupHost(const QString &name, Functor &&slot)
85
    {
86
        return lookupHost(name, nullptr, std::forward<Functor>(slot));
87
    }
88
#endif // QT_NO_CONTEXTLESS_CONNECT
89
90
private:
91
    QHostInfoPrivate *d_ptr;
92
0
    Q_DECLARE_PRIVATE(QHostInfo)
Unexecuted instantiation: QHostInfo::d_func()
Unexecuted instantiation: QHostInfo::d_func() const
93
0
94
0
    static int lookupHostImpl(const QString &name,
95
0
                              const QObject *receiver,
96
0
                              QtPrivate::QSlotObjectBase *slotObj,
97
0
                              const char *member);
98
0
99
0
    friend QHostInfo Q_NETWORK_EXPORT qt_qhostinfo_lookup(const QString &name, QObject *receiver,
100
0
                                                          const char *member, bool *valid, int *id);
101
0
};
102
0
103
0
Q_DECLARE_SHARED(QHostInfo)
104
0
105
0
QT_END_NAMESPACE
106
0
107
QT_DECL_METATYPE_EXTERN(QHostInfo, Q_NETWORK_EXPORT)
Unexecuted instantiation: int qRegisterNormalizedMetaType<QHostInfo>(QByteArray const&)
Unexecuted instantiation: QMetaTypeId<QHostInfo>::qt_metatype_id()
108
109
#endif // QHOSTINFO_H