Develop and Download Open Source Software

Browse Subversion Repository

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9309 - (hide annotations) (download) (as text)
Sat Jun 12 15:29:57 2021 UTC (2 years, 9 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/ttplug.c
File MIME type: text/x-csrc
File size: 9946 byte(s)
layer_for_unicodeを使用するよう修正
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 maya 3227 #include "ttwinman.h"
41     #include "ttplugin.h"
42 zmatsuo 9224 #include "codeconv.h"
43 zmatsuo 9225 #include "asprintf.h"
44 zmatsuo 9309 #include "layer_for_unicode.h"
45 maya 3227
46 zmatsuo 9225 #include "ttplug.h"
47    
48 maya 3227 static int NumExtensions = 0;
49    
50     typedef struct _ExtensionList {
51 zmatsuo 9226 TTXExports * exports;
52     HANDLE LibHandle;
53 maya 3227 } ExtensionList;
54    
55 zmatsuo 9226 static ExtensionList *Extensions;
56    
57 maya 3227 static int compareOrder(const void * e1, const void * e2) {
58     TTXExports * * exports1 = (TTXExports * *)e1;
59     TTXExports * * exports2 = (TTXExports * *)e2;
60    
61     return (*exports1)->loadOrder - (*exports2)->loadOrder;
62     }
63    
64 zmatsuo 9226 static void loadExtension(wchar_t const *fileName)
65 zmatsuo 9224 {
66     DWORD err;
67     const wchar_t *sub_message;
68     HMODULE hPlugin;
69 maya 3227
70 zmatsuo 9309 hPlugin = _LoadLibraryW(fileName);
71 zmatsuo 9224 if (hPlugin != NULL) {
72     TTXBindProc bind = NULL;
73 zmatsuo 9227 FARPROC *pbind = (FARPROC *)&bind;
74 zmatsuo 7536 #if defined(_MSC_VER)
75 zmatsuo 9224 if (bind == NULL)
76 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "_TTXBind@8");
77 zmatsuo 7536 #else
78 zmatsuo 9224 if (bind == NULL)
79 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind@8");
80 zmatsuo 7536 #endif
81 zmatsuo 9224 if (bind == NULL)
82 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind");
83 zmatsuo 9224 if (bind != NULL) {
84 zmatsuo 9226 TTXExports * exports = (TTXExports *)malloc(sizeof(TTXExports));
85     if (exports == NULL) {
86     return;
87     }
88     memset(exports, 0, sizeof(TTXExports));
89     exports->size = sizeof(TTXExports);
90 maya 3227
91 zmatsuo 9226 if (bind(TTVERSION, exports)) {
92     ExtensionList *newExtension;
93     ExtensionList *extensions = (ExtensionList *)realloc(Extensions, sizeof(ExtensionList) * (NumExtensions + 1));
94     if (extensions == NULL) {
95     free(exports);
96     FreeLibrary(hPlugin);
97     return;
98     }
99     Extensions = extensions;
100     newExtension = &extensions[NumExtensions];
101 zmatsuo 9224 NumExtensions++;
102 zmatsuo 9226
103     newExtension->exports = exports;
104     newExtension->LibHandle = hPlugin;
105 zmatsuo 9224 return;
106     }
107     else {
108 zmatsuo 9226 free(exports);
109 zmatsuo 9224 }
110     }
111 zmatsuo 9226 FreeLibrary(hPlugin);
112 zmatsuo 9224 }
113 maya 3227
114 zmatsuo 9224 err = GetLastError();
115     switch (err) {
116     case 31:
117     sub_message = L"Unresolved dll entry";
118     break;
119     case 1114:
120     sub_message = L"tls entry exists";
121     break;
122     case 2:
123     sub_message = L"rejected by plugin";
124     break;
125     case 193:
126     sub_message = L"invalid dll image";
127     break;
128     default:
129     sub_message = L"unknown";
130     break;
131     }
132     // �����t�@�C�����������b�Z�[�W�����������s�����������A�������_����������
133     // �������������������������A���b�Z�[�W���p���������������B�v�����B
134 zmatsuo 9230 {
135     static const TTMessageBoxInfoW info = {"Tera Term", "MSG_TT_ERROR", L"Tera Term: Error", "MSG_LOAD_EXT_ERROR",
136     L"Cannot load extension %s (%d, %s)"};
137     TTMessageBoxW(NULL, &info, MB_OK | MB_ICONEXCLAMATION, ts.UILanguageFile, fileName, err, sub_message);
138     }
139 maya 3227 }
140    
141 zmatsuo 9225 void PASCAL TTXInit(PTTSet ts_, PComVar cv_)
142     {
143     int i;
144     wchar_t *load_mask;
145     WIN32_FIND_DATAW fd;
146     HANDLE hFind;
147     wchar_t *HomeDirW = ToWcharA(ts_->HomeDir);
148 maya 3227
149 zmatsuo 9225 aswprintf(&load_mask, L"%s\\TTX*.DLL", HomeDirW);
150 maya 3227
151 zmatsuo 9309 hFind = _FindFirstFileW(load_mask, &fd);
152 zmatsuo 9225 if (hFind != INVALID_HANDLE_VALUE) {
153     do {
154     wchar_t *filename;
155     aswprintf(&filename, L"%s\\%s", HomeDirW, fd.cFileName);
156 zmatsuo 9226 loadExtension(filename);
157 zmatsuo 9225 free(filename);
158 zmatsuo 9309 } while (_FindNextFileW(hFind, &fd));
159 zmatsuo 9225 FindClose(hFind);
160     }
161     free(load_mask);
162     free(HomeDirW);
163 maya 3227
164 zmatsuo 9225 if (NumExtensions==0) return;
165 maya 3227
166 zmatsuo 9225 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
167 maya 3227
168 zmatsuo 9225 for (i = 0; i < NumExtensions; i++) {
169 zmatsuo 9226 if (Extensions[i].exports->TTXInit != NULL) {
170     Extensions[i].exports->TTXInit(ts_, cv_);
171 zmatsuo 9225 }
172     }
173 maya 3227 }
174    
175 zmatsuo 9223 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
176 maya 3227 int i;
177    
178     for (i = 0; i < NumExtensions; i++) {
179 zmatsuo 9226 if (Extensions[i].exports->TTXOpenTCP != NULL) {
180     Extensions[i].exports->TTXOpenTCP(hooks);
181 maya 3227 }
182     }
183     }
184    
185 zmatsuo 9223 void PASCAL TTXOpenTCP(void)
186     {
187 zmatsuo 9226 static TTXSockHooks SockHooks = {
188     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
189     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
190     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
191     &PWSACancelAsyncRequest, &PWSAGetLastError,
192     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
193     };
194     TTXInternalOpenTCP(&SockHooks);
195 zmatsuo 9223 }
196    
197     static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
198 maya 3227 int i;
199    
200     for (i = NumExtensions - 1; i >= 0; i--) {
201 zmatsuo 9226 if (Extensions[i].exports->TTXCloseTCP != NULL) {
202     Extensions[i].exports->TTXCloseTCP(hooks);
203 maya 3227 }
204     }
205     }
206    
207 zmatsuo 9223 void PASCAL TTXCloseTCP(void)
208     {
209 zmatsuo 9226 static TTXSockHooks SockHooks = {
210     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
211     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
212     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
213     &PWSACancelAsyncRequest, &PWSAGetLastError,
214     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
215     };
216     TTXInternalCloseTCP(&SockHooks);
217 zmatsuo 9223 }
218    
219     static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
220 maya 3227 int i;
221    
222     for (i = 0; i < NumExtensions; i++) {
223 zmatsuo 9226 if (Extensions[i].exports->TTXOpenFile != NULL) {
224     Extensions[i].exports->TTXOpenFile(hooks);
225 maya 3227 }
226     }
227     }
228    
229 zmatsuo 9223 void PASCAL TTXOpenFile(void)
230     {
231 zmatsuo 9226 static TTXFileHooks FileHooks = {
232     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
233     };
234     TTXInternalOpenFile(&FileHooks);
235 zmatsuo 9223 }
236    
237     static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
238 maya 3227 int i;
239    
240     for (i = NumExtensions - 1; i >= 0; i--) {
241 zmatsuo 9226 if (Extensions[i].exports->TTXCloseFile != NULL) {
242     Extensions[i].exports->TTXCloseFile(hooks);
243 maya 3227 }
244     }
245     }
246    
247 zmatsuo 9223 void PASCAL TTXCloseFile(void)
248     {
249 zmatsuo 9226 static TTXFileHooks FileHooks = {
250     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
251     };
252     TTXInternalCloseFile(&FileHooks);
253 zmatsuo 9223 }
254    
255     static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
256 maya 3227 int i;
257    
258     for (i = 0; i < NumExtensions; i++) {
259 zmatsuo 9226 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
260     Extensions[i].exports->TTXGetUIHooks(hooks);
261 maya 3227 }
262     }
263     }
264    
265 zmatsuo 9223 void PASCAL TTXGetUIHooks(void)
266     {
267 zmatsuo 9226 static TTXUIHooks UIHooks = {
268     &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
269     &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
270     &ChooseFontDlg, &SetupGeneral, &WindowWindow
271     };
272     TTXInternalGetUIHooks(&UIHooks);
273 zmatsuo 9223 }
274    
275     static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
276 maya 3227 int i;
277    
278     for (i = NumExtensions - 1; i >= 0; i--) {
279 zmatsuo 9226 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
280     Extensions[i].exports->TTXGetSetupHooks(hooks);
281 maya 3227 }
282     }
283     }
284    
285 zmatsuo 9223 void PASCAL TTXGetSetupHooks(void)
286     {
287 zmatsuo 9226 static TTXSetupHooks SetupHooks = {
288     &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
289     &AddHostToList, &ParseParam
290     };
291     TTXInternalGetSetupHooks(&SetupHooks);
292 zmatsuo 9223 }
293    
294 doda 6801 void PASCAL TTXSetWinSize(int rows, int cols) {
295 maya 3227 int i;
296    
297     for (i = 0; i < NumExtensions; i++) {
298 zmatsuo 9226 if (Extensions[i].exports->TTXSetWinSize != NULL) {
299     Extensions[i].exports->TTXSetWinSize(rows, cols);
300 maya 3227 }
301     }
302     }
303    
304 doda 6801 void PASCAL TTXModifyMenu(HMENU menu) {
305 maya 3227 int i;
306    
307     for (i = 0; i < NumExtensions; i++) {
308 zmatsuo 9226 if (Extensions[i].exports->TTXModifyMenu != NULL) {
309     Extensions[i].exports->TTXModifyMenu(menu);
310 maya 3227 }
311     }
312     }
313    
314 doda 6801 void PASCAL TTXModifyPopupMenu(HMENU menu) {
315 maya 3227 int i;
316    
317     for (i = 0; i < NumExtensions; i++) {
318 zmatsuo 9226 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
319     Extensions[i].exports->TTXModifyPopupMenu(menu);
320 maya 3227 }
321     }
322     }
323    
324 doda 6801 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
325 maya 3227 int i;
326    
327     for (i = NumExtensions - 1; i >= 0; i--) {
328 zmatsuo 9226 if (Extensions[i].exports->TTXProcessCommand != NULL) {
329     if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
330 maya 3227 return TRUE;
331     }
332     }
333     }
334    
335     return FALSE;
336     }
337    
338 zmatsuo 9226 void PASCAL TTXEnd(void)
339     {
340     int i;
341 maya 3227
342 zmatsuo 9226 if (NumExtensions == 0)
343     return;
344 maya 3227
345 zmatsuo 9226 for (i = NumExtensions - 1; i >= 0; i--) {
346     if (Extensions[i].exports->TTXEnd != NULL) {
347     Extensions[i].exports->TTXEnd();
348     }
349     }
350 maya 3227
351 zmatsuo 9226 for (i = 0; i < NumExtensions; i++) {
352     free(Extensions[i].exports);
353     FreeLibrary(Extensions[i].LibHandle);
354     }
355 maya 3227
356 zmatsuo 9226 free(Extensions);
357     Extensions = NULL;
358     NumExtensions = 0;
359 maya 3227 }
360    
361 doda 6801 void PASCAL TTXSetCommandLine(PCHAR cmd, int cmdlen, PGetHNRec rec) {
362 maya 3227 int i;
363    
364     for (i = 0; i < NumExtensions; i++) {
365 zmatsuo 9226 if (Extensions[i].exports->TTXSetCommandLine != NULL) {
366     Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
367 maya 3227 }
368     }
369     }

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