中间件标准版5.1git,去除基础模块

CfgSipAccount.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include "StdAfx.h"
  2. #include "CfgSipAccount.h"
  3. CCfgSipAccount::CCfgSipAccount(void)
  4. {
  5. }
  6. CCfgSipAccount::~CCfgSipAccount(void)
  7. {
  8. __free();
  9. }
  10. /*****************************************************************
  11. **【函数名称】 __free
  12. **【函数功能】 释放所有sip账户信息
  13. **【参数】
  14. **【返回值】
  15. ****************************************************************/
  16. void CCfgSipAccount::__free( void )
  17. {
  18. while(m_nCount > 0)
  19. {
  20. SIP_ACCOUNT* pAccount = RemoveHead();
  21. ASSERT(pAccount != NULL);
  22. delete pAccount;
  23. }
  24. }
  25. /*****************************************************************
  26. **【函数名称】 load
  27. **【函数功能】 加载所有sip账户信息
  28. **【参数】
  29. **【返回值】
  30. ****************************************************************/
  31. bool CCfgSipAccount::load( void )
  32. {
  33. long Count = COtlConnection::GetOtlInstence()->GetSingleDataInt(_T("select count(*) from information_schema.columns where table_name = 'conf_sip_account' and column_name = 'IsDynamicGw'"));
  34. COtlRecordset* pAccountRcd = NULL;
  35. BOOL bAddOk = FALSE;
  36. if (Count == 1)
  37. {
  38. 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"));
  39. }
  40. else if (Count == 0)
  41. {
  42. bAddOk = COtlConnection::GetOtlInstence()->ExecCommand(_T("ALTER TABLE conf_sip_account ADD IsDynamicGw VARCHAR (10) NOT NULL DEFAULT 'false'"));
  43. if (bAddOk == TRUE)
  44. {
  45. 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"));
  46. }
  47. else
  48. {
  49. 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"));
  50. }
  51. }
  52. if (NULL == pAccountRcd)
  53. return false;
  54. while (!pAccountRcd->IsEOF())
  55. {
  56. SIP_ACCOUNT* pSipAccount = new SIP_ACCOUNT;
  57. ASSERT(pSipAccount != NULL);
  58. ZeroMemory(pSipAccount, sizeof(SIP_ACCOUNT));
  59. pAccountRcd->MoveNextRow();
  60. pSipAccount->Id = pAccountRcd->GetValueIntByIndex(1);
  61. lstrcpy(pSipAccount->Account, pAccountRcd->GetValueStrByIndex(2));
  62. lstrcpy(pSipAccount->AuthAccount, pAccountRcd->GetValueStrByIndex(3));
  63. lstrcpy(pSipAccount->Password, pAccountRcd->GetValueStrByIndex(4));
  64. lstrcpy(pSipAccount->Proxy, pAccountRcd->GetValueStrByIndex(5));
  65. pSipAccount->ProxyPort = pAccountRcd->GetValueIntByIndex(6);
  66. if (lstrcmp(CONST_DEF_SIP_REG_TRUE, pAccountRcd->GetValueStrByIndex(7)) == 0)
  67. pSipAccount->IsReg = true;
  68. else
  69. pSipAccount->IsReg = false;
  70. pSipAccount->RegInterval = pAccountRcd->GetValueIntByIndex(8);
  71. if (Count == 1 || bAddOk == TRUE)
  72. {
  73. if (lstrcmp(_T("true"), pAccountRcd->GetValueStrByIndex(9)) == 0)
  74. pSipAccount->IsDynamicGw = true;
  75. else
  76. pSipAccount->IsDynamicGw = false;
  77. }
  78. else
  79. {
  80. pSipAccount->IsDynamicGw = false;
  81. }
  82. AddTail(pSipAccount);
  83. } // end while
  84. COtlRecordset::DestroyInstance(pAccountRcd); // 释放记录集
  85. return true;
  86. }
  87. void CCfgSipAccount::unload(void)
  88. {
  89. __free();
  90. }
  91. /*****************************************************************
  92. **【函数名称】 getAccount
  93. **【函数功能】 获取指定sip账户信息
  94. **【参数】
  95. **【返回值】
  96. ****************************************************************/
  97. SIP_ACCOUNT* CCfgSipAccount::getAccount( int AccountId )
  98. {
  99. CNode* pNodeCur = m_pNodeHead;
  100. while(pNodeCur != NULL)
  101. {
  102. SIP_ACCOUNT* pAccount = pNodeCur->data;
  103. ASSERT(pAccount != NULL);
  104. if(pAccount->Id == AccountId)
  105. return pAccount;
  106. pNodeCur = pNodeCur->pNext;
  107. }
  108. return NULL;
  109. }