Ejemplo n.º 1
0
	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;
	}
Ejemplo n.º 2
0
	QXmppElement UserTune::ToXML () const
	{
		QXmppElement result;
		result.setTagName ("item");

		QXmppElement tune;
		tune.setTagName ("tune");
		tune.setAttribute ("xmlns", NsTuneNode);

		auto appendTxt = [&tune] (const QString& tag, const QString& str)
		{
			if (str.isEmpty ())
				return;

			QXmppElement elem;
			elem.setTagName (tag);
			elem.setValue (str);
			tune.appendChild (elem);
		};

		appendTxt ("artist", Artist_);
		appendTxt ("source", Source_);
		appendTxt ("title", Title_);
		appendTxt ("track", Track_);
		appendTxt ("uri", URI_.toEncoded ());
		if (Length_)
			appendTxt ("length", QString::number (Length_));
		if (Rating_)
			appendTxt ("rating", QString::number (Rating_));

		result.appendChild (tune);

		return result;
	}
Ejemplo n.º 3
0
	void JabberSearchManager::SubmitSearchRequest (const QString& server, const QXmppDataForm& form)
	{
		QXmppElement query;
		query.setTagName ("query");
		query.setAttribute ("xmlns", NsJabberSearch);
		query.appendChild (XooxUtil::Form2XmppElem (form));
		SubmitSearchRequest (server, query);
	}
Ejemplo n.º 4
0
 foreach (QXmppElement element, extensions()) {
     if (element.tagName() == "html") {
         QString html;
         QXmlStreamWriter writer(&html);
         element.toXml(&writer);
         return html;
     }
 }
Ejemplo n.º 5
0
	void JabberSearchManager::SubmitSearchRequest (const QString& server, const QList<QXmppElement>& fields)
	{
		QXmppElement query;
		query.setTagName ("query");
		query.setAttribute ("xmlns", NsJabberSearch);

		Q_FOREACH (const QXmppElement& field, fields)
			query.appendChild (field);

		SubmitSearchRequest (server, query);
	}
Ejemplo n.º 6
0
	QXmppIq LastActivityManager::CreateIq (const QString& to, int secs)
	{
		QXmppIq iq;
		iq.setTo (to);

		QXmppElement queryElem;
		queryElem.setAttribute ("xmlns", NsLastActivity);
		if (secs != -1)
			queryElem.setAttribute ("seconds", QString::number (secs));
		iq.setExtensions (queryElem);
		
		return iq;
	}
void QXmppDeliveryReceiptsManager::sendReceipt(const QString &jid, const QString &id)
{
    QXmppMessage msg;
    msg.setTo(jid);

    QXmppElement elem;
    elem.setTagName("received");
    elem.setAttribute("xmlns", ns_message_receipts);
    elem.setAttribute("id", id);

    msg.setExtensions(QXmppElementList(elem));

    client()->sendPacket(msg);
}
Ejemplo n.º 8
0
	void Xep0313Manager::HandleMessage (const QXmppElement& resultExt)
	{
		const auto& id = resultExt.attribute ("id");

		const auto& message = XooxUtil::Forwarded2Message (resultExt);
		if (message.to ().isEmpty ())
			return;

		const auto& ourJid = client ()->configuration ().jidBare ();

		IMessage::Direction dir;
		QString otherJid;
		if (message.to ().startsWith (ourJid))
		{
			dir = IMessage::Direction::In;
			otherJid = message.from ().section ('/', 0, 0);
		}
		else
		{
			dir = IMessage::Direction::Out;
			otherJid = message.to ().section ('/', 0, 0);
		}

		const SrvHistMessage msg { dir, id.toUtf8 (), {}, message.body (), message.stamp (), message.xhtml () };
		Messages_ [otherJid] << msg;
		LastId2Jid_ [id] = otherJid;
	}
Ejemplo n.º 9
0
void PrivateStorageIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
    writer->writeStartElement("query");
    helperToXmlAddAttribute(writer, "xmlns", ns_private_storage);
    m_payload.toXml(writer);
    writer->writeEndElement();
}
Ejemplo n.º 10
0
void PrivateStorage::setXml(const QXmppElement &element)
{
    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);
    QXmlStreamWriter writer(&buffer);
    element.toXml(&writer);
    m_data = QString::fromUtf8(buffer.data());
}
Ejemplo n.º 11
0
void QXmppCarbonManager::setCarbonsEnabled(bool enabled)
{
    if(m_carbonsEnabled == enabled)
        return;

    m_carbonsEnabled = enabled;

    if(client()) {
        QXmppIq iq(QXmppIq::Set);
        QXmppElement carbonselement;
        carbonselement.setTagName(m_carbonsEnabled ? "enable" : "disable");
        carbonselement.setAttribute("xmlns", ns_carbons);

        iq.setExtensions(QXmppElementList() << carbonselement);
        client()->sendPacket(iq);
    }
}
Ejemplo n.º 12
0
	QDomElement XmppElem2DomElem (const QXmppElement& elem)
	{
		QByteArray arr;
		QXmlStreamWriter w (&arr);
		elem.toXml (&w);

		QDomDocument doc;
		doc.setContent (arr, true);
		return doc.documentElement ();
	}
Ejemplo n.º 13
0
	void GlooxAccount::UpdateServerPassword (const QString& newPass)
	{
		if (newPass.isEmpty ())
			return;

		const QString nsRegister = "jabber:iq:register";

		const auto& jid = SettingsHolder_->GetJID ();
		const auto aPos = jid.indexOf ('@');

		QXmppElement userElem;
		userElem.setTagName ("username");
		userElem.setValue (aPos > 0 ? jid.left (aPos) : jid);

		QXmppElement passElem;
		passElem.setTagName ("password");
		passElem.setValue (newPass);

		QXmppElement queryElem;
		queryElem.setTagName ("query");
		queryElem.setAttribute ("xmlns", nsRegister);
		queryElem.appendChild (userElem);
		queryElem.appendChild (passElem);

		QXmppIq iq (QXmppIq::Set);
		iq.setTo (GetDefaultReqHost ());
		iq.setExtensions ({ queryElem });

		ClientConnection_->SendPacketWCallback (iq,
				[this, newPass] (const QXmppIq& reply) -> void
				{
					if (reply.type () != QXmppIq::Result)
						return;

					emit serverPasswordUpdated (newPass);
					Core::Instance ().GetPluginProxy ()->SetPassword (newPass, this);
					ClientConnection_->SetPassword (newPass);
				});
	}
Ejemplo n.º 14
0
	void AdHocCommandServer::SendCompleted (const QDomElement& sourceElem,
			const QString& node, const QString& sessionId)
	{
		QXmppElement elem;
		elem.setTagName ("command");
		elem.setAttribute ("xmlns", NsCommands);
		elem.setAttribute ("node", node);
		elem.setAttribute ("status", "completed");
		elem.setAttribute ("sessionid", sessionId);

		QXmppIq iq;
		iq.setTo (sourceElem.attribute ("from"));
		iq.setId (sourceElem.attribute ("id"));
		iq.setType (QXmppIq::Result);
		iq.setExtensions (QXmppElementList () << elem);

		Conn_->GetClient ()->sendPacket (iq);
	}
Ejemplo n.º 15
0
bool QXmppMucManager::joinRoom(const QString &roomJid, const QString &nickName, const QString &password)
{
    QXmppPresence packet;
    packet.setTo(roomJid + "/" + nickName);
    packet.setType(QXmppPresence::Available);
    QXmppElement x;
    x.setTagName("x");
    x.setAttribute("xmlns", ns_muc);
    if (!password.isEmpty())
    {
        QXmppElement p;
        p.setTagName("password");
        p.setValue(password);
        x.appendChild(p);
    }
    packet.setExtensions(x);
    if (client()->sendPacket(packet))
    {
        m_nickNames[roomJid] = nickName;
        return true;
    } else {
        return false;
    }
}
Ejemplo n.º 16
0
	QXmppElement UserActivity::ToXML () const
	{
		QXmppElement activityElem;
		activityElem.setTagName ("activity");
		activityElem.setAttribute ("xmlns", NsActivityNode);

		QXmppElement result;
		result.setTagName ("item");
		if (General_ == GeneralEmpty)
		{
			result.appendChild (activityElem);
			return result;
		}
		
		QXmppElement generalElem;
		generalElem.setTagName (activity_general [General_]);
		
		if (Specific_ != SpecificEmpty)
		{
			QXmppElement specific;
			specific.setTagName (activity_specific [Specific_]);
			generalElem.appendChild (specific);
		}
		
		if (!Text_.isEmpty ())
		{
			QXmppElement textElem;
			textElem.setTagName ("text");
			textElem.setValue (Text_);
			generalElem.appendChild (textElem);
		}

		activityElem.appendChild (generalElem);		
		result.appendChild (activityElem);

		return result;
	}
Ejemplo n.º 17
0
	bool LegacyEntityTimeExt::handleStanza (const QDomElement& elem)
	{
		if (elem.tagName () != "iq" ||
				elem.attribute ("type") != "get")
			return false;

		if (elem.firstChildElement ("query").namespaceURI () != NsLegacyEntityTime)
			return false;

		const QString& from = elem.attribute ("from");
		if (from.isEmpty ())
			return false;

		const QDateTime& date = QDateTime::currentDateTime ().toUTC ();

		QXmppElement utcElem;
		utcElem.setTagName ("utc");
		utcElem.setValue (date.toString ("yyyyMMddThh:mm:ss"));

		const QString& displayStr = "Your client/bot sucks since it "
				"uses the long-deprecated XEP-0090. Upgrade your code. "
				"Ah, and, regarding your question, it's " +
				QDateTime::currentDateTime ().toString () + " here";
		QXmppElement displayElem;
		displayElem.setTagName ("display");
		displayElem.setValue (displayStr);

		QXmppElement queryElem;
		queryElem.setTagName ("query");
		queryElem.setAttribute ("xmlns", NsLegacyEntityTime);
		queryElem.appendChild (utcElem);
		queryElem.appendChild (displayElem);

		QXmppIq iq (QXmppIq::Result);
		iq.setTo (from);
		iq.setId (elem.attribute ("id"));
		iq.setExtensions (QXmppElementList () << queryElem);

		client ()->sendPacket (iq);

		return true;
	}
Ejemplo n.º 18
0
	QXmppElement UserMood::ToXML () const
	{
		QXmppElement mood;
		mood.setTagName ("mood");
		mood.setAttribute ("xmlns", NsMoodNode);

		if (Mood_ != MoodEmpty)
		{
			QXmppElement elem;
			elem.setTagName (MoodStr [Mood_]);
			mood.appendChild (elem);

			if (!Text_.isEmpty ())
			{
				QXmppElement text;
				text.setTagName ("text");
				text.setValue (Text_);
				mood.appendChild (text);
			}
		}

		QXmppElement result;
		result.setTagName ("item");
		result.appendChild (mood);
		return result;
	}