OSDN Git Service

Update OpenSSL to 1.0.2c.
[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         New->NoWeakEncryption = Host->NoWeakEncryption;\r
236         // 同時接続対応\r
237         New->MaxThreadCount = Host->MaxThreadCount;\r
238         New->ReuseCmdSkt = Host->ReuseCmdSkt;\r
239         // MLSD対応\r
240         New->UseMLSD = Host->UseMLSD;\r
241         // IPv6対応\r
242         New->NetType = Host->NetType;\r
243         // 自動切断対策\r
244         New->NoopInterval = Host->NoopInterval;\r
245         // 再転送対応\r
246         New->TransferErrorMode = Host->TransferErrorMode;\r
247         New->TransferErrorNotify = Host->TransferErrorNotify;\r
248         // セッションあたりの転送量制限対策\r
249         New->TransferErrorReconnect = Host->TransferErrorReconnect;\r
250         return;\r
251 }\r
252 \r
253 \r
254 /*----- ヒストリ情報をホスト情報にセット --------------------------------------\r
255 *\r
256 *       Parameter\r
257 *               HISTORYDATA *Hist : ヒストリ\r
258 *               HOSTDATA *Host : ホストデータをセットするワーク\r
259 *\r
260 *       Return Value\r
261 *               なし\r
262 *----------------------------------------------------------------------------*/\r
263 \r
264 void CopyHistoryToHost(HISTORYDATA *Hist, HOSTDATA *Host)\r
265 {\r
266         CopyDefaultHost(Host);\r
267 \r
268         strcpy(Host->HostAdrs, Hist->HostAdrs);\r
269         strcpy(Host->UserName, Hist->UserName);\r
270         if(PassToHist == YES)\r
271                 strcpy(Host->PassWord, Hist->PassWord);\r
272         else\r
273                 strcpy(Host->PassWord, "");\r
274         strcpy(Host->Account, Hist->Account);\r
275         strcpy(Host->LocalInitDir, Hist->LocalInitDir);\r
276         strcpy(Host->RemoteInitDir, Hist->RemoteInitDir);\r
277         strcpy(Host->ChmodCmd, Hist->ChmodCmd);\r
278         strcpy(Host->LsName, Hist->LsName);\r
279         strcpy(Host->InitCmd, Hist->InitCmd);\r
280         Host->Port = Hist->Port;\r
281         Host->KanjiCode = Hist->KanjiCode;\r
282         Host->KanaCnv = Hist->KanaCnv;\r
283         Host->NameKanjiCode = Hist->NameKanjiCode;\r
284         Host->NameKanaCnv = Hist->NameKanaCnv;\r
285         Host->Pasv = Hist->Pasv;\r
286         Host->FireWall = Hist->FireWall;\r
287         Host->ListCmdOnly = Hist->ListCmdOnly;\r
288         Host->UseNLST_R = Hist->UseNLST_R;\r
289         Host->TimeZone = Hist->TimeZone;\r
290         Host->HostType = Hist->HostType;\r
291         Host->SyncMove = Hist->SyncMove;\r
292         Host->NoFullPath = Hist->NoFullPath;\r
293         Host->Sort = Hist->Sort;\r
294         Host->Security = Hist->Security;\r
295         Host->Dialup = Hist->Dialup;\r
296         Host->DialupAlways = Hist->DialupAlways;\r
297         Host->DialupNotify = Hist->DialupNotify;\r
298         strcpy(Host->DialEntry, Hist->DialEntry);\r
299         // 暗号化通信対応\r
300         Host->UseNoEncryption = Hist->UseNoEncryption;\r
301         Host->UseFTPES = Hist->UseFTPES;\r
302         Host->UseFTPIS = Hist->UseFTPIS;\r
303         Host->UseSFTP = Hist->UseSFTP;\r
304         strcpy(Host->PrivateKey, Hist->PrivateKey);\r
305         Host->NoWeakEncryption = Hist->NoWeakEncryption;\r
306         // 同時接続対応\r
307         Host->MaxThreadCount = Hist->MaxThreadCount;\r
308         Host->ReuseCmdSkt = Hist->ReuseCmdSkt;\r
309         // MLSD対応\r
310         Host->UseMLSD = Hist->UseMLSD;\r
311         // IPv6対応\r
312         Host->NetType = Hist->NetType;\r
313         // 自動切断対策\r
314         Host->NoopInterval = Hist->NoopInterval;\r
315         // 再転送対応\r
316         Host->TransferErrorMode = Hist->TransferErrorMode;\r
317         Host->TransferErrorNotify = Hist->TransferErrorNotify;\r
318         // セッションあたりの転送量制限対策\r
319         Host->TransferErrorReconnect = Hist->TransferErrorReconnect;\r
320         return;\r
321 }\r
322 \r
323 \r
324 /*----- ヒストリ情報の初期値を取得 --------------------------------------------\r
325 *\r
326 *       Parameter\r
327 *               HISTORYDATA *Set : ヒストリをセットするワーク\r
328 *\r
329 *       Return Value\r
330 *               なし\r
331 *----------------------------------------------------------------------------*/\r
332 \r
333 void CopyDefaultHistory(HISTORYDATA *Set)\r
334 {\r
335         HOSTDATA Host;\r
336 \r
337         CopyDefaultHost(&Host);\r
338         CopyHostToHistory(&Host, Set);\r
339         return;\r
340 }\r
341 \r
342 \r
343 /*----- 全ヒストリをメニューにセット ------------------------------------------\r
344 *\r
345 *       Parameter\r
346 *               なし\r
347 *\r
348 *       Return Value\r
349 *               なし\r
350 *----------------------------------------------------------------------------*/\r
351 \r
352 void SetAllHistoryToMenu(void)\r
353 {\r
354         int i;\r
355         HISTORYDATA *Pos;\r
356 \r
357         RemoveAllHistoryFromMenu();\r
358 \r
359         Pos = HistoryBase;\r
360         for(i = 0; i < HistoryNum; i++)\r
361         {\r
362                 AddOneFnameToMenu(Pos->HostAdrs, Pos->UserName, Pos->RemoteInitDir, i);\r
363                 Pos = Pos->Next;\r
364         }\r
365         return;\r
366 }\r
367 \r
368 \r
369 /*----- ヒストリをメニューに追加 ----------------------------------------------\r
370 *\r
371 *       Parameter\r
372 *               char *Host : ホスト名\r
373 *               char *User : ユーザ名\r
374 *               char *Remote : ホストのフォルダ\r
375 *               int Num : 番号\r
376 *\r
377 *       Return Value\r
378 *               なし\r
379 *----------------------------------------------------------------------------*/\r
380 \r
381 static void AddOneFnameToMenu(char *Host, char *User, char *Remote, int Num)\r
382 {\r
383         HMENU hMenu;\r
384         char Tmp[HOST_ADRS_LEN+USER_NAME_LEN+INIT_DIR_LEN+7+1];\r
385 \r
386         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);\r
387 \r
388         if(Num == 0)\r
389                 AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);\r
390 \r
391         if(Num < 9)\r
392                 sprintf(Tmp, "&%d %s (%s) %s", Num+1, Host, User, Remote);\r
393         else if(Num == 9)\r
394                 sprintf(Tmp, "&0 %s (%s) %s", Host, User, Remote);\r
395         else\r
396                 sprintf(Tmp, "&* %s (%s) %s", Host, User, Remote);\r
397 \r
398         AppendMenu(hMenu, MF_STRING, MenuHistId[Num], Tmp);\r
399 \r
400         return;\r
401 }\r
402 \r
403 \r
404 /*----- 全ヒストリをメニューから削除 ------------------------------------------\r
405 *\r
406 *       Parameter\r
407 *               なし\r
408 *\r
409 *       Return Value\r
410 *               なし\r
411 *----------------------------------------------------------------------------*/\r
412 \r
413 static void RemoveAllHistoryFromMenu(void)\r
414 {\r
415         HMENU hMenu;\r
416         int Cnt;\r
417         int i;\r
418 \r
419         hMenu = GetSubMenu(GetMenu(GetMainHwnd()), 0);\r
420         Cnt = GetMenuItemCount(hMenu);\r
421         for(i = DEF_FMENU_ITEMS; i < Cnt; i++)\r
422         {\r
423                 DeleteMenu(hMenu, DEF_FMENU_ITEMS, MF_BYPOSITION);\r
424         }\r
425         return;\r
426 }\r
427 \r
428 \r
429 /*----- 指定メニューコマンドに対応するヒストリを返す --------------------------\r
430 *\r
431 *       Parameter\r
432 *               int MenuCmd : 取り出すヒストリに割り当てられたメニューコマンド (MENU_xxx)\r
433 *               HISTORYDATA *Buf : ヒストリデータを返すバッファ\r
434 *\r
435 *       Return Value\r
436 *               int ステータス\r
437 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
438 *----------------------------------------------------------------------------*/\r
439 \r
440 int GetHistoryByCmd(int MenuCmd, HISTORYDATA *Buf)\r
441 {\r
442         int Sts;\r
443         int i;\r
444         HISTORYDATA *Pos;\r
445 \r
446         Sts = FFFTP_FAIL;\r
447         Pos = HistoryBase;\r
448         for(i = 0; i < HistoryNum; i++)\r
449         {\r
450                 if(MenuHistId[i] == MenuCmd)\r
451                 {\r
452                         memcpy(Buf, Pos, sizeof(HISTORYDATA));\r
453                         Sts = FFFTP_SUCCESS;\r
454                 }\r
455                 Pos = Pos->Next;\r
456         }\r
457         return(Sts);\r
458 }\r
459 \r
460 \r
461 /*----- 指定番号に対応するヒストリを返す --------------------------------------\r
462 *\r
463 *       Parameter\r
464 *               int Num : 番号(0~)\r
465 *               HISTORYDATA *Buf : ヒストリデータを返すバッファ\r
466 *\r
467 *       Return Value\r
468 *               int ステータス\r
469 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
470 *----------------------------------------------------------------------------*/\r
471 \r
472 int GetHistoryByNum(int Num, HISTORYDATA *Buf)\r
473 {\r
474         return(GetHistoryByCmd(MenuHistId[Num], Buf));\r
475 }\r
476 \r
477 \r