• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • dnssd
 

dnssd

  • dnssd
servicebase.cpp
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #include "servicebase.h"
22 #include <tqregexp.h>
23 
24 namespace DNSSD
25 {
26 
27 ServiceBase::ServiceBase(const TQString& name, const TQString& type, const TQString& domain,
28  const TQString& host, unsigned short port) :
29  m_serviceName(name), m_type(type), m_domain(domain), m_hostName(host), m_port(port)
30 {}
31 
32 ServiceBase::~ServiceBase()
33 {}
34 
35 TQString ServiceBase::encode()
36 {
37  return m_serviceName.replace(".","\\.").replace("\\","\\\\") + TQString(".") + m_type +
38  TQString(".") + m_domain;
39 }
40 
41 // example: 3rd\.\032Floor\032Copy\032Room._ipp._tcp.dns-sd.org. - normal service
42 // 3rd\.\032Floor\032Copy\032Room.dns-sd.org - domain
43 // _ipp._tcp.dns-sd.org - metaquery
44 
45 void ServiceBase::decode(const TQString& name)
46 {
47  TQString rest;
48  if (name[0]=='_') { // metaquery
49  m_serviceName="";
50  rest=name;
51  } else { // normal service or domain
52  TQString decoded_name=name;
53  decoded_name=decoded_name.replace("\\\\","\\");
54  int i = decoded_name.find(TQRegExp("[^\\\\]\\."));
55  if (i==-1) return; // first find service name
56  rest = decoded_name.mid(i+2);
57  m_serviceName=decoded_name.left(i+1).replace("\\.",".");
58  }
59  m_type = rest.section('.',0,1);
60  // does it really have a type?
61  if (m_type[0]=='_' && m_type[m_type.find('.')+1]=='_')
62  m_domain = rest.section('.',2,-1,TQString::SectionIncludeTrailingSep);
63  else {
64  m_type="";
65  m_domain=rest;
66  }
67 }
68 
69 const TQString& ServiceBase::serviceName() const
70 {
71  return m_serviceName;
72 }
73 
74 const TQString& ServiceBase::type() const
75 {
76  return m_type;
77 }
78 
79 const TQString& ServiceBase::domain() const
80 {
81  return m_domain;
82 }
83 
84 const TQString& ServiceBase::hostName() const
85 {
86  return m_hostName;
87 }
88 
89 unsigned short ServiceBase::port() const
90 {
91  return m_port;
92 }
93 const TQMap<TQString,TQString>& ServiceBase::textData() const
94 {
95  return m_textData;
96 }
97 
98 void ServiceBase::virtual_hook(int, void*)
99 {}
100 
101 TQDataStream & operator<< (TQDataStream & s, const ServiceBase & a)
102 {
103  s << a.m_serviceName << a.m_type << a.m_domain << a.m_hostName << TQ_INT16(a.m_port) << a.m_textData;
104  return s;
105 }
106 
107 TQDataStream & operator>> (TQDataStream & s, ServiceBase & a)
108 {
109  TQ_INT16 port;
110  s >> a.m_serviceName >> a.m_type >> a.m_domain >> a.m_hostName >> port >> a.m_textData;
111  a.m_port = port;
112  return s;
113 }
114 
115 }
DNSSD::ServiceBase::domain
const TQString & domain() const
Returns domain that given service belongs to.
Definition: servicebase.cpp:79
DNSSD::ServiceBase::hostName
const TQString & hostName() const
Returns hostname.
Definition: servicebase.cpp:84
DNSSD::ServiceBase::port
unsigned short port() const
Returns port number.
Definition: servicebase.cpp:89
DNSSD::ServiceBase::textData
const TQMap< TQString, TQString > & textData() const
Returns read only map of text properties.
Definition: servicebase.cpp:93
DNSSD::ServiceBase::encode
TQString encode()
Encode service name, type and domain into string that can be used as DNS-SD PTR label.
Definition: servicebase.cpp:35
DNSSD::ServiceBase::m_textData
TQMap< TQString, TQString > m_textData
Map of TXT properties.
Definition: servicebase.h:99
DNSSD::ServiceBase::type
const TQString & type() const
Returns type of service.
Definition: servicebase.cpp:74
DNSSD
Definition: domainbrowser.cpp:36
DNSSD::ServiceBase::ServiceBase
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)
Definition: servicebase.cpp:27
DNSSD::ServiceBase::decode
void decode(const TQString &name)
Decode PTR label returned by DNS resolver into service name, type and domain.
Definition: servicebase.cpp:45
DNSSD::ServiceBase::serviceName
const TQString & serviceName() const
Returns name of service.
Definition: servicebase.cpp:69

dnssd

Skip menu "dnssd"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

dnssd

Skip menu "dnssd"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dnssd by doxygen 1.8.8
This website is maintained by Timothy Pearson.