File indexing completed on 2024-04-28 04:44:21

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 UPNPDEVICESOAPSERVEROBJECT_H
0008 #define UPNPDEVICESOAPSERVEROBJECT_H
0009 
0010 #include "upnplibqt_export.h"
0011 
0012 #include <KDSoapServer/KDSoapServerCustomVerbRequestInterface.h>
0013 #include <KDSoapServer/KDSoapServerObjectInterface.h>
0014 
0015 #include <QList>
0016 #include <QObject>
0017 
0018 #include <memory>
0019 
0020 class UpnpAbstractDevice;
0021 class UpnpDeviceSoapServerObjectPrivate;
0022 
0023 /**
0024  * @brief The UpnpDeviceSoapServerObject class is needed to handle incoming request made to an UPnP device or service
0025  */
0026 class UpnpDeviceSoapServerObject : public QObject, public KDSoapServerObjectInterface, public KDSoapServerCustomVerbRequestInterface
0027 {
0028     Q_OBJECT
0029 
0030     Q_INTERFACES(KDSoapServerObjectInterface KDSoapServerCustomVerbRequestInterface)
0031 
0032 public:
0033     explicit UpnpDeviceSoapServerObject(QList<UpnpAbstractDevice *> &devices, QObject *parent = nullptr);
0034 
0035     ~UpnpDeviceSoapServerObject() override;
0036 
0037     void processRequest(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction) override;
0038 
0039     QIODevice* processFileRequest(const QString &path, QByteArray &contentType) override;
0040 
0041     void processRequestWithPath(const KDSoapMessage &request, KDSoapMessage &response, const QByteArray &soapAction, const QString &path) override;
0042 
0043     /**
0044      * Process a request made with a custom HTTP verb
0045      * @param requestType HTTP verb other than GET and POST
0046      * @param requestData is the content of the request
0047      * @param httpHeaders the map of http headers (keys have been lowercased since they are case insensitive)
0048      * @param customAnswer allow to send back the answer to the client if the request has been handled
0049      * @return true if the request has been handled and if customAnswer is valid and will be sent back to the client.
0050      */
0051     bool processCustomVerbRequest(const QByteArray &requestType, const QByteArray &requestData,
0052         const QMap<QByteArray, QByteArray> &httpHeaders, QByteArray &customAnswer) override;
0053 
0054 private:
0055     std::unique_ptr<QIODevice> downloadDeviceXmlDescription(UpnpAbstractDevice *device, QByteArray &contentType);
0056 
0057     std::unique_ptr<QIODevice> downloadServiceXmlDescription(UpnpAbstractDevice *device, const int serviceIndex, QByteArray &contentType);
0058 
0059     std::unique_ptr<UpnpDeviceSoapServerObjectPrivate> d;
0060 };
0061 
0062 #endif // UPNPDEVICESOAPSERVEROBJECT_H