516
576
x.setAttribute("xmlns", "jabber:x:signed");
517
577
tag.appendChild(x);
580
if(!s.capsNode().isEmpty() && !s.capsVersion().isEmpty()) {
581
QDomElement c = doc()->createElement("c");
582
c.setAttribute("xmlns","http://jabber.org/protocol/caps");
583
c.setAttribute("node",s.capsNode());
584
c.setAttribute("ver",s.capsVersion());
585
if (!s.capsExt().isEmpty())
586
c.setAttribute("ext",s.capsExt());
591
QDomElement m = doc()->createElement("x");
592
m.setAttribute("xmlns","http://jabber.org/protocol/muc");
593
if (!s.mucPassword().isEmpty()) {
594
m.appendChild(textTag(doc(),"password",s.mucPassword()));
596
if (s.hasMUCHistory()) {
597
QDomElement h = doc()->createElement("history");
598
if (s.mucHistoryMaxChars() >= 0)
599
h.setAttribute("maxchars",s.mucHistoryMaxChars());
600
if (s.mucHistoryMaxStanzas() >= 0)
601
h.setAttribute("maxstanzas",s.mucHistoryMaxStanzas());
602
if (s.mucHistorySeconds() >= 0)
603
h.setAttribute("seconds",s.mucHistorySeconds());
625
725
else if(i.tagName() == "x" && i.attribute("xmlns") == "http://jabber.org/protocol/e2e") {
626
726
p.setKeyID(tagContent(i));
728
else if(i.tagName() == "c" && i.attribute("xmlns") == "http://jabber.org/protocol/caps") {
729
p.setCapsNode(i.attribute("node"));
730
p.setCapsVersion(i.attribute("ver"));
731
p.setCapsExt(i.attribute("ext"));
733
else if(i.tagName() == "x" && i.attribute("xmlns") == "vcard-temp:x:update") {
736
t = findSubTag(i, "photo", &found);
738
p.setPhotoHash(tagContent(t));
742
else if(i.tagName() == "x" && i.attribute("xmlns") == "http://jabber.org/protocol/muc#user") {
743
for(QDomNode muc_n = i.firstChild(); !muc_n.isNull(); muc_n = muc_n.nextSibling()) {
744
QDomElement muc_e = muc_n.toElement();
748
if (muc_e.tagName() == "item")
749
p.setMUCItem(MUCItem(muc_e));
750
else if (muc_e.tagName() == "status")
751
p.setMUCStatus(muc_e.attribute("code").toInt());
752
else if (muc_e.tagName() == "destroy")
753
p.setMUCDestroy(MUCDestroy(muc_e));
696
825
//----------------------------------------------------------------------------
697
826
// JT_PushMessage
698
827
//----------------------------------------------------------------------------
699
static QDomElement addCorrectNS(const QDomElement &e)
704
/*QDomDocumentFragment frag = e.ownerDocument().createDocumentFragment();
705
QDomNodeList nl = e.childNodes();
706
for(x = 0; x < nl.count(); ++x)
707
frag.appendChild(nl.item(x).cloneNode());*/
709
// find closest xmlns
711
while(!n.isNull() && !n.toElement().hasAttribute("xmlns"))
714
if(n.isNull() || !n.toElement().hasAttribute("xmlns"))
715
ns = "jabber:client";
717
ns = n.toElement().attribute("xmlns");
720
QDomElement i = e.ownerDocument().createElementNS(ns, e.tagName());
723
QDomNamedNodeMap al = e.attributes();
724
for(x = 0; x < al.count(); ++x) {
725
QDomAttr a = al.item(x).toAttr();
726
if(a.name() != "xmlns")
727
i.setAttributeNodeNS(al.item(x).cloneNode().toAttr());
731
QDomNodeList nl = e.childNodes();
732
for(x = 0; x < nl.count(); ++x) {
733
QDomNode n = nl.item(x);
735
i.appendChild(addCorrectNS(n.toElement()));
737
i.appendChild(n.cloneNode());
740
//i.appendChild(frag);
744
828
JT_PushMessage::JT_PushMessage(Task *parent)
1265
1349
// return TRUE;
1267
1351
else if(ns == "http://jabber.org/protocol/disco#info") {
1352
// Find out the node
1353
bool invalid_node = false;
1356
QDomElement q = findSubTag(e, "query", &found);
1357
if(found) // NOTE: Should always be true, since a NS was found above
1358
node = q.attribute("node");
1268
1360
QDomElement iq = createIQ(doc(), "result", e.attribute("from"), e.attribute("id"));
1269
1361
QDomElement query = doc()->createElement("query");
1270
1362
query.setAttribute("xmlns", "http://jabber.org/protocol/disco#info");
1363
if (!node.isEmpty())
1364
query.setAttribute("node", node);
1271
1365
iq.appendChild(query);
1368
DiscoItem::Identity identity = client()->identity();
1369
QDomElement id = doc()->createElement("identity");
1370
if (!identity.category.isEmpty() && !identity.type.isEmpty()) {
1371
id.setAttribute("category",identity.category);
1372
id.setAttribute("type",identity.type);
1373
if (!identity.name.isEmpty()) {
1374
id.setAttribute("name",identity.name);
1379
id.setAttribute("category","client");
1380
id.setAttribute("type","pc");
1382
query.appendChild(id);
1272
1384
QDomElement feature;
1274
feature = doc()->createElement("feature");
1275
feature.setAttribute("var", "http://jabber.org/protocol/bytestreams");
1276
query.appendChild(feature);
1278
feature = doc()->createElement("feature");
1279
feature.setAttribute("var", "http://jabber.org/protocol/si");
1280
query.appendChild(feature);
1282
feature = doc()->createElement("feature");
1283
feature.setAttribute("var", "http://jabber.org/protocol/si/profile/file-transfer");
1284
query.appendChild(feature);
1385
if (node.isEmpty() || node == client()->capsNode() + "#" + client()->capsVersion()) {
1386
// Standard features
1387
feature = doc()->createElement("feature");
1388
feature.setAttribute("var", "http://jabber.org/protocol/bytestreams");
1389
query.appendChild(feature);
1391
feature = doc()->createElement("feature");
1392
feature.setAttribute("var", "http://jabber.org/protocol/si");
1393
query.appendChild(feature);
1395
feature = doc()->createElement("feature");
1396
feature.setAttribute("var", "http://jabber.org/protocol/si/profile/file-transfer");
1397
query.appendChild(feature);
1399
feature = doc()->createElement("feature");
1400
feature.setAttribute("var", "http://jabber.org/protocol/disco#info");
1401
query.appendChild(feature);
1403
// Client-specific features
1404
QStringList clientFeatures = client()->features().list();
1405
for (QStringList::ConstIterator i = clientFeatures.begin(); i != clientFeatures.end(); ++i) {
1406
feature = doc()->createElement("feature");
1407
feature.setAttribute("var", *i);
1408
query.appendChild(feature);
1411
if (node.isEmpty()) {
1412
// Extended features
1413
QStringList exts = client()->extensions();
1414
for (QStringList::ConstIterator i = exts.begin(); i != exts.end(); ++i) {
1415
const QStringList& l = client()->extension(*i).list();
1416
for ( QStringList::ConstIterator j = l.begin(); j != l.end(); ++j ) {
1417
feature = doc()->createElement("feature");
1418
feature.setAttribute("var", *j);
1419
query.appendChild(feature);
1424
else if (node.startsWith(client()->capsNode() + "#")) {
1425
QString ext = node.right(node.length()-client()->capsNode().length()-1);
1426
if (client()->extensions().contains(ext)) {
1427
const QStringList& l = client()->extension(ext).list();
1428
for ( QStringList::ConstIterator it = l.begin(); it != l.end(); ++it ) {
1429
feature = doc()->createElement("feature");
1430
feature.setAttribute("var", *it);
1431
query.appendChild(feature);
1435
invalid_node = true;
1439
invalid_node = true;
1442
if (!invalid_node) {
1446
// Create error reply
1447
QDomElement error_reply = createIQ(doc(), "result", e.attribute("from"), e.attribute("id"));
1450
for (QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
1451
error_reply.appendChild(n.cloneNode());
1455
QDomElement error = doc()->createElement("error");
1456
error.setAttribute("type","cancel");
1457
error_reply.appendChild(error);
1458
QDomElement error_type = doc()->createElement("item-not-found");
1459
error_type.setAttribute("xmlns","urn:ietf:params:xml:ns:xmpp-stanzas");
1460
error.appendChild(error_type);
1592
1768
//----------------------------------------------------------------------------
1594
//----------------------------------------------------------------------------
1595
class JT_DiscoInfo::Private
1605
JT_DiscoInfo::JT_DiscoInfo(Task *parent)
1611
JT_DiscoInfo::~JT_DiscoInfo()
1616
void JT_DiscoInfo::get(const DiscoItem &item)
1618
DiscoItem::Identity id;
1619
if ( item.identities().count() == 1 )
1620
id = item.identities().first();
1621
get(item.jid(), item.node(), id);
1624
void JT_DiscoInfo::get (const Jid &j, const QString &node, DiscoItem::Identity ident)
1626
d->item = DiscoItem(); // clear item
1629
d->iq = createIQ(doc(), "get", d->jid.full(), id());
1630
QDomElement query = doc()->createElement("query");
1631
query.setAttribute("xmlns", "http://jabber.org/protocol/disco#info");
1633
if ( !node.isEmpty() )
1634
query.setAttribute("node", node);
1636
if ( !ident.category.isEmpty() && !ident.type.isEmpty() ) {
1637
QDomElement i = doc()->createElement("item");
1639
i.setAttribute("category", ident.category);
1640
i.setAttribute("type", ident.type);
1641
if ( !ident.name.isEmpty() )
1642
i.setAttribute("name", ident.name);
1644
query.appendChild( i );
1648
d->iq.appendChild(query);
1651
const DiscoItem &JT_DiscoInfo::item() const
1656
void JT_DiscoInfo::onGo ()
1661
bool JT_DiscoInfo::take(const QDomElement &x)
1663
if(!iqVerify(x, d->jid, id()))
1666
if(x.attribute("type") == "result") {
1667
QDomElement q = queryTag(x);
1671
item.setJid( d->jid );
1672
item.setNode( q.attribute("node") );
1674
QStringList features;
1675
DiscoItem::Identities identities;
1677
for(QDomNode n = q.firstChild(); !n.isNull(); n = n.nextSibling()) {
1678
QDomElement e = n.toElement();
1682
if ( e.tagName() == "feature" ) {
1683
features << e.attribute("var");
1685
else if ( e.tagName() == "identity" ) {
1686
DiscoItem::Identity id;
1688
id.category = e.attribute("category");
1689
id.name = e.attribute("name");
1690
id.type = e.attribute("type");
1692
identities.append( id );
1696
item.setFeatures( features );
1697
item.setIdentities( identities );
1710
//----------------------------------------------------------------------------
1711
1769
// JT_DiscoPublish
1712
1770
//----------------------------------------------------------------------------
1713
1771
class JT_DiscoPublish::Private