#include "StdAfx.h" #include "MBParseServerXml.h" #include "MBBaseDef.h" CMBParseServerXml::CMBParseServerXml(void) { } CMBParseServerXml::~CMBParseServerXml(void) { } bool CMBParseServerXml::ParseErrInfo( CString strXml,int& nErrCode,CString & strErr) { CString strErrCode; pugi::xml_document xmlDoc; if (!xmlDoc.load(strXml)) { return false; } pugi::xml_node form = xmlDoc.child(_T("Body")); strErrCode = form.child_value(_T("ErrCode")); nErrCode = _ttoi(strErrCode); strErr = form.child_value(_T("ErrInfo")); return true; } bool CMBParseServerXml::ParseLoginInfo(CString strXml,CMBUserLogin *pUserLogin) { if( NULL == pUserLogin ) return false; CMBFileSvrInfo *pFileSvrInfo = pUserLogin->GetFileSvrInfo(); if( NULL == pFileSvrInfo ) return false; pugi::xml_document xmlDoc; if (!xmlDoc.load(strXml)) { return false; } COleDateTime dtCurrent= COleDateTime::GetCurrentTime(); pUserLogin->m_strLoginTime = dtCurrent.Format(_T("%Y-%m-%d %H:%M:%S")); pugi::xml_node form = xmlDoc.child(_T("User")); pUserLogin->m_strLoginName = form.attribute(_T("Login")).value(); pUserLogin->m_strUserName = form.attribute(_T("Name")).value(); pUserLogin->m_strAliasName= form.attribute(_T("Alias")).value(); pUserLogin->m_strUserConnIP = form.child_value(_T("ConnIP")); pUserLogin->m_strToken = form.child_value(_T("Token")); form = xmlDoc.child(_T("User")).child(_T("Admin")); pUserLogin->m_bIsSysAdmin = _tstoi(form.attribute(_T("SysAdmin")).value()) ? true: false; form = xmlDoc.child(_T("User")).child(_T("FileService")); pFileSvrInfo->m_strFlag = form.attribute(_T("Flag")).value(); pFileSvrInfo->m_strExterIP = form.attribute(_T("ExterIP")).value(); pFileSvrInfo->m_strExterPort = form.attribute(_T("ExterPort")).value(); if( _tstol(pFileSvrInfo->m_strExterPort) < 0) pFileSvrInfo->m_strExterPort.Format(_T("%d"),DEFAULTPORT_FILE); pFileSvrInfo->m_strInterIP = form.attribute(_T("InterIP")).value(); pFileSvrInfo->m_strInterPort = form.attribute(_T("InterPort")).value(); if( _tstol(pFileSvrInfo->m_strInterPort) < 0) pFileSvrInfo->m_strInterPort.Format(_T("%d"),DEFAULTPORT_FILE); pFileSvrInfo->m_strInterURL = form.child_value(_T("InterURL")); pFileSvrInfo->m_strExterURL = form.child_value(_T("ExterURL")); pFileSvrInfo->CheckServerInfo(pUserLogin->m_strServerName); pUserLogin->m_strFileSFlag = pFileSvrInfo->m_strFlag ; CMBAuthInfo *pAuthInfo = pUserLogin->GetAuthInfo(); if( NULL == pAuthInfo ) return false; pugi::xml_node node = xmlDoc.child(_T("User")).child(_T("AuthInfo")).child(_T("App")); for(pugi::xml_node nodeTmp = node; nodeTmp; nodeTmp = nodeTmp.next_sibling(_T("App"))) { CMBAuthApp *pApp = new CMBAuthApp(); pApp->m_strFlag = nodeTmp.attribute(_T("Flag")).value(); pApp->m_strName = nodeTmp.attribute(_T("Name")).value(); pApp->m_strVer = nodeTmp.attribute(_T("Ver")).value(); pApp->m_strFuncModule = nodeTmp.attribute(_T("FuncModule")).value(); if( !pAuthInfo->Add(pApp) ){ delete pApp; pApp = NULL; return false; } } return true; } bool CMBParseServerXml::ParseParamInfo( CString &strParam,long &nTrID, CString &strAppType,CString &strMethod ) { CStringArray strArray,strTmpArray; CString strName,strValue; CMBStrOper::SplitString(strParam, _T(';'), strArray); for( int i= 0;i < strArray.GetCount();i++ ) { strTmpArray.RemoveAll(); CMBStrOper::SplitString(strArray[i], _T(':'), strTmpArray); strName = strTmpArray[0]; if( strTmpArray.GetCount() == 2 ){ strValue = strTmpArray[1]; }else{ strValue = _T(""); } if(strName.CompareNoCase(_T("TrID")) == 0) { nTrID = _tstol(strValue); } else if(strName.CompareNoCase(_T("AppType")) == 0) { strAppType = strValue; } else if(strName.CompareNoCase(_T("Method")) == 0) { strMethod = strValue; } } return true; } bool CMBParseServerXml::ParseParamErrInfo( CMBParamErrInfoMap & mapParam,CString &strParam ) { CStringArray aryItem; int n = CMBStrOper::SplitString(strParam,_T(';'), aryItem); for( int i =0;i < aryItem.GetCount();i++ ) { CString strTmp = aryItem[i]; int nPos = strTmp.Find(_T("=")); CString strKey = strTmp.Left(nPos); CString strValue = strTmp.Right( strTmp.GetLength() - nPos -1 ) ; mapParam[strKey] = strValue; } return true; }