[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    DNS-SD discovery for krdc
From:       Jakub Stachowski <stachowski () hypair ! net>
Date:       2004-11-28 15:36:20
Message-ID: 200411281636.20845.stachowski () hypair ! net
[Download RAW message or body]

Hello,

Following patch adds ability to discover VNC and RDP servers using DNS based 
service discovery (ZeroConf, Rendezvous). Existing SLP-based discovery is 
still working (DNS-SD adds itself as new scope). 

In kdenonbeta/kdnssd/patches/kpf.patch there is second patch causing kpf to 
announce its shared directories on network (also using DNS-SD). I don't 
attach it as it is quite big (over 20k).

Both patches rely on libkdnssd library that I have been developing for some 
time (see kdenonbeta/kdnssd). If you think that it is useful and polished 
enough , I would like to move it to kdenetwork (at least library and kcm 
module). 

There is also Ioslave - working but I still need to write kded module 
providing dynamic updates via KDirNotify.

Comments, opinions, suggestions?

["krdc.patch" (text/x-diff)]

diff -urdP krdc-old/maindialogbase.ui krdc/maindialogbase.ui
--- krdc-old/maindialogbase.ui	2004-07-14 00:10:29.000000000 +0200
+++ krdc/maindialogbase.ui	2004-11-28 14:42:17.000000000 +0100
@@ -317,12 +317,6 @@
         <slot>rescan()</slot>
     </connection>
     <connection>
-        <sender>m_scopeCombo</sender>
-        <signal>activated(int)</signal>
-        <receiver>MainDialogBase</receiver>
-        <slot>rescan()</slot>
-    </connection>
-    <connection>
         <sender>m_serverInput</sender>
         <signal>textChanged(const QString&amp;)</signal>
         <receiver>MainDialogBase</receiver>
diff -urdP krdc-old/maindialogwidget.cpp krdc/maindialogwidget.cpp
--- krdc-old/maindialogwidget.cpp	2004-05-24 17:42:23.000000000 +0200
+++ krdc/maindialogwidget.cpp	2004-11-28 14:35:49.000000000 +0100
@@ -33,6 +33,7 @@
 #include "maindialogwidget.h"
 
 static const QString DEFAULT_SCOPE = "default";
+static const QString DNSSD_SCOPE = "DNS-SD";
 
 class UrlListViewItem : public KListViewItem
 {
@@ -67,6 +68,10 @@
   {
     return m_url;
   }
+  const QString& serviceid() const
+  {
+    return m_serviceid;
+  }
 
   protected:
     QString m_url;
@@ -75,7 +80,7 @@
 
 MainDialogWidget::MainDialogWidget( QWidget *parent, const char *name )
     : MainDialogBase( parent, name ),
-      m_scanning( false )
+      m_scanning( false ), m_locator_vnc(0), m_locator_rdp(0)
 {
   HostPreferences *hp = HostPreferences::instance();
   QStringList list;
@@ -174,9 +179,9 @@
 {
   UrlListViewItem *u = ( UrlListViewItem* ) item;
   QRegExp rx( "^service:remotedesktop\\.kde:([^;]*)" );
-  if ( rx.search( u->url() ) < 0 )
-    return;
-  m_serverInput->setCurrentText( rx.cap( 1 ) );
+  if ( rx.search( u->url() ) < 0 ) 
+    m_serverInput->setCurrentText( u->url());
+    else m_serverInput->setCurrentText( rx.cap( 1 ) );
 }
 
 void MainDialogWidget::itemDoubleClicked( QListViewItem *item )
@@ -211,18 +216,38 @@
 
   m_browsingView->clear();
 
-  QString filter;
-  if ( !m_searchInput->text().stripWhiteSpace().isEmpty() ) {
-    QString ef = KServiceLocator::escapeFilter(
-      m_searchInput->text().stripWhiteSpace() );
-    filter = "(|(|(description=*"+ef+"*)(username=*"+ef+"*))(fullname=*"+ef+"*))";
-  }
+  if (m_locator_vnc) delete m_locator_vnc;  // still active browsers
+  if (m_locator_rdp) delete m_locator_rdp;
 
-  if ( !m_locator->findServices( "service:remotedesktop.kde",
-                                 filter, m_scope ) ) {
-    kdWarning() << "Failure in findServices()" << endl;
-    errorScanning();
-    return;
+  if (m_scope == DNSSD_SCOPE) {
+    m_locator_vnc = new DNSSD::ServiceBrowser("_rfb._tcp",0,true);
+    m_locator_rdp = new DNSSD::ServiceBrowser("_rdp._tcp",0,true);
+    connect(m_locator_vnc,SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),
+      SLOT(addedService(DNSSD::RemoteService::Ptr)));
+    connect(m_locator_vnc,SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),
+      SLOT(removedService(DNSSD::RemoteService::Ptr)));
+    connect(m_locator_rdp,SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),
+      SLOT(addedService(DNSSD::RemoteService::Ptr)));
+    connect(m_locator_rdp,SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),
+      SLOT(removedService(DNSSD::RemoteService::Ptr)));
+    m_locator_vnc->startBrowse();
+    m_locator_rdp->startBrowse();
+    // now find scopes
+    lastSignalServices(true);
+  } else {
+    QString filter;
+    if ( !m_searchInput->text().stripWhiteSpace().isEmpty() ) {
+      QString ef = KServiceLocator::escapeFilter(
+        m_searchInput->text().stripWhiteSpace() );
+      filter = "(|(|(description=*"+ef+"*)(username=*"+ef+"*))(fullname=*"+ef+"*))";
+    }
+
+    if ( !m_locator->findServices( "service:remotedesktop.kde",
+                                   filter, m_scope ) ) {
+      kdWarning() << "Failure in findServices()" << endl;
+      errorScanning();
+      return;
+    }
   }
 }
 
@@ -289,6 +314,28 @@
       KServiceLocator::decodeAttributeValue( map[ "serviceid" ] ) );
 }
 
+void MainDialogWidget::addedService( DNSSD::RemoteService::Ptr service )
+{
+QString type = service->type().mid(1,3);
+if (type == "rfb") type = "vnc";
+QString url = type+"://"+service->hostName()+":"+QString::number(service->port());
+new UrlListViewItem( m_browsingView, url, service->serviceName(),
+     type.upper(),service->textData()["type"],
+     service->textData()["u"],service->textData()["fullname"],
+     service->textData()["description"],service->serviceName()+service->domain());
+}
+
+void MainDialogWidget::removedService( DNSSD::RemoteService::Ptr service )
+{
+  QListViewItemIterator it( m_browsingView );
+  while ( it.current() ) {
+    if ( ((UrlListViewItem*)it.current())->serviceid() == \
service->serviceName()+service->domain() ) +      delete it.current();
+      else ++it;
+  }
+}
+
+
 void MainDialogWidget::lastSignalServices( bool success )
 {
   if ( !success )
@@ -306,8 +353,7 @@
 
 void MainDialogWidget::foundScopes( QStringList scopeList )
 {
-  if ( scopeList.isEmpty() )
-    return;
+  scopeList << DNSSD_SCOPE;  
 
   int di = scopeList.findIndex( DEFAULT_SCOPE );
   if ( di >= 0 )
diff -urdP krdc-old/maindialogwidget.h krdc/maindialogwidget.h
--- krdc-old/maindialogwidget.h	2004-02-21 23:53:23.000000000 +0100
+++ krdc/maindialogwidget.h	2004-11-27 20:25:00.000000000 +0100
@@ -23,6 +23,8 @@
 
 #include "kservicelocator.h"
 #include "maindialogbase.h"
+#include <dnssd/servicebrowser.h>
+#include <dnssd/remoteservice.h>
 #include "smartptr.h"
 
 class MainDialogWidget : public MainDialogBase
@@ -58,11 +60,16 @@
     void foundService( QString url, int );
     void lastSignalServices( bool success );
     void foundScopes( QStringList scopeList );
+    void addedService( DNSSD::RemoteService::Ptr );
+    void removedService( DNSSD::RemoteService::Ptr );
+
 
   protected:
     QString m_scope;
     bool m_scanning;
     SmartPtr<KServiceLocator> m_locator;
+    DNSSD::ServiceBrowser *m_locator_vnc;
+    DNSSD::ServiceBrowser *m_locator_rdp;
 };
 
 #endif // MAINDIALOGWIDGET_H
diff -urdP krdc-old/Makefile.am krdc/Makefile.am
--- krdc-old/Makefile.am	2004-03-10 19:56:59.000000000 +0100
+++ krdc/Makefile.am	2004-11-27 21:42:10.000000000 +0100
@@ -21,7 +21,7 @@
   iconify.png close.png
 
 
-krdc_LDADD   = vnc/libvnc.la rdp/librdp.la $(LIB_KDEUI) $(LIBXF86VIDMODE) $(LIB_SLP) \
-L/usr/X11R6/lib -lX11 +krdc_LDADD   = vnc/libvnc.la rdp/librdp.la $(LIB_KDEUI) \
$(LIBXF86VIDMODE) $(LIB_SLP) -L/usr/X11R6/lib -lX11 -lkdnssd  krdc_LDFLAGS = \
$(all_libraries) $(KDE_RPATH)  
 xdg_apps_DATA = krdc.desktop



>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic