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 9227 - (hide annotations) (download) (as text)
Tue Apr 27 16:10:55 2021 UTC (2 years, 11 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/ttplug.c
File MIME type: text/x-csrc
File size: 9911 byte(s)
gcc で警告が出ないよう修正

- GetProcAddress() から変数の代入時
  - warning: cast between incompatible function types from 'FARPROC' {aka 'long long int (*)()'} to 'BOOL (*)(WORD,  TTXExports *)' {aka 'int (*)(short unsigned int,  TTXExports *)'}
- winsock2.h を最初にinclude
  - warning: #warning Please include winsock2.h before windows.h [-Wcpp]
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 maya 3227
45 zmatsuo 9225 #include "ttplug.h"
46    
47 maya 3227 static int NumExtensions = 0;
48    
49     typedef struct _ExtensionList {
50 zmatsuo 9226 TTXExports * exports;
51     HANDLE LibHandle;
52 maya 3227 } ExtensionList;
53    
54 zmatsuo 9226 static ExtensionList *Extensions;
55    
56 maya 3227 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 9226 static void loadExtension(wchar_t const *fileName)
64 zmatsuo 9224 {
65     DWORD err;
66     const wchar_t *sub_message;
67     HMODULE hPlugin;
68 maya 3227
69 zmatsuo 9224 hPlugin = LoadLibraryW(fileName);
70     if (hPlugin != NULL) {
71     TTXBindProc bind = NULL;
72 zmatsuo 9227 FARPROC *pbind = (FARPROC *)&bind;
73 zmatsuo 7536 #if defined(_MSC_VER)
74 zmatsuo 9224 if (bind == NULL)
75 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "_TTXBind@8");
76 zmatsuo 7536 #else
77 zmatsuo 9224 if (bind == NULL)
78 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind@8");
79 zmatsuo 7536 #endif
80 zmatsuo 9224 if (bind == NULL)
81 zmatsuo 9227 *pbind = GetProcAddress(hPlugin, "TTXBind");
82 zmatsuo 9224 if (bind != NULL) {
83 zmatsuo 9226 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 maya 3227
90 zmatsuo 9226 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 zmatsuo 9224 NumExtensions++;
101 zmatsuo 9226
102     newExtension->exports = exports;
103     newExtension->LibHandle = hPlugin;
104 zmatsuo 9224 return;
105     }
106     else {
107 zmatsuo 9226 free(exports);
108 zmatsuo 9224 }
109     }
110 zmatsuo 9226 FreeLibrary(hPlugin);
111 zmatsuo 9224 }
112 maya 3227
113 zmatsuo 9224 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     static const TTMessageBoxInfoW info = {"Tera Term", "MSG_TT_ERROR", L"Tera Term: Error", "MSG_LOAD_EXT_ERROR",
134     L"Cannot load extension %s (%d, %s)"};
135     TTMessageBoxW(NULL, &info, MB_OK | MB_ICONEXCLAMATION, ts.UILanguageFile, fileName, err, sub_message);
136 maya 3227 }
137    
138 zmatsuo 9225 void PASCAL TTXInit(PTTSet ts_, PComVar cv_)
139     {
140     int i;
141     wchar_t *load_mask;
142     WIN32_FIND_DATAW fd;
143     HANDLE hFind;
144     wchar_t *HomeDirW = ToWcharA(ts_->HomeDir);
145 maya 3227
146 zmatsuo 9225 aswprintf(&load_mask, L"%s\\TTX*.DLL", HomeDirW);
147 maya 3227
148 zmatsuo 9225 hFind = FindFirstFileW(load_mask, &fd);
149     if (hFind != INVALID_HANDLE_VALUE) {
150     do {
151     wchar_t *filename;
152     aswprintf(&filename, L"%s\\%s", HomeDirW, fd.cFileName);
153 zmatsuo 9226 loadExtension(filename);
154 zmatsuo 9225 free(filename);
155     } while (FindNextFileW(hFind, &fd));
156     FindClose(hFind);
157     }
158     free(load_mask);
159     free(HomeDirW);
160 maya 3227
161 zmatsuo 9225 if (NumExtensions==0) return;
162 maya 3227
163 zmatsuo 9225 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
164 maya 3227
165 zmatsuo 9225 for (i = 0; i < NumExtensions; i++) {
166 zmatsuo 9226 if (Extensions[i].exports->TTXInit != NULL) {
167     Extensions[i].exports->TTXInit(ts_, cv_);
168 zmatsuo 9225 }
169     }
170 maya 3227 }
171    
172 zmatsuo 9223 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
173 maya 3227 int i;
174    
175     for (i = 0; i < NumExtensions; i++) {
176 zmatsuo 9226 if (Extensions[i].exports->TTXOpenTCP != NULL) {
177     Extensions[i].exports->TTXOpenTCP(hooks);
178 maya 3227 }
179     }
180     }
181    
182 zmatsuo 9223 void PASCAL TTXOpenTCP(void)
183     {
184 zmatsuo 9226 static TTXSockHooks SockHooks = {
185     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
186     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
187     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
188     &PWSACancelAsyncRequest, &PWSAGetLastError,
189     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
190     };
191     TTXInternalOpenTCP(&SockHooks);
192 zmatsuo 9223 }
193    
194     static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
195 maya 3227 int i;
196    
197     for (i = NumExtensions - 1; i >= 0; i--) {
198 zmatsuo 9226 if (Extensions[i].exports->TTXCloseTCP != NULL) {
199     Extensions[i].exports->TTXCloseTCP(hooks);
200 maya 3227 }
201     }
202     }
203    
204 zmatsuo 9223 void PASCAL TTXCloseTCP(void)
205     {
206 zmatsuo 9226 static TTXSockHooks SockHooks = {
207     &Pclosesocket, &Pconnect, &Phtonl, &Phtons, &Pinet_addr,
208     &Pioctlsocket, &Precv, &Pselect, &Psend, &Psetsockopt,
209     &Psocket, &PWSAAsyncSelect, &PWSAAsyncGetHostByName,
210     &PWSACancelAsyncRequest, &PWSAGetLastError,
211     /* &Pgetaddrinfo,*/ &Pfreeaddrinfo, &PWSAAsyncGetAddrInfo
212     };
213     TTXInternalCloseTCP(&SockHooks);
214 zmatsuo 9223 }
215    
216     static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
217 maya 3227 int i;
218    
219     for (i = 0; i < NumExtensions; i++) {
220 zmatsuo 9226 if (Extensions[i].exports->TTXOpenFile != NULL) {
221     Extensions[i].exports->TTXOpenFile(hooks);
222 maya 3227 }
223     }
224     }
225    
226 zmatsuo 9223 void PASCAL TTXOpenFile(void)
227     {
228 zmatsuo 9226 static TTXFileHooks FileHooks = {
229     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
230     };
231     TTXInternalOpenFile(&FileHooks);
232 zmatsuo 9223 }
233    
234     static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
235 maya 3227 int i;
236    
237     for (i = NumExtensions - 1; i >= 0; i--) {
238 zmatsuo 9226 if (Extensions[i].exports->TTXCloseFile != NULL) {
239     Extensions[i].exports->TTXCloseFile(hooks);
240 maya 3227 }
241     }
242     }
243    
244 zmatsuo 9223 void PASCAL TTXCloseFile(void)
245     {
246 zmatsuo 9226 static TTXFileHooks FileHooks = {
247     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
248     };
249     TTXInternalCloseFile(&FileHooks);
250 zmatsuo 9223 }
251    
252     static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
253 maya 3227 int i;
254    
255     for (i = 0; i < NumExtensions; i++) {
256 zmatsuo 9226 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
257     Extensions[i].exports->TTXGetUIHooks(hooks);
258 maya 3227 }
259     }
260     }
261    
262 zmatsuo 9223 void PASCAL TTXGetUIHooks(void)
263     {
264 zmatsuo 9226 static TTXUIHooks UIHooks = {
265     &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
266     &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
267     &ChooseFontDlg, &SetupGeneral, &WindowWindow
268     };
269     TTXInternalGetUIHooks(&UIHooks);
270 zmatsuo 9223 }
271    
272     static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
273 maya 3227 int i;
274    
275     for (i = NumExtensions - 1; i >= 0; i--) {
276 zmatsuo 9226 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
277     Extensions[i].exports->TTXGetSetupHooks(hooks);
278 maya 3227 }
279     }
280     }
281    
282 zmatsuo 9223 void PASCAL TTXGetSetupHooks(void)
283     {
284 zmatsuo 9226 static TTXSetupHooks SetupHooks = {
285     &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
286     &AddHostToList, &ParseParam
287     };
288     TTXInternalGetSetupHooks(&SetupHooks);
289 zmatsuo 9223 }
290    
291 doda 6801 void PASCAL TTXSetWinSize(int rows, int cols) {
292 maya 3227 int i;
293    
294     for (i = 0; i < NumExtensions; i++) {
295 zmatsuo 9226 if (Extensions[i].exports->TTXSetWinSize != NULL) {
296     Extensions[i].exports->TTXSetWinSize(rows, cols);
297 maya 3227 }
298     }
299     }
300    
301 doda 6801 void PASCAL TTXModifyMenu(HMENU menu) {
302 maya 3227 int i;
303    
304     for (i = 0; i < NumExtensions; i++) {
305 zmatsuo 9226 if (Extensions[i].exports->TTXModifyMenu != NULL) {
306     Extensions[i].exports->TTXModifyMenu(menu);
307 maya 3227 }
308     }
309     }
310    
311 doda 6801 void PASCAL TTXModifyPopupMenu(HMENU menu) {
312 maya 3227 int i;
313    
314     for (i = 0; i < NumExtensions; i++) {
315 zmatsuo 9226 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
316     Extensions[i].exports->TTXModifyPopupMenu(menu);
317 maya 3227 }
318     }
319     }
320    
321 doda 6801 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
322 maya 3227 int i;
323    
324     for (i = NumExtensions - 1; i >= 0; i--) {
325 zmatsuo 9226 if (Extensions[i].exports->TTXProcessCommand != NULL) {
326     if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
327 maya 3227 return TRUE;
328     }
329     }
330     }
331    
332     return FALSE;
333     }
334    
335 zmatsuo 9226 void PASCAL TTXEnd(void)
336     {
337     int i;
338 maya 3227
339 zmatsuo 9226 if (NumExtensions == 0)
340     return;
341 maya 3227
342 zmatsuo 9226 for (i = NumExtensions - 1; i >= 0; i--) {
343     if (Extensions[i].exports->TTXEnd != NULL) {
344     Extensions[i].exports->TTXEnd();
345     }
346     }
347 maya 3227
348 zmatsuo 9226 for (i = 0; i < NumExtensions; i++) {
349     free(Extensions[i].exports);
350     FreeLibrary(Extensions[i].LibHandle);
351     }
352 maya 3227
353 zmatsuo 9226 free(Extensions);
354     Extensions = NULL;
355     NumExtensions = 0;
356 maya 3227 }
357    
358 doda 6801 void PASCAL TTXSetCommandLine(PCHAR cmd, int cmdlen, PGetHNRec rec) {
359 maya 3227 int i;
360    
361     for (i = 0; i < NumExtensions; i++) {
362 zmatsuo 9226 if (Extensions[i].exports->TTXSetCommandLine != NULL) {
363     Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
364 maya 3227 }
365     }
366     }

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