From kde-core-devel Tue Aug 06 13:48:43 2002 From: Lubos Lunak Date: Tue, 06 Aug 2002 13:48:43 +0000 To: kde-core-devel Subject: Short hostnames in URLs X-MARC-Message: https://marc.info/?l=kde-core-devel&m=102864151829531 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--------------Boundary-00=_81DFFLV6M9V24YAWSMNK" --------------Boundary-00=_81DFFLV6M9V24YAWSMNK Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hello, could somebody review the attached patch fixing #22901 ? Many people use= only=20 hostnames without domains for hosts in their local network, and Konqueror= now=20 redirects such requests to Real^H^H^H^HGoogle, which is pretty annoying. = My=20 change checks if the given cmd can be a short hostname. There's 0,5sec=20 timeout on the DNS lookup, so I don't think it should be noticeable,=20 especially as it's the last thing done in the URI filter (could somebody = on=20 dial-up please check?). (The patches belong in kdebase/kcontrol/ebrowing/plugins/shorturi). --=20 Lubos Lunak llunak@suse.cz ; l.lunak@kde.org http://dforce.sh.cvut.cz/~seli --------------Boundary-00=_81DFFLV6M9V24YAWSMNK Content-Type: text/x-diff; charset="us-ascii"; name="kshorturifilter.cpp.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kshorturifilter.cpp.patch" --- kshorturifilter.cpp.sav Sat Dec 29 17:59:54 2001 +++ kshorturifilter.cpp Tue Aug 6 15:09:55 2002 @@ -24,10 +24,14 @@ #include #include #include +#include #include #include #include +#include +#include +#include #include #include @@ -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; --------------Boundary-00=_81DFFLV6M9V24YAWSMNK Content-Type: text/x-diff; charset="us-ascii"; name="kshorturifilter.h.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="kshorturifilter.h.patch" --- 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 --------------Boundary-00=_81DFFLV6M9V24YAWSMNK--