fix tricky regression noticed by Vyacheslav Tokarev on Google Reader.
[kdelibs.git] / dnssd / mdnsd-responder.cpp
blob11b780d0b077baf61169a4a908b0e194c286088c
1 /* This file is part of the KDE project
3 * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
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.
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.
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.
21 #include "mdnsd-responder.h"
22 #include "servicebase.h"
23 #include <kurl.h>
24 #include <QtCore/QCoreApplication>
26 namespace DNSSD
29 Responder::Responder(DNSServiceRef ref,QObject *parent)
30 : QObject(parent), m_ref(0), m_socket(0)
32 setRef(ref);
35 void Responder::setRef(DNSServiceRef ref)
37 if (m_socket || m_ref) stop();
38 m_running = false;
39 m_ref = ref;
40 if (m_ref == 0 ) return;
41 int fd = DNSServiceRefSockFD(ref);
42 if (fd == -1) return;
43 m_socket = new QSocketNotifier(fd,QSocketNotifier::Read,this);
44 connect(m_socket,SIGNAL(activated(int)),this,SLOT(process()));
45 m_running = true;
47 Responder::~Responder()
49 stop();
52 void Responder::stop()
54 if (m_socket) delete m_socket;
55 m_socket = 0;
56 if (m_ref) DNSServiceRefDeallocate(m_ref);
57 m_ref = 0;
58 m_running = false;
62 void Responder::process()
64 if ( DNSServiceProcessResult(m_ref) != kDNSServiceErr_NoError) stop();
67 bool Responder::isRunning() const
69 return m_running;
72 QByteArray domainToDNS(const QString &domain)
74 if (domainIsLocal(domain)) return domain.toUtf8();
75 else return KUrl::toAce(domain);
78 QString DNSToDomain(const char* domain)
80 if (domainIsLocal(domain)) return QString::fromUtf8(domain);
81 else return KUrl::fromAce(domain);
85 #include "mdnsd-responder.moc"