예제 #1
0
파일: util.cpp 프로젝트: AlexWMF/leechcraft
	QXmppMessage Forwarded2Message (const QXmppElement& wrapper)
	{
		const auto& forwardedElem = wrapper.tagName () == "forwarded" ?
				wrapper :
				wrapper.firstChildElement ("forwarded");
		if (forwardedElem.isNull ())
			return {};

		const auto& messageElem = forwardedElem.firstChildElement ("message");
		if (messageElem.isNull ())
			return {};

		QXmppMessage original;
#if QXMPP_VERSION >= 0x000800
		original.parse (messageElem.sourceDomElement ());
#else
#warning "You won't have good forwarded messages, Message Archive Management and Message Carbons will look like crap."
		original.parse (XmppElem2DomElem (messageElem));
#endif

		auto delayElem = forwardedElem.firstChildElement ("delay");
		if (!delayElem.isNull ())
		{
			const auto& sourceDT = QXmppUtils::datetimeFromString (delayElem.attribute ("stamp"));
			original.setStamp (sourceDT.toLocalTime ());
		}

		return original;
	}
예제 #2
0
bool QXmppCarbonManager::handleStanza(const QDomElement &element)
{
    if(element.tagName() != "message")
        return false;

    bool sent = true;
    QDomElement carbon = element.firstChildElement("sent");
    if(carbon.isNull()) {
        carbon = element.firstChildElement("received");
        sent = false;
    }

    if(carbon.isNull() || carbon.namespaceURI() != ns_carbons)
        return false;   // Neither sent nor received -> no carbon message

    QDomElement forwarded = carbon.firstChildElement("forwarded");
    if(forwarded.isNull())
        return false;

    QDomElement messageelement = forwarded.firstChildElement("message");
    if(messageelement.isNull())
        return false;

    QXmppMessage message;
    message.parse(messageelement);

    if(sent)
        emit messageSent(message);
    else
        emit messageReceived(message);

    return true;
}
bool QXmppMessageReceiptManager::handleStanza(const QDomElement &stanza)
{
    if (stanza.tagName() != "message")
        return false;

    QXmppMessage message;
    message.parse(stanza);

    // Handle receipts and cancel any further processing.
    if (!message.receiptId().isEmpty()) {
        Q_EMIT messageDelivered(message.from(), message.receiptId());
        return true;
    }

    // If requested, send a receipt.
    if (message.isReceiptRequested()
        && !message.from().isEmpty()
        && !message.id().isEmpty()) {
        QXmppMessage receipt;
        receipt.setTo(message.from());
        receipt.setReceiptId(message.id());
        client()->sendPacket(receipt);
    }

    // Continue processing.
    return false;
}
예제 #4
0
bool XmppServerArchive::handleStanza(const QDomElement &element)
{
    const QString domain = server()->domain();
    const QString from = element.attribute("from");
    const QString to = element.attribute("to");

    if (element.tagName() == "message" &&
        to != domain &&
        (QXmppUtils::jidToDomain(from) == domain || QXmppUtils::jidToDomain(to) == domain) &&
        element.attribute("type") != "error" &&
        element.attribute("type") != "groupchat" &&
        element.attribute("type") != "headline" &&
        !element.firstChildElement("body").text().isEmpty())
    {
        const QDateTime now = QDateTime::currentDateTime().toUTC();
        QXmppMessage message;
        message.parse(element);

        if (QXmppUtils::jidToDomain(from) == domain)
            saveMessage(message, now, false);

        if (QXmppUtils::jidToDomain(to) == domain) {
            saveMessage(message, now, true);

            // offline messages
            bool found = false;

            XmppServerPresence *presenceExtension = XmppServerPresence::instance(server());
            Q_ASSERT(presenceExtension);
            foreach (const QXmppPresence &presence, presenceExtension->availablePresences(QXmppUtils::jidToBareJid(to))) {
                if (QXmppUtils::jidToResource(to).isEmpty() || presence.from() == to) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                message.setStamp(now);
                message.setState(QXmppMessage::None);
                message.setTo(QXmppUtils::jidToBareJid(to));

                QBuffer buffer;
                buffer.open(QIODevice::WriteOnly);
                QXmlStreamWriter writer(&buffer);
                message.toXml(&writer);

                OfflineMessage offline;
                offline.setData(QString::fromUtf8(buffer.data()));
                offline.setJid(QXmppUtils::jidToBareJid(to));
                offline.setStamp(now);
                offline.save();
                return true;
            }
        }

        return false;

    } else if (element.tagName() == "presence" &&
예제 #5
0
bool QXmppSimpleArchiveManager::handleStanza(const QDomElement &element)
{
    bool isIq = (element.tagName() == "iq");
    if (!isIq && (element.tagName() != "message")) {
        return false;
    }

    // XEP-0313: Message Archiving
    if(isIq && !QXmppSimpleArchiveQueryIq::isSimpleArchiveQueryIq(element)) {
        return false;
    }

    if (isIq && (element.attribute("type") == "result")) {
        QString id = element.attribute("id");
        if (m_pendingQueries.contains(id)) {
            PendingQuery pendingQuery = m_pendingQueries.value(id);
            m_pendingQueries.remove(id);
            QXmppSimpleArchiveQueryIq packet;
            packet.parse(element);
            emit archiveMessagesReceived(pendingQuery.jid, pendingQuery.messages, packet.resultSetReply());
            return true;
        }
    } else if (isIq && (element.attribute("type") == "error")) {
        QDomElement queryElement = element.firstChildElement("query");
        if (!queryElement.isNull()) {
            QString queryId = queryElement.attribute("queryid");
            if (m_pendingQueries.contains(queryId)) {
              PendingQuery pendingQuery = m_pendingQueries.value(queryId);
              m_pendingQueries.remove(queryId);
              emit archiveMessagesReceived(pendingQuery.jid, pendingQuery.messages, QXmppResultSetReply());
              return true;
            }
        }
    } else {
        // message, check for result UUID + query ID
        QDomElement resultElement = element.firstChildElement("result");
        if (!resultElement.isNull()) {
            QString queryId = resultElement.attribute("queryid");
            if (m_pendingQueries.contains(queryId)) {
                QXmppMessage msg;
                msg.parse(element);
                m_pendingQueries[queryId].messages.append(msg.mamMessage());
                
                return true;
            } else {
                qWarning() << "SimpleArchiveManager: unknown query ID:" << queryId;
            }
        }
    }

    return false;
}
예제 #6
0
bool Lvk::CA::FbOwnMessageExtension::handleStanza(const QDomElement &nodeRecv)
{
    bool handled = false;

    if (nodeRecv.tagName() == "iq") {
        QDomElement child = nodeRecv.firstChildElement();

        if (child.tagName() == "own-message" && child.attribute("self") == "false") {
            QXmppMessage msg;
            msg.parse(child);

            emit ownMessage(msg);

            handled = true;
        }
    }

    return handled;
}
QXmppMessage QXmppMessage::parseForward(QDomElement &element)
{
    QXmppMessage result;
    if (!element.isNull() && element.namespaceURI() == ns_stanza_forwarding)
    {
        QDomElement msgElement = element.firstChildElement("message");

        QXmppMessage fwd;
        fwd.parse(msgElement);

        QDomElement delayElement = element.firstChildElement("delay");
        if (!delayElement.isNull() && delayElement.namespaceURI() == ns_delayed_delivery) {
            const QString str = delayElement.attribute("stamp");
            fwd.d->stamp = QXmppUtils::datetimeFromString(str);
            fwd.d->stampType = DelayedDelivery;
        }

        result = fwd;
    }
    return result;
}
예제 #8
0
bool QXmppPEPManager::handleStanza(const QDomElement &stanza)
{
    bool isIq = (stanza.tagName() == "iq");
    if (!isIq && (stanza.tagName() != "message")) {
        return false;
    }

    // XEP-0163: Personal Eventing Protocol
    QDomElement pepElement = stanza.firstChildElement("event");

    if(!pepElement.isNull() && pepElement.namespaceURI() == ns_personal_eventing_protocol)
    {
        QXmppMessage message;
        message.parse(stanza);

        QDomElement itemsElement = pepElement.firstChildElement("items");
        QString nodeType = itemsElement.attribute("node");

        // XEP-0152: Reachability Addresses
        if(nodeType == ns_reach)
        {
            QDomElement itemElement = itemsElement.firstChildElement("item");
            if(!itemElement.isNull())
            {
                QString itemId = itemElement.attribute("id");
                QDomElement reachElement = itemElement.firstChildElement("reach");

                QXmppReachAddress reachAddress;
                reachAddress.parse(reachElement);

                if(!reachAddress.isNull())
                    emit reachabilityAddressReceived(message.from(), itemId, reachAddress);

                return true;
            }
        }
    }
    return false;
}