summaryrefslogtreecommitdiffstats
path: root/dnssd/servicebase.h
blob: 89afed99e5b3319590d21bcbb23f1f78cad45fdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* This file is part of the KDE project
 *
 * Copyright (C) 2004 Jakub Stachowski <[email protected]>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifndef DNSSDSERVICEBASE_H
#define DNSSDSERVICEBASE_H

#include <tqmap.h>
#include <ksharedptr.h>

class TQString;
class TQDataStream;
namespace DNSSD
{
class ServiceBasePrivate;

/**
This class is used to carry information about service. It can be remote, local,
metaservice or domain. Metaservice has only type and domain - it means that
services of given type are present in given domain.
@short Describes any type of service.
@author Jakub Stachowski
 */
class TDEDNSSD_EXPORT ServiceBase : public TDEShared
{
public:
	typedef TDESharedPtr<ServiceBase> Ptr;

	/**
	@param name Service name - empty for metaservices
	@param type Service type - empty for domains
	@param domain Domain name
	@param host Host name
	@param port Port number
	 */
	ServiceBase(const TQString& name=TQString::null,const TQString& type=TQString::null,
		    const TQString& domain=TQString::null, const TQString& host=TQString::null,
		    unsigned short port=0);

	virtual  ~ServiceBase();

	/**
	Returns name of service. This is empty for metaservices
	 */
	const TQString& serviceName() const;

	/**
	Returns type of service. It always in format _sometype._udp or _sometype._tcp and
	it is empty for domains.
	 */
	const TQString& type() const;

	/**
	Returns domain that given service belongs to. It is "local." for link-local services.
	 */
	const TQString& domain() const;

	/**
	Returns hostname. It is only valid for local and resolved remote services.
	 */
	const TQString& hostName() const;

	/**
	Returns port number. It is only valid for local and resolved remote services.
	 */
	unsigned short port() const;

	/**
	Returns read only map of text properties.  It is only valid for local and resolved remote services.
	 */
	const TQMap<TQString,TQString>& textData() const;

protected:
	TQString m_serviceName;
	TQString m_type;
	TQString m_domain;
	TQString m_hostName;
	unsigned short m_port;

	/**
	Map of TXT properties
	 */
	TQMap<TQString,TQString> m_textData;
	/**
	Encode service name, type and domain into string that can be used as DNS-SD PTR label
	 */
	TQString encode();
	/**
	Decode PTR label returned by DNS resolver into service name, type and domain. It also
	handles special cases - metaservices and domains.
	 */
	void decode(const TQString& name);

	friend TDEDNSSD_EXPORT TQDataStream & operator<< (TQDataStream & s, const ServiceBase & a);
	friend TDEDNSSD_EXPORT TQDataStream & operator>> (TQDataStream & s, ServiceBase & a);

	virtual void virtual_hook(int, void*);
private:
	ServiceBasePrivate* d;

};

}

#endif