OSDN Git Service

3dbc6769315ec0de20c2567fa662ec3603e1773a
[ffftp/ffftp.git] / tool.c
1 /*=============================================================================\r
2 *\r
3 *                                                                       \83c\81[\83\8b\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 // UTF-8\91Î\89\9e\r
45 #undef __MBSWRAPPER_H__\r
46 #include "mbswrapper.h"\r
47 \r
48 \r
49 /*===== \83v\83\8d\83g\83^\83C\83v =====*/\r
50 \r
51 static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
52 \r
53 \r
54 /*===== \8aO\95\94\8eQ\8fÆ =====*/\r
55 \r
56 extern HWND hHelpWin;\r
57 \r
58 \r
59 /*----- \83\8f\83\93\83^\83C\83\80\83p\83X\83\8f\81[\83h\8cv\8eZ ----------------------------------------------\r
60 *\r
61 *       Parameter\r
62 *               \82È\82µ\r
63 *\r
64 *       Return Value\r
65 *               \82È\82µ\r
66 *----------------------------------------------------------------------------*/\r
67 \r
68 void OtpCalcTool(void)\r
69 {\r
70         DialogBox(GetFtpInst(), MAKEINTRESOURCE(otp_calc_dlg), GetMainHwnd(), OtpCalcWinProc);\r
71         return;\r
72 }\r
73 \r
74 \r
75 /*----- \83\8f\83\93\83^\83C\83\80\83p\83X\83\8f\81[\83h\8cv\8eZ\83E\83C\83\93\83h\83E\82Ì\83R\81[\83\8b\83o\83b\83N ----------------------\r
76 *\r
77 *       Parameter\r
78 *               HWND hDlg : \83E\83C\83\93\83h\83E\83n\83\93\83h\83\8b\r
79 *               UINT message : \83\81\83b\83Z\81[\83W\94Ô\8d\86\r
80 *               WPARAM wParam : \83\81\83b\83Z\81[\83W\82Ì WPARAM \88ø\90\94\r
81 *               LPARAM lParam : \83\81\83b\83Z\81[\83W\82Ì LPARAM \88ø\90\94\r
82 *\r
83 *       Return Value\r
84 *               BOOL TRUE/FALSE\r
85 *----------------------------------------------------------------------------*/\r
86 \r
87 static BOOL CALLBACK OtpCalcWinProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
88 {\r
89         char Tmp[41];\r
90         char *Pos;\r
91         int Seq;\r
92         int Type;\r
93         char Seed[MAX_SEED_LEN+1];\r
94         char Pass[PASSWORD_LEN+1];\r
95 \r
96         static const RADIOBUTTON AlgoButton[] = {\r
97                 { OTPCALC_MD4, MD4 },\r
98                 { OTPCALC_MD5, MD5 },\r
99                 { OTPCALC_SHA1, SHA1 }\r
100         };\r
101         #define ALGOBUTTONS     (sizeof(AlgoButton)/sizeof(RADIOBUTTON))\r
102 \r
103         switch (message)\r
104         {\r
105                 case WM_INITDIALOG :\r
106                         SendDlgItemMessage(hDlg, OTPCALC_KEY, EM_LIMITTEXT, 40, 0);\r
107                         SendDlgItemMessage(hDlg, OTPCALC_PASS, EM_LIMITTEXT, PASSWORD_LEN, 0);\r
108                         SetRadioButtonByValue(hDlg, MD4, AlgoButton, ALGOBUTTONS);\r
109                     return(TRUE);\r
110 \r
111                 case WM_COMMAND :\r
112                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
113                         {\r
114                                 case IDOK :\r
115                                         SendDlgItemMessage(hDlg, OTPCALC_KEY, WM_GETTEXT, 41, (LPARAM)Tmp);\r
116                                         SendDlgItemMessage(hDlg, OTPCALC_PASS, WM_GETTEXT, PASSWORD_LEN+1, (LPARAM)Pass);\r
117                                         Type = AskRadioButtonValue(hDlg, AlgoButton, ALGOBUTTONS);\r
118 \r
119                                         Pos = Tmp;\r
120                                         while(*Pos == ' ')\r
121                                                 Pos++;\r
122 \r
123                                         if(IsDigit(*Pos))\r
124                                         {\r
125                                                 Seq = atoi(Pos);\r
126                                                 /* Seed */\r
127                                                 if((Pos = GetNextField(Pos)) != NULL)\r
128                                                 {\r
129                                                         if(GetOneField(Pos, Seed, MAX_SEED_LEN) == SUCCESS)\r
130                                                         {\r
131                                                                 Make6WordPass(Seq, Seed, Pass, Type, Tmp);\r
132                                                         }\r
133                                                         else\r
134                                                                 strcpy(Tmp, MSGJPN251);\r
135                                                 }\r
136                                                 else\r
137                                                         strcpy(Tmp, MSGJPN252);\r
138                                         }\r
139                                         else\r
140                                                 strcpy(Tmp, MSGJPN253);\r
141 \r
142                                         SendDlgItemMessage(hDlg, OTPCALC_RES, WM_SETTEXT, 0, (LPARAM)Tmp);\r
143                                         break;\r
144 \r
145                                 case IDCANCEL :\r
146                                         EndDialog(hDlg, NO);\r
147                                         break;\r
148 \r
149                                 case IDHELP :\r
150                                         hHelpWin = HtmlHelp(NULL, AskHelpFilePath(), HH_HELP_CONTEXT, IDH_HELP_TOPIC_0000037);\r
151                                         break;\r
152                 }\r
153                         return(TRUE);\r
154         }\r
155     return(FALSE);\r
156 }\r
157 \r
158 \r
159 \r