1 /*
2     SPDX-FileCopyrightText: 2004, 2005 Jakub Stachowski <qbast@go2.pl>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef _dnssd_H_
8 #define _dnssd_H_
9 
10 // KF
11 #include <KIO/SlaveBase>
12 #include <KDNSSD/ServiceBrowser>
13 #include <KDNSSD/ServiceTypeBrowser>
14 #include <KDNSSD/RemoteService>
15 // Qt
16 #include <QObject>
17 
18 
19 using namespace KIO;
20 using namespace KDNSSD;
21 
22 class ZeroConfUrl;
23 
24 struct ProtocolData
25 {
ProtocolDataProtocolData26     ProtocolData() {}
27     ProtocolData( const QString& _name, const QString& proto,
28                   const QString& path=QString(), const QString& user=QString(), const QString& passwd=QString() )
nameProtocolData29      : name(_name), protocol(proto), pathEntry(path), userEntry(user), passwordEntry(passwd)
30     {}
31 
32     void feedUrl( QUrl* url, const RemoteService* remoteService ) const;
33 
34     QString name;
35     QString protocol;
36     QString pathEntry;
37     QString userEntry;
38     QString passwordEntry;
39 };
40 
41 class ZeroConfProtocol : public QObject, public KIO::SlaveBase
42 {
43     Q_OBJECT
44 public:
45     ZeroConfProtocol( const QByteArray& protocol, const QByteArray& pool_socket, const QByteArray& app_socket);
46     ~ZeroConfProtocol() override;
47 
48 public: // KIO::SlaveBase API
49     void get( const QUrl& url ) override;
50     void mimetype( const QUrl& url ) override;
51     void stat( const QUrl& url ) override;
52     void listDir( const QUrl& url ) override;
53 
54 Q_SIGNALS:
55     void leaveModality();
56 
57 private:
58     // Create UDSEntry for zeroconf:/ or zeroconf:/type/ urls
59     void feedEntryAsDir( UDSEntry* entry, const QString& name, const QString& displayName = QString() );
60     // resolve given service and redirect() to it
61     void resolveAndRedirect( const ZeroConfUrl& zeroConfUrl );
62 
63     void listCurrentDirEntry();
64 
65     bool dnssdOK();
66 
67     void enterLoop();
68 
69 private Q_SLOTS:
70     void addServiceType( const QString& );
71     void addService( KDNSSD::RemoteService::Ptr );
72     void onBrowserFinished();
73 
74 private: // data
75     ServiceBrowser* serviceBrowser;
76     ServiceTypeBrowser* serviceTypeBrowser;
77     // service types merged from all domains - to avoid duplicates
78     QStringList ServiceTypesAdded;
79 
80     RemoteService* serviceToResolve;
81     QHash<QString,ProtocolData> knownProtocols;
82 };
83 
84 #endif
85