[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-09 13:59:45
[Download RAW message or body]

Dne p 9. srpen 2002 07:52 Dawit A. napsal(a):
> On Thursday 08 August 2002 04:38, Lubos Lunak wrote:
> > Dne t 8. srpen 2002 03:43 Dawit A. napsal(a):
> > > On Wednesday 07 August 2002 12:45, Lubos Lunak wrote:
>
> [snipped]
>
> >  So instead of adding it to kshorturifilter, I should write a new plugin
> > for kdeaddons?  How does that change anything, besides being more work,
> > and explicitly saying it's mine code and not yours? Nothing will change
> > for the user.
>
> First of all kdeaddons is just a suggestion, but you can add it wherever
> you please. Second where did I say it is mine and not yours ?  I've never
> said that. However, last I checked I, just like you, have every right to
> either object or agree with any patch anyone posts.

 I was just trying to say that I don't undestand why it should be moved into 
its own plugin when there would be no difference besides it being in its own 
plugin.

> Moreover, I've given
> you the technical reason for which I object to this patch, but you flat out
> choose to dismiss them. You refuse to see that the work your patch does is
> something that needs to be handled at a lower level not in the filter
> plugin which was not designed for this purpose.  That is the very reason
> why a similar suggestion were rejected the last time this issue came up,
> but I digress.

 Ok, you understand this stuff better than I do, so where you suggest this 
'lower level' to be? If you find a better place for it, I'll change the code.

>
> Anyways, no matter how small the delay, you still end up doing multiple
> lookups on ALL one-word short url's like "localhost".

 I can cache the last hostname, that should take care of repeated filtering, 
if there's any done.

>  I 've several
> machines in the office that have easy to remember on word "short names"
> like admin. They are within one hop from where my computer is so why would
> I want to go through the nameserver 2x rather than using a single rule like
> ^admin=http://.  I understand how that can become unmaintainable for very
> very very large installations, but I do not really see it a problem for
> normal day to day usage compared to the alternative proposed.

 You would rather want to go through the nameserver because:
- you don't know how to add the rule (I don't think this is a power-user 
feature)
- you don't want to add many rules
- you simply don't want to bother adding anything (I guess you must have used 
another WWW browser in a large LAN to understand this)

>
> >  And I still fail to see the problem with having the lookup there. The
> > DNS lookup is limited to 0,5s , which is nothing considering that right
> > now the filter turns it into Google search, so the user would have to
> > wait anyway. Morever, the DNS lookup is done only rarely, only if the
> > command doesn't contain whitespaces, dots, colons, it's not a valid URL
> > nor a valid command, which basically rules out almost everything except
> > for things that would end up as a Google search anyway. Let me stress
> > this once again: Unless I missed something, the lookup will be done only
> > if it would otherwise become a Google search (but not for all Google
> > searches).
>
> If it only affects people that know how to use "shortnames", mainly power
> users, and even then only affects them under a very small subset of
> conditions, what would be advantage of this patch ?  See, this can be
> argued both ways using the same argument :)

 Based on this argument, I suggest removing Control Center from KDE, or at 
least half of its modules. And I'll be happy to follow this argument in KWin 
too :).

 I know a couple of people who consider the lack of this feature as strange 
and annoying as e.g. missing close button in window frames.

>
> >  If you're still against applying this patch to kshorturifilter, I'll do
> > as you said and put a new filter in kdeaddons, but given the things
> > above, I consider it rather silly.
>
> Well I do not consider this being silly and no I have not changed my mind. 
> I guess we will not see eye-to-eye on this issue. However, others might
> agree with your approach and if enough people do, then the patch should be
> applied. I neither want nor have a dictatorship power on such things...

 Unless you know a better place where to put the lookup, I've attached 
(hopefully final and everybody sufficiently pleasing) another version. The 
lookup is done in an extra URIFilter, and minicli uses this filter only for 
the final filtering of the entered command (who cares the icon for local 
hostnames will be wrong). This makes thing feature work fine in Konqy or 
wherever else where it doesn't cause any serious problem, and not using it in 
minicli while typing avoids any possible delays. I've also increased the 
timeout to 1s.

-- 
 Lubos Lunak
 llunak@suse.cz ; l.lunak@kde.org
 http://dforce.sh.cvut.cz/~seli

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

--- minicli.cpp.sav	Fri Aug  9 15:03:22 2002
+++ minicli.cpp	Fri Aug  9 15:37:18 2002
@@ -217,13 +217,9 @@ void Minicli::keyPressEvent( QKeyEvent* 
 
 int Minicli::runCommand()
 {
-    // Make sure we have an updated icon. We do
-    // so only when the parse timer is active.
-    if( m_parseTimer->isActive() )
-    {
-        m_parseTimer->stop();
-        slotParseTimer();
-    }
+    m_parseTimer->stop();
+    // Make sure we have an updated data
+    parseLine( true );    
 
     if ( m_runCombo->currentText().isEmpty() )
         return 1;  // Ignore
@@ -503,6 +499,11 @@ void Minicli::slotAdvanced()
 
 void Minicli::slotParseTimer()
 {
+    parseLine( false );
+}
+
+void Minicli::parseLine( bool final )
+{
     QString cmd = m_runCombo->currentText().stripWhiteSpace();
     
     // Update checkbox if Advanced is visible
@@ -534,6 +535,8 @@ void Minicli::slotParseTimer()
         m_filterData->setData( cmd );
         QStringList filters;
         filters << "kurisearchfilter" << "kshorturifilter";
+	if( final )
+	    filters << "localdomainurifilter";
         KURIFilter::self()->filterURI( *(m_filterData), filters );
         m_IconName = m_filterData->iconName();
         if( m_IconName.isEmpty() || m_IconName == "unknown" )
--- minicli.h.sav	Fri Aug  9 15:03:22 2002
+++ minicli.h	Fri Aug  9 15:12:48 2002
@@ -61,6 +61,8 @@ private slots:
     int runCommand();
 
 private:
+    void parseLine( bool final );
+    
     bool m_bAdvanced;
 
     QString m_IconName;

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

diff -u3 -p -d -N -r plugins.sav/Makefile.am plugins/Makefile.am
--- plugins.sav/Makefile.am	Sat Mar  4 04:49:04 2000
+++ plugins/Makefile.am	Fri Aug  9 12:58:02 2002
@@ -1,3 +1,3 @@
 
-SUBDIRS = ikws shorturi
+SUBDIRS = ikws shorturi localdomain
 
diff -u3 -p -d -N -r plugins.sav/ikws/kurisearchfilter.desktop \
                plugins/ikws/kurisearchfilter.desktop
--- plugins.sav/ikws/kurisearchfilter.desktop	Wed Jul 31 12:20:56 2002
+++ plugins/ikws/kurisearchfilter.desktop	Fri Aug  9 13:05:03 2002
@@ -44,4 +44,4 @@ Name[zh_TW]=搜索關鍵字過濾
 Name[zu]=Phendla amagama abalulekile ecebo lokucoca ulwelo
 X-KDE-Library=libkurisearchfilter
 ServiceTypes=KURIFilter/Plugin
-InitialPreference=6
+InitialPreference=7
diff -u3 -p -d -N -r plugins.sav/localdomain/Makefile.am plugins/localdomain/Makefile.am
--- plugins.sav/localdomain/Makefile.am	Thu Jan  1 01:00:00 1970
+++ plugins/localdomain/Makefile.am	Fri Aug  9 14:03:06 2002
@@ -0,0 +1,22 @@
+## Makefile.am of kdebase/kcontrol/ebrowsing/plugins/localdomain
+
+AM_CPPFLAGS = -DQT_NO_CAST_ASCII
+
+INCLUDES  =  $(all_includes)
+LDFLAGS   = $(all_libraries)
+
+kde_module_LTLIBRARIES = liblocaldomainurifilter.la
+
+liblocaldomainurifilter_la_LDFLAGS = -module $(KDE_PLUGIN)
+liblocaldomainurifilter_la_LIBADD = $(LIB_KSYCOCA) $(LIB_KDEUI)
+
+liblocaldomainurifilter_la_SOURCES = localdomainurifilter.cpp localdomainurifilter.skel
+
+service_DATA = localdomainurifilter.desktop
+servicedir = $(kde_servicesdir)
+
+METASOURCES = AUTO
+
+bin_PROGRAMS = klocaldomainurifilterhelper
+
+klocaldomainurifilterhelper_SOURCES = klocaldomainurifilterhelper.c
diff -u3 -p -d -N -r plugins.sav/localdomain/klocaldomainurifilterhelper.c \
                plugins/localdomain/klocaldomainurifilterhelper.c
--- plugins.sav/localdomain/klocaldomainurifilterhelper.c	Thu Jan  1 01:00:00 1970
+++ plugins/localdomain/klocaldomainurifilterhelper.c	Fri Aug  9 13:15:46 2002
@@ -0,0 +1,32 @@
+/*
+    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 version 2
+    as published by the Free Software Foundation.
+
+    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 localdomainurifilter 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;
+    }
diff -u3 -p -d -N -r plugins.sav/localdomain/localdomainurifilter.cpp \
                plugins/localdomain/localdomainurifilter.cpp
--- plugins.sav/localdomain/localdomainurifilter.cpp	Thu Jan  1 01:00:00 1970
+++ plugins/localdomain/localdomainurifilter.cpp	Fri Aug  9 13:59:01 2002
@@ -0,0 +1,116 @@
+/*
+    kshorturifilter.h
+
+    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 version 2
+    as published by the Free Software Foundation.
+
+    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.
+*/
+
+#include "localdomainurifilter.h"
+
+#include <qregexp.h>
+
+#include <kprocess.h>
+#include <kstandarddirs.h>
+
+LocalDomainURIFilter::LocalDomainURIFilter( QObject *parent, const char *name,
+    const QStringList & /*args*/ )
+    : KURIFilterPlugin( parent, name ? name : "localdomainurifilter", 1.0 ),
+      DCOPObject( "LocalDomainURIFilterIface" ), last_time( 0 )
+    {
+    configure();
+    }
+
+bool LocalDomainURIFilter::filterURI( KURIFilterData& data ) const
+    {
+    KURL url = data.uri();
+    QString cmd = url.url();
+
+    if( cmd[ 0 ] != '#' && cmd[ 0 ] != '~' && cmd[ 0 ] != '/'
+	&& !cmd.contains( ' ' ) && !cmd.contains( '.' )
+	&& !cmd.contains( ':' ) // KShortURIFilter takes care of these
+	// most of these are taken from KShortURIFilter
+	&& cmd[ cmd.length() - 1 ] != '&'
+	&& !cmd.contains( QString::fromLatin1("||"))
+	&& !cmd.contains( QString::fromLatin1("&&")) // must not look like shell
+	&& !cmd.contains( QRegExp( QString::fromLatin1( "[ ;<>]" )))
+	&& KStandardDirs::findExe( cmd ).isNull()
+	&& url.isMalformed()
+	&& isLocalDomainHost( cmd ))
+        {
+        cmd.insert( 0, QString::fromLatin1( "http://" ));
+        setFilteredURI( data, cmd );
+        setURIType( data, KURIFilterData::NET_PROTOCOL );
+        return true;
+        }
+    return false;
+    }
+
+// 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
+    {
+    QString host( cmd.contains( '/' ) ? cmd.left( cmd.find( '/' )) : cmd );
+    if( host == last_host && last_time > time( NULL ) - 5 )
+	return last_result;
+
+    pid_t pid;
+
+	{
+	QString helper = KStandardDirs::findExe(
+	    QString::fromLatin1( "klocaldomainurifilterhelper" ));
+	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
+
+    last_host = host;
+    last_time = time( NULL );
+    for( int rounds = 0;
+	 rounds < 50; // 50 * 20ms = 1s
+	 ++rounds )
+	{
+	int status;
+	int ret = waitpid( pid, &status, WNOHANG );
+	if( ret < 0 )
+	    return false;
+	if( ret > 0 )
+	    {
+	    bool last_result = WIFEXITED( status ) && WEXITSTATUS( status ) == 0;
+	    return last_result;
+	    }
+	struct timespec tm;
+	tm.tv_sec = 0;
+	tm.tv_nsec = 20 * 1000 * 1000; // 20ms
+	nanosleep( &tm, NULL );
+	}
+    kill( pid, SIGTERM );
+    last_result = false;
+    return false;
+    }
+
+void LocalDomainURIFilter::configure()
+    {
+    // nothing
+    }
+
+K_EXPORT_COMPONENT_FACTORY( liblocaldomainurifilter, 
+	                    KGenericFactory<LocalDomainURIFilter>( "localdomainurifilter" ) );
+
+#include "localdomainurifilter.moc"
diff -u3 -p -d -N -r plugins.sav/localdomain/localdomainurifilter.desktop \
                plugins/localdomain/localdomainurifilter.desktop
--- plugins.sav/localdomain/localdomainurifilter.desktop	Thu Jan  1 01:00:00 1970
+++ plugins/localdomain/localdomainurifilter.desktop	Fri Aug  9 13:05:18 2002
@@ -0,0 +1,7 @@
+[Desktop Entry]
+Encoding=UTF-8
+Type=Service
+Name=LocalDomainFilter
+X-KDE-Library=liblocaldomainurifilter
+ServiceTypes=KURIFilter/Plugin
+InitialPreference=6
diff -u3 -p -d -N -r plugins.sav/localdomain/localdomainurifilter.h \
                plugins/localdomain/localdomainurifilter.h
--- plugins.sav/localdomain/localdomainurifilter.h	Thu Jan  1 01:00:00 1970
+++ plugins/localdomain/localdomainurifilter.h	Fri Aug  9 13:58:26 2002
@@ -0,0 +1,47 @@
+/*
+    localdomainurifilter.h
+
+    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 version 2
+    as published by the Free Software Foundation.
+
+    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.
+*/
+
+#ifndef _LOCALDOMAINURIFILTER_H_
+#define _LOCALDOMAINURIFILTER_H_
+
+#include <dcopobject.h>
+#include <kgenericfactory.h>
+#include <kurifilter.h>
+
+class KInstance;
+
+class LocalDomainURIFilter
+    : public KURIFilterPlugin, public DCOPObject
+    {
+    K_DCOP
+    Q_OBJECT
+    public:
+	LocalDomainURIFilter( QObject* parent, const char* name, const QStringList& args );
+        virtual bool filterURI( KURIFilterData &data ) const;
+    k_dcop:
+        virtual void configure();
+    private:
+	bool isLocalDomainHost( const QString& cmd ) const;
+	mutable QString last_host;
+	mutable bool last_result;
+	mutable time_t last_time;
+    };
+
+#endif



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

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