summaryrefslogtreecommitdiffstats
path: root/kcontrol/ebrowsing/plugins/localdomain
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kcontrol/ebrowsing/plugins/localdomain
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kcontrol/ebrowsing/plugins/localdomain')
-rw-r--r--kcontrol/ebrowsing/plugins/localdomain/Makefile.am20
-rw-r--r--kcontrol/ebrowsing/plugins/localdomain/klocaldomainurifilterhelper.c60
-rw-r--r--kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.cpp117
-rw-r--r--kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.desktop48
-rw-r--r--kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.h65
5 files changed, 310 insertions, 0 deletions
diff --git a/kcontrol/ebrowsing/plugins/localdomain/Makefile.am b/kcontrol/ebrowsing/plugins/localdomain/Makefile.am
new file mode 100644
index 000000000..cb524dd4b
--- /dev/null
+++ b/kcontrol/ebrowsing/plugins/localdomain/Makefile.am
@@ -0,0 +1,20 @@
+## Makefile.am of kdebase/kcontrol/ebrowsing/plugins/localdomain
+
+AM_CPPFLAGS = $(all_includes) -DQT_NO_CAST_ASCII
+
+kde_module_LTLIBRARIES = liblocaldomainurifilter.la
+
+liblocaldomainurifilter_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+liblocaldomainurifilter_la_LIBADD = $(LIB_KIO) $(LIB_KDEUI) $(LIB_KDECORE)
+
+liblocaldomainurifilter_la_SOURCES = localdomainurifilter.cpp localdomainurifilter.skel
+
+service_DATA = localdomainurifilter.desktop
+servicedir = $(kde_servicesdir)
+
+METASOURCES = AUTO
+
+bin_PROGRAMS = klocaldomainurifilterhelper
+
+klocaldomainurifilterhelper_SOURCES = klocaldomainurifilterhelper.c
+klocaldomainurifilterhelper_LDADD = $(LIBSOCKET)
diff --git a/kcontrol/ebrowsing/plugins/localdomain/klocaldomainurifilterhelper.c b/kcontrol/ebrowsing/plugins/localdomain/klocaldomainurifilterhelper.c
new file mode 100644
index 000000000..2f61d6824
--- /dev/null
+++ b/kcontrol/ebrowsing/plugins/localdomain/klocaldomainurifilterhelper.c
@@ -0,0 +1,60 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+/* Helper for localdomainurifilter for finding out if a host exist */
+
+#ifndef NULL
+#define NULL 0
+#endif
+
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+
+int main( int argc, char* argv[] )
+{
+ struct hostent* ent;
+
+ if( argc != 2 )
+ return 2;
+
+ ent = gethostbyname( argv[ 1 ] );
+ if (ent)
+ {
+ int i;
+ int found = 0;
+ /* try to find the same fully qualified name first */
+ for( i = 0;
+ ent->h_aliases[ i ] != NULL;
+ ++i )
+ {
+ if( strncmp( argv[ 1 ], ent->h_aliases[ i ], strlen( argv[ 1 ] )) == 0 )
+ {
+ found = 1;
+ fputs( ent->h_aliases[ i ], stdout );
+ break;
+ }
+ }
+ if( !found )
+ fputs( ent->h_name, stdout );
+ }
+
+ return (ent != NULL || h_errno == NO_ADDRESS) ? 0 : 1;
+}
diff --git a/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.cpp b/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.cpp
new file mode 100644
index 000000000..3bd247729
--- /dev/null
+++ b/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.cpp
@@ -0,0 +1,117 @@
+/*
+ localdomainfilter.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#include <config.h>
+
+#include "localdomainurifilter.h"
+
+#include <kprocess.h>
+#include <kstandarddirs.h>
+#include <kdebug.h>
+
+#include <qregexp.h>
+#include <qfile.h>
+
+#define HOSTPORT_PATTERN "[a-zA-Z0-9][a-zA-Z0-9+-]*(?:\\:[0-9]{1,5})?(?:/[\\w:@&=+$,-.!~*'()]*)*"
+
+/**
+ * IMPORTANT: If you change anything here, please run the regression test
+ * kdelibs/kio/tests/kurifiltertest
+ */
+
+LocalDomainURIFilter::LocalDomainURIFilter( QObject *parent, const char *name,
+ const QStringList & /*args*/ )
+ : KURIFilterPlugin( parent, name ? name : "localdomainurifilter", 1.0 ),
+ DCOPObject( "LocalDomainURIFilterIface" ),
+ last_time( 0 ),
+ m_hostPortPattern( QString::fromLatin1(HOSTPORT_PATTERN) )
+{
+ configure();
+}
+
+bool LocalDomainURIFilter::filterURI( KURIFilterData& data ) const
+{
+ KURL url = data.uri();
+ QString cmd = url.url();
+
+ kdDebug() << "LocalDomainURIFilter::filterURI: " << url << endl;
+
+ if( m_hostPortPattern.exactMatch( cmd ) &&
+ isLocalDomainHost( cmd ) )
+ {
+ cmd.prepend( QString::fromLatin1("http://") );
+ setFilteredURI( data, KURL( cmd ) );
+ setURIType( data, KURIFilterData::NET_PROTOCOL );
+
+ kdDebug() << "FilteredURI: " << data.uri() << endl;
+ 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( 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 ) ) {
+
+ QString helper = KStandardDirs::findExe(QString::fromLatin1( "klocaldomainurifilterhelper" ));
+ if( helper.isEmpty())
+ return last_result = false;
+
+ m_fullname = QString::null;
+
+ 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;
+
+ last_host = host;
+ last_time = time( (time_t *)0 );
+
+ 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()
+{
+ // nothing
+}
+
+K_EXPORT_COMPONENT_FACTORY( liblocaldomainurifilter,
+ KGenericFactory<LocalDomainURIFilter>( "kcmkurifilt" ) )
+
+#include "localdomainurifilter.moc"
diff --git a/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.desktop b/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.desktop
new file mode 100644
index 000000000..57826630a
--- /dev/null
+++ b/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.desktop
@@ -0,0 +1,48 @@
+[Desktop Entry]
+Type=Service
+Name=LocalDomainFilter
+Name[af]=Plaaslike domein filter
+Name[az]=YerliDomenSüzgəci
+Name[ca]=Filtre de dominis locals
+Name[cs]=Filtr pro lokální doménu
+Name[csb]=Filter môlowi domenë
+Name[cy]=HidlParthLleol
+Name[el]=Φίλτρο τοπικού τομέα
+Name[eo]=LokaRetejo-filtrilo
+Name[es]=FiltrodeDominioLocal
+Name[eu]=Domeinu lokal iragazkia
+Name[fr]=Filtre de domaine local
+Name[fy]=Lokaaldomeinfilter
+Name[he]=מסנן תחומים מקומיים
+Name[hi]=लोकल-डोमेन-फ़िल्टर
+Name[hr]=Filtar lokalnih domena
+Name[hu]=HelyiTartománySzűrő
+Name[it]=FiltroDominioLocale
+Name[lo]=ຕົວກອງການບີບຂອງ KDE
+Name[lv]=LokāloDomēnuFiltrs
+Name[mt]=FiltruDominjiLokali
+Name[nds]=Filter för LocalDomain
+Name[ne]=स्थानीय डोमेन फिल्टर
+Name[nl]=Lokaaldomeinfilter
+Name[nso]=Sesekodi sa Tikologo ya Selegae
+Name[pa]=ਲੋਕਲ ਡੋਮੇਨ ਫਿਲਟਰ
+Name[pl]=Filtr lokalnej domeny
+Name[pt_BR]=Filtro de Domínio Local
+Name[ro]=Filtru de domeniu local
+Name[rw]=MuyunguruziIndangarubugaYahafi
+Name[sk]=Filter lokálnej domény
+Name[sl]=FilterLokalneDomene
+Name[sv]=Filter för lokal domän
+Name[ta]=உள்பகுதிவடிகட்டி
+Name[te]=స్థానిక డొమెయిన్ గలని
+Name[th]=ตัวกรองโดเมนท้องถื่น
+Name[uk]=Фільтр локальних доменів
+Name[ven]=Filithara ya tshigwada ya henefhano
+Name[vi]=Lọc Tên miền Địa phương
+Name[wa]=PasseteLocåDominne
+Name[zh_CN]=本地域名过滤
+Name[zh_TW]=區域網域過濾器
+Name[zu]=Ihluzo Lendawo Yaseduze
+X-KDE-Library=liblocaldomainurifilter
+ServiceTypes=KURIFilter/Plugin
+InitialPreference=2
diff --git a/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.h b/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.h
new file mode 100644
index 000000000..465214e69
--- /dev/null
+++ b/kcontrol/ebrowsing/plugins/localdomain/localdomainurifilter.h
@@ -0,0 +1,65 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+#ifndef _LOCALDOMAINURIFILTER_H_
+#define _LOCALDOMAINURIFILTER_H_
+
+#include <time.h>
+
+#include <dcopobject.h>
+#include <kgenericfactory.h>
+#include <kurifilter.h>
+#include <qregexp.h>
+
+class KInstance;
+class KProcess;
+
+/*
+ This filter takes care of hostnames in the local search domain.
+ If you're in domain domain.org which has a host intranet.domain.org
+ and the typed URI is just intranet, check if there's a host
+ intranet.domain.org and if yes, it's a network URI.
+*/
+
+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( 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