OSDN Git Service

This version may be nearly stable.
[ffftp/ffftp.git] / socketwrapper.c
index 744f7c2..e4f03b0 100644 (file)
 
 #include "socketwrapper.h"
 
-typedef void (__stdcall* _SSL_load_error_strings)();
-typedef int (__stdcall* _SSL_library_init)();
-typedef SSL_METHOD* (__stdcall* _SSLv23_method)();
-typedef SSL_CTX* (__stdcall* _SSL_CTX_new)(SSL_METHOD*);
-typedef void (__stdcall* _SSL_CTX_free)(SSL_CTX*);
-typedef SSL* (__stdcall* _SSL_new)(SSL_CTX*);
-typedef void (__stdcall* _SSL_free)(SSL*);
-typedef int (__stdcall* _SSL_shutdown)(SSL*);
-typedef int (__stdcall* _SSL_get_fd)(SSL*);
-typedef int (__stdcall* _SSL_set_fd)(SSL*, int);
-typedef int (__stdcall* _SSL_accept)(SSL*);
-typedef int (__stdcall* _SSL_connect)(SSL*);
-typedef int (__stdcall* _SSL_write)(SSL*, const void*, int);
-typedef int (__stdcall* _SSL_peek)(SSL*, void*, int);
-typedef int (__stdcall* _SSL_read)(SSL*, void*, int);
-typedef int (__stdcall* _SSL_get_error)(SSL*, int);
+typedef void (__cdecl* _SSL_load_error_strings)();
+typedef int (__cdecl* _SSL_library_init)();
+typedef SSL_METHOD* (__cdecl* _SSLv23_method)();
+typedef SSL_CTX* (__cdecl* _SSL_CTX_new)(SSL_METHOD*);
+typedef void (__cdecl* _SSL_CTX_free)(SSL_CTX*);
+typedef SSL* (__cdecl* _SSL_new)(SSL_CTX*);
+typedef void (__cdecl* _SSL_free)(SSL*);
+typedef int (__cdecl* _SSL_shutdown)(SSL*);
+typedef int (__cdecl* _SSL_get_fd)(SSL*);
+typedef int (__cdecl* _SSL_set_fd)(SSL*, int);
+typedef int (__cdecl* _SSL_accept)(SSL*);
+typedef int (__cdecl* _SSL_connect)(SSL*);
+typedef int (__cdecl* _SSL_write)(SSL*, const void*, int);
+typedef int (__cdecl* _SSL_peek)(SSL*, void*, int);
+typedef int (__cdecl* _SSL_read)(SSL*, void*, int);
+typedef int (__cdecl* _SSL_get_error)(SSL*, int);
 
 _SSL_load_error_strings pSSL_load_error_strings;
 _SSL_library_init pSSL_library_init;
@@ -86,7 +86,8 @@ BOOL LoadOpenSSL()
                || !(pSSL_read = (_SSL_read)GetProcAddress(g_hOpenSSL, "SSL_read"))
                || !(pSSL_get_error = (_SSL_get_error)GetProcAddress(g_hOpenSSL, "SSL_get_error")))
        {
-               FreeLibrary(g_hOpenSSL);
+               if(g_hOpenSSL)
+                       FreeLibrary(g_hOpenSSL);
                g_hOpenSSL = NULL;
                return FALSE;
        }
@@ -155,6 +156,8 @@ SSL** FindSSLPointerFromSocket(SOCKET s)
 
 void SetSSLTimeoutCallback(DWORD Timeout, LPSSLTIMEOUTCALLBACK pCallback)
 {
+       if(!g_bOpenSSLLoaded)
+               return;
        EnterCriticalSection(&g_OpenSSLLock);
        g_OpenSSLTimeout = Timeout;
        g_pOpenSSLTimeoutCallback = pCallback;
@@ -166,6 +169,8 @@ BOOL AttachSSL(SOCKET s)
        BOOL r;
        DWORD Time;
        SSL** ppSSL;
+       if(!g_bOpenSSLLoaded)
+               return FALSE;
        r = FALSE;
        Time = timeGetTime();
        EnterCriticalSection(&g_OpenSSLLock);
@@ -207,6 +212,8 @@ BOOL DetachSSL(SOCKET s)
 {
        BOOL r;
        SSL** ppSSL;
+       if(!g_bOpenSSLLoaded)
+               return FALSE;
        r = FALSE;
        EnterCriticalSection(&g_OpenSSLLock);
        if(ppSSL = FindSSLPointerFromSocket(s))
@@ -223,6 +230,8 @@ BOOL DetachSSL(SOCKET s)
 BOOL IsSSLAttached(SOCKET s)
 {
        SSL** ppSSL;
+       if(!g_bOpenSSLLoaded)
+               return FALSE;
        EnterCriticalSection(&g_OpenSSLLock);
        ppSSL = FindSSLPointerFromSocket(s);
        LeaveCriticalSection(&g_OpenSSLLock);
@@ -276,6 +285,8 @@ int closesocketS(SOCKET s)
 int sendS(SOCKET s, const char * buf, int len, int flags)
 {
        SSL** ppSSL;
+       if(!g_bOpenSSLLoaded)
+               return send(s, buf, len, flags);
        EnterCriticalSection(&g_OpenSSLLock);
        ppSSL = FindSSLPointerFromSocket(s);
        LeaveCriticalSection(&g_OpenSSLLock);
@@ -287,6 +298,8 @@ int sendS(SOCKET s, const char * buf, int len, int flags)
 int recvS(SOCKET s, char * buf, int len, int flags)
 {
        SSL** ppSSL;
+       if(!g_bOpenSSLLoaded)
+               return recv(s, buf, len, flags);
        EnterCriticalSection(&g_OpenSSLLock);
        ppSSL = FindSSLPointerFromSocket(s);
        LeaveCriticalSection(&g_OpenSSLLock);