| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- #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 = COtlConnection::GetOtlInstence()->GetSingleDataInt(_T("select count(*) from information_schema.columns where table_name = 'conf_sip_account' and column_name = 'IsDynamicGw'"));
- 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) NOT NULL DEFAULT 'false'"));
- 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;
- }
|