~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to iris/src/xmpp/xmpp-im/xmpp_discoinfotask.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2001, 2002  Justin Karneges
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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
 
17
 *
 
18
 */
 
19
 
 
20
#include <QDomElement>
 
21
#include <QString>
 
22
 
 
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"
 
28
 
 
29
using namespace XMPP;
 
30
 
 
31
class DiscoInfoTask::Private
 
32
{
 
33
public:
 
34
        Private() { }
 
35
 
 
36
        QDomElement iq;
 
37
        Jid jid;
 
38
        QString node;
 
39
        DiscoItem item;
 
40
};
 
41
 
 
42
DiscoInfoTask::DiscoInfoTask(Task *parent)
 
43
: Task(parent)
 
44
{
 
45
        d = new Private;
 
46
}
 
47
 
 
48
DiscoInfoTask::~DiscoInfoTask()
 
49
{
 
50
        delete d;
 
51
}
 
52
 
 
53
void DiscoInfoTask::get(const DiscoItem &item)
 
54
{
 
55
        DiscoItem::Identity id;
 
56
        if ( item.identities().count() == 1 )
 
57
                id = item.identities().first();
 
58
        get(item.jid(), item.node(), id);
 
59
}
 
60
 
 
61
void DiscoInfoTask::get (const Jid &j, const QString &node, DiscoItem::Identity ident)
 
62
{
 
63
        d->item = DiscoItem(); // clear item
 
64
 
 
65
        d->jid = j;
 
66
        d->node = node;
 
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");
 
70
 
 
71
        if ( !node.isEmpty() )
 
72
                query.setAttribute("node", node);
 
73
 
 
74
        if ( !ident.category.isEmpty() && !ident.type.isEmpty() ) {
 
75
                QDomElement i = doc()->createElement("item");
 
76
 
 
77
                i.setAttribute("category", ident.category);
 
78
                i.setAttribute("type", ident.type);
 
79
                if ( !ident.name.isEmpty() )
 
80
                        i.setAttribute("name", ident.name);
 
81
 
 
82
                query.appendChild( i );
 
83
 
 
84
        }
 
85
 
 
86
        d->iq.appendChild(query);
 
87
}
 
88
 
 
89
 
 
90
/**
 
91
 * Original requested jid.
 
92
 * Is here because sometimes the responder does not include this information
 
93
 * in the reply.
 
94
 */
 
95
const Jid& DiscoInfoTask::jid() const
 
96
{
 
97
        return d->jid;
 
98
}
 
99
 
 
100
/**
 
101
 * Original requested node.
 
102
 * Is here because sometimes the responder does not include this information
 
103
 * in the reply.
 
104
 */
 
105
const QString& DiscoInfoTask::node() const
 
106
{
 
107
        return d->node;
 
108
}
 
109
 
 
110
 
 
111
 
 
112
const DiscoItem &DiscoInfoTask::item() const
 
113
{
 
114
        return d->item;
 
115
}
 
116
 
 
117
void DiscoInfoTask::onGo ()
 
118
{
 
119
        send(d->iq);
 
120
}
 
121
 
 
122
bool DiscoInfoTask::take(const QDomElement &x)
 
123
{
 
124
        if(!iqVerify(x, d->jid, id()))
 
125
                return false;
 
126
 
 
127
        if(x.attribute("type") == "result") {
 
128
                QDomElement q = queryTag(x);
 
129
 
 
130
                DiscoItem item;
 
131
 
 
132
                item.setJid( d->jid );
 
133
                item.setNode( q.attribute("node") );
 
134
 
 
135
                QStringList features;
 
136
                DiscoItem::Identities identities;
 
137
 
 
138
                for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
 
139
                        QDomElement e = n.toElement();
 
140
                        if( e.isNull() )
 
141
                                continue;
 
142
 
 
143
                        if ( e.tagName() == "feature" ) {
 
144
                                features << e.attribute("var");
 
145
                        }
 
146
                        else if ( e.tagName() == "identity" ) {
 
147
                                DiscoItem::Identity id;
 
148
 
 
149
                                id.category = e.attribute("category");
 
150
                                id.name     = e.attribute("name");
 
151
                                id.type     = e.attribute("type");
 
152
 
 
153
                                identities.append( id );
 
154
                        }
 
155
                }
 
156
 
 
157
                item.setFeatures( features );
 
158
                item.setIdentities( identities );
 
159
 
 
160
                d->item = item;
 
161
 
 
162
                setSuccess(true);
 
163
        }
 
164
        else {
 
165
                setError(x);
 
166
        }
 
167
 
 
168
        return true;
 
169
}
 
170
 
 
171