HPSocket-SSL.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright: JessMA Open Source (ldcsaa@gmail.com)
  3. *
  4. * Version : 3.6.1
  5. * Author : Bruce Liang
  6. * Website : http://www.jessma.org
  7. * Project : https://github.com/ldcsaa
  8. * Blog : http://www.cnblogs.com/ldcsaa
  9. * Wiki : http://www.oschina.net/p/hp-socket
  10. * QQ Group : 75375912
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #include "stdafx.h"
  25. #include "HPSocket-SSL.h"
  26. #include "TcpServer.h"
  27. #include "TcpAgent.h"
  28. #include "TcpClient.h"
  29. #include "TcpPullServer.h"
  30. #include "TcpPullClient.h"
  31. #include "TcpPullAgent.h"
  32. #include "TcpPackServer.h"
  33. #include "TcpPackClient.h"
  34. #include "TcpPackAgent.h"
  35. #include "HttpServer.h"
  36. #include "HttpAgent.h"
  37. #include "HttpClient.h"
  38. /*****************************************************************************************************************************************************/
  39. /******************************************************************** SSL Exports ********************************************************************/
  40. /*****************************************************************************************************************************************************/
  41. HPSOCKET_API ITcpServer* HP_Create_SSLServer(ITcpServerListener* pListener)
  42. {
  43. return new CSSLServer(pListener);
  44. }
  45. HPSOCKET_API ITcpAgent* HP_Create_SSLAgent(ITcpAgentListener* pListener)
  46. {
  47. return new CSSLAgent(pListener);
  48. }
  49. HPSOCKET_API ITcpClient* HP_Create_SSLClient(ITcpClientListener* pListener)
  50. {
  51. return new CSSLClient(pListener);
  52. }
  53. HPSOCKET_API ITcpPullServer* HP_Create_SSLPullServer(ITcpServerListener* pListener)
  54. {
  55. return (ITcpPullServer*)(new CSSLPullServer(pListener));
  56. }
  57. HPSOCKET_API ITcpPullAgent* HP_Create_SSLPullAgent(ITcpAgentListener* pListener)
  58. {
  59. return (ITcpPullAgent*)(new CSSLPullAgent(pListener));
  60. }
  61. HPSOCKET_API ITcpPullClient* HP_Create_SSLPullClient(ITcpClientListener* pListener)
  62. {
  63. return (ITcpPullClient*)(new CSSLPullClient(pListener));
  64. }
  65. HPSOCKET_API ITcpPackServer* HP_Create_SSLPackServer(ITcpServerListener* pListener)
  66. {
  67. return (ITcpPackServer*)(new CSSLPackServer(pListener));
  68. }
  69. HPSOCKET_API ITcpPackAgent* HP_Create_SSLPackAgent(ITcpAgentListener* pListener)
  70. {
  71. return (ITcpPackAgent*)(new CSSLPackAgent(pListener));
  72. }
  73. HPSOCKET_API ITcpPackClient* HP_Create_SSLPackClient(ITcpClientListener* pListener)
  74. {
  75. return (ITcpPackClient*)(new CSSLPackClient(pListener));
  76. }
  77. HPSOCKET_API void HP_Destroy_SSLServer(ITcpServer* pServer)
  78. {
  79. delete pServer;
  80. }
  81. HPSOCKET_API void HP_Destroy_SSLAgent(ITcpAgent* pAgent)
  82. {
  83. delete pAgent;
  84. }
  85. HPSOCKET_API void HP_Destroy_SSLClient(ITcpClient* pClient)
  86. {
  87. delete pClient;
  88. }
  89. HPSOCKET_API void HP_Destroy_SSLPullServer(ITcpPullServer* pServer)
  90. {
  91. delete pServer;
  92. }
  93. HPSOCKET_API void HP_Destroy_SSLPullAgent(ITcpPullAgent* pAgent)
  94. {
  95. delete pAgent;
  96. }
  97. HPSOCKET_API void HP_Destroy_SSLPullClient(ITcpPullClient* pClient)
  98. {
  99. delete pClient;
  100. }
  101. HPSOCKET_API void HP_Destroy_SSLPackServer(ITcpPackServer* pServer)
  102. {
  103. delete pServer;
  104. }
  105. HPSOCKET_API void HP_Destroy_SSLPackAgent(ITcpPackAgent* pAgent)
  106. {
  107. delete pAgent;
  108. }
  109. HPSOCKET_API void HP_Destroy_SSLPackClient(ITcpPackClient* pClient)
  110. {
  111. delete pClient;
  112. }
  113. /*****************************************************************************************************************************************************/
  114. /******************************************************************** HTTPS Exports ******************************************************************/
  115. /*****************************************************************************************************************************************************/
  116. HPSOCKET_API IHttpServer* HP_Create_HttpsServer(IHttpServerListener* pListener)
  117. {
  118. return (IHttpServer*)(new CHttpsServer(pListener));
  119. }
  120. HPSOCKET_API IHttpAgent* HP_Create_HttpsAgent(IHttpAgentListener* pListener)
  121. {
  122. return (IHttpAgent*)(new CHttpsAgent(pListener));
  123. }
  124. HPSOCKET_API IHttpClient* HP_Create_HttpsClient(IHttpClientListener* pListener)
  125. {
  126. return (IHttpClient*)(new CHttpsClient(pListener));
  127. }
  128. HPSOCKET_API void HP_Destroy_HttpsServer(IHttpServer* pServer)
  129. {
  130. delete pServer;
  131. }
  132. HPSOCKET_API void HP_Destroy_HttpsAgent(IHttpAgent* pAgent)
  133. {
  134. delete pAgent;
  135. }
  136. HPSOCKET_API void HP_Destroy_HttpsClient(IHttpClient* pClient)
  137. {
  138. delete pClient;
  139. }
  140. /*****************************************************************************************************************************************************/
  141. /*************************************************************** Global Function Exports *************************************************************/
  142. /*****************************************************************************************************************************************************/
  143. HPSOCKET_API BOOL HP_SSL_Initialize(EnSSLSessionMode enSessionMode, int iVerifyMode, LPCTSTR lpszPemCertFile, LPCTSTR lpszPemKeyFile, LPCTSTR lpszKeyPasswod, LPCTSTR lpszCAPemCertFileOrPath)
  144. {
  145. return g_SSL.Initialize(enSessionMode, iVerifyMode, lpszPemCertFile, lpszPemKeyFile, lpszKeyPasswod, lpszCAPemCertFileOrPath);
  146. }
  147. HPSOCKET_API void HP_SSL_Cleanup()
  148. {
  149. g_SSL.Cleanup();
  150. }
  151. HPSOCKET_API void HP_SSL_RemoveThreadLocalState(DWORD dwThreadID)
  152. {
  153. g_SSL.RemoveThreadLocalState();
  154. }
  155. HPSOCKET_API BOOL HP_SSL_IsValid()
  156. {
  157. return g_SSL.IsValid();
  158. }