FFFTPのソースコードです。
修订版 | f453e0e463e50f18f50f051f23fa08c8eb28dd54 (tree) |
---|---|
时间 | 2011-10-16 02:11:32 |
作者 | s_kawamoto <s_kawamoto@user...> |
Commiter | s_kawamoto |
Fix bugs of asyncronous socket control.
Fix bugs of simultaneous connection.
Change to reuse SSL sessions.
This version may be nearly stable (not for 1.99 but for 1.98b).
@@ -1028,8 +1028,6 @@ typedef struct transpacket { | ||
1028 | 1028 | int Mode; /* 転送モード (EXIST_xxx) */ |
1029 | 1029 | HWND hWndTrans; /* 転送中ダイアログのウインドウハンドル */ |
1030 | 1030 | int Abort; /* 転送中止フラグ (ABORT_xxx) */ |
1031 | - // 暗号化通信対応 | |
1032 | - int CryptMode; /* 暗号化通信モード (CRYPT_xxx) */ | |
1033 | 1031 | // 同時接続対応 |
1034 | 1032 | int ThreadCount; |
1035 | 1033 | struct transpacket *Next; |
@@ -1304,7 +1304,7 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char | ||
1304 | 1304 | // ; |
1305 | 1305 | if(CryptMode == CRYPT_FTPIS) |
1306 | 1306 | { |
1307 | - if(AttachSSL(ContSock)) | |
1307 | + if(AttachSSL(ContSock, INVALID_SOCKET)) | |
1308 | 1308 | { |
1309 | 1309 | while((Sts = ReadReplyMessage(ContSock, Buf, 1024, &CancelFlg, TmpBuf) / 100) == FTP_PRELIM) |
1310 | 1310 | ; |
@@ -1419,7 +1419,7 @@ static SOCKET DoConnectCrypt(int CryptMode, HOSTDATA* HostData, char *Host, char | ||
1419 | 1419 | { |
1420 | 1420 | if(IsOpenSSLLoaded() && (Sts = command(ContSock, Reply, &CancelFlg, "AUTH TLS")) == 234) |
1421 | 1421 | { |
1422 | - if(AttachSSL(ContSock)) | |
1422 | + if(AttachSSL(ContSock, INVALID_SOCKET)) | |
1423 | 1423 | { |
1424 | 1424 | if((Sts = command(ContSock, Reply, &CancelFlg, "PBSZ 0")) == 200) |
1425 | 1425 | { |
@@ -107,6 +107,8 @@ static int IsSpecialDevice(char *Fname); | ||
107 | 107 | static int MirrorDelNotify(int Cur, int Notify, TRANSPACKET *Pkt); |
108 | 108 | static BOOL CALLBACK MirrorDeleteDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam); |
109 | 109 | static void SetErrorMsg(char *fmt, ...); |
110 | +// 同時接続対応 | |
111 | +static char* GetErrMsg(); | |
110 | 112 | |
111 | 113 | /*===== ローカルなワーク =====*/ |
112 | 114 |
@@ -141,7 +143,11 @@ static int KeepDlg = NO; /* 転送中ダイアログを消さないかどうか | ||
141 | 143 | static int MoveToForeground = NO; /* ウインドウを前面に移動するかどうか (YES/NO) */ |
142 | 144 | |
143 | 145 | static char CurDir[FMAX_PATH+1] = { "" }; |
144 | -static char ErrMsg[ERR_MSG_LEN+7]; | |
146 | +// 同時接続対応 | |
147 | +//static char ErrMsg[ERR_MSG_LEN+7]; | |
148 | +static char ErrMsg[MAX_DATA_CONNECTION+1][ERR_MSG_LEN+7]; | |
149 | +static DWORD ErrMsgThreadId[MAX_DATA_CONNECTION+1]; | |
150 | +static HANDLE hErrMsgMutex; | |
145 | 151 | |
146 | 152 | // 同時接続対応 |
147 | 153 | static int WaitForMainThread = NO; |
@@ -175,6 +181,8 @@ int MakeTransferThread(void) | ||
175 | 181 | |
176 | 182 | hListAccMutex = CreateMutex( NULL, FALSE, NULL ); |
177 | 183 | hRunMutex = CreateMutex( NULL, TRUE, NULL ); |
184 | + // 同時接続対応 | |
185 | + hErrMsgMutex = CreateMutex( NULL, FALSE, NULL ); | |
178 | 186 | |
179 | 187 | ClearAll = NO; |
180 | 188 | ForceAbort = NO; |
@@ -236,6 +244,8 @@ void CloseTransferThread(void) | ||
236 | 244 | |
237 | 245 | CloseHandle( hListAccMutex ); |
238 | 246 | CloseHandle( hRunMutex ); |
247 | + // 同時接続対応 | |
248 | + CloseHandle( hErrMsgMutex ); | |
239 | 249 | return; |
240 | 250 | } |
241 | 251 |
@@ -682,7 +692,8 @@ static ULONG WINAPI TransferThread(void *Dummy) | ||
682 | 692 | BackgrndMessageProc(); |
683 | 693 | Sleep(1); |
684 | 694 | } |
685 | - memset(ErrMsg, NUL, ERR_MSG_LEN+7); | |
695 | +// memset(ErrMsg, NUL, ERR_MSG_LEN+7); | |
696 | + memset(GetErrMsg(), NUL, ERR_MSG_LEN+7); | |
686 | 697 | |
687 | 698 | // Canceled = NO; |
688 | 699 | Canceled[ThreadCount] = NO; |
@@ -1304,12 +1315,12 @@ static int DownLoadNonPassive(TRANSPACKET *Pkt, int *CancelCheckWork) | ||
1304 | 1315 | ReleaseMutex(hListAccMutex); |
1305 | 1316 | // FTPS対応 |
1306 | 1317 | // iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork); |
1307 | - if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS) | |
1318 | + if(IsSSLAttached(Pkt->ctrl_skt)) | |
1308 | 1319 | { |
1309 | - if(AttachSSL(data_socket)) | |
1320 | + if(AttachSSL(data_socket, Pkt->ctrl_skt)) | |
1310 | 1321 | iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork); |
1311 | 1322 | else |
1312 | - iRetCode = FTP_ERROR; | |
1323 | + iRetCode = 500; | |
1313 | 1324 | } |
1314 | 1325 | else |
1315 | 1326 | iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork); |
@@ -1380,12 +1391,12 @@ static int DownLoadPassive(TRANSPACKET *Pkt, int *CancelCheckWork) | ||
1380 | 1391 | ReleaseMutex(hListAccMutex); |
1381 | 1392 | // FTPS対応 |
1382 | 1393 | // iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork); |
1383 | - if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS) | |
1394 | + if(IsSSLAttached(Pkt->ctrl_skt)) | |
1384 | 1395 | { |
1385 | - if(AttachSSL(data_socket)) | |
1396 | + if(AttachSSL(data_socket, Pkt->ctrl_skt)) | |
1386 | 1397 | iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork); |
1387 | 1398 | else |
1388 | - iRetCode = FTP_ERROR; | |
1399 | + iRetCode = 500; | |
1389 | 1400 | } |
1390 | 1401 | else |
1391 | 1402 | iRetCode = DownLoadFile(Pkt, data_socket, CreateMode, CancelCheckWork); |
@@ -2094,7 +2105,9 @@ static BOOL CALLBACK UpDownErrorDialogProc(HWND hDlg, UINT message, WPARAM wPara | ||
2094 | 2105 | { |
2095 | 2106 | case WM_INITDIALOG : |
2096 | 2107 | SendDlgItemMessage(hDlg, UPDOWN_ERR_FNAME, WM_SETTEXT, 0, (LPARAM)lParam); |
2097 | - SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg); | |
2108 | + // 同時接続対応 | |
2109 | +// SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)ErrMsg); | |
2110 | + SendDlgItemMessage(hDlg, UPDOWN_ERR_MSG, WM_SETTEXT, 0, (LPARAM)GetErrMsg()); | |
2098 | 2111 | return(TRUE); |
2099 | 2112 | |
2100 | 2113 | case WM_COMMAND : |
@@ -2340,12 +2353,12 @@ static int UpLoadNonPassive(TRANSPACKET *Pkt) | ||
2340 | 2353 | ReleaseMutex(hListAccMutex); |
2341 | 2354 | // FTPS対応 |
2342 | 2355 | // iRetCode = UpLoadFile(Pkt, data_socket); |
2343 | - if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS) | |
2356 | + if(IsSSLAttached(Pkt->ctrl_skt)) | |
2344 | 2357 | { |
2345 | - if(AttachSSL(data_socket)) | |
2358 | + if(AttachSSL(data_socket, Pkt->ctrl_skt)) | |
2346 | 2359 | iRetCode = UpLoadFile(Pkt, data_socket); |
2347 | 2360 | else |
2348 | - iRetCode = FTP_ERROR; | |
2361 | + iRetCode = 500; | |
2349 | 2362 | } |
2350 | 2363 | else |
2351 | 2364 | iRetCode = UpLoadFile(Pkt, data_socket); |
@@ -2422,12 +2435,12 @@ static int UpLoadPassive(TRANSPACKET *Pkt) | ||
2422 | 2435 | ReleaseMutex(hListAccMutex); |
2423 | 2436 | // FTPS対応 |
2424 | 2437 | // iRetCode = UpLoadFile(Pkt, data_socket); |
2425 | - if(AskCryptMode() == CRYPT_FTPES || AskCryptMode() == CRYPT_FTPIS) | |
2438 | + if(IsSSLAttached(Pkt->ctrl_skt)) | |
2426 | 2439 | { |
2427 | - if(AttachSSL(data_socket)) | |
2440 | + if(AttachSSL(data_socket, Pkt->ctrl_skt)) | |
2428 | 2441 | iRetCode = UpLoadFile(Pkt, data_socket); |
2429 | 2442 | else |
2430 | - iRetCode = FTP_ERROR; | |
2443 | + iRetCode = 500; | |
2431 | 2444 | } |
2432 | 2445 | else |
2433 | 2446 | iRetCode = UpLoadFile(Pkt, data_socket); |
@@ -3561,10 +3574,14 @@ static void SetErrorMsg(char *fmt, ...) | ||
3561 | 3574 | { |
3562 | 3575 | va_list Args; |
3563 | 3576 | |
3564 | - if(strlen(ErrMsg) == 0) | |
3577 | + // 同時接続対応 | |
3578 | +// if(strlen(ErrMsg) == 0) | |
3579 | + if(strlen(GetErrMsg()) == 0) | |
3565 | 3580 | { |
3566 | 3581 | va_start(Args, fmt); |
3567 | - wvsprintf(ErrMsg, fmt, Args); | |
3582 | + // 同時接続対応 | |
3583 | +// wvsprintf(ErrMsg, fmt, Args); | |
3584 | + wvsprintf(GetErrMsg(), fmt, Args); | |
3568 | 3585 | va_end(Args); |
3569 | 3586 | } |
3570 | 3587 | return; |
@@ -3606,3 +3623,39 @@ int CheckPathViolation(TRANSPACKET *packet) | ||
3606 | 3623 | } |
3607 | 3624 | |
3608 | 3625 | |
3626 | +// 同時接続対応 | |
3627 | +static char* GetErrMsg() | |
3628 | +{ | |
3629 | + char* r; | |
3630 | + DWORD ThreadId; | |
3631 | + int i; | |
3632 | + r = NULL; | |
3633 | + WaitForSingleObject(hErrMsgMutex, INFINITE); | |
3634 | + ThreadId = GetCurrentThreadId(); | |
3635 | + i = 0; | |
3636 | + while(i < MAX_DATA_CONNECTION + 1) | |
3637 | + { | |
3638 | + if(ErrMsgThreadId[i] == ThreadId) | |
3639 | + { | |
3640 | + r = ErrMsg[i]; | |
3641 | + break; | |
3642 | + } | |
3643 | + i++; | |
3644 | + } | |
3645 | + if(!r) | |
3646 | + { | |
3647 | + i = 0; | |
3648 | + while(i < MAX_DATA_CONNECTION + 1) | |
3649 | + { | |
3650 | + if(ErrMsgThreadId[i] == 0) | |
3651 | + { | |
3652 | + ErrMsgThreadId[i] = ThreadId; | |
3653 | + r = ErrMsg[i]; | |
3654 | + break; | |
3655 | + } | |
3656 | + i++; | |
3657 | + } | |
3658 | + } | |
3659 | + ReleaseMutex(hErrMsgMutex); | |
3660 | + return r; | |
3661 | +} |
@@ -271,6 +271,8 @@ static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LP | ||
271 | 271 | break; |
272 | 272 | |
273 | 273 | case WM_ASYNC_DBASE : |
274 | + // APIの仕様上ハンドルが登録される前にウィンドウメッセージが呼び出される可能性あり | |
275 | + RegistAsyncTableDbase((HANDLE)wParam); | |
274 | 276 | // スレッド衝突のバグ修正 |
275 | 277 | WaitForSingleObject(hAsyncTblAccMutex, INFINITE); |
276 | 278 | for(Pos = 0; Pos < MAX_SIGNAL_ENTRY_DBASE; Pos++) |
@@ -291,31 +293,6 @@ static LRESULT CALLBACK SocketWndProc(HWND hWnd, UINT message, WPARAM wParam, LP | ||
291 | 293 | break; |
292 | 294 | } |
293 | 295 | } |
294 | - // APIの仕様上ハンドルが登録される前にウィンドウメッセージが呼び出される可能性あり | |
295 | - if(Pos == MAX_SIGNAL_ENTRY_DBASE) | |
296 | - { | |
297 | - for(Pos = 0; Pos < MAX_SIGNAL_ENTRY_DBASE; Pos++) | |
298 | - { | |
299 | - if(SignalDbase[Pos].Async == 0) | |
300 | - { | |
301 | - SignalDbase[Pos].Async = (HANDLE)wParam; | |
302 | - SignalDbase[Pos].Done = 0; | |
303 | - SignalDbase[Pos].ErrorDb = 0; | |
304 | - if(HIWORD(lParam) != 0) | |
305 | - { | |
306 | - SignalDbase[Pos].ErrorDb = 1; | |
307 | -#if DBG_MSG | |
308 | - DoPrintf("##### SignalDatabase: error"); | |
309 | -#endif | |
310 | - } | |
311 | - SignalDbase[Pos].Done = 1; | |
312 | -#if DBG_MSG | |
313 | - DoPrintf("##### SignalDatabase: Done"); | |
314 | -#endif | |
315 | - break; | |
316 | - } | |
317 | - } | |
318 | - } | |
319 | 296 | // スレッド衝突のバグ修正 |
320 | 297 | ReleaseMutex(hAsyncTblAccMutex); |
321 | 298 | break; |
@@ -738,6 +715,9 @@ int do_closesocket(SOCKET s) | ||
738 | 715 | #endif |
739 | 716 | CancelCheckWork = NO; |
740 | 717 | |
718 | + // スレッド衝突のバグ修正 | |
719 | + WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0); | |
720 | + UnRegistAsyncTable(s); | |
741 | 721 | // FTPS対応 |
742 | 722 | // Ret = closesocket(s); |
743 | 723 | Ret = closesocketS(s); |
@@ -755,10 +735,12 @@ int do_closesocket(SOCKET s) | ||
755 | 735 | Ret = 0; |
756 | 736 | } |
757 | 737 | |
758 | - WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0); | |
738 | + // スレッド衝突のバグ修正 | |
739 | +// WSAAsyncSelect(s, hWndSocket, WM_ASYNC_SOCKET, 0); | |
759 | 740 | if(BackgrndMessageProc() == YES) |
760 | 741 | CancelCheckWork = YES; |
761 | - UnRegistAsyncTable(s); | |
742 | + // スレッド衝突のバグ修正 | |
743 | +// UnRegistAsyncTable(s); | |
762 | 744 | |
763 | 745 | #if DBG_MSG |
764 | 746 | DoPrintf("# Exit close"); |
@@ -30,6 +30,8 @@ typedef int (__cdecl* _SSL_read)(SSL*, void*, int); | ||
30 | 30 | typedef int (__cdecl* _SSL_get_error)(SSL*, int); |
31 | 31 | typedef X509* (__cdecl* _SSL_get_peer_certificate)(const SSL*); |
32 | 32 | typedef long (__cdecl* _SSL_get_verify_result)(const SSL*); |
33 | +typedef SSL_SESSION* (__cdecl* _SSL_get_session)(SSL*); | |
34 | +typedef int (__cdecl* _SSL_set_session)(SSL*, SSL_SESSION*); | |
33 | 35 | typedef BIO_METHOD* (__cdecl* _BIO_s_mem)(); |
34 | 36 | typedef BIO* (__cdecl* _BIO_new)(BIO_METHOD*); |
35 | 37 | typedef int (__cdecl* _BIO_free)(BIO*); |
@@ -37,7 +39,6 @@ typedef long (__cdecl* _BIO_ctrl)(BIO*, int, long, void*); | ||
37 | 39 | typedef void (__cdecl* _X509_free)(X509*); |
38 | 40 | typedef int (__cdecl* _X509_print_ex)(BIO*, X509*, unsigned long, unsigned long); |
39 | 41 | typedef X509_NAME* (__cdecl* _X509_get_subject_name)(X509*); |
40 | -typedef X509_NAME* (__cdecl* _X509_get_issuer_name)(X509*); | |
41 | 42 | typedef int (__cdecl* _X509_NAME_print_ex)(BIO*, X509_NAME*, int, unsigned long); |
42 | 43 | |
43 | 44 | _SSL_load_error_strings p_SSL_load_error_strings; |
@@ -58,6 +59,8 @@ _SSL_read p_SSL_read; | ||
58 | 59 | _SSL_get_error p_SSL_get_error; |
59 | 60 | _SSL_get_peer_certificate p_SSL_get_peer_certificate; |
60 | 61 | _SSL_get_verify_result p_SSL_get_verify_result; |
62 | +_SSL_get_session p_SSL_get_session; | |
63 | +_SSL_set_session p_SSL_set_session; | |
61 | 64 | _BIO_s_mem p_BIO_s_mem; |
62 | 65 | _BIO_new p_BIO_new; |
63 | 66 | _BIO_free p_BIO_free; |
@@ -65,7 +68,6 @@ _BIO_ctrl p_BIO_ctrl; | ||
65 | 68 | _X509_free p_X509_free; |
66 | 69 | _X509_print_ex p_X509_print_ex; |
67 | 70 | _X509_get_subject_name p_X509_get_subject_name; |
68 | -_X509_get_issuer_name p_X509_get_issuer_name; | |
69 | 71 | _X509_NAME_print_ex p_X509_NAME_print_ex; |
70 | 72 | |
71 | 73 | #define MAX_SSL_SOCKET 64 |
@@ -124,7 +126,9 @@ BOOL LoadOpenSSL() | ||
124 | 126 | || !(p_SSL_read = (_SSL_read)GetProcAddress(g_hOpenSSL, "SSL_read")) |
125 | 127 | || !(p_SSL_get_error = (_SSL_get_error)GetProcAddress(g_hOpenSSL, "SSL_get_error")) |
126 | 128 | || !(p_SSL_get_peer_certificate = (_SSL_get_peer_certificate)GetProcAddress(g_hOpenSSL, "SSL_get_peer_certificate")) |
127 | - || !(p_SSL_get_verify_result = (_SSL_get_verify_result)GetProcAddress(g_hOpenSSL, "SSL_get_verify_result"))) | |
129 | + || !(p_SSL_get_verify_result = (_SSL_get_verify_result)GetProcAddress(g_hOpenSSL, "SSL_get_verify_result")) | |
130 | + || !(p_SSL_get_session = (_SSL_get_session)GetProcAddress(g_hOpenSSL, "SSL_get_session")) | |
131 | + || !(p_SSL_set_session = (_SSL_set_session)GetProcAddress(g_hOpenSSL, "SSL_set_session"))) | |
128 | 132 | { |
129 | 133 | if(g_hOpenSSL) |
130 | 134 | FreeLibrary(g_hOpenSSL); |
@@ -140,7 +144,6 @@ BOOL LoadOpenSSL() | ||
140 | 144 | || !(p_X509_free = (_X509_free)GetProcAddress(g_hOpenSSLCommon, "X509_free")) |
141 | 145 | || !(p_X509_print_ex = (_X509_print_ex)GetProcAddress(g_hOpenSSLCommon, "X509_print_ex")) |
142 | 146 | || !(p_X509_get_subject_name = (_X509_get_subject_name)GetProcAddress(g_hOpenSSLCommon, "X509_get_subject_name")) |
143 | - || !(p_X509_get_issuer_name = (_X509_get_issuer_name)GetProcAddress(g_hOpenSSLCommon, "X509_get_issuer_name")) | |
144 | 147 | || !(p_X509_NAME_print_ex = (_X509_NAME_print_ex)GetProcAddress(g_hOpenSSLCommon, "X509_NAME_print_ex"))) |
145 | 148 | { |
146 | 149 | if(g_hOpenSSL) |
@@ -330,11 +333,13 @@ BOOL IsHostNameMatched(LPCSTR HostName, LPCSTR CommonName) | ||
330 | 333 | return bResult; |
331 | 334 | } |
332 | 335 | |
333 | -BOOL AttachSSL(SOCKET s) | |
336 | +BOOL AttachSSL(SOCKET s, SOCKET parent) | |
334 | 337 | { |
335 | 338 | BOOL r; |
336 | 339 | DWORD Time; |
337 | 340 | SSL** ppSSL; |
341 | + SSL** ppSSLParent; | |
342 | + SSL_SESSION* pSession; | |
338 | 343 | if(!g_bOpenSSLLoaded) |
339 | 344 | return FALSE; |
340 | 345 | r = FALSE; |
@@ -350,8 +355,20 @@ BOOL AttachSSL(SOCKET s) | ||
350 | 355 | { |
351 | 356 | if(p_SSL_set_fd(*ppSSL, s) != 0) |
352 | 357 | { |
353 | - r = TRUE; | |
358 | + if(parent != INVALID_SOCKET) | |
359 | + { | |
360 | + if(ppSSLParent = FindSSLPointerFromSocket(parent)) | |
361 | + { | |
362 | + if(pSession = p_SSL_get_session(*ppSSLParent)) | |
363 | + { | |
364 | + if(p_SSL_set_session(*ppSSL, pSession) == 1) | |
365 | + { | |
366 | + } | |
367 | + } | |
368 | + } | |
369 | + } | |
354 | 370 | // SSLのネゴシエーションには時間がかかる場合がある |
371 | + r = TRUE; | |
355 | 372 | while(p_SSL_connect(*ppSSL) != 1) |
356 | 373 | { |
357 | 374 | LeaveCriticalSection(&g_OpenSSLLock); |
@@ -364,6 +381,14 @@ BOOL AttachSSL(SOCKET s) | ||
364 | 381 | } |
365 | 382 | EnterCriticalSection(&g_OpenSSLLock); |
366 | 383 | } |
384 | + if(ConfirmSSLCertificate(*ppSSL)) | |
385 | + { | |
386 | + } | |
387 | + else | |
388 | + { | |
389 | + DetachSSL(s); | |
390 | + r = FALSE; | |
391 | + } | |
367 | 392 | } |
368 | 393 | else |
369 | 394 | { |
@@ -371,14 +396,6 @@ BOOL AttachSSL(SOCKET s) | ||
371 | 396 | DetachSSL(s); |
372 | 397 | EnterCriticalSection(&g_OpenSSLLock); |
373 | 398 | } |
374 | - if(ConfirmSSLCertificate(*ppSSL)) | |
375 | - { | |
376 | - } | |
377 | - else | |
378 | - { | |
379 | - DetachSSL(s); | |
380 | - r = FALSE; | |
381 | - } | |
382 | 399 | } |
383 | 400 | } |
384 | 401 | } |
@@ -437,7 +454,7 @@ SOCKET acceptS(SOCKET s, struct sockaddr *addr, int *addrlen) | ||
437 | 454 | { |
438 | 455 | SOCKET r; |
439 | 456 | r = accept(s, addr, addrlen); |
440 | - if(!AttachSSL(r)) | |
457 | + if(!AttachSSL(r, INVALID_SOCKET)) | |
441 | 458 | { |
442 | 459 | closesocket(r); |
443 | 460 | return INVALID_SOCKET; |
@@ -449,7 +466,7 @@ int connectS(SOCKET s, const struct sockaddr *name, int namelen) | ||
449 | 466 | { |
450 | 467 | int r; |
451 | 468 | r = connect(s, name, namelen); |
452 | - if(!AttachSSL(r)) | |
469 | + if(!AttachSSL(r, INVALID_SOCKET)) | |
453 | 470 | return SOCKET_ERROR; |
454 | 471 | return r; |
455 | 472 | } |
@@ -16,7 +16,7 @@ BOOL IsOpenSSLLoaded(); | ||
16 | 16 | void SetSSLTimeoutCallback(DWORD Timeout, LPSSLTIMEOUTCALLBACK pCallback); |
17 | 17 | void SetSSLConfirmCallback(LPSSLCONFIRMCALLBACK pCallback); |
18 | 18 | BOOL IsHostNameMatched(LPCSTR HostName, LPCSTR CommonName); |
19 | -BOOL AttachSSL(SOCKET s); | |
19 | +BOOL AttachSSL(SOCKET s, SOCKET parent); | |
20 | 20 | BOOL DetachSSL(SOCKET s); |
21 | 21 | BOOL IsSSLAttached(SOCKET s); |
22 | 22 | SOCKET socketS(int af, int type, int protocol); |