OSDN Git Service

Change to ask if a user wants to disable unused encryption method.
[ffftp/ffftp.git] / history.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 <mbstring.h>\r
38 #include <malloc.h>\r
39 #include <windowsx.h>\r
40 #include <commctrl.h>\r
41 #include <stdarg.h>\r
42 // IPv6対応\r
43 //#include <winsock.h>\r
44 \r
45 #include "common.h"\r
46 #include "resource.h"\r
47 \r
48 \r
49 /*===== プロトタイプ =====*/\r
50 \r
51 static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New);\r
52 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num);\r
53 static void RemoveAllHistoryFromMenu(void);\r
54 \r
55 /*===== 外部参照 =====*/\r
56 \r
57 /* 設定値 */\r
58 extern int FileHist;\r
59 extern int PassToHist;\r
60 \r
61 /*===== ローカルなワーク =====*/\r
62 \r
63 static HISTORYDATA *HistoryBase = NULL;\r
64 static int HistoryNum = 0;\r
65 \r
66 /* ヒストリのメニュー項目のID */\r
67 static int MenuHistId[HISTORY_MAX] = {\r
68         MENU_HIST_1,  MENU_HIST_2,  MENU_HIST_3,  MENU_HIST_4,  MENU_HIST_5,\r
69         MENU_HIST_6,  MENU_HIST_7,  MENU_HIST_8,  MENU_HIST_9,  MENU_HIST_10,\r
70         MENU_HIST_11, MENU_HIST_12, MENU_HIST_13, MENU_HIST_14, MENU_HIST_15,\r
71         MENU_HIST_16, MENU_HIST_17, MENU_HIST_18, MENU_HIST_19, MENU_HIST_20\r
72 };\r
73 \r
74 \r
75 \r
76 /*----- ホスト情報をヒストリリストの先頭に追加する ----------------------------\r
77 *\r
78 *       Parameter\r
79 *               HOSTDATA *Host : ホストデータ\r
80 *               int TrMode : 転送モード\r
81 *\r
82 *       Return Value\r
83 *               なし\r
84 *----------------------------------------------------------------------------*/\r
85 \r
86 void AddHostToHistory(HOSTDATA *Host, int TrMode)\r
87 {\r
88         HISTORYDATA New;\r
89 \r
90         CopyHostToHistory(Host, &New);\r
91         New.Type = TrMode;\r
92         AddHistoryToHistory(&New);\r
93         return;\r
94 }\r
95 \r
96 \r
97 /*----- ヒストリをヒストリリストの先頭に追加する ------------------------------\r
98 *\r
99 *       Parameter\r
100 *               HISTORYDATA *Hist : ヒストリデータ\r
101 *\r
102 *       Return Value\r
103 *               なし\r
104 *----------------------------------------------------------------------------*/\r
105 \r
106 void AddHistoryToHistory(HISTORYDATA *Hist)\r
107 {\r
108         HISTORYDATA *New;\r
109 \r
110         CheckHistoryNum(1);\r
111         if(FileHist > HistoryNum)\r
112         {\r
113                 New = malloc(sizeof(HISTORYDATA));\r
114                 if(New != NULL)\r
115                 {\r
116                         memcpy(New, Hist, sizeof(HISTORYDATA));\r
117                         New->Next = HistoryBase;\r
118                         HistoryBase = New;\r
119                         HistoryNum++;\r
120                 }\r
121         }\r
122         return;\r
123 }\r
124 \r
125 \r
126 /*----- ヒストリの数を返す ----------------------------------------------------\r
127 *\r
128 *       Parameter\r
129 *               なし\r
130 *\r
131 *       Return Value\r
132 *               int ヒストリの数\r
133 *----------------------------------------------------------------------------*/\r
134 \r
135 int AskHistoryNum(void)\r
136 {\r
137         return(HistoryNum);\r
138 }\r
139 \r
140 \r
141 /*----- ヒストリの数をチェックし多すぎたら削除 --------------------------------\r
142 *\r
143 *       Parameter\r
144 *               int Space : 空けておく個数 (0~)\r
145 *\r
146 *       Return Value\r
147 *               なし\r
148 *----------------------------------------------------------------------------*/\r
149 \r
150 void CheckHistoryNum(int Space)\r
151 {\r
152         int i;\r
153         HISTORYDATA *Prev;\r
154         HISTORYDATA *Pos;\r
155         HISTORYDATA *Next;\r
156 \r
157         if(HistoryNum > FileHist-Space)\r
158         {\r
159                 /* 残すべきヒストリを探す */\r
160                 Pos = HistoryBase;\r
161                 Prev = NULL;\r
162                 for(i = 0; i < FileHist-Space; i++)\r
163                 {\r
164                         Prev = Pos;\r
165                         Pos = Pos->Next;\r
166                 }\r
167 \r
168                 /* いらないヒストリを消す */\r
169                 if(Prev == NULL)\r
170                         HistoryBase = NULL;\r
171                 else\r
172                         Prev->Next = NULL;\r
173 \r
174                 while(Pos != NULL)\r
175                 {\r
176                         Next = Pos->Next;\r
177                         free(Pos);\r
178                         Pos = Next;\r
179                         HistoryNum--;\r
180                 }\r
181         }\r
182         return;\r
183 }\r
184 \r
185 \r
186 /*----- ホスト情報をヒストリにセット ------------------------------------------\r
187 *\r
188 *       Parameter\r
189 *               HOSTDATA *Host : ホストデータ\r
190 *               HISTORYDATA *New : ヒストリをセットするワーク\r
191 *\r
192 *       Return Value\r
193 *               なし\r
194 *----------------------------------------------------------------------------*/\r
195 \r
196 static void CopyHostToHistory(HOSTDATA *Host, HISTORYDATA *New)\r
197 {\r
198         strcpy(New->HostAdrs, Host->HostAdrs);\r
199         strcpy(New->UserName, Host->UserName);\r
200         if(PassToHist == YES)\r
201                 strcpy(New->PassWord, Host->PassWord);\r
202         else\r
203                 strcpy(New->PassWord, "");\r
204         strcpy(New->Account, Host->Account);\r
205         strcpy(New->LocalInitDir, Host->LocalInitDir);\r
206         strcpy(New->RemoteInitDir, Host->RemoteInitDir);\r
207         strcpy(New->ChmodCmd, Host->ChmodCmd);\r
208         strcpy(New->LsName, Host->LsName);\r
209         strcpy(New->InitCmd, Host->InitCmd);\r
210         New->Port = Host->Port;\r
211         New->KanjiCode = Host->KanjiCode;\r
212         New->KanaCnv = Host->KanaCnv;\r
213         New->NameKanjiCode = Host->NameKanjiCode;\r
214         New->NameKanaCnv = Host->NameKanaCnv;\r
215         New->Pasv = Host->Pasv;\r
216         New->FireWall = Host->FireWall;\r
217         New->ListCmdOnly = Host->ListCmdOnly;\r
218         New->UseNLST_R = Host->UseNLST_R;\r
219         New->TimeZone = Host->TimeZone;\r
220         New->HostType = Host->HostType;\r
221         New->SyncMove = Host->SyncMove;\r
222         New->NoFullPath = Host->NoFullPath;\r
223         New->Sort = Host->Sort;\r
224         New->Security = Host->Security;\r
225         New->Dialup = Host->Dialup;\r
226         New->DialupAlways = Host->DialupAlways;\r
227         New->DialupNotify = Host->DialupNotify;\r
228         strcpy(New->DialEntry, Host->DialEntry);\r
229         // 暗号化通信対応\r
230         New->UseNoEncryption = Host->UseNoEncryption;\r
231         New->UseFTPES = Host->UseFTPES;\r
232         New->UseFTPIS = Host->UseFTPIS;\r
233         New->UseSFTP = Host->UseSFTP;\r
234         strcpy(New->PrivateKey, Host->PrivateKey);\r
235         // 同時接続対応\r
236         New->MaxThreadCount = Host->MaxThreadCount;\r
237         New->ReuseCmdSkt = Host->ReuseCmdSkt;\r
238         // MLSD対応\r
239         New->UseMLSD = Host->UseMLSD;\r
240         // IPv6対応\r
241         New->UseIPv6 = Host->UseIPv6;\r
242         return;\r
243 }\r
244 \r
245 \r
246 /*----- ヒストリ情報をホスト情報にセット --------------------------------------\r
247 *\r
248 *       Parameter\r
249 *               HISTORYDATA *Hist : ヒストリ\r
250 *               HOSTDATA *Host : ホストデータをセットするワーク\r
251 *\r
252 *       Return Value\r
253 *               なし\r
254 *----------------------------------------------------------------------------*/\r
255 \r
256 void CopyHistoryToHost(HISTORYDATA *Hist, HOSTDATA *Host)\r
257 {\r
258         CopyDefaultHost(Host);\r
259 \r
260         strcpy(Host->HostAdrs, Hist->HostAdrs);\r
261         strcpy(Host->UserName, Hist->UserName);\r
262         if(PassToHist == YES)\r
263                 strcpy(Host->PassWord, Hist->PassWord);\r
264         else\r
265                 strcpy(Host->PassWord, "");\r
266         strcpy(Host->Account, Hist->Account);\r
267         strcpy(Host->LocalInitDir, Hist->LocalInitDir);\r
268         strcpy(Host->RemoteInitDir, Hist->RemoteInitDir);\r
269         strcpy(Host->ChmodCmd, Hist->ChmodCmd);\r
270         strcpy(Host->LsName, Hist->LsName);\r
271         strcpy(Host->InitCmd, Hist->InitCmd);\r
272         Host->Port = Hist->Port;\r
273         Host->KanjiCode = Hist->KanjiCode;\r
274         Host->KanaCnv = Hist->KanaCnv;\r
275         Host->NameKanjiCode = Hist->NameKanjiCode;\r
276         Host->NameKanaCnv = Hist->NameKanaCnv;\r
277         Host->Pasv = Hist->Pasv;\r
278         Host->FireWall = Hist->FireWall;\r
279         Host->ListCmdOnly = Hist->ListCmdOnly;\r
280         Host->UseNLST_R = Hist->UseNLST_R;\r
281         Host->TimeZone = Hist->TimeZone;\r
282         Host->HostType = Hist->HostType;\r
283         Host->SyncMove = Hist->SyncMove;\r
284         Host->NoFullPath = Hist->NoFullPath;\r
285         Host->Sort = Hist->Sort;\r
286         Host->Security = Hist->Security;\r
287         Host->Dialup = Hist->Dialup;\r
288         Host->DialupAlways = Hist->DialupAlways;\r
289         Host->DialupNotify = Hist->DialupNotify;\r
290         strcpy(Host->DialEntry, Hist->DialEntry);\r
291         // 暗号化通信対応\r
292         Host->UseNoEncryption = Hist->UseNoEncryption;\r
293         Host->UseFTPES = Hist->UseFTPES;\r
294         Host->UseFTPIS = Hist->UseFTPIS;\r
295         Host->UseSFTP = Hist->UseSFTP;\r
296         strcpy(Host->PrivateKey, Hist->PrivateKey);\r
297         // 同時接続対応\r
298         Host->MaxThreadCount = Hist->MaxThreadCount;\r
299         Host->ReuseCmdSkt = Hist->ReuseCmdSkt;\r
300         // MLSD対応\r
301         Host->UseMLSD = Hist->UseMLSD;\r
302         // IPv6対応\r
303         Host->UseIPv6 = Hist->UseIPv6;\r
304         return;\r
305 }\r
306 \r
307 \r
308 /*----- ヒストリ情報の初期値を取得 --------------------------------------------\r
309 *\r
310 *       Parameter\r
311 *               HISTORYDATA *Set : ヒストリをセットするワーク\r
312 *\r
313 *       Return Value\r
314 *               なし\r
315 *----------------------------------------------------------------------------*/\r
316 \r
317 void CopyDefaultHistory(HISTORYDATA *Set)\r
318 {\r
319         HOSTDATA Host;\r
320 \r
321         CopyDefaultHost(&Host);\r
322         CopyHostToHistory(&Host, Set);\r
323         return;\r
324 }\r
325 \r
326 \r
327 /*----- 全ヒストリをメニューにセット ------------------------------------------\r
328 *\r
329 *       Parameter\r
330 *               なし\r
331 *\r
332 *       Return Value\r
333 *               なし\r
334 *----------------------------------------------------------------------------*/\r
335 \r
336 void SetAllHistoryToMenu(void)\r
337 {\r
338         int i;\r
339         HISTORYDATA *Pos;\r
340 \r
341         RemoveAllHistoryFromMenu();\r
342 \r
343         Pos = HistoryBase;\r
344         for(i = 0; i < HistoryNum; i++)\r
345         {\r
346                 AddOneFnameToMenu(Pos->HostAdrs, Pos->UserName, Pos->RemoteInitDir, i);\r
347                 Pos = Pos->Next;\r
348         }\r
349         return;\r
350 }\r
351 \r
352 \r
353 /*----- ヒストリをメニューに追加 ----------------------------------------------\r
354 *\r
355 *       Parameter\r
356 *               char *Host : ホスト名\r
357 *               char *User : ユーザ名\r
358 *               char *Remote : ホストのフォルダ\r
359 *               int Num : 番号\r
360 *\r
361 *       Return Value\r
362 *               なし\r
363 *----------------------------------------------------------------------------*/\r
364 \r
365 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num)\r
366 {\r
367         HMENU hMenu;\r
368         char Tmp[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+7+1];\r
369 \r
370         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);\r
371 \r
372         if(Num == 0)\r
373                 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);\r
374 \r
375         if(Num < 9)\r
376                 sprintf(Tmp, "&%d %s (%s) %s", Num+1, Host, User, Remote);\r
377         else if(Num == 9)\r
378                 sprintf(Tmp, "&0 %s (%s) %s", Host, User, Remote);\r
379         else\r
380                 sprintf(Tmp, "&* %s (%s) %s", Host, User, Remote);\r
381 \r
382         AppendMenu(hMenu, MF_STRING, MenuHistId[Num], Tmp);\r
383 \r
384         return;\r
385 }\r
386 \r
387 \r
388 /*----- 全ヒストリをメニューから削除 ------------------------------------------\r
389 *\r
390 *       Parameter\r
391 *               なし\r
392 *\r
393 *       Return Value\r
394 *               なし\r
395 *----------------------------------------------------------------------------*/\r
396 \r
397 static void RemoveAllHistoryFromMenu(void)\r
398 {\r
399         HMENU hMenu;\r
400         int Cnt;\r
401         int i;\r
402 \r
403         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);\r
404         Cnt = GetMenuItemCount(hMenu);\r
405         for(i = DEF_FMENU_ITEMS; i < Cnt; i++)\r
406         {\r
407                 DeleteMenu(hMenu, DEF_FMENU_ITEMS, MF_BYPOSITION);\r
408         }\r
409         return;\r
410 }\r
411 \r
412 \r
413 /*----- 指定メニューコマンドに対応するヒストリを返す --------------------------\r
414 *\r
415 *       Parameter\r
416 *               int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド (MENU_xxx)\r
417 *               HISTORYDATA *Buf : ヒストリデータを返すバッファ\r
418 *\r
419 *       Return Value\r
420 *               int ステータス\r
421 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
422 *----------------------------------------------------------------------------*/\r
423 \r
424 int GetHistoryByCmd(int MenuCmd, HISTORYDATA *Buf)\r
425 {\r
426         int Sts;\r
427         int i;\r
428         HISTORYDATA *Pos;\r
429 \r
430         Sts = FFFTP_FAIL;\r
431         Pos = HistoryBase;\r
432         for(i = 0; i < HistoryNum; i++)\r
433         {\r
434                 if(MenuHistId[i] == MenuCmd)\r
435                 {\r
436                         memcpy(Buf, Pos, sizeof(HISTORYDATA));\r
437                         Sts = FFFTP_SUCCESS;\r
438                 }\r
439                 Pos = Pos->Next;\r
440         }\r
441         return(Sts);\r
442 }\r
443 \r
444 \r
445 /*----- 指定番号に対応するヒストリを返す --------------------------------------\r
446 *\r
447 *       Parameter\r
448 *               int Num : 番号(0~)\r
449 *               HISTORYDATA *Buf : ヒストリデータを返すバッファ\r
450 *\r
451 *       Return Value\r
452 *               int ステータス\r
453 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
454 *----------------------------------------------------------------------------*/\r
455 \r
456 int GetHistoryByNum(int Num, HISTORYDATA *Buf)\r
457 {\r
458         return(GetHistoryByCmd(MenuHistId[Num], Buf));\r
459 }\r
460 \r
461 \r