Esempio n. 1
0
void CLocalSearch::CreatePacket(int nCount)
{
	ASSERT( m_pPacket == NULL );

	if ( m_nProtocol == PROTOCOL_G1 )
		CreatePacketG1( nCount );
	else
		CreatePacketG2();

	if ( m_pSchemas.GetCount() ) GetXMLString();
}
Esempio n. 2
0
void XMLStringToMessageXML(AMChar* pSrc, AMInt32 srcLen, MessageXML* msgXML)
{
	AMInt32 i;
	typedef struct{
		AMChar* pToken;
		AMChar** ppValue;
		AMInt32* pLength;
	}TokenMap;

#ifdef WIN32
	TokenMap map[] = {
		{XML_PARAM_FROMUID  , &msgXML->fromUID   , &msgXML->fromUIDLen    },
		{XML_PARAM_TOUID    , &msgXML->toUID     , &msgXML->toUIDLen      },
		{XML_PARAM_MSG      , &msgXML->msg       , &msgXML->msgLen        },
		{XML_PARAM_PGID     , &msgXML->pgID      , &msgXML->pgIDLen       },
		{XML_PARAM_RESULT   , &msgXML->result    , &msgXML->resultLen     }, 
		{XML_PARAM_DISPNAME , &msgXML->dispName  , &msgXML->dispNameLen   } 
	};
#else
	TokenMap map[] = {
		{XML_PARAM_FROMUID  , 0   , 0    },
		{XML_PARAM_TOUID    , 0   , 0    },
		{XML_PARAM_MSG      , 0   , 0    },
		{XML_PARAM_PGID     , 0   , 0    },
		{XML_PARAM_RESULT   , 0   , 0    }, 
		{XML_PARAM_DISPNAME , 0   , 0    } 
	};
	map[0].ppValue = &msgXML->fromUID;
	map[0].pLength = &msgXML->fromUIDLen;
	map[1].ppValue = &msgXML->toUID;
	map[1].pLength = &msgXML->toUIDLen;
	map[2].ppValue = &msgXML->msg;
	map[2].pLength = &msgXML->msgLen;
	map[3].ppValue = &msgXML->pgID;
	map[3].pLength = &msgXML->pgIDLen;
	map[4].ppValue = &msgXML->result;
	map[4].pLength = &msgXML->resultLen;
	map[5].ppValue = &msgXML->dispName;
	map[5].pLength = &msgXML->dispNameLen;
#endif
	
	for(i=0; i<sizeof(map)/sizeof(map[0]); i++)
		GetXMLString(pSrc, map[i].pToken, strlen(map[i].pToken), map[i].ppValue, map[i].pLength);
}
Esempio n. 3
0
void CLocalSearch::WriteTrailerG1()
{
	m_pPacket->WriteString( SHAREAZA_VENDOR_T, FALSE );

	BYTE nFlags[2] = { 0, 0 };

	nFlags[0] |= G1_QHD_BUSY|G1_QHD_STABLE|G1_QHD_SPEED;
	nFlags[1] |= G1_QHD_PUSH;

	if ( ! Network.IsListening() ) nFlags[0] |= G1_QHD_PUSH;
	if ( Uploads.m_bStable ) nFlags[1] |= G1_QHD_STABLE;
	if ( Uploads.m_bStable ) nFlags[1] |= G1_QHD_SPEED;
	if ( ! UploadQueues.IsTransferAvailable() ) nFlags[1] |= G1_QHD_BUSY;

	if ( Settings.Community.ServeFiles && Settings.Gnutella1.EnableGGEP )
	{
		nFlags[0] |= G1_QHD_GGEP;
		nFlags[1] |= G1_QHD_GGEP;
	}

	CString strXML		= GetXMLString();
	DWORD nCompressed	= 0;
	BYTE* pCompressed	= NULL;

	m_pPacket->WriteByte( strXML.IsEmpty() ? 2 : 4 );
	m_pPacket->WriteByte( nFlags[0] );
	m_pPacket->WriteByte( nFlags[1] );

	LPSTR pszXML = NULL;
	int nXML = 0;

	if ( strXML.GetLength() > 0 )
	{
		nXML = WideCharToMultiByte( CP_ACP, 0, strXML, -1, NULL, 0, NULL, NULL );
		pszXML = new CHAR[ nXML ];
		WideCharToMultiByte( CP_ACP, 0, strXML, -1, pszXML, nXML, NULL, NULL );
		if ( nXML > 0 ) nXML --;

		pCompressed = CZLib::Compress( pszXML, nXML, &nCompressed );

		if ( nCompressed + 9 < (DWORD)nXML + 11 && pCompressed != NULL )
		{
			m_pPacket->WriteShortLE( (WORD)( nCompressed + 9 + 1 ) );
		}
		else
		{
			m_pPacket->WriteShortLE( nXML + 11 + 1 );
			if ( pCompressed != NULL ) delete [] pCompressed;
			pCompressed = NULL;
		}
	}

	m_pPacket->WriteByte( Settings.Community.ChatEnable ? 1 : 0 );

	if ( Settings.Community.ServeFiles && Settings.Gnutella1.EnableGGEP )
	{
		m_pPacket->WriteByte( GGEP_MAGIC );
		m_pPacket->WriteByte( GGEP_HDR_LAST | 2 );
		m_pPacket->WriteByte( 'B' );
		m_pPacket->WriteByte( 'H' );
		m_pPacket->WriteByte( GGEP_LEN_LAST );
	}

	if ( pCompressed != NULL )
	{
		m_pPacket->Write( "{deflate}", 9 );
		m_pPacket->Write( pCompressed, nCompressed );
		m_pPacket->WriteByte( 0 );
		delete [] pCompressed;
	}
	else if ( pszXML != NULL )
	{
		m_pPacket->Write( "{plaintext}", 11 );
		m_pPacket->Write( pszXML, nXML );
	}

	if ( pszXML != NULL ) delete [] pszXML;

	GGUID tmp( MyProfile.GUID );
	m_pPacket->Write( &tmp, sizeof(GGUID) );
}
Esempio n. 4
0
CLocalSearch::~CLocalSearch()
{
	GetXMLString();
}
Esempio n. 5
0
//----------------------------------------------------------------------------------//
bool CTradesCache::ProcessTradeForAnalytics(CTradePtr spTrade){
	if (spTrade.get()){

		long	lStep		= 0;
		IRisks	retRisks;

		try{
			retRisks = spTrade->m_spContract->Calculate(NULL, NULL);
		}
		catch (_com_error& err){
			
			std::ostringstream out_stream;
			out_stream << "Analytical data for trade [";
			out_stream << spTrade->m_nTradeID;
			out_stream<< "] has not been ready at this moment. It will be respocessed one more time by queue.";

			TRACE_COM_ERROR(LOG4CPLUS_WARN,
							VS::Log,
							err,
							std::string(out_stream.str()));

			return false;
		}

		try{

			//format xml to pass to DB
			lStep = 1;
			_bstr_t	bstrXML;
			bstrXML.Attach(GetXMLString(&retRisks, spTrade));

			lStep = 2;
			//save to DB
			InitializeDB();
			CStoredProc<CClientRecordset> rs(GetDBConnection(), L"usp_ContractAnalytics_Save");
			rs << bstrXML;

			lStep = 3;
			rs.Open();
			
			lStep = 4;
			rs.Close();

			return true;
		}
		catch (_com_error& err){
			std::ostringstream out_stream;
			out_stream<<"Exception occured while ProcessTradeForAnalytics().\n\tStep = " << lStep;
			out_stream<<"\n\tTradeID = " << spTrade->m_nTradeID;
			TRACE_COM_ERROR(LOG4CPLUS_ERROR, VS::Log, err, std::string(out_stream.str()));
			return false;
		}
		catch (...){
			std::ostringstream out_stream;
			out_stream<<"Unknown C++ exception occured while ProcessTradeForAnalytics().\n\tStep = " << lStep;
			out_stream<<"\n\tTradeID = " << spTrade->m_nTradeID;
			TRACE_UNKNOWN_ERROR(LOG4CPLUS_ERROR, VS::Log, std::string(out_stream.str()));
			return false;
		}
	}
	return false;
};