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 9501 - (hide annotations) (download) (as text)
Wed Oct 27 12:48:49 2021 UTC (2 years, 5 months ago) by zmatsuo
Original Path: trunk/teraterm/teraterm/ttplug.c
File MIME type: text/x-csrc
File size: 10094 byte(s)
設定ファイルを置くフォルダを変更

- フォルダ
  - %APPDATA%\teraterm5 (%USERPROFILE%\AppData\Roaming\teraterm5)
- ファイル
  - TERATERM.INI
  - KEYBOARD.CFG
  - broadcast.log
- 使用していない GetDefaultFName() を削除
  - GetDefaultFNameW() に置き換えた
- フォルダに関する関数を整理
  - GetHomeDirW() を修正
    - 設定ファイルを置くフォルダを返す
    - ttypes.HomeDirW と同一
	- 従来は ttermpro.exe などが置いてあるフォルダを返していた
  - GetLogDirW() を追加
    - ログなどを置くフォルダを返す
    - ttypes.LogDirW と同一
  - GetExeDirW() を追加
    - ttermpro.exe などが存在するフォルダを返す
    - ttypes.LogDirW と同一
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 zmatsuo 9387
41 maya 3227 #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 typedef struct _ExtensionList {
48 zmatsuo 9226 TTXExports * exports;
49     HANDLE LibHandle;
50 maya 3227 } ExtensionList;
51    
52 zmatsuo 9226 static ExtensionList *Extensions;
53 zmatsuo 9387 static int NumExtensions = 0;
54 zmatsuo 9226
55 zmatsuo 9387 static int compareOrder(const void * e1, const void * e2)
56     {
57     TTXExports * * exports1 = (TTXExports * *)e1;
58     TTXExports * * exports2 = (TTXExports * *)e2;
59 maya 3227
60 zmatsuo 9387 return (*exports1)->loadOrder - (*exports2)->loadOrder;
61 maya 3227 }
62    
63 zmatsuo 9387 static void loadExtension(wchar_t const *fileName, const wchar_t *UILanguageFile)
64 zmatsuo 9224 {
65     DWORD err;
66     const wchar_t *sub_message;
67     HMODULE hPlugin;
68 maya 3227
69 zmatsuo 9324 hPlugin = LoadLibraryW(fileName);
70 zmatsuo 9224 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 zmatsuo 9230 {
134 zmatsuo 9342 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 zmatsuo 9387 TTMessageBoxW(NULL, &info, UILanguageFile, fileName, err, sub_message);
141 zmatsuo 9230 }
142 maya 3227 }
143    
144 zmatsuo 9356 static void LoadExtensions(PTTSet ts_)
145 zmatsuo 9225 {
146     wchar_t *load_mask;
147     WIN32_FIND_DATAW fd;
148     HANDLE hFind;
149 zmatsuo 9501 wchar_t *ExeDirW = ts_->ExeDirW;
150 maya 3227
151 zmatsuo 9501 aswprintf(&load_mask, L"%s\\TTX*.DLL", ExeDirW);
152 maya 3227
153 zmatsuo 9324 hFind = FindFirstFileW(load_mask, &fd);
154 zmatsuo 9225 if (hFind != INVALID_HANDLE_VALUE) {
155     do {
156     wchar_t *filename;
157 zmatsuo 9501 aswprintf(&filename, L"%s\\%s", ExeDirW, fd.cFileName);
158 zmatsuo 9387 loadExtension(filename, ts_->UILanguageFileW);
159 zmatsuo 9225 free(filename);
160 zmatsuo 9324 } while (FindNextFileW(hFind, &fd));
161 zmatsuo 9225 FindClose(hFind);
162     }
163     free(load_mask);
164 maya 3227
165 zmatsuo 9225 if (NumExtensions==0) return;
166 maya 3227
167 zmatsuo 9225 qsort(Extensions, NumExtensions, sizeof(Extensions[0]), compareOrder);
168 zmatsuo 9356 }
169 maya 3227
170 zmatsuo 9356 static void UnloadExtensions()
171     {
172     int i;
173 zmatsuo 9225 for (i = 0; i < NumExtensions; i++) {
174 zmatsuo 9356 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 zmatsuo 9226 if (Extensions[i].exports->TTXInit != NULL) {
193     Extensions[i].exports->TTXInit(ts_, cv_);
194 zmatsuo 9225 }
195     }
196 maya 3227 }
197    
198 zmatsuo 9223 static void PASCAL TTXInternalOpenTCP(TTXSockHooks * hooks) {
199 maya 3227 int i;
200    
201     for (i = 0; i < NumExtensions; i++) {
202 zmatsuo 9226 if (Extensions[i].exports->TTXOpenTCP != NULL) {
203     Extensions[i].exports->TTXOpenTCP(hooks);
204 maya 3227 }
205     }
206     }
207    
208 zmatsuo 9223 void PASCAL TTXOpenTCP(void)
209     {
210 zmatsuo 9226 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 zmatsuo 9223 }
219    
220     static void PASCAL TTXInternalCloseTCP(TTXSockHooks * hooks) {
221 maya 3227 int i;
222    
223     for (i = NumExtensions - 1; i >= 0; i--) {
224 zmatsuo 9226 if (Extensions[i].exports->TTXCloseTCP != NULL) {
225     Extensions[i].exports->TTXCloseTCP(hooks);
226 maya 3227 }
227     }
228     }
229    
230 zmatsuo 9223 void PASCAL TTXCloseTCP(void)
231     {
232 zmatsuo 9226 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 zmatsuo 9223 }
241    
242     static void PASCAL TTXInternalOpenFile(TTXFileHooks * hooks) {
243 maya 3227 int i;
244    
245     for (i = 0; i < NumExtensions; i++) {
246 zmatsuo 9226 if (Extensions[i].exports->TTXOpenFile != NULL) {
247     Extensions[i].exports->TTXOpenFile(hooks);
248 maya 3227 }
249     }
250     }
251    
252 zmatsuo 9223 void PASCAL TTXOpenFile(void)
253     {
254 zmatsuo 9226 static TTXFileHooks FileHooks = {
255     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
256     };
257     TTXInternalOpenFile(&FileHooks);
258 zmatsuo 9223 }
259    
260     static void PASCAL TTXInternalCloseFile(TTXFileHooks * hooks) {
261 maya 3227 int i;
262    
263     for (i = NumExtensions - 1; i >= 0; i--) {
264 zmatsuo 9226 if (Extensions[i].exports->TTXCloseFile != NULL) {
265     Extensions[i].exports->TTXCloseFile(hooks);
266 maya 3227 }
267     }
268     }
269    
270 zmatsuo 9223 void PASCAL TTXCloseFile(void)
271     {
272 zmatsuo 9226 static TTXFileHooks FileHooks = {
273     &PCreateFile, &PCloseFile, &PReadFile, &PWriteFile
274     };
275     TTXInternalCloseFile(&FileHooks);
276 zmatsuo 9223 }
277    
278     static void PASCAL TTXInternalGetUIHooks(TTXUIHooks * hooks) {
279 maya 3227 int i;
280    
281     for (i = 0; i < NumExtensions; i++) {
282 zmatsuo 9226 if (Extensions[i].exports->TTXGetUIHooks != NULL) {
283     Extensions[i].exports->TTXGetUIHooks(hooks);
284 maya 3227 }
285     }
286     }
287    
288 zmatsuo 9223 void PASCAL TTXGetUIHooks(void)
289     {
290 zmatsuo 9226 static TTXUIHooks UIHooks = {
291     &SetupTerminal, &SetupWin, &SetupKeyboard, &SetupSerialPort,
292     &SetupTCPIP, &GetHostName, &ChangeDirectory, &AboutDialog,
293     &ChooseFontDlg, &SetupGeneral, &WindowWindow
294     };
295     TTXInternalGetUIHooks(&UIHooks);
296 zmatsuo 9223 }
297    
298     static void PASCAL TTXInternalGetSetupHooks(TTXSetupHooks * hooks) {
299 maya 3227 int i;
300    
301     for (i = NumExtensions - 1; i >= 0; i--) {
302 zmatsuo 9226 if (Extensions[i].exports->TTXGetSetupHooks != NULL) {
303     Extensions[i].exports->TTXGetSetupHooks(hooks);
304 maya 3227 }
305     }
306     }
307    
308 zmatsuo 9223 void PASCAL TTXGetSetupHooks(void)
309     {
310 zmatsuo 9226 static TTXSetupHooks SetupHooks = {
311     &ReadIniFile, &WriteIniFile, &ReadKeyboardCnf, &CopyHostList,
312     &AddHostToList, &ParseParam
313     };
314     TTXInternalGetSetupHooks(&SetupHooks);
315 zmatsuo 9223 }
316    
317 doda 6801 void PASCAL TTXSetWinSize(int rows, int cols) {
318 maya 3227 int i;
319    
320     for (i = 0; i < NumExtensions; i++) {
321 zmatsuo 9226 if (Extensions[i].exports->TTXSetWinSize != NULL) {
322     Extensions[i].exports->TTXSetWinSize(rows, cols);
323 maya 3227 }
324     }
325     }
326    
327 doda 6801 void PASCAL TTXModifyMenu(HMENU menu) {
328 maya 3227 int i;
329    
330     for (i = 0; i < NumExtensions; i++) {
331 zmatsuo 9226 if (Extensions[i].exports->TTXModifyMenu != NULL) {
332     Extensions[i].exports->TTXModifyMenu(menu);
333 maya 3227 }
334     }
335     }
336    
337 doda 6801 void PASCAL TTXModifyPopupMenu(HMENU menu) {
338 maya 3227 int i;
339    
340     for (i = 0; i < NumExtensions; i++) {
341 zmatsuo 9226 if (Extensions[i].exports->TTXModifyPopupMenu != NULL) {
342     Extensions[i].exports->TTXModifyPopupMenu(menu);
343 maya 3227 }
344     }
345     }
346    
347 doda 6801 BOOL PASCAL TTXProcessCommand(HWND hWin, WORD cmd) {
348 maya 3227 int i;
349    
350     for (i = NumExtensions - 1; i >= 0; i--) {
351 zmatsuo 9226 if (Extensions[i].exports->TTXProcessCommand != NULL) {
352     if (Extensions[i].exports->TTXProcessCommand(hWin,cmd)) {
353 maya 3227 return TRUE;
354     }
355     }
356     }
357    
358     return FALSE;
359     }
360    
361 zmatsuo 9226 void PASCAL TTXEnd(void)
362     {
363     int i;
364 maya 3227
365 zmatsuo 9226 if (NumExtensions == 0)
366     return;
367 maya 3227
368 zmatsuo 9226 for (i = NumExtensions - 1; i >= 0; i--) {
369     if (Extensions[i].exports->TTXEnd != NULL) {
370     Extensions[i].exports->TTXEnd();
371     }
372     }
373 maya 3227
374 zmatsuo 9356 UnloadExtensions();
375 maya 3227 }
376    
377 zmatsuo 9487 void PASCAL TTXSetCommandLine(wchar_t *cmd, int cmdlen, PGetHNRec rec)
378     {
379     int i;
380 maya 3227
381 zmatsuo 9487 for (i = 0; i < NumExtensions; i++) {
382     if (Extensions[i].exports->TTXSetCommandLine != NULL) {
383     Extensions[i].exports->TTXSetCommandLine(cmd, cmdlen, rec);
384     }
385     }
386 maya 3227 }

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