Ejemplo n.º 1
0
bool CSqlWhere::AddCond(const CString& oName, uint32 nOp, const CString& oVal)
{
    if(m_pAccess == NULL)
        return false;
    uint32 nFieldNo = m_pAccess->GetFieldNo(oName.GetStr());
    if(nFieldNo == (uint32)(-1))
    {
        m_bError = true;
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlWhere::AddCond() there isn't the field '%s' in the table '%s'", oName.GetStr(), m_oName.GetStr()));
        return false;
    }
    bool bSet;
    CMdbParaSet* pParaSet;
    uint32 i, nCount = m_pWhere->GetParaCount();
    if(nCount)
        pParaSet = (CMdbParaSet*)m_pWhere->GetPara(nCount - 1, bSet);
    else
        pParaSet = (CMdbParaSet*)m_pWhere->AddParaSet();
    nCount = pParaSet->GetParaCount();
    for(i=0; i<nCount; ++i)
    {
        CMdbSqlPara* pPara = (CMdbSqlPara*)pParaSet->GetPara(i, bSet);
        if(!pPara->IsSetField(nFieldNo))
        {
            pPara->SetFromString(nFieldNo, oVal.GetStr(), nOp);
            return true;
        }
    }
    CMdbSqlPara* pPara = (CMdbSqlPara*)pParaSet->AddPara();
    pPara->SetFromString(nFieldNo, oVal.GetStr(), nOp);
    return true;
}
Ejemplo n.º 2
0
bool CSqlInsert::AddValue(const CString& oVal)
{
    if(m_pAccess == NULL)
        return false;
    uint32 nFldNo = m_nFldNo++;
    if(!m_oFieldTable.GetSize())
    {
        uint32 nFieldCount = m_pAccess->GetFieldCount();
        if(nFldNo < nFieldCount)
            m_pInsertAttr->SetFromString(nFldNo, (char*)oVal.GetStr(), MDB_SQLPARA_OPERATOR_EQUAL);
        else
        {
            m_bError = true;
            FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlInsert::AddValue() there isn't the field no '%u' in the table '%s'", nFldNo, m_oName.GetStr()));
            return false;
        }
    }
    else
    {
        CString& oFieldName = m_oFieldTable[nFldNo];
        uint32 nFieldNo = m_pAccess->GetFieldNo(oFieldName.GetStr());
        if(nFieldNo == (uint32)(-1))
        {
            m_bError = true;
            FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlInsert::AddValue() there isn't the field no '%u' in the table '%s'", nFldNo, m_oName.GetStr()));
            return false;
        }
        m_pInsertAttr->SetFromString(nFieldNo, oVal.GetStr(), MDB_SQLPARA_OPERATOR_EQUAL);
    }
    return true;
}
Ejemplo n.º 3
0
static void InitializeMdbSecurityInfo(CString& oUser, CString& oPasswd)
{
	CMdb* pDb = CMdb::GetMdb(MDB_SYSDB_NAME);
	CMdbAccess* pAccess = pDb->QueryAccess("MdbSecurity");
	CMdbPara* pPara = pAccess->GetInsertPara();
	pPara->SetNull(0);//MdbName
	pPara->SetString(1, oUser.GetStr());
	pPara->SetString(2, oPasswd.GetStr());
	pAccess->Insert();
	pAccess->Release();
}
Ejemplo n.º 4
0
bool CSqlUpdate::AddSetPara(const CString& oName, const CString& oVal, uint32 nOp)
{
    if(m_pAccess == NULL)
        return false;
    uint32 nFieldNo = m_pAccess->GetFieldNo(oName.GetStr());
    if(nFieldNo == (uint32)(-1))
    {
        m_bError = true;
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlUpdate::AddSetPara() there isn't the field '%s' in the table '%s'", oName.GetStr(), m_oName.GetStr()));
        return false;
    }
    m_pSetAttr->SetFromString(nFieldNo, oVal.GetStr(), nOp);
    return true;
}
Ejemplo n.º 5
0
uint32 CLogArchiver::GetNameValue(const char* &pStr, uint32 &nName, CString &oValue, uint32 &nValue)
{
	bool bInt;
	uint32 nRet;
	CString oName;
	nRet = GetIdentifier(pStr, oName);
	if(!nRet)
		nRet = GetNameType(oName, nName, bInt);
	if(!nRet)
	{
		SkipWhiteSpace(pStr);
		if(pStr[0] != '=')
			nRet = 1;
		else
			++pStr;
	}
	if(!nRet)
	{
		if(bInt)
		{
			nRet = GetInt(pStr, oValue);
			if(!nRet)
				nValue = CString::Atoi(oValue.GetStr());
		}
		else
			nRet = GetString(pStr, oValue);
	}
	return nRet;
}
Ejemplo n.º 6
0
	virtual void OnWalk(uint32 nDomain, uint32 nNode, const CAsmNode& oNode)
	{
		CString oDate;
		struct tm *tloc;
#ifndef WINDOWS
		struct tm tt;
		localtime_r((const time_t*)&oNode.nTime, &tt);
		tloc = &tt;
#else
		tloc = localtime((const time_t*)&oNode.nTime);
#endif
		CStringFormatter(&oDate).Print("%04d-%02d-%02d %02d:%02d:%02d",
			1900+tloc->tm_year,tloc->tm_mon+1,tloc->tm_mday,
			tloc->tm_hour,tloc->tm_min,tloc->tm_sec);

		CIpAddr oAddr;
		CString oFileName;
		CAcmUdp* pUdp = CAcmUdp::QueryUdp(nDomain);
		pUdp->GetNodeAddr(nNode, oAddr);
		CFile::GetIpFileName(oAddr, oFileName);

		m_pSession->Print(" Node[%u].Addr(%s) startup at %s, %s, %s\r\n", nNode, oFileName.GetStr(), oDate.GetStr(),
			oNode.bOnLine?"online ":"offline", oNode.bServering?"active":"inactive");

		++m_nWalkSize;
	}
Ejemplo n.º 7
0
void CInterfaceManager::Load()
{
	m_oMutex.Enter();
	if(m_pAutoLibrary == NULL)
	{
		uint32 i, nCount;
		CString oLibDir;
		const char* sAppHome = CFilePathInfo::GetInstance()->GetHome();
		oLibDir += sAppHome;
		oLibDir += "/lib/";
		oLibDir += m_sLibDir;
		m_pAutoLibrary = new CAutoLibrary(oLibDir.GetStr());
		nCount = m_oInterfaces.GetSize();
		for(i=nCount; i; --i)
		{
			CInterface* pInterface = m_oInterfaces[i-1];
			if(QueryInterface(pInterface->GetInterfaceName()) != pInterface)
			{
				m_oMutex.Leave();
				FocpAbort(( "re-register interface :%s",  pInterface->GetInterfaceName()));
			}
		}
	}
	m_oMutex.Leave();
}
Ejemplo n.º 8
0
void CAcmUdp::Walk()
{
	CIpAddr oItfAddr;
	CString oFileName;
	GetInterfaceAddr(oItfAddr);
	CFile::GetIpFileName(oItfAddr, oFileName);
	m_pContext->OnWalk(m_nNode, oFileName.GetStr());
	CRbTreeNode* pEnd = m_oNodeList.End();
	m_oMutex.Enter();
	CRbTreeNode* pIt = m_oNodeList.First();
	for(; pIt!=pEnd; pIt=m_oNodeList.GetNext(pIt))
	{
		uint32 nNode = m_oNodeList.GetKey(pIt);
		CIpAddr& oAddr = m_oNodeList.GetItem(pIt);
		CFile::GetIpFileName(oAddr, oFileName);
		m_pContext->OnWalk(nNode, oFileName.GetStr());
	}
	m_oMutex.Leave();
}
Ejemplo n.º 9
0
uint32 CSqlDataBase::CreateSqlInsert(const CString& oName)
{
    CMdbAccess * pAccess = m_pDb->QueryAccess(oName.GetStr());
    if(!pAccess)
    {
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlDataBase::CreateSqlInsert(%s.%s) failure: MDB_TABLE_NOTEXIST", m_pDb->GetDbName(), oName.GetStr()));
        return MDB_TABLE_NOTEXIST;
    }
    m_oInsert.Bind(oName, pAccess);
    return MDB_SUCCESS;
}
Ejemplo n.º 10
0
void CLogArchiver::DoArchive(bool bDispErr)
{
	uint32 nOldArchId = m_nArchId;
	++m_nArchId;
	if(m_nArchId > m_nArchNo)
		m_nArchId = 1;
	char sLogDir[FOCP_MAX_PATH];
	CFormatString oCmd;
	CString::StringCopy(sLogDir, m_oLogDir.GetStr());
	CDiskFileSystem::GetInstance()->GetOsPathName(sLogDir);
#ifdef WINDOWS
	oCmd.Print("tar -czf %s\\%s.%03d.log.tar.gz %s\\%s.*.log 1>1.txt 2>2.txt", m_oArchDir.GetStr(), m_oLogName.GetStr(), m_nArchId, sLogDir, m_oLogName.GetStr());
#else
	oCmd.Print("tar -czf %s/%s.%03d.log.tar.gz %s/%s.*.log 1>1.txt 2>2.txt", m_oArchDir.GetStr(), m_oLogName.GetStr(), m_nArchId, sLogDir, m_oLogName.GetStr());
#endif
	int32 nRet = System(oCmd.GetStr());
	char sErrFile[FOCP_MAX_PATH];
	CString::StringCopy(sErrFile, "disk://");
	CDiskFileSystem::GetInstance()->GetFullPath("2.txt", sErrFile+7);
	CFile oFile(sErrFile, "r");
	bool bHaveError = false;
	CString oError;
	while(true)
	{
		int32 nLen = oFile.Read(sErrFile, FOCP_MAX_PATH);
		if(nLen <= 0)
			break;
		bHaveError = true;
		oError.Append(sErrFile, nLen);
	}
	oFile.Redirect(NULL);
	if(bHaveError)
	{
		m_nArchId = nOldArchId;
		if(bDispErr)
			FocpError(("%s", oError.GetStr()));
	}
	else if(nRet)
	{
		m_nArchId = nOldArchId;
		if(bDispErr)
			FocpError(("system('%s') failure", oCmd.GetStr()));
	}
	else
	{
		oCmd.Clear();
		oCmd.Print("rm -rf %s\\%s.*.log 1>1.txt 2>2.txt", sLogDir, m_oLogName.GetStr());
		System(oCmd.GetStr());
	}
	System("rm -rf 1.txt");
	System("rm -rf 2.txt");
}
Ejemplo n.º 11
0
uint32 CSqlDataBase::TruncateTable(const CString& oName)
{
    CMdbAccess * pAccess = m_pDb->QueryAccess(oName.GetStr());
    if(!pAccess)
    {
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlDataBase::TruncateTable(%s.%s) failure: MDB_TABLE_NOTEXIST", m_pDb->GetDbName(), oName.GetStr()));
        return MDB_TABLE_NOTEXIST;
    }
    pAccess->Truncate();
    pAccess->Release();
    FocpCmdLogEx("SQL", FOCP_LOG_SYSLOG, ("CSqlDataBase::TruncateTable(%s.%s) success", m_pDb->GetDbName(), oName.GetStr()));
    return 0;
}
Ejemplo n.º 12
0
uint32 CSqlEnv::SelectDataBase(const CString& oName)
{
    CMdb* pDb = CMdb::GetMdb(oName.GetStr());
    if(!pDb)
    {
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR,
                     ("CSqlEnv::SelectDataBase(%s) failure", oName.GetStr()));
        return MDB_DB_NOTEXIST;
    }
    if(!pDb->GetLocalInterface())
    {
        if(!oName.Compare("sysdb", false))
        {
            FocpCmdLogEx("SQL", FOCP_LOG_ERROR,
                         ("CSqlEnv::SelectDataBase(%s) failure", oName.GetStr()));
            return MDB_DB_NOTEXIST;
        }
    }
    m_oDataBase.Bind(pDb);
    FocpCmdLogEx("SQL", FOCP_LOG_CLOSE,
                 ("CSqlEnv::SelectDataBase(%s) success", oName.GetStr()));
    return MDB_SUCCESS;
}
Ejemplo n.º 13
0
uint32 CSqlDataBase::QueryTable()
{
    if(!m_oSelect.m_pAccess)
        return 0;

    CMdbFilter* pFilter = m_oSelect.m_pAccess->GetResultFilter();
    uint32 nSize = m_oSelect.m_oFieldTable.GetSize();
    for(uint32 i=0; i<nSize; ++i)
        pFilter->SetField(m_oSelect.m_pAccess->GetFieldNo(m_oSelect.m_oFieldTable[i].GetStr()));

    uint32 nRet;
    if(m_oSelect.m_bError)
        return 0;
    uint32 nTotal = 0;
    CString oList = GetFieldList();
    while(true)
    {
        nRet = m_oSelect.m_pAccess->Query(m_nResultSize, nTotal);
        m_oSelect.m_pRecordSet = m_oSelect.m_pAccess->GetResultSet();
        if(nRet)
        {
            FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlDataBase::QueryTable(%s.%s) failure: %s", m_pDb->GetDbName(), m_oSelect.m_oName.GetStr(), GetMdbError(nRet)));
            m_pEnv->Flush(false);
            m_oSelect.UnBind();
            return 0;
        }
        else
        {
            if(!nTotal)
            {
                FocpCmdLogEx("SQL", FOCP_LOG_CLOSE, ("%s", oList.GetStr()));
                m_pEnv->Flush(false);
            }
            uint32 nCount = m_oSelect.GetResultCount();
            for(uint32 i=0; i<nCount; ++i)
            {
                CMdbResult* pRecord = m_oSelect.GetRecord(i);
                FocpCmdLogEx("SQL", FOCP_LOG_CLOSE, ("%s", GetRecordText(pRecord, oList).GetStr()));
                m_pEnv->Flush(false);
            }
            nTotal += nCount;
            if(nCount < m_nResultSize)
                break;
        }
    }
    FocpCmdLogEx("SQL", FOCP_LOG_CLOSE, ("\r\ntotal %u records in %s.%s", nTotal, m_pDb->GetDbName(), m_oSelect.m_oName.GetStr()));
    m_oSelect.UnBind();
    return 0;
}
Ejemplo n.º 14
0
	void UnLoad()
	{
		if(m_pLib && m_bNeedFree)
		{
	#if defined(WINDOWS)// || defined(CYGWIN_NT)
			::FreeLibrary((HMODULE)m_pLib);
	#else
			::dlclose(m_pLib);
	#endif
			if(!m_oFileName.Empty())
				FocpLog(FOCP_LOG_SYSLOG, ("UnLoad(%s) success", m_oFileName.GetStr()));
		}
		m_bNeedFree = true;
		m_pLib = NULL;
	}
Ejemplo n.º 15
0
void CLogArchiver::Query(CCmdSession* pSession, const char *sCmdLine, const char* sCmdArg)
{
	CString oLogName;
	CFormatString oFmt(sCmdArg);
	int32 nRet = oFmt.Scan("%s", &oLogName);
	if(nRet < 1)
	{
		pSession->Print("Missing the server address argument\r\n");
		return;
	}
	if(!oLogName.IsIdentifierOfC())
	{
		pSession->Print("Invalid logname\r\n");
		return;
	}
	CArchiverTable* pTable = CArchiverTable::GetInstance();
	pTable->m_oMutex.Enter();
	CRbTreeNode* pIt = pTable->m_oArchiverTable.Find(oLogName);
	if(pIt == pTable->m_oArchiverTable.End())
	{
		pTable->m_oMutex.Leave();
		pSession->Print("The logname isn't existed\r\n");
		return;
	}
	CString oChooser;
	CLogArchiver* pItem = pTable->m_oArchiverTable.GetItem(pIt);
	pItem->GetChooser(oChooser);
	CFormatString oFmt2;
	oFmt2.Print("The chooser is '%s', \r\nand the filter include:", oChooser.GetStr());
	if(pItem->m_nFilter & FOCP_LOG_HOST)
		oFmt2.Print("HOST ");
	if(pItem->m_nFilter & FOCP_LOG_DATE)
		oFmt2.Print("DATE ");
	if(pItem->m_nFilter & FOCP_LOG_APPN)
		oFmt2.Print("APP ");
	if(pItem->m_nFilter & FOCP_LOG_MODU)
		oFmt2.Print("MODULE ");
	if(pItem->m_nFilter & FOCP_LOG_SRCF)
		oFmt2.Print("FILE ");
	if(pItem->m_nFilter & FOCP_LOG_FUNC)
		oFmt2.Print("FUNC");
	pSession->Print("%s\r\n", oFmt2.GetStr());
	pTable->m_oMutex.Leave();
}
Ejemplo n.º 16
0
	virtual void OnAddNode(CAcmUdp* pUdp, uint32 nNode, uint32 nIp, uint16 nPort)
	{
		uint32 nDomain = pUdp->GetDomain();
		CAcmDomain & oDomain = m_oDomainInfo[nDomain];
		if(oDomain.nDomainType == 2)//µ¥²¥
		{
			CRbTreeNode* pIt = oDomain.oUniCastInfo.Find(nNode);
			if(pIt == oDomain.oUniCastInfo.End())
			{
				CIpAddr & oAddr = oDomain.oUniCastInfo[nNode];
				oAddr.nAddr = nIp;
				oAddr.nPort = nPort;
				CTextAccess oAccess;
				CInitConfigSystem* pConfigSystem = CInitConfigSystem::GetInstance();
				if(!pConfigSystem->OpenConfig(oAccess, "AcmUniCast"))
					return;
				oAccess.OpenColVal();
				{
					CFormatString oIdx;
					oIdx.Print("%u", nDomain);
					oAccess.SetColVal("AcmDomain", oIdx.GetStr());
				}
				{
					CFormatString oIdx;
					oIdx.Print("%u", nNode);
					oAccess.SetColVal("Node", oIdx.GetStr());
				}
				{
					CString oIdx;
					CIpAddr oIp = {nIp, 0};
					CFile::GetIpFileName(oIp, oIdx);
					oAccess.SetColVal("UniCastAddr", oIdx.GetStr());
				}
				{
					CFormatString oIdx;
					oIdx.Print("%u16", nPort);
					oAccess.SetColVal("UniCastPort", oIdx.GetStr());
				}
				oAccess.Insert(true);
			}
		}
	}
Ejemplo n.º 17
0
void CLogArchiver::Process(CLogMsg& oLog)
{
	CString oLogInfo;
	GetLogInfo(oLog, oLogInfo);
	if(NotAccess())
	{
		++m_nLogId;
		if(m_nLogId > m_nLogNo)
		{
			if(m_bNeedArch)
			{
				m_oFile.Redirect(NULL);
				DoArchive();
			}
			m_nLogId = 1;
		}
		CreateLogFile();
	}
	m_oFile.Write(oLogInfo.GetStr(), oLogInfo.GetSize());
}
Ejemplo n.º 18
0
uint32 CSqlDataBase::CreateIndex()
{
    CString oFieldName;
    CVector<CString>& oFieldTable = m_oIndex.oIndexFieldTable;
    uint32 nSize = oFieldTable.GetSize();
    for(uint32 i=0; i<nSize; ++i)
    {
        if(!oFieldName.Empty())
            oFieldName += ",";
        oFieldName += oFieldTable[i];
    }

    CMdbIndexDef oIdxDef;
    CBinary::MemorySet(&oIdxDef, 0, sizeof(oIdxDef));
    oIdxDef.sIndexName = (char*)m_oIndex.oIndexName.GetStr();
    oIdxDef.sTableName = (char*)m_oIndex.oTableName.GetStr();
    oIdxDef.sPrimaryIndex = (char*)m_oIndex.oPrimaryIndex.GetStr();
    if(!oIdxDef.sPrimaryIndex[0])
        oIdxDef.sPrimaryIndex = NULL;
    oIdxDef.nQualifier = m_oIndex.nQualifier;
    oIdxDef.nArithmetic = m_oIndex.nArithmetic;
    oIdxDef.nHashRate = m_oIndex.nHashRate;
    oIdxDef.pFieldList = (char*)oFieldName.GetStr();

    CMdbLocalInterface* pItf = m_pDb->GetLocalInterface();
    if(pItf == NULL)
    {
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlDataBase::CreateIndex(%s.%s) failure: MDB_INVALID_INTERFACE", m_pDb->GetDbName(), oIdxDef.sIndexName));
        return MDB_INVALID_INTERFACE;
    }
    uint32 nRet = pItf->CreateIndex(&oIdxDef);
    if(nRet)
        FocpCmdLogEx("SQL", FOCP_LOG_ERROR, ("CSqlDataBase::CreateIndex(%s.%s) failure: %s", m_pDb->GetDbName(), oIdxDef.sIndexName, GetMdbError(nRet)));
    else
        FocpCmdLogEx("SQL", FOCP_LOG_SYSLOG, ("CSqlDataBase::CreateIndex(%s.%s) success", m_pDb->GetDbName(), oIdxDef.sIndexName));
    return nRet;
}
Ejemplo n.º 19
0
void CLogChooser::AddCond(uint32 nType, bool bNot, const CString& oVal1, const CString &oVal2, bool bIncBeg, bool bIncEnd)
{
	CLogChoiceGroup* pGroup = m_oGroups.GetItem(m_oGroups.Last());
	CLogChoice* pChoice = pGroup->NewChoice(nType);
	pChoice->SetNot(bNot);
	if(nType == 1)
	{
		CDateTime nBegin(oVal1), nEnd(oVal2);
		CLogTimeChoice* pTimeChoice = (CLogTimeChoice*)pChoice;
		pTimeChoice->SetBegin(nBegin.GetValue(), bIncBeg);
		pTimeChoice->SetEnd(nEnd.GetValue(), bIncEnd);
	}
	else if(nType >= 7)
	{
		uint32 nValue = CString::Atoi(oVal1.GetStr());
		CLogIntChoice* pIntChoice = (CLogIntChoice*)pChoice;
		pIntChoice->SetValue(nValue);
	}
	else
	{
		CLogTextChoice* pTextChoice = (CLogTextChoice*)pChoice;
		pTextChoice->SetValue(oVal1);
	}
}
Ejemplo n.º 20
0
CAutoLibrary::CAutoLibrary(const char* sLibDir)
{
	char sLibFile[FOCP_MAX_PATH];
#if defined(WINDOWS)// || defined(CYGWIN_NT)
	const char * sPostfix = ".dll";
	const char * sPrefix = "";
#elif defined(CYGWIN_NT)
	const char * sPostfix = ".dll";
	const char * sPrefix = "cyg";
#else
	const char * sPostfix = ".so";
	const char * sPrefix = "lib";
#endif
	CDynamicLibrary* pLibrary = NULL;
	CDiskFileSystem* pFileSystem = CDiskFileSystem::GetInstance();
	void* pDirectory = pFileSystem->OpenDirectory(sLibDir);
	if(pDirectory == NULL)
	{
		FocpLog(FOCP_LOG_ERROR, ("OpenDirectory(%s) failure", sLibDir));
		return;
	}
	//这里不能使用CFile,因为文件驱动的加载需要使用该函数,会形成死递归调用
	FILE* fp;
	CString oLibraryList, oUnLoadList;
	CString::StringCopy(sLibFile, sLibDir);
	CString::StringCatenate(sLibFile, "/load.cfg");
	pFileSystem->GetOsPathName(sLibFile);
	fp = fopen(sLibFile, "rb");
	if(fp)
	{
		fseek(fp, 0, SEEK_END);
		int32 nSize = ftell(fp);
		fseek(fp, 0, SEEK_SET);
		oLibraryList.Append('A', nSize);
		fread((void*)oLibraryList.GetStr(), 1, nSize, fp);
		fclose(fp);
	}
	CString::StringCopy(sLibFile, sLibDir);
	CString::StringCatenate(sLibFile, "/unload.cfg");
	pFileSystem->GetOsPathName(sLibFile);
	fp = fopen(sLibFile, "rb");
	if(fp)
	{
		fseek(fp, 0, SEEK_END);
		int32 nSize = ftell(fp);
		fseek(fp, 0, SEEK_SET);
		oUnLoadList.Append('A', nSize);
		fread((void*)oUnLoadList.GetStr(), 1, nSize, fp);
		fclose(fp);
	}

	bool bIsDirectory;
	const char* sFileName;
	uint32 nLen2 = CString::StringLength(sPostfix);
	uint32 nLen3 = CString::StringLength(sPrefix);
	if(!oLibraryList.Empty())
	{
		CString oFileName;
		CStringFormatter oFormatter(&oLibraryList);
		while(oFormatter.Scan("%r", &oFileName)==1)
		{
			oFileName.Trim();
			if(!oFileName.Empty())
			{
				if(!oUnLoadList.Empty())
				{
					uint32 nLen = oFileName.GetSize();
					const char* sHead = oUnLoadList.GetStr();
					char* sLib = CString::StringOfString(sHead, oFileName.GetStr(), false);
					if(sLib &&
							(sLib[nLen] == '\0' || CString::IsSpace(sLib[nLen])) &&
							(sHead == sLib || CString::IsSpace(*(sLib-1))))
						continue;
				}
				CString::StringCopy(sLibFile, sLibDir);
				CString::StringCatenate(sLibFile, "/");
				CString::StringCatenate(sLibFile, sPrefix);
				CString::StringCatenate(sLibFile, oFileName.GetStr());
				CString::StringCatenate(sLibFile, sPostfix);
				if(pLibrary == NULL)
					pLibrary = new CDynamicLibrary;
				if(pLibrary->Load(sLibFile))
				{
					m_oLibrary.Insert(m_oLibrary.GetSize(), pLibrary);
					pLibrary = NULL;
				}
			}
		}
	}
	else while( (sFileName = pFileSystem->ReadDirectory(pDirectory, bIsDirectory)) )
		{
			if(bIsDirectory)
				continue;
			uint32 nLen = CString::StringLength(sFileName);
			if(nLen <= nLen2+nLen3)
				continue;
			if(CString::StringCompare(sFileName+nLen-nLen2, sPostfix))
				continue;
			if(nLen3 && CString::StringCompare(sFileName, sPrefix, true, nLen3))
				continue;
			if(!oUnLoadList.Empty())
			{
				uint32 nLen4 = nLen-nLen2-nLen3;
				CString oSimpleFileName(sFileName+nLen3, nLen4);
				const char* sHead = oUnLoadList.GetStr();
				char* sLib = CString::StringOfString(sHead, oSimpleFileName.GetStr(), false);
				if(sLib && (sLib[nLen4] == '\0' ||
							CString::IsSpace(sLib[nLen4])) &&
						(sHead == sLib || CString::IsSpace(*(sLib-1))))
					continue;
			}
			CString::StringCopy(sLibFile, sLibDir);
			CString::StringCatenate(sLibFile, "/");
			CString::StringCatenate(sLibFile, sFileName);
			if(pLibrary == NULL)
				pLibrary = new CDynamicLibrary;
			if(pLibrary->Load(sLibFile))
			{
				m_oLibrary.Insert(m_oLibrary.GetSize(), pLibrary);
				pLibrary = NULL;
			}
		}
	pFileSystem->CloseDirectory(pDirectory);
	if(pLibrary)
		delete pLibrary;
}
Ejemplo n.º 21
0
	virtual bool OnInitialize()
	{
		uint32 nLength;
		const char* sVal = NULL;
		CTextAccess oAccess;
		CInitConfigSystem* pConfigSystem = CInitConfigSystem::GetInstance();

		//Register telnet command line interface
		CCmdSystem::GetInstance()->RegisterCmd("/Mdb", "Mdb<CR>:\r\n\t sql command line", MdbSqlCmdFunc);

		//Create Local Memory Database
		uint32 nMdbSvr = 0;
		if(pConfigSystem->OpenConfig(oAccess, "MdbService", true))
		{
			oAccess.OpenIdxVal();
			if(oAccess.Query())
			{
				sVal = oAccess.GetVal("MdbSvr", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'MdbService.ServerPort' is invalid"));
					return false;
				}
				nMdbSvr = CString::Atoi(sVal);
				sVal = oAccess.GetVal("MdbList", nLength);
			}
		}

		bool bInitializeMdbDataSource = false;
		bool bInitializeMdbStorageAttr = false;
		bool bCreateMdbReplicator = false;
		bool bConfigMdbDomain = false;

		if(sVal && sVal[0])
		{
			bool bCreated = false;
			char*pShift, *pDbName = (char*)sVal;
			while(pDbName)
			{
				pShift = (char*)CString::CharOfString(pDbName, ',');
				if(pShift)
					pShift[0] = 0;

				if(m_pMdbItf == NULL)
				{
					m_pMdbItf = new CLocalMdbItf;
					if(!m_pMdbItf->Valid())
					{
						if(pShift)
							pShift[0] = ',';
						return false;
					}
				}
				if(!m_pMdbItf->CreateMemoryDataBase(pDbName))
				{
					if(pShift)
						pShift[0] = ',';
					return false;
				}
				bCreated = true;
				CCmdSession oSession;
				char sDbfScript[FOCP_MAX_PATH];
				const char* sHome = CFilePathInfo::GetInstance()->GetHome();
				StringPrint(sDbfScript, "%s/dbf/%s.Create.sql", sHome, pDbName);
				oSession.ProcessScript(sDbfScript);

				pDbName = pShift;
				if(pDbName)
				{
					pDbName[0] = ',';
					++pDbName;
				}
			}

			if(bCreated)//创建了本地数据库
			{
				if(pConfigSystem->OpenConfig(oAccess, "MdbStorage", true))
				{
					oAccess.OpenIdxVal();
					while(oAccess.Query())
					{
						sVal = oAccess.GetVal("MdbName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.MdbName' is invalid"));
							return false;
						}
						CString oMdbName(sVal);
						sVal = oAccess.GetVal("CacheName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.CacheName' is invalid"));
							return false;
						}
						CString oMdbTabName(sVal);
						sVal = oAccess.GetVal("TableName", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.TableName' is invalid"));
							return false;
						}
						CString oDbTabName(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("LoadWhere", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.LoadWhere' is invalid"));
							return false;
						}
						CString oLoadWhere(sVal?sVal:"");
						sVal = oAccess.GetVal("StorageWhere", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.StorageWhere' is invalid"));
							return false;
						}
						CString oStorageWhere(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("CacheWhere", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.CacheWhere' is invalid"));
							return false;
						}
						CString oCacheWhere(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("StorageIdx", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.StorageIdx' is invalid"));
							return false;
						}
						CString oStorageIdx(sVal);
						sVal = oAccess.GetVal("FieldList", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.FieldList' is invalid"));
							return false;
						}
						CString oFieldList(sVal?sVal:(char*)"");
						if(m_pStoItf == NULL)
						{
							m_pStoItf = new CMdbStoItf;
							if(!m_pStoItf->Valid())
								return false;
						}
						if(!m_pStoItf->InitializeMdbStorageAttr(oMdbName.GetStr(), oMdbTabName.GetStr(),
																oDbTabName.GetStr(), oLoadWhere.GetStr(), oStorageWhere.GetStr(), oCacheWhere.GetStr(), 
																oStorageIdx.GetStr(), oFieldList.GetStr()))
							return false;
						bInitializeMdbStorageAttr = true;
					}
				}

				if(pConfigSystem->OpenConfig(oAccess, "MdbReplication", true))
				{
					oAccess.OpenIdxVal();
					while(oAccess.Query())
					{
						sVal = oAccess.GetVal("MdbName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.MdbName' is invalid"));
							return false;
						}
						CString oDbName(sVal);
						sVal = oAccess.GetVal("TableName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.TableName' is invalid"));
							return false;
						}
						CString oTabName(sVal);
						sVal = oAccess.GetVal("ReplicateTable", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.ReplicateTable' is invalid"));
							return false;
						}
						uint32 bTableReplicative = CString::Atoi(sVal);
						sVal = oAccess.GetVal("WithoutFields", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.WithoutFields' is invalid"));
							return false;
						}
						uint32 bWithout = CString::Atoi(sVal);
						sVal = oAccess.GetVal("Fields", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.Fields' is invalid"));
							return false;
						}
						CString oFields(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("Where", nLength);
						if(sVal && sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbStorage.Where' is invalid"));
							return false;
						}
						CString oWhere(sVal?sVal:(char*)"");
						sVal = oAccess.GetVal("TransferIdx", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbReplication.TransferIdx' is invalid"));
							return false;
						}
						if(!m_pRepItf)
						{
							m_pRepItf = new CMdbRepItf;
							if(!m_pRepItf->Valid())
								return false;
						}
						if(!m_pRepItf->CreateMdbReplicator(oDbName.GetStr(), oTabName.GetStr(), sVal, bTableReplicative?true:false, bWithout?true:false, oFields.GetStr(), oWhere.GetStr()))
							return false;
						bCreateMdbReplicator = true;
					}
				}

				if( (bCreateMdbReplicator || bInitializeMdbStorageAttr) && pConfigSystem->OpenConfig(oAccess, "MdbDomain", true))
				{
					oAccess.OpenIdxVal();
					while(oAccess.Query())
					{
						sVal = oAccess.GetVal("MdbDomain", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.MdbDomain' is invalid"));
							return false;
						}
						uint32 nDomain = CString::Atoi(sVal);
						sVal = oAccess.GetVal("MdbName", nLength);
						if(!sVal || sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.MdbName' is invalid"));
							return false;
						}
						if(bCreateMdbReplicator)
						{
							if(!m_pRepItf->ConfigMdbDomain(sVal, nDomain))
								return false;
							bConfigMdbDomain = true;
						}
						if(bInitializeMdbStorageAttr)
						{
							CString oMdbName(sVal);
							sVal = oAccess.GetVal("OdbcSource", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.OdbcSource' is invalid"));
								return false;
							}
							if(!sVal)
								continue;
							CString oOdbcDsn, oOdbcUser, oOdbcPasswd;
							if(!GetOdbcSourceInfo(sVal, oOdbcDsn, oOdbcUser, oOdbcPasswd))
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.OdbcSource' is invalid"));
								return false;
							}
							sVal = oAccess.GetVal("EventDb", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.EventDb' is invalid"));
								return false;
							}
							CString oEventDb(sVal?sVal:"");
							sVal = oAccess.GetVal("EventTable", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.EventTable' is invalid"));
								return false;
							}
							CString oEventTable(sVal?sVal:"");
							uint32 nSupportStorage = 0;
							sVal = oAccess.GetVal("SupportStorage", nLength);
							if(sVal && sVal[nLength-1])
							{
								FocpLog(FOCP_LOG_ERROR, ("The config 'MdbDomain.SupportStorage' is invalid"));
								return false;
							}
							if(sVal)
								nSupportStorage = CString::Atoi(sVal);
							if(!m_pStoItf->InitializeMdbDataSource(oMdbName.GetStr(), nDomain, (nSupportStorage!=0),
																   oOdbcDsn.GetStr(), oOdbcUser.GetStr(), oOdbcPasswd.GetStr(),
																   oEventDb.GetStr(), oEventTable.GetStr()))
								return false;
							bInitializeMdbDataSource = true;
						}
					}
					if(bConfigMdbDomain && !m_pRepItf->RegisterMdbTransfer())
						return false;
				}
			}
		}

		//Create Remote Memory Database
		if(pConfigSystem->OpenConfig(oAccess, "RemoteMdb", true))
		{
			CString oServerAddr;
			uint32 nServerPort;
			const char* sDbList;
			oAccess.OpenIdxVal();
			while(oAccess.Query())
			{
				sVal = oAccess.GetVal("ServerPort", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerPort' is invalid"));
					return false;
				}
				nServerPort = CString::Atoi(sVal);
				if(!nServerPort || nServerPort > 65535)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerPort' is invalid"));
					return false;
				}
				sVal = oAccess.GetVal("ServerAddr", nLength);
				if(!sVal || !sVal[0] || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.ServerAddr' is invalid"));
					return false;
				}
				oServerAddr = sVal;
				sVal = oAccess.GetVal("MdbList", nLength);
				if(sVal && sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'RemoteMdb.MdbList' is invalid"));
					return false;
				}
				sDbList = sVal;

				if(m_pRdbItf == NULL)
				{
					m_pRdbItf = new CRemoteMdbItf;
					if(!m_pRdbItf->Valid())
						return false;
				}

				void* pRdbList = m_pRdbItf->CreateMdbClient(sDbList, oServerAddr.GetStr(), (uint16)nServerPort);
				if(pRdbList == NULL)
					return false;
				m_oMdbClients.Insert((char*)pRdbList);
			}
		}

		// Create Mdb Server
		if(nMdbSvr)
		{
			CService* pService = CServiceManager::GetInstance()->QueryService("AcmService");
			if(!pService)
			{
				FocpLog(FOCP_LOG_ERROR, ("MdbService need AcmService for MdbSvrModule, but there isn't it"));
				return false;
			}
			if(!Wait(pService, FOCP_SERVICE_INITIALIZED))
				return false;
			if(!pService->HaveAbility(ACM_TCPSVR_ABILITY))
			{
				FocpLog(FOCP_LOG_ERROR, ("MdbService need AcmService's tcp server ability for MdbSvrModule, but there isn't it"));
				return false;
			}
			m_pSvrItf = new CMdbServerItf;
			if(!m_pSvrItf->Valid())
				return false;
		}

		if(!bConfigMdbDomain && m_pRepItf)
		{
			m_pRepItf->CleanupMdbReplication();
			delete m_pStoItf;
			m_pStoItf = NULL;
		}

		if(!bInitializeMdbDataSource && m_pStoItf)
		{
			m_pStoItf->CleanupMdbStorage();
			delete m_pStoItf;
			m_pStoItf = NULL;
		}

		const char* sCreateCode = GetEnvVar("CreateMdbCode");
		if(sCreateCode && sCreateCode[0] == '1')
			CMdb::CreateCppCode();

		return true;
	}
Ejemplo n.º 22
0
void CLogArchiver::GetLogInfo(CLogMsg& oLog, CString &oLogInfo)
{
	CStringFormatter oFmt(&oLogInfo);
	if(m_nFilter & FOCP_LOG_HOST)
		oFmt.Print("%s ", oLog.oHost.GetStr());
	if(m_nFilter & FOCP_LOG_DATE)
	{
		CString oDate;
		CDateTime(oLog.nDate).GetString(oDate);
		oFmt.Print("%s ", oDate.GetStr());
	}
	oFmt.Print("[%s] ", GetLogLevelName(oLog.nLevel));
	if( (m_nFilter & FOCP_LOG_APPN) || (m_nFilter & FOCP_LOG_MODU) )
	{
		oFmt.Print("[");
		if(m_nFilter & FOCP_LOG_APPN)
		{
			oFmt.Print("%u:", oLog.nDMN);
			oFmt.Print("%s:", oLog.oAppName.GetStr());
			oFmt.Print("%u", oLog.nAIN);
			if(m_nFilter & FOCP_LOG_MODU)
				oFmt.Print("-");
		}
		if(m_nFilter & FOCP_LOG_MODU)
			oFmt.Print("%s", oLog.oModuleName.GetStr());
		oFmt.Print("] ");
	}
	if( (m_nFilter & FOCP_LOG_SRCF) || (m_nFilter & FOCP_LOG_FUNC) )
	{
		oFmt.Print("[");
		if(m_nFilter & FOCP_LOG_FUNC)
		{
			oFmt.Print("%s", oLog.oFuncName.GetStr());
			if(m_nFilter & FOCP_LOG_SRCF)
				oFmt.Print("@");
		}
		if(m_nFilter & FOCP_LOG_SRCF)
			oFmt.Print("%s:%u", oLog.oFile.GetStr(), oLog.nLine);
#ifdef WINDOWS
		oFmt.Print("] ->\r\n  ");
#else
		oFmt.Print("] ->\n  ");
#endif
	}
	else
		oFmt.Print("-> ");
	CString oInfo(oLog.oInfo);
	char* pShift = (char*)oInfo.GetStr();
	while(true)
	{
		char* pNewLine = CString::CharOfString(pShift, '\n');
		if(pNewLine)
		{
			pNewLine[0] = '\0';
			if(*(pNewLine-1) == '\r')
				*(pNewLine-1) = '\0';
		}
#ifdef WINDOWS
		oFmt.Print("%s\r\n", pShift);
#else
		oFmt.Print("%s\n", pShift);
#endif
		if(!pNewLine)
			break;
		pShift = pNewLine + 1;
		if(!pShift[0])
			break;
		oFmt.Print("  ");
	}
}
Ejemplo n.º 23
0
const char* CMdb::GetDbList()
{
	return g_oDbList.GetStr();
}
Ejemplo n.º 24
0
static void AcmCmdFunc_LsDomain(CCmdSession* pSession, const char *sCmdLine, const char* sCmdArg)
{
	CArguments oArgs;
	oArgs.SetCmdLine(sCmdLine);
	int32 nArgc = oArgs.GetArgc();
	if(nArgc == 1)
	{
		CVector<uint32> oDomains;
		CAcmUdp::GetAllDomains(oDomains);
		uint32 nSize = oDomains.GetSize();
		pSession->Print("There are %u domains:\r\n", nSize);
		for(uint32 i=0; i<nSize; ++i)
		{
			uint32 nDomain = oDomains[i];
			pSession->Print("\tDomain:%u\r\n", nDomain);
		}
		pSession->Print("\r\n");
	}
	else if(nArgc == 2)
	{
		const char* sArg = oArgs.GetArgv()[1];
		uint32 nDomain = CString::Atoi(sArg);
		CAcmUdp* pUdp = CAcmUdp::QueryUdp(nDomain);
		if(pUdp == NULL)
			pSession->Print("There isn't the domain '%u'\r\n", nDomain);
		else
		{
			if(pUdp->IsMultiCast())
			{
				CIpAddr oAddr;
				CString oFileName;
				uint32 nTTL = pUdp->GetMultiCastAddr(oAddr);
				CFile::GetIpFileName(oAddr, oFileName);
				pSession->Print("The domain %u is multicast domain, and the multicast addr is %s, and the TTL is %u\r\n", nDomain, oFileName.GetStr(), nTTL);
			}
			else
				pSession->Print("The domain %u is unicast domain\r\n", nDomain);
			CAcmService* pService = (CAcmService*)CServiceManager::GetInstance()->QueryService("AcmService");
			pService->SetSession(pSession);
			pUdp->Walk();
			uint32 nSize = pService->GetWalkSize();
			pSession->Print("There are %u nodes in the domain %u\r\n", nSize, nDomain);
		}
	}
}
Ejemplo n.º 25
0
	virtual bool OnInitialize()
	{
		uint32 nLength;
		const char* sVal;
		CTextAccess oAccess;
		CInitConfigSystem* pConfigSystem = CInitConfigSystem::GetInstance();

		if(pConfigSystem->OpenConfig(oAccess, "AcmTcp", true))
		{
			uint32 nPort, nWorkerNum;
			oAccess.OpenIdxVal();
			if(oAccess.Query())
			{
				sVal = oAccess.GetVal("LsnPort", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmTcp.LsnPort' is invalid"));
					return false;
				}
				nPort = CString::Atoi(sVal);
				if(nPort >= 65536)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmTcp.LsnPort(%u)' is invalid", nPort));
					return false;
				}
				sVal = oAccess.GetVal("WorkerNum", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmTcp.WorkerNum' is invalid"));
					return false;
				}
				nWorkerNum = CString::Atoi(sVal);
				if(nPort)
				{
					m_pTcp = CAcmTcpServer::GetInstance();
					if(m_pTcp->Initialize(nPort, nWorkerNum))
						return false;
				}
			}
		}

		if(!pConfigSystem->OpenConfig(oAccess, "AcmApplication"))
			return false;
		oAccess.OpenIdxVal();
		while(oAccess.Query())
		{
			uint32 nAcmDomain, nNode;
			sVal = oAccess.GetVal("AcmDomain", nLength);
			if(!sVal || sVal[nLength-1])
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmApplication.AcmDomain' is invalid"));
				return false;
			}
			nAcmDomain = CString::Atoi(sVal);
			sVal = oAccess.GetVal("Node", nLength);
			if(!sVal || sVal[nLength-1])
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmApplication[%u].Node' is invalid", nAcmDomain));
				return false;
			}
			nNode = CString::Atoi(sVal);
			if(nNode == (uint32)(-1))
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmApplication[%u].Node(%u)' is invalid", nAcmDomain, nNode));
				return false;
			}
			CRbTreeNode* pIt = m_oDomainInfo.Find(nAcmDomain);
			if(pIt != m_oDomainInfo.End())
			{
				CAcmDomain & oDomain = m_oDomainInfo.GetItem(pIt);
				if(oDomain.nNode != nNode)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmApplication[%u] is repeated defined", nAcmDomain));
					return false;
				};
			}
			else
			{
				CAcmDomain & oDomain = m_oDomainInfo[nAcmDomain];
				oDomain.nNode = nNode;
				oDomain.nDomainType = 0;
				oDomain.pUdp = NULL;
				oDomain.pSerialModule = NULL;
			}
		}
		if(m_oDomainInfo.GetSize() == 0)
		{
			FocpLog(FOCP_LOG_SYSLOG, ("AcmApplication is empty"));
			return true;
		}
		if(!pConfigSystem->OpenConfig(oAccess, "AcmDomain"))
			return false;
		oAccess.OpenIdxVal();
		bool bHaveAcmMultiCast = false, bHaveAcmUniCast = false;
		CRbTreeNode* pIt = m_oDomainInfo.First();
		CRbTreeNode* pEnd = m_oDomainInfo.End();
		for(; pIt!=pEnd; pIt=m_oDomainInfo.GetNext(pIt))
		{
			uint32 nAcmDomain = m_oDomainInfo.GetKey(pIt);
			CAcmDomain & oDomain = m_oDomainInfo.GetItem(pIt);
			CFormatString oIdx;
			oIdx.Print("%u", nAcmDomain);
			oAccess.OpenIdxVal();
			if(!oAccess.SetIdxVal("AcmDomain", oIdx.GetStr()))
			{
				FocpLog(FOCP_LOG_ERROR, ("AcmDomain.AcmDomain isn't existed"));
				return false;
			}
			if(!oAccess.Query())
			{
				FocpLog(FOCP_LOG_ERROR, ("AcmDomain[%u] isn't existed", nAcmDomain));
				return false;
			}
			sVal = oAccess.GetVal("DomainType", nLength);
			if(!sVal || sVal[nLength-1])
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].DomainType' is invalid", nAcmDomain));
				return false;
			}
			oDomain.nDomainType = CString::Atoi(sVal);
			if(oDomain.nDomainType == 1)
				bHaveAcmMultiCast = true;
			else if(oDomain.nDomainType == 2)
				bHaveAcmUniCast = true;
			else
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].DomainType(%u) is invalid", nAcmDomain, oDomain.nDomainType));
				return false;
			}
			sVal = oAccess.GetVal("SerialAbility", nLength);
			if(!sVal || sVal[nLength-1])
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].SerialAbility' is invalid", nAcmDomain));
				return false;
			}
			oDomain.nSerialAbility = CString::Atoi(sVal);
			if(oDomain.nSerialAbility > 6 || (oDomain.nDomainType == 1 && (oDomain.nSerialAbility & ASM_SUPPORT_ACK)))
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].SerialAbility(%u) is invalid", nAcmDomain, oDomain.nSerialAbility));
				return false;
			}
			sVal = oAccess.GetVal("SerialCapacity", nLength);
			if(!sVal || sVal[nLength-1])
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].SerialCapacity' is invalid", nAcmDomain));
				return false;
			}
			oDomain.nSerialCapacity = CString::Atoi(sVal);
			sVal = oAccess.GetVal("SerialMaxAck", nLength);
			if(!sVal || sVal[nLength-1])
			{
				FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].SerialMaxAck' is invalid", nAcmDomain));
				return false;
			}
			oDomain.nSerialMaxAck = CString::Atoi(sVal);
		}
		if(bHaveAcmMultiCast)
		{
			if(!pConfigSystem->OpenConfig(oAccess, "AcmMultiCast"))
				return false;
			pIt = m_oDomainInfo.First();
			for(; pIt!=pEnd; pIt=m_oDomainInfo.GetNext(pIt))
			{
				CAcmDomain & oDomain = m_oDomainInfo.GetItem(pIt);
				if(oDomain.nDomainType == 2)
					continue;
				uint32 nPort, nAcmDomain = m_oDomainInfo.GetKey(pIt);
				CFormatString oIdx;
				oAccess.OpenIdxVal();
				oIdx.Print("%u", nAcmDomain);
				if(!oAccess.SetIdxVal("AcmDomain", oIdx.GetStr()))
				{
					FocpLog(FOCP_LOG_ERROR, ("AcmMultiCast.AcmDomain isn't existed"));
					return false;
				}
				if(!oAccess.Query())
				{
					FocpLog(FOCP_LOG_ERROR, ("AcmMultiCast[%u] isn't existed", nAcmDomain));
					return false;
				}
				sVal = oAccess.GetVal("MultiCastAddr", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].MultiCastAddr' is invalid", nAcmDomain));
					return false;
				}
				oDomain.nMultiCastAddr = CFile::GetIpAddr(sVal);
				if(!CFile::IsMulticastAddr(oDomain.nMultiCastAddr))
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].MultiCastAddr(%s) is invalid", nAcmDomain, sVal));
					return false;
				}
				sVal = oAccess.GetVal("MultiCastPort", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].MultiCastPort' is invalid", nAcmDomain));
					return false;
				}
				nPort = CString::Atoi(sVal);
				if(nPort >= 65536 || nPort == 0)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].MultiCastPort(%s) is invalid", nAcmDomain, sVal));
					return false;
				}
				oDomain.nMultiCastPort = nPort;
				sVal = oAccess.GetVal("MultiCastTTL", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].MultiCastTTL' is invalid", nAcmDomain));
					return false;
				}
				nPort = CString::Atoi(sVal);
				if(nPort >= 256 || nPort == 0)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].MultiCastTTL(%s) is invalid", nAcmDomain, sVal));
					return false;
				}
				oDomain.nMultiCastTTL = nPort;
				sVal = oAccess.GetVal("AllowLoopBack", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].AllowLoopBack' is invalid", nAcmDomain));
					return false;
				}
				nPort = CString::Atoi(sVal);
				if(nPort)
					oDomain.bAllowLoop = 1;
				else
					oDomain.bAllowLoop = 0;
				sVal = oAccess.GetVal("InterfaceAddr", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].InterfaceAddr' is invalid", nAcmDomain));
					return false;
				}
				oDomain.nMcItfAddr = CFile::GetIpAddr(sVal);
				if(!CFile::CheckHostIp(oDomain.nMcItfAddr))
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].InterfaceAddr(%s)' is invalid", nAcmDomain, sVal));
					return false;
				}
				sVal = oAccess.GetVal("InterfacePort", nLength);
				if(!sVal || sVal[nLength-1])
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].InterfacePort' is invalid", nAcmDomain));
					return false;
				}
				nPort = CString::Atoi(sVal);
				if(nPort >= 65536)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmDomain[%u].InterfacePort(%s)' is invalid", nAcmDomain, sVal));
					return false;
				}
				oDomain.nMcItfPort = nPort;
			}
		}
		if(bHaveAcmUniCast)
		{
			if(!pConfigSystem->OpenConfig(oAccess, "AcmUniCast"))
				return false;
			pIt = m_oDomainInfo.First();
			for(; pIt!=pEnd; pIt=m_oDomainInfo.GetNext(pIt))
			{
				CAcmDomain & oDomain = m_oDomainInfo.GetItem(pIt);
				if(oDomain.nDomainType == 1)
					continue;
				uint32 nAcmDomain = m_oDomainInfo.GetKey(pIt);
				CFormatString oIdx;
				oAccess.OpenIdxVal();
				oIdx.Print("%u", nAcmDomain);
				if(!oAccess.SetIdxVal("AcmDomain", oIdx.GetStr()))
				{
					FocpLog(FOCP_LOG_ERROR, ("AcmUniCast.AcmDomain isn't existed"));
					return false;
				}
				while(oAccess.Query())
				{
					sVal = oAccess.GetVal("Node", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u].Node is invalid", nAcmDomain));
						return false;
					}
					uint32 nNode = CString::Atoi(sVal);
					CRbTreeNode* pNode = oDomain.oUniCastInfo.Find(nNode);
					if(pNode != oDomain.oUniCastInfo.End())
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u].Node(%u) is repeated defined", nAcmDomain, nNode));
						return false;
					}
					CIpAddr & oIpAddr = oDomain.oUniCastInfo[nNode];
					sVal = oAccess.GetVal("UniCastAddr", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u-%u].UniCastAddr is invalid", nAcmDomain, nNode));
						return false;
					}
					oIpAddr.nAddr = CFile::GetIpAddr(sVal);
					if(CFile::IsMulticastAddr(oIpAddr.nAddr))
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u-%u].UniCastAddr(%s) is invalid", nAcmDomain, nNode, sVal));
						return false;
					}
					if(nNode == oDomain.nNode && !CFile::CheckHostIp(oIpAddr.nAddr))
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u-%u].UniCastAddr(%s) is invalid", nAcmDomain, nNode, sVal));
						return false;
					}
					sVal = oAccess.GetVal("UniCastPort", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u-%u].UniCastPort is invalid", nAcmDomain, nNode));
						return false;
					}
					uint32 nPort = CFile::GetIpAddr(sVal);
					if(nPort >= 65536)
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u-%u].UniCastPort(%u) is invalid", nAcmDomain, nNode, nPort));
						return false;
					}
					oIpAddr.nPort = nPort;
				}
				if(oDomain.oUniCastInfo.GetSize() == 0)
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u] isn't existed", nAcmDomain));
					return false;
				}
				if(oDomain.oUniCastInfo.Find(oDomain.nNode) == oDomain.oUniCastInfo.End())
				{
					FocpLog(FOCP_LOG_ERROR, ("The config 'AcmUniCast[%u-%u] isn't existed", nAcmDomain, oDomain.nNode));
					return false;
				}
			}
		}
		pIt = m_oDomainInfo.First();
		for(; pIt!=pEnd; pIt=m_oDomainInfo.GetNext(pIt))
		{
			CAcmUdp* pUdp;
			uint32 nDomain = m_oDomainInfo.GetKey(pIt);
			CAcmDomain& oDomain = m_oDomainInfo.GetItem(pIt);
			if(oDomain.nDomainType == 1)//¶à²¥
			{
				pUdp = new CAcmUdp(this, nDomain, oDomain.nNode, true, true);
				pUdp->AddNode(oDomain.nNode, oDomain.nMcItfAddr, oDomain.nMcItfPort);
				if(!pUdp->InitMultiCast(oDomain.nMultiCastPort, oDomain.nMultiCastAddr,
					oDomain.nMultiCastTTL, oDomain.bAllowLoop?true:false))
				{
					delete pUdp;
					CString oAddrName;
					CIpAddr oIpAddr = {oDomain.nMultiCastAddr, oDomain.nMultiCastPort};
					CFile::GetIpFileName(oIpAddr, oAddrName);
					FocpLog(FOCP_LOG_ERROR, ("Initialize AcmMultiCast(Domain=%u, Node=%u, MultiCastAddr=%s) failure", nDomain, oDomain.nNode, oAddrName.GetStr()));
					return false;
				}
			}
			else
			{
				uint16 nUniPort = oDomain.oUniCastInfo[oDomain.nNode].nPort;
				pUdp = new CAcmUdp(this, nDomain, oDomain.nNode, false, true);
				if(!pUdp->InitUniCast(nUniPort))
				{
					delete pUdp;
					FocpLog(FOCP_LOG_ERROR, ("Initialize AcmUniCast(Domain=%u, Node=%u, UniCastPort=%u16) failure", nDomain, oDomain.nNode, nUniPort));
					return false;
				}
				CRbTreeNode* pNode = oDomain.oUniCastInfo.First();
				CRbTreeNode* pEnd2 = oDomain.oUniCastInfo.End();
				for(; pNode!=pEnd2; pNode=oDomain.oUniCastInfo.GetNext(pNode))
				{
					CIpAddr &oAddr = oDomain.oUniCastInfo.GetItem(pNode);
					if(!pUdp->AddNode(oDomain.oUniCastInfo.GetKey(pNode), oAddr.nAddr, oAddr.nPort))
					{
						delete pUdp;
						return false;
					}
				}
			}
			oDomain.pUdp = pUdp;
			if(oDomain.nSerialAbility)
				oDomain.pSerialModule = new CAcmSequenceModule(pUdp, oDomain.nSerialAbility, oDomain.nSerialCapacity, oDomain.nSerialMaxAck);
		}

		if(m_oDomainInfo.GetSize())
		{
			m_pTokenMoudle = CAcmTokenModule::GetInstance(false);
			if(pConfigSystem->OpenConfig(oAccess, "AcmVip"))
			{
				oAccess.OpenIdxVal();
				while(oAccess.Query())
				{
					CIpAddress oAddr;
					sVal = oAccess.GetVal("Domain", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.Domain' is invalid"));
						return false;
					}
					uint32 nDomain = CString::Atoi(sVal);
					if(CAcmUdp::QueryUdp(nDomain) == NULL)
						continue;
					sVal = oAccess.GetVal("Vip", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.Vip' is invalid"));
						return false;
					}
					if(!oAddr.SetIp(sVal, false, false, false))
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.Vip' is invalid"));
						return false;
					}
					CString oVip(sVal);
					sVal = oAccess.GetVal("Mask", nLength);
					if(sVal)
					{
						if(sVal[nLength-1])
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.Mask' is invalid"));
							return false;
						}
						if(!oAddr.SetIp(sVal, false, false, false))
						{
							FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.Mask' is invalid"));
							return false;
						}
					}
					CString oMask(sVal);
					sVal = oAccess.GetVal("IfMac", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.IfMac' is invalid"));
						return false;
					}
					CString oIfMac(sVal);
					sVal = oAccess.GetVal("Default", nLength);
					if(!sVal || sVal[nLength-1])
					{
						FocpLog(FOCP_LOG_ERROR, ("The config 'AcmVip.Default' is invalid"));
						return false;
					}
					uint32 nDefault = CString::Atoi(sVal);
					DelIpv4Addr(oVip.GetStr());
					if(!m_pVipModule)
						m_pVipModule = CAcmVipModule::GetInstance();
					if(!m_pVipModule->AddToken(nDomain, oVip.GetStr(), oMask.GetStr(), oIfMac.GetStr(), nDefault))
					{
						FocpError(("Add vip(%s/%s on %s) failure", oVip.GetStr(), oMask.GetStr(), oIfMac.GetStr()));
						return false;
					}
				}
			}
		}

		CCmdSystem* pCmdSys = CCmdSystem::GetInstance();
		pCmdSys->RegisterCmd("/Acm/LsDomain", "LsDomain [DomainId] <CR>:\r\n\t list the domain information", AcmCmdFunc_LsDomain);
		pCmdSys->RegisterCmd("/Acm/LsSerial", "LsSerial [DomainId] <CR>:\r\n\t list the domain serial information", AcmCmdFunc_LsSerial);
		pCmdSys->RegisterCmd("/Acm/LsToken", "LsToken <CR>:\r\n\t list token information", AcmCmdFunc_LsToken);

		return true;
	}
Ejemplo n.º 26
0
CString CSqlDataBase::GetRecordText(CMdbResult* pRecord, CString& oFieldList)
{
    char sName[MDB_NAME_MAXLEN+1];
    CString oRet;
    const char* s = oFieldList.GetStr();
    uint32 nCount = 0;
    while(s)
    {
        char* pShift = (char*)CString::CharOfString(s, ',');
        if(pShift)
        {
            uint32 nLen = pShift - s;
            CBinary::MemoryCopy(sName, s, nLen);
            sName[nLen] = 0;
        }
        else
            CString::StringCopy(sName, s);
        s = (const char*)pShift;
        if(s) s += 2;
        if(nCount)
            oRet += ", ";

        uint32 nFieldNo = m_oSelect.m_pAccess->GetFieldNo((const char*)sName);
        if(nFieldNo == (uint32)(-1))
            oRet += "NULL";
        else
        {
            uint32 nSize = pRecord->GetStringSize(nFieldNo);
            char * pStr = new char[nSize+1];
            pRecord->GetAsString(nFieldNo, pStr);
            if(!pStr[0])
                oRet += "NULL";
            else
            {
                char* pTmp = pStr;
                while(pTmp[0])
                {
                    switch(pTmp[0])
                    {
//					case ' ':   oRet += "\\w"; break;
                    case '\r':
                        oRet += "\\r";
                        break;
                    case '\n':
                        oRet += "\\n";
                        break;
                    case '\f':
                        oRet += "\\f";
                        break;
                    case '\v':
                        oRet += "\\v";
                        break;
                    case '\t':
                        oRet += "\\t";
                        break;
                    case '\a':
                        oRet += "\\a";
                        break;
                    case '\b':
                        oRet += "\\b";
                        break;
                    case '\\':
                        oRet += "\\\\";
                        break;
                    default:
                        if(pTmp[0] == ',' || !isprint(pTmp[0]))
                        {
                            char cBuf[6];
                            StringPrint(cBuf, "\\X%2X", (uint32)(uint8)pTmp[0]);
                            oRet += cBuf;
                        }
                        else
                            oRet += pTmp[0];
                        break;
                    }
                    ++pTmp;
                }
            }
            delete[] pStr;
        }
        ++nCount;
    }
    return oRet;
}
Ejemplo n.º 27
0
void CSqlDataBase::OrderBy(const CString& oIdxName, bool bAsc)
{
    if(m_oSelect.m_pAccess && !m_oSelect.m_pAccess->SetOrderBy(oIdxName.GetStr(), bAsc))
        FocpCmdLogEx("SQL", FOCP_LOG_WARNING, ("CSqlDataBase::OrderBy(%s.%s.%s) failure", m_pDb->GetDbName(), m_oSelect.m_oName.GetStr(), oIdxName.GetStr()));
}