OSDN Git Service

convert source code's character encoding to UTF-8 with BOM
[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 #include <windows.h>\r
32 #include <stdio.h>\r
33 #include <stdlib.h>\r
34 #include <string.h>\r
35 #include <commctrl.h>\r
36 #include <windowsx.h>\r
37 \r
38 #include "common.h"\r
39 #include "resource.h"\r
40 \r
41 #include <htmlhelp.h>\r
42 #include "helpid.h"\r
43 \r
44 \r
45 /*===== プロトタイプ =====*/\r
46 \r
47 static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
48 \r
49 \r
50 /*===== 外部参照 =====*/\r
51 \r
52 extern HWND hHelpWin;\r
53 \r
54 \r
55 /*----- ワンタイムパスワード計算 ----------------------------------------------\r
56 *\r
57 *       Parameter\r
58 *               なし\r
59 *\r
60 *       Return Value\r
61 *               なし\r
62 *----------------------------------------------------------------------------*/\r
63 \r
64 void OtpCalcTool(void)\r
65 {\r
66         DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_calc_dlg), GetMainHwnd(), OtpCalcWinProc);\r
67         return;\r
68 }\r
69 \r
70 \r
71 /*----- ワンタイムパスワード計算ウインドウのコールバック ----------------------\r
72 *\r
73 *       Parameter\r
74 *               HWND hDlg : ウインドウハンドル\r
75 *               UINT message : メッセージ番号\r
76 *               WPARAM wParam : メッセージの WPARAM 引数\r
77 *               LPARAM lParam : メッセージの LPARAM 引数\r
78 *\r
79 *       Return Value\r
80 *               BOOL TRUE/FALSE\r
81 *----------------------------------------------------------------------------*/\r
82 \r
83 static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
84 {\r
85         char Tmp[41];\r
86         char *Pos;\r
87         int Seq;\r
88         int Type;\r
89         char Seed[MAX_SEED_LEN+1];\r
90         char Pass[PASSWORD_LEN+1];\r
91 \r
92         static const RADIOBUTTON AlgoButton[] = {\r
93                 { OTPCALC_MD4, MD4 },\r
94                 { OTPCALC_MD5, MD5 },\r
95                 { OTPCALC_SHA1, SHA1 }\r
96         };\r
97         #define ALGOBUTTONS     (sizeof(AlgoButton)/sizeof(RADIOBUTTON))\r
98 \r
99         switch (message)\r
100         {\r
101                 case WM_INITDIALOG :\r
102                         SendDlgItemMessage(hDlg, OTPCALC_KEY, EM_LIMITTEXT, 40, 0);\r
103                         SendDlgItemMessage(hDlg, OTPCALC_PASS, EM_LIMITTEXT, PASSWORD_LEN, 0);\r
104                         SetRadioButtonByValue(hDlg, MD4, AlgoButton, ALGOBUTTONS);\r
105                     return(TRUE);\r
106 \r
107                 case WM_COMMAND :\r
108                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
109                         {\r
110                                 case IDOK :\r
111                                         SendDlgItemMessage(hDlg, OTPCALC_KEY, WM_GETTEXT, 41, (LPARAM)Tmp);\r
112                                         SendDlgItemMessage(hDlg, OTPCALC_PASS, WM_GETTEXT, PASSWORD_LEN+1, (LPARAM)Pass);\r
113                                         Type = AskRadioButtonValue(hDlg, AlgoButton, ALGOBUTTONS);\r
114 \r
115                                         Pos = Tmp;\r
116                                         while(*Pos == ' ')\r
117                                                 Pos++;\r
118 \r
119                                         if(IsDigit(*Pos))\r
120                                         {\r
121                                                 Seq = atoi(Pos);\r
122                                                 /* Seed */\r
123                                                 if((Pos = GetNextField(Pos)) != NULL)\r
124                                                 {\r
125                                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == SUCCESS)\r
126                                                         {\r
127                                                                 Make6WordPass(Seq, Seed, Pass, Type, Tmp);\r
128                                                         }\r
129                                                         else\r
130                                                                 strcpy(Tmp, MSGJPN251);\r
131                                                 }\r
132                                                 else\r
133                                                         strcpy(Tmp, MSGJPN252);\r
134                                         }\r
135                                         else\r
136                                                 strcpy(Tmp, MSGJPN253);\r
137 \r
138                                         SendDlgItemMessage(hDlg, OTPCALC_RES, WM_SETTEXT, 0, (LPARAM)Tmp);\r
139                                         break;\r
140 \r
141                                 case IDCANCEL :\r
142                                         EndDialog(hDlg, NO);\r
143                                         break;\r
144 \r
145                                 case IDHELP :\r
146                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000037);\r
147                                         break;\r
148                 }\r
149                         return(TRUE);\r
150         }\r
151     return(FALSE);\r
152 }\r
153 \r
154 \r
155 \r