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 9225 - (hide annotations) (download) (as text)
Tue Apr 27 16:10:27 2021 UTC (2 years, 11 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/ttplug.c
File MIME type: text/x-csrc
File size: 10179 byte(s)
プラグインの検索をUnicode化

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

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