123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /*
- * Copyright: JessMA Open Source (ldcsaa@gmail.com)
- *
- * Version : 3.6.1
- * Author : Bruce Liang
- * Website : http://www.jessma.org
- * Project : https://github.com/ldcsaa
- * Blog : http://www.cnblogs.com/ldcsaa
- * Wiki : http://www.oschina.net/p/hp-socket
- * QQ Group : 75375912
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
- #include "stdafx.h"
- #include "HPSocket4C-SSL.h"
- #include "SocketObject4C.h"
- #include "TcpServer.h"
- #include "TcpClient.h"
- #include "TcpAgent.h"
- #include "TcpPullServer.h"
- #include "TcpPullClient.h"
- #include "TcpPullAgent.h"
- #include "TcpPackServer.h"
- #include "TcpPackClient.h"
- #include "TcpPackAgent.h"
- #include "HttpServer.h"
- #include "HttpAgent.h"
- #include "HttpClient.h"
- #if !defined(_WIN64) && !defined(HPSOCKET_STATIC_LIB)
- #pragma comment(linker, "/EXPORT:Create_HP_SSLAgent=_Create_HP_SSLAgent@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLClient=_Create_HP_SSLClient@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLPullAgent=_Create_HP_SSLPullAgent@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLPullClient=_Create_HP_SSLPullClient@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLPullServer=_Create_HP_SSLPullServer@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLPackAgent=_Create_HP_SSLPackAgent@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLPackClient=_Create_HP_SSLPackClient@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLPackServer=_Create_HP_SSLPackServer@4")
- #pragma comment(linker, "/EXPORT:Create_HP_SSLServer=_Create_HP_SSLServer@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLAgent=_Destroy_HP_SSLAgent@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLClient=_Destroy_HP_SSLClient@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLPullAgent=_Destroy_HP_SSLPullAgent@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLPullClient=_Destroy_HP_SSLPullClient@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLPullServer=_Destroy_HP_SSLPullServer@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLPackAgent=_Destroy_HP_SSLPackAgent@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLPackClient=_Destroy_HP_SSLPackClient@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLPackServer=_Destroy_HP_SSLPackServer@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_SSLServer=_Destroy_HP_SSLServer@4")
- #pragma comment(linker, "/EXPORT:Create_HP_HttpsAgent=_Create_HP_HttpsAgent@4")
- #pragma comment(linker, "/EXPORT:Create_HP_HttpsClient=_Create_HP_HttpsClient@4")
- #pragma comment(linker, "/EXPORT:Create_HP_HttpsServer=_Create_HP_HttpsServer@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_HttpsAgent=_Destroy_HP_HttpsAgent@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_HttpsClient=_Destroy_HP_HttpsClient@4")
- #pragma comment(linker, "/EXPORT:Destroy_HP_HttpsServer=_Destroy_HP_HttpsServer@4")
- #pragma comment(linker, "/EXPORT:HP_SSL_Initialize=_HP_SSL_Initialize@24")
- #pragma comment(linker, "/EXPORT:HP_SSL_Cleanup=_HP_SSL_Cleanup@0")
- #pragma comment(linker, "/EXPORT:HP_SSL_RemoveThreadLocalState=_HP_SSL_RemoveThreadLocalState@4")
- #pragma comment(linker, "/EXPORT:HP_SSL_IsValid=_HP_SSL_IsValid@0")
- #endif
- /*****************************************************************************************************************************************************/
- /******************************************************************** SSL Exports ********************************************************************/
- /*****************************************************************************************************************************************************/
- typedef C_HP_ObjectT<CSSLServer, ITcpServerListener> C_HP_SSLServer;
- typedef C_HP_ObjectT<CSSLPullServer, ITcpServerListener, sizeof(IPullSocket)> C_HP_SSLPullServer;
- typedef C_HP_ObjectT<CSSLPackServer, ITcpServerListener, sizeof(IPackSocket)> C_HP_SSLPackServer;
- typedef C_HP_ObjectT<CSSLAgent, ITcpAgentListener> C_HP_SSLAgent;
- typedef C_HP_ObjectT<CSSLPullAgent, ITcpAgentListener, sizeof(IPullSocket)> C_HP_SSLPullAgent;
- typedef C_HP_ObjectT<CSSLPackAgent, ITcpAgentListener, sizeof(IPackSocket)> C_HP_SSLPackAgent;
- typedef C_HP_ObjectT<CSSLClient, ITcpClientListener> C_HP_SSLClient;
- typedef C_HP_ObjectT<CSSLPullClient, ITcpClientListener, sizeof(IPullClient)> C_HP_SSLPullClient;
- typedef C_HP_ObjectT<CSSLPackClient, ITcpClientListener, sizeof(IPackClient)> C_HP_SSLPackClient;
- /********************************************************/
- /************** HPSocket4C-SSL 对象创建函数 **************/
- HPSOCKET_API HP_SSLServer __stdcall Create_HP_SSLServer(HP_TcpServerListener pListener)
- {
- return (HP_SSLServer)(new C_HP_SSLServer((ITcpServerListener*)pListener));
- }
- HPSOCKET_API HP_SSLAgent __stdcall Create_HP_SSLAgent(HP_TcpAgentListener pListener)
- {
- return (HP_SSLAgent)(new C_HP_SSLAgent((ITcpAgentListener*)pListener));
- }
- HPSOCKET_API HP_SSLClient __stdcall Create_HP_SSLClient(HP_TcpClientListener pListener)
- {
- return (HP_SSLClient)(new C_HP_SSLClient((ITcpClientListener*)pListener));
- }
- HPSOCKET_API HP_SSLPullServer __stdcall Create_HP_SSLPullServer(HP_TcpPullServerListener pListener)
- {
- return (HP_SSLPullServer)(new C_HP_SSLPullServer((ITcpServerListener*)pListener));
- }
- HPSOCKET_API HP_SSLPullAgent __stdcall Create_HP_SSLPullAgent(HP_TcpPullAgentListener pListener)
- {
- return (HP_SSLPullAgent)(new C_HP_SSLPullAgent((ITcpAgentListener*)pListener));
- }
- HPSOCKET_API HP_SSLPullClient __stdcall Create_HP_SSLPullClient(HP_TcpPullClientListener pListener)
- {
- return (HP_SSLPullClient)(new C_HP_SSLPullClient((ITcpClientListener*)pListener));
- }
- HPSOCKET_API HP_SSLPackServer __stdcall Create_HP_SSLPackServer(HP_TcpServerListener pListener)
- {
- return (HP_SSLPackServer)(new C_HP_SSLPackServer((ITcpServerListener*)pListener));
- }
- HPSOCKET_API HP_SSLPackAgent __stdcall Create_HP_SSLPackAgent(HP_TcpAgentListener pListener)
- {
- return (HP_SSLPackAgent)(new C_HP_SSLPackAgent((ITcpAgentListener*)pListener));
- }
- HPSOCKET_API HP_SSLPackClient __stdcall Create_HP_SSLPackClient(HP_TcpClientListener pListener)
- {
- return (HP_SSLPackClient)(new C_HP_SSLPackClient((ITcpClientListener*)pListener));
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLServer(HP_SSLServer pServer)
- {
- delete (C_HP_SSLServer*)pServer;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLAgent(HP_SSLAgent pAgent)
- {
- delete (C_HP_SSLAgent*)pAgent;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLClient(HP_SSLClient pClient)
- {
- delete (C_HP_SSLClient*)pClient;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLPullServer(HP_SSLPullServer pServer)
- {
- delete (C_HP_SSLPullServer*)pServer;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLPullAgent(HP_SSLPullAgent pAgent)
- {
- delete (C_HP_SSLPullAgent*)pAgent;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLPullClient(HP_SSLPullClient pClient)
- {
- delete (C_HP_SSLPullClient*)pClient;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLPackServer(HP_SSLPackServer pServer)
- {
- delete (C_HP_SSLPackServer*)pServer;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLPackAgent(HP_SSLPackAgent pAgent)
- {
- delete (C_HP_SSLPackAgent*)pAgent;
- }
- HPSOCKET_API void __stdcall Destroy_HP_SSLPackClient(HP_SSLPackClient pClient)
- {
- delete (C_HP_SSLPackClient*)pClient;
- }
- /*****************************************************************************************************************************************************/
- /******************************************************************** HTTPS Exports ******************************************************************/
- /*****************************************************************************************************************************************************/
- typedef C_HP_ObjectT<CHttpsServer, IHttpServerListener> C_HP_HttpsServer;
- typedef C_HP_ObjectT<CHttpsAgent, IHttpAgentListener> C_HP_HttpsAgent;
- typedef C_HP_ObjectT<CHttpsClient, IHttpClientListener> C_HP_HttpsClient;
- /****************************************************/
- /**************** HTTPS 对象创建函数 *****************/
- HPSOCKET_API HP_HttpsServer __stdcall Create_HP_HttpsServer(HP_HttpServerListener pListener)
- {
- return (HP_HttpsServer)(new C_HP_HttpsServer((IHttpServerListener*)pListener));
- }
- HPSOCKET_API HP_HttpsAgent __stdcall Create_HP_HttpsAgent(HP_HttpAgentListener pListener)
- {
- return (HP_HttpsAgent)(new C_HP_HttpsAgent((IHttpAgentListener*)pListener));
- }
- HPSOCKET_API HP_HttpsClient __stdcall Create_HP_HttpsClient(HP_HttpClientListener pListener)
- {
- return (HP_HttpsClient)(new C_HP_HttpsClient((IHttpClientListener*)pListener));
- }
- HPSOCKET_API void __stdcall Destroy_HP_HttpsServer(HP_HttpsServer pServer)
- {
- delete (C_HP_HttpsServer*)pServer;
- }
- HPSOCKET_API void __stdcall Destroy_HP_HttpsAgent(HP_HttpsAgent pAgent)
- {
- delete (C_HP_HttpsAgent*)pAgent;
- }
- HPSOCKET_API void __stdcall Destroy_HP_HttpsClient(HP_HttpsClient pClient)
- {
- delete (C_HP_HttpsClient*)pClient;
- }
- /*****************************************************************************************************************************************************/
- /*************************************************************** Global Function Exports *************************************************************/
- /*****************************************************************************************************************************************************/
- HPSOCKET_API BOOL __stdcall HP_SSL_Initialize(En_HP_SSLSessionMode enSessionMode, int iVerifyMode, LPCTSTR lpszPemCertFile, LPCTSTR lpszPemKeyFile, LPCTSTR lpszKeyPasswod, LPCTSTR lpszCAPemCertFileOrPath)
- {
- return g_SSL.Initialize((EnSSLSessionMode)enSessionMode, iVerifyMode, lpszPemCertFile, lpszPemKeyFile, lpszKeyPasswod, lpszCAPemCertFileOrPath);
- }
- HPSOCKET_API void __stdcall HP_SSL_Cleanup()
- {
- g_SSL.Cleanup();
- }
- HPSOCKET_API void __stdcall HP_SSL_RemoveThreadLocalState(DWORD dwThreadID)
- {
- g_SSL.RemoveThreadLocalState(dwThreadID);
- }
- HPSOCKET_API BOOL __stdcall HP_SSL_IsValid()
- {
- return g_SSL.IsValid();
- }
|