22 #include <config-kpac.h>
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
29 #ifdef HAVE_NETINET_IN_H
30 #include <netinet/in.h>
32 #include <arpa/nameser.h>
33 #ifdef HAVE_ARPA_NAMESER8_COMPAT_H
34 #include <arpa/nameser8_compat.h>
36 #ifdef HAVE_ARPA_NAMESER_COMPAT_H
37 #include <arpa/nameser_compat.h>
40 #ifdef HAVE_SYS_PARAM_H
42 #include <sys/param.h>
46 #include <sys/utsname.h>
48 #include <QtCore/QTimer>
49 #include <QtNetwork/QHostInfo>
55 #include "discovery.moc"
64 connect( m_helper, SIGNAL(readyReadStandardOutput()), SLOT(helperOutput()) );
65 connect( m_helper, SIGNAL(finished(
int,QProcess::ExitStatus)), SLOT(
failed()) );
68 if ( !m_helper->waitForStarted() )
69 QTimer::singleShot( 0,
this, SLOT(
failed()) );
72 bool Discovery::initDomainName()
74 m_domainName = QHostInfo::localDomainName();
75 return !m_domainName.isEmpty();
78 bool Discovery::checkDomain()
const
86 unsigned char buf[ PACKETSZ ];
89 int len = res_query( m_domainName.toLocal8Bit(), C_IN, T_SOA,
90 response.buf,
sizeof( response.buf ) );
91 if ( len <=
int(
sizeof( response.header ) ) ||
92 ntohs( response.header.ancount ) != 1 )
95 unsigned char* pos = response.buf +
sizeof( response.header );
96 unsigned char*
end = response.buf + len;
99 pos += dn_skipname( pos, end ) + QFIXEDSZ;
104 pos += dn_skipname( pos, end );
106 GETSHORT( type, pos );
107 return type != T_SOA;
112 setError(
i18n(
"Could not find a usable proxy configuration script" ) );
117 const bool firstQuery = m_domainName.isEmpty();
118 if ( ( firstQuery && !initDomainName() ) ||
119 ( !firstQuery && !checkDomain() ) )
125 const int dot = m_domainName.indexOf(
'.' );
126 if ( dot > -1 || firstQuery )
128 QString address (QLatin1String(
"http://wpad."));
129 address += m_domainName;
130 address += QLatin1String (
"/wpad.dat");
132 m_domainName.remove (0, dot + 1);
140 void Discovery::helperOutput()
142 m_helper->disconnect(
this );
143 const QByteArray line = m_helper->readLine();
144 const KUrl url( QString::fromLocal8Bit(line.constData(), line.length()).trimmed() );
QString i18n(const char *text)
void setOutputChannelMode(OutputChannelMode mode)
void setError(const QString &)
void download(const KUrl &)
static QString findExe(const QString &appname, const QString &pathstr=QString(), SearchOptions options=NoSearchOptions)