OSDN Git Service

Add support for retrying file transfer.
[ffftp/ffftp.git] / tool.c
1 /*=============================================================================\r
2 *\r
3 *                                                                       ツール\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 #define STRICT\r
31 // IPv6対応\r
32 #include <winsock2.h>\r
33 #include <windows.h>\r
34 #include <stdio.h>\r
35 #include <stdlib.h>\r
36 #include <string.h>\r
37 #include <commctrl.h>\r
38 #include <windowsx.h>\r
39 \r
40 #include "common.h"\r
41 #include "resource.h"\r
42 \r
43 #include <htmlhelp.h>\r
44 #include "helpid.h"\r
45 \r
46 // UTF-8対応\r
47 #undef __MBSWRAPPER_H__\r
48 #include "mbswrapper.h"\r
49 \r
50 \r
51 /*===== プロトタイプ =====*/\r
52 \r
53 static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
54 \r
55 \r
56 /*===== 外部参照 =====*/\r
57 \r
58 extern HWND hHelpWin;\r
59 \r
60 \r
61 /*----- ワンタイムパスワード計算 ----------------------------------------------\r
62 *\r
63 *       Parameter\r
64 *               なし\r
65 *\r
66 *       Return Value\r
67 *               なし\r
68 *----------------------------------------------------------------------------*/\r
69 \r
70 void OtpCalcTool(void)\r
71 {\r
72         DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_calc_dlg), GetMainHwnd(), OtpCalcWinProc);\r
73         return;\r
74 }\r
75 \r
76 \r
77 /*----- ワンタイムパスワード計算ウインドウのコールバック ----------------------\r
78 *\r
79 *       Parameter\r
80 *               HWND hDlg : ウインドウハンドル\r
81 *               UINT message : メッセージ番号\r
82 *               WPARAM wParam : メッセージの WPARAM 引数\r
83 *               LPARAM lParam : メッセージの LPARAM 引数\r
84 *\r
85 *       Return Value\r
86 *               BOOL TRUE/FALSE\r
87 *----------------------------------------------------------------------------*/\r
88 \r
89 static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
90 {\r
91         char Tmp[41];\r
92         char *Pos;\r
93         int Seq;\r
94         int Type;\r
95         char Seed[MAX_SEED_LEN+1];\r
96         char Pass[PASSWORD_LEN+1];\r
97 \r
98         static const RADIOBUTTON AlgoButton[] = {\r
99                 { OTPCALC_MD4, MD4 },\r
100                 { OTPCALC_MD5, MD5 },\r
101                 { OTPCALC_SHA1, SHA1 }\r
102         };\r
103         #define ALGOBUTTONS     (sizeof(AlgoButton)/sizeof(RADIOBUTTON))\r
104 \r
105         switch (message)\r
106         {\r
107                 case WM_INITDIALOG :\r
108                         SendDlgItemMessage(hDlg, OTPCALC_KEY, EM_LIMITTEXT, 40, 0);\r
109                         SendDlgItemMessage(hDlg, OTPCALC_PASS, EM_LIMITTEXT, PASSWORD_LEN, 0);\r
110                         SetRadioButtonByValue(hDlg, MD4, AlgoButton, ALGOBUTTONS);\r
111                     return(TRUE);\r
112 \r
113                 case WM_COMMAND :\r
114                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
115                         {\r
116                                 case IDOK :\r
117                                         SendDlgItemMessage(hDlg, OTPCALC_KEY, WM_GETTEXT, 41, (LPARAM)Tmp);\r
118                                         SendDlgItemMessage(hDlg, OTPCALC_PASS, WM_GETTEXT, PASSWORD_LEN+1, (LPARAM)Pass);\r
119                                         Type = AskRadioButtonValue(hDlg, AlgoButton, ALGOBUTTONS);\r
120 \r
121                                         Pos = Tmp;\r
122                                         while(*Pos == ' ')\r
123                                                 Pos++;\r
124 \r
125                                         if(IsDigit(*Pos))\r
126                                         {\r
127                                                 Seq = atoi(Pos);\r
128                                                 /* Seed */\r
129                                                 if((Pos = GetNextField(Pos)) != NULL)\r
130                                                 {\r
131                                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == FFFTP_SUCCESS)\r
132                                                         {\r
133                                                                 Make6WordPass(Seq, Seed, Pass, Type, Tmp);\r
134                                                         }\r
135                                                         else\r
136                                                                 strcpy(Tmp, MSGJPN251);\r
137                                                 }\r
138                                                 else\r
139                                                         strcpy(Tmp, MSGJPN252);\r
140                                         }\r
141                                         else\r
142                                                 strcpy(Tmp, MSGJPN253);\r
143 \r
144                                         SendDlgItemMessage(hDlg, OTPCALC_RES, WM_SETTEXT, 0, (LPARAM)Tmp);\r
145                                         break;\r
146 \r
147                                 case IDCANCEL :\r
148                                         EndDialog(hDlg, NO);\r
149                                         break;\r
150 \r
151                                 case IDHELP :\r
152                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000037);\r
153                                         break;\r
154                 }\r
155                         return(TRUE);\r
156         }\r
157     return(FALSE);\r
158 }\r
159 \r
160 \r
161 \r