HPSocket-SSL.cpp 5.7 KB

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