Пример #1
0
void CG2Node::OnQuery(G2Packet *pPacket)
{
	// just read guid for now to have it in routing table

	QUuid oGUID;
	if( pPacket->m_bCompound )
		pPacket->SkipCompound();

	if( pPacket->GetRemaining() >= 16 )
	{
		oGUID = pPacket->ReadGUID();
		Network.m_oRoutingTable.Add(oGUID, this, false);

		if( m_nType == G2_LEAF ) // temporary
		{
			G2Packet* pQA = G2Packet::New("QA", true);
			quint32 tNow = time(0);
			pQA->WritePacket("TS", 4)->WriteIntLE(tNow);
			pQA->WritePacket("D", 8)->WriteHostAddress(&Network.m_oAddress);
			pQA->WriteIntLE(Network.m_nLeavesConnected);

			quint32 nCount = 0;

			for( uint i = 0; i < HostCache.size() && nCount < 100u; i++, nCount++ )
			{
				pQA->WritePacket("S", 6)->WriteHostAddress(&HostCache.m_lHosts[i]->m_oAddress);
			}

			pQA->WriteByte(0);
			pQA->WriteGUID(oGUID);
			//qDebug() << "Sending query ACK " << pQA->ToHex() << pQA->ToASCII();
			SendPacket(pQA, true, true);
		}
	}
}
Пример #2
0
void CChatSessionG2::OnUPROD(G2Packet *pPacket)
{
	qDebug() << "OnUPROD";

	if( !pPacket->m_bCompound )
		return;

	QUuid oGUID;
	bool hasXML = false;

	char szType[9];
	quint32 nLength = 0, nNext = 0;

	while(pPacket->ReadPacket(&szType[0], nLength))
	{
		nNext = pPacket->m_nPosition + nLength;

		if(strcmp("XML", szType) == 0)
		{
			// Temporary code, needs to be moved to GProfile class
			QXmlStreamReader oXML;
			bool hasGprofile = false;
			bool hasGUID = false;
			bool hasIdentity = false;
			bool hasNick = false;
			oXML.addData(pPacket->ReadString(nLength));

			while(!oXML.atEnd() && !oXML.hasError())
			{
				QXmlStreamReader::TokenType token = oXML.readNext();

				if( token == QXmlStreamReader::StartDocument)
				{
					continue;
				}
				else if( token == QXmlStreamReader::StartElement )
				{
					if( oXML.name() == "gprofile" )
					{
						/*
						if( oXML.attributes().value("xmlns") != "http://www.shareaza.com/schemas/GProfile.xsd" )
							return;*/
						hasGprofile = true;
						continue;
					}
					else if( hasGprofile && oXML.name() == "gnutella" )
					{
						if( oXML.attributes().hasAttribute("guid") )
						{
							QString sTemp = oXML.attributes().value("guid").toString();
							QUuid oTemp(sTemp);
							oGUID = oTemp;
							hasGUID = true;
							continue;
						}
					}
					else if( hasGprofile && oXML.name() == "identity" )
					{
						hasIdentity = true;
						continue;
					}
					else if( hasGprofile && hasIdentity && oXML.name() == "handle" )
					{
						if( oXML.attributes().hasAttribute("primary") )
						{
							m_sNick = oXML.attributes().value("primary").toString();
							hasNick = true;
							continue;
						}
					}
				}
			}

			if( !hasNick || !hasGUID )
				return;

			hasXML = true;
		}

		pPacket->m_nPosition = nNext;
	}

	if( !hasXML )
		return;

	m_oGUID = oGUID;
	emit guidChanged(oGUID);
	emit nickChanged(m_sNick);

	if( m_bInitiated ) // TODO PUSH handling
	{
		G2Packet* pReq = G2Packet::New("CHATREQ", true);
		pReq->WritePacket("USERGUID", 16);
		pReq->WriteGUID(m_oGUID);

		SendPacket(pReq);
	}
}