bool CServerBrowser::SaveServerList ( CXMLNode* pNode, std::string strTagName, CServerList *pList ) { if ( !pNode ) return false; // Start by clearing out all previous nodes pNode->DeleteAllSubNodes (); // Iterate through the list, adding any items to our node CServerListIterator i, i_b = pList->IteratorBegin (), i_e = pList->IteratorEnd (); int j = 0; int k = pList->GetServerCount (); if ( k > 0 ) { for ( CServerListIterator i = i_b; i != i_e; i++ ) { CServerListItem * pServer = *i; // Add the item to the node CXMLNode * pSubNode = pNode->CreateSubNode ( strTagName.c_str () ); if ( pSubNode ) { CXMLAttribute* pHostAttribute = pSubNode->GetAttributes ().Create ( "host" ); pHostAttribute->SetValue ( pServer->strHost.c_str () ); CXMLAttribute* pPortAttribute = pSubNode->GetAttributes ().Create ( "port" ); pPortAttribute->SetValue ( pServer->usGamePort ); } j++; } } return true; }
void CServerBrowser::SetServerPassword ( std::string strHost, std::string strPassword ) { CXMLNode* pConfig = CCore::GetSingletonPtr ()->GetConfig (); CXMLNode* pServerPasswords = pConfig->FindSubNode ( CONFIG_NODE_SERVER_SAVED ); if ( !pServerPasswords ) { pServerPasswords = pConfig ->CreateSubNode ( CONFIG_NODE_SERVER_SAVED ); } //Check if the server password already exists for ( unsigned int i = 0 ; i < pServerPasswords->GetSubNodeCount() ; i++ ) { CXMLAttributes* pAttributes = &(pServerPasswords->GetSubNode(i)->GetAttributes()); if ( pAttributes->Find( "host" ) ) { if ( CXMLAttribute* pHost = pAttributes->Find ( "host" ) ) { std::string strXMLHost = pHost->GetValue(); if ( strXMLHost == strHost ) { CXMLAttribute* pPassword = pAttributes->Create( "password" ); pPassword->SetValue(strPassword.c_str()); return; } } } } // Otherwise create the node from scratch CXMLNode* pNode = pServerPasswords->CreateSubNode( "server" ); CXMLAttribute* pHostAttribute = pNode->GetAttributes().Create ( "host" ); pHostAttribute->SetValue(strHost.c_str()); CXMLAttribute* pPasswordAttribute = pNode->GetAttributes().Create ( "password" ); pPasswordAttribute->SetValue(strPassword.c_str()); }
CXMLNode * CCustomData::OutputToXML ( CXMLNode * pNode ) { std::map < std::string, SCustomData > :: const_iterator iter = m_Data.begin (); for ( ; iter != m_Data.end (); iter++ ) { CLuaArgument* arg = (CLuaArgument *)&iter->second.Variable; switch ( arg->GetType() ) { case LUA_TSTRING: { CXMLAttribute* attr = pNode->GetAttributes().Create( iter->first.c_str () ); attr->SetValue ( arg->GetString ().c_str () ); break; } case LUA_TNUMBER: { CXMLAttribute* attr = pNode->GetAttributes().Create( iter->first.c_str () ); attr->SetValue ( (float)arg->GetNumber () ); break; } case LUA_TBOOLEAN: { CXMLAttribute* attr = pNode->GetAttributes().Create( iter->first.c_str () ); attr->SetValue ( arg->GetBoolean () ); break; } } } return pNode; }
void CAccessControlListGroup::WriteToXMLNode ( CXMLNode* pNode ) { assert ( pNode ); // Create the subnode for this CXMLNode* pSubNode = pNode->CreateSubNode ( "group" ); assert ( pSubNode ); // Create attribute for the name and set it CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Create ( "name" ); pAttribute->SetValue ( m_strGroupName ); // Write the ACL's this group use ACLsList::iterator iterACL = m_ACLs.begin (); for ( ; iterACL != m_ACLs.end (); iterACL++ ) { CAccessControlList* pACL = *iterACL; // Create the subnode for this object and write the name attribute we generated CXMLNode* pObjectNode = pSubNode->CreateSubNode ( "acl" ); pAttribute = pObjectNode->GetAttributes ().Create ( "name" ); pAttribute->SetValue ( pACL->GetName () ); } // Write every object ObjectList::iterator iter = m_Objects.begin (); for ( ; iter != m_Objects.end (); iter++ ) { CAccessControlListGroupObject* pObject = *iter; // Find out the object type string char szObjectType [255]; switch ( pObject->GetObjectType () ) { case CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE: strcpy ( szObjectType, "resource" ); break; case CAccessControlListGroupObject::OBJECT_TYPE_USER: strcpy ( szObjectType, "user" ); break; default: strcpy ( szObjectType, "error" ); break; } // Append a dot append the name of the node strcat ( szObjectType, "." ); strncat ( szObjectType, pObject->GetObjectName (), NUMELMS( szObjectType ) - 1 ); // Create the subnode for this object and write the name attribute we generated CXMLNode* pObjectNode = pSubNode->CreateSubNode ( "object" ); pAttribute = pObjectNode->GetAttributes ().Create ( "name" ); pAttribute->SetValue ( szObjectType ); } }
CXMLAttribute* CXMLElement::AddAttribute(LPCTSTR pszName, LPCTSTR pszValue) { ASSERT( pszName && *pszName ); CXMLAttribute* pAttribute = GetAttribute( pszName ); if ( ! pAttribute ) { pAttribute = new CXMLAttribute( this, pszName ); if ( ! pAttribute ) return NULL; CString strNameLower( pszName ); strNameLower.MakeLower(); // Delete the old attribute if one exists CXMLAttribute* pExisting; if ( m_pAttributes.Lookup( strNameLower, pExisting ) ) delete pExisting; m_pAttributes.SetAt( strNameLower, pAttribute ); if ( ! m_pAttributesInsertion.Find( strNameLower ) ) m_pAttributesInsertion.AddTail( strNameLower ); // Track output order workaround } if ( pszValue ) pAttribute->SetValue( pszValue ); return pAttribute; }
/////////////////////////////////////////////////////////////// // // CResourceChecker::CheckMetaSourceForIssues // // // /////////////////////////////////////////////////////////////// void CResourceChecker::CheckMetaSourceForIssues ( CXMLNode* pRootNode, const string& strFileName, const string& strResourceName, ECheckerModeType checkerMode, bool* pbOutHasChanged ) { // Check min_mta_version is correct if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml || m_strReqServerVersion > m_strMinServerReqFromMetaXml ) { // It's not right. What to do? if ( checkerMode == ECheckerMode::WARNINGS ) { SString strTemp = "<min_mta_version> section in the meta.xml is incorrect or missing (expected at least "; if ( m_strReqClientVersion > m_strMinClientReqFromMetaXml ) strTemp += SString ( "client %s because of '%s')", *m_strReqClientVersion, *m_strReqClientReason ); else if ( m_strReqServerVersion > m_strMinServerReqFromMetaXml ) strTemp += SString ( "server %s because of '%s')", *m_strReqServerVersion, *m_strReqServerReason ); CLogger::LogPrint ( SString ( "WARNING: %s %s\n", strResourceName.c_str (), *strTemp ) ); } else if ( checkerMode == ECheckerMode::UPGRADE ) { // Create min_mta_version node if required CXMLNode* pNodeMinMtaVersion = pRootNode->FindSubNode("min_mta_version", 0); if ( !pNodeMinMtaVersion ) pNodeMinMtaVersion = pRootNode->CreateSubNode ( "min_mta_version" ); CXMLAttributes& attributes = pNodeMinMtaVersion->GetAttributes (); attributes.Delete ( "server" ); attributes.Delete ( "client" ); attributes.Delete ( "both" ); if ( !m_strReqServerVersion.empty () ) { CXMLAttribute* pAttr = attributes.Create ( "server" ); pAttr->SetValue ( m_strReqServerVersion ); } if ( !m_strReqClientVersion.empty () ) { CXMLAttribute* pAttr = attributes.Create ( "client" ); pAttr->SetValue ( m_strReqClientVersion ); } if ( pbOutHasChanged ) *pbOutHasChanged = true; } } }
int CLuaXMLDefs::xmlNodeSetAttribute ( lua_State* luaVM ) { // pNode, Attribute Name, Value int iType1 = lua_type ( luaVM, 1 ); int iType2 = lua_type ( luaVM, 2 ); int iType3 = lua_type ( luaVM, 3 ); if ( ( iType1 == LUA_TLIGHTUSERDATA ) && ( iType2 == LUA_TSTRING ) && ( iType3 == LUA_TSTRING || iType3 == LUA_TNUMBER || iType3 == LUA_TNIL ) ) { // Grab the xml node CXMLNode* pNode = lua_toxmlnode ( luaVM, 1 ); if ( pNode ) { // Grab the attribute name and value const char * szAttributeName = lua_tostring ( luaVM, 2 ); // Are we going to set it to a value? if ( iType3 == LUA_TSTRING || iType3 == LUA_TNUMBER ) { const char * szAttributeValue = lua_tostring ( luaVM, 3 ); // Write the node CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( szAttributeName ); if ( pAttribute ) { pAttribute->SetValue ( szAttributeValue ); lua_pushboolean ( luaVM, true ); return 1; } } else { // Delete the attribute if it exists CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( szAttributeName ); if ( pAttribute ) { delete pAttribute; lua_pushboolean ( luaVM, true ); return 1; } } } } else { m_pScriptDebugging->LogBadType ( luaVM, "xmlNodeSetAttribute" ); lua_pushboolean ( luaVM, false ); return 1; } lua_pushboolean ( luaVM, false ); return 1; }
BOOL CXMLElement::Merge(const CXMLElement* pInput, BOOL bOverwrite) { if ( ! this || ! pInput ) return FALSE; if ( this == pInput ) return TRUE; TRACE( "Merging XML: %s\n", (LPCSTR)CT2A( ToString( FALSE, FALSE ) ) ); TRACE( " and XML: %s\n", (LPCSTR)CT2A( pInput->ToString( FALSE, FALSE ) ) ); if ( m_sName.CompareNoCase( pInput->m_sName ) != 0 ) { TRACE( "Failed to merge XML due different schemes \"%s\" and \"%s\".\n", (LPCSTR)CT2A( m_sName ), (LPCSTR)CT2A( pInput->m_sName ) ); return FALSE; } BOOL bChanged = FALSE; for ( POSITION pos = pInput->GetElementIterator(); pos; ) { const CXMLElement* pElement = pInput->GetNextElement( pos ); CXMLElement* pTarget = GetElementByName( pElement->m_sName ); if ( pTarget == NULL ) { AddElement( pElement->Clone() ); bChanged = TRUE; } else if ( pTarget->Merge( pElement, bOverwrite ) ) { bChanged = TRUE; } } for ( POSITION pos = pInput->GetAttributeIterator(); pos; ) { CXMLAttribute* pAttribute = pInput->GetNextAttribute( pos ); CXMLAttribute* pTarget = GetAttribute( pAttribute->m_sName ); if ( pTarget == NULL ) { AddAttribute( pAttribute->Clone() ); bChanged = TRUE; } else if ( bOverwrite && ! pTarget->Equals( pAttribute ) ) { pTarget->SetValue( pAttribute->GetValue() ); bChanged = TRUE; } } if ( bChanged ) TRACE( "resulting XML: %s\n", (LPCSTR)CT2A( ToString( FALSE, FALSE ) ) ); else TRACE( "resulting XML unchanged.\n" ); return bChanged; }
void CBanManager::SafeSetValue ( CXMLNode* pNode, const char* szKey, unsigned int uiValue ) { if ( uiValue ) { CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( szKey ); if ( pAttribute ) { pAttribute->SetValue ( uiValue ); } } }
void CBanManager::SafeSetValue ( CXMLNode* pNode, const char* szKey, std::string strValue ) { if ( !strValue.empty() ) { CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( szKey ); if ( pAttribute ) { pAttribute->SetValue ( strValue.c_str () ); } } }
BOOL CNetworkMonitorBox::ProcessXML(POSITION posNext) { CXMLElement* pXML = Profiles.FindProcess( NULL, posNext ); if ( pXML == NULL ) return FALSE; CSingleLock pLock( &Network.m_pSection, TRUE ); CString strValue = pXML->GetAttributeValue( "Host" ); if ( CChannel* pChannel = Network.FindChannel( strValue ) ) { if ( pChannel->m_hSocket == INVALID_SOCKET && pChannel->TimeOut( 60 * 1000 ) ) { CXMLAttribute* pAttri = pXML->GetAttribute( "Retry" ); if ( ! pAttri ) pAttri = pXML->AddAttribute( "Retry" ); if ( _ttoi( pAttri->GetValue() ) >= 2 ) { AlarmToShortMessage( (LPCTSTR)strValue ); strValue = pXML->GetAttributeValue( _T("Path") ); RestartMachine( (LPCTSTR)strValue ); pXML->DeleteAttribute( "Retry" ); } else { strValue.Format( "%i", _ttoi( pAttri->GetValue() ) + 1 ); pAttri->SetValue( (LPCTSTR)strValue ); pChannel->LinkRestart(); pChannel->m_tConnected = GetTickCount(); } } else if ( pChannel->IsConnected() ) { pXML->DeleteAttribute( "Retry" ); } } else { CChannel* pChannel = new CSentryChannel( pXML ); Network.SetChannel( pChannel ); pChannel->LinkRestart(); } if ( posNext ) return ProcessXML( posNext ); return TRUE; }
void CHisReport::Register(int nInk) { DWORD nValue; CString strValue; CXMLAttribute* pAttri; CXMLElement* pXML = FindToday( TRUE ); pAttri = pXML->GetAttribute( "Total" ); if ( ! pAttri ) pAttri = pXML->AddAttribute( "Total" ); strValue = pAttri->GetValue(); nValue = _ttol( strValue ); strValue.Format( _T("%lu"), nValue + nInk ); pAttri->SetValue( strValue ); pAttri = m_pXML->GetAttribute( "Total" ); if ( ! pAttri ) pAttri = m_pXML->AddAttribute( "Total" ); strValue = pAttri->GetValue(); nValue = _ttol( strValue ); strValue.Format( _T("%lu"), nValue + nInk ); pAttri->SetValue( strValue ); }
int CLuaFunctionDefs::XMLNodeSetAttribute ( lua_State* luaVM ) { // pNode, Attribute Name, Value CXMLNode* pNode = NULL; SString strAttributeName = ""; SString strAttributeValue = ""; CScriptArgReader argStream ( luaVM ); argStream.ReadUserData ( pNode ); argStream.ReadString ( strAttributeName ); argStream.ReadString ( strAttributeValue, "" ); if ( !argStream.HasErrors ( ) ) { if ( pNode ) { // Are we going to set it to a value? if ( argStream.NextCouldBeString( -1 ) ) { // Write the node CXMLAttribute* pAttribute = pNode->GetAttributes ().Create ( strAttributeName ); if ( pAttribute ) { pAttribute->SetValue ( strAttributeValue ); lua_pushboolean ( luaVM, true ); return 1; } } else { // Delete the attribute if it exists CXMLAttribute* pAttribute = pNode->GetAttributes ().Find ( strAttributeName ); if ( pAttribute ) { delete pAttribute; lua_pushboolean ( luaVM, true ); return 1; } } } } else m_pScriptDebugging->LogCustom ( luaVM, argStream.GetFullErrorMessage() ); lua_pushboolean ( luaVM, false ); return 1; }
void CAccessControlList::WriteToXMLNode ( CXMLNode* pNode ) { assert ( pNode ); // Create the subnode for this CXMLNode* pSubNode = pNode->CreateSubNode ( "acl" ); assert ( pSubNode ); // Create attribute for the name and set it CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Create ( "name" ); pAttribute->SetValue ( m_strACLName ); // Loop through each right and write it to the ACL list < CAccessControlListRight* > ::iterator iter = m_Rights.begin (); for ( ; iter != m_Rights.end (); iter++ ) { CAccessControlListRight* pRight = *iter; pRight->WriteToXMLNode ( pSubNode ); } }
CXMLAttribute* CXMLAttributesImpl::Create(const CXMLAttribute& Copy) { CXMLAttribute* pTemp = Create(Copy.GetName().c_str()); pTemp->SetValue(Copy.GetValue().c_str()); return pTemp; }
/////////////////////////////////////////////////////////////// // // CJoystickManager::SaveToXML // // Save axes mapping for the current joypad. // /////////////////////////////////////////////////////////////// bool CJoystickManager::SaveToXML ( void ) { if ( !IsJoypadValid () ) return false; m_SettingsRevision++; CXMLNode* pMainNode = GetConfigNode ( true ); // Add the current settings if ( pMainNode ) { // Clear our current bind nodes pMainNode->DeleteAllSubNodes (); { // Create a new 'info' node CXMLNode* pNode = pMainNode->CreateSubNode ( "info" ); // If it was created if ( pNode ) { CXMLAttributes* pAttributes = &pNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "deadzone" ); pA->SetValue ( m_DevInfo.iDeadZone ); pA = pAttributes->Create ( "saturation" ); pA->SetValue ( m_DevInfo.iSaturation ); pA = pAttributes->Create ( "product_name" ); pA->SetValue ( m_DevInfo.strProductName.c_str () ); } } // Iterate the binds adding them to the XML tree for ( int i = 0 ; i < NUMELMS(m_currentMapping) ; i++ ) { const SMappingLine& line = m_currentMapping[i]; // Create the new 'axis' node CXMLNode* pNode = pMainNode->CreateSubNode ( "axis" ); // If it was created if ( pNode ) { CXMLAttributes* pAttributes = &pNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "source_index" ); pA->SetValue ( line.SourceAxisIndex ); pA = pAttributes->Create ( "source_dir" ); pA->SetValue ( line.SourceAxisDir ); pA = pAttributes->Create ( "output_index" ); pA->SetValue ( line.OutputAxisIndex ); pA = pAttributes->Create ( "output_dir" ); pA->SetValue ( line.OutputAxisDir ); pA = pAttributes->Create ( "enabled" ); pA->SetValue ( line.bEnabled ); pA = pAttributes->Create ( "max_value" ); pA->SetValue ( line.MaxValue ); } } return true; } return false; }
/////////////////////////////////////////////////////////////// // // CJoystickManager::GetConfigNode // // Get the main node for load/saving data for the current joypad. // /////////////////////////////////////////////////////////////// CXMLNode* CJoystickManager::GetConfigNode ( bool bCreateIfRequired ) { // Get the root node CXMLNode *pRoot = CCore::GetSingleton ().GetConfig (); if ( !pRoot ) return NULL; // Get the top joypad config node CXMLNode* pSectionNode = pRoot->FindSubNode ( CONFIG_NODE_JOYPAD ); if ( !pSectionNode ) { if ( !bCreateIfRequired ) return NULL; // Non-existant, create a new node pSectionNode = pRoot->CreateSubNode ( CONFIG_NODE_JOYPAD ); } // Get the node for this joystick's GUID CXMLNode* pItemNode = NULL; // Find existing node for( int i=0; true; i++ ) { CXMLNode* pNode = pSectionNode->FindSubNode ( "product", i ); if ( !pNode ) break; CXMLAttributes* pAttributes = &pNode->GetAttributes (); if ( CXMLAttribute* pA = pAttributes->Find ( "guid" ) ) { string value = pA->GetValue (); if ( value == m_DevInfo.strGuid ) { pItemNode = pNode; break; } } } if ( !pItemNode ) { if ( !bCreateIfRequired ) return NULL; // Non-existant, create a new node pItemNode = pSectionNode->CreateSubNode ( "product" ); if ( pItemNode ) { CXMLAttributes* pAttributes = &pItemNode->GetAttributes (); CXMLAttribute* pA = NULL; pA = pAttributes->Create ( "guid" ); pA->SetValue ( m_DevInfo.strGuid.c_str () ); } } return pItemNode; }
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; }