KDNSSD

mdnsd-responder.cpp
1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2004 Jakub Stachowski <qbast@go2.pl>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "mdnsd-responder.h"
10#include "servicebase.h"
11#include <QCoreApplication>
12#include <QUrl>
13
14namespace KDNSSD
15{
16Responder::Responder(DNSServiceRef ref, QObject *parent)
17 : QObject(parent)
18 , m_ref(0)
19 , m_socket(0)
20{
21 setRef(ref);
22}
23
24void Responder::setRef(DNSServiceRef ref)
25{
26 if (m_socket || m_ref) {
27 stop();
28 }
29 m_running = false;
30 m_ref = ref;
31 if (m_ref == 0) {
32 return;
33 }
34 int fd = DNSServiceRefSockFD(ref);
35 if (fd == -1) {
36 return;
37 }
38 m_socket = new QSocketNotifier(fd, QSocketNotifier::Read, this);
39 connect(m_socket, SIGNAL(activated(int)), this, SLOT(process()));
40 m_running = true;
41}
42Responder::~Responder()
43{
44 stop();
45}
46
47void Responder::stop()
48{
49 delete m_socket;
50 m_socket = 0;
51 if (m_ref) {
52 DNSServiceRefDeallocate(m_ref);
53 }
54 m_ref = 0;
55 m_running = false;
56}
57
58void Responder::process()
59{
60 if (DNSServiceProcessResult(m_ref) != kDNSServiceErr_NoError) {
61 stop();
62 }
63}
64
65bool Responder::isRunning() const
66{
67 return m_running;
68}
69
70QByteArray domainToDNS(const QString &domain)
71{
72 if (domainIsLocal(domain)) {
73 return domain.toUtf8();
74 } else {
75 return QUrl::toAce(domain);
76 }
77}
78
79QString DNSToDomain(const char *domain)
80{
81 if (domainIsLocal(domain)) {
82 return QString::fromUtf8(domain);
83 } else {
84 return QUrl::fromAce(domain);
85 }
86}
87
88}
89
90#include "moc_mdnsd-responder.cpp"
void stop(Ekos::AlignState mode)
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QString fromAce(const QByteArray &domain, AceProcessingOptions options)
QByteArray toAce(const QString &domain, AceProcessingOptions options)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:48 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.