~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to cutestuff/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:
25
25
#include <q3dns.h>
26
26
//Added by qt3to4:
27
27
#include <QList>
 
28
#include <QtAlgorithms>
28
29
#include "safedelete.h"
29
30
 
30
31
#ifndef NO_NDNS
33
34
 
34
35
// CS_NAMESPACE_BEGIN
35
36
 
 
37
bool serverLessThan(const Q3Dns::Server &s1, const Q3Dns::Server &s2)
 
38
{
 
39
        int a = s1.priority;
 
40
        int b = s2.priority;
 
41
        int j = s1.weight;
 
42
        int k = s2.weight;
 
43
        return a < b || (a == b && j < k);
 
44
}
 
45
 
36
46
static void sortSRVList(QList<Q3Dns::Server> &list)
37
47
{
38
 
        QList<Q3Dns::Server> tmp = list;
39
 
        list.clear();
40
 
 
41
 
        while(!tmp.isEmpty()) {
42
 
                QList<Q3Dns::Server>::Iterator p = tmp.end();
43
 
                for(QList<Q3Dns::Server>::Iterator it = tmp.begin(); it != tmp.end(); ++it) {
44
 
                        if(p == tmp.end())
45
 
                                p = it;
46
 
                        else {
47
 
                                int a = (*it).priority;
48
 
                                int b = (*p).priority;
49
 
                                int j = (*it).weight;
50
 
                                int k = (*p).weight;
51
 
                                if(a < b || (a == b && j < k))
52
 
                                        p = it;
53
 
                        }
54
 
                }
55
 
                list.append(*p);
56
 
                tmp.remove(p);
57
 
        }
 
48
        qStableSort(list.begin(), list.end(), serverLessThan);
58
49
}
59
50
 
60
51
class SrvResolver::Private
99
90
        delete d;
100
91
}
101
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.start(15000, true);
 
101
        d->qdns = new Q3Dns;
 
102
        connect(d->qdns, SIGNAL(resultsReady()), SLOT(qdns_done()));
 
103
        d->qdns->setRecordType(Q3Dns::Srv);
 
104
        d->qdns->setLabel(d->srv);
 
105
}
 
106
 
102
107
void SrvResolver::resolve(const QString &server, const QString &type, const QString &proto)
103
108
{
104
 
        stop();
105
 
 
106
 
        d->failed = false;
107
 
        d->srvonly = false;
108
 
        d->srv = QString("_") + type + "._" + proto + '.' + server;
109
 
        d->t.start(15000, true);
110
 
        d->qdns = new Q3Dns;
111
 
        connect(d->qdns, SIGNAL(resultsReady()), SLOT(qdns_done()));
112
 
        d->qdns->setRecordType(Q3Dns::Srv);
113
 
        d->qdns->setLabel(d->srv);
 
109
        resolve(server, type, proto, false);
114
110
}
115
111
 
116
112
void SrvResolver::resolveSrvOnly(const QString &server, const QString &type, const QString &proto)
117
113
{
118
 
        stop();
119
 
 
120
 
        d->failed = false;
121
 
        d->srvonly = true;
122
 
        d->srv = QString("_") + type + "._" + proto + '.' + server;
123
 
        d->t.start(15000, true);
124
 
        d->qdns = new Q3Dns;
125
 
        connect(d->qdns, SIGNAL(resultsReady()), SLOT(qdns_done()));
126
 
        d->qdns->setRecordType(Q3Dns::Srv);
127
 
        d->qdns->setLabel(d->srv);
 
114
        resolve(server, type, proto, true);
128
115
}
129
116
 
130
117
void SrvResolver::next()
249
236
        d->servers.remove(d->servers.begin());
250
237
 
251
238
        if(!r.isNull()) {
252
 
                d->resultAddress = d->ndns.result();
 
239
                d->resultAddress = r;
253
240
                d->resultPort = port;
254
241
                resultsReady();
255
242
        }