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 9224 - (hide annotations) (download) (as text)
Tue Apr 27 16:10:14 2021 UTC (2 years, 11 months ago) by zmatsuo
File MIME type: text/x-csrc
File size: 10448 byte(s)
プラグインのロードに渡すファイル名をUnicode化

- loadExtension()
- ファイル検索はANSIのまま
  - この修正はロードのみをUnicode化
- プラグインロード失敗時、エラーコードの説明を追加
- TTXInit() の引数名をグローバル変数とかぶらないよう修正
- crtdbg.h を include
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 maya 3227 #include "teraterm.h"
31     #include "tttypes.h"
32     #include "ttlib.h"
33    
34 zmatsuo 9224 #define _CRTDBG_MAP_ALLOC
35 maya 3227 // #include <windows.h>
36     #include <stdlib.h>
37     #include <stdio.h>
38     #include <string.h>
39 zmatsuo 9224 #include <crtdbg.h>
40 maya 3227 /* for _findXXXX() functions */
41     #include <io.h>
42     #include "ttwinman.h"
43     #include "ttplugin.h"
44     #include "ttplug.h"
45 zmatsuo 9224 #include "codeconv.h"
46 maya 3227
47 doda 4087 #define MAXNUMEXTENSIONS 32
48 maya 3227 static HANDLE LibHandle[MAXNUMEXTENSIONS];
49     static int NumExtensions = 0;
50     static TTXExports * * Extensions;
51    
52     typedef struct _ExtensionList {
53     TTXExports * exports;
54     struct _ExtensionList * next;
55     } ExtensionList;
56    
57     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 9224 static void loadExtension(ExtensionList **extensions, wchar_t const *fileName)
65     {
66     DWORD err;
67     const wchar_t *sub_message;
68     HMODULE hPlugin;
69 maya 3227
70 zmatsuo 9224 if (NumExtensions >= MAXNUMEXTENSIONS)
71     return;
72     hPlugin = LoadLibraryW(fileName);
73     if (hPlugin != NULL) {
74     TTXBindProc bind = NULL;
75 zmatsuo 7536 #if defined(_MSC_VER)
76 zmatsuo 9224 if (bind == NULL)
77     bind = (TTXBindProc)GetProcAddress(hPlugin, "_TTXBind@8");
78 zmatsuo 7536 #else
79 zmatsuo 9224 if (bind == NULL)
80     bind = (TTXBindProc)GetProcAddress(hPlugin, "TTXBind@8");
81 zmatsuo 7536 #endif
82 zmatsuo 9224 if (bind == NULL)
83     bind = (TTXBindProc)GetProcAddress(hPlugin, "TTXBind");
84     if (bind != NULL) {
85     ExtensionList *newExtension = (ExtensionList *)malloc(sizeof(ExtensionList));
86 maya 3227
87 zmatsuo 9224 newExtension->exports = (TTXExports *)malloc(sizeof(TTXExports));
88     memset(newExtension->exports, 0, sizeof(TTXExports));
89     newExtension->exports->size = sizeof(TTXExports);
90     if (bind(TTVERSION, newExtension->exports)) {
91     newExtension->next = *extensions;
92     *extensions = newExtension;
93     LibHandle[NumExtensions] = hPlugin;
94     NumExtensions++;
95     return;
96     }
97     else {
98     free(newExtension->exports);
99     free(newExtension);
100     }
101     }
102     FreeLibrary(LibHandle[NumExtensions]);
103     }
104 maya 3227
105 zmatsuo 9224 err = GetLastError();
106     switch (err) {
107     case 31:
108     sub_message = L"Unresolved dll entry";
109     break;
110     case 1114:
111     sub_message = L"tls entry exists";
112     break;
113     case 2:
114     sub_message = L"rejected by plugin";
115     break;
116     case 193:
117     sub_message = L"invalid dll image";
118     break;
119     default:
120     sub_message = L"unknown";
121     break;
122     }
123     // �����t�@�C�����������b�Z�[�W�����������s�����������A�������_����������
124     // �������������������������A���b�Z�[�W���p���������������B�v�����B
125     static const TTMessageBoxInfoW info = {"Tera Term", "MSG_TT_ERROR", L"Tera Term: Error", "MSG_LOAD_EXT_ERROR",
126     L"Cannot load extension %s (%d, %s)"};
127     TTMessageBoxW(NULL, &info, MB_OK | MB_ICONEXCLAMATION, ts.UILanguageFile, fileName, err, sub_message);
128 maya 3227 }
129    
130 zmatsuo 9224 void PASCAL TTXInit(PTTSet ts_, PComVar cv_) {
131 maya 3227 ExtensionList * extensionList = NULL;
132     int i;
133    
134     // ���������������L�������������ATTX���L���������B
135     //if (getenv("TERATERM_EXTENSIONS") != NULL) {
136     if (1) {
137     char buf[1024];
138     struct _finddata_t searchData;
139 zmatsuo 7896 intptr_t searchHandle;
140 maya 3227
141 zmatsuo 9224 _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s\\TTX*.DLL", ts_->HomeDir);
142 maya 3227
143 doda 6791 searchHandle = _findfirst(buf, &searchData);
144 maya 3227 if (searchHandle != -1L) {
145 doda 6791 do {
146 zmatsuo 9224 wchar_t *bufW;
147     _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s\\%s", ts_->HomeDir, searchData.name);
148     bufW = ToWcharA(buf);
149     loadExtension(&extensionList, bufW);
150     free(bufW);
151 doda 6791 } while (_findnext(searchHandle, &searchData)==0);
152 maya 3227 _findclose(searchHandle);
153     }
154    
155     if (NumExtensions==0) return;
156    
157     Extensions = (TTXExports * *)malloc(sizeof(TTXExports *)*NumExtensions);
158     for (i = 0; i < NumExtensions; i++) {
159     ExtensionList * old;
160    
161     Extensions[i] = extensionList->exports;
162     old = extensionList;
163     extensionList = extensionList->next;
164     free(old);
165     }
166    
167     qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
168    
169     for (i = 0; i < NumExtensions; i++) {
170     if (Extensions[i]->TTXInit != NULL) {
171 zmatsuo 9224 Extensions[i]->TTXInit(ts_, cv_);
172 maya 3227 }
173     }
174     }
175     }
176    
177 zmatsuo 9223 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
178 maya 3227 int i;
179    
180     for (i = 0; i < NumExtensions; i++) {
181     if (Extensions[i]->TTXOpenTCP != NULL) {
182     Extensions[i]->TTXOpenTCP(hooks);
183     }
184     }
185     }
186    
187 zmatsuo 9223 void PASCAL TTXOpenTCP(void)
188     {
189     do {
190     static TTXSockHooks SockHooks = {
191     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
192     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
193     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
194     &PWSACancelAsyncRequest, &PWSAGetLastError,
195     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
196     };
197     TTXInternalOpenTCP(&SockHooks);
198     } while (0);
199     }
200    
201     static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
202 maya 3227 int i;
203    
204     for (i = NumExtensions - 1; i >= 0; i--) {
205     if (Extensions[i]->TTXCloseTCP != NULL) {
206     Extensions[i]->TTXCloseTCP(hooks);
207     }
208     }
209     }
210    
211 zmatsuo 9223 void PASCAL TTXCloseTCP(void)
212     {
213     do {
214     static TTXSockHooks SockHooks = {
215     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
216     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
217     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
218     &PWSACancelAsyncRequest, &PWSAGetLastError,
219     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
220     };
221     TTXInternalCloseTCP(&SockHooks);
222     } while (0);
223     }
224    
225     static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
226 maya 3227 int i;
227    
228     for (i = 0; i < NumExtensions; i++) {
229     if (Extensions[i]->TTXOpenFile != NULL) {
230     Extensions[i]->TTXOpenFile(hooks);
231     }
232     }
233     }
234    
235 zmatsuo 9223 void PASCAL TTXOpenFile(void)
236     {
237     do {
238     static TTXFileHooks FileHooks = {
239     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
240     };
241     TTXInternalOpenFile(&FileHooks);
242     } while (0);
243     }
244    
245     static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
246 maya 3227 int i;
247    
248     for (i = NumExtensions - 1; i >= 0; i--) {
249     if (Extensions[i]->TTXCloseFile != NULL) {
250     Extensions[i]->TTXCloseFile(hooks);
251     }
252     }
253     }
254    
255 zmatsuo 9223 void PASCAL TTXCloseFile(void)
256     {
257     do {
258     static TTXFileHooks FileHooks = {
259     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
260     };
261     TTXInternalCloseFile(&FileHooks);
262     } while (0);
263     }
264    
265     static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
266 maya 3227 int i;
267    
268     for (i = 0; i < NumExtensions; i++) {
269     if (Extensions[i]->TTXGetUIHooks != NULL) {
270     Extensions[i]->TTXGetUIHooks(hooks);
271     }
272     }
273     }
274    
275 zmatsuo 9223 void PASCAL TTXGetUIHooks(void)
276     {
277     do {
278     static TTXUIHooks UIHooks = {
279     &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
280     &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
281     &ChooseFontDlg, &SetupGeneral, &WindowWindow
282     };
283     TTXInternalGetUIHooks(&UIHooks);
284     } while (0);
285     }
286    
287     static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
288 maya 3227 int i;
289    
290     for (i = NumExtensions - 1; i >= 0; i--) {
291     if (Extensions[i]->TTXGetSetupHooks != NULL) {
292     Extensions[i]->TTXGetSetupHooks(hooks);
293     }
294     }
295     }
296    
297 zmatsuo 9223 void PASCAL TTXGetSetupHooks(void)
298     {
299     do {
300     static TTXSetupHooks SetupHooks = {
301     &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
302     &AddHostToList, &ParseParam
303     };
304     TTXInternalGetSetupHooks(&SetupHooks);
305     } while (0);
306     }
307    
308 doda 6801 void PASCAL TTXSetWinSize(int rows, int cols) {
309 maya 3227 int i;
310    
311     for (i = 0; i < NumExtensions; i++) {
312     if (Extensions[i]->TTXSetWinSize != NULL) {
313     Extensions[i]->TTXSetWinSize(rows, cols);
314     }
315     }
316     }
317    
318 doda 6801 void PASCAL TTXModifyMenu(HMENU menu) {
319 maya 3227 int i;
320    
321     for (i = 0; i < NumExtensions; i++) {
322     if (Extensions[i]->TTXModifyMenu != NULL) {
323     Extensions[i]->TTXModifyMenu(menu);
324     }
325     }
326     }
327    
328 doda 6801 void PASCAL TTXModifyPopupMenu(HMENU menu) {
329 maya 3227 int i;
330    
331     for (i = 0; i < NumExtensions; i++) {
332     if (Extensions[i]->TTXModifyPopupMenu != NULL) {
333     Extensions[i]->TTXModifyPopupMenu(menu);
334     }
335     }
336     }
337    
338 doda 6801 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
339 maya 3227 int i;
340    
341     for (i = NumExtensions - 1; i >= 0; i--) {
342     if (Extensions[i]->TTXProcessCommand != NULL) {
343     if (Extensions[i]->TTXProcessCommand(hWin,cmd)) {
344     return TRUE;
345     }
346     }
347     }
348    
349     return FALSE;
350     }
351    
352 doda 6801 void PASCAL TTXEnd(void) {
353 maya 3227 int i;
354    
355     if (NumExtensions==0) return;
356    
357     for (i = NumExtensions - 1; i >= 0; i--) {
358     if (Extensions[i]->TTXEnd != NULL) {
359     Extensions[i]->TTXEnd();
360     }
361     }
362    
363     for (i=0; i<NumExtensions; i++)
364     FreeLibrary(LibHandle[i]);
365    
366     for (i = 0; i < NumExtensions; i++) {
367     free(Extensions[i]);
368     }
369    
370     free(Extensions);
371     NumExtensions = 0;
372     }
373    
374 doda 6801 void PASCAL TTXSetCommandLine(PCHAR cmd, int cmdlen, PGetHNRec rec) {
375 maya 3227 int i;
376    
377     for (i = 0; i < NumExtensions; i++) {
378     if (Extensions[i]->TTXSetCommandLine != NULL) {
379     Extensions[i]->TTXSetCommandLine(cmd, cmdlen, rec);
380     }
381     }
382     }

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