| # dnssd Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# responder.cpp

    00001 /* This file is part of the KDE project
    00002  *
    00003  * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
    00004  *
    00005  * This library is free software; you can redistribute it and/or
    00006  * modify it under the terms of the GNU Library General Public
    00007  * License as published by the Free Software Foundation; either
    00008  * version 2 of the License, or (at your option) any later version.
    00009  *
    00010  * This library is distributed in the hope that it will be useful,
    00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013  * Library General Public License for more details.
    00014  *
    00015  * You should have received a copy of the GNU Library General Public License
    00016  * along with this library; see the file COPYING.LIB.  If not, write to
    00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018  * Boston, MA 02111-1307, USA.
    00019  */
    00020
    00021 #include "responder.h"
    00022 #include <qapplication.h>
    00023 #include <kidna.h>
    00024
    00025 // dns_sd.h API should care about proper encoding of non-latin1 characters
    00026 // but for now it does not
    00027 #define IDN_BROKEN_IN_MDNSRESPONDER
    00028
    00029 namespace DNSSD
    00030 {
    00031
    00032 Responder::Responder(DNSServiceRef ref,QObject *parent, const char *name)
    00033         : QObject(parent, name), m_ref(0), m_socket(0)
    00034 {
    00035     setRef(ref);
    00036 }
    00037
    00038 void Responder::setRef(DNSServiceRef ref)
    00039 {
    00040     if (m_socket || m_ref) stop();
    00041     m_running = false;
    00042     m_ref = ref;
    00043     if (m_ref == 0 ) return;
    00044 #ifdef HAVE_DNSSD
    00045     int fd = DNSServiceRefSockFD(ref);
    00046     if (fd == -1) return;
    00047     m_socket = new QSocketNotifier(fd,QSocketNotifier::Read,this);
    00048     connect(m_socket,SIGNAL(activated(int)),this,SLOT(process()));
    00049     m_running = true;
    00050 #endif
    00051 }
    00052 Responder::~Responder()
    00053 {
    00054     stop();
    00055 }
    00056
    00057 void Responder::stop()
    00058 {
    00059     if (m_socket) delete m_socket;
    00060     m_socket = 0;
    00061 #ifdef HAVE_DNSSD
    00062     if (m_ref) DNSServiceRefDeallocate(m_ref);
    00063 #endif
    00064     m_ref = 0;
    00065     m_running = false;
    00066 }
    00067
    00068
    00069 void Responder::process()
    00070 {
    00071 #ifdef HAVE_DNSSD
    00072     if ( DNSServiceProcessResult(m_ref) != kDNSServiceErr_NoError) stop();
    00073 #endif
    00074 }
    00075
    00076 bool Responder::isRunning() const
    00077 {
    00078     return m_running;
    00079 }
    00080
    00081 bool domainIsLocal(const QString& domain)
    00082 {
    00083     return domain.section('.',-1,-1).lower()=="local";
    00084 }
    00085
    00086 QCString domainToDNS(const QString &domain)
    00087 {
    00088 #ifdef IDN_BROKEN_IN_MDNSRESPONDER
    00089     if (domainIsLocal(domain)) return domain.utf8();
    00090         else return KIDNA::toAsciiCString(domain);
    00091 #else
    00092     return domain.utf8();
    00093 #endif
    00094 }
    00095
    00096 QString DNSToDomain(const char* domain)
    00097 {
    00098 #ifdef IDN_BROKEN_IN_MDNSRESPONDER
    00099     if (domainIsLocal(domain)) return QString::fromUtf8(domain);
    00100         else return KIDNA::toUnicode(domain);
    00101 #else
    00102     return QString::fromUtf8(domain);
    00103 #endif
    00104 }
    00105
    00106
    00107 }
    00108 #include "responder.moc"

This file is part of the documentation for dnssd Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:28:18 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003