File indexing completed on 2024-06-23 04:03:40
0001 /* 0002 * Copyright (C) 2001, 2002 Justin Karneges 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * either version 2 0008 of the License, or (at your option) any later version.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library; if not, write to the Free Software 0017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0018 * 0019 */ 0020 0021 #include <QDomElement> 0022 #include <QString> 0023 0024 #include "xmpp/jid/jid.h" 0025 #include "xmpp_discoinfotask.h" 0026 #include "xmpp_xmlcommon.h" 0027 0028 using namespace XMPP; 0029 0030 class DiscoInfoTask::Private 0031 { 0032 public: 0033 Private() { } 0034 0035 QDomElement iq; 0036 Jid jid; 0037 QString node; 0038 DiscoItem item; 0039 }; 0040 0041 DiscoInfoTask::DiscoInfoTask(Task *parent) 0042 : Task(parent) 0043 { 0044 d = new Private; 0045 } 0046 0047 DiscoInfoTask::~DiscoInfoTask() 0048 { 0049 delete d; 0050 } 0051 0052 void DiscoInfoTask::get(const DiscoItem &item) 0053 { 0054 DiscoItem::Identity id; 0055 if ( item.identities().count() == 1 ) 0056 id = item.identities().first(); 0057 get(item.jid(), item.node(), id); 0058 } 0059 0060 void DiscoInfoTask::get (const Jid &j, const QString &node, DiscoItem::Identity ident) 0061 { 0062 d->item = DiscoItem(); // clear item 0063 0064 d->jid = j; 0065 d->node = node; 0066 d->iq = createIQ(doc(), "get", d->jid.full(), id()); 0067 QDomElement query = doc()->createElement("query"); 0068 query.setAttribute("xmlns", "http://jabber.org/protocol/disco#info"); 0069 0070 if ( !node.isEmpty() ) 0071 query.setAttribute("node", node); 0072 0073 if ( !ident.category.isEmpty() && !ident.type.isEmpty() ) { 0074 QDomElement i = doc()->createElement("item"); 0075 0076 i.setAttribute("category", ident.category); 0077 i.setAttribute("type", ident.type); 0078 if ( !ident.name.isEmpty() ) 0079 i.setAttribute("name", ident.name); 0080 0081 query.appendChild( i ); 0082 0083 } 0084 0085 d->iq.appendChild(query); 0086 } 0087 0088 0089 /** 0090 * Original requested jid. 0091 * Is here because sometimes the responder does not include this information 0092 * in the reply. 0093 */ 0094 const Jid& DiscoInfoTask::jid() const 0095 { 0096 return d->jid; 0097 } 0098 0099 /** 0100 * Original requested node. 0101 * Is here because sometimes the responder does not include this information 0102 * in the reply. 0103 */ 0104 const QString& DiscoInfoTask::node() const 0105 { 0106 return d->node; 0107 } 0108 0109 0110 0111 const DiscoItem &DiscoInfoTask::item() const 0112 { 0113 return d->item; 0114 } 0115 0116 void DiscoInfoTask::onGo () 0117 { 0118 send(d->iq); 0119 } 0120 0121 bool DiscoInfoTask::take(const QDomElement &x) 0122 { 0123 if(!iqVerify(x, d->jid, id())) 0124 return false; 0125 0126 if(x.attribute("type") == "result") { 0127 QDomElement q = queryTag(x); 0128 0129 DiscoItem item; 0130 0131 item.setJid( d->jid ); 0132 item.setNode( q.attribute("node") ); 0133 0134 QStringList features; 0135 DiscoItem::Identities identities; 0136 0137 for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) { 0138 QDomElement e = n.toElement(); 0139 if( e.isNull() ) 0140 continue; 0141 0142 if ( e.tagName() == "feature" ) { 0143 features << e.attribute("var"); 0144 } 0145 else if ( e.tagName() == "identity" ) { 0146 DiscoItem::Identity id; 0147 0148 id.category = e.attribute("category"); 0149 id.name = e.attribute("name"); 0150 id.type = e.attribute("type"); 0151 0152 identities.append( id ); 0153 } 0154 } 0155 0156 item.setFeatures( features ); 0157 item.setIdentities( identities ); 0158 0159 d->item = item; 0160 0161 setSuccess(true); 0162 } 0163 else { 0164 setError(x); 0165 } 0166 0167 return true; 0168 } 0169 0170