~ubuntu-branches/ubuntu/vivid/psi/vivid

« back to all changes in this revision

Viewing changes to iris/irisnet/legacy/srvresolver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "srvresolver.h"
22
22
 
 
23
#include <QtAlgorithms>
 
24
 
23
25
#ifndef NO_NDNS
24
26
# include "ndns.h"
25
27
#endif
26
28
 
27
29
// CS_NAMESPACE_BEGIN
28
30
 
 
31
bool serverLessThan(const Q3Dns::Server &s1, const Q3Dns::Server &s2)
 
32
{
 
33
        int a = s1.priority;
 
34
        int b = s2.priority;
 
35
        int j = s1.weight;
 
36
        int k = s2.weight;
 
37
        return a < b || (a == b && j < k);
 
38
}
 
39
 
 
40
 
29
41
static void sortSRVList(QList<Q3Dns::Server> &list)
30
42
{
31
 
        QList<Q3Dns::Server> tmp = list;
32
 
        list.clear();
33
 
 
34
 
        while(!tmp.isEmpty()) {
35
 
                QList<Q3Dns::Server>::Iterator p = tmp.end();
36
 
                for(QList<Q3Dns::Server>::Iterator it = tmp.begin(); it != tmp.end(); ++it) {
37
 
                        if(p == tmp.end())
38
 
                                p = it;
39
 
                        else {
40
 
                                int a = (*it).priority;
41
 
                                int b = (*p).priority;
42
 
                                int j = (*it).weight;
43
 
                                int k = (*p).weight;
44
 
                                if(a < b || (a == b && j < k))
45
 
                                        p = it;
46
 
                        }
47
 
                }
48
 
                list.append(*p);
49
 
                tmp.erase(p);
50
 
        }
 
43
        qStableSort(list.begin(), list.end(), serverLessThan);
51
44
}
52
45
 
53
46
class SrvResolver::Private
97
90
        delete d;
98
91
}
99
92
 
 
93
void SrvResolver::resolve(const QString &server, const QString &type, const QString &proto, bool srvOnly)
 
94
{
 
95
        stop();
 
96
 
 
97
        d->failed = false;
 
98
        d->srvonly = srvOnly;
 
99
        d->srv = QString("_") + type + "._" + proto + '.' + server;
 
100
        d->t.setSingleShot(true);
 
101
        d->t.start(15000);
 
102
        d->nndns_busy = true;
 
103
        d->nntype = XMPP::NameRecord::Srv;
 
104
        d->nndns.start(d->srv.toLatin1(), d->nntype);
 
105
}
 
106
 
100
107
void SrvResolver::resolve(const QString &server, const QString &type, const QString &proto)
101
108
{
102
 
        stop();
103
 
 
104
 
        d->failed = false;
105
 
        d->srvonly = false;
106
 
        d->srv = QString("_") + type + "._" + proto + '.' + server;
107
 
        d->t.setSingleShot(true);
108
 
        d->t.start(15000);
109
 
        d->nndns_busy = true;
110
 
        d->nntype = XMPP::NameRecord::Srv;
111
 
        d->nndns.start(d->srv.toLatin1(), d->nntype);
 
109
        resolve(server, type, proto, false);
112
110
}
113
111
 
114
112
void SrvResolver::resolveSrvOnly(const QString &server, const QString &type, const QString &proto)
115
113
{
116
 
        stop();
117
 
 
118
 
        d->failed = false;
119
 
        d->srvonly = true;
120
 
        d->srv = QString("_") + type + "._" + proto + '.' + server;
121
 
        d->t.setSingleShot(true);
122
 
        d->t.start(15000);
123
 
        d->nndns_busy = true;
124
 
        d->nntype = XMPP::NameRecord::Srv;
125
 
        d->nndns.start(d->srv.toLatin1(), d->nntype);
 
114
        resolve(server, type, proto, true);
126
115
}
127
116
 
128
117
void SrvResolver::next()
282
271
        d->servers.removeFirst();
283
272
 
284
273
        if(!r.isNull()) {
285
 
                d->resultAddress = d->ndns.result();
 
274
                d->resultAddress = r;
286
275
                d->resultPort = port;
287
276
                resultsReady();
288
277
        }