OSDN Git Service

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