Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/teraterm/teraterm/ttplug.c

Parent Directory Parent Directory | Revision Log Revision Log


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

- ttxssh.dll 読み込み時に bcrypt.dll が存在しない場合など
1 /*
2 * Copyright (C) 1994-1998 T. Teranishi
3 * (C) Robert O'Callahan
4 * (C) 2004- TeraTerm Project
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 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 *
19 * 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 */
30 #include <winsock2.h>
31 #include "teraterm.h"
32 #include "tttypes.h"
33 #include "ttlib.h"
34
35 #define _CRTDBG_MAP_ALLOC
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <crtdbg.h>
40
41 #include "ttplugin.h"
42 #include "codeconv.h"
43 #include "asprintf.h"
44
45 #include "ttplug.h"
46
47 typedef struct _ExtensionList {
48 TTXExports * exports;
49 HANDLE LibHandle;
50 } ExtensionList;
51
52 static ExtensionList *Extensions;
53 static int NumExtensions = 0;
54
55 static int compareOrder(const void * e1, const void * e2)
56 {
57 TTXExports * * exports1 = (TTXExports * *)e1;
58 TTXExports * * exports2 = (TTXExports * *)e2;
59
60 return (*exports1)->loadOrder - (*exports2)->loadOrder;
61 }
62
63 static void loadExtension(wchar_t const *fileName, const wchar_t *UILanguageFile)
64 {
65 DWORD err;
66 const wchar_t *sub_message;
67 HMODULE hPlugin;
68
69 hPlugin = LoadLibraryW(fileName);
70 if (hPlugin != NULL) {
71 TTXBindProc bind = NULL;
72 FARPROC *pbind = (FARPROC *)&bind;
73 #if defined(_MSC_VER)
74 if (bind == NULL)
75 *pbind = GetProcAddress(hPlugin, "_TTXBind@8");
76 #else
77 if (bind == NULL)
78 *pbind = GetProcAddress(hPlugin, "TTXBind@8");
79 #endif
80 if (bind == NULL)
81 *pbind = GetProcAddress(hPlugin, "TTXBind");
82 if (bind != NULL) {
83 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
90 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 NumExtensions++;
101
102 newExtension->exports = exports;
103 newExtension->LibHandle = hPlugin;
104 return;
105 }
106 else {
107 free(exports);
108 }
109 }
110 FreeLibrary(hPlugin);
111 }
112
113 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 case 126:
128 sub_message = L"dll not exist";
129 break;
130 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 {
137 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 TTMessageBoxW(NULL, &info, UILanguageFile, fileName, err, sub_message);
144 }
145 }
146
147 static void LoadExtensions(PTTSet ts_)
148 {
149 wchar_t *load_mask;
150 WIN32_FIND_DATAW fd;
151 HANDLE hFind;
152 wchar_t *ExeDirW = ts_->ExeDirW;
153
154 aswprintf(&load_mask, L"%s\\TTX*.DLL", ExeDirW);
155
156 hFind = FindFirstFileW(load_mask, &fd);
157 if (hFind != INVALID_HANDLE_VALUE) {
158 do {
159 wchar_t *filename;
160 aswprintf(&filename, L"%s\\%s", ExeDirW, fd.cFileName);
161 loadExtension(filename, ts_->UILanguageFileW);
162 free(filename);
163 } while (FindNextFileW(hFind, &fd));
164 FindClose(hFind);
165 }
166 free(load_mask);
167
168 if (NumExtensions==0) return;
169
170 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
171 }
172
173 static void UnloadExtensions()
174 {
175 int i;
176 for (i = 0; i < NumExtensions; i++) {
177 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 if (Extensions[i].exports->TTXInit != NULL) {
196 Extensions[i].exports->TTXInit(ts_, cv_);
197 }
198 }
199 }
200
201 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
202 int i;
203
204 for (i = 0; i < NumExtensions; i++) {
205 if (Extensions[i].exports->TTXOpenTCP != NULL) {
206 Extensions[i].exports->TTXOpenTCP(hooks);
207 }
208 }
209 }
210
211 void PASCAL TTXOpenTCP(void)
212 {
213 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 }
222
223 static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
224 int i;
225
226 for (i = NumExtensions - 1; i >= 0; i--) {
227 if (Extensions[i].exports->TTXCloseTCP != NULL) {
228 Extensions[i].exports->TTXCloseTCP(hooks);
229 }
230 }
231 }
232
233 void PASCAL TTXCloseTCP(void)
234 {
235 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 }
244
245 static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
246 int i;
247
248 for (i = 0; i < NumExtensions; i++) {
249 if (Extensions[i].exports->TTXOpenFile != NULL) {
250 Extensions[i].exports->TTXOpenFile(hooks);
251 }
252 }
253 }
254
255 void PASCAL TTXOpenFile(void)
256 {
257 static TTXFileHooks FileHooks = {
258 &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
259 };
260 TTXInternalOpenFile(&FileHooks);
261 }
262
263 static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
264 int i;
265
266 for (i = NumExtensions - 1; i >= 0; i--) {
267 if (Extensions[i].exports->TTXCloseFile != NULL) {
268 Extensions[i].exports->TTXCloseFile(hooks);
269 }
270 }
271 }
272
273 void PASCAL TTXCloseFile(void)
274 {
275 static TTXFileHooks FileHooks = {
276 &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
277 };
278 TTXInternalCloseFile(&FileHooks);
279 }
280
281 static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
282 int i;
283
284 for (i = 0; i < NumExtensions; i++) {
285 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
286 Extensions[i].exports->TTXGetUIHooks(hooks);
287 }
288 }
289 }
290
291 void PASCAL TTXGetUIHooks(void)
292 {
293 static TTXUIHooks UIHooks = {
294 &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
295 &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
296 &ChooseFontDlg, &SetupGeneral, &WindowWindow
297 };
298 TTXInternalGetUIHooks(&UIHooks);
299 }
300
301 static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
302 int i;
303
304 for (i = NumExtensions - 1; i >= 0; i--) {
305 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
306 Extensions[i].exports->TTXGetSetupHooks(hooks);
307 }
308 }
309 }
310
311 void PASCAL TTXGetSetupHooks(void)
312 {
313 static TTXSetupHooks SetupHooks = {
314 &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
315 &AddHostToList, &ParseParam
316 };
317 TTXInternalGetSetupHooks(&SetupHooks);
318 }
319
320 void PASCAL TTXSetWinSize(int rows, int cols) {
321 int i;
322
323 for (i = 0; i < NumExtensions; i++) {
324 if (Extensions[i].exports->TTXSetWinSize != NULL) {
325 Extensions[i].exports->TTXSetWinSize(rows, cols);
326 }
327 }
328 }
329
330 void PASCAL TTXModifyMenu(HMENU menu) {
331 int i;
332
333 for (i = 0; i < NumExtensions; i++) {
334 if (Extensions[i].exports->TTXModifyMenu != NULL) {
335 Extensions[i].exports->TTXModifyMenu(menu);
336 }
337 }
338 }
339
340 void PASCAL TTXModifyPopupMenu(HMENU menu) {
341 int i;
342
343 for (i = 0; i < NumExtensions; i++) {
344 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
345 Extensions[i].exports->TTXModifyPopupMenu(menu);
346 }
347 }
348 }
349
350 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
351 int i;
352
353 for (i = NumExtensions - 1; i >= 0; i--) {
354 if (Extensions[i].exports->TTXProcessCommand != NULL) {
355 if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
356 return TRUE;
357 }
358 }
359 }
360
361 return FALSE;
362 }
363
364 void PASCAL TTXEnd(void)
365 {
366 int i;
367
368 if (NumExtensions == 0)
369 return;
370
371 for (i = NumExtensions - 1; i >= 0; i--) {
372 if (Extensions[i].exports->TTXEnd != NULL) {
373 Extensions[i].exports->TTXEnd();
374 }
375 }
376
377 UnloadExtensions();
378 }
379
380 void PASCAL TTXSetCommandLine(wchar_t *cmd, int cmdlen, PGetHNRec rec)
381 {
382 int i;
383
384 for (i = 0; i < NumExtensions; i++) {
385 if (Extensions[i].exports->TTXSetCommandLine != NULL) {
386 Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
387 }
388 }
389 }

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