예제 #1
0
	void RoomHandler::requestVoice ()
	{
		QList<QXmppDataForm::Field> fields;

		QXmppDataForm::Field typeField (QXmppDataForm::Field::HiddenField);
		typeField.setKey ("FORM_TYPE");
		typeField.setValue ("http://jabber.org/protocol/muc#request");
		fields << typeField;

		QXmppDataForm::Field reqField (QXmppDataForm::Field::TextSingleField);
		reqField.setLabel ("Requested role");
		reqField.setKey ("muc#role");
		reqField.setValue ("participant");
		fields << reqField;

		QXmppDataForm form;
		form.setType (QXmppDataForm::Submit);
		form.setFields (fields);

		QXmppMessage msg ("", Room_->jid ());
		msg.setType (QXmppMessage::Normal);
		msg.setExtensions (XooxUtil::Form2XmppElem (form));

		Account_->GetClientConnection ()->GetClient ()->sendPacket (msg);
	}
예제 #2
0
	void Xep0313ReqIq::parseElementFromChild (const QDomElement& element)
	{
		QXmppIq::parseElementFromChild (element);

		const auto& queryElem = element.firstChildElement ("query");

		QXmppDataForm form;
		form.parse (queryElem.firstChildElement ("x"));
		if (!form.isNull ())
			for (const auto& field : form.fields ())
				if (field.key () == "with")
					JID_ = field.value ().toString ();

		QXmppResultSetQuery q;
		q.parse (queryElem.firstChildElement ("set"));

		Count_ = q.max ();

		Dir_ = Direction::Unspecified;
		if (!q.after ().isNull ())
		{
			ItemId_ = q.after ().toLatin1 ();
			Dir_ = Direction::After;
		}
		else if (!q.before ().isNull ())
		{
			ItemId_ = q.before ().toLatin1 ();
			Dir_ = Direction::Before;
		}
	}
예제 #3
0
	void Xep0313ReqIq::toXmlElementFromChild (QXmlStreamWriter *writer) const
	{
		QXmppIq::toXmlElementFromChild (writer);

		writer->writeStartElement ("query");
		const auto endGuard = Util::MakeScopeGuard ([writer] { writer->writeEndElement (); });

		writer->writeAttribute ("xmlns", Xep0313Manager::GetNsUri ());

		if (!QueryID_.isEmpty ())
			writer->writeAttribute ("queryid", QueryID_);

		if (JID_.isEmpty () && !Count_ && ItemId_.isEmpty ())
			return;

		if (!JID_.isEmpty ())
		{
			QXmppDataForm::Field formTypeField { QXmppDataForm::Field::HiddenField };
			formTypeField.setKey ("FORM_TYPE");
			formTypeField.setValue (Xep0313Manager::GetNsUri ());

			QXmppDataForm::Field jidField { QXmppDataForm::Field::JidSingleField };
			jidField.setKey ("with");
			jidField.setValue (JID_);

			QXmppDataForm form { QXmppDataForm::Form };
			form.setFields ({ formTypeField, jidField });
			form.toXml (writer);
		}

		if (Count_ > 0 || !ItemId_.isEmpty ())
		{
			QXmppResultSetQuery q;
			if (Count_ > 0)
				q.setMax (Count_);
			if (!ItemId_.isEmpty ())
			{
				switch (Dir_)
				{
				case Direction::After:
					q.setAfter (ItemId_);
					break;
				case Direction::Before:
					q.setBefore (ItemId_);
					break;
				default:
					break;
				}
			}
			q.toXml (writer);
		}
	}
예제 #4
0
파일: util.cpp 프로젝트: AlexWMF/leechcraft
	QXmppElement Form2XmppElem (const QXmppDataForm& form)
	{
		QByteArray formData;
		QXmlStreamWriter w (&formData);
		form.toXml (&w);
		QDomDocument doc;
		doc.setContent (formData);
		return doc.documentElement ();
	}
	bool XMPPCaptchaManager::handleStanza (const QDomElement& stanza)
	{
		if (stanza.tagName () != "message")
			return false;

		const auto& captchaStanza = stanza.firstChildElement ("captcha");

		if (captchaStanza.namespaceURI () != NSCaptcha)
			return false;

		const auto& dataFormStanza = captchaStanza.firstChildElement ("x");
		if (dataFormStanza.isNull ())
			return false;

		QXmppDataForm dataForm;
		dataForm.parse (dataFormStanza);

		if (dataForm.isNull ())
			return false;

		emit captchaFormReceived (stanza.attribute ("from"), dataForm);
		return true;
	}
예제 #6
0
	void RoomHandler::HandleMessage (const QXmppMessage& msg, const QString& nick)
	{
		Q_FOREACH (const QXmppElement& elem, msg.extensions ())
		{
			const QString& xmlns = elem.attribute ("xmlns");
			if (xmlns == ns_data)
			{
				QXmppDataForm *df = new QXmppDataForm ();
				df->parse (XooxUtil::XmppElem2DomElem (elem));
				if (df->isNull ())
				{
					qWarning () << Q_FUNC_INFO
							<< "unable to parse form from"
							<< msg.from ();
					delete df;
				}
				else
					emit gotPendingForm (df, msg.from ());
			}
			else
				qWarning () << Q_FUNC_INFO
						<< "unhandled <x> element"
						<< xmlns;
		}

		const bool existed = Nick2Entry_.contains (nick);
		RoomParticipantEntry_ptr entry = GetParticipantEntry (nick, false);
		if (msg.type () == QXmppMessage::Chat && !nick.isEmpty ())
		{
			if (msg.isAttentionRequested ())
				entry->HandleAttentionMessage (msg);

			if (msg.state ())
				entry->UpdateChatState (msg.state (), QString ());

			if (!msg.body ().isEmpty ())
			{
				GlooxMessage *message = new GlooxMessage (msg,
						Account_->GetClientConnection ().get ());
				entry->HandleMessage (message);
			}
		}
		else
		{
			RoomPublicMessage *message = 0;
			if (msg.type () == QXmppMessage::GroupChat &&
				!msg.subject ().isEmpty ())
			{
				Subject_ = msg.subject ();
				CLEntry_->HandleSubjectChanged (Subject_);

				const QString& string = nick.isEmpty () ?
						msg.subject () :
						tr ("%1 changed subject to %2")
							.arg (nick)
							.arg (msg.subject ());

				message = new RoomPublicMessage (string,
					IMessage::DIn,
					CLEntry_,
					IMessage::MTEventMessage,
					IMessage::MSTOther);
			}
			else if (!nick.isEmpty ())
			{
				if (!msg.body ().isEmpty ())
					message = new RoomPublicMessage (msg, CLEntry_, entry);
			}
			else if (!msg.body ().isEmpty ())
				message = new RoomPublicMessage (msg.body (),
					IMessage::DIn,
					CLEntry_,
					IMessage::MTEventMessage,
					IMessage::MSTOther);

			if (message)
				CLEntry_->HandleMessage (message);

			if (!existed)
				Nick2Entry_.remove (nick);
		}
	}