OSDN Git Service

Fix bugs of corruption on resuming downloading files larger than 4GB.
[ffftp/ffftp.git] / ras.c
1 /*=============================================================================\r
2 *\r
3 *                                                                       RAS関係\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 \r
32 // UTF-8対応\r
33 //#define WINVER 0x400\r
34 \r
35 #include <windows.h>\r
36 #include <stdio.h>\r
37 #include <stdlib.h>\r
38 #include <string.h>\r
39 #include <mbstring.h>\r
40 #include <malloc.h>\r
41 #include <windowsx.h>\r
42 #include <winsock.h>\r
43 #include <ras.h>\r
44 #include <rasdlg.h>\r
45 #include <raserror.h>\r
46 \r
47 #include "common.h"\r
48 #include "resource.h"\r
49 \r
50 \r
51 typedef DWORD (WINAPI*FUNC_RASENUMCONNECTIONS) (LPRASCONN, LPDWORD, LPDWORD);\r
52 typedef DWORD (WINAPI*FUNC_RASENUMENTRIES) (LPCTSTR, LPCTSTR, LPRASENTRYNAME, LPDWORD, LPDWORD);\r
53 typedef DWORD (WINAPI*FUNC_RASHANGUP) (HRASCONN);\r
54 typedef BOOL (WINAPI*FUNC_RASDIAL) (LPRASDIALEXTENSIONS, LPCTSTR, LPRASDIALPARAMS, DWORD, LPVOID, LPHRASCONN);\r
55 typedef BOOL (WINAPI*FUNC_RASGETENTRYDIALPARAMS) (LPCTSTR, LPRASDIALPARAMS, LPBOOL);\r
56 typedef BOOL (WINAPI*FUNC_RASGETCONNECTSTATUS) (HRASCONN, LPRASCONNSTATUS);\r
57 typedef BOOL (WINAPI*FUNC_RASGETERRORSTRING)(UINT, LPTSTR, DWORD);\r
58 \r
59 typedef BOOL (WINAPI*FUNC_RASDIALDLG) (LPSTR, LPSTR, LPSTR, LPRASDIALDLG);\r
60 \r
61 \r
62 static int GetCurConnections(RASCONN **Buf);\r
63 static DWORD RasHangUpWait(HRASCONN hRasConn);\r
64 static int DoDisconnect(RASCONN *Buf, int Num);\r
65 static BOOL CALLBACK DialCallBackProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
66 static VOID WINAPI RasDialFunc( UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError );\r
67 static void MakeRasConnMsg(char *Phone, RASCONNSTATE rasconn, char *Buf);\r
68 static BOOL CALLBACK DialPassCallBackProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
69 \r
70 \r
71 /*===== ローカルなワーク =====*/\r
72 \r
73 static HINSTANCE m_hDll = NULL;\r
74 static HINSTANCE m_hDll2 = NULL;\r
75 \r
76 static FUNC_RASENUMCONNECTIONS m_RasEnumConnections = NULL;\r
77 static FUNC_RASENUMENTRIES m_RasEnumEntries = NULL;\r
78 static FUNC_RASHANGUP m_RasHangUp = NULL;\r
79 static FUNC_RASDIAL m_RasDial = NULL;\r
80 static FUNC_RASGETENTRYDIALPARAMS m_RasGetEntryDialParams = NULL;\r
81 static FUNC_RASGETCONNECTSTATUS m_RasGetConnectStatus = NULL;\r
82 static FUNC_RASGETERRORSTRING m_RasGetErrorString = NULL;\r
83 \r
84 static FUNC_RASDIALDLG m_RasDialDlg = NULL;\r
85 \r
86 static HWND hWndDial;\r
87 \r
88 \r
89 \r
90 /*----- RASライブラリをロードする ---------------------------------------------\r
91 *\r
92 *       Parameter\r
93 *               なし\r
94 *\r
95 *       Return Value\r
96 *               なし\r
97 *\r
98 *       Note\r
99 *               RASライブラリは必ずインストールされるものではないので、スタティックに\r
100 *               リンクしない。\r
101 *----------------------------------------------------------------------------*/\r
102 \r
103 void LoadRasLib(void)\r
104 {\r
105         if((m_hDll = LoadLibrary("rasapi32.dll")) != NULL)\r
106         {\r
107                 m_RasEnumConnections = (FUNC_RASENUMCONNECTIONS)GetProcAddress(m_hDll, "RasEnumConnectionsA");\r
108                 m_RasEnumEntries = (FUNC_RASENUMENTRIES)GetProcAddress(m_hDll, "RasEnumEntriesA");\r
109                 m_RasHangUp = (FUNC_RASHANGUP)GetProcAddress(m_hDll, "RasHangUpA");\r
110                 m_RasDial = (FUNC_RASDIAL)GetProcAddress(m_hDll, "RasDialA");\r
111                 m_RasGetEntryDialParams = (FUNC_RASGETENTRYDIALPARAMS)GetProcAddress(m_hDll, "RasGetEntryDialParamsA");\r
112                 m_RasGetConnectStatus = (FUNC_RASGETCONNECTSTATUS)GetProcAddress(m_hDll, "RasGetConnectStatusA");\r
113                 m_RasGetErrorString = (FUNC_RASGETERRORSTRING)GetProcAddress(m_hDll, "RasGetErrorStringA");\r
114 \r
115                 if((m_RasEnumConnections == NULL) ||\r
116                    (m_RasEnumEntries == NULL) ||\r
117                    (m_RasHangUp == NULL) ||\r
118                    (m_RasDial == NULL) ||\r
119                    (m_RasGetEntryDialParams == NULL) ||\r
120                    (m_RasGetConnectStatus == NULL) ||\r
121                    (m_RasGetErrorString == NULL))\r
122                 {\r
123                         FreeLibrary(m_hDll);\r
124                         m_hDll = NULL;\r
125                 }\r
126         }\r
127 \r
128         if(m_hDll != NULL)\r
129         {\r
130                 if((m_hDll2 = LoadLibrary("rasdlg.dll")) != NULL)\r
131                 {\r
132                         m_RasDialDlg = (FUNC_RASDIALDLG)GetProcAddress(m_hDll2, "RasDialDlgA");\r
133 \r
134                         if(m_RasDialDlg == NULL)\r
135                         {\r
136                                 FreeLibrary(m_hDll2);\r
137                                 m_hDll2 = NULL;\r
138                         }\r
139                 }\r
140         }\r
141         return;\r
142 }\r
143 \r
144 \r
145 /*----- RASライブラリをリリースする -------------------------------------------\r
146 *\r
147 *       Parameter\r
148 *               なし\r
149 *\r
150 *       Return Value\r
151 *               なし\r
152 *----------------------------------------------------------------------------*/\r
153 \r
154 void ReleaseRasLib(void)\r
155 {\r
156         if(m_hDll != NULL)\r
157                 FreeLibrary(m_hDll);\r
158         m_hDll = NULL;\r
159 \r
160         if(m_hDll2 != NULL)\r
161                 FreeLibrary(m_hDll2);\r
162         m_hDll2 = NULL;\r
163 \r
164         return;\r
165 }\r
166 \r
167 \r
168 /*----- RASが使えるかどうかを返す ---------------------------------------------\r
169 *\r
170 *       Parameter\r
171 *               なし\r
172 *\r
173 *       Return Value\r
174 *               int RASが使えるかどうか\r
175 *                       YES/NO\r
176 *----------------------------------------------------------------------------*/\r
177 \r
178 int AskRasUsable(void)\r
179 {\r
180         int Sts;\r
181 \r
182         Sts = NO;\r
183         if(m_hDll != NULL)\r
184                 Sts = YES;\r
185 \r
186         return(Sts);\r
187 }\r
188 \r
189 \r
190 /*----- 現在のRASコネクション一覧を返す ---------------------------------------\r
191 *\r
192 *       Parameter\r
193 *               RASCONN **Buf : 一覧へのポインタを返すワーク\r
194 *\r
195 *       Return Value\r
196 *               int 個数 (-1=エラー)\r
197 *\r
198 *       Note\r
199 *               Bufの領域は呼出側で開放すること\r
200 *----------------------------------------------------------------------------*/\r
201 \r
202 static int GetCurConnections(RASCONN **Buf)\r
203 {\r
204         RASCONN *RasConn;\r
205         RASCONN *Tmp;\r
206         DWORD Size;\r
207         DWORD Num;\r
208         DWORD Sts;\r
209         int Ret;\r
210 \r
211         Ret = -1;\r
212         Size = sizeof(RASCONN);\r
213         if((RasConn = malloc(Size)) != NULL)\r
214         {\r
215                 RasConn->dwSize = sizeof(RASCONN);\r
216                 Sts = (*m_RasEnumConnections)(RasConn, &Size, &Num);\r
217                 if((Sts == ERROR_BUFFER_TOO_SMALL) || (Sts == ERROR_NOT_ENOUGH_MEMORY))\r
218             {\r
219                         if((Tmp = realloc(RasConn, Size)) != NULL)\r
220                 {\r
221                                 RasConn = Tmp;\r
222                                 Sts = (*m_RasEnumConnections)(RasConn, &Size, &Num);\r
223                         }\r
224                 }\r
225 \r
226                 if(Sts == 0)\r
227                 {\r
228                         Ret = Num;\r
229                         *Buf = RasConn;\r
230                 }\r
231                 else\r
232                         free(RasConn);\r
233         }\r
234         return(Ret);\r
235 }\r
236 \r
237 \r
238 /*----- RasHangUp()------------------------------------------------------------\r
239 *\r
240 *       Parameter\r
241 *               HRASCONN hRasConn : ハンドル\r
242 *\r
243 *       Return Value\r
244 *               DWORD ステータス\r
245 *\r
246 *       Note\r
247 *               切断が完了するまで待つ\r
248 *----------------------------------------------------------------------------*/\r
249 \r
250 static DWORD RasHangUpWait(HRASCONN hRasConn)\r
251 {\r
252         RASCONNSTATUS RasSts;\r
253         DWORD Sts;\r
254 \r
255         Sts = (*m_RasHangUp)(hRasConn);\r
256 \r
257         RasSts.dwSize = sizeof(RASCONNSTATUS);\r
258         while((*m_RasGetConnectStatus)(hRasConn, &RasSts) != ERROR_INVALID_HANDLE)\r
259                 Sleep(10);\r
260 \r
261         return(Sts);\r
262 }\r
263 \r
264 \r
265 /*----- 現在のRASコネクションを切断する ---------------------------------------\r
266 *\r
267 *       Parameter\r
268 *               RASCONN *RasConn : 接続一覧\r
269 *               int Num : 個数\r
270 *\r
271 *       Return Value\r
272 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
273 *----------------------------------------------------------------------------*/\r
274 \r
275 static int DoDisconnect(RASCONN *RasConn, int Num)\r
276 {\r
277         int i;\r
278         int Sts;\r
279 \r
280         Sts = FFFTP_SUCCESS;\r
281         if(Num > 0)\r
282         {\r
283                 SetTaskMsg(MSGJPN220);\r
284                 for(i = 0; i < Num; i++)\r
285                 {\r
286                         if(RasHangUpWait(RasConn[i].hrasconn) != 0)\r
287                                 Sts = FFFTP_FAIL;\r
288                 }\r
289         }\r
290         return(Sts);\r
291 }\r
292 \r
293 \r
294 /*----- RASを切断する ---------------------------------------------------------\r
295 *\r
296 *       Parameter\r
297 *               int Notify : 確認するかどうか (YES/NO)\r
298 *\r
299 *       Return Value\r
300 *               なし\r
301 *----------------------------------------------------------------------------*/\r
302 \r
303 void DisconnectRas(int Notify)\r
304 {\r
305         RASCONN *RasConn;\r
306         int Num;\r
307 \r
308         if(m_hDll != NULL)\r
309         {\r
310                 if((Num = GetCurConnections(&RasConn)) != -1)\r
311                 {\r
312                         if(Num > 0)\r
313                         {\r
314                                 if((Notify == NO) ||\r
315                                    (DialogBox(GetFtpInst(), MAKEINTRESOURCE(rasnotify_dlg), GetMainHwnd(), ExeEscDialogProc) == YES))\r
316                                 {\r
317                                         DoDisconnect(RasConn, Num);\r
318                                 }\r
319                         }\r
320                         free(RasConn);\r
321                 }\r
322         }\r
323         return;\r
324 }\r
325 \r
326 \r
327 /*----- RASのエントリ一覧をコンボボックスにセットする -------------------------\r
328 *\r
329 *       Parameter\r
330 *               HWND hDlg : ダイアログボックスのハンドル\r
331 *               int Item : コンボボックスのリソース番号\r
332 *               char *CurName : 初期値\r
333 *\r
334 *       Return Value\r
335 *               int エントリ数\r
336 *----------------------------------------------------------------------------*/\r
337 \r
338 int SetRasEntryToComboBox(HWND hDlg, int Item, char *CurName)\r
339 {\r
340         RASENTRYNAME *Entry;\r
341         RASENTRYNAME *Tmp;\r
342         DWORD i;\r
343         DWORD Size;\r
344         DWORD Num;\r
345         DWORD Sts;\r
346 \r
347         Num = 0;\r
348         if(m_hDll != NULL)\r
349         {\r
350                 Size = sizeof(RASENTRYNAME);\r
351                 if((Entry = malloc(Size)) != NULL)\r
352                 {\r
353                         Entry->dwSize = sizeof(RASENTRYNAME);\r
354                         Sts = (*m_RasEnumEntries)(NULL, NULL, Entry, &Size, &Num);\r
355                         if((Sts == ERROR_BUFFER_TOO_SMALL) || (Sts == ERROR_NOT_ENOUGH_MEMORY))\r
356                         {\r
357                                 if((Tmp = realloc(Entry, Size)) != NULL)\r
358                         {\r
359                                         Entry = Tmp;\r
360                                         Sts = (*m_RasEnumEntries)(NULL, NULL, Entry, &Size, &Num);\r
361                                 }\r
362                         }\r
363 \r
364                         if((Sts == 0) && (Num > 0))\r
365                         {\r
366                                 for(i = 0; i < Num; i++)\r
367                                         SendDlgItemMessage(hDlg, Item, CB_ADDSTRING, 0, (LPARAM)Entry[i].szEntryName);\r
368 \r
369                                 SendDlgItemMessage(hDlg, Item, CB_SELECTSTRING, -1, (LPARAM)CurName);\r
370                         }\r
371                         free(Entry);\r
372                 }\r
373         }\r
374         return(Num);\r
375 }\r
376 \r
377 \r
378 /*----- RASの接続を行う -------------------------------------------------------\r
379 *\r
380 *       Parameter\r
381 *               int Dialup : ダイアルアップするかどうか (YES/NO)\r
382 *               int UseThis : 必ずこのエントリに接続するかどうか (YES/NO)\r
383 *               int Notify : 再接続前に確認するかどうか (YES/NO)\r
384 *               char *Name : 接続先\r
385 *\r
386 *       Return Value\r
387 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
388 *----------------------------------------------------------------------------*/\r
389 \r
390 int ConnectRas(int Dialup, int UseThis, int Notify, char *Name)\r
391 {\r
392         RASDIALDLG DlgParam;\r
393         RASCONN *RasConn;\r
394         int i;\r
395         int Num;\r
396         int Sts;\r
397         int DoDial;\r
398         RASDIALPARAMS Param;\r
399         BOOL Flg;\r
400         OSVERSIONINFO VerInfo;\r
401 \r
402         Sts = FFFTP_SUCCESS;\r
403         if(Dialup == YES)\r
404         {\r
405                 if(m_hDll != NULL)\r
406                 {\r
407                         /* 現在の接続を確認 */\r
408                         DoDial = 1;\r
409                         if((Num = GetCurConnections(&RasConn)) != -1)\r
410                         {\r
411                                 if(Num > 0)\r
412                                 {\r
413                                         DoDial = 0;\r
414                                         if(UseThis == YES)\r
415                                         {\r
416                                                 DoDial = 2;\r
417                                                 for(i = 0; i < Num; i++)\r
418                                                 {\r
419                                                         if(_mbscmp(RasConn[i].szEntryName, Name) == 0)\r
420                                                                 DoDial = 0;\r
421                                                 }\r
422 \r
423                                                 if(DoDial == 2)\r
424                                                 {\r
425                                                         if((Notify == NO) ||\r
426                                                            (DialogBox(GetFtpInst(), MAKEINTRESOURCE(rasreconnect_dlg), GetMainHwnd(), ExeEscDialogProc) == YES))\r
427                                                         {\r
428                                                                 DoDisconnect(RasConn, Num);\r
429                                                         }\r
430                                                         else\r
431                                                                 DoDial = 0;\r
432                                                 }\r
433                                         }\r
434                                 }\r
435                                 free(RasConn);\r
436                         }\r
437 \r
438                         if(DoDial != 0)\r
439                         {\r
440                                 /* 接続する */\r
441                                 SetTaskMsg(MSGJPN221);\r
442                                 Sts = FFFTP_FAIL;\r
443 \r
444                                 Num = 0;\r
445                                 VerInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\r
446                                 if(GetVersionEx(&VerInfo) == TRUE)\r
447                                 {\r
448                                         if(VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)\r
449                                                 Num = 1;\r
450                                 }\r
451 \r
452                                 if(Num == 1)\r
453                                 {\r
454                                         if(m_hDll2 != NULL)\r
455                                         {\r
456                                                 /* Windows NT */\r
457                                                 DlgParam.dwSize = sizeof(RASDIALDLG);\r
458                                                 DlgParam.hwndOwner = GetMainHwnd();\r
459                                                 DlgParam.dwFlags = 0;\r
460                                                 DlgParam.dwSubEntry = 0;\r
461                                                 DlgParam.reserved = 0;\r
462                                                 DlgParam.reserved2 = 0;\r
463                                                 if((*m_RasDialDlg)(NULL, Name, NULL, &DlgParam) != 0)\r
464                                                         Sts = FFFTP_SUCCESS;\r
465                                         }\r
466                                         else\r
467                                                 SetTaskMsg(MSGJPN222);\r
468                                 }\r
469                                 else\r
470                                 {\r
471                                         /* Windows 95,98 */\r
472                                         Param.dwSize = sizeof(RASDIALPARAMS);\r
473                                         strcpy(Param.szEntryName, Name);\r
474                                         Flg = TRUE;\r
475                                         Sts = (*m_RasGetEntryDialParams)(NULL, &Param, &Flg);\r
476                                         strcpy(Param.szPhoneNumber, "");\r
477 \r
478                                         if(((strlen(Param.szUserName) != 0) && (strlen(Param.szPassword) != 0)) ||\r
479                                            (DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(dial_password_dlg), GetMainHwnd(), (DLGPROC)DialPassCallBackProc, (LPARAM)&Param) == YES))\r
480                                         {\r
481                                                 if(DialogBoxParam(GetFtpInst(), MAKEINTRESOURCE(dial_dlg), GetMainHwnd(), (DLGPROC)DialCallBackProc, (LPARAM)&Param) == YES)\r
482                                                         Sts = FFFTP_SUCCESS;\r
483                                         }\r
484                                 }\r
485                         }\r
486                 }\r
487         }\r
488         return(Sts);\r
489 }\r
490 \r
491 \r
492 /*----- RASダイアルウインドウのコールバック -----------------------------------\r
493 *\r
494 *       Parameter\r
495 *               HWND hDlg : ウインドウハンドル\r
496 *               UINT message : メッセージ番号\r
497 *               WPARAM wParam : メッセージの WPARAM 引数\r
498 *               LPARAM lParam : メッセージの LPARAM 引数\r
499 *\r
500 *       Return Value\r
501 *               BOOL TRUE/FALSE\r
502 *----------------------------------------------------------------------------*/\r
503 \r
504 static BOOL CALLBACK DialCallBackProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
505 {\r
506         static RASDIALPARAMS *Param;\r
507         static HRASCONN hRasConn;\r
508         char Tmp[RAS_NAME_LEN+25];\r
509         DWORD Sts;\r
510 \r
511         switch (message)\r
512         {\r
513                 case WM_INITDIALOG :\r
514                         Param = (RASDIALPARAMS *)lParam;\r
515                         hWndDial = hDlg;\r
516                         hRasConn = NULL;\r
517                         sprintf(Tmp, MSGJPN223, Param->szEntryName);\r
518                         SendMessage(hDlg, WM_SETTEXT, 0, (LPARAM)Tmp);\r
519                         Sts = (*m_RasDial)(NULL, NULL, Param, 0, &RasDialFunc, &hRasConn);\r
520                         if(Sts != 0)\r
521                         EndDialog(hDlg, NO);\r
522                     return(TRUE);\r
523 \r
524                 case WM_COMMAND :\r
525                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
526                         {\r
527                                 case IDCANCEL :\r
528                                         RasHangUpWait(hRasConn);\r
529                                         EndDialog(hDlg, NO);\r
530                                         break;\r
531                         }\r
532                         return(TRUE);\r
533 \r
534                 case WM_DIAL_MSG :\r
535                         if(lParam != 0)\r
536                         {\r
537                                 /* エラー発生 */\r
538                                 if((*m_RasGetErrorString)((UINT)lParam, (LPTSTR)Tmp, RAS_NAME_LEN+25) != 0)\r
539                                         sprintf(Tmp, MSGJPN224);\r
540                                 RasHangUpWait(hRasConn);\r
541                                 MessageBox(hDlg, Tmp, MSGJPN225, MB_OK | MB_ICONSTOP);\r
542                                 EndDialog(hDlg, NO);\r
543                         }\r
544                         else if(wParam & RASCS_DONE)\r
545                         {\r
546                                 /* 終了 */\r
547                                 EndDialog(hDlg, YES);\r
548                         }\r
549                         else\r
550                         {\r
551                                 /* ステータス変更 */\r
552                                 MakeRasConnMsg(Param->szPhoneNumber, wParam, Tmp);\r
553                                 SendDlgItemMessage(hDlg, DIAL_STATUS, WM_SETTEXT, 0, (LPARAM)Tmp);\r
554                         }\r
555                         return(TRUE);\r
556         }\r
557         return(FALSE);\r
558 }\r
559 \r
560 \r
561 /*----- RasDial()のコールバック -----------------------------------------------\r
562 *\r
563 *       Parameter\r
564 *               UINT unMsg : メッセージ\r
565 *               RASCONNSTATE rasconnstate : ステータス\r
566 *               DWORD dwError : エラー\r
567 *\r
568 *       Return Value\r
569 *               なし\r
570 *----------------------------------------------------------------------------*/\r
571 \r
572 static VOID WINAPI RasDialFunc(UINT unMsg, RASCONNSTATE rasconnstate, DWORD dwError)\r
573 {\r
574         PostMessage(hWndDial, WM_DIAL_MSG, (WPARAM)rasconnstate, (LPARAM)dwError );\r
575 }\r
576 \r
577 \r
578 /*----- RasDial()のステータスメッセージを作成する -----------------------------\r
579 *\r
580 *       Parameter\r
581 *               char *Phone : 電話番号\r
582 *               RASCONNSTATE rasconn : ステータス\r
583 *               char *Buf : 文字列をセットするバッファ\r
584 *\r
585 *       Return Value\r
586 *               なし\r
587 *----------------------------------------------------------------------------*/\r
588 \r
589 static void MakeRasConnMsg(char *Phone, RASCONNSTATE rasconn, char *Buf)\r
590 {\r
591     switch( rasconn )\r
592     {\r
593         case RASCS_OpenPort:\r
594             strcpy(Buf, MSGJPN226);\r
595                         break;\r
596         case RASCS_PortOpened:\r
597             strcpy(Buf, MSGJPN227);\r
598                         break;\r
599         case RASCS_ConnectDevice:\r
600             sprintf(Buf, MSGJPN228);\r
601                         break;\r
602         case RASCS_DeviceConnected:\r
603             strcpy(Buf, MSGJPN229);\r
604                         break;\r
605         case RASCS_AllDevicesConnected:\r
606             strcpy(Buf, MSGJPN230);\r
607                         break;\r
608         case RASCS_Authenticate:\r
609         case RASCS_AuthNotify:\r
610             strcpy(Buf, MSGJPN231);\r
611                         break;\r
612         case RASCS_AuthRetry:\r
613         case RASCS_ReAuthenticate:\r
614             strcpy(Buf, MSGJPN232);\r
615                         break;\r
616         case RASCS_AuthChangePassword:\r
617             strcpy(Buf, MSGJPN233);\r
618                         break;\r
619         case RASCS_Authenticated:\r
620             strcpy(Buf, MSGJPN234);\r
621                         break;\r
622         case RASCS_Connected:\r
623             strcpy(Buf, MSGJPN235);\r
624                         break;\r
625         case RASCS_Disconnected:\r
626             strcpy(Buf, MSGJPN236);\r
627                         break;\r
628         case RASCS_AuthCallback:\r
629         case RASCS_PrepareForCallback:\r
630         case RASCS_WaitForModemReset:\r
631         case RASCS_WaitForCallback:\r
632         case RASCS_Interactive:\r
633         case RASCS_RetryAuthentication:\r
634         case RASCS_CallbackSetByCaller:\r
635         case RASCS_PasswordExpired:\r
636         case RASCS_AuthProject:\r
637         case RASCS_AuthLinkSpeed:\r
638         case RASCS_AuthAck:\r
639         default:\r
640             strcpy(Buf, MSGJPN237);\r
641                         break;\r
642     }\r
643         return;\r
644 }\r
645 \r
646 \r
647 /*----- ユーザ名、パスワード入力ウインドウのコールバック ----------------------\r
648 *\r
649 *       Parameter\r
650 *               HWND hDlg : ウインドウハンドル\r
651 *               UINT message : メッセージ番号\r
652 *               WPARAM wParam : メッセージの WPARAM 引数\r
653 *               LPARAM lParam : メッセージの LPARAM 引数\r
654 *\r
655 *       Return Value\r
656 *               BOOL TRUE/FALSE\r
657 *----------------------------------------------------------------------------*/\r
658 \r
659 static BOOL CALLBACK DialPassCallBackProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
660 {\r
661         static RASDIALPARAMS *Param;\r
662         char Tmp[RAS_NAME_LEN+25];\r
663 \r
664         switch (message)\r
665         {\r
666                 case WM_INITDIALOG :\r
667                         Param = (RASDIALPARAMS *)lParam;\r
668                         sprintf(Tmp, MSGJPN238, Param->szEntryName);\r
669                         SendMessage(hDlg, WM_SETTEXT, 0, (LPARAM)Tmp);\r
670                         SendDlgItemMessage(hDlg, RASPASS_USER, EM_LIMITTEXT, UNLEN, 0);\r
671                         SendDlgItemMessage(hDlg, RASPASS_PASS, EM_LIMITTEXT, PWLEN, 0);\r
672                         SendDlgItemMessage(hDlg, RASPASS_USER, WM_SETTEXT, 0, (LPARAM)Param->szUserName);\r
673                         SendDlgItemMessage(hDlg, RASPASS_PASS, WM_SETTEXT, 0, (LPARAM)Param->szPassword);\r
674                     return(TRUE);\r
675 \r
676                 case WM_COMMAND :\r
677                         switch(GET_WM_COMMAND_ID(wParam, lParam))\r
678                         {\r
679                                 case IDOK :\r
680                                         SendDlgItemMessage(hDlg, RASPASS_USER, WM_GETTEXT, UNLEN+1, (LPARAM)Param->szUserName);\r
681                                         SendDlgItemMessage(hDlg, RASPASS_PASS, WM_GETTEXT, PWLEN+1, (LPARAM)Param->szPassword);\r
682                                         EndDialog(hDlg, YES);\r
683                                         break;\r
684 \r
685                                 case IDCANCEL :\r
686                                         EndDialog(hDlg, NO);\r
687                                         break;\r
688                         }\r
689                         return(TRUE);\r
690         }\r
691         return(FALSE);\r
692 }\r
693 \r
694 \r