189 lines
5.2 KiB
C++
189 lines
5.2 KiB
C++
#include "StdAfx.h"
|
|
#include ".\accessinfoparser.h"
|
|
#include "AccessInfo.h"
|
|
#include "ServerInfoParser.h"
|
|
#include "UserInfoParser.h"
|
|
#include "UserInfo.h"
|
|
|
|
AccessInfoParser::AccessInfoParser(void)
|
|
{
|
|
m_XMLParser.Init();
|
|
m_AccessInfoHash.Initialize( MAX_USER_COUNT );
|
|
}
|
|
|
|
AccessInfoParser::~AccessInfoParser(void)
|
|
{
|
|
UnLoad();
|
|
}
|
|
|
|
|
|
BOOL AccessInfoParser::Load( char* pszFileName )
|
|
{
|
|
if( !m_XMLParser.Load( pszFileName ) )
|
|
return FALSE;
|
|
|
|
long nUserNum = 0;
|
|
NODELISTPtr pUserNodeList = m_XMLParser.FindNodeList( L"//USER", nUserNum );
|
|
if( pUserNodeList == NULL )
|
|
return FALSE;
|
|
|
|
DWORD dwUserKey = 0;
|
|
DWORD dwServerKey = 0;
|
|
BOOL bAccess = FALSE;
|
|
|
|
for( int nUser = 0; nUser < nUserNum; nUser++ )
|
|
{
|
|
NODEPtr pUserNode = m_XMLParser.FindNode( pUserNodeList, nUser );
|
|
if( pUserNode == NULL ) continue;
|
|
|
|
// 유저키를 얻는다.
|
|
dwUserKey = 0;
|
|
if( !m_XMLParser.GetAttriDataDWORD( pUserNode, L"KEY", dwUserKey ) ) continue;
|
|
|
|
// 유저가 가지고 있는 서버의 목록을 얻는다.
|
|
long nServerNum = 0;
|
|
NODELISTPtr pServerList = m_XMLParser.FindChildNodeList( pUserNode, nServerNum );
|
|
if( pServerList == NULL ) continue;
|
|
|
|
// 서버 접근 정보를 추가한다.
|
|
AccessInfo *pAccessInfo = new AccessInfo;
|
|
pAccessInfo->SetUserGUID( dwUserKey );
|
|
m_AccessInfoHash.Add( pAccessInfo, dwUserKey );
|
|
|
|
for( int nServer = 0; nServer < nServerNum; nServer++ )
|
|
{
|
|
NODEPtr pServerNode = m_XMLParser.FindNode( pServerList, nServer ); //첫번째 채널부터 순차적으로.
|
|
if( pServerNode == NULL ) continue;
|
|
|
|
// 서버키와, 접근권한을 얻어온다.
|
|
dwServerKey = 0;
|
|
bAccess = FALSE;
|
|
if( !m_XMLParser.GetAttriDataDWORD( pServerNode, L"KEY", dwServerKey ) ) continue;
|
|
if( !m_XMLParser.GetAttriDataBOOL( pServerNode, L"ACCESS", bAccess ) ) continue;
|
|
|
|
ACCESS_SERVER* pAccessServer = new ACCESS_SERVER;
|
|
pAccessServer->m_dwServerKey = dwServerKey;
|
|
pAccessServer->m_bAccess = bAccess;
|
|
pAccessInfo->InsertAccessServer( pAccessServer );
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
VOID AccessInfoParser::UnLoad()
|
|
{
|
|
AccessInfo* pAccessInfo = NULL;
|
|
|
|
for( ACCESS_INFO_HASH_ITR it = m_AccessInfoHash.begin(); it != m_AccessInfoHash.end(); ++it )
|
|
{
|
|
pAccessInfo = *it;
|
|
delete pAccessInfo;
|
|
}
|
|
|
|
m_AccessInfoHash.RemoveAll();
|
|
}
|
|
|
|
//새로운 유저를 추가한다.
|
|
//모든 권한은 없는것으로 한다.
|
|
BOOL AccessInfoParser::InsertUser( DWORD dwUserKey )
|
|
{
|
|
if( GetAccessInfo( dwUserKey ) ) //이미 해당유저키가 존재한다면..
|
|
return FALSE;
|
|
|
|
// 새로운 User Element를 생성한다.
|
|
ELEMENTPtr pUserEle = m_XMLParser.InsertElement( L"USER_ACCESS", L"USER" );
|
|
if( pUserEle == NULL ) return FALSE;
|
|
m_XMLParser.SetAttributeDWORD( pUserEle, L"KEY", dwUserKey );
|
|
|
|
AccessInfo *pAccessInfo = new AccessInfo;
|
|
pAccessInfo->SetUserGUID( dwUserKey );
|
|
m_AccessInfoHash.Add( pAccessInfo, dwUserKey );
|
|
|
|
SERVER_TOTAL_INFO info;
|
|
ServerInfoParser::Instance()->SerializeServerInfoStream( info, FALSE );
|
|
for( int i = 0; i < info.m_Count; i++ )
|
|
{
|
|
SERVER_INFO_EX ServerInfo = (SERVER_INFO_EX)info.m_Data[i];
|
|
|
|
ACCESS_SERVER* pAccessServer = new ACCESS_SERVER;
|
|
pAccessServer->m_bAccess = FALSE;
|
|
pAccessServer->m_dwServerKey = ServerInfo.m_dwServerKey;
|
|
pAccessInfo->InsertAccessServer( pAccessServer );
|
|
|
|
ELEMENTPtr pServerEle = m_XMLParser.CreateElement( L"SERVER" );
|
|
if( pServerEle == NULL ) return FALSE;
|
|
m_XMLParser.SetAttributeDWORD( pServerEle, L"KEY", pAccessServer->m_dwServerKey );
|
|
m_XMLParser.SetAttributeBYTE( pServerEle, L"ACCESS", pAccessServer->m_bAccess );
|
|
pUserEle->appendChild( pServerEle );
|
|
}
|
|
|
|
if( !m_XMLParser.Save() ) return FALSE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
BOOL AccessInfoParser::SerializeStreamForUser( DWORD dwUserKey, SERVER_ACCESS_TOTAL_INFO& info, BOOL bSave )
|
|
{
|
|
if( bSave )
|
|
{
|
|
AccessInfo* pAccessInfo = GetAccessInfo( dwUserKey );
|
|
if( !pAccessInfo ) return FALSE;
|
|
|
|
//1. 우선 메모리상의 데이터를 저장시키고..
|
|
pAccessInfo->SerializeStream( info, TRUE );
|
|
|
|
for( int i = 0; i < info.m_Count; i++ )
|
|
{
|
|
TCHAR szQuery[MAX_PATH];
|
|
_snprintf( szQuery, MAX_PATH, "//USER[@KEY='%u']/SERVER[@KEY='%u']", dwUserKey, info.m_Data[i].m_dwServerKey );
|
|
NODEPtr pNode = m_XMLParser.SingleQuery( szQuery );
|
|
if( pNode == NULL ) continue;
|
|
|
|
// 테스트 해보자... 엘레멘트를 노드형태로 사용할 수 있는지....==> 결로은 사용할 수 있는데.. 왜 그럴까?
|
|
m_XMLParser.SetAttributeBOOL( pNode, L"ACCESS", info.m_Data[i].bAccessRight );
|
|
}
|
|
|
|
if( !m_XMLParser.Save() ) return FALSE;
|
|
}
|
|
else
|
|
{
|
|
AccessInfo* pAccessInfo = GetAccessInfo( dwUserKey );
|
|
if( !pAccessInfo ) return FALSE;
|
|
|
|
pAccessInfo->SerializeStream( info, FALSE );
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// 접근권한정보를 현재 유저의 수에 맞게 동기화 시킨다.
|
|
// 접근 테이블에 유저가 없으면, 권한이 없는 것으로 하여 테이블에 유저를 추가한다.
|
|
BOOL AccessInfoParser::SyncAllUserRight()
|
|
{
|
|
//1. 모든 데이터를 삭제한다.
|
|
if( !m_XMLParser.RemoveElement( "USER_ACCESS" ) )
|
|
return FALSE;
|
|
|
|
//2. 메모리상의 데이터를 삭제한다.
|
|
UnLoad();
|
|
|
|
//3. 루트 엘레먼트를 삽입한다.
|
|
ELEMENTPtr pRootEle = m_XMLParser.InsertElement( L"/", L"USER_ACCESS" );
|
|
if( pRootEle == NULL ) return FALSE;
|
|
|
|
//4. 유저의 수만큼에 서버의 개수만큼 삽입한다.
|
|
USER_INFO_MAP_ITER UserIter = NULL;
|
|
for( UserIter = UserInfoParser::Instance()->Begin();
|
|
UserIter != UserInfoParser::Instance()->End(); ++UserIter )
|
|
{
|
|
UserInfo* pUserInfo = UserIter->second;
|
|
if( !pUserInfo ) continue;
|
|
|
|
InsertUser( pUserInfo->GetUserGUID() );
|
|
}
|
|
|
|
return TRUE;
|
|
} |