Lines 1-5
Link Here
|
1 |
/* -*- C++ -*- |
1 |
/* -*- C++ -*- |
2 |
* Copyright (C) 2003,2004 Thiago Macieira <thiago.macieira@kdemail.net> |
2 |
* Copyright (C) 2003-2005 Thiago Macieira <thiago.macieira@kdemail.net> |
3 |
* |
3 |
* |
4 |
* |
4 |
* |
5 |
* Permission is hereby granted, free of charge, to any person obtaining |
5 |
* Permission is hereby granted, free of charge, to any person obtaining |
Lines 32-37
Link Here
|
32 |
#include <time.h> |
32 |
#include <time.h> |
33 |
#include <arpa/inet.h> |
33 |
#include <arpa/inet.h> |
34 |
#include <netinet/in.h> |
34 |
#include <netinet/in.h> |
|
|
35 |
#include <stdlib.h> |
35 |
|
36 |
|
36 |
// Qt includes |
37 |
// Qt includes |
37 |
#include <qapplication.h> |
38 |
#include <qapplication.h> |
Lines 185-191
Link Here
|
185 |
///////////////////////////////////////////// |
186 |
///////////////////////////////////////////// |
186 |
// class KResolverResults |
187 |
// class KResolverResults |
187 |
|
188 |
|
188 |
class KNetwork::KResolverResultsPrivate: public QShared |
189 |
class KNetwork::KResolverResultsPrivate |
189 |
{ |
190 |
{ |
190 |
public: |
191 |
public: |
191 |
QString node, service; |
192 |
QString node, service; |
Lines 194-212
Link Here
|
194 |
KResolverResultsPrivate() : |
195 |
KResolverResultsPrivate() : |
195 |
errorcode(0), syserror(0) |
196 |
errorcode(0), syserror(0) |
196 |
{ } |
197 |
{ } |
197 |
|
|
|
198 |
// duplicate the data if necessary, while decreasing the reference count |
199 |
// on the original data |
200 |
inline void dup(KResolverResultsPrivate*& d) |
201 |
{ |
202 |
if (!d->count > 1) |
203 |
{ |
204 |
d->deref(); |
205 |
KResolverResultsPrivate *e = new KResolverResultsPrivate(*d); |
206 |
e->count = 1; |
207 |
d = e; // set the pointer |
208 |
} |
209 |
} |
210 |
}; |
198 |
}; |
211 |
|
199 |
|
212 |
// default constructor |
200 |
// default constructor |
Lines 217-246
Link Here
|
217 |
|
205 |
|
218 |
// copy constructor |
206 |
// copy constructor |
219 |
KResolverResults::KResolverResults(const KResolverResults& other) |
207 |
KResolverResults::KResolverResults(const KResolverResults& other) |
220 |
: QValueList<KResolverEntry>(other), d(other.d) |
208 |
: QValueList<KResolverEntry>(other), d(new KResolverResultsPrivate) |
221 |
{ |
209 |
{ |
222 |
d->ref(); |
210 |
*d = *other.d; |
223 |
} |
211 |
} |
224 |
|
212 |
|
225 |
// destructor |
213 |
// destructor |
226 |
KResolverResults::~KResolverResults() |
214 |
KResolverResults::~KResolverResults() |
227 |
{ |
215 |
{ |
228 |
if (d->deref()) |
216 |
delete d; |
229 |
delete d; |
|
|
230 |
} |
217 |
} |
231 |
|
218 |
|
232 |
// assignment operator |
219 |
// assignment operator |
233 |
KResolverResults& |
220 |
KResolverResults& |
234 |
KResolverResults::operator= (const KResolverResults& other) |
221 |
KResolverResults::operator= (const KResolverResults& other) |
235 |
{ |
222 |
{ |
236 |
other.d->ref(); |
223 |
if (this == &other) |
237 |
|
224 |
return *this; |
238 |
// release our data |
|
|
239 |
if (d->deref()) |
240 |
delete d; |
241 |
|
225 |
|
242 |
// copy over the other data |
226 |
// copy over the other data |
243 |
d = other.d; |
227 |
*d = *other.d; |
244 |
|
228 |
|
245 |
// now let QValueList do the rest of the work |
229 |
// now let QValueList do the rest of the work |
246 |
QValueList<KResolverEntry>::operator =(other); |
230 |
QValueList<KResolverEntry>::operator =(other); |
Lines 263-270
Link Here
|
263 |
// sets the error codes |
247 |
// sets the error codes |
264 |
void KResolverResults::setError(int errorcode, int systemerror) |
248 |
void KResolverResults::setError(int errorcode, int systemerror) |
265 |
{ |
249 |
{ |
266 |
d->dup(d); |
|
|
267 |
|
268 |
d->errorcode = errorcode; |
250 |
d->errorcode = errorcode; |
269 |
d->syserror = systemerror; |
251 |
d->syserror = systemerror; |
270 |
} |
252 |
} |
Lines 285-292
Link Here
|
285 |
void KResolverResults::setAddress(const QString& node, |
267 |
void KResolverResults::setAddress(const QString& node, |
286 |
const QString& service) |
268 |
const QString& service) |
287 |
{ |
269 |
{ |
288 |
d->dup(d); |
|
|
289 |
|
290 |
d->node = node; |
270 |
d->node = node; |
291 |
d->service = service; |
271 |
d->service = service; |
292 |
} |
272 |
} |
Lines 298-303
Link Here
|
298 |
/////////////////////// |
278 |
/////////////////////// |
299 |
// class KResolver |
279 |
// class KResolver |
300 |
|
280 |
|
|
|
281 |
QStringList *KResolver::idnDomains = 0; |
282 |
|
283 |
|
301 |
// default constructor |
284 |
// default constructor |
302 |
KResolver::KResolver(QObject *parent, const char *name) |
285 |
KResolver::KResolver(QObject *parent, const char *name) |
303 |
: QObject(parent, name), d(new KResolverPrivate(this)) |
286 |
: QObject(parent, name), d(new KResolverPrivate(this)) |
Lines 874-880
Link Here
|
874 |
lst.append(*p); |
857 |
lst.append(*p); |
875 |
} |
858 |
} |
876 |
|
859 |
|
877 |
#ifdef HAVE_GETSERVBYNAME_R |
860 |
#ifdef HAVE_GETSERVBYPORT_R |
878 |
delete [] buf; |
861 |
delete [] buf; |
879 |
#endif |
862 |
#endif |
880 |
|
863 |
|
Lines 885-894
Link Here
|
885 |
static QStringList splitLabels(const QString& unicodeDomain); |
868 |
static QStringList splitLabels(const QString& unicodeDomain); |
886 |
static QCString ToASCII(const QString& label); |
869 |
static QCString ToASCII(const QString& label); |
887 |
static QString ToUnicode(const QString& label); |
870 |
static QString ToUnicode(const QString& label); |
888 |
|
871 |
|
|
|
872 |
static QStringList *KResolver_initIdnDomains() |
873 |
{ |
874 |
const char *kde_use_idn = getenv("KDE_USE_IDN"); |
875 |
if (!kde_use_idn) |
876 |
kde_use_idn = "at:ch:cn:de:dk:kr:jp:li:no:se:tw"; |
877 |
return new QStringList(QStringList::split(':', QString::fromLatin1(kde_use_idn).lower())); |
878 |
} |
879 |
|
889 |
// implement the ToAscii function, as described by IDN documents |
880 |
// implement the ToAscii function, as described by IDN documents |
890 |
QCString KResolver::domainToAscii(const QString& unicodeDomain) |
881 |
QCString KResolver::domainToAscii(const QString& unicodeDomain) |
891 |
{ |
882 |
{ |
|
|
883 |
if (!idnDomains) |
884 |
idnDomains = KResolver_initIdnDomains(); |
885 |
|
892 |
QCString retval; |
886 |
QCString retval; |
893 |
// RFC 3490, section 4 describes the operation: |
887 |
// RFC 3490, section 4 describes the operation: |
894 |
// 1) this is a query, so don't allow unassigned |
888 |
// 1) this is a query, so don't allow unassigned |
Lines 897-902
Link Here
|
897 |
// separators. |
891 |
// separators. |
898 |
QStringList input = splitLabels(unicodeDomain); |
892 |
QStringList input = splitLabels(unicodeDomain); |
899 |
|
893 |
|
|
|
894 |
// Do we allow IDN names for this TLD? |
895 |
if (input.count() && !idnDomains->contains(input[input.count()-1].lower())) |
896 |
return unicodeDomain.latin1(); // No IDN allowed for this TLD |
897 |
|
900 |
// 3) decide whether to enforce the STD3 rules for chars < 0x7F |
898 |
// 3) decide whether to enforce the STD3 rules for chars < 0x7F |
901 |
// we don't enforce |
899 |
// we don't enforce |
902 |
|
900 |
|
Lines 928-933
Link Here
|
928 |
{ |
926 |
{ |
929 |
if (asciiDomain.isEmpty()) |
927 |
if (asciiDomain.isEmpty()) |
930 |
return asciiDomain; |
928 |
return asciiDomain; |
|
|
929 |
if (!idnDomains) |
930 |
idnDomains = KResolver_initIdnDomains(); |
931 |
|
931 |
|
932 |
QString retval; |
932 |
QString retval; |
933 |
|
933 |
|
Lines 939-944
Link Here
|
939 |
// separators. |
939 |
// separators. |
940 |
QStringList input = splitLabels(asciiDomain); |
940 |
QStringList input = splitLabels(asciiDomain); |
941 |
|
941 |
|
|
|
942 |
// Do we allow IDN names for this TLD? |
943 |
if (input.count() && !idnDomains->contains(input[input.count()-1].lower())) |
944 |
return asciiDomain; // No TLDs allowed |
945 |
|
942 |
// 3) decide whether to enforce the STD3 rules for chars < 0x7F |
946 |
// 3) decide whether to enforce the STD3 rules for chars < 0x7F |
943 |
// we don't enforce |
947 |
// we don't enforce |
944 |
|
948 |
|
Lines 1001-1007
Link Here
|
1001 |
start = i + 1; |
1005 |
start = i + 1; |
1002 |
} |
1006 |
} |
1003 |
} |
1007 |
} |
1004 |
if ((long)i > start) |
1008 |
if ((long)i >= start) |
1005 |
// there is still one left |
1009 |
// there is still one left |
1006 |
lst << unicodeDomain.mid(start, i - start); |
1010 |
lst << unicodeDomain.mid(start, i - start); |
1007 |
|
1011 |
|
Lines 1017-1022
Link Here
|
1017 |
if (label.length() > 64) |
1021 |
if (label.length() > 64) |
1018 |
return (char*)0L; // invalid label |
1022 |
return (char*)0L; // invalid label |
1019 |
|
1023 |
|
|
|
1024 |
if (label.length() == 0) |
1025 |
// this is allowed |
1026 |
return QCString(""); // empty, not null |
1027 |
|
1020 |
QCString retval; |
1028 |
QCString retval; |
1021 |
char buf[65]; |
1029 |
char buf[65]; |
1022 |
|
1030 |
|
Lines 926-931
Link Here
|
926 |
KResolverPrivate* d; |
926 |
KResolverPrivate* d; |
927 |
friend class KResolverResults; |
927 |
friend class KResolverResults; |
928 |
friend class ::KNetwork::Internal::KResolverManager; |
928 |
friend class ::KNetwork::Internal::KResolverManager; |
|
|
929 |
|
930 |
static QStringList *idnDomains; |
929 |
}; |
931 |
}; |
930 |
|
932 |
|
931 |
} // namespace KNetwork |
933 |
} // namespace KNetwork |
Lines 30-35
Link Here
|
30 |
#include <ksockaddr.h> |
30 |
#include <ksockaddr.h> |
31 |
#include <kextsock.h> |
31 |
#include <kextsock.h> |
32 |
#include <netsupp.h> |
32 |
#include <netsupp.h> |
|
|
33 |
#ifndef Q_WS_WIN //TODO kresolver not ported |
34 |
#include "network/kresolver.h" |
35 |
#endif |
33 |
|
36 |
|
34 |
#include "ksslx509map.h" |
37 |
#include "ksslx509map.h" |
35 |
|
38 |
|
Lines 59-65
Link Here
|
59 |
while(d->peerHost.endsWith(".")) |
62 |
while(d->peerHost.endsWith(".")) |
60 |
d->peerHost.truncate(d->peerHost.length()-1); |
63 |
d->peerHost.truncate(d->peerHost.length()-1); |
61 |
|
64 |
|
|
|
65 |
#ifdef Q_WS_WIN //TODO kresolver not ported |
62 |
d->peerHost = d->peerHost.lower(); |
66 |
d->peerHost = d->peerHost.lower(); |
|
|
67 |
#else |
68 |
d->peerHost = QString::fromLatin1(KNetwork::KResolver::domainToAscii(d->peerHost)); |
69 |
#endif |
63 |
} |
70 |
} |
64 |
|
71 |
|
65 |
bool KSSLPeerInfo::certMatchesAddress() { |
72 |
bool KSSLPeerInfo::certMatchesAddress() { |