Warning, file /libraries/upnp-lib-qt/src/upnpssdpengine.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002    SPDX-FileCopyrightText: 2015 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
0003 
0004    SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #ifndef UPNPSSDPENGINE_H
0008 #define UPNPSSDPENGINE_H
0009 
0010 #include "upnplibqt_export.h"
0011 
0012 #include <QHostAddress>
0013 #include <QNetworkInformation>
0014 
0015 #include <QObject>
0016 #include <QString>
0017 
0018 #include <memory>
0019 
0020 enum class SearchTargetType {
0021     All,
0022     RootDevice,
0023     DeviceUUID,
0024     DeviceType,
0025     ServiceType,
0026 };
0027 
0028 enum class SsdpMessageType {
0029     query,
0030     queryAnswer,
0031     announce,
0032     invalid,
0033 };
0034 
0035 struct UpnpSearchQuery
0036 {
0037     /**
0038      * @brief mSearchHostAddress is the host address to which we should answer
0039      */
0040     QHostAddress mSearchHostAddress;
0041 
0042     /**
0043      * @brief mSearchHostPort is the host port to which we should answer
0044      */
0045     quint16 mSearchHostPort;
0046 
0047     /**
0048      * @brief mSearchTargetType is the search target type as defined by enum SearchTargetType
0049      */
0050     SearchTargetType mSearchTargetType;
0051 
0052     /**
0053      * @brief mSearchTarget is the search target string that we should use when determining if we should answer
0054      */
0055     QString mSearchTarget;
0056 
0057     /**
0058      * @brief mAnswerDelay is the delay defined by UPnP SSDP that will be interpreted as the maximum delay before sending the answer
0059      */
0060     int mAnswerDelay;
0061 };
0062 
0063 class UpnpAbstractDevice;
0064 class UpnpDiscoveryResult;
0065 class UpnpSsdpEnginePrivate;
0066 
0067 /**
0068  * @brief The UpnpSsdpEngine class implements the SSDP protocol.
0069  *
0070  * SSDP allows to discover services or devices present on a network. The \class UpnpSsdpEngine allows to perform queries or publish devices or services.
0071  */
0072 class UPNPLIBQT_EXPORT UpnpSsdpEngine : public QObject
0073 {
0074 
0075     Q_OBJECT
0076 
0077     Q_PROPERTY(quint16 port
0078             READ port
0079                 WRITE setPort
0080                     NOTIFY portChanged)
0081 
0082     Q_PROPERTY(bool canExportServices
0083             READ canExportServices
0084                 WRITE setCanExportServices
0085                     NOTIFY canExportServicesChanged)
0086 
0087 public:
0088     enum class NotificationSubType {
0089         Invalid,
0090         Alive,
0091         ByeBye,
0092         Discover,
0093     };
0094 
0095     Q_ENUM(NotificationSubType)
0096 
0097     enum SEARCH_TYPE {
0098         AllDevices,
0099         RootDevices,
0100         DeviceByUUID,
0101         DeviceByType,
0102         ServiceByType,
0103     };
0104 
0105     Q_ENUM(SEARCH_TYPE)
0106 
0107     explicit UpnpSsdpEngine(QObject *parent = nullptr);
0108 
0109     ~UpnpSsdpEngine() override;
0110 
0111     [[nodiscard]] bool port() const;
0112 
0113     [[nodiscard]] bool canExportServices() const;
0114 
0115     [[nodiscard]] QList<UpnpDiscoveryResult> existingServices() const;
0116 
0117 Q_SIGNALS:
0118 
0119     void newSearchQuery(UpnpSsdpEngine *engine, const UpnpSearchQuery &searchQuery);
0120 
0121     void newService(const UpnpDiscoveryResult &serviceDiscovery);
0122 
0123     void removedService(const UpnpDiscoveryResult &serviceDiscovery);
0124 
0125     void portChanged();
0126 
0127     void canExportServicesChanged();
0128 
0129     void networkChanged();
0130 
0131 public Q_SLOTS:
0132 
0133     void initialize();
0134 
0135     void setPort(quint16 value);
0136 
0137     void setCanExportServices(bool value);
0138 
0139     /**
0140      * @brief searchUpnpDevice will trigger a search for upnp device depending on the parameters
0141      */
0142     bool searchUpnp(UpnpSsdpEngine::SEARCH_TYPE searchType, const QString &searchCriteria, int maxDelay = 1);
0143 
0144     /**
0145      * @brief searchAllUpnpDevice will trigger a search for all upnp device
0146      */
0147     bool searchAllUpnpDevice(int maxDelay = 1);
0148 
0149     /**
0150      * @brief searchAllRootDevice will trigger a search for all upnp root device
0151      */
0152     bool searchAllRootDevice(int maxDelay = 1);
0153 
0154     /**
0155      * @brief searchByDeviceUUID will trigger a search by device UUID
0156      */
0157     bool searchByDeviceUUID(const QString &uuid, int maxDelay = 1);
0158 
0159     /**
0160      * @brief searchByDeviceType will trigger a search by device type
0161      */
0162     bool searchByDeviceType(const QString &upnpDeviceType, int maxDelay = 1);
0163 
0164     /**
0165      * @brief searchByServiceType will trigger a search by service type
0166      */
0167     bool searchByServiceType(const QString &upnpServiceType, int maxDelay = 1);
0168 
0169     void subscribeDevice(UpnpAbstractDevice *device);
0170 
0171     void publishDevice(UpnpAbstractDevice *device);
0172 
0173 private Q_SLOTS:
0174 
0175     void standardReceivedData();
0176 
0177     void queryReceivedData();
0178 
0179     void discoveryResultTimeout();
0180 
0181     void networkReachabilityChanged(QNetworkInformation::Reachability newReachability);
0182 
0183     void networkUpdateCompleted();
0184 
0185 private:
0186     void reconfigureNetwork();
0187 
0188     void parseSsdpDatagram(const QByteArray &datagram);
0189 
0190     void parseSsdpQueryDatagram(const QByteArray &datagram, const QList<QByteArray> &headers);
0191 
0192     void parseSsdpAnnounceDatagram(const QByteArray &datagram, const QList<QByteArray> &headers, SsdpMessageType messageType);
0193 
0194     std::unique_ptr<UpnpSsdpEnginePrivate> d;
0195 };
0196 
0197 #endif