Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/ttplug.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10658 - (hide annotations) (download) (as text)
Sun Apr 2 16:08:12 2023 UTC (12 months, 1 week ago) by zmatsuo
File MIME type: text/x-csrc
File size: 10154 byte(s)
プラグイン読み込み時必要なDLLが存在しない場合メッセージを追加

- ttxssh.dll 読み込み時に bcrypt.dll が存在しない場合など
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3     * (C) Robert O'Callahan
4 nmaya 9048 * (C) 2004- TeraTerm Project
5 doda 6806 * All rights reserved.
6     *
7 doda 6841 * Redistribution and use in source and binary forms, with or without
8     * modification, are permitted provided that the following conditions
9     * are met:
10 doda 6806 *
11 doda 6841 * 1. Redistributions of source code must retain the above copyright
12     * notice, this list of conditions and the following disclaimer.
13     * 2. Redistributions in binary form must reproduce the above copyright
14     * notice, this list of conditions and the following disclaimer in the
15     * documentation and/or other materials provided with the distribution.
16     * 3. The name of the author may not be used to endorse or promote products
17     * derived from this software without specific prior written permission.
18 doda 6806 *
19 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
20     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 doda 6806 */
30 zmatsuo 9227 #include <winsock2.h>
31 maya 3227 #include "teraterm.h"
32     #include "tttypes.h"
33     #include "ttlib.h"
34    
35 zmatsuo 9224 #define _CRTDBG_MAP_ALLOC
36 maya 3227 #include <stdlib.h>
37     #include <stdio.h>
38     #include <string.h>
39 zmatsuo 9224 #include <crtdbg.h>
40 zmatsuo 9387
41 maya 3227 #include "ttplugin.h"
42 zmatsuo 9224 #include "codeconv.h"
43 zmatsuo 9225 #include "asprintf.h"
44 maya 3227
45 zmatsuo 9225 #include "ttplug.h"
46    
47 maya 3227 typedef struct _ExtensionList {
48 zmatsuo 9226 TTXExports * exports;
49     HANDLE LibHandle;
50 maya 3227 } ExtensionList;
51    
52 zmatsuo 9226 static ExtensionList *Extensions;
53 zmatsuo 9387 static int NumExtensions = 0;
54 zmatsuo 9226
55 zmatsuo 9387 static int compareOrder(const void * e1, const void * e2)
56     {
57     TTXExports * * exports1 = (TTXExports * *)e1;
58     TTXExports * * exports2 = (TTXExports * *)e2;
59 maya 3227
60 zmatsuo 9387 return (*exports1)->loadOrder - (*exports2)->loadOrder;
61 maya 3227 }
62    
63 zmatsuo 9387 static void loadExtension(wchar_t const *fileName, const wchar_t *UILanguageFile)
64 zmatsuo 9224 {
65     DWORD err;
66     const wchar_t *sub_message;
67     HMODULE hPlugin;
68 maya 3227
69 zmatsuo 9324 hPlugin = LoadLibraryW(fileName);
70 zmatsuo 9224 if (hPlugin != NULL) {
71     TTXBindProc bind = NULL;
72 zmatsuo 9227 FARPROC *pbind = (FARPROC *)&bind;
73 zmatsuo 7536 #if defined(_MSC_VER)
74 zmatsuo 9224 if (bind == NULL)
75 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "_TTXBind@8");
76 zmatsuo 7536 #else
77 zmatsuo 9224 if (bind == NULL)
78 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind@8");
79 zmatsuo 7536 #endif
80 zmatsuo 9224 if (bind == NULL)
81 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind");
82 zmatsuo 9224 if (bind != NULL) {
83 zmatsuo 9226 TTXExports * exports = (TTXExports *)malloc(sizeof(TTXExports));
84     if (exports == NULL) {
85     return;
86     }
87     memset(exports, 0, sizeof(TTXExports));
88     exports->size = sizeof(TTXExports);
89 maya 3227
90 zmatsuo 9226 if (bind(TTVERSION, exports)) {
91     ExtensionList *newExtension;
92     ExtensionList *extensions = (ExtensionList *)realloc(Extensions, sizeof(ExtensionList) * (NumExtensions + 1));
93     if (extensions == NULL) {
94     free(exports);
95     FreeLibrary(hPlugin);
96     return;
97     }
98     Extensions = extensions;
99     newExtension = &extensions[NumExtensions];
100 zmatsuo 9224 NumExtensions++;
101 zmatsuo 9226
102     newExtension->exports = exports;
103     newExtension->LibHandle = hPlugin;
104 zmatsuo 9224 return;
105     }
106     else {
107 zmatsuo 9226 free(exports);
108 zmatsuo 9224 }
109     }
110 zmatsuo 9226 FreeLibrary(hPlugin);
111 zmatsuo 9224 }
112 maya 3227
113 zmatsuo 9224 err = GetLastError();
114     switch (err) {
115     case 31:
116     sub_message = L"Unresolved dll entry";
117     break;
118     case 1114:
119     sub_message = L"tls entry exists";
120     break;
121     case 2:
122     sub_message = L"rejected by plugin";
123     break;
124     case 193:
125     sub_message = L"invalid dll image";
126     break;
127 zmatsuo 10658 case 126:
128     sub_message = L"dll not exist";
129     break;
130 zmatsuo 9224 default:
131     sub_message = L"unknown";
132     break;
133     }
134     // �����t�@�C�����������b�Z�[�W�����������s�����������A�������_����������
135     // �������������������������A���b�Z�[�W���p���������������B�v�����B
136 zmatsuo 9230 {
137 zmatsuo 9342 static const TTMessageBoxInfoW info = {
138     "Tera Term",
139     "MSG_TT_ERROR", L"Tera Term: Error",
140     "MSG_LOAD_EXT_ERROR", L"Cannot load extension %s (%d, %s)",
141     MB_OK | MB_ICONEXCLAMATION
142     };
143 zmatsuo 9387 TTMessageBoxW(NULL, &info, UILanguageFile, fileName, err, sub_message);
144 zmatsuo 9230 }
145 maya 3227 }
146    
147 zmatsuo 9356 static void LoadExtensions(PTTSet ts_)
148 zmatsuo 9225 {
149     wchar_t *load_mask;
150     WIN32_FIND_DATAW fd;
151     HANDLE hFind;
152 zmatsuo 9501 wchar_t *ExeDirW = ts_->ExeDirW;
153 maya 3227
154 zmatsuo 9501 aswprintf(&load_mask, L"%s\\TTX*.DLL", ExeDirW);
155 maya 3227
156 zmatsuo 9324 hFind = FindFirstFileW(load_mask, &fd);
157 zmatsuo 9225 if (hFind != INVALID_HANDLE_VALUE) {
158     do {
159     wchar_t *filename;
160 zmatsuo 9501 aswprintf(&filename, L"%s\\%s", ExeDirW, fd.cFileName);
161 zmatsuo 9387 loadExtension(filename, ts_->UILanguageFileW);
162 zmatsuo 9225 free(filename);
163 zmatsuo 9324 } while (FindNextFileW(hFind, &fd));
164 zmatsuo 9225 FindClose(hFind);
165     }
166     free(load_mask);
167 maya 3227
168 zmatsuo 9225 if (NumExtensions==0) return;
169 maya 3227
170 zmatsuo 9225 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
171 zmatsuo 9356 }
172 maya 3227
173 zmatsuo 9356 static void UnloadExtensions()
174     {
175     int i;
176 zmatsuo 9225 for (i = 0; i < NumExtensions; i++) {
177 zmatsuo 9356 free(Extensions[i].exports);
178     FreeLibrary(Extensions[i].LibHandle);
179     }
180    
181     free(Extensions);
182     Extensions = NULL;
183     NumExtensions = 0;
184     }
185    
186     void PASCAL TTXInit(PTTSet ts_, PComVar cv_)
187     {
188     int i;
189    
190     LoadExtensions(ts_);
191    
192     if (NumExtensions==0) return;
193    
194     for (i = 0; i < NumExtensions; i++) {
195 zmatsuo 9226 if (Extensions[i].exports->TTXInit != NULL) {
196     Extensions[i].exports->TTXInit(ts_, cv_);
197 zmatsuo 9225 }
198     }
199 maya 3227 }
200    
201 zmatsuo 9223 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
202 maya 3227 int i;
203    
204     for (i = 0; i < NumExtensions; i++) {
205 zmatsuo 9226 if (Extensions[i].exports->TTXOpenTCP != NULL) {
206     Extensions[i].exports->TTXOpenTCP(hooks);
207 maya 3227 }
208     }
209     }
210    
211 zmatsuo 9223 void PASCAL TTXOpenTCP(void)
212     {
213 zmatsuo 9226 static TTXSockHooks SockHooks = {
214     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
215     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
216     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
217     &PWSACancelAsyncRequest, &PWSAGetLastError,
218     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
219     };
220     TTXInternalOpenTCP(&SockHooks);
221 zmatsuo 9223 }
222    
223     static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
224 maya 3227 int i;
225    
226     for (i = NumExtensions - 1; i >= 0; i--) {
227 zmatsuo 9226 if (Extensions[i].exports->TTXCloseTCP != NULL) {
228     Extensions[i].exports->TTXCloseTCP(hooks);
229 maya 3227 }
230     }
231     }
232    
233 zmatsuo 9223 void PASCAL TTXCloseTCP(void)
234     {
235 zmatsuo 9226 static TTXSockHooks SockHooks = {
236     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
237     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
238     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
239     &PWSACancelAsyncRequest, &PWSAGetLastError,
240     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
241     };
242     TTXInternalCloseTCP(&SockHooks);
243 zmatsuo 9223 }
244    
245     static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
246 maya 3227 int i;
247    
248     for (i = 0; i < NumExtensions; i++) {
249 zmatsuo 9226 if (Extensions[i].exports->TTXOpenFile != NULL) {
250     Extensions[i].exports->TTXOpenFile(hooks);
251 maya 3227 }
252     }
253     }
254    
255 zmatsuo 9223 void PASCAL TTXOpenFile(void)
256     {
257 zmatsuo 9226 static TTXFileHooks FileHooks = {
258     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
259     };
260     TTXInternalOpenFile(&FileHooks);
261 zmatsuo 9223 }
262    
263     static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
264 maya 3227 int i;
265    
266     for (i = NumExtensions - 1; i >= 0; i--) {
267 zmatsuo 9226 if (Extensions[i].exports->TTXCloseFile != NULL) {
268     Extensions[i].exports->TTXCloseFile(hooks);
269 maya 3227 }
270     }
271     }
272    
273 zmatsuo 9223 void PASCAL TTXCloseFile(void)
274     {
275 zmatsuo 9226 static TTXFileHooks FileHooks = {
276     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
277     };
278     TTXInternalCloseFile(&FileHooks);
279 zmatsuo 9223 }
280    
281     static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
282 maya 3227 int i;
283    
284     for (i = 0; i < NumExtensions; i++) {
285 zmatsuo 9226 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
286     Extensions[i].exports->TTXGetUIHooks(hooks);
287 maya 3227 }
288     }
289     }
290    
291 zmatsuo 9223 void PASCAL TTXGetUIHooks(void)
292     {
293 zmatsuo 9226 static TTXUIHooks UIHooks = {
294     &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
295     &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
296     &ChooseFontDlg, &SetupGeneral, &WindowWindow
297     };
298     TTXInternalGetUIHooks(&UIHooks);
299 zmatsuo 9223 }
300    
301     static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
302 maya 3227 int i;
303    
304     for (i = NumExtensions - 1; i >= 0; i--) {
305 zmatsuo 9226 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
306     Extensions[i].exports->TTXGetSetupHooks(hooks);
307 maya 3227 }
308     }
309     }
310    
311 zmatsuo 9223 void PASCAL TTXGetSetupHooks(void)
312     {
313 zmatsuo 9226 static TTXSetupHooks SetupHooks = {
314     &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
315     &AddHostToList, &ParseParam
316     };
317     TTXInternalGetSetupHooks(&SetupHooks);
318 zmatsuo 9223 }
319    
320 doda 6801 void PASCAL TTXSetWinSize(int rows, int cols) {
321 maya 3227 int i;
322    
323     for (i = 0; i < NumExtensions; i++) {
324 zmatsuo 9226 if (Extensions[i].exports->TTXSetWinSize != NULL) {
325     Extensions[i].exports->TTXSetWinSize(rows, cols);
326 maya 3227 }
327     }
328     }
329    
330 doda 6801 void PASCAL TTXModifyMenu(HMENU menu) {
331 maya 3227 int i;
332    
333     for (i = 0; i < NumExtensions; i++) {
334 zmatsuo 9226 if (Extensions[i].exports->TTXModifyMenu != NULL) {
335     Extensions[i].exports->TTXModifyMenu(menu);
336 maya 3227 }
337     }
338     }
339    
340 doda 6801 void PASCAL TTXModifyPopupMenu(HMENU menu) {
341 maya 3227 int i;
342    
343     for (i = 0; i < NumExtensions; i++) {
344 zmatsuo 9226 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
345     Extensions[i].exports->TTXModifyPopupMenu(menu);
346 maya 3227 }
347     }
348     }
349    
350 doda 6801 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
351 maya 3227 int i;
352    
353     for (i = NumExtensions - 1; i >= 0; i--) {
354 zmatsuo 9226 if (Extensions[i].exports->TTXProcessCommand != NULL) {
355     if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
356 maya 3227 return TRUE;
357     }
358     }
359     }
360    
361     return FALSE;
362     }
363    
364 zmatsuo 9226 void PASCAL TTXEnd(void)
365     {
366     int i;
367 maya 3227
368 zmatsuo 9226 if (NumExtensions == 0)
369     return;
370 maya 3227
371 zmatsuo 9226 for (i = NumExtensions - 1; i >= 0; i--) {
372     if (Extensions[i].exports->TTXEnd != NULL) {
373     Extensions[i].exports->TTXEnd();
374     }
375     }
376 maya 3227
377 zmatsuo 9356 UnloadExtensions();
378 maya 3227 }
379    
380 zmatsuo 9487 void PASCAL TTXSetCommandLine(wchar_t *cmd, int cmdlen, PGetHNRec rec)
381     {
382     int i;
383 maya 3227
384 zmatsuo 9487 for (i = 0; i < NumExtensions; i++) {
385     if (Extensions[i].exports->TTXSetCommandLine != NULL) {
386     Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
387     }
388     }
389 maya 3227 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26