多数据源中间件标准版1.0

CfgSipAccount.cpp 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 = 0;
  34. if (DB_MySQL == COtlConnection::GetOtlInstence()->GetDatabaseType() || DB_Oracle == COtlConnection::GetOtlInstence()->GetDatabaseType())
  35. {
  36. Count = COtlConnection::GetOtlInstence()->GetSingleDataInt(_T("SELECT COUNT(*) FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'CONF_SIP_ACCOUNT' AND COLUMN_NAME ='ISDYNAMICGW'"));
  37. }
  38. else if (DB_SQLServer == COtlConnection::GetOtlInstence()->GetDatabaseType())
  39. {
  40. Count = COtlConnection::GetOtlInstence()->GetSingleDataInt(_T("select count(*) from information_schema.columns where table_name = 'conf_sip_account' and column_name = 'IsDynamicGw'"));
  41. }
  42. else
  43. {
  44. return false;
  45. }
  46. COtlRecordset* pAccountRcd = NULL;
  47. BOOL bAddOk = FALSE;
  48. if (Count == 1)
  49. {
  50. 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"));
  51. }
  52. else if (Count == 0)
  53. {
  54. bAddOk = COtlConnection::GetOtlInstence()->ExecCommand(_T("ALTER TABLE conf_sip_account ADD IsDynamicGw VARCHAR (10) DEFAULT 'false' NOT NULL"));
  55. if (bAddOk == TRUE)
  56. {
  57. 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"));
  58. }
  59. else
  60. {
  61. 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"));
  62. }
  63. }
  64. if (NULL == pAccountRcd)
  65. return false;
  66. while (!pAccountRcd->IsEOF())
  67. {
  68. SIP_ACCOUNT* pSipAccount = new SIP_ACCOUNT;
  69. ASSERT(pSipAccount != NULL);
  70. ZeroMemory(pSipAccount, sizeof(SIP_ACCOUNT));
  71. pAccountRcd->MoveNextRow();
  72. pSipAccount->Id = pAccountRcd->GetValueIntByIndex(1);
  73. lstrcpy(pSipAccount->Account, pAccountRcd->GetValueStrByIndex(2));
  74. lstrcpy(pSipAccount->AuthAccount, pAccountRcd->GetValueStrByIndex(3));
  75. lstrcpy(pSipAccount->Password, pAccountRcd->GetValueStrByIndex(4));
  76. lstrcpy(pSipAccount->Proxy, pAccountRcd->GetValueStrByIndex(5));
  77. pSipAccount->ProxyPort = pAccountRcd->GetValueIntByIndex(6);
  78. if (lstrcmp(CONST_DEF_SIP_REG_TRUE, pAccountRcd->GetValueStrByIndex(7)) == 0)
  79. pSipAccount->IsReg = true;
  80. else
  81. pSipAccount->IsReg = false;
  82. pSipAccount->RegInterval = pAccountRcd->GetValueIntByIndex(8);
  83. if (Count == 1 || bAddOk == TRUE)
  84. {
  85. if (lstrcmp(_T("true"), pAccountRcd->GetValueStrByIndex(9)) == 0)
  86. pSipAccount->IsDynamicGw = true;
  87. else
  88. pSipAccount->IsDynamicGw = false;
  89. }
  90. else
  91. {
  92. pSipAccount->IsDynamicGw = false;
  93. }
  94. AddTail(pSipAccount);
  95. } // end while
  96. COtlRecordset::DestroyInstance(pAccountRcd); // 释放记录集
  97. return true;
  98. }
  99. void CCfgSipAccount::unload(void)
  100. {
  101. __free();
  102. }
  103. /*****************************************************************
  104. **【函数名称】 getAccount
  105. **【函数功能】 获取指定sip账户信息
  106. **【参数】
  107. **【返回值】
  108. ****************************************************************/
  109. SIP_ACCOUNT* CCfgSipAccount::getAccount(int AccountId)
  110. {
  111. CNode* pNodeCur = m_pNodeHead;
  112. while (pNodeCur != NULL)
  113. {
  114. SIP_ACCOUNT* pAccount = pNodeCur->data;
  115. ASSERT(pAccount != NULL);
  116. if (pAccount->Id == AccountId)
  117. return pAccount;
  118. pNodeCur = pNodeCur->pNext;
  119. }
  120. return NULL;
  121. }