29
#include "xmpp_xmlcommon.h"
29
30
#define NS_XML "http://www.w3.org/XML/1998/namespace"
31
static QDomElement textTag(QDomDocument *doc, const QString &name, const QString &content)
33
QDomElement tag = doc->createElement(name);
34
QDomText text = doc->createTextNode(content);
35
tag.appendChild(text);
40
static QString tagContent(const QDomElement &e)
42
// look for some tag content
43
for(QDomNode n = e.firstChild(); !n.isNull(); n = n.nextSibling()) {
44
QDomText i = n.toText();
53
static QDateTime stamp2TS(const QString &ts)
58
int year = ts.mid(0,4).toInt();
59
int month = ts.mid(4,2).toInt();
60
int day = ts.mid(6,2).toInt();
62
int hour = ts.mid(9,2).toInt();
63
int min = ts.mid(12,2).toInt();
64
int sec = ts.mid(15,2).toInt();
67
xd.setYMD(year, month, day);
72
xt.setHMS(hour, min, sec);
76
return QDateTime(xd, xt);
79
static QString TS2stamp(const QDateTime &d)
83
str.sprintf("%04d%02d%02dT%02d:%02d:%02d",
905
HTMLElement::HTMLElement(const QDomElement &body) : body_(body) {}
843
HTMLElement::HTMLElement(const QDomElement &body) { setBody(body); }
907
845
void HTMLElement::setBody(const QDomElement &body)
847
body_ = doc_.importNode(body, true).toElement();
912
850
const QDomElement& HTMLElement::body() const
971
909
QString xencrypted, invite;
972
910
ChatState chatState;
911
MessageReceipt messageReceipt;
974
913
HttpAuthRequest httpAuthRequest;
976
915
QMap<QString,HTMLElement> htmlElements;
980
919
QList<MUCInvite> mucInvites;
981
920
MUCDecline mucDecline;
982
921
QString mucPassword;
983
int mucHistoryMaxChars, mucHistoryMaxStanzas, mucHistorySeconds;
985
923
bool spooled, wasEncrypted;
1332
1271
d->chatState = state;
1274
MessageReceipt Message::messageReceipt() const
1276
return d->messageReceipt;
1279
void Message::setMessageReceipt(MessageReceipt messageReceipt)
1281
d->messageReceipt = messageReceipt;
1335
1284
QString Message::xencrypted() const
1337
1286
return d->xencrypted;
1427
1376
return d->xdata;
1430
const QDomElement& Message::whiteboard() const
1379
const QDomElement& Message::sxe() const
1435
void Message::setWhiteboard(const QDomElement& e)
1384
void Message::setSxe(const QDomElement& e)
1440
1389
bool Message::spooled() const
1522
QString messageReceiptNS = "urn:xmpp:receipts";
1523
if (d->messageReceipt != ReceiptNone) {
1524
switch(d->messageReceipt) {
1525
case ReceiptRequest:
1526
s.appendChild(s.createElement(messageReceiptNS, "request"));
1528
case ReceiptReceived:
1529
s.appendChild(s.createElement(messageReceiptNS, "received"));
1573
1537
if(!d->xencrypted.isEmpty())
1574
1538
s.appendChild(s.createTextElement("jabber:x:encrypted", "x", d->xencrypted));
1707
1671
d->error = s.error();
1710
nl = root.elementsByTagNameNS("http://jabber.org/protocol/xhtml-im", "html");
1674
nl = childElementsByTagNameNS(root, "http://jabber.org/protocol/xhtml-im", "html");
1711
1675
if (nl.count()) {
1712
1676
nl = nl.item(0).childNodes();
1713
1677
for(n = 0; n < nl.count(); ++n) {
1723
QDomElement t = root.elementsByTagNameNS("jabber:x:delay", "x").item(0).toElement();
1687
QDomElement t = childElementsByTagNameNS(root, "jabber:x:delay", "x").item(0).toElement();
1724
1688
if(!t.isNull()) {
1725
1689
d->timeStamp = stamp2TS(t.attribute("stamp"));
1726
1690
d->timeStamp = d->timeStamp.addSecs(timeZoneOffset * 3600);
1735
1699
d->urlList.clear();
1736
nl = root.elementsByTagNameNS("jabber:x:oob", "x");
1700
nl = childElementsByTagNameNS(root, "jabber:x:oob", "x");
1737
1701
for(n = 0; n < nl.count(); ++n) {
1738
1702
QDomElement t = nl.item(n).toElement();
1746
1710
d->eventList.clear();
1747
nl = root.elementsByTagNameNS("jabber:x:event", "x");
1711
nl = childElementsByTagNameNS(root, "jabber:x:event", "x");
1748
1712
if (nl.count()) {
1749
1713
nl = nl.item(0).childNodes();
1750
1714
for(n = 0; n < nl.count(); ++n) {
1767
1731
QString chatStateNS = "http://jabber.org/protocol/chatstates";
1768
t = root.elementsByTagNameNS(chatStateNS, "active").item(0).toElement();
1732
t = childElementsByTagNameNS(root, chatStateNS, "active").item(0).toElement();
1769
1733
if(!t.isNull())
1770
1734
d->chatState = StateActive;
1771
t = root.elementsByTagNameNS(chatStateNS, "composing").item(0).toElement();
1735
t = childElementsByTagNameNS(root, chatStateNS, "composing").item(0).toElement();
1772
1736
if(!t.isNull())
1773
1737
d->chatState = StateComposing;
1774
t = root.elementsByTagNameNS(chatStateNS, "paused").item(0).toElement();
1738
t = childElementsByTagNameNS(root, chatStateNS, "paused").item(0).toElement();
1775
1739
if(!t.isNull())
1776
1740
d->chatState = StatePaused;
1777
t = root.elementsByTagNameNS(chatStateNS, "inactive").item(0).toElement();
1741
t = childElementsByTagNameNS(root, chatStateNS, "inactive").item(0).toElement();
1778
1742
if(!t.isNull())
1779
1743
d->chatState = StateInactive;
1780
t = root.elementsByTagNameNS(chatStateNS, "gone").item(0).toElement();
1744
t = childElementsByTagNameNS(root, chatStateNS, "gone").item(0).toElement();
1781
1745
if(!t.isNull())
1782
1746
d->chatState = StateGone;
1749
QString messageReceiptNS = "urn:xmpp:receipts";
1750
t = childElementsByTagNameNS(root, messageReceiptNS, "request").item(0).toElement();
1752
d->messageReceipt = ReceiptRequest;
1753
t = childElementsByTagNameNS(root, messageReceiptNS, "received").item(0).toElement();
1755
d->messageReceipt = ReceiptReceived;
1786
t = root.elementsByTagNameNS("jabber:x:encrypted", "x").item(0).toElement();
1758
t = childElementsByTagNameNS(root, "jabber:x:encrypted", "x").item(0).toElement();
1787
1759
if(!t.isNull())
1788
1760
d->xencrypted = t.text();
1793
1765
d->addressList.clear();
1794
nl = root.elementsByTagNameNS("http://jabber.org/protocol/address", "addresses");
1766
nl = childElementsByTagNameNS(root, "http://jabber.org/protocol/address", "addresses");
1795
1767
if (nl.count()) {
1796
1768
QDomElement t = nl.item(0).toElement();
1797
1769
nl = t.elementsByTagName("address");
1803
1775
// roster item exchange
1804
1776
d->rosterExchangeItems.clear();
1805
nl = root.elementsByTagNameNS("http://jabber.org/protocol/rosterx", "x");
1777
nl = childElementsByTagNameNS(root, "http://jabber.org/protocol/rosterx", "x");
1806
1778
if (nl.count()) {
1807
1779
QDomElement t = nl.item(0).toElement();
1808
1780
nl = t.elementsByTagName("item");
1817
t = root.elementsByTagNameNS("jabber:x:conference", "x").item(0).toElement();
1789
t = childElementsByTagNameNS(root, "jabber:x:conference", "x").item(0).toElement();
1818
1790
if(!t.isNull())
1819
1791
d->invite = t.attribute("jid");
1821
1793
d->invite = QString();
1824
t = root.elementsByTagNameNS("http://jabber.org/protocol/nick", "nick").item(0).toElement();
1796
t = childElementsByTagNameNS(root, "http://jabber.org/protocol/nick", "nick").item(0).toElement();
1825
1797
if(!t.isNull())
1826
1798
d->nick = t.text();
1828
1800
d->nick = QString();
1831
t = root.elementsByTagNameNS("http://jabber.org/protocol/svgwb", "wb").item(0).toElement();
1803
t = childElementsByTagNameNS(root, "http://jabber.org/protocol/sxe", "sxe").item(0).toElement();
1832
1804
if(!t.isNull())
1835
d->wb = QDomElement();
1807
d->sxe = QDomElement();
1837
t = root.elementsByTagNameNS("http://jabber.org/protocol/muc#user", "x").item(0).toElement();
1809
t = childElementsByTagNameNS(root, "http://jabber.org/protocol/muc#user", "x").item(0).toElement();
1838
1810
if(!t.isNull()) {
1839
1811
for(QDomNode muc_n = t.firstChild(); !muc_n.isNull(); muc_n = muc_n.nextSibling()) {
1840
1812
QDomElement muc_e = muc_n.toElement();
1861
t = root.elementsByTagNameNS("http://jabber.org/protocol/http-auth", "confirm").item(0).toElement();
1833
t = childElementsByTagNameNS(root, "http://jabber.org/protocol/http-auth", "confirm").item(0).toElement();
1862
1834
if(!t.isNull()){
1863
1835
d->httpAuthRequest = HttpAuthRequest(t);