中间件底层,websocket

CfgSipAccount.cpp 4.2KB

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