1
/****************************************************************************
5
** Copyright © 2011 Ruslan Nigmatullin <euroelessar@yandex.ru>
7
*****************************************************************************
9
** $JREEN_BEGIN_LICENSE$
10
** This program is free software: you can redistribute it and/or modify
11
** it under the terms of the GNU General Public License as published by
12
** the Free Software Foundation, either version 2 of the License, or
13
** (at your option) any later version.
15
** This program is distributed in the hope that it will be useful,
16
** but WITHOUT ANY WARRANTY; without even the implied warranty of
17
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
** See the GNU General Public License for more details.
20
** You should have received a copy of the GNU General Public License
21
** along with this program. If not, see http://www.gnu.org/licenses/.
22
** $JREEN_END_LICENSE$
24
****************************************************************************/
32
SJDns &SJDns::instance()
34
static SJDns *sjdns = 0;
35
if (sjdns && !sjdns->m_valid) {
41
sjdns->m_qjdns = new QJDns;
42
sjdns->m_valid = true;
43
if (!sjdns->m_qjdns->init(QJDns::Unicast, QHostAddress::Any)) {
44
delete sjdns->m_qjdns;
46
sjdns->m_valid = false;
49
connect(sjdns->m_qjdns, SIGNAL(resultsReady(int,QJDns::Response)), sjdns, SLOT(resultsReady(int,QJDns::Response)));
50
connect(sjdns->m_qjdns, SIGNAL(published(int)), sjdns, SLOT(published(int)));
51
connect(sjdns->m_qjdns, SIGNAL(error(int,QJDns::Error)), sjdns, SLOT(error(int,QJDns::Error)));
53
QJDns::SystemInfo info = QJDns::systemInfo();
54
if (info.nameServers.isEmpty()) {
55
QJDns::NameServer server;
56
server.address = QLatin1String("8.8.8.8");
57
info.nameServers << server;
58
server.address = QLatin1String("77.88.39.152");
59
info.nameServers << server;
61
sjdns->m_qjdns->setNameServers(info.nameServers);
71
void SJDns::doLookup(const QString &host, QObject *receiver, const char *member)
74
int id = m_qjdns->queryStart("_xmpp-client._tcp." + QUrl::toAce(host), QJDns::Srv);
75
Action *action = new Action(this);
76
action->setData(host);
77
connect(action, SIGNAL(triggered()), receiver, member);
78
m_actions.insert(id, action);
81
const QJDns::Response *SJDns::servers(const QString &host)
84
QHash<QString, QJDns::Response>::const_iterator iter = m_results.constFind(host);
85
if(iter == m_results.constEnd())
90
void SJDns::resultsReady(int id, const QJDns::Response &results)
92
Action *action = m_actions.value(id, 0);
94
foreach(const QJDns::Record &record, results.answerRecords)
95
Logger::debug() << record.name << record.port << record.priority << record.weight;
96
m_results.insert(action->data().toString(), results);
100
void SJDns::published(int id)
105
void SJDns::error(int id, QJDns::Error e)
107
Action *action = m_actions.value(id, 0);
109
QJDns::Response response;
110
QJDns::Record record;
112
record.name = action->data().toString().toUtf8();
113
response.answerRecords << record;
114
m_results.insert(record.name, response);
117
case QJDns::ErrorGeneric:
118
Logger::critical() << "error Generic" << id;
120
case QJDns::ErrorNXDomain:
121
Logger::critical() << "error NXDomain" << id;
123
case QJDns::ErrorTimeout:
124
Logger::critical() << "error Timeout" << id;
126
case QJDns::ErrorConflict:
127
Logger::critical() << "error Conflict" << id;