#include "StdAfx.h" #include "CfgSipAccount.h" CCfgSipAccount::CCfgSipAccount(void) { } CCfgSipAccount::~CCfgSipAccount(void) { __free(); } /***************************************************************** **【函数名称】 __free **【函数功能】 释放所有sip账户信息 **【参数】 **【返回值】 ****************************************************************/ void CCfgSipAccount::__free(void) { while (m_nCount > 0) { SIP_ACCOUNT* pAccount = RemoveHead(); ASSERT(pAccount != NULL); delete pAccount; } } /***************************************************************** **【函数名称】 load **【函数功能】 加载所有sip账户信息 **【参数】 **【返回值】 ****************************************************************/ bool CCfgSipAccount::load(void) { long Count = 0; if (DB_MySQL == COtlConnection::GetOtlInstence()->GetDatabaseType() || DB_Oracle == COtlConnection::GetOtlInstence()->GetDatabaseType()) { Count = COtlConnection::GetOtlInstence()->GetSingleDataInt(_T("SELECT COUNT(*) FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'CONF_SIP_ACCOUNT' AND COLUMN_NAME ='ISDYNAMICGW'")); } else if (DB_SQLServer == COtlConnection::GetOtlInstence()->GetDatabaseType()) { Count = COtlConnection::GetOtlInstence()->GetSingleDataInt(_T("select count(*) from information_schema.columns where table_name = 'conf_sip_account' and column_name = 'IsDynamicGw'")); } else { return false; } COtlRecordset* pAccountRcd = NULL; BOOL bAddOk = FALSE; if (Count == 1) { pAccountRcd = COtlConnection::GetOtlInstence()->QueryRecords(_T("SELECT id, account, auth_account, password, proxy_addr, proxy_port, reg, reg_interval, IsDynamicGw FROM conf_sip_account ORDER BY id ASC")); } else if (Count == 0) { bAddOk = COtlConnection::GetOtlInstence()->ExecCommand(_T("ALTER TABLE conf_sip_account ADD IsDynamicGw VARCHAR (10) DEFAULT 'false' NOT NULL")); if (bAddOk == TRUE) { pAccountRcd = COtlConnection::GetOtlInstence()->QueryRecords(_T("SELECT id, account, auth_account, password, proxy_addr, proxy_port, reg, reg_interval, IsDynamicGw FROM conf_sip_account ORDER BY id ASC")); } else { pAccountRcd = COtlConnection::GetOtlInstence()->QueryRecords(_T("SELECT id, account, auth_account, password, proxy_addr, proxy_port, reg, reg_interval FROM conf_sip_account ORDER BY id ASC")); } } if (NULL == pAccountRcd) return false; while (!pAccountRcd->IsEOF()) { SIP_ACCOUNT* pSipAccount = new SIP_ACCOUNT; ASSERT(pSipAccount != NULL); ZeroMemory(pSipAccount, sizeof(SIP_ACCOUNT)); pAccountRcd->MoveNextRow(); pSipAccount->Id = pAccountRcd->GetValueIntByIndex(1); lstrcpy(pSipAccount->Account, pAccountRcd->GetValueStrByIndex(2)); lstrcpy(pSipAccount->AuthAccount, pAccountRcd->GetValueStrByIndex(3)); lstrcpy(pSipAccount->Password, pAccountRcd->GetValueStrByIndex(4)); lstrcpy(pSipAccount->Proxy, pAccountRcd->GetValueStrByIndex(5)); pSipAccount->ProxyPort = pAccountRcd->GetValueIntByIndex(6); if (lstrcmp(CONST_DEF_SIP_REG_TRUE, pAccountRcd->GetValueStrByIndex(7)) == 0) pSipAccount->IsReg = true; else pSipAccount->IsReg = false; pSipAccount->RegInterval = pAccountRcd->GetValueIntByIndex(8); if (Count == 1 || bAddOk == TRUE) { if (lstrcmp(_T("true"), pAccountRcd->GetValueStrByIndex(9)) == 0) pSipAccount->IsDynamicGw = true; else pSipAccount->IsDynamicGw = false; } else { pSipAccount->IsDynamicGw = false; } AddTail(pSipAccount); } // end while COtlRecordset::DestroyInstance(pAccountRcd); // 释放记录集 return true; } void CCfgSipAccount::unload(void) { __free(); } /***************************************************************** **【函数名称】 getAccount **【函数功能】 获取指定sip账户信息 **【参数】 **【返回值】 ****************************************************************/ SIP_ACCOUNT* CCfgSipAccount::getAccount(int AccountId) { CNode* pNodeCur = m_pNodeHead; while (pNodeCur != NULL) { SIP_ACCOUNT* pAccount = pNodeCur->data; ASSERT(pAccount != NULL); if (pAccount->Id == AccountId) return pAccount; pNodeCur = pNodeCur->pNext; } return NULL; }