Develop and Download Open Source Software

Browse Subversion Repository

Contents of /branches/ttcomtester/teraterm/teraterm/ttplug.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10521 - (show annotations) (download) (as text)
Fri Jan 20 16:03:38 2023 UTC (13 months, 2 weeks ago) by zmatsuo
File MIME type: text/x-csrc
File size: 10094 byte(s)
add communication test tool
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 default:
128 sub_message = L"unknown";
129 break;
130 }
131 // �����t�@�C�����������b�Z�[�W�����������s�����������A�������_����������
132 // �������������������������A���b�Z�[�W���p���������������B�v�����B
133 {
134 static const TTMessageBoxInfoW info = {
135 "Tera Term",
136 "MSG_TT_ERROR", L"Tera Term: Error",
137 "MSG_LOAD_EXT_ERROR", L"Cannot load extension %s (%d, %s)",
138 MB_OK | MB_ICONEXCLAMATION
139 };
140 TTMessageBoxW(NULL, &info, UILanguageFile, fileName, err, sub_message);
141 }
142 }
143
144 static void LoadExtensions(PTTSet ts_)
145 {
146 wchar_t *load_mask;
147 WIN32_FIND_DATAW fd;
148 HANDLE hFind;
149 wchar_t *ExeDirW = ts_->ExeDirW;
150
151 aswprintf(&load_mask, L"%s\\TTX*.DLL", ExeDirW);
152
153 hFind = FindFirstFileW(load_mask, &fd);
154 if (hFind != INVALID_HANDLE_VALUE) {
155 do {
156 wchar_t *filename;
157 aswprintf(&filename, L"%s\\%s", ExeDirW, fd.cFileName);
158 loadExtension(filename, ts_->UILanguageFileW);
159 free(filename);
160 } while (FindNextFileW(hFind, &fd));
161 FindClose(hFind);
162 }
163 free(load_mask);
164
165 if (NumExtensions==0) return;
166
167 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
168 }
169
170 static void UnloadExtensions()
171 {
172 int i;
173 for (i = 0; i < NumExtensions; i++) {
174 free(Extensions[i].exports);
175 FreeLibrary(Extensions[i].LibHandle);
176 }
177
178 free(Extensions);
179 Extensions = NULL;
180 NumExtensions = 0;
181 }
182
183 void PASCAL TTXInit(PTTSet ts_, PComVar cv_)
184 {
185 int i;
186
187 LoadExtensions(ts_);
188
189 if (NumExtensions==0) return;
190
191 for (i = 0; i < NumExtensions; i++) {
192 if (Extensions[i].exports->TTXInit != NULL) {
193 Extensions[i].exports->TTXInit(ts_, cv_);
194 }
195 }
196 }
197
198 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
199 int i;
200
201 for (i = 0; i < NumExtensions; i++) {
202 if (Extensions[i].exports->TTXOpenTCP != NULL) {
203 Extensions[i].exports->TTXOpenTCP(hooks);
204 }
205 }
206 }
207
208 void PASCAL TTXOpenTCP(void)
209 {
210 static TTXSockHooks SockHooks = {
211 &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
212 &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
213 &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
214 &PWSACancelAsyncRequest, &PWSAGetLastError,
215 /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
216 };
217 TTXInternalOpenTCP(&SockHooks);
218 }
219
220 static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
221 int i;
222
223 for (i = NumExtensions - 1; i >= 0; i--) {
224 if (Extensions[i].exports->TTXCloseTCP != NULL) {
225 Extensions[i].exports->TTXCloseTCP(hooks);
226 }
227 }
228 }
229
230 void PASCAL TTXCloseTCP(void)
231 {
232 static TTXSockHooks SockHooks = {
233 &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
234 &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
235 &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
236 &PWSACancelAsyncRequest, &PWSAGetLastError,
237 /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
238 };
239 TTXInternalCloseTCP(&SockHooks);
240 }
241
242 static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
243 int i;
244
245 for (i = 0; i < NumExtensions; i++) {
246 if (Extensions[i].exports->TTXOpenFile != NULL) {
247 Extensions[i].exports->TTXOpenFile(hooks);
248 }
249 }
250 }
251
252 void PASCAL TTXOpenFile(void)
253 {
254 static TTXFileHooks FileHooks = {
255 &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
256 };
257 TTXInternalOpenFile(&FileHooks);
258 }
259
260 static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
261 int i;
262
263 for (i = NumExtensions - 1; i >= 0; i--) {
264 if (Extensions[i].exports->TTXCloseFile != NULL) {
265 Extensions[i].exports->TTXCloseFile(hooks);
266 }
267 }
268 }
269
270 void PASCAL TTXCloseFile(void)
271 {
272 static TTXFileHooks FileHooks = {
273 &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
274 };
275 TTXInternalCloseFile(&FileHooks);
276 }
277
278 static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
279 int i;
280
281 for (i = 0; i < NumExtensions; i++) {
282 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
283 Extensions[i].exports->TTXGetUIHooks(hooks);
284 }
285 }
286 }
287
288 void PASCAL TTXGetUIHooks(void)
289 {
290 static TTXUIHooks UIHooks = {
291 &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
292 &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
293 &ChooseFontDlg, &SetupGeneral, &WindowWindow
294 };
295 TTXInternalGetUIHooks(&UIHooks);
296 }
297
298 static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
299 int i;
300
301 for (i = NumExtensions - 1; i >= 0; i--) {
302 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
303 Extensions[i].exports->TTXGetSetupHooks(hooks);
304 }
305 }
306 }
307
308 void PASCAL TTXGetSetupHooks(void)
309 {
310 static TTXSetupHooks SetupHooks = {
311 &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
312 &AddHostToList, &ParseParam
313 };
314 TTXInternalGetSetupHooks(&SetupHooks);
315 }
316
317 void PASCAL TTXSetWinSize(int rows, int cols) {
318 int i;
319
320 for (i = 0; i < NumExtensions; i++) {
321 if (Extensions[i].exports->TTXSetWinSize != NULL) {
322 Extensions[i].exports->TTXSetWinSize(rows, cols);
323 }
324 }
325 }
326
327 void PASCAL TTXModifyMenu(HMENU menu) {
328 int i;
329
330 for (i = 0; i < NumExtensions; i++) {
331 if (Extensions[i].exports->TTXModifyMenu != NULL) {
332 Extensions[i].exports->TTXModifyMenu(menu);
333 }
334 }
335 }
336
337 void PASCAL TTXModifyPopupMenu(HMENU menu) {
338 int i;
339
340 for (i = 0; i < NumExtensions; i++) {
341 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
342 Extensions[i].exports->TTXModifyPopupMenu(menu);
343 }
344 }
345 }
346
347 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
348 int i;
349
350 for (i = NumExtensions - 1; i >= 0; i--) {
351 if (Extensions[i].exports->TTXProcessCommand != NULL) {
352 if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
353 return TRUE;
354 }
355 }
356 }
357
358 return FALSE;
359 }
360
361 void PASCAL TTXEnd(void)
362 {
363 int i;
364
365 if (NumExtensions == 0)
366 return;
367
368 for (i = NumExtensions - 1; i >= 0; i--) {
369 if (Extensions[i].exports->TTXEnd != NULL) {
370 Extensions[i].exports->TTXEnd();
371 }
372 }
373
374 UnloadExtensions();
375 }
376
377 void PASCAL TTXSetCommandLine(wchar_t *cmd, int cmdlen, PGetHNRec rec)
378 {
379 int i;
380
381 for (i = 0; i < NumExtensions; i++) {
382 if (Extensions[i].exports->TTXSetCommandLine != NULL) {
383 Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
384 }
385 }
386 }

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