Example #1
0
BOOL CUserChannel::OnSyncHostshaking(CXMLElement* pXML)
{
	CSingleLock pLock( &Network.m_pSection, TRUE );
	
	CXMLElement* pSync = pXML->GetElementByName( "RemoteId" );
	CString xRemoteId = pSync->GetValue();
	
	pSync = pXML->GetElementByName( "CallerId" );
	Network.JoinTalk( xRemoteId, pSync->GetValue() );
	
	return TRUE;
}
Example #2
0
BOOL CCollectionFile::File::Parse(CXMLElement* pRoot)
{
	//if ( ! pRoot->IsNamed( L"file" ) ) return FALSE;	// Discards DC++

	for ( POSITION pos = pRoot->GetElementIterator(); pos; )
	{
		CXMLElement* pXML = pRoot->GetNextElement( pos );

		if ( pXML->IsNamed( L"id" ) )
		{
			if ( ! m_oSHA1 )  m_oSHA1.fromUrn( pXML->GetValue() );
			if ( ! m_oTiger ) m_oTiger.fromUrn( pXML->GetValue() );
			if ( ! m_oED2K )  m_oED2K.fromUrn( pXML->GetValue() );
			if ( ! m_oMD5 )   m_oMD5.fromUrn( pXML->GetValue() );
			if ( ! m_oBTH )   m_oBTH.fromUrn( pXML->GetValue() );
			if ( ! m_oBTH )   m_oBTH.fromUrn< Hashes::base16Encoding >( pXML->GetValue() );
		}
		else if ( pXML->IsNamed( L"description" ) )
		{
			if ( CXMLElement* pName = pXML->GetElementByName( L"name" ) )
				m_sName = pName->GetValue();

			if ( CXMLElement* pSize = pXML->GetElementByName( L"size" ) )
			{
				if ( _stscanf( pSize->GetValue(), L"%I64i", &m_nSize ) != 1 )
					return FALSE;
			}
		}
		else if ( pXML->IsNamed( L"metadata" ) )
		{
			if ( m_pMetadata ) delete m_pMetadata;
			m_pMetadata = CCollectionFile::CloneMetadata( pXML );
		}
		//else if ( pXML->IsNamed( L"packaged" ) )
		//{
		//	if ( CXMLElement* pSource = pXML->GetElementByName( L"source" ) )
		//		/*m_sSource =*/ pSource->GetValue();	// ToDo: Use Sources?
		//}
	}

	// DC++ format
	if ( m_sName.IsEmpty() && ! m_oTiger && m_nSize == SIZE_UNKNOWN )
	{
		m_sName = pRoot->GetAttributeValue( L"Name" );
		_stscanf( pRoot->GetAttributeValue( L"Size" ), L"%I64i", &m_nSize );
		m_oTiger.fromString( pRoot->GetAttributeValue( L"TTH" ) );
	}

	return HasHash();
}
Example #3
0
BOOL CMonitorWnd::ParseMatch(CXMLElement* pXML, CDatagrams* pParent)
{
	SOCKADDR_IN pHost;
	ZeroMemory( &pHost, sizeof(pHost) );
	
	CXMLElement* pSync = pXML->GetElementByName( "IP" );
	pHost.sin_addr.S_un.S_addr = inet_addr(  pSync->GetValue() );
	
	pSync = pXML->GetElementByName( "Port" );
	pHost.sin_port	= htons( _ttoi( pSync->GetValue() ) );
	pHost.sin_family= PF_INET;
	
	CString strValue = pXML->GetAttributeValue( "ID" );
	return pParent->JoinedMirror( _ttoi(strValue), &pHost );
}
BOOL CSchemaMember::LoadDescriptor(CXMLElement* pXML)
{
	CString strSearch = pXML->GetAttributeValue( _T("search") );
	
	if ( strSearch.CompareNoCase( _T("generic") ) == 0 )
	{
		m_bIndexed	= TRUE;
		m_bSearched	= TRUE;
	}
	else if ( strSearch.CompareNoCase( _T("indexed") ) == 0 )
	{
		m_bIndexed = TRUE;
	}
	
	CString strTitle = m_sTitle;
	m_sTitle.Empty();
	
	for ( POSITION pos = pXML->GetElementIterator() ; pos ; )
	{
		CXMLElement* pElement = pXML->GetNextElement( pos );
		
		if ( pElement->IsNamed( _T("display") ) )
		{
			LoadDisplay( pElement );
		}
		else if ( pElement->IsNamed( _T("title") ) )
		{
			if ( pElement->GetAttributeValue( _T("language") ).
				 CompareNoCase( Settings.General.Language ) == 0 )
			{
				m_sTitle = pElement->GetValue();
			}
			else if ( m_sTitle.IsEmpty() )
			{
				m_sTitle = pElement->GetValue();
			}
		}
		else if ( pElement->IsNamed( _T("link") ) )
		{
			m_sLinkURI	= pElement->GetAttributeValue( _T("location") );
			m_sLinkName	= pElement->GetAttributeValue( _T("remote") );
		}
	}
	
	if ( m_sTitle.IsEmpty() ) m_sTitle = strTitle;
	
	return TRUE;
}
Example #5
0
void CPlayerWnd::LoadXML(CXMLElement* pXML)
{
	ASSERT( pXML->IsNamed( _T("XlivePlayer") ) );
	
	for ( POSITION pos = pXML->GetElementIterator() ; pos ; )
	{
		CXMLElement* pMap = pXML->GetNextElement( pos );
		if ( ! pMap->IsNamed( _T("Cookie") ) ) continue;
		
		int nItem = m_wndHistory.AddString( pMap->GetValue() );
		if ( nItem >= MAX_ITEM ) break;
	}
	
	m_wndHistory.SetCurSel( 0 );
}
CString CBitziDownloader::LookupValue(LPCTSTR pszPath)
{
	CString strName, strPath( pszPath );
	CXMLElement* pXML = m_pXML;
	BOOL bFirst = TRUE;

	while ( strPath.GetLength() )
	{
		strName = strPath.SpanExcluding( _T("/") );
		strPath = strPath.Mid( strName.GetLength() );

		if ( strPath.IsEmpty() )
		{
			return pXML->GetAttributeValue( strName, NULL );
		}

		if ( bFirst )
		{
			bFirst = FALSE;
			if ( strName.CompareNoCase( pXML->GetName() ) ) pXML = NULL;
		}
		else
		{
			pXML = pXML->GetElementByName( strName );
		}

		if ( ! pXML )
		{
			strName.Empty();
			return strName;
		}

		strPath = strPath.Mid( 1 );
	}

	strName.Empty();
	if ( pXML ) strName = pXML->GetValue();

	return strName;
}
Example #7
0
BOOL CProfileProfilePage::OnInitDialog()
{
	CSettingsPage::OnInitDialog();

	m_pWorld = new CWorldGPS();
	m_pWorld->Load();

	CWorldCountry* pCountry = m_pWorld->m_pCountry;

	for ( int nCountry = m_pWorld->m_nCountry ; nCountry ; nCountry--, pCountry++ )
	{
		m_wndCountry.SetItemData( m_wndCountry.AddString( pCountry->m_sName ), (LPARAM)pCountry );
	}

	if ( CXMLElement* pLocation = MyProfile.GetXML( _T("location") ) )
	{
		if ( CXMLElement* pPolitical = pLocation->GetElementByName( _T("political") ) )
		{
			m_sLocCountry	= pPolitical->GetAttributeValue( _T("country") );
			m_sLocCity		= pPolitical->GetAttributeValue( _T("city") );
			CString str		= pPolitical->GetAttributeValue( _T("state") );
			if ( str.GetLength() && m_sLocCity.GetLength() )
				m_sLocCity += _T(", ");
            m_sLocCity += str;
		}

		if ( CXMLElement* pCoordinates = pLocation->GetElementByName( _T("coordinates") ) )
		{
			CString str = pCoordinates->GetAttributeValue( _T("latitude") );
			float nValue;

			if ( _stscanf( str, _T("%f"), &nValue ) == 1 )
			{
				m_sLocLatitude.Format( nValue >= 0 ?
					_T("%.2f\xb0 N") : _T("%.2f\xb0 S"), double( fabs( nValue ) ) );
			}

			str = pCoordinates->GetAttributeValue( _T("longitude") );

			if ( _stscanf( str, _T("%f"), &nValue ) == 1 )
			{
				m_sLocLongitude.Format( nValue >= 0 ? _T("%.1f\xb0 E") : _T("%.1f\xb0 W"),
					double( fabs( nValue ) ) );
			}
		}
	}

	if ( CXMLElement* pInterests = MyProfile.GetXML( _T("interests") ) )
	{
		for ( POSITION pos = pInterests->GetElementIterator() ; pos ; )
		{
			CXMLElement* pInterest = pInterests->GetNextElement( pos );

			if ( pInterest->IsNamed( _T("interest") ) )
			{
				m_wndInterestList.AddString( pInterest->GetValue() );
			}
		}
	}

	UpdateData( FALSE );

	m_wndInterestAdd.EnableWindow( FALSE );
	m_wndInterestRemove.EnableWindow( FALSE );

	OnSelChangeCountry();
	RecalcDropWidth( &m_wndCountry );

	return TRUE;
}
BOOL CRichDocument::LoadXML(CXMLElement* pBase, CMapStringToPtr* pMap, int nGroup)
{
	CSingleLock pLock( &m_pSection, TRUE );
	
	if ( pBase == NULL ) return FALSE;
	
	CString strTemp;
	
	if ( pBase->IsNamed( _T("document") ) )
	{
		strTemp = pBase->GetAttributeValue( _T("fontFace") );
		if ( strTemp.GetLength() ) CreateFonts( strTemp );
		
		LoadXMLColour( pBase, _T("crBackground"), &m_crBackground );
		LoadXMLColour( pBase, _T("crText"), &m_crText );
		LoadXMLColour( pBase, _T("crLink"), &m_crLink );
		LoadXMLColour( pBase, _T("crHover"), &m_crHover );
		LoadXMLColour( pBase, _T("crHeading"), &m_crHeading );
		
		strTemp = pBase->GetAttributeValue( _T("leftMargin") );
		if ( strTemp.GetLength() ) _stscanf( strTemp, _T("%i"), &m_szMargin.cx );
		strTemp = pBase->GetAttributeValue( _T("topMargin") );
		if ( strTemp.GetLength() ) _stscanf( strTemp, _T("%i"), &m_szMargin.cy );
	}
	
	for ( POSITION pos = pBase->GetElementIterator() ; pos ; )
	{
		CXMLElement* pXML		= pBase->GetNextElement( pos );
		CRichElement* pElement	= NULL;
		
		if ( pXML->IsNamed( _T("text") ) )
		{
			pElement = new CRichElement( retText );
		}
		else if ( pXML->IsNamed( _T("link") ) )
		{
			pElement = new CRichElement( retLink );
		}
		else if ( pXML->IsNamed( _T("heading") ) )
		{
			pElement = new CRichElement( retHeading );
		}
		else if ( pXML->IsNamed( _T("newline") ) )
		{
			pElement = new CRichElement( retNewline );
			
			strTemp = pXML->GetAttributeValue( _T("gap") );
			
			if ( strTemp.GetLength() )
			{
				pElement->m_sText = strTemp;
				strTemp = pXML->GetAttributeValue( _T("indent") );
				if ( strTemp.GetLength() ) pElement->m_sText += '.' + strTemp;
			}
			else
			{
				strTemp = pXML->GetAttributeValue( _T("indent") );
				if ( strTemp.GetLength() ) pElement->m_sText = _T("0.") + strTemp;
			}
		}
		else if ( pXML->IsNamed( _T("gap") ) )
		{
			pElement = new CRichElement( retGap );
			
			strTemp = pXML->GetAttributeValue( _T("size") );
			if ( strTemp ) pElement->m_sText = strTemp;
		}
		else if ( pXML->IsNamed( _T("bitmap") ) )
		{
			pElement = new CRichElement( retBitmap );
		}
		else if ( pXML->IsNamed( _T("icon") ) )
		{
			pElement = new CRichElement( retIcon );
		}
		else if ( pXML->IsNamed( _T("anchor") ) )
		{
			pElement = new CRichElement( retAnchor );
		}
		else if ( pXML->IsNamed( _T("para") ) )
		{
			Add( pElement = new CRichElement( retAlign,
				pXML->GetAttributeValue( _T("align") ) ) );
			
			if ( pXML->GetElementCount() )
			{
				if ( ! LoadXML( pXML, pMap, nGroup ) ) return FALSE;
				if ( pElement->m_sText.CompareNoCase( _T("left") ) )
				{
					Add( new CRichElement( retAlign, _T("left") ) );
				}
			}
			
			continue;
		}
		else if ( pXML->IsNamed( _T("group") ) )
		{
			int nSubGroup = 0;
			if ( _stscanf( pXML->GetAttributeValue( _T("id") ), _T("%i"), &nSubGroup ) != 1 )
				return FALSE;
			if ( ! LoadXML( pXML, pMap, nSubGroup ) ) return FALSE;
			continue;
		}
		else if ( pXML->IsNamed( _T("styles") ) )
		{
			if ( ! LoadXMLStyles( pXML ) ) return FALSE;
		}
		else
		{
			return FALSE;
		}
		
		if ( pElement == NULL ) continue;
		
		strTemp = pXML->GetValue();
		if ( strTemp.GetLength() ) pElement->m_sText = strTemp;
		
		pElement->m_nGroup = nGroup;
		strTemp = pXML->GetAttributeValue( _T("group") );
		if ( strTemp.GetLength() ) _stscanf( strTemp, _T("%i"), &pElement->m_nGroup );
		
		strTemp = pXML->GetAttributeValue( _T("format") );
		CharLower( strTemp.GetBuffer() );
		strTemp.ReleaseBuffer();
		if ( strTemp.Find( 'b' ) >= 0 )	pElement->m_nFlags |= retfBold;
		if ( strTemp.Find( 'i' ) >= 0 )	pElement->m_nFlags |= retfItalic;
		if ( strTemp.Find( 'u' ) >= 0 )	pElement->m_nFlags |= retfUnderline;
		
		strTemp = pXML->GetAttributeValue( _T("align") );
		CharLower( strTemp.GetBuffer() );
		strTemp.ReleaseBuffer(); 
		if ( strTemp == _T("middle") ) pElement->m_nFlags |= retfMiddle;
		
		strTemp = pXML->GetAttributeValue( _T("colour") );
		if ( strTemp.GetLength() == 6 )
		{
			pElement->m_nFlags |= retfColour;
			LoadXMLColour( pXML, _T("colour"), &pElement->m_cColour );
		}
		
		if ( pElement->m_nType == retIcon )
		{
			strTemp = pXML->GetAttributeValue( _T("command") );
			if ( strTemp.GetLength() )
			{
				pElement->m_nType = retCmdIcon;
				pElement->m_sText = strTemp;
			}
		}
		
		if ( pElement->m_nType == retIcon || pElement->m_nType == retBitmap || pElement->m_nType == retAnchor )
		{
			strTemp = pXML->GetAttributeValue( _T("res") );
			if ( strTemp.GetLength() ) pElement->m_sText = strTemp;
			strTemp = pXML->GetAttributeValue( _T("path") );
			if ( strTemp.GetLength() ) pElement->m_sText = strTemp;
			
			strTemp = pXML->GetAttributeValue( _T("width") );
			if ( strTemp.GetLength() )
			{
				if ( pElement->m_sText.GetLength() ) pElement->m_sText += '.';
				pElement->m_sText += strTemp;
				strTemp = pXML->GetAttributeValue( _T("height") );
				if ( strTemp.GetLength() ) pElement->m_sText += '.' + strTemp;
			}
		}
		
		pElement->m_sLink = pXML->GetAttributeValue( _T("target") );
		
		if ( pMap )
		{
			strTemp = pXML->GetAttributeValue( _T("id") );
			if ( strTemp.GetLength() ) pMap->SetAt( strTemp, pElement );
		}
		
		Add( pElement );
	}
	
	return TRUE;
}
BOOL CShareMonkeyData::ImportData(CXMLElement* pRoot)
{
	if ( pRoot == NULL )
		return FALSE;

	if ( m_nRequestType == stProductMatch )
	{
		if ( m_pSchema == NULL )	// Get the schema from the product Category
		{
			CXMLElement* pCategory = pRoot->GetElementByName( L"CategoryID" );
			int nCategory = 0;
			CString strCategory = pCategory->GetValue();
			if ( pCategory && strCategory.GetLength() && _stscanf( strCategory, L"%i", &nCategory ) == 1 )
			{
				switch ( nCategory )
				{
				case 1:
					m_pSchema = SchemaCache.Get( CSchema::uriAudio );
					break;
				case 2:
					m_pSchema = SchemaCache.Get( CSchema::uriBook );		// For documents
					break;
				case 3:
					m_pSchema = SchemaCache.Get( CSchema::uriArchive );		// For games
					break;
				case 4:
					m_pSchema = SchemaCache.Get( CSchema::uriApplication );	// For software
					break;
				case 5:
					m_pSchema = SchemaCache.Get( CSchema::uriVideo );
					break;
				//default:
				//	break;
				}
			}
		}

		if ( m_pSchema == NULL )
			return FALSE;

		m_pRazaXML = m_pSchema->Instantiate( TRUE );

		CXMLElement* pXML = m_pRazaXML->AddElement( m_pSchema->m_sSingular );
		Setup( m_pSchema, TRUE );

		for ( POSITION pos = pRoot->GetElementIterator() ; pos ; )
		{
			CXMLElement* pElement = pRoot->GetNextElement( pos );
			if ( pElement->IsNamed( L"ProductName" ) )
				m_sProductName = pElement->GetValue();
			else if ( pElement->IsNamed( L"ProductID" ) )
				m_sProductID = pElement->GetValue();
			else if ( pElement->IsNamed( L"ProductDescription" ) )
				m_sDescription = pElement->GetValue();
			else if ( pElement->IsNamed( L"ProductURLs" ) )
			{
				CXMLElement* pBuyURL = pElement->GetElementByName( L"ProductBuyURL" );
				if ( pBuyURL )
					m_sBuyURL = pBuyURL->GetValue();
			}
			else if ( pElement->IsNamed( L"ProductImages" ) )
			{
				CXMLElement* pImage = pElement->GetElementByName( L"LargeImage" );
				if ( pImage == NULL )
					pImage = pElement->GetElementByName( L"MediumImage" );
				if ( pImage == NULL )
					pImage = pElement->GetElementByName( L"SmallImage" );
				if ( pImage )
				{
					if ( CXMLElement* pImageURL = pImage->GetElementByName( L"ImageURL" ) )
						m_sThumbnailURL = pImageURL->GetValue();
				}
			}
		}

		CXMLAttribute* pAttribute = new CXMLAttribute( NULL, L"title" );
		pAttribute->SetValue( m_sProductName );
		pXML->AddAttribute( pAttribute );

		pAttribute = new CXMLAttribute( NULL, L"description" );
		pAttribute->SetValue( m_sDescription );
		pXML->AddAttribute( pAttribute );

		//if ( ! m_sBuyURL.IsEmpty() )
		//{
		//	pAttribute = new CXMLAttribute( NULL, L"distributerLink" );
		//	pAttribute->SetValue( m_sBuyURL );
		//	pXML->AddAttribute( pAttribute );
		//}

		Combine( pXML );

		delete m_pRazaXML;
		m_pRazaXML = NULL;
	}
	else if ( m_nRequestType == stStoreMatch )
	{
		CXMLElement* pStore = pRoot->GetElementByName( L"StoreName" );
		if ( pStore == NULL )
			return FALSE;
		CString strName = pStore->GetValue();
		if ( strName.IsEmpty() )
			return FALSE;

		CXMLElement* pPrice = pRoot->GetElementByName( L"Price" );
		if ( pPrice == NULL )
			return FALSE;

		CXMLElement* pValue = pPrice->GetElementByName( L"PriceFormatted" );
		if ( pValue == NULL )
			return FALSE;

		CString strValue = pValue->GetValue();
		if ( strValue.IsEmpty() )
			return FALSE;

		CXMLElement* pLink = pRoot->GetElementByName( L"StoreURL" );
		if ( pLink )
		{
			CString strLink;
			strLink.Format( L"%s|%s", (LPCTSTR)pLink->GetValue(), (LPCTSTR)strValue );

			while ( Find( strName ) )
				strName += '\x00A0';

			CMetaItem* pItem = Add( strName, strLink );
			pItem->m_bValueDefined = TRUE;
		}
	}

	return TRUE;
}
BOOL CShareMonkeyData::DecodeResponse(CString& strMessage)
{
	if ( m_pXML && m_nRequestType == stProductMatch )
		Clear();

	m_pXML = CXMLElement::FromString( m_sResponse, TRUE );
	if ( m_pXML == NULL )
	{
		strMessage = L"Invalid XML";
		return FALSE;
	}

	bool bFailed = false;
	BOOL bResult = FALSE;
	CString strStatus, strWarnings;

	for ( POSITION pos = m_pXML->GetElementIterator() ; pos ; )
	{
		CXMLElement* pElement = m_pXML->GetNextElement( pos );
		if ( pElement->IsNamed( L"Version" ) )
		{
			CString strVersion = pElement->GetValue();
			float nVersion = 0;
			if ( _stscanf( strVersion, L"%f", &nVersion ) != 1 || nVersion > 1.5f )
			{
				strMessage = L"Failed: Version mismatch.";
				Clear();
				return FALSE;
			}
		}
		else if ( pElement->IsNamed( L"Status" ) )
		{
			strStatus = pElement->GetValue();
			if ( strStatus.CompareNoCase( L"success" ) != NULL )
			{
				if ( m_nRequestType != stComparison )
					bFailed = true;
			}
		}
		else if ( pElement->IsNamed( L"ShareMonkeyComparisonURL" ) )
		{
			m_sComparisonURL = pElement->GetValue();
			if ( m_sComparisonURL.IsEmpty() && m_nRequestType == stComparison )
			{
				strMessage = L"Failed: No URL is available.";
				Clear();
				return FALSE;
			}

			int curPos = 0, currToken = 0;
			CString strToken;
			while ( curPos != -1 )
			{
				strToken = m_sComparisonURL.Tokenize( L"/", curPos );
				if ( ++currToken == 3 )
				{
					m_sSessionID = strToken;
					break;
				}
			}
		}
		else if ( pElement->IsNamed( L"Count" ) && m_nRequestType != stComparison )
		{
			if ( pElement->GetValue() == L"0" )
				bFailed = true;
		}
		else if ( pElement->IsNamed( L"Message" ) )
		{
			strWarnings = pElement->GetValue();
		}
		else if ( pElement->IsNamed( L"Product" ) && m_nRequestType == stProductMatch )
		{
			bResult = ImportData( pElement );
		}
		else if ( pElement->IsNamed( L"Store" ) && m_nRequestType == stStoreMatch )
		{
			bResult = ImportData( pElement ) || bResult;
		}
	}

	strMessage = strStatus + L". " + strWarnings;
	Clear();

	if ( bFailed )
		return FALSE;
	if ( m_nRequestType == stComparison )
		return TRUE;

	return bResult;
}