dnssd Library: servicebase.cpp Source File (dnssd Library)

| # dnssd Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# servicebase.cpp

    00001 /* This file is part of the KDE project
    00002  *
    00003  * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public License
    00016  * along with this library; see the file COPYING.LIB.  If not, write to
    00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021 #include "servicebase.h"
    00022 #include <qregexp.h>
    00023
    00024 namespace DNSSD
    00025 {
    00026
    00027 ServiceBase::ServiceBase(const QString& name, const QString& type, const QString& domain,
    00028              const QString& host, unsigned short port) :
    00029             m_serviceName(name), m_type(type), m_domain(domain), m_hostName(host), m_port(port)
    00030 {}
    00031
    00032 ServiceBase::~ServiceBase()
    00033 {}
    00034
    00035 QString ServiceBase::encode()
    00036 {
    00037     return  m_serviceName.replace(".","\\.").replace("\\","\\\\") + QString(".") + m_type +
    00038              QString(".") + m_domain;
    00039 }
    00040
    00041 // example: 3rd\.\032Floor\032Copy\032Room._ipp._tcp.dns-sd.org.  - normal service
    00042 // 3rd\.\032Floor\032Copy\032Room.dns-sd.org  - domain
    00043 //  _ipp._tcp.dns-sd.org    - metaquery
    00044
    00045 void ServiceBase::decode(const QString& name)
    00046 {
    00047     QString rest;
    00048     if (name[0]=='_') {         // metaquery
    00049         m_serviceName="";
    00050         rest=name;
    00051     } else {        // normal service or domain
    00052         QString decoded_name=name;
    00053         decoded_name=decoded_name.replace("\\\\","\\");
    00054         int i = decoded_name.find(QRegExp("[^\\\\]\\."));
    00055         if (i==-1) return;            // first find service name
    00056         rest = decoded_name.mid(i+2);
    00057         m_serviceName=decoded_name.left(i+1).replace("\\.",".");
    00058     }
    00059     m_type = rest.section('.',0,1);
    00060     // does it really have a type?
    00061     if (m_type[0]=='_' && m_type[m_type.find('.')+1]=='_')
    00062         m_domain = rest.section('.',2,-1,QString::SectionIncludeTrailingSep);
    00063     else {
    00064         m_type="";
    00065         m_domain=rest;
    00066     }
    00067 }
    00068
    00069 const QString& ServiceBase::serviceName() const
    00070 {
    00071     return m_serviceName;
    00072 }
    00073
    00074 const QString& ServiceBase::type() const
    00075 {
    00076     return m_type;
    00077 }
    00078
    00079 const QString& ServiceBase::domain() const
    00080 {
    00081     return m_domain;
    00082 }
    00083
    00084 const QString& ServiceBase::hostName() const
    00085 {
    00086     return m_hostName;
    00087 }
    00088
    00089 unsigned short ServiceBase::port() const
    00090 {
    00091     return m_port;
    00092 }
    00093 const QMap<QString,QString>& ServiceBase::textData() const
    00094 {
    00095     return m_textData;
    00096 }
    00097
    00098 void ServiceBase::virtual_hook(int, void*)
    00099 {}
    00100
    00101 QDataStream & operator<< (QDataStream & s, const ServiceBase & a)
    00102 {
    00103     s << a.m_serviceName << a.m_type << a.m_domain << a.m_hostName << Q_INT16(a.m_port) << a.m_textData;
    00104     return s;
    00105 }
    00106
    00107 QDataStream & operator>> (QDataStream & s, ServiceBase & a)
    00108 {
    00109     Q_INT16 port;
    00110     s >> a.m_serviceName >> a.m_type >> a.m_domain >> a.m_hostName >> port >> a.m_textData;
    00111     a.m_port = port;
    00112     return s;
    00113 }
    00114
    00115 }

This file is part of the documentation for dnssd Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:28:18 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003