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

List:       kde-core-devel
Subject:    Short hostnames in URLs
From:       Lubos Lunak <l.lunak () sh ! cvut ! cz>
Date:       2002-08-06 13:48:43
[Download RAW message or body]

Hello,

 could somebody review the attached patch fixing #22901 ? Many people use only 
hostnames without domains for hosts in their local network, and Konqueror now 
redirects such requests to Real^H^H^H^HGoogle, which is pretty annoying. My 
change checks if the given cmd can be a short hostname. There's 0,5sec 
timeout on the DNS lookup, so I don't think it should be noticeable, 
especially as it's the last thing done in the URI filter (could somebody on 
dial-up please check?).

 (The patches belong in kdebase/kcontrol/ebrowing/plugins/shorturi).
-- 
 Lubos Lunak
 llunak@suse.cz ; l.lunak@kde.org
 http://dforce.sh.cvut.cz/~seli

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

--- kshorturifilter.cpp.sav	Sat Dec 29 17:59:54 2001
+++ kshorturifilter.cpp	Tue Aug  6 15:09:55 2002
@@ -24,10 +24,14 @@
 #include <unistd.h>
 #include <pwd.h>
 #include <sys/stat.h>
+#include <time.h>
 
 #include <qdir.h>
 #include <qptrlist.h>
 #include <qregexp.h>
+#include <qdns.h>
+#include <qtimer.h>
+#include <qapplication.h>
 
 #include <kurl.h>
 #include <kdebug.h>
@@ -60,14 +64,48 @@ KShortURIFilter::KShortURIFilter( QObjec
     m_strDefaultProtocol = QFL1("http://");
 }
 
+// if it's e.g. just 'www', try if it's a hostname in the local search domain
+bool KShortURIFilter::isInLocalDomain( const QString& cmd ) const
+{
+    KShortURIFilterHostName check;
+    return check.check( cmd );
+}
+
+bool KShortURIFilterHostName::check( const QString& cmd )
+{
+    QDns dns( cmd.contains( '/' ) ? cmd.left( cmd.find( '/' )) : cmd );
+    query_done = false;
+    connect( &dns, SIGNAL( resultsReady()), SLOT( queryDone()));
+    QTimer::singleShot( 500, this, SLOT( queryDone()));
+    for(;;)
+    {
+	qApp->processEvents();
+	if( query_done )
+	    break;
+	struct timespec tm;
+	tm.tv_sec = 0;
+	tm.tv_nsec = 1000000000;
+	nanosleep( &tm, NULL );
+    }
+    if( dns.addresses().count() >= 1 ) // found the hostname
+	return true;
+    return false;
+}
+
+void KShortURIFilterHostName::queryDone()
+    {
+    query_done = true;
+    }
+    
 bool KShortURIFilter::isValidShortURL( const QString& cmd ) const
 {
   // Loose many of the QRegExp matches as they tend
   // to slow things down.  They are also unnecessary!! (DA)
     if ( cmd[cmd.length()-1] == '&' ||     // must not end with '&'
-       (!cmd.contains('.') && !cmd.contains(':')) ||             // must contain either '.' or ':'
        cmd.contains(QFL1("||")) || cmd.contains(QFL1("&&")) ||   // must not look like shell
-       cmd.contains(QRegExp(QFL1("[ ;<>]"))) )  // must not contain space, ;, < or >
+       cmd.contains(QRegExp(QFL1("[ ;<>]"))) ||  // must not contain space, ;, < or >
+        // must contain either '.' or ':' or be local hostname
+       (!cmd.contains('.') && !cmd.contains(':')) && !isInLocalDomain( cmd ))
        return false;
 
   return true;

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

--- kshorturifilter.h.sav	Sat Oct 27 18:33:14 2001
+++ kshorturifilter.h	Tue Aug  6 14:13:14 2002
@@ -118,6 +118,7 @@ protected:
     bool expandEnvVar( QString& ) const;
 
 private:
+    bool isInLocalDomain( const QString& cmd ) const;
 
     struct URLHint
     {
@@ -131,4 +132,16 @@ private:
     QString m_strDefaultProtocol;
 };
 
+class KShortURIFilterHostName
+    : public QObject
+    {
+    Q_OBJECT
+public:
+    bool check( const QString& cmd );
+private slots:
+    void queryDone();
+private:
+    bool query_done;
+    };
+    
 #endif


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

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