File indexing completed on 2024-05-19 05:00:42
0001 /* 0002 SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef ZEROCONFURL_H 0008 #define ZEROCONFURL_H 0009 0010 // KF 0011 #include <KDNSSD/RemoteService> 0012 // Qt 0013 #include <QUrl> 0014 0015 0016 // URL zeroconf:/_http._tcp/some%20service 0017 class ZeroConfUrl 0018 { 0019 public: 0020 enum Type { InvalidUrl, RootDir, ServiceDir, Service }; 0021 0022 public: 0023 explicit ZeroConfUrl( const QUrl& url ); 0024 0025 public: 0026 const QString& serviceType() const; 0027 const QString& serviceName() const; 0028 const QString& domain() const; 0029 bool matches( const RemoteService* remoteService ) const; 0030 ZeroConfUrl::Type type() const; 0031 0032 private: 0033 QString mServiceType; 0034 QString mServiceName; 0035 QString mDomain; 0036 }; 0037 0038 0039 inline ZeroConfUrl::ZeroConfUrl( const QUrl& url ) 0040 { 0041 mServiceType = url.path().section(QChar::fromLatin1('/'),1,1); 0042 mServiceName = url.path().section(QChar::fromLatin1('/'),2,-1); 0043 mDomain = url.host(); 0044 } 0045 0046 inline const QString& ZeroConfUrl::serviceType() const { return mServiceType; } 0047 inline const QString& ZeroConfUrl::serviceName() const { return mServiceName; } 0048 inline const QString& ZeroConfUrl::domain() const { return mDomain; } 0049 0050 inline bool ZeroConfUrl::matches( const RemoteService* remoteService ) const 0051 { 0052 return ( remoteService->serviceName()==mServiceName && remoteService->type()==mServiceType 0053 && remoteService->domain()==mDomain); 0054 } 0055 0056 // TODO: how is a invalid url defined? 0057 inline ZeroConfUrl::Type ZeroConfUrl::type() const 0058 { 0059 Type result = 0060 mServiceType.isEmpty() ? RootDir : 0061 mServiceName.isEmpty() ? ServiceDir : 0062 /*else*/ Service; 0063 0064 return result; 0065 } 0066 0067 #endif