NetConfig.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #include "NetConfig.h"
  2. #include "ErrorCode.h"
  3. #include "PhmsLogger.h"
  4. #include "Util.h"
  5. CNetConfig::CNetConfig(void):m_nPort(0), m_enumProxyType(NO_PROXY), m_nProxyPort(0)
  6. {
  7. }
  8. CNetConfig::~CNetConfig(void)
  9. {
  10. }
  11. CNetConfig::CNetConfig(bool bSsl, string stringAddr, unsigned short nPort, EnumProxyType enumProxyType, string stringProxyAddr, unsigned short nProxyPort,
  12. string stringProxyUsername, string stringProxyPassword, string stringUrl):m_bSsl(bSsl), m_stringAddr(stringAddr), m_nPort(nPort),
  13. m_enumProxyType(enumProxyType), m_stringProxyAddr(stringProxyAddr), m_nProxyPort(nProxyPort), m_stringProxyUsername(stringProxyUsername),
  14. m_stringProxyPassword(stringProxyPassword), m_stringUrl(stringUrl)
  15. {
  16. }
  17. //Setter
  18. void CNetConfig::SetSsl(bool bSsl)
  19. {
  20. m_bSsl = bSsl;
  21. }
  22. void CNetConfig::SetAddr(string stringAddr)
  23. {
  24. m_stringAddr = stringAddr;
  25. }
  26. void CNetConfig::SetHost(string stringHost)
  27. {
  28. m_stringHost = stringHost;
  29. }
  30. void CNetConfig::SetPort(unsigned short nPort)
  31. {
  32. m_nPort = nPort;
  33. }
  34. void CNetConfig::SetProxyType(EnumProxyType nProxyType)
  35. {
  36. m_enumProxyType = nProxyType;
  37. }
  38. void CNetConfig::SetProxyAddr(string stringProxyAddr)
  39. {
  40. m_stringProxyAddr = stringProxyAddr;
  41. }
  42. void CNetConfig::SetProxyPort(unsigned short nProxyPort)
  43. {
  44. m_nProxyPort = nProxyPort;
  45. }
  46. void CNetConfig::SetProxyUsername(string stringProxyUsername)
  47. {
  48. m_stringProxyUsername = stringProxyUsername;
  49. }
  50. void CNetConfig::SetProxyPassword(string stringProxyPassword)
  51. {
  52. m_stringProxyPassword = stringProxyPassword;
  53. }
  54. void CNetConfig::SetUrl(string stringUrl)
  55. {
  56. m_stringUrl = stringUrl;
  57. }
  58. void CNetConfig::SetIp(string stringIp)
  59. {
  60. m_stringIp = stringIp;
  61. }
  62. //Getter
  63. bool CNetConfig::GetSsl()
  64. {
  65. return m_bSsl;
  66. }
  67. string CNetConfig::GetAddr()
  68. {
  69. return m_stringAddr;
  70. }
  71. string CNetConfig::GetHost()
  72. {
  73. return m_stringHost;
  74. }
  75. unsigned short CNetConfig::GetPort()
  76. {
  77. return m_nPort;
  78. }
  79. EnumProxyType CNetConfig::GetPrpxyType()
  80. {
  81. return m_enumProxyType;
  82. }
  83. string CNetConfig::GetProxyAddr()
  84. {
  85. return m_stringProxyAddr;
  86. }
  87. unsigned short CNetConfig::GetProxyPort()
  88. {
  89. return m_nProxyPort;
  90. }
  91. string CNetConfig::GetProxyUsername()
  92. {
  93. return m_stringProxyUsername;
  94. }
  95. string CNetConfig::GetProxyPassword()
  96. {
  97. return m_stringProxyPassword;
  98. }
  99. string CNetConfig::GetUrl()
  100. {
  101. return m_stringUrl;
  102. }
  103. string CNetConfig::GetIp()
  104. {
  105. return m_stringIp;
  106. }
  107. bool CNetConfig::ValidatePort()
  108. {
  109. if(m_nPort>=1 && m_nPort<=65535)
  110. {
  111. if(m_enumProxyType == HTTP_PROXY || m_enumProxyType == SOCK_PROXY)
  112. {
  113. if(m_nProxyPort>1 && m_nProxyPort<=65535)
  114. {
  115. return true;
  116. }
  117. else
  118. {
  119. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_PORT), __FUNCTION__, __FILE__, __LINE__);
  120. return false;
  121. }
  122. }
  123. }
  124. return true;
  125. }
  126. bool CNetConfig::ValidAddrAndUrl()
  127. {
  128. if(m_stringAddr.size() == 0)
  129. {
  130. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_IP), __FUNCTION__, __FILE__, __LINE__);
  131. return false;
  132. }
  133. if(m_stringHost.size() == 0)
  134. {
  135. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_IP), __FUNCTION__, __FILE__, __LINE__);
  136. return false;
  137. }
  138. if(m_stringUrl.size() == 0)
  139. {
  140. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_URL), __FUNCTION__, __FILE__, __LINE__);
  141. return false;
  142. }
  143. if(m_enumProxyType == HTTP_PROXY || m_enumProxyType == SOCK_PROXY)
  144. {
  145. if(m_stringProxyAddr.size() == 0)
  146. {
  147. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_NO_IP), __FUNCTION__, __FILE__, __LINE__);
  148. return false;
  149. }
  150. }
  151. return true;
  152. }
  153. bool CNetConfig::ValidateProxyInfo()
  154. {
  155. if(m_enumProxyType != HTTP_PROXY && m_enumProxyType != SOCK_PROXY)
  156. {
  157. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
  158. return false;
  159. }
  160. if(m_stringProxyAddr.size() == 0)
  161. {
  162. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
  163. return false;
  164. }
  165. if(m_nProxyPort>1 && m_nProxyPort<=65535)
  166. {
  167. return true;
  168. }
  169. CPhmsLogger::GetPhmsLogger()->WriteLog(CUtil::GetErrorMsg(COMMON_PROXY_INFO_ERROR), __FUNCTION__, __FILE__, __LINE__);
  170. return false;
  171. }