2
* Copyright (C) 2001, 2002 Justin Karneges
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#include <QDomElement>
23
#include "xmpp_task.h"
24
#include "xmpp/jid/jid.h"
25
#include "xmpp_discoitem.h"
26
#include "xmpp_discoinfotask.h"
27
#include "xmpp_xmlcommon.h"
31
class DiscoInfoTask::Private
42
DiscoInfoTask::DiscoInfoTask(Task *parent)
48
DiscoInfoTask::~DiscoInfoTask()
53
void DiscoInfoTask::get(const DiscoItem &item)
55
DiscoItem::Identity id;
56
if ( item.identities().count() == 1 )
57
id = item.identities().first();
58
get(item.jid(), item.node(), id);
61
void DiscoInfoTask::get (const Jid &j, const QString &node, DiscoItem::Identity ident)
63
d->item = DiscoItem(); // clear item
67
d->iq = createIQ(doc(), "get", d->jid.full(), id());
68
QDomElement query = doc()->createElement("query");
69
query.setAttribute("xmlns", "http://jabber.org/protocol/disco#info");
71
if ( !node.isEmpty() )
72
query.setAttribute("node", node);
74
if ( !ident.category.isEmpty() && !ident.type.isEmpty() ) {
75
QDomElement i = doc()->createElement("item");
77
i.setAttribute("category", ident.category);
78
i.setAttribute("type", ident.type);
79
if ( !ident.name.isEmpty() )
80
i.setAttribute("name", ident.name);
82
query.appendChild( i );
86
d->iq.appendChild(query);
91
* Original requested jid.
92
* Is here because sometimes the responder does not include this information
95
const Jid& DiscoInfoTask::jid() const
101
* Original requested node.
102
* Is here because sometimes the responder does not include this information
105
const QString& DiscoInfoTask::node() const
112
const DiscoItem &DiscoInfoTask::item() const
117
void DiscoInfoTask::onGo ()
122
bool DiscoInfoTask::take(const QDomElement &x)
124
if(!iqVerify(x, d->jid, id()))
127
if(x.attribute("type") == "result") {
128
QDomElement q = queryTag(x);
132
item.setJid( d->jid );
133
item.setNode( q.attribute("node") );
135
QStringList features;
136
DiscoItem::Identities identities;
138
for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
139
QDomElement e = n.toElement();
143
if ( e.tagName() == "feature" ) {
144
features << e.attribute("var");
146
else if ( e.tagName() == "identity" ) {
147
DiscoItem::Identity id;
149
id.category = e.attribute("category");
150
id.name = e.attribute("name");
151
id.type = e.attribute("type");
153
identities.append( id );
157
item.setFeatures( features );
158
item.setIdentities( identities );