void CElement::ReadCustomData ( CLuaMain* pLuaMain, CEvents* pEvents ) { assert ( pLuaMain ); assert ( pEvents ); // Got an XML node? if ( m_pXMLNode ) { // Iterate the attributes of our XML node CXMLAttributes* pAttributes = &(m_pXMLNode->GetAttributes ()); unsigned int uiAttributeCount = pAttributes->Count (); for ( unsigned int uiIndex = 0; uiIndex < uiAttributeCount; uiIndex++ ) { // Grab the node (we can assume it exists here) CXMLAttribute* pAttribute = pAttributes->Get ( uiIndex ); // Make a lua argument from it and set the content CLuaArguments args; if ( !args.ReadFromJSONString ( pAttribute->GetValue ().c_str() ) ) args.PushString ( pAttribute->GetValue ().c_str () ); // Don't trigger onElementDataChanged event SetCustomData ( pAttribute->GetName ().c_str (), *args[0], pLuaMain, g_pGame->GetConfig ()->GetSyncMapElementData (), NULL, false ); } } }
////////////////////////////////////////////////////////////////////// // // Fetch multiple values for a named setting from the server config // // <module src="module_test.dll" /> // <resource src="admin" startup="1" protected="0" /> // ////////////////////////////////////////////////////////////////////// bool CMainConfig::GetSettingTable ( const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable ) { uint uiXMLIndex = 0; uint uiLuaIndex = 1; CXMLNode* pNode = NULL; do { // Grab the current script node pNode = m_pRootNode->FindSubNode ( strName, uiXMLIndex++ ); if ( pNode ) { CLuaArguments resultLine; CXMLAttributes& attributes = pNode->GetAttributes(); for ( uint i = 0 ; i < attributes.Count() ; i++ ) { CXMLAttribute* pAttribute = attributes.Get( i ); resultLine.PushString( pAttribute->GetName() ); resultLine.PushString( pAttribute->GetValue() ); } if ( resultLine.Count() != 0 ) { outTable->PushNumber( uiLuaIndex++ ); outTable->PushTable( &resultLine ); } } } while( pNode ); return outTable->Count() != 0; }
void CGroupingDlg::FormatUpdate(CXMLElement* pXML, CString& str) { for ( POSITION pos = pXML->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttri = pXML->GetNextAttribute( pos ); if ( ! str.IsEmpty() ) str += _T(", "); BOOL bNumber = IsNumField( pAttri->GetName() ); str += pAttri->GetName(); str += '='; if ( ! bNumber ) str += '\''; str += pAttri->GetValue(); if ( ! bNumber ) str += '\''; } }
void CXMLElement::AddRecursiveWords(CString& strWords) const { for ( POSITION pos = GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = GetNextAttribute( pos ); CString strText = pAttribute->GetName(); if ( strText.Find( ':' ) >= 0 ) continue; if ( strText.CompareNoCase( _T("SHA1") ) == 0 ) continue; // NOTE: PeerProject/Shareaza Specific if ( ! strWords.IsEmpty() ) strWords += ' '; strWords += pAttribute->GetValue(); } for ( POSITION pos = GetElementIterator() ; pos ; ) { GetNextElement( pos )->AddRecursiveWords( strWords ); } if ( ! m_sValue.IsEmpty() ) { if ( ! strWords.IsEmpty() ) strWords += ' '; strWords += m_sValue; } }
BOOL CBitziDownloader::MergeMetaData(CXMLElement* pOutput, CXMLElement* pInput) { if ( ! pOutput || ! pInput ) return FALSE; pOutput = pOutput->GetFirstElement(); if ( ! pOutput || pOutput->GetName() != pInput->GetName() ) return FALSE; for ( POSITION pos = pInput->GetElementIterator() ; pos ; ) { CXMLElement* pElement = pInput->GetNextElement( pos ); CXMLElement* pTarget = pOutput->GetElementByName( pElement->GetName() ); if ( pTarget == NULL ) pOutput->AddElement( pElement->Clone() ); } for ( POSITION pos = pInput->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = pInput->GetNextAttribute( pos ); CXMLAttribute* pTarget = pOutput->GetAttribute( pAttribute->GetName() ); if ( pTarget == NULL ) pOutput->AddAttribute( pAttribute->Clone() ); } return TRUE; }
void CGroupingDlg::FormatMapping(CXMLElement* pXML, CString& str) { static LPCTSTR pszNum[] = { _T("xgroupnum"), _T("xgrouprow") }; static LPCTSTR pszExclude[] = { _T("xgroupname"), NULL }; for ( POSITION pos = pXML->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttri = pXML->GetNextAttribute( pos ); if ( IsNotField( pAttri->GetName() ) ) continue; if ( ! str.IsEmpty() ) str += _T(" and "); BOOL bNumber = IsNumField( pAttri->GetName() ); str += pAttri->GetName(); str += '='; if ( ! bNumber ) str += '\''; str += pAttri->GetValue(); if ( ! bNumber ) str += '\''; } }
// MDW-2013-07-09: [[ RevXmlXPath ]] int CXMLElement::AttributeCount(char *attributename) { if (!isinited()) return 0; CXMLAttribute tattribute; int attributecount = 0; if (GetFirstAttribute(&tattribute)){ do { if (!attributename || util_strnicmp(tattribute.GetName(),attributename,strlen(attributename)) == 0) attributecount++; } while (tattribute.GoNext()); } return attributecount; }
CRelatedSearch::CRelatedSearch(CMatchFile* pFile) { if ( pFile != NULL ) { m_bSHA1 = pFile->m_bSHA1; m_pSHA1 = pFile->m_pSHA1; m_bTiger = pFile->m_bTiger; m_pTiger = pFile->m_pTiger; m_bED2K = pFile->m_bED2K; m_pED2K = pFile->m_pED2K; m_sName = pFile->m_pBest->m_sName; m_pSchema = SchemaCache.Get( pFile->m_pBest->m_sSchemaURI ); m_pXML = NULL; m_bXML = FALSE; if ( m_pSchema != NULL ) { m_pXML = new CXMLElement( NULL, m_pSchema->m_sSingular ); m_bXML = TRUE; for ( CQueryHit* pHit = pFile->m_pHits ; pHit ; pHit = pHit->m_pNext ) { if ( pHit->m_pXML != NULL ) { for ( POSITION pos = pHit->m_pXML->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pAttribute = pHit->m_pXML->GetNextAttribute( pos ); m_pXML->AddAttribute( pAttribute->GetName(), pAttribute->GetValue() ); } } } } } else { m_bSHA1 = m_bTiger = m_bED2K = m_bXML = FALSE; m_pSchema = NULL; m_pXML = NULL; } }
CXMLElement* CXMLElement::Prefix(const CString& sPrefix, CXMLElement* pParent) const { CXMLElement* pCloned = Clone( pParent ); if ( pCloned ) { pCloned->SetName( sPrefix + pCloned->GetName() ); for ( POSITION pos = pCloned->GetElementIterator() ; pos ; ) { CXMLElement* pNode = pCloned->GetNextElement( pos ); pNode->SetName( sPrefix + pNode->GetName() ); } for ( POSITION pos = pCloned->GetAttributeIterator() ; pos ; ) { CXMLAttribute* pNode = pCloned->GetNextAttribute( pos ); pNode->SetName( sPrefix + pNode->GetName() ); } } return pCloned; }
void DumpXMLElement( const CXMLElement * pElement ) { if( pElement != NULL ) { ::wprintf( L"Element Name: %s\n", pElement->GetName() ); ::wprintf( L"Text: %s\n", pElement->GetText() ); CXMLElement::ATTR_CONST_ITER pos = pElement->GetAttrBegin(); CXMLElement::ATTR_CONST_ITER end = pElement->GetAttrEnd(); for( ; pos != end; ++pos ) { CXMLAttribute * pAttr = *pos; if( pAttr != NULL ) { ::wprintf( L"<%s = %s>\n", pAttr->GetName(), pAttr->GetValue() ); } } ::wprintf( L"\n" ); } }
/*GetAttribute - returns value of specified attribute attname - name of attribute to look for isbuffered - if true returns copy of attribute value (must be freed by caller). returns NULL if specified attribute not found */ char *CXMLElement::GetAttributeValue(char *attname, Bool isbuffered) { if (!isinited()) return NULL; // OK-2009-01-05: [[Bug 7586]] - Some elements may have a "namespace". This is not regarded by libXML // as one of the elements' attributes, but is stored separately. If the required attribute is called // "xmlns", then we retreive the namespace instead of using GetAttributeValue. if (strcasecmp(attname, "xmlns") == 0) { xmlNs *t_namespace; t_namespace = NULL; GetNamespace(t_namespace); if (t_namespace != NULL && t_namespace -> href != NULL) { return strdup((char *)t_namespace -> href); } } if (isbuffered) { CXMLAttribute tattribute; if (GetFirstAttribute(&tattribute)) { int attributecount = 1; do { if (!attname || util_strnicmp(tattribute.GetName(), attname, strlen(attname)) == 0) return tattribute.GetContent(); } while (tattribute.GoNext()); } } else return (char *)xmlGetProp(element, (xmlChar *)attname); return NULL; }
bool CAccessControlListManager::Load ( void ) { // Eventually destroy the previously loaded xml if ( m_pXML ) { delete m_pXML; } // Load the XML m_pXML = g_pServerInterface->GetXML ()->CreateXML ( GetFileName ().c_str () ); if ( !m_pXML ) { CLogger::ErrorPrintf ( "Error loading Access Control List file\n" ); return false; } // Parse it if ( !m_pXML->Parse () ) { CLogger::ErrorPrintf ( "Error parsing Access Control List file\n" ); return false; } // Grab the XML root node m_pRootNode = m_pXML->GetRootNode (); if ( !m_pRootNode ) { CLogger::ErrorPrintf ( "Missing root node ('ACL')\n" ); return false; } // Clear previous ACL stuff ClearACLs (); ClearGroups (); // load the acl's CXMLNode* pSubNode = NULL; unsigned int uiSubNodesCount = m_pRootNode->GetSubNodeCount (); for ( unsigned int i = 0 ; i < uiSubNodesCount ; i++ ) { pSubNode = m_pRootNode->GetSubNode ( i ); if ( !pSubNode ) continue; if ( pSubNode->GetTagName ().compare ( "acl" ) == 0 ) { CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Find ( "name" ); if ( pAttribute ) { CAccessControlList* pACL = AddACL ( pAttribute->GetValue ().c_str () ); CXMLNode* pSubSubNode = NULL; unsigned int uiSubSubNodesCount = pSubNode->GetSubNodeCount (); for ( unsigned int j = 0 ; j < uiSubSubNodesCount ; j++ ) { // If this subnode doesn't exist, return to the for loop and continue it pSubSubNode = pSubNode->GetSubNode ( j ); if ( !pSubSubNode ) continue; // Check that this subsub node is named "right" if ( pSubSubNode->GetTagName ().compare ( "right" ) == 0 ) { // Grab the name and the access attributes CXMLAttribute* pNameAttribute = pSubSubNode->GetAttributes ().Find ( "name" ); CXMLAttribute* pAccessAttribute = pSubSubNode->GetAttributes ().Find ( "access" ); if ( pNameAttribute && pAccessAttribute ) { // See if the access attribute is true or false bool bAccess = false; std::string strAccess = pAccessAttribute->GetValue (); if ( stricmp ( strAccess.c_str (), "true" ) == 0 || stricmp ( strAccess.c_str (), "yes" ) == 0 || strcmp ( strAccess.c_str (), "1" ) == 0 ) { bAccess = true; } // Grab the name of the 'right' name const char *szRightName = pNameAttribute->GetValue ().c_str (); // Create the rights control list CAccessControlListRight* pRight = NULL; if ( StringBeginsWith ( szRightName, "command." ) ) { pRight = pACL->AddRight ( &szRightName[8], CAccessControlListRight::RIGHT_TYPE_COMMAND, bAccess ); } else if ( StringBeginsWith ( szRightName, "function." ) ) { pRight = pACL->AddRight ( &szRightName[9], CAccessControlListRight::RIGHT_TYPE_FUNCTION, bAccess ); } else if ( StringBeginsWith ( szRightName, "resource." ) ) { pRight = pACL->AddRight ( &szRightName[9], CAccessControlListRight::RIGHT_TYPE_RESOURCE, bAccess ); } else if ( StringBeginsWith ( szRightName, "general." ) ) { pRight = pACL->AddRight ( &szRightName[8], CAccessControlListRight::RIGHT_TYPE_GENERAL, bAccess ); } else continue; // Set all the extra attributes for ( uint i = 0 ; i < pSubSubNode->GetAttributes ().Count () ; i++ ) { CXMLAttribute* pAttribute = pSubSubNode->GetAttributes ().Get ( i ); pRight->SetAttributeValue ( pAttribute->GetName (), pAttribute->GetValue () ); } } } } } } } // Load the groups pSubNode = NULL; uiSubNodesCount = m_pRootNode->GetSubNodeCount (); for ( unsigned int i = 0 ; i < uiSubNodesCount ; i++ ) { pSubNode = m_pRootNode->GetSubNode ( i ); if ( !pSubNode ) continue; if ( pSubNode->GetTagName ().compare ( "group" ) == 0 ) { CXMLAttribute* pAttribute = pSubNode->GetAttributes ().Find ( "name" ); if ( pAttribute ) { CAccessControlListGroup* pGroup = AddGroup ( pAttribute->GetValue ().c_str () ); CXMLNode* pSubSubNode = NULL; unsigned int uiSubSubNodesCount = pSubNode->GetSubNodeCount (); for ( unsigned int j = 0 ; j < uiSubSubNodesCount ; j++ ) { pSubSubNode = pSubNode->GetSubNode ( j ); if ( !pSubSubNode ) continue; if ( pSubSubNode->GetTagName ().compare ( "object" ) == 0 ) { CXMLAttribute* pSubAttribute = pSubSubNode->GetAttributes ().Find ( "name" ); if ( pSubAttribute ) { const char *szAccountName = pSubAttribute->GetValue ().c_str (); if ( StringBeginsWith ( szAccountName, "user." ) ) { pGroup->AddObject ( &szAccountName[5], CAccessControlListGroupObject::OBJECT_TYPE_USER ); } else if ( StringBeginsWith ( szAccountName, "resource." ) ) { pGroup->AddObject ( &szAccountName[9], CAccessControlListGroupObject::OBJECT_TYPE_RESOURCE ); } } } else if ( pSubSubNode->GetTagName ().compare ( "acl" ) == 0 ) { CXMLAttribute* pSubAttribute = pSubSubNode->GetAttributes ().Find ( "name" ); if ( pSubAttribute ) { CAccessControlList* pACL = GetACL ( pSubAttribute->GetValue ().c_str () ); if ( pACL ) { pGroup->AddACL ( pACL ); } } } } } } } m_bNeedsSave = false; return true; }
bool CAccountManager::LoadXML ( CXMLNode* pParent ) { CLogger::LogPrint ( "Converting Accounts.xml into internal.db\n" ); //##Keep for backwards compatability with accounts.xml## #define ACCOUNT_VALUE_LENGTH 128 std::string strBuffer, strName, strPassword, strIP, strDataKey, strDataValue; if ( pParent ) { CXMLNode* pAccountNode = NULL; unsigned int uiAccountNodesCount = pParent->GetSubNodeCount (); for ( unsigned int i = 0 ; i < uiAccountNodesCount ; i++ ) { pAccountNode = pParent->GetSubNode ( i ); if ( pAccountNode == NULL ) continue; strBuffer = pAccountNode->GetTagName (); if ( strBuffer.compare ( "account" ) == 0 ) { CXMLAttribute* pAttribute = pAccountNode->GetAttributes ().Find ( "name" ); if ( pAttribute ) { strName = pAttribute->GetValue (); pAttribute = pAccountNode->GetAttributes ().Find ( "password" ); if ( pAttribute ) { strPassword = pAttribute->GetValue (); if ( !strName.empty () && !strPassword.empty () ) { pAttribute = pAccountNode->GetAttributes ().Find ( "ip" ); if ( pAttribute ) { strIP = pAttribute->GetValue (); CAccount* pAccount = NULL; pAttribute = pAccountNode->GetAttributes ().Find ( "serial" ); if ( pAttribute ) { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, ip, serial, password) VALUES(?,?,?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strIP.c_str(), SQLITE_TEXT, pAttribute->GetValue ().c_str(), SQLITE_TEXT, strPassword.c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, strIP, m_iAccounts++, pAttribute->GetValue () ); } else { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, ip, password) VALUES(?,?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strIP.c_str(), SQLITE_TEXT, strPassword.c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, strIP, m_iAccounts++ ); } // Grab the data on this account CXMLNode* pDataNode = NULL; int iType = LUA_TNIL; unsigned int uiDataNodesCount = pAccountNode->GetSubNodeCount (); for ( unsigned int j = 0 ; j < uiDataNodesCount ; j++ ) { pDataNode = pAccountNode->GetSubNode ( j ); if ( pDataNode == NULL ) continue; strBuffer = pDataNode->GetTagName (); if ( strBuffer == "nil_data" ) iType = LUA_TNIL; else if ( strBuffer == "boolean_data" ) iType = LUA_TBOOLEAN; else if ( strBuffer == "string_data" ) iType = LUA_TSTRING; else if ( strBuffer == "number_data" ) iType = LUA_TNUMBER; CXMLAttributes* pAttributes = &(pDataNode->GetAttributes ()); CXMLAttribute* pAttribute = NULL; unsigned int uiDataValuesCount = pAttributes->Count (); for ( unsigned int a = 0 ; a < uiDataValuesCount ; a++ ) { pAttribute = pAttributes->Get ( a ); strDataKey = pAttribute->GetName (); strDataValue = pAttribute->GetValue (); char szKey[128]; STRNCPY( szKey, strDataKey.c_str(), 128 ); SetAccountData( pAccount, szKey, strDataValue, iType ); } } } else { CAccount* pAccount = NULL; pAttribute = pAccountNode->GetAttributes ().Find ( "serial" ); if ( pAttribute ) { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, password, serial) VALUES(?,?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strPassword.c_str(), SQLITE_TEXT, pAttribute->GetValue().c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, "", m_iAccounts++, pAttribute->GetValue () ); } else { //Insert the entry into the accounts database m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, password) VALUES(?,?)", SQLITE_TEXT, strName.c_str(), SQLITE_TEXT, strPassword.c_str() ); pAccount = new CAccount ( this, true, strName, strPassword, "", m_iAccounts++, "" ); } } } else { if ( strName == CONSOLE_ACCOUNT_NAME ) { //Add Console to the SQL Database (You don't need to create an account since the server takes care of that m_pDatabaseManager->Execf ( m_hDbConnection, "INSERT INTO accounts (name, password) VALUES(?,?)", SQLITE_TEXT, "Console", SQLITE_TEXT, "" ); ++m_iAccounts; } } } } } else { //Load the settings from XML LoadSetting ( pAccountNode ); } } //Save the settings to SQL SaveSettings(); CLogger::LogPrint ( "Conversion Complete.\n" ); m_bChangedSinceSaved = false; return true; } return false; }