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"
24 #include <QtCore/QCoreApplication>
29 Responder::Responder(DNSServiceRef ref
,QObject
*parent
)
30 : QObject(parent
), m_ref(0), m_socket(0)
35 void Responder::setRef(DNSServiceRef ref
)
37 if (m_socket
|| m_ref
) stop();
40 if (m_ref
== 0 ) return;
41 int fd
= DNSServiceRefSockFD(ref
);
43 m_socket
= new QSocketNotifier(fd
,QSocketNotifier::Read
,this);
44 connect(m_socket
,SIGNAL(activated(int)),this,SLOT(process()));
47 Responder::~Responder()
52 void Responder::stop()
54 if (m_socket
) delete m_socket
;
56 if (m_ref
) DNSServiceRefDeallocate(m_ref
);
62 void Responder::process()
64 if ( DNSServiceProcessResult(m_ref
) != kDNSServiceErr_NoError
) stop();
67 bool Responder::isRunning() const
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"