localdomain short URI filter

Oswald Buddenhagen ossi at kde.org
Wed May 7 13:56:10 BST 2003


hi,

i noticed that my local proxy does not grok unqualified hostnames.
therefore i suggest the attached patch, which makes the filter expand
the hostname to the cname returned by gethostbyname. should i commit?

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
-------------- next part --------------
? ldomexpand.diff
Index: klocaldomainurifilterhelper.c
===================================================================
RCS file: /home/kde/kdebase/kcontrol/ebrowsing/plugins/localdomain/klocaldomainurifilterhelper.c,v
retrieving revision 1.6
diff -u -r1.6 klocaldomainurifilterhelper.c
--- klocaldomainurifilterhelper.c	1 Apr 2003 14:46:06 -0000	1.6
+++ klocaldomainurifilterhelper.c	7 May 2003 12:45:41 -0000
@@ -25,12 +25,15 @@
 #endif
 
 #include <netdb.h>
+#include <stdio.h>
 
 int main( int argc, char* argv[] )
-    {
+{
     struct hostent* ent;
     if( argc != 2 )
 	return 2;
     ent = gethostbyname( argv[ 1 ] );
+    if (ent)
+	fputs( ent->h_name, stdout );
     return (ent != NULL || h_errno == NO_ADDRESS) ? 0 : 1;
-    }
+}
Index: localdomainurifilter.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.cpp,v
retrieving revision 1.12
diff -u -r1.12 localdomainurifilter.cpp
--- localdomainurifilter.cpp	7 May 2003 11:40:25 -0000	1.12
+++ localdomainurifilter.cpp	7 May 2003 12:45:41 -0000
@@ -18,15 +18,17 @@
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 
-#include "localdomainurifilter.h"
+#include <config.h>
 
-#include <qregexp.h>
+#include "localdomainurifilter.h"
 
 #include <kprocess.h>
 #include <kstandarddirs.h>
-#include <config.h>
 #include <kdebug.h>
 
+#include <qregexp.h>
+#include <qfile.h>
+
 #define HOSTPORT_PATTERN "[a-zA-Z][a-zA-Z0-9-]*:[0-9]+"
 
 LocalDomainURIFilter::LocalDomainURIFilter( QObject *parent, const char *name,
@@ -66,31 +68,42 @@
 }
 
 // if it's e.g. just 'www', try if it's a hostname in the local search domain
-bool LocalDomainURIFilter::isLocalDomainHost( const QString& cmd ) const
+bool LocalDomainURIFilter::isLocalDomainHost( QString& cmd ) const
 {
     // find() returns -1 when no match -> left()/truncate() are noops then
     QString host( cmd.left( cmd.find( '/' ) ) );
     host.truncate( host.find( ':' ) ); // Remove port number
 
-    if( host == last_host && last_time > time( NULL ) - 5 )
-        return last_result;
+    if( !(host == last_host && last_time > time( NULL ) - 5 ) ) {
 
-    QString helper = KStandardDirs::findExe(QString::fromLatin1( "klocaldomainurifilterhelper" ));
-    if( helper.isEmpty())
-        return last_result = false;
+        QString helper = KStandardDirs::findExe(QString::fromLatin1( "klocaldomainurifilterhelper" ));
+        if( helper.isEmpty())
+            return last_result = false;
 
-    KProcess proc;
-    proc << helper << host;
-    if( !proc.start( KProcess::NotifyOnExit ))
-        return last_result = false;
+        m_fullname = QString::null;
 
-    last_host = host;
-    last_time = time( (time_t *)0 );
+        KProcess proc;
+        proc << helper << host;
+        connect( &proc, SIGNAL(receivedStdout(KProcess *, char *, int)),
+                 SLOT(receiveOutput(KProcess *, char *, int)) );
+        if( !proc.start( KProcess::NotifyOnExit, KProcess::Stdout ))
+            return last_result = false;
 
-    if( proc.wait( 1 ) && proc.normalExit() && proc.exitStatus() == 0)
-        return last_result = true;
+        last_host = host;
+        last_time = time( (time_t *)0 );
 
-    return last_result = false;
+        last_result = proc.wait( 1 ) && proc.normalExit() && !proc.exitStatus();
+
+        if( !m_fullname.isEmpty() )
+            cmd.replace( 0, host.length(), m_fullname );
+    }
+
+    return last_result;
+}
+
+void LocalDomainURIFilter::receiveOutput( KProcess *, char *buf, int )
+{
+    m_fullname = QFile::decodeName( buf );
 }
 
 void LocalDomainURIFilter::configure()
Index: localdomainurifilter.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.h,v
retrieving revision 1.5
diff -u -r1.5 localdomainurifilter.h
--- localdomainurifilter.h	13 Mar 2003 15:40:43 -0000	1.5
+++ localdomainurifilter.h	7 May 2003 12:45:41 -0000
@@ -29,6 +29,7 @@
 #include <qregexp.h>
 
 class KInstance;
+class KProcess;
 
 /*
  This filter takes care of hostnames in the local search domain.
@@ -50,11 +51,15 @@
     virtual void configure();
 
   private:
-    bool isLocalDomainHost( const QString& cmd ) const;
+    bool isLocalDomainHost( QString& cmd ) const;
     mutable QString last_host;
     mutable bool last_result;
     mutable time_t last_time;
+    mutable QString m_fullname;
     QRegExp m_hostPortPattern;
+
+  private slots:
+    void receiveOutput( KProcess *, char *, int );
 };
 
 #endif


More information about the kde-core-devel mailing list