[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Short hostnames in URLs
From: Lubos Lunak <l.lunak () sh ! cvut ! cz>
Date: 2002-08-07 16:45:27
[Download RAW message or body]
Dne st 7. srpen 2002 16:45 Simon Hausmann napsal(a):
[snip]
> >
> > QDns is not blocking. Never. You just need to connect the right signals
> > and enter (or return to) the event loop.
>
> The fact that the urifilter API is sync is a pity in this very case,
> but I think we shouldn't try to work around it. IMHO there should be
> no code in kdelibs (and I consider this plugin to be a kdelibs
> thing, because it is loaded by kdelibs in every default setup) using
> enter_loop()/exit_loop() or equivalent constructs, unless it is
> explicitly mentioned in the documentation or somewhere.
> enter_loop()/processEvents is asking for absolutely nothing but
> trouble. Just imagine the lookup takes a bit too long and the user
> closes the konqueror window in the meantime.
*sigh* ... ok.
>
> Aside from that I second Waldo's concern about QDns. The class does
> not obey /etc/nsswitch.conf at all (yes, I've seen setups where host
> lookups were partially done through NIS :(
>
> I'd probably dump the feature instead of taking the risk.
I wouldn't. Attached is try #2. Unless there are some more technical details
to discuss, could now somebody with dial-up check if the timeout value
doesn't cause some problems?
--
Lubos Lunak
llunak@suse.cz ; l.lunak@kde.org
http://dforce.sh.cvut.cz/~seli
["Makefile.am.patch" (text/x-makefile)]
--- Makefile.am.sav Sun Dec 31 06:08:40 2000
+++ Makefile.am Wed Aug 7 18:16:07 2002
@@ -19,3 +19,7 @@ rc_DATA = kshorturifilterrc
rcdir = $(kde_confdir)
METASOURCES = AUTO
+
+bin_PROGRAMS = kshorturifilterhelper
+
+kshorturifilterhelper_SOURCES = kshorturifilterhelper.c
["kshorturifilter.cpp.patch" (text/x-diff)]
--- kshorturifilter.cpp.sav Sat Dec 29 17:59:54 2001
+++ kshorturifilter.cpp Wed Aug 7 18:31:33 2002
@@ -37,6 +37,8 @@
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kconfig.h>
+#include <kstandarddirs.h>
+#include <kprocess.h>
//#include "kshorturiopts.h"
#include "kshorturifilter.h"
@@ -60,14 +62,51 @@ 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
+{
+ QString host( cmd.contains( '/' ) ? cmd.left( cmd.find( '/' )) : cmd );
+ pid_t pid;
+
+ {
+ QString helper = KStandardDirs::findExe( QString::fromLatin1( "kshorturifilterhelper" ));
+ if( helper.isEmpty())
+ return false;
+ KProcess proc;
+ proc << helper << host;
+ if( !proc.start( KProcess::DontCare ))
+ return false;
+ pid = proc.getPid();
+ } // destroy 'proc', so that KProcessController now won't do waitpid()
+ // on the process immediatelly
+ for( int rounds = 0;
+ rounds < 10;
+ ++rounds )
+ {
+ int status;
+ int ret = waitpid( pid, &status, WNOHANG );
+ if( ret < 0 )
+ return false;
+ if( ret > 0 )
+ return WIFEXITED( status ) && WEXITSTATUS( status ) == 0;
+ struct timespec tm;
+ tm.tv_sec = 0;
+ tm.tv_nsec = 50 * 1000 * 1000; // 50ms
+ nanosleep( &tm, NULL );
+ }
+ kill( pid, SIGTERM );
+ return false;
+}
+
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 Wed Aug 7 17:18:00 2002
@@ -118,6 +118,7 @@ protected:
bool expandEnvVar( QString& ) const;
private:
+ bool isInLocalDomain( const QString& cmd ) const;
struct URLHint
{
["kshorturifilterhelper.c.patch" (text/x-diff)]
--- kshorturifilterhelper.c.sav Wed Aug 7 18:16:17 2002
+++ kshorturifilterhelper.c Wed Aug 7 18:22:56 2002
@@ -0,0 +1,33 @@
+/*
+ kshorturifilterhelper.cpp
+
+ This file is part of the KDE project
+ Copyright (C) 2002 Lubos Lunak <llunak@suse.cz>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+/* Helper for KShortURIFilter for finding out if a host exist */
+
+#include <netdb.h>
+
+int main( int argc, char* argv[] )
+ {
+ struct hostent* ent;
+ if( argc != 2 )
+ return 2;
+ ent = gethostbyname( argv[ 1 ] );
+ return ent != NULL ? 0 : 1;
+ }
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic