Warning: That file was not part of the compilation database. It may have many parsing errors.

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 "mdnsd-responder.h"
22#include "servicebase.h"
23#include <kurl.h>
24#include <QtCore/QCoreApplication>
25
26namespace DNSSD
27{
28
29Responder::Responder(DNSServiceRef ref,QObject *parent)
30 : QObject(parent), m_ref(0), m_socket(0)
31{
32 setRef(ref);
33}
34
35void Responder::setRef(DNSServiceRef ref)
36{
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;
46}
47Responder::~Responder()
48{
49 stop();
50}
51
52void Responder::stop()
53{
54 delete m_socket;
55 m_socket = 0;
56 if (m_ref) DNSServiceRefDeallocate(m_ref);
57 m_ref = 0;
58 m_running = false;
59}
60
61
62void Responder::process()
63{
64 if ( DNSServiceProcessResult(m_ref) != kDNSServiceErr_NoError) stop();
65}
66
67bool Responder::isRunning() const
68{
69 return m_running;
70}
71
72QByteArray domainToDNS(const QString &domain)
73{
74 if (domainIsLocal(domain)) return domain.toUtf8();
75 else return KUrl::toAce(domain);
76}
77
78QString DNSToDomain(const char* domain)
79{
80 if (domainIsLocal(domain)) return QString::fromUtf8(domain);
81 else return KUrl::fromAce(domain);
82}
83
84}
85#include "mdnsd-responder.moc"
86

Warning: That file was not part of the compilation database. It may have many parsing errors.