File indexing completed on 2024-05-19 05:00:42
0001 /* 0002 SPDX-FileCopyrightText: 2004, 2005 Jakub Stachowski <qbast@go2.pl> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _dnssd_H_ 0008 #define _dnssd_H_ 0009 0010 // KF 0011 #include <KIO/WorkerBase> 0012 #include <KDNSSD/ServiceBrowser> 0013 #include <KDNSSD/ServiceTypeBrowser> 0014 #include <KDNSSD/RemoteService> 0015 // Qt 0016 #include <QObject> 0017 0018 0019 using namespace KIO; 0020 using namespace KDNSSD; 0021 0022 class ZeroConfUrl; 0023 0024 struct ProtocolData 0025 { 0026 ProtocolData() {} 0027 ProtocolData( const QString& _name, const QString& proto, 0028 const QString& path=QString(), const QString& user=QString(), const QString& passwd=QString() ) 0029 : name(_name), protocol(proto), pathEntry(path), userEntry(user), passwordEntry(passwd) 0030 {} 0031 0032 void feedUrl( QUrl* url, const RemoteService* remoteService ) const; 0033 0034 QString name; 0035 QString protocol; 0036 QString pathEntry; 0037 QString userEntry; 0038 QString passwordEntry; 0039 }; 0040 0041 class ZeroConfProtocol : public QObject, public KIO::WorkerBase 0042 { 0043 Q_OBJECT 0044 public: 0045 ZeroConfProtocol( const QByteArray& protocol, const QByteArray& pool_socket, const QByteArray& app_socket); 0046 ~ZeroConfProtocol() override; 0047 0048 public: // KIO::WorkerBase API 0049 KIO::WorkerResult get( const QUrl& url ) override; 0050 KIO::WorkerResult mimetype( const QUrl& url ) override; 0051 KIO::WorkerResult stat( const QUrl& url ) override; 0052 KIO::WorkerResult listDir( const QUrl& url ) override; 0053 0054 Q_SIGNALS: 0055 void leaveModality(); 0056 0057 private: 0058 // Create UDSEntry for zeroconf:/ or zeroconf:/type/ urls 0059 void feedEntryAsDir( UDSEntry* entry, const QString& name, const QString& displayName = QString() ); 0060 // resolve given service and redirect() to it 0061 KIO::WorkerResult resolveAndRedirect( const ZeroConfUrl& zeroConfUrl ); 0062 0063 void listCurrentDirEntry(); 0064 0065 KIO::WorkerResult dnssdOK(); 0066 0067 void enterLoop(); 0068 0069 private Q_SLOTS: 0070 void addServiceType( const QString& ); 0071 void addService( KDNSSD::RemoteService::Ptr ); 0072 void onBrowserFinished(); 0073 0074 private: // data 0075 ServiceBrowser* serviceBrowser; 0076 ServiceTypeBrowser* serviceTypeBrowser; 0077 // service types merged from all domains - to avoid duplicates 0078 QStringList ServiceTypesAdded; 0079 0080 RemoteService* serviceToResolve; 0081 QHash<QString,ProtocolData> knownProtocols; 0082 }; 0083 0084 #endif