Exemple #1
0
bool StartTLSFeature::xmppStanzaIn(IXmppStream *AXmppStream, Stanza &AStanza, int AOrder)
{
	if (AXmppStream==FXmppStream && AOrder==XSHO_XMPP_FEATURE)
	{
		FXmppStream->removeXmppStanzaHandler(XSHO_XMPP_FEATURE,this);
		if (AStanza.tagName() == "proceed")
		{
			if (FXmppStream->connection()->startEncryption())
			{
				LOG_STRM_INFO(FXmppStream->streamJid(),"Starting StartTLS encryption");
				connect(FXmppStream->connection()->instance(),SIGNAL(encrypted()),SLOT(onConnectionEncrypted()));
			}
			else
			{
				LOG_STRM_ERROR(FXmppStream->streamJid(),"Failed to negotiate StartTLS encryption: Handshake not started");
				emit error(XmppError(IERR_STARTTLS_NOT_STARTED));
			}
		}
		else if (AStanza.tagName() == "failure")
		{
			LOG_STRM_WARNING(FXmppStream->streamJid(),"Failed to negotiate StartTLS encryption: Negotiation failed");
			emit error(XmppError(IERR_STARTTLS_NEGOTIATION_FAILED));
		}
		else
		{
			LOG_STRM_WARNING(FXmppStream->streamJid(),"Failed to negotiate StartTLS encryption: Invalid responce");
			emit error(XmppError(IERR_STARTTLS_INVALID_RESPONCE));
		}
		return true;
	}
	return false;
}
Exemple #2
0
bool MultiUserChat::sendMessage(const Message &AMessage, const QString &AToNick)
{
	if (isOpen())
	{
		Jid toJid = FRoomJid;
		toJid.setResource(AToNick);

		Message message = AMessage;
		message.setTo(toJid.full());
		message.setType(AToNick.isEmpty() ? Message::GroupChat : Message::Chat);

		if (FMessageProcessor)
		{
			if (FMessageProcessor->sendMessage(FStreamJid,message,IMessageProcessor::DirectionOut))
				return true;
			else
				LOG_STRM_WARNING(FStreamJid,QString("Failed to send message to conference, room=%1").arg(FRoomJid.bare()));
		}
		else if (FStanzaProcessor)
		{
			if (FStanzaProcessor->sendStanzaOut(FStreamJid, message.stanza()))
			{
				emit messageSent(message);
				return true;
			}
			else
			{
				LOG_STRM_WARNING(FStreamJid,QString("Failed to send message to conference, room=%1").arg(FRoomJid.bare()));
			}
		}
	}
	return false;
}
void Registration::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	XmppStanzaError err = AStanza.type()!="result" ? XmppStanzaError(AStanza) : XmppStanzaError::null;

	if (FSendRequests.contains(AStanza.id()))
	{
		QDomElement queryElem = AStanza.firstElement("query",NS_JABBER_REGISTER);
		IRegisterFields fields = readFields(AStanza.from(),queryElem);
		if (AStanza.type()=="result" || (fields.fieldMask & IRegisterFields::Form)>0)
		{
			LOG_STRM_INFO(AStreamJid,QString("Registration fields loaded, from=%1, id=%2").arg(AStanza.from(),AStanza.id()));
			emit registerFields(AStanza.id(),fields);
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Failed to load registration fields from=%1, id=%2: %3").arg(AStanza.from(),AStanza.id(),err.condition()));
			emit registerError(AStanza.id(),err);
		}
		FSendRequests.removeAll(AStanza.id());
	}
	else if (FSubmitRequests.contains(AStanza.id()))
	{
		if (AStanza.type()=="result")
		{
			LOG_STRM_INFO(AStreamJid,QString("Registration submit accepted, from=%1, id=%2").arg(AStanza.from(),AStanza.id()));
			emit registerSuccess(AStanza.id());
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Registration submit rejected, from=%1, id=%2: %3").arg(AStanza.from(),AStanza.id(),err.condition()));
			emit registerError(AStanza.id(),err);
		}
		FSubmitRequests.removeAll(AStanza.id());
	}
}
void PrivateStorage::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	if (FSaveRequests.contains(AStanza.id()))
	{
		QDomElement dataElem = FSaveRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data saved on server, ns=%1, id=%2").arg(dataElem.namespaceURI(),AStanza.id()));
			notifyDataChanged(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Private data saved in local storage, ns=%1, id=%2: %3").arg(dataElem.namespaceURI(),AStanza.id(),XmppStanzaError(AStanza).condition()));
		}
		saveOptionsElement(AStreamJid,dataElem);
		emit dataSaved(AStanza.id(),AStreamJid,dataElem);
	}
	else if (FLoadRequests.contains(AStanza.id()))
	{
		QDomElement dataElem; 
		QDomElement loadElem = FLoadRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			dataElem = AStanza.firstElement("query",NS_JABBER_PRIVATE).firstChildElement(loadElem.tagName());
			LOG_STRM_INFO(AStreamJid,QString("Private data loaded from server, ns=%1, id=%2").arg(loadElem.namespaceURI(),AStanza.id()));
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Private data loaded from local storage, ns=%1, id=%2: %3").arg(loadElem.namespaceURI(),AStanza.id(),XmppStanzaError(AStanza).condition()));
		}
		if (dataElem.isNull())
			dataElem = loadOptionsElement(AStreamJid,loadElem.tagName(),loadElem.namespaceURI());
		emit dataLoaded(AStanza.id(),AStreamJid,insertElement(AStreamJid,dataElem));
	}
	else if (FRemoveRequests.contains(AStanza.id()))
	{
		QDomElement dataElem = FRemoveRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data removed from server, ns=%1, id=%2").arg(dataElem.namespaceURI(),AStanza.id()));
			notifyDataChanged(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Private data removed from local storage, ns=%1, id=%2: %3").arg(dataElem.namespaceURI(),AStanza.id(),XmppStanzaError(AStanza).condition()));
		}
		removeElement(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		removeOptionsElement(AStreamJid,dataElem.tagName(),dataElem.namespaceURI());
		emit dataRemoved(AStanza.id(),AStreamJid,dataElem);
	}
}
Exemple #5
0
void Roster::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	if (AStanza.id() == FDelimRequestId)
	{
		FDelimRequestId.clear();
		QString groupDelim = ROSTER_GROUP_DELIMITER;
		if (AStanza.type() == "result")
		{
			groupDelim = AStanza.firstElement("query",NS_JABBER_PRIVATE).firstChildElement("roster").text();
			if (groupDelim.isEmpty())
			{
				groupDelim = ROSTER_GROUP_DELIMITER;
				LOG_STRM_INFO(streamJid(),QString("Saving default roster group delimiter on server, delimiter='%1'").arg(groupDelim));

				Stanza delim("iq");
				delim.setType("set").setId(FStanzaProcessor->newId());
				QDomElement elem = delim.addElement("query",NS_JABBER_PRIVATE);
				elem.appendChild(delim.createElement("roster",NS_STORAGE_GROUP_DELIMITER)).appendChild(delim.createTextNode(groupDelim));
				FStanzaProcessor->sendStanzaOut(AStreamJid,delim);
			}
			else
			{
				LOG_STRM_INFO(streamJid(),QString("Roster group delimiter loaded, delimiter='%1'").arg(groupDelim));
			}
		}
		else
		{
			LOG_STRM_WARNING(streamJid(),QString("Failed to load roster group delimiter: %1").arg(XmppStanzaError(AStanza).condition()));
		}
		setGroupDelimiter(groupDelim);
		requestRosterItems();
	}
	else if (AStanza.id() == FOpenRequestId)
	{
		FOpenRequestId.clear();
		if (AStanza.type() == "result")
		{
			LOG_STRM_INFO(streamJid(),"Roster items loaded");
			processItemsElement(AStanza.firstElement("query",NS_JABBER_ROSTER),true);
			FOpened = true;
			emit opened();
		}
		else
		{
			LOG_STRM_WARNING(streamJid(),QString("Failed to load roster items: %1").arg(XmppStanzaError(AStanza).condition()));
			FXmppStream->abort(XmppError(IERR_ROSTER_REQUEST_FAILED));
		}
	}
}
Exemple #6
0
bool MultiUserChat::requestAffiliationList(const QString &AAffiliation)
{
	if (FAffilListRequests.values().contains(AAffiliation))
	{
		return true;
	}
	else if (FStanzaProcessor && isOpen() && AAffiliation!=MUC_AFFIL_NONE)
	{
		Stanza request("iq");
		request.setTo(FRoomJid.bare()).setType("get").setId(FStanzaProcessor->newId());
		QDomElement itemElem = request.addElement("query",NS_MUC_ADMIN).appendChild(request.createElement("item")).toElement();
		itemElem.setAttribute("affiliation",AAffiliation);
		if (FStanzaProcessor->sendStanzaRequest(this,FStreamJid,request,MUC_LIST_TIMEOUT))
		{
			LOG_STRM_INFO(FStreamJid,QString("Affiliation list request sent, room=%1, affiliation=%2, id=%3").arg(FRoomJid.bare(),AAffiliation,request.id()));
			FAffilListRequests.insert(request.id(),AAffiliation);
			return true;
		}
		else
		{
			LOG_STRM_WARNING(FStreamJid,QString("Failed to send affiliation list request, room=%1, affiliation=%2").arg(FRoomJid.bare(),AAffiliation));
			emit chatError(tr("Failed to send request for list of %1s.").arg(AAffiliation));
		}
	}
	return false;
}
bool RegisterStream::start(const QDomElement &AElem)
{
	if (AElem.tagName()=="register")
	{
		if (!xmppStream()->isEncryptionRequired() || xmppStream()->connection()->isEncrypted())
		{
			Stanza request("iq");
			request.setType("get").setId("getReg");
			request.addElement("query",NS_JABBER_REGISTER);
			FXmppStream->insertXmppStanzaHandler(XSHO_XMPP_FEATURE,this);
			FXmppStream->sendStanza(request);

			REPORT_EVENT(SEVP_REGISTRATION_STREAM_BEGIN,1);
			LOG_STRM_INFO(FXmppStream->streamJid(),"Account registration fields request sent");

			return true;
		}
		else
		{
			XmppError err(IERR_XMPPSTREAM_NOT_SECURE);
			LOG_STRM_WARNING(FXmppStream->streamJid(),QString("Failed to register new account on server: %1").arg(err.condition()));
			emit error(err);
		}
	}
	deleteLater();
	return false;
}
Exemple #8
0
bool StartTLSFeature::start(const QDomElement &AElem)
{
	if (AElem.tagName() == "starttls")
	{
		if (FXmppStream->connection()->isEncryptionSupported() && !FXmppStream->connection()->isEncrypted())
		{
			Stanza request("starttls");
			request.setAttribute("xmlns",NS_FEATURE_STARTTLS);
			FXmppStream->insertXmppStanzaHandler(XSHO_XMPP_FEATURE,this);
			FXmppStream->sendStanza(request);
			LOG_STRM_INFO(FXmppStream->streamJid(),"StartTLS negotiation request sent");
			return true;
		}
		else if (!FXmppStream->connection()->isEncryptionSupported())
		{
			LOG_STRM_WARNING(FXmppStream->streamJid(),"Failed to send StartTLS negotiation request: Encryption is not supported");
		}
	}
	else
	{
		LOG_STRM_ERROR(FXmppStream->streamJid(),QString("Failed to send StartTLS negotiation request: Invalid element=%1").arg(AElem.tagName()));
	}
	deleteLater();
	return false;
}
QString PrivateStorage::saveData(const Jid &AStreamJid, const QDomElement &AElement)
{
	if (FStanzaProcessor && isOpen(AStreamJid) && !AElement.tagName().isEmpty() && !AElement.namespaceURI().isEmpty())
	{
		Stanza request(STANZA_KIND_IQ);
		request.setType(STANZA_TYPE_SET).setUniqueId();
		QDomElement elem = request.addElement("query",NS_JABBER_PRIVATE);
		elem.appendChild(AElement.cloneNode(true));
		if (FStanzaProcessor->sendStanzaRequest(this,AStreamJid,request,PRIVATE_STORAGE_TIMEOUT))
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data save request sent, ns=%1, id=%2").arg(AElement.namespaceURI(),request.id()));
			if (FPreClosedStreams.contains(AStreamJid))
				notifyDataChanged(AStreamJid,AElement.tagName(),AElement.namespaceURI());
			FSaveRequests.insert(request.id(),insertElement(AStreamJid,AElement));
			return request.id();
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Failed to send private data save request, ns=%1").arg(AElement.namespaceURI()));
		}
	}
	else if (!isOpen(AStreamJid))
	{
		REPORT_ERROR("Failed to save private data: Storage is not opened");
	}
	else if (AElement.tagName().isEmpty() || AElement.namespaceURI().isEmpty())
	{
		REPORT_ERROR("Failed to save private data: Invalid data");
	}
	return QString::null;
}
bool RosterItemExchange::stanzaReadWrite(int AHandleId, const Jid &AStreamJid, Stanza &AStanza, bool &AAccept)
{
	if (FSHIExchangeRequest==AHandleId && !AStanza.isError())
	{
		QDomElement xElem = AStanza.firstElement("x",NS_ROSTERX);
		if (!xElem.isNull() && !xElem.firstChildElement("item").isNull())
		{
			AAccept = true;

			LOG_STRM_INFO(AStreamJid,QString("Roster exchange request received, from=%1, kind=%2, id=%3").arg(AStanza.from(),AStanza.kind(),AStanza.id()));

			IRosterExchangeRequest request;
			request.streamJid = AStreamJid;
			request.contactJid = AStanza.from();
			request.id = AStanza.kind()==STANZA_KIND_IQ ? AStanza.id() : QString::null;
			request.message = AStanza.kind()==STANZA_KIND_MESSAGE ? Message(AStanza).body() : QString::null;

			QList<Jid> existItems;
			QDomElement itemElem = xElem.firstChildElement("item");

			bool isItemsValid = true;
			while (isItemsValid && !itemElem.isNull())
			{
				IRosterExchangeItem item;
				item.itemJid = Jid(itemElem.attribute("jid")).bare();
				item.name = itemElem.attribute("name");
				item.action = itemElem.attribute("action",ROSTEREXCHANGE_ACTION_ADD);

				QDomElement groupElem = itemElem.firstChildElement("group");
				while(!groupElem.isNull())
				{
					item.groups += groupElem.text();
					groupElem = groupElem.nextSiblingElement("group");
				}

				if (item.itemJid.isValid() && !existItems.contains(item.itemJid) && 
					(item.action==ROSTEREXCHANGE_ACTION_ADD || item.action==ROSTEREXCHANGE_ACTION_DELETE || item.action==ROSTEREXCHANGE_ACTION_MODIFY))
				{
					request.items.append(item);
					existItems.append(item.itemJid);
				}
				else
				{
					isItemsValid = false;
					LOG_STRM_WARNING(AStreamJid,QString("Failed to append roster exchange item, jid=%1, action=%2: Invalid item").arg(item.itemJid.bare(),item.action));
				}

				itemElem = itemElem.nextSiblingElement("item");
			}

			if (isItemsValid && !request.items.isEmpty())
				processRequest(request);
			else
				replyRequestError(request,XmppStanzaError::EC_BAD_REQUEST);

			return true;
		}
	}
	return false;
}
Exemple #11
0
bool MultiUserChat::setNickName(const QString &ANick)
{
	if (!ANick.isEmpty())
	{
		if (isConnected())
		{
			if (FNickName != ANick)
			{
				Jid userJid(FRoomJid.node(),FRoomJid.domain(),ANick);
				Stanza presence("presence");
				presence.setTo(userJid.full());
				if (FStanzaProcessor->sendStanzaOut(FStreamJid,presence))
				{
					LOG_STRM_INFO(FStreamJid,QString("Change conference nick request sent, room=%1, old=%2, new=%3").arg(FRoomJid.bare(),FNickName,ANick));
					return true;
				}
				LOG_STRM_WARNING(FStreamJid,QString("Failed to send change conference nick request, room=%1").arg(FRoomJid.bare()));
			}
		}
		else
		{
			FNickName = ANick;
			return true;
		}
	}
	else
	{
		REPORT_ERROR("Failed to change conference nick: Nick is empty");
	}
	return false;
}
QString PrivateStorage::removeData(const Jid &AStreamJid, const QString &ATagName, const QString &ANamespace)
{
	if (FStanzaProcessor && isOpen(AStreamJid) && !ATagName.isEmpty() && !ANamespace.isEmpty())
	{
		Stanza request(STANZA_KIND_IQ);
		request.setType(STANZA_TYPE_SET).setUniqueId();
		QDomElement elem = request.addElement("query",NS_JABBER_PRIVATE);
		elem = elem.appendChild(request.createElement(ATagName,ANamespace)).toElement();
		if (FStanzaProcessor->sendStanzaRequest(this,AStreamJid,request,PRIVATE_STORAGE_TIMEOUT))
		{
			LOG_STRM_INFO(AStreamJid,QString("Private data remove request sent, ns=%1, id=%2").arg(ANamespace,request.id()));
			QDomElement dataElem = getData(AStreamJid,ATagName,ANamespace);
			if (dataElem.isNull())
				dataElem = insertElement(AStreamJid,elem);
			if (FPreClosedStreams.contains(AStreamJid))
				notifyDataChanged(AStreamJid,ATagName,ANamespace);
			FRemoveRequests.insert(request.id(),dataElem);
			return request.id();
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,QString("Failed to send private data remove request, ns=%1").arg(ANamespace));
		}
	}
	else if (!isOpen(AStreamJid))
	{
		REPORT_ERROR("Failed to remove private data: Storage is not opened");
	}
	else if (ATagName.isEmpty() || ANamespace.isEmpty())
	{
		REPORT_ERROR("Failed to remove private data: Invalid params");
	}
	return QString::null;
}
Exemple #13
0
bool MultiUserChat::setAffiliation(const QString &ANick, const QString &AAffiliation, const QString &AReason)
{
	if (FStanzaProcessor && isOpen())
	{
		IMultiUser *user = userByNick(ANick);
		if (user)
		{
			Stanza request("iq");
			request.setTo(FRoomJid.bare()).setType("set").setId(FStanzaProcessor->newId());
			QDomElement itemElem = request.addElement("query",NS_MUC_ADMIN).appendChild(request.createElement("item")).toElement();
			itemElem.setAttribute("affiliation",AAffiliation);
			itemElem.setAttribute("nick",ANick);
			if (!user->data(MUDR_REAL_JID).toString().isEmpty())
				itemElem.setAttribute("jid",user->data(MUDR_REAL_JID).toString());
			if (!AReason.isEmpty())
				itemElem.appendChild(request.createElement("reason")).appendChild(request.createTextNode(AReason));
			if (FStanzaProcessor->sendStanzaRequest(this,FStreamJid,request,0))
			{
				LOG_STRM_INFO(FStreamJid,QString("User affiliation change request sent, room=%1, user=%2, affiliation=%3").arg(FRoomJid.bare(),ANick,AAffiliation));
				return true;
			}
			else
			{
				LOG_STRM_WARNING(FStreamJid,QString("Failed to send user affiliation change request, room=%1, user=%1, affiliation=%3").arg(FRoomJid.bare(),ANick,AAffiliation));
			}
		}
		else
		{
			LOG_STRM_ERROR(FStreamJid,QString("Failed to change user affiliation, room=%1, user=%2: User not found").arg(FRoomJid.bare(),ANick));
		}
	}
	return false;
}
Exemple #14
0
bool MultiUserChat::inviteContact(const Jid &AContactJid, const QString &AReason)
{
	if (FStanzaProcessor && isOpen())
	{
		Message message;
		message.setTo(FRoomJid.bare());

		Stanza &mstanza = message.stanza();
		QDomElement invElem = mstanza.addElement("x",NS_MUC_USER).appendChild(mstanza.createElement("invite")).toElement();
		invElem.setAttribute("to",AContactJid.full());
		if (!AReason.isEmpty())
			invElem.appendChild(mstanza.createElement("reason")).appendChild(mstanza.createTextNode(AReason));

		if (FStanzaProcessor->sendStanzaOut(FStreamJid, mstanza))
		{
			LOG_STRM_INFO(FStreamJid,QString("Conference invite request sent, room=%1, contact=%2").arg(FRoomJid.bare(),AContactJid.full()));
			return true;
		}
		else
		{
			LOG_STRM_WARNING(FStreamJid,QString("Failed to send conference invite request, room=%1, contact=%2").arg(FRoomJid.bare(),AContactJid.full()));
		}
	}
	return false;
}
Exemple #15
0
bool MultiUserChat::requestVoice()
{
	if (FStanzaProcessor && isOpen() && FMainUser->data(MUDR_ROLE).toString()==MUC_ROLE_VISITOR)
	{
		Message message;
		message.setTo(FRoomJid.bare());

		Stanza &mstanza = message.stanza();
		QDomElement formElem = mstanza.addElement("x",NS_JABBER_DATA);
		formElem.setAttribute("type",DATAFORM_TYPE_SUBMIT);

		QDomElement fieldElem =  formElem.appendChild(mstanza.createElement("field")).toElement();
		fieldElem.setAttribute("var","FORM_TYPE");
		fieldElem.setAttribute("type",DATAFIELD_TYPE_HIDDEN);
		fieldElem.appendChild(mstanza.createElement("value")).appendChild(mstanza.createTextNode(MUC_FT_REQUEST));

		fieldElem = formElem.appendChild(mstanza.createElement("field")).toElement();
		fieldElem.setAttribute("var",MUC_FV_ROLE);
		fieldElem.setAttribute("type",DATAFIELD_TYPE_TEXTSINGLE);
		fieldElem.setAttribute("label","Requested role");
		fieldElem.appendChild(mstanza.createElement("value")).appendChild(mstanza.createTextNode(MUC_ROLE_PARTICIPANT));

		if (FStanzaProcessor->sendStanzaOut(FStreamJid, mstanza))
		{
			LOG_STRM_INFO(FStreamJid,QString("Voice request sent to conference, room=%1").arg(FRoomJid.bare()));
			return true;
		}
		else
		{
			LOG_STRM_WARNING(FStreamJid,QString("Failed to send voice request to conference, room=%1").arg(FRoomJid.bare()));
		}
	}
	return false;
}
Exemple #16
0
bool Annotations::setAnnotation(const Jid &AStreamJid, const Jid &AContactJid, const QString &ANote)
{
	if (isEnabled(AStreamJid))
	{
		if (!ANote.isEmpty())
		{
			Annotation &item = FAnnotations[AStreamJid][AContactJid.bare()];
			item.modified = DateTime(QDateTime::currentDateTime());
			if (!item.created.isValid())
				item.created = item.modified;
			item.note = ANote;
		}
		else
		{
			FAnnotations[AStreamJid].remove(AContactJid.bare());
		}

		updateDataHolder(AStreamJid,QList<Jid>()<<AContactJid);
		emit annotationModified(AStreamJid,AContactJid);

		FSavePendingStreams += AStreamJid;
		FSaveTimer.start();
		return true;
	}
	else
	{
		LOG_STRM_WARNING(AStreamJid,QString("Failed to set annotation to=%1: Annotations is not enabled").arg(AContactJid.bare()));
	}
	return false;
}
Exemple #17
0
void InBandStream::close()
{
	int state = streamState();
	if (state==IDataStreamSocket::Opened || state==IDataStreamSocket::Opening)
	{
		emit aboutToClose();
		if (FStanzaProcessor)
		{
			Stanza closeRequest(STANZA_KIND_IQ);
			closeRequest.setType(STANZA_TYPE_SET).setTo(FContactJid.full()).setUniqueId();
			closeRequest.addElement("close",NS_INBAND_BYTESTREAMS).setAttribute("sid",FStreamId);
			if (FStanzaProcessor->sendStanzaRequest(this,FStreamJid,closeRequest,CLOSE_TIMEOUT))
			{
				LOG_STRM_INFO(FStreamJid,QString("Close stream request sent, sid=%1").arg(FStreamId));
				FCloseRequestId = closeRequest.id();
				setStreamState(IDataStreamSocket::Closing);
			}
			else
			{
				LOG_STRM_WARNING(FStreamJid,QString("Failed to send close stream request, sid=%1").arg(FStreamId));
				setStreamState(IDataStreamSocket::Closed);
			}
		}
		else
		{
			setStreamState(IDataStreamSocket::Closed);
		}
	}
}
Exemple #18
0
bool InBandStream::open(QIODevice::OpenMode AMode)
{
	if (FStanzaProcessor && streamState()==IDataStreamSocket::Closed)
	{
		setStreamError(XmppError::null);
		if (streamKind() == IDataStream::Initiator)
		{
			Stanza openRequest(STANZA_KIND_IQ);
			openRequest.setType(STANZA_TYPE_SET).setTo(FContactJid.full()).setUniqueId();
			QDomElement elem = openRequest.addElement("open",NS_INBAND_BYTESTREAMS);
			elem.setAttribute("sid",FStreamId);
			elem.setAttribute("block-size",FBlockSize);
			elem.setAttribute("stanza",FStanzaType==StanzaMessage ? STANZA_KIND_MESSAGE : STANZA_KIND_IQ);
			if (FStanzaProcessor->sendStanzaRequest(this,FStreamJid,openRequest,OPEN_TIMEOUT))
			{
				LOG_STRM_INFO(FStreamJid,QString("Open stream request sent, sid=%1").arg(FStreamId));
				FOpenRequestId = openRequest.id();
				setOpenMode(AMode);
				setStreamState(IDataStreamSocket::Opening);
				return true;
			}
			else
			{
				LOG_STRM_WARNING(FStreamJid,QString("Failed to send open stream request, sid=%1").arg(FStreamId));
			}
		}
		else
		{
			FSHIOpen = insertStanzaHandle(SHC_INBAND_OPEN);
			if (FSHIOpen != -1)
			{
				LOG_STRM_INFO(FStreamJid,QString("Open stanza handler inserted, sid=%1").arg(FStreamId));
				setOpenMode(AMode);
				setStreamState(IDataStreamSocket::Opening);
				return true;
			}
			else
			{
				LOG_STRM_WARNING(FStreamJid,QString("Failed to insert open stanza handler, sid=%1").arg(FStreamId));
			}
		}
	}
	return false;
}
Exemple #19
0
void InBandStream::abort(const XmppError &AError)
{
	if (streamState() != IDataStreamSocket::Closed)
	{
		LOG_STRM_WARNING(FStreamJid,QString("Aborting stream, sid=%1: %2").arg(FStreamId,AError.errorMessage()));
		setStreamError(AError);
		close();
		setStreamState(IDataStreamSocket::Closed);
	}
}
Exemple #20
0
bool SASLAuthFeature::start(const QDomElement &AElem)
{
	if (AElem.tagName() == "mechanisms")
	{
		if (!xmppStream()->isEncryptionRequired() || xmppStream()->connection()->isEncrypted())
		{
			QStringList mechanisms;
			QDomElement mechElem = AElem.firstChildElement("mechanism");
			while (!mechElem.isNull())
			{
				QString mech = mechElem.text().toUpper();
				if (SupportedMechanisms.contains(mech))
					mechanisms.append(mech);
				mechElem = mechElem.nextSiblingElement("mechanism");
			}

			if (!mechanisms.isEmpty())
			{
				if (!FXmppStream->requestPassword())
					sendAuthRequest(mechanisms);
				else
					FMechanisms = mechanisms;
				return true;
			}
			else
			{
				LOG_STRM_WARNING(FXmppStream->streamJid(),QString("Failed to send authorization request: Supported mechanism not found"));
			}
		}
		else
		{
			XmppError err(IERR_XMPPSTREAM_NOT_SECURE);
			LOG_STRM_WARNING(FXmppStream->streamJid(),QString("Failed to send authorization request: %1").arg(err.condition()));
			emit error(err);
		}
	}
	else
	{
		LOG_STRM_ERROR(FXmppStream->streamJid(),QString("Failed to send authorization request: Invalid element=%1").arg(AElem.tagName()));
	}
	deleteLater();
	return false;
}
Exemple #21
0
void Gateways::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	Q_UNUSED(AStreamJid);
	if (FPromptRequests.contains(AStanza.id()))
	{
		if (AStanza.type() == "result")
		{
			LOG_STRM_DEBUG(AStreamJid,QString("Legacy user prompt received, id=%1").arg(AStanza.id()));
			QString desc = AStanza.firstElement("query",NS_JABBER_GATEWAY).firstChildElement("desc").text();
			QString prompt = AStanza.firstElement("query",NS_JABBER_GATEWAY).firstChildElement("prompt").text();
			emit promptReceived(AStanza.id(),desc,prompt);
		}
		else
		{
			XmppStanzaError err(AStanza);
			LOG_STRM_WARNING(AStreamJid,QString("Failed to receive legacy user prompt, id=%1: %2").arg(AStanza.id(),err.condition()));
			emit errorReceived(AStanza.id(),err);
		}
		FPromptRequests.removeAll(AStanza.id());
	}
	else if (FUserJidRequests.contains(AStanza.id()))
	{
		if (AStanza.type() == "result")
		{
			LOG_STRM_DEBUG(AStreamJid,QString("Legacy user JID received, id=%1").arg(AStanza.id()));
			Jid userJid = AStanza.firstElement("query",NS_JABBER_GATEWAY).firstChildElement("jid").text();
			emit userJidReceived(AStanza.id(),userJid);
		}
		else
		{
			XmppStanzaError err(AStanza);
			LOG_STRM_WARNING(AStreamJid,QString("Failed to receive legacy user JID, id=%1: %2").arg(AStanza.id(),err.condition()));
			emit errorReceived(AStanza.id(),err);
		}
		FUserJidRequests.removeAll(AStanza.id());
	}
}
Exemple #22
0
bool Annotations::saveAnnotations(const Jid &AStreamJid)
{
	if (isEnabled(AStreamJid))
	{
		QDomDocument doc;
		QDomElement storage = doc.appendChild(doc.createElementNS(PSN_ANNOTATIONS,PST_ANNOTATIONS)).toElement();

		const QMap<Jid, Annotation> &items = FAnnotations.value(AStreamJid);
		QMap<Jid, Annotation>::const_iterator it = items.constBegin();
		while (it != items.constEnd())
		{
			QDomElement elem = storage.appendChild(doc.createElement("note")).toElement();
			elem.setAttribute("jid",it.key().bare());
			elem.setAttribute("cdate",it.value().created.toX85UTC());
			elem.setAttribute("mdate",it.value().modified.toX85UTC());
			elem.appendChild(doc.createTextNode(it.value().note));
			++it;
		}

		QString id = FPrivateStorage->saveData(AStreamJid,doc.documentElement());
		if (!id.isEmpty())
		{
			LOG_STRM_INFO(AStreamJid,QString("Save annotations request sent, id=%1").arg(id));
			FSaveRequests.insert(id,AStreamJid);
			return true;
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,"Failed to send save annotations request");
		}
	}
	else
	{
		LOG_STRM_WARNING(AStreamJid,"Failed to save annotations: Annotations is not ready");
	}
	return false;
}
Exemple #23
0
bool XmppUriQueries::openXmppUri(const Jid &AStreamJid, const QUrl &AUrl) const
{
	Jid contactJid;
	QString action;
	QMultiMap<QString, QString> params;
	if (parseXmppUri(AUrl,contactJid,action,params))
	{
		LOG_STRM_INFO(AStreamJid,QString("Opening XMPP URI, url=%1").arg(AUrl.toString()));
		foreach (IXmppUriHandler *handler, FHandlers)
		{
			if (handler->xmppUriOpen(AStreamJid, contactJid, action, params))
				return true;
		}
		LOG_STRM_WARNING(AStreamJid,QString("Failed to open XMPP URI, url=%1").arg(AUrl.toString()));
	}
	return false;
}
Exemple #24
0
bool MultiUserChat::sendSubject(const QString &ASubject)
{
	if (FStanzaProcessor && isOpen())
	{
		Message message;
		message.setTo(FRoomJid.bare()).setType(Message::GroupChat).setSubject(ASubject);
		if (FStanzaProcessor->sendStanzaOut(FStreamJid,message.stanza()))
		{
			LOG_STRM_INFO(FStreamJid,QString("Conference subject change message sent, room=%1").arg(FRoomJid.bare()));
			return true;
		}
		else
		{
			LOG_STRM_WARNING(FStreamJid,QString("Failed to send conference subject change message, room=%1").arg(FRoomJid.bare()));
		}
	}
	return false;
}
Exemple #25
0
bool Annotations::loadAnnotations(const Jid &AStreamJid)
{
	if (FPrivateStorage)
	{
		QString id = FPrivateStorage->loadData(AStreamJid,PST_ANNOTATIONS,PSN_ANNOTATIONS);
		if (!id.isEmpty())
		{
			LOG_STRM_INFO(AStreamJid,QString("Annotations load request sent, id=%1").arg(id));
			FLoadRequests.insert(id,AStreamJid);
			return true;
		}
		else
		{
			LOG_STRM_WARNING(AStreamJid,"Failed to send load annotations request");
		}
	}
	return false;
}
void RosterItemExchange::stanzaRequestResult(const Jid &AStreamJid, const Stanza &AStanza)
{
	Q_UNUSED(AStreamJid);
	if (FSentRequests.contains(AStanza.id()))
	{
		IRosterExchangeRequest request = FSentRequests.take(AStanza.id());
		if (AStanza.isResult())
		{
			LOG_STRM_INFO(AStreamJid,QString("Roster exchange request accepted by=%1, id=%2").arg(AStanza.from(),AStanza.id()));
			emit exchangeRequestApproved(request);
		}
		else
		{
			XmppStanzaError err(AStanza);
			LOG_STRM_WARNING(AStreamJid,QString("Roster exchange request rejected by=%1, id=%2: %3").arg(AStanza.from(),AStanza.id(),err.condition()));
			emit exchangeRequestFailed(request,err);
		}
	}
}
bool SASLSessionFeature::start(const QDomElement &AElem)
{
	if (AElem.tagName() == "session")
	{
		Stanza session(STANZA_KIND_IQ);
		session.setType(STANZA_TYPE_SET).setId("session");
		session.addElement("session",NS_FEATURE_SESSION);
		FXmppStream->insertXmppStanzaHandler(XSHO_XMPP_FEATURE,this);
		FXmppStream->sendStanza(session);
		LOG_STRM_INFO(FXmppStream->streamJid(),"Session start request sent");
		return true;
	}
	else
	{
		LOG_STRM_WARNING(FXmppStream->streamJid(),QString("Failed to start session: Invalid element=%1").arg(AElem.tagName()));
	}
	deleteLater();
	return false;
}
void RegisterStream::onRegisterDialogAccepred()
{
	FXmppStream->setKeepAliveTimerActive(true);
	if (FDialog)
	{
		Stanza submit("iq");
		submit.setType("set").setId("setReg");
		QDomElement query = submit.addElement("query",NS_JABBER_REGISTER);
		FDataForms->xmlForm(FDataForms->dataSubmit(FDialog->formWidget()->userDataForm()),query);
		FXmppStream->sendStanza(submit);

		LOG_STRM_INFO(FXmppStream->streamJid(),"Account registration submit request sent");
	}
	else
	{
		LOG_STRM_WARNING(FXmppStream->streamJid(),"Account registration form dialog destroyed");
		emit error(XmppError(IERR_REGISTER_INVALID_DIALOG));
	}
	FDialog = NULL;
}
void PrivateStorage::notifyDataChanged(const Jid &AStreamJid, const QString &ATagName, const QString &ANamespace)
{
	IPresence *presence = FPresenceManager!=NULL ? FPresenceManager->findPresence(AStreamJid) : NULL;
	if (FStanzaProcessor && presence && presence->isOpen())
	{
		foreach(const IPresenceItem &item, presence->findItems(AStreamJid))
		{
			if (item.itemJid != AStreamJid)
			{
				Stanza notify(STANZA_KIND_MESSAGE);
				notify.setTo(item.itemJid.full());
				QDomElement xElem = notify.addElement("x",NS_VACUUM_PRIVATESTORAGE_UPDATE);
				xElem.appendChild(notify.createElement(ATagName,ANamespace));
				if (FStanzaProcessor->sendStanzaOut(AStreamJid,notify))
					LOG_STRM_DEBUG(AStreamJid,QString("Private data updated notify sent, to=%1, ns=%2").arg(item.itemJid.full(),ANamespace));
				else
					LOG_STRM_WARNING(AStreamJid,QString("Failed to send private data updated notify, to=%1, ns=%2").arg(item.itemJid.full(),ANamespace));
			}
		}
	}
Exemple #30
0
QString JabberSearch::sendRequest(const Jid &AStreamJid, const Jid &AServiceJid)
{
    if (FStanzaProcessor)
    {
        Stanza request("iq");
        request.setTo(AServiceJid.full()).setType("get").setId(FStanzaProcessor->newId());
        request.addElement("query",NS_JABBER_SEARCH);
        if (FStanzaProcessor->sendStanzaRequest(this,AStreamJid,request,SEARCH_TIMEOUT))
        {
            LOG_STRM_INFO(AStreamJid,QString("Search request sent to=%1, id=%2").arg(AServiceJid.full(),request.id()));
            FRequests.append(request.id());
            return request.id();
        }
        else
        {
            LOG_STRM_WARNING(AStreamJid,QString("Failed to send search request to=%1").arg(AServiceJid.full()));
        }
    }
    return QString::null;
}