KDNSSD

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

KDE's Doxygen guidelines are available online.