4 This file is part of the KDE project
5 Copyright (C) 2007 Lubos Lunak <llunak@suse.cz>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config-runtime.h>
23 #include "fixhosturifilter.h"
27 #include <k3resolver.h>
29 using namespace KNetwork
;
32 * IMPORTANT: If you change anything here, please run the regression test
33 * ../tests/kurifiltertest
36 FixHostUriFilter::FixHostUriFilter( QObject
*parent
, const QVariantList
& /*args*/ )
37 : KUriFilterPlugin( "fixhosturifilter", parent
)
41 bool FixHostUriFilter::filterUri( KUriFilterData
& data
) const
43 KUrl url
= data
.uri();
44 QString cmd
= url
.url();
46 kDebug() << "FixHostUriFilter::filterUri: " << url
;
49 url2
.setHost( "www." + url
.host());
51 if(( url
.protocol() == "http" || url
.protocol() == "https" )
52 && !url
.host().startsWith( "www." ) && !exists( url
) && exists( url2
))
54 setFilteredUri( data
, url2
);
55 setUriType( data
, KUriFilterData::NetProtocol
);
57 kDebug() << "FilteredUri: " << data
.uri();
64 bool FixHostUriFilter::exists( const KUrl
& url
)
66 KResolver
resolver( url
.host());
67 resolver
.setFamily( KResolver::InetFamily
);
68 return( resolver
.start() && resolver
.wait( 5000 ) && resolver
.error() == KResolver::NoError
);
71 K_PLUGIN_FACTORY(FixHostUriFilterFactory
, registerPlugin
<FixHostUriFilter
>();)
72 K_EXPORT_PLUGIN(FixHostUriFilterFactory("kcmkurifilt"))
74 #include "fixhosturifilter.moc"