Open-Source-Software-Entwicklung und Downloads

Browse Subversion Repository

Diff of /trunk/ttssh2/ttxssh/fwdui.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3226 by maya, Tue Mar 24 09:37:20 2009 UTC revision 3227 by maya, Tue Mar 24 15:10:33 2009 UTC
# Line 1  Line 1 
1  /*  /*
2  Copyright (c) 1998-2001, Robert O'Callahan  Copyright (c) 1998-2001, Robert O'Callahan
3  All rights reserved.  All rights reserved.
4    
5  Redistribution and use in source and binary forms, with or without modification,  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:  are permitted provided that the following conditions are met:
7    
8  Redistributions of source code must retain the above copyright notice, this list of  Redistributions of source code must retain the above copyright notice, this list of
9  conditions and the following disclaimer.  conditions and the following disclaimer.
10    
11  Redistributions in binary form must reproduce the above copyright notice, this list  Redistributions in binary form must reproduce the above copyright notice, this list
12  of conditions and the following disclaimer in the documentation and/or other materials  of conditions and the following disclaimer in the documentation and/or other materials
13  provided with the distribution.  provided with the distribution.
14    
15  The name of Robert O'Callahan may not be used to endorse or promote products derived from  The name of Robert O'Callahan may not be used to endorse or promote products derived from
16  this software without specific prior written permission.  this software without specific prior written permission.
17    
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
19  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21  THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */  */
28    
29  /*  /*
30  This code is copyright (C) 1998-1999 Robert O'Callahan.  This code is copyright (C) 1998-1999 Robert O'Callahan.
31  See LICENSE.TXT for the license.  See LICENSE.TXT for the license.
32  */  */
33    
34  #include "fwdui.h"  #include "fwdui.h"
35    
36  #include "resource.h"  #include "resource.h"
37  #include "x11util.h"  #include "x11util.h"
38  #include "util.h"  #include "util.h"
39    
40  static HFONT DlgFwdEditFont;  static HFONT DlgFwdEditFont;
41  static HFONT DlgFwdFont;  static HFONT DlgFwdFont;
42    
43  typedef struct {  typedef struct {
44          int port;          int port;
45          char FAR *name;          char FAR *name;
46  } TCP_service_name;  } TCP_service_name;
47    
48  typedef struct {  typedef struct {
49          FWDRequestSpec FAR *spec;          FWDRequestSpec FAR *spec;
50          PTInstVar pvar;          PTInstVar pvar;
51  } FWDEditClosure;  } FWDEditClosure;
52    
53  static TCP_service_name service_DB[] = {  static TCP_service_name service_DB[] = {
54          {384, "arns"},          {384, "arns"},
55          {204, "at-echo"},          {204, "at-echo"},
56          {202, "at-nbp"},          {202, "at-nbp"},
57          {201, "at-rtmp"},          {201, "at-rtmp"},
58          {206, "at-zis"},          {206, "at-zis"},
59          {705, "auditd"},          {705, "auditd"},
60          {113, "auth"},          {113, "auth"},
61          {113, "authentication"},          {113, "authentication"},
62          {152, "bftp"},          {152, "bftp"},
63          {179, "bgp"},          {179, "bgp"},
64          {67, "bootp"},          {67, "bootp"},
65          {68, "bootpc"},          {68, "bootpc"},
66          {67, "bootps"},          {67, "bootps"},
67          {881, "bshell"},          {881, "bshell"},
68          {1133, "bshelldbg"},          {1133, "bshelldbg"},
69          {877, "buildd"},          {877, "buildd"},
70          {2003, "cfinger"},          {2003, "cfinger"},
71          {19, "chargen"},          {19, "chargen"},
72          {531, "chat"},          {531, "chat"},
73          {2030, "client"},          {2030, "client"},
74          {514, "cmd"},          {514, "cmd"},
75          {164, "cmip-agent"},          {164, "cmip-agent"},
76          {163, "cmip-man"},          {163, "cmip-man"},
77          {1431, "coda_aux1"},          {1431, "coda_aux1"},
78          {1433, "coda_aux2"},          {1433, "coda_aux2"},
79          {1435, "coda_aux3"},          {1435, "coda_aux3"},
80          {1407, "coda_backup"},          {1407, "coda_backup"},
81          {1423, "codacon"},          {1423, "codacon"},
82          {1285, "codger"},          {1285, "codger"},
83          {1541, "codgerdbg"},          {1541, "codgerdbg"},
84          {531, "conference"},          {531, "conference"},
85          {1389, "controller"},          {1389, "controller"},
86          {530, "courier"},          {530, "courier"},
87          {1100, "cpsys"},          {1100, "cpsys"},
88          {1346, "csd"},          {1346, "csd"},
89          {1602, "csddbg"},          {1602, "csddbg"},
90          {105, "csnet-ns"},          {105, "csnet-ns"},
91          {105, "cso-ns"},          {105, "cso-ns"},
92          {1999, "cvskserver"},          {1999, "cvskserver"},
93          {987, "daserver"},          {987, "daserver"},
94          {13, "daytime"},          {13, "daytime"},
95          {1429, "dbp"},          {1429, "dbp"},
96          {10300, "dictionary"},          {10300, "dictionary"},
97          {9, "discard"},          {9, "discard"},
98          {2100, "discuss"},          {2100, "discuss"},
99          {1399, "disptool0"},          {1399, "disptool0"},
100          {1401, "disptool1"},          {1401, "disptool1"},
101          {1403, "disptool2"},          {1403, "disptool2"},
102          {1405, "disptool3"},          {1405, "disptool3"},
103          {53, "domain"},          {53, "domain"},
104          {7000, "dos"},          {7000, "dos"},
105          {7, "echo"},          {7, "echo"},
106          {8100, "eda1_mbx"},          {8100, "eda1_mbx"},
107          {8101, "eda2_mbx"},          {8101, "eda2_mbx"},
108          {8000, "eda_mbx"},          {8000, "eda_mbx"},
109          {520, "efs"},          {520, "efs"},
110          {2105, "eklogin"},          {2105, "eklogin"},
111          {545, "ekshell"},          {545, "ekshell"},
112          {1377, "erim"},          {1377, "erim"},
113          {1617, "erimdbg"},          {1617, "erimdbg"},
114          {888, "erlogin"},          {888, "erlogin"},
115          {512, "exec"},          {512, "exec"},
116          {2001, "filesrv"},          {2001, "filesrv"},
117          {79, "finger"},          {79, "finger"},
118          {21, "ftp"},          {21, "ftp"},
119          {20, "ftp-data"},          {20, "ftp-data"},
120          {1397, "gds_db"},          {1397, "gds_db"},
121          {70, "gopher"},          {70, "gopher"},
122          {1025, "greendbg"},          {1025, "greendbg"},
123          {5999, "grmd"},          {5999, "grmd"},
124          {5710, "hcserver"},          {5710, "hcserver"},
125          {751, "hesupd"},          {751, "hesupd"},
126          {101, "hostname"},          {101, "hostname"},
127          {101, "hostnames"},          {101, "hostnames"},
128          {80, "http"},          {80, "http"},
129          {7489, "iasqlsvr"},          {7489, "iasqlsvr"},
130          {113, "ident"},          {113, "ident"},
131          {143, "imap"},          {143, "imap"},
132          {143, "imap2"},          {143, "imap2"},
133          {220, "imap3"},          {220, "imap3"},
134          {1524, "ingreslock"},          {1524, "ingreslock"},
135          {1234, "instsrv"},          {1234, "instsrv"},
136          {1387, "ipt"},          {1387, "ipt"},
137          {213, "ipx"},          {213, "ipx"},
138          {194, "irc"},          {194, "irc"},
139          {6667, "irc-alt"},          {6667, "irc-alt"},
140          {883, "ishell"},          {883, "ishell"},
141          {102, "iso-tsap"},          {102, "iso-tsap"},
142          {885, "itkt"},          {885, "itkt"},
143          {1439, "jeeves"},          {1439, "jeeves"},
144          {1389, "joysticknav"},          {1389, "joysticknav"},
145          {1629, "joysticknavdbg"},          {1629, "joysticknavdbg"},
146          {544, "kcmd"},          {544, "kcmd"},
147          {750, "kdc"},          {750, "kdc"},
148          {10401, "kdebug"},          {10401, "kdebug"},
149          {750, "kerberos"},          {750, "kerberos"},
150          {749, "kerberos-adm"},          {749, "kerberos-adm"},
151          {88, "kerberos-sec"},          {88, "kerberos-sec"},
152          {751, "kerberos_master"},          {751, "kerberos_master"},
153          {1445, "kjdbc"},          {1445, "kjdbc"},
154          {543, "klogin"},          {543, "klogin"},
155          {561, "kopexec"},          {561, "kopexec"},
156          {562, "kopshell"},          {562, "kopshell"},
157          {761, "kpasswd"},          {761, "kpasswd"},
158          {1109, "kpop"},          {1109, "kpop"},
159          {1110, "kpopr"},          {1110, "kpopr"},
160          {761, "kpwd"},          {761, "kpwd"},
161          {88, "krb5"},          {88, "krb5"},
162          {4444, "krb524"},          {4444, "krb524"},
163          {754, "krb5_prop"},          {754, "krb5_prop"},
164          {754, "krb_prop"},          {754, "krb_prop"},
165          {760, "krbupdate"},          {760, "krbupdate"},
166          {545, "krcmd"},          {545, "krcmd"},
167          {1443, "krcp"},          {1443, "krcp"},
168          {760, "kreg"},          {760, "kreg"},
169          {544, "kshell"},          {544, "kshell"},
170          {750, "ktc"},          {750, "ktc"},
171          {549, "kxct"},          {549, "kxct"},
172          {5696, "lanmgrx.osb"},          {5696, "lanmgrx.osb"},
173          {1441, "lcladm"},          {1441, "lcladm"},
174          {87, "link"},          {87, "link"},
175          {98, "linuxconf"},          {98, "linuxconf"},
176          {2766, "listen"},          {2766, "listen"},
177          {1025, "listener"},          {1025, "listener"},
178          {135, "loc-srv"},          {135, "loc-srv"},
179          {4045, "lockd"},          {4045, "lockd"},
180          {513, "login"},          {513, "login"},
181          {25, "mail"},          {25, "mail"},
182          {9535, "man"},          {9535, "man"},
183          {3881, "mbatchd"},          {3881, "mbatchd"},
184          {1393, "motionnav"},          {1393, "motionnav"},
185          {1633, "motionnavdbg"},          {1633, "motionnavdbg"},
186          {7000, "msdos"},          {7000, "msdos"},
187          {18, "msp"},          {18, "msp"},
188          {57, "mtp"},          {57, "mtp"},
189          {42, "name"},          {42, "name"},
190          {42, "nameserver"},          {42, "nameserver"},
191          {773, "nanny"},          {773, "nanny"},
192          {138, "nbdgm"},          {138, "nbdgm"},
193          {137, "nbns"},          {137, "nbns"},
194          {139, "nbssn"},          {139, "nbssn"},
195          {1419, "ndim"},          {1419, "ndim"},
196          {138, "netbios-dgm"},          {138, "netbios-dgm"},
197          {137, "netbios-ns"},          {137, "netbios-ns"},
198          {139, "netbios-ssn"},          {139, "netbios-ssn"},
199          {138, "netbios_dgm"},          {138, "netbios_dgm"},
200          {137, "netbios_ns"},          {137, "netbios_ns"},
201          {139, "netbios_ssn"},          {139, "netbios_ssn"},
202          {2106, "netdist"},          {2106, "netdist"},
203          {1287, "netimage"},          {1287, "netimage"},
204          {1543, "netimagedbg"},          {1543, "netimagedbg"},
205          {532, "netnews"},          {532, "netnews"},
206          {1353, "netreg"},          {1353, "netreg"},
207          {1609, "netregdbg"},          {1609, "netregdbg"},
208          {77, "netrjs"},          {77, "netrjs"},
209          {15, "netstat"},          {15, "netstat"},
210          {1026, "network_terminal"},          {1026, "network_terminal"},
211          {526, "newdate"},          {526, "newdate"},
212          {144, "news"},          {144, "news"},
213          {178, "nextstep"},          {178, "nextstep"},
214          {1536, "nft"},          {1536, "nft"},
215          {43, "nicname"},          {43, "nicname"},
216          {119, "nntp"},          {119, "nntp"},
217          {1026, "nterm"},          {1026, "nterm"},
218          {123, "ntp"},          {123, "ntp"},
219          {123, "ntpd"},          {123, "ntpd"},
220          {9, "null"},          {9, "null"},
221          {891, "odexm"},          {891, "odexm"},
222          {560, "opcmd"},          {560, "opcmd"},
223          {560, "opshell"},          {560, "opshell"},
224          {879, "pag"},          {879, "pag"},
225          {893, "papyrus"},          {893, "papyrus"},
226          {1379, "parvis"},          {1379, "parvis"},
227          {1619, "parvisdbg"},          {1619, "parvisdbg"},
228          {600, "pcserver"},          {600, "pcserver"},
229          {2026, "pcserverbulk"},          {2026, "pcserverbulk"},
230          {2025, "pcserverrpc"},          {2025, "pcserverrpc"},
231          {1385, "pharos"},          {1385, "pharos"},
232          {1373, "pierunt"},          {1373, "pierunt"},
233          {1613, "pieruntdbg"},          {1613, "pieruntdbg"},
234          {1351, "piesrv"},          {1351, "piesrv"},
235          {1607, "piesrvdbg"},          {1607, "piesrvdbg"},
236          {1889, "pmlockd"},          {1889, "pmlockd"},
237          {109, "pop"},          {109, "pop"},
238          {109, "pop-2"},          {109, "pop-2"},
239          {110, "pop-3"},          {110, "pop-3"},
240          {109, "pop2"},          {109, "pop2"},
241          {110, "pop3"},          {110, "pop3"},
242          {111, "portmap"},          {111, "portmap"},
243          {111, "portmapper"},          {111, "portmapper"},
244          {109, "postoffice"},          {109, "postoffice"},
245          {170, "print-srv"},          {170, "print-srv"},
246          {515, "printer"},          {515, "printer"},
247          {191, "prospero"},          {191, "prospero"},
248          {1525, "prospero-np"},          {1525, "prospero-np"},
249          {17, "qotd"},          {17, "qotd"},
250          {17, "quote"},          {17, "quote"},
251          {601, "rauth"},          {601, "rauth"},
252          {5347, "rcisimmux"},          {5347, "rcisimmux"},
253          {1530, "rdeliver"},          {1530, "rdeliver"},
254          {532, "readnews"},          {532, "readnews"},
255          {7815, "recserv"},          {7815, "recserv"},
256          {64, "rem"},          {64, "rem"},
257          {1025, "remote_file_sharing"},          {1025, "remote_file_sharing"},
258          {1026, "remote_login"},          {1026, "remote_login"},
259          {556, "remotefs"},          {556, "remotefs"},
260          {3878, "res"},          {3878, "res"},
261          {875, "resolve"},          {875, "resolve"},
262          {1131, "resolvedbg"},          {1131, "resolvedbg"},
263          {4672, "rfa"},          {4672, "rfa"},
264          {5002, "rfe"},          {5002, "rfe"},
265          {1025, "rfs"},          {1025, "rfs"},
266          {556, "rfs_server"},          {556, "rfs_server"},
267          {1027, "rfsdbg"},          {1027, "rfsdbg"},
268          {77, "rje"},          {77, "rje"},
269          {1260, "rlb"},          {1260, "rlb"},
270          {1425, "rndb2"},          {1425, "rndb2"},
271          {530, "rpc"},          {530, "rpc"},
272          {111, "rpcbind"},          {111, "rpcbind"},
273          {1347, "rpl"},          {1347, "rpl"},
274          {1603, "rpldbg"},          {1603, "rpldbg"},
275          {107, "rtelnet"},          {107, "rtelnet"},
276          {3882, "sbatchd"},          {3882, "sbatchd"},
277          {778, "serv"},          {778, "serv"},
278          {1375, "service_warp"},          {1375, "service_warp"},
279          {1615, "service_warpdbg"},          {1615, "service_warpdbg"},
280          {115, "sftp"},          {115, "sftp"},
281          {5232, "sgi-dgl"},          {5232, "sgi-dgl"},
282          {514, "shell"},          {514, "shell"},
283          {1135, "shelob"},          {1135, "shelob"},
284          {1137, "shelobsrv"},          {1137, "shelobsrv"},
285          {9, "sink"},          {9, "sink"},
286          {775, "sms_db"},          {775, "sms_db"},
287          {777, "sms_update"},          {777, "sms_update"},
288          {25, "smtp"},          {25, "smtp"},
289          {199, "smux"},          {199, "smux"},
290          {108, "snagas"},          {108, "snagas"},
291          {19, "source"},          {19, "source"},
292          {6111, "spc"},          {6111, "spc"},
293          {515, "spooler"},          {515, "spooler"},
294          {23523, "sshprop"},          {23523, "sshprop"},
295          {1391, "statnav"},          {1391, "statnav"},
296          {1621, "statnavdbg"},          {1621, "statnavdbg"},
297          {1395, "stm_switch"},          {1395, "stm_switch"},
298          {1283, "sunmatrox"},          {1283, "sunmatrox"},
299          {1539, "sunmatroxdbg"},          {1539, "sunmatroxdbg"},
300          {111, "sunrpc"},          {111, "sunrpc"},
301          {95, "supdup"},          {95, "supdup"},
302          {1127, "supfiledbg"},          {1127, "supfiledbg"},
303          {871, "supfilesrv"},          {871, "supfilesrv"},
304          {1125, "supnamedbg"},          {1125, "supnamedbg"},
305          {869, "supnamesrv"},          {869, "supnamesrv"},
306          {1529, "support"},          {1529, "support"},
307          {11, "systat"},          {11, "systat"},
308          {601, "ta-rauth"},          {601, "ta-rauth"},
309          {113, "tap"},          {113, "tap"},
310          {1381, "task_control"},          {1381, "task_control"},
311          {1, "tcpmux"},          {1, "tcpmux"},
312          {23, "telnet"},          {23, "telnet"},
313          {24, "telnet2"},          {24, "telnet2"},
314          {526, "tempo"},          {526, "tempo"},
315          {17, "text"},          {17, "text"},
316          {37, "time"},          {37, "time"},
317          {37, "timserver"},          {37, "timserver"},
318          {1600, "tnet"},          {1600, "tnet"},
319          {102, "tsap"},          {102, "tsap"},
320          {87, "ttylink"},          {87, "ttylink"},
321          {19, "ttytst"},          {19, "ttytst"},
322          {372, "ulistserv"},          {372, "ulistserv"},
323          {119, "untp"},          {119, "untp"},
324          {119, "usenet"},          {119, "usenet"},
325          {11, "users"},          {11, "users"},
326          {1400, "usim"},          {1400, "usim"},
327          {540, "uucp"},          {540, "uucp"},
328          {117, "uucp-path"},          {117, "uucp-path"},
329          {540, "uucpd"},          {540, "uucpd"},
330          {1387, "vapor"},          {1387, "vapor"},
331          {712, "vexec"},          {712, "vexec"},
332          {712, "vice-exec"},          {712, "vice-exec"},
333          {713, "vice-login"},          {713, "vice-login"},
334          {714, "vice-shell"},          {714, "vice-shell"},
335          {1371, "visim"},          {1371, "visim"},
336          {1611, "visimdbg"},          {1611, "visimdbg"},
337          {713, "vlogin"},          {713, "vlogin"},
338          {714, "vshell"},          {714, "vshell"},
339          {210, "wais"},          {210, "wais"},
340          {1427, "warplite"},          {1427, "warplite"},
341          {765, "webster"},          {765, "webster"},
342          {43, "whois"},          {43, "whois"},
343          {1421, "wiztemp"},          {1421, "wiztemp"},
344          {2000, "wm"},          {2000, "wm"},
345          {1383, "wnn"},          {1383, "wnn"},
346          {22273, "wnn4"},          {22273, "wnn4"},
347          {22289, "wnn4_cn"},          {22289, "wnn4_cn"},
348          {22273, "wnn4_jp"},          {22273, "wnn4_jp"},
349          {1348, "worldc"},          {1348, "worldc"},
350          {1604, "worldcdbg"},          {1604, "worldcdbg"},
351          {2401, "writesrv"},          {2401, "writesrv"},
352          {80, "www"},          {80, "www"},
353          {6000, "x-server"},          {6000, "x-server"},
354          {103, "x400"},          {103, "x400"},
355          {104, "x400-snd"},          {104, "x400-snd"},
356          {177, "xdmcp"},          {177, "xdmcp"},
357          {873, "xtermd"},          {873, "xtermd"},
358          {210, "z3950"}          {210, "z3950"}
359  };  };
360    
361  static int compare_services(void const FAR * elem1, void const FAR * elem2)  static int compare_services(void const FAR * elem1, void const FAR * elem2)
362  {  {
363          TCP_service_name FAR *s1 = (TCP_service_name FAR *) elem1;          TCP_service_name FAR *s1 = (TCP_service_name FAR *) elem1;
364          TCP_service_name FAR *s2 = (TCP_service_name FAR *) elem2;          TCP_service_name FAR *s2 = (TCP_service_name FAR *) elem2;
365    
366          return strcmp(s1->name, s2->name);          return strcmp(s1->name, s2->name);
367  }  }
368    
369  static void make_X_forwarding_spec(FWDRequestSpec FAR * spec, PTInstVar pvar)  static void make_X_forwarding_spec(FWDRequestSpec FAR * spec, PTInstVar pvar)
370  {  {
371          spec->type = FWD_REMOTE_X11_TO_LOCAL;          spec->type = FWD_REMOTE_X11_TO_LOCAL;
372          spec->from_port = -1;          spec->from_port = -1;
373          X11_get_DISPLAY_info(spec->to_host, sizeof(spec->to_host),          X11_get_DISPLAY_info(spec->to_host, sizeof(spec->to_host),
374                               &spec->to_port);                               &spec->to_port);
375          UTIL_get_lang_msg("MSG_FWD_REMOTE_XSERVER", pvar, "remote X server");          UTIL_get_lang_msg("MSG_FWD_REMOTE_XSERVER", pvar, "remote X server");
376          strncpy_s(spec->from_port_name, sizeof(spec->from_port_name),          strncpy_s(spec->from_port_name, sizeof(spec->from_port_name),
377                    pvar->ts->UIMsg, _TRUNCATE);                    pvar->ts->UIMsg, _TRUNCATE);
378          UTIL_get_lang_msg("MSG_FWD_REMOTE_XSCREEN", pvar, "X server (screen %d)");          UTIL_get_lang_msg("MSG_FWD_REMOTE_XSCREEN", pvar, "X server (screen %d)");
379          _snprintf_s(spec->to_port_name, sizeof(spec->to_port_name), _TRUNCATE,          _snprintf_s(spec->to_port_name, sizeof(spec->to_port_name), _TRUNCATE,
380                      pvar->ts->UIMsg, spec->to_port - 6000);                      pvar->ts->UIMsg, spec->to_port - 6000);
381  }  }
382    
383  static BOOL is_service_name_char(char ch)  static BOOL is_service_name_char(char ch)
384  {  {
385          return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')          return (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')
386              || ch == '_' || ch == '-' || (ch >= '0' && ch <= '9');              || ch == '_' || ch == '-' || (ch >= '0' && ch <= '9');
387  }  }
388    
389  static int parse_port_from_buf(char FAR * buf)  static int parse_port_from_buf(char FAR * buf)
390  {  {
391          int i;          int i;
392    
393          if (buf[0] >= '0' && buf[0] <= '9') {          if (buf[0] >= '0' && buf[0] <= '9') {
394                  int result = atoi(buf);                  int result = atoi(buf);
395    
396                  if (result < 1 || result > 65535) {                  if (result < 1 || result > 65535) {
397                          return -1;                          return -1;
398                  } else {                  } else {
399                          return result;                          return result;
400                  }                  }
401          } else {          } else {
402                  char lower_buf[32];                  char lower_buf[32];
403                  TCP_service_name FAR *result;                  TCP_service_name FAR *result;
404                  TCP_service_name key;                  TCP_service_name key;
405    
406                  for (i = 0; buf[i] != 0 && i < sizeof(lower_buf) - 1; i++) {                  for (i = 0; buf[i] != 0 && i < sizeof(lower_buf) - 1; i++) {
407                          lower_buf[i] = tolower(buf[i]);                          lower_buf[i] = tolower(buf[i]);
408                  }                  }
409                  lower_buf[i] = 0;                  lower_buf[i] = 0;
410    
411                  key.name = lower_buf;                  key.name = lower_buf;
412                  result = (TCP_service_name FAR *)                  result = (TCP_service_name FAR *)
413                          bsearch(&key, service_DB, NUM_ELEM(service_DB),                          bsearch(&key, service_DB, NUM_ELEM(service_DB),
414                                  sizeof(service_DB[0]), compare_services);                                  sizeof(service_DB[0]), compare_services);
415    
416                  if (result == NULL) {                  if (result == NULL) {
417                          return -1;                          return -1;
418                  } else {                  } else {
419                          return result->port;                          return result->port;
420                  }                  }
421          }          }
422  }  }
423    
424  static int parse_port(char FAR * FAR * str, char FAR * buf, int bufsize)  static int parse_port(char FAR * FAR * str, char FAR * buf, int bufsize)
425  {  {
426          int i = 0;          int i = 0;
427    
428          while (is_service_name_char(**str) && i < bufsize - 1) {          while (is_service_name_char(**str) && i < bufsize - 1) {
429                  buf[i] = **str;                  buf[i] = **str;
430                  (*str)++;                  (*str)++;
431                  i++;                  i++;
432          }          }
433          buf[i] = 0;          buf[i] = 0;
434    
435          return parse_port_from_buf(buf);          return parse_port_from_buf(buf);
436  }  }
437    
438  static BOOL parse_request(FWDRequestSpec FAR * request, char FAR * str, PTInstVar pvar)  static BOOL parse_request(FWDRequestSpec FAR * request, char FAR * str, PTInstVar pvar)
439  {  {
440          char FAR *host_start;          char FAR *host_start;
441    
442          if (str[0] == 'L' || str[0] == 'l') {          if (str[0] == 'L' || str[0] == 'l') {
443                  request->type = FWD_LOCAL_TO_REMOTE;                  request->type = FWD_LOCAL_TO_REMOTE;
444          } else if (str[0] == 'R' || str[0] == 'r') {          } else if (str[0] == 'R' || str[0] == 'r') {
445                  request->type = FWD_REMOTE_TO_LOCAL;                  request->type = FWD_REMOTE_TO_LOCAL;
446          } else if (str[0] == 'X' || str[0] == 'x') {          } else if (str[0] == 'X' || str[0] == 'x') {
447                  make_X_forwarding_spec(request, pvar);                  make_X_forwarding_spec(request, pvar);
448                  return TRUE;                  return TRUE;
449          } else {          } else {
450                  return FALSE;                  return FALSE;
451          }          }
452          str++;          str++;
453    
454          request->from_port =          request->from_port =
455                  parse_port(&str, request->from_port_name,                  parse_port(&str, request->from_port_name,
456                             sizeof(request->from_port_name));                             sizeof(request->from_port_name));
457          if (request->from_port < 0) {          if (request->from_port < 0) {
458                  return FALSE;                  return FALSE;
459          }          }
460    
461          if (*str != ':') {          if (*str != ':') {
462                  return FALSE;                  return FALSE;
463          }          }
464          str++;          str++;
465    
466          host_start = str;          host_start = str;
467          while (*str != ':' && *str != 0 && *str != ';') {          while (*str != ':' && *str != 0 && *str != ';') {
468                  str++;                  str++;
469          }          }
470          if (*str != ':') {          if (*str != ':') {
471                  return FALSE;                  return FALSE;
472          }          }
473          *str = 0;          *str = 0;
474          strncpy_s(request->to_host, sizeof(request->to_host), host_start, _TRUNCATE);          strncpy_s(request->to_host, sizeof(request->to_host), host_start, _TRUNCATE);
475          request->to_host[sizeof(request->to_host) - 1] = 0;          request->to_host[sizeof(request->to_host) - 1] = 0;
476          *str = ':';          *str = ':';
477          str++;          str++;
478    
479          request->to_port =          request->to_port =
480                  parse_port(&str, request->to_port_name,                  parse_port(&str, request->to_port_name,
481                             sizeof(request->to_port_name));                             sizeof(request->to_port_name));
482          if (request->to_port < 0) {          if (request->to_port < 0) {
483                  return FALSE;                  return FALSE;
484          }          }
485    
486          if (*str == ':') {          if (*str == ':') {
487                  str++;                  str++;
488                  request->check_identity = TRUE;                  request->check_identity = TRUE;
489                  if (*str == '1') {                  if (*str == '1') {
490                          request->check_identity = FALSE;                          request->check_identity = FALSE;
491                          str++;                          str++;
492                  }                  }
493          }          }
494    
495          if (*str != ';' && *str != 0) {          if (*str != ';' && *str != 0) {
496                  return FALSE;                  return FALSE;
497          }          }
498    
499          return TRUE;          return TRUE;
500  }  }
501    
502  static void FWDUI_save_settings(PTInstVar pvar)  static void FWDUI_save_settings(PTInstVar pvar)
503  {  {
504          int num_specs = FWD_get_num_request_specs(pvar);          int num_specs = FWD_get_num_request_specs(pvar);
505          FWDRequestSpec FAR *requests =          FWDRequestSpec FAR *requests =
506                  (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) * num_specs);                  (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) * num_specs);
507          int i;          int i;
508          char FAR *str = pvar->settings.DefaultForwarding;          char FAR *str = pvar->settings.DefaultForwarding;
509          int str_remaining = sizeof(pvar->settings.DefaultForwarding) - 1;          int str_remaining = sizeof(pvar->settings.DefaultForwarding) - 1;
510    
511          FWD_get_request_specs(pvar, requests, num_specs);          FWD_get_request_specs(pvar, requests, num_specs);
512    
513          *str = 0;          *str = 0;
514          str[str_remaining] = 0;          str[str_remaining] = 0;
515    
516          for (i = 0; i < num_specs; i++) {          for (i = 0; i < num_specs; i++) {
517                  if (str_remaining > 0 && i > 0) {                  if (str_remaining > 0 && i > 0) {
518                          str[0] = ';';                          str[0] = ';';
519                          str[1] = 0;                          str[1] = 0;
520                          str++;                          str++;
521                          str_remaining--;                          str_remaining--;
522                  }                  }
523    
524                  if (str_remaining > 0) {                  if (str_remaining > 0) {
525                          FWDRequestSpec FAR *spec = requests + i;                          FWDRequestSpec FAR *spec = requests + i;
526                          int chars;                          int chars;
527    
528                          switch (spec->type) {                          switch (spec->type) {
529                          case FWD_LOCAL_TO_REMOTE:                          case FWD_LOCAL_TO_REMOTE:
530                                  if (spec->check_identity == 0) {                                  if (spec->check_identity == 0) {
531                                          _snprintf_s(str, str_remaining, _TRUNCATE, "L%s:%s:%s:1",                                          _snprintf_s(str, str_remaining, _TRUNCATE, "L%s:%s:%s:1",
532                                                      spec->from_port_name, spec->to_host,                                                      spec->from_port_name, spec->to_host,
533                                                      spec->to_port_name);                                                      spec->to_port_name);
534                                  }                                  }
535                                  else {                                  else {
536                                          _snprintf_s(str, str_remaining, _TRUNCATE, "L%s:%s:%s",                                          _snprintf_s(str, str_remaining, _TRUNCATE, "L%s:%s:%s",
537                                                      spec->from_port_name, spec->to_host,                                                      spec->from_port_name, spec->to_host,
538                                                      spec->to_port_name);                                                      spec->to_port_name);
539                                  }                                  }
540                                  break;                                  break;
541                          case FWD_REMOTE_TO_LOCAL:                          case FWD_REMOTE_TO_LOCAL:
542                                  _snprintf_s(str, str_remaining, _TRUNCATE, "R%s:%s:%s",                                  _snprintf_s(str, str_remaining, _TRUNCATE, "R%s:%s:%s",
543                                              spec->from_port_name, spec->to_host,                                              spec->from_port_name, spec->to_host,
544                                              spec->to_port_name);                                              spec->to_port_name);
545                                  break;                                  break;
546                          case FWD_REMOTE_X11_TO_LOCAL:                          case FWD_REMOTE_X11_TO_LOCAL:
547                                  _snprintf_s(str, str_remaining, _TRUNCATE, "X");                                  _snprintf_s(str, str_remaining, _TRUNCATE, "X");
548                                  break;                                  break;
549                          }                          }
550    
551                          chars = strlen(str);                          chars = strlen(str);
552                          str += chars;                          str += chars;
553                          str_remaining -= chars;                          str_remaining -= chars;
554                  }                  }
555          }          }
556    
557          free(requests);          free(requests);
558  }  }
559    
560  void FWDUI_load_settings(PTInstVar pvar)  void FWDUI_load_settings(PTInstVar pvar)
561  {  {
562          char FAR *str = pvar->settings.DefaultForwarding;          char FAR *str = pvar->settings.DefaultForwarding;
563    
564          if (str[0] != 0) {          if (str[0] != 0) {
565                  int i, ch, j;                  int i, ch, j;
566                  FWDRequestSpec FAR *requests;                  FWDRequestSpec FAR *requests;
567    
568                  j = 1;                  j = 1;
569                  for (i = 0; (ch = str[i]) != 0; i++) {                  for (i = 0; (ch = str[i]) != 0; i++) {
570                          if (ch == ';') {                          if (ch == ';') {
571                                  j++;                                  j++;
572                          }                          }
573                  }                  }
574    
575                  requests =                  requests =
576                          (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) * j);                          (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) * j);
577    
578                  j = 0;                  j = 0;
579                  if (parse_request(requests, str, pvar)) {                  if (parse_request(requests, str, pvar)) {
580                          j++;                          j++;
581                  }                  }
582                  for (i = 0; (ch = str[i]) != 0; i++) {                  for (i = 0; (ch = str[i]) != 0; i++) {
583                          if (ch == ';') {                          if (ch == ';') {
584                                  if (parse_request(requests + j, str + i + 1, pvar)) {                                  if (parse_request(requests + j, str + i + 1, pvar)) {
585                                          j++;                                          j++;
586                                  }                                  }
587                          }                          }
588                  }                  }
589    
590                  qsort(requests, j, sizeof(FWDRequestSpec), FWD_compare_specs);                  qsort(requests, j, sizeof(FWDRequestSpec), FWD_compare_specs);
591    
592                  for (i = 0; i < j - 1; i++) {                  for (i = 0; i < j - 1; i++) {
593                          if (FWD_compare_specs(requests + i, requests + i + 1) == 0) {                          if (FWD_compare_specs(requests + i, requests + i + 1) == 0) {
594                                  memmove(requests + i, requests + i + 1,                                  memmove(requests + i, requests + i + 1,
595                                          sizeof(FWDRequestSpec) * (j - 1 - i));                                          sizeof(FWDRequestSpec) * (j - 1 - i));
596                                  i--;                                  i--;
597                                  j--;                                  j--;
598                          }                          }
599                  }                  }
600    
601                  FWD_set_request_specs(pvar, requests, j);                  FWD_set_request_specs(pvar, requests, j);
602                  FWDUI_save_settings(pvar);                  FWDUI_save_settings(pvar);
603    
604                  free(requests);                  free(requests);
605          }          }
606  }  }
607    
608  void FWDUI_init(PTInstVar pvar)  void FWDUI_init(PTInstVar pvar)
609  {  {
610  }  }
611    
612  void FWDUI_end(PTInstVar pvar)  void FWDUI_end(PTInstVar pvar)
613  {  {
614  }  }
615    
616  void FWDUI_open(PTInstVar pvar)  void FWDUI_open(PTInstVar pvar)
617  {  {
618  }  }
619    
620  static void set_verbose_port(char FAR * buf, int bufsize, int port,  static void set_verbose_port(char FAR * buf, int bufsize, int port,
621                               char FAR * name)                               char FAR * name)
622  {  {
623          if (*name >= '0' && *name <= '9') {          if (*name >= '0' && *name <= '9') {
624                  strncpy_s(buf, bufsize, name, _TRUNCATE);                  strncpy_s(buf, bufsize, name, _TRUNCATE);
625          } else {          } else {
626                  _snprintf_s(buf, bufsize, _TRUNCATE, "%d (%s)", port, name);                  _snprintf_s(buf, bufsize, _TRUNCATE, "%d (%s)", port, name);
627          }          }
628    
629          buf[bufsize - 1] = 0;          buf[bufsize - 1] = 0;
630  }  }
631    
632  static void get_spec_string(FWDRequestSpec FAR * spec, char FAR * buf,  static void get_spec_string(FWDRequestSpec FAR * spec, char FAR * buf,
633                              int bufsize, PTInstVar pvar)                              int bufsize, PTInstVar pvar)
634  {  {
635          char verbose_from_port[64];          char verbose_from_port[64];
636          char verbose_to_port[64];          char verbose_to_port[64];
637    
638          set_verbose_port(verbose_from_port, sizeof(verbose_from_port),          set_verbose_port(verbose_from_port, sizeof(verbose_from_port),
639                           spec->from_port, spec->from_port_name);                           spec->from_port, spec->from_port_name);
640          set_verbose_port(verbose_to_port, sizeof(verbose_to_port),          set_verbose_port(verbose_to_port, sizeof(verbose_to_port),
641                           spec->to_port, spec->to_port_name);                           spec->to_port, spec->to_port_name);
642    
643          switch (spec->type) {          switch (spec->type) {
644          case FWD_REMOTE_TO_LOCAL:          case FWD_REMOTE_TO_LOCAL:
645                  UTIL_get_lang_msg("MSG_FWD_REMOTE", pvar,                  UTIL_get_lang_msg("MSG_FWD_REMOTE", pvar,
646                                    "Remote %s to local \"%s\" port %s");                                    "Remote %s to local \"%s\" port %s");
647                  _snprintf_s(buf, bufsize, _TRUNCATE, pvar->ts->UIMsg,                  _snprintf_s(buf, bufsize, _TRUNCATE, pvar->ts->UIMsg,
648                              verbose_from_port, spec->to_host, verbose_to_port);                              verbose_from_port, spec->to_host, verbose_to_port);
649                  break;                  break;
650          case FWD_LOCAL_TO_REMOTE:          case FWD_LOCAL_TO_REMOTE:
651                  UTIL_get_lang_msg("MSG_FWD_LOCAL", pvar,                  UTIL_get_lang_msg("MSG_FWD_LOCAL", pvar,
652                                    "Local %s to remote \"%s\" port %s");                                    "Local %s to remote \"%s\" port %s");
653                  _snprintf_s(buf, bufsize, _TRUNCATE, pvar->ts->UIMsg,                  _snprintf_s(buf, bufsize, _TRUNCATE, pvar->ts->UIMsg,
654                              verbose_from_port, spec->to_host, verbose_to_port);                              verbose_from_port, spec->to_host, verbose_to_port);
655                  break;                  break;
656          case FWD_REMOTE_X11_TO_LOCAL:          case FWD_REMOTE_X11_TO_LOCAL:
657                  UTIL_get_lang_msg("MSG_FWD_X", pvar,                  UTIL_get_lang_msg("MSG_FWD_X", pvar,
658                                    "Remote X applications to local X server");                                    "Remote X applications to local X server");
659                  strncpy_s(buf, bufsize, pvar->ts->UIMsg, _TRUNCATE);                  strncpy_s(buf, bufsize, pvar->ts->UIMsg, _TRUNCATE);
660                  return;                  return;
661          }          }
662  }  }
663    
664  static void update_listbox_selection(HWND dlg)  static void update_listbox_selection(HWND dlg)
665  {  {
666          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);
667          int cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0);          int cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0);
668    
669          EnableWindow(GetDlgItem(dlg, IDC_EDIT), cursel >= 0);          EnableWindow(GetDlgItem(dlg, IDC_EDIT), cursel >= 0);
670          EnableWindow(GetDlgItem(dlg, IDC_REMOVE), cursel >= 0);          EnableWindow(GetDlgItem(dlg, IDC_REMOVE), cursel >= 0);
671  }  }
672    
673  static void init_listbox_selection(HWND dlg)  static void init_listbox_selection(HWND dlg)
674  {  {
675          SendMessage(GetDlgItem(dlg, IDC_SSHFWDLIST), LB_SETCURSEL, 0, 0);          SendMessage(GetDlgItem(dlg, IDC_SSHFWDLIST), LB_SETCURSEL, 0, 0);
676          update_listbox_selection(dlg);          update_listbox_selection(dlg);
677  }  }
678    
679  static int add_spec_to_listbox(HWND dlg, FWDRequestSpec FAR * spec, PTInstVar pvar)  static int add_spec_to_listbox(HWND dlg, FWDRequestSpec FAR * spec, PTInstVar pvar)
680  {  {
681          char buf[1024];          char buf[1024];
682          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);
683          int index;          int index;
684    
685          get_spec_string(spec, buf, sizeof(buf), pvar);          get_spec_string(spec, buf, sizeof(buf), pvar);
686    
687          index = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM) buf);          index = SendMessage(listbox, LB_ADDSTRING, 0, (LPARAM) buf);
688    
689          if (index >= 0) {          if (index >= 0) {
690                  FWDRequestSpec FAR *listbox_spec = malloc(sizeof(FWDRequestSpec));                  FWDRequestSpec FAR *listbox_spec = malloc(sizeof(FWDRequestSpec));
691    
692                  *listbox_spec = *spec;                  *listbox_spec = *spec;
693                  if (SendMessage                  if (SendMessage
694                          (listbox, LB_SETITEMDATA, index,                          (listbox, LB_SETITEMDATA, index,
695                           (LPARAM) listbox_spec) == LB_ERR) {                           (LPARAM) listbox_spec) == LB_ERR) {
696                          free(listbox_spec);                          free(listbox_spec);
697                  }                  }
698          }          }
699    
700          return index;          return index;
701  }  }
702    
703  static void init_fwd_dlg(PTInstVar pvar, HWND dlg)  static void init_fwd_dlg(PTInstVar pvar, HWND dlg)
704  {  {
705          int num_specs = FWD_get_num_request_specs(pvar);          int num_specs = FWD_get_num_request_specs(pvar);
706          FWDRequestSpec FAR *requests =          FWDRequestSpec FAR *requests =
707                  (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) * num_specs);                  (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) * num_specs);
708          int i;          int i;
709          char uimsg[MAX_UIMSG];          char uimsg[MAX_UIMSG];
710    
711          GetWindowText(dlg, uimsg, sizeof(uimsg));          GetWindowText(dlg, uimsg, sizeof(uimsg));
712          UTIL_get_lang_msg("DLG_FWD_TITLE", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_TITLE", pvar, uimsg);
713          SetWindowText(dlg, pvar->ts->UIMsg);          SetWindowText(dlg, pvar->ts->UIMsg);
714          GetDlgItemText(dlg, IDC_PORTFORWARD, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_PORTFORWARD, uimsg, sizeof(uimsg));
715          UTIL_get_lang_msg("DLG_FWDSETUP_LIST", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWDSETUP_LIST", pvar, uimsg);
716          SetDlgItemText(dlg, IDC_PORTFORWARD, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_PORTFORWARD, pvar->ts->UIMsg);
717          GetDlgItemText(dlg, IDC_ADD, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_ADD, uimsg, sizeof(uimsg));
718          UTIL_get_lang_msg("DLG_FWDSETUP_ADD", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWDSETUP_ADD", pvar, uimsg);
719          SetDlgItemText(dlg, IDC_ADD, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_ADD, pvar->ts->UIMsg);
720          GetDlgItemText(dlg, IDC_EDIT, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_EDIT, uimsg, sizeof(uimsg));
721          UTIL_get_lang_msg("DLG_FWDSETUP_EDIT", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWDSETUP_EDIT", pvar, uimsg);
722          SetDlgItemText(dlg, IDC_EDIT, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_EDIT, pvar->ts->UIMsg);
723          GetDlgItemText(dlg, IDC_REMOVE, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_REMOVE, uimsg, sizeof(uimsg));
724          UTIL_get_lang_msg("DLG_FWDSETUP_REMOVE", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWDSETUP_REMOVE", pvar, uimsg);
725          SetDlgItemText(dlg, IDC_REMOVE, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_REMOVE, pvar->ts->UIMsg);
726          GetDlgItemText(dlg, IDC_CHECKIDENTITY, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_CHECKIDENTITY, uimsg, sizeof(uimsg));
727          UTIL_get_lang_msg("DLG_FWDSETUP_CHECKIDENTITY", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWDSETUP_CHECKIDENTITY", pvar, uimsg);
728          SetDlgItemText(dlg, IDC_CHECKIDENTITY, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_CHECKIDENTITY, pvar->ts->UIMsg);
729          GetDlgItemText(dlg, IDC_XFORWARD, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_XFORWARD, uimsg, sizeof(uimsg));
730          UTIL_get_lang_msg("DLD_FWDSETUP_X", pvar, uimsg);          UTIL_get_lang_msg("DLD_FWDSETUP_X", pvar, uimsg);
731          SetDlgItemText(dlg, IDC_XFORWARD, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_XFORWARD, pvar->ts->UIMsg);
732          GetDlgItemText(dlg, IDC_SSHFWDX11, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDX11, uimsg, sizeof(uimsg));
733          UTIL_get_lang_msg("DLG_FWDSETUP_XAPP", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWDSETUP_XAPP", pvar, uimsg);
734          SetDlgItemText(dlg, IDC_SSHFWDX11, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDX11, pvar->ts->UIMsg);
735          GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
736          UTIL_get_lang_msg("BTN_OK", pvar, uimsg);          UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
737          SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
738          GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
739          UTIL_get_lang_msg("BTN_CANCEL", pvar, uimsg);          UTIL_get_lang_msg("BTN_CANCEL", pvar, uimsg);
740          SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
741    
742          FWD_get_request_specs(pvar, requests, num_specs);          FWD_get_request_specs(pvar, requests, num_specs);
743    
744          for (i = 0; i < num_specs; i++) {          for (i = 0; i < num_specs; i++) {
745                  if (requests[i].type == FWD_REMOTE_X11_TO_LOCAL) {                  if (requests[i].type == FWD_REMOTE_X11_TO_LOCAL) {
746                          CheckDlgButton(dlg, IDC_SSHFWDX11, TRUE);                          CheckDlgButton(dlg, IDC_SSHFWDX11, TRUE);
747                  } else {                  } else {
748                          add_spec_to_listbox(dlg, requests + i, pvar);                          add_spec_to_listbox(dlg, requests + i, pvar);
749                  }                  }
750          }          }
751    
752          if (!pvar->settings.LocalForwardingIdentityCheck) {          if (!pvar->settings.LocalForwardingIdentityCheck) {
753                  CheckDlgButton(dlg, IDC_CHECKIDENTITY, TRUE);                  CheckDlgButton(dlg, IDC_CHECKIDENTITY, TRUE);
754          }          }
755    
756          free(requests);          free(requests);
757    
758          init_listbox_selection(dlg);          init_listbox_selection(dlg);
759  }  }
760    
761  static void free_listbox_spec(HWND listbox, int selection)  static void free_listbox_spec(HWND listbox, int selection)
762  {  {
763          FWDRequestSpec FAR *spec = (FWDRequestSpec FAR *)          FWDRequestSpec FAR *spec = (FWDRequestSpec FAR *)
764                  SendMessage(listbox, LB_GETITEMDATA, selection, 0);                  SendMessage(listbox, LB_GETITEMDATA, selection, 0);
765    
766          if (spec != NULL) {          if (spec != NULL) {
767                  free(spec);                  free(spec);
768          }          }
769  }  }
770    
771  static void free_all_listbox_specs(HWND dlg)  static void free_all_listbox_specs(HWND dlg)
772  {  {
773          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);
774          int i;          int i;
775    
776          for (i = SendMessage(listbox, LB_GETCOUNT, 0, 0) - 1; i >= 0; i--) {          for (i = SendMessage(listbox, LB_GETCOUNT, 0, 0) - 1; i >= 0; i--) {
777                  free_listbox_spec(listbox, i);                  free_listbox_spec(listbox, i);
778          }          }
779  }  }
780    
781  static BOOL end_fwd_dlg(PTInstVar pvar, HWND dlg)  static BOOL end_fwd_dlg(PTInstVar pvar, HWND dlg)
782  {  {
783          char buf[1024];          char buf[1024];
784          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);
785          int num_items = SendMessage(listbox, LB_GETCOUNT, 0, 0);          int num_items = SendMessage(listbox, LB_GETCOUNT, 0, 0);
786          BOOL X_enabled = IsDlgButtonChecked(dlg, IDC_SSHFWDX11);          BOOL X_enabled = IsDlgButtonChecked(dlg, IDC_SSHFWDX11);
787          int num_specs = X_enabled ? 1 : 0;          int num_specs = X_enabled ? 1 : 0;
788          FWDRequestSpec FAR *specs =          FWDRequestSpec FAR *specs =
789                  (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) *                  (FWDRequestSpec FAR *) malloc(sizeof(FWDRequestSpec) *
790                                                (num_specs + num_items));                                                (num_specs + num_items));
791          int i;          int i;
792          int num_unspecified_forwardings = 0;          int num_unspecified_forwardings = 0;
793    
794          for (i = 0; i < num_items; i++) {          for (i = 0; i < num_items; i++) {
795                  FWDRequestSpec FAR *spec = (FWDRequestSpec FAR *)                  FWDRequestSpec FAR *spec = (FWDRequestSpec FAR *)
796                          SendMessage(listbox, LB_GETITEMDATA, i, 0);                          SendMessage(listbox, LB_GETITEMDATA, i, 0);
797    
798                  if (spec != NULL) {                  if (spec != NULL) {
799                          specs[num_specs] = *spec;                          specs[num_specs] = *spec;
800                          num_specs++;                          num_specs++;
801                  }                  }
802          }          }
803    
804          if (X_enabled) {          if (X_enabled) {
805                  make_X_forwarding_spec(specs, pvar);                  make_X_forwarding_spec(specs, pvar);
806          }          }
807    
808          if (IsDlgButtonChecked(dlg, IDC_CHECKIDENTITY)) {          if (IsDlgButtonChecked(dlg, IDC_CHECKIDENTITY)) {
809                  pvar->settings.LocalForwardingIdentityCheck = FALSE;                  pvar->settings.LocalForwardingIdentityCheck = FALSE;
810          }          }
811          else {          else {
812                  pvar->settings.LocalForwardingIdentityCheck = TRUE;                  pvar->settings.LocalForwardingIdentityCheck = TRUE;
813          }          }
814    
815          qsort(specs, num_specs, sizeof(FWDRequestSpec), FWD_compare_specs);          qsort(specs, num_specs, sizeof(FWDRequestSpec), FWD_compare_specs);
816    
817          buf[0] = '\0';          buf[0] = '\0';
818          for (i = 0; i < num_specs; i++) {          for (i = 0; i < num_specs; i++) {
819                  if (i < num_specs - 1                  if (i < num_specs - 1
820                          && FWD_compare_specs(specs + i, specs + i + 1) == 0) {                          && FWD_compare_specs(specs + i, specs + i + 1) == 0) {
821                          switch (specs[i].type) {                          switch (specs[i].type) {
822                          case FWD_REMOTE_TO_LOCAL:                          case FWD_REMOTE_TO_LOCAL:
823                                  UTIL_get_lang_msg("MSG_SAME_SERVERPORT_ERROR", pvar,                                  UTIL_get_lang_msg("MSG_SAME_SERVERPORT_ERROR", pvar,
824                                                    "You cannot have two forwardings from the same server port (%d).");                                                    "You cannot have two forwardings from the same server port (%d).");
825                                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,                                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,
826                                              pvar->ts->UIMsg, specs[i].from_port);                                              pvar->ts->UIMsg, specs[i].from_port);
827                                  break;                                  break;
828                          case FWD_LOCAL_TO_REMOTE:                          case FWD_LOCAL_TO_REMOTE:
829                                  UTIL_get_lang_msg("MSG_SAME_LOCALPORT_ERROR", pvar,                                  UTIL_get_lang_msg("MSG_SAME_LOCALPORT_ERROR", pvar,
830                                                    "You cannot have two forwardings from the same local port (%d).");                                                    "You cannot have two forwardings from the same local port (%d).");
831                                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,                                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,
832                                              pvar->ts->UIMsg, specs[i].from_port);                                              pvar->ts->UIMsg, specs[i].from_port);
833                                  break;                                  break;
834                          }                          }
835                          notify_nonfatal_error(pvar, buf);                          notify_nonfatal_error(pvar, buf);
836    
837                          free(specs);                          free(specs);
838                          return FALSE;                          return FALSE;
839                  }                  }
840    
841                  if (specs[i].type != FWD_LOCAL_TO_REMOTE                  if (specs[i].type != FWD_LOCAL_TO_REMOTE
842                          && !FWD_can_server_listen_for(pvar, specs + i)) {                          && !FWD_can_server_listen_for(pvar, specs + i)) {
843                          num_unspecified_forwardings++;                          num_unspecified_forwardings++;
844                  }                  }
845          }          }
846    
847          if (num_unspecified_forwardings > 0) {          if (num_unspecified_forwardings > 0) {
848                  if (num_unspecified_forwardings > 1) {                  if (num_unspecified_forwardings > 1) {
849                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWDS_ERROR1", pvar,                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWDS_ERROR1", pvar,
850                                            "The following forwardings were not specified when this SSH session began:\n\n");                                            "The following forwardings were not specified when this SSH session began:\n\n");
851                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);
852                  } else {                  } else {
853                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWD_ERROR1", pvar,                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWD_ERROR1", pvar,
854                                            "The following forwarding was not specified when this SSH session began:\n\n");                                            "The following forwarding was not specified when this SSH session began:\n\n");
855                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);
856                  }                  }
857    
858                  for (i = 0; i < num_specs; i++) {                  for (i = 0; i < num_specs; i++) {
859                          if (specs[i].type != FWD_LOCAL_TO_REMOTE &&                          if (specs[i].type != FWD_LOCAL_TO_REMOTE &&
860                              !FWD_can_server_listen_for(pvar, specs + i)) {                              !FWD_can_server_listen_for(pvar, specs + i)) {
861                                  char buf2[1024];                                  char buf2[1024];
862    
863                                  get_spec_string(specs + i, buf2, sizeof(buf2), pvar);                                  get_spec_string(specs + i, buf2, sizeof(buf2), pvar);
864    
865                                  strncat_s(buf, sizeof(buf), buf2, _TRUNCATE);                                  strncat_s(buf, sizeof(buf), buf2, _TRUNCATE);
866                                  strncat_s(buf, sizeof(buf), "\n", _TRUNCATE);                                  strncat_s(buf, sizeof(buf), "\n", _TRUNCATE);
867                          }                          }
868                  }                  }
869    
870                  if (num_unspecified_forwardings > 1) {                  if (num_unspecified_forwardings > 1) {
871                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWDS_ERROR2", pvar,                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWDS_ERROR2", pvar,
872                                            "\nDue to a limitation of the SSH protocol, these forwardings will not work in the current SSH session.\n"                                            "\nDue to a limitation of the SSH protocol, these forwardings will not work in the current SSH session.\n"
873                                            "If you save these settings and start a new SSH session, the forwardings should work.");                                            "If you save these settings and start a new SSH session, the forwardings should work.");
874                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);
875                  } else {                  } else {
876                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWD_ERROR2", pvar,                          UTIL_get_lang_msg("MSG_UNSPECIFYIED_FWD_ERROR2", pvar,
877                                            "\nDue to a limitation of the SSH protocol, this forwarding will not work in the current SSH session.\n"                                            "\nDue to a limitation of the SSH protocol, this forwarding will not work in the current SSH session.\n"
878                                            "If you save these settings and start a new SSH session, the forwarding should work.");                                            "If you save these settings and start a new SSH session, the forwarding should work.");
879                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);                          strncat_s(buf, sizeof(buf), pvar->ts->UIMsg, _TRUNCATE);
880                  }                  }
881                  notify_nonfatal_error(pvar, buf);                  notify_nonfatal_error(pvar, buf);
882          }          }
883    
884          FWD_set_request_specs(pvar, specs, num_specs);          FWD_set_request_specs(pvar, specs, num_specs);
885          FWDUI_save_settings(pvar);          FWDUI_save_settings(pvar);
886          free_all_listbox_specs(dlg);          free_all_listbox_specs(dlg);
887          EndDialog(dlg, 1);          EndDialog(dlg, 1);
888    
889          free(specs);          free(specs);
890    
891          return TRUE;          return TRUE;
892  }  }
893    
894  static void fill_service_names(HWND dlg, WORD item)  static void fill_service_names(HWND dlg, WORD item)
895  {  {
896          HWND cbox = GetDlgItem(dlg, item);          HWND cbox = GetDlgItem(dlg, item);
897          int i;          int i;
898    
899          for (i = 0; i < NUM_ELEM(service_DB); i++) {          for (i = 0; i < NUM_ELEM(service_DB); i++) {
900                  SendMessage(cbox, CB_ADDSTRING, 0, (LPARAM) service_DB[i].name);                  SendMessage(cbox, CB_ADDSTRING, 0, (LPARAM) service_DB[i].name);
901          }          }
902  }  }
903    
904  static void shift_over_input(HWND dlg, int type, WORD rtl_item,  static void shift_over_input(HWND dlg, int type, WORD rtl_item,
905                                                           WORD ltr_item)                                                           WORD ltr_item)
906  {  {
907          HWND shift_from;          HWND shift_from;
908          HWND shift_to;          HWND shift_to;
909    
910          if (type == FWD_REMOTE_TO_LOCAL) {          if (type == FWD_REMOTE_TO_LOCAL) {
911                  shift_from = GetDlgItem(dlg, ltr_item);                  shift_from = GetDlgItem(dlg, ltr_item);
912                  shift_to = GetDlgItem(dlg, rtl_item);                  shift_to = GetDlgItem(dlg, rtl_item);
913          } else {          } else {
914                  shift_from = GetDlgItem(dlg, rtl_item);                  shift_from = GetDlgItem(dlg, rtl_item);
915                  shift_to = GetDlgItem(dlg, ltr_item);                  shift_to = GetDlgItem(dlg, ltr_item);
916          }          }
917    
918          EnableWindow(shift_from, FALSE);          EnableWindow(shift_from, FALSE);
919          EnableWindow(shift_to, TRUE);          EnableWindow(shift_to, TRUE);
920    
921          if (GetWindowTextLength(shift_to) == 0) {          if (GetWindowTextLength(shift_to) == 0) {
922                  char buf[128];                  char buf[128];
923    
924                  GetWindowText(shift_from, buf, sizeof(buf));                  GetWindowText(shift_from, buf, sizeof(buf));
925                  buf[sizeof(buf) - 1] = 0;                  buf[sizeof(buf) - 1] = 0;
926                  SetWindowText(shift_to, buf);                  SetWindowText(shift_to, buf);
927                  SetWindowText(shift_from, "");                  SetWindowText(shift_from, "");
928          }          }
929  }  }
930    
931  static void set_dir_options_status(HWND dlg)  static void set_dir_options_status(HWND dlg)
932  {  {
933          int type = IsDlgButtonChecked(dlg, IDC_SSHFWDREMOTETOLOCAL)          int type = IsDlgButtonChecked(dlg, IDC_SSHFWDREMOTETOLOCAL)
934                  ? FWD_REMOTE_TO_LOCAL : FWD_LOCAL_TO_REMOTE;                  ? FWD_REMOTE_TO_LOCAL : FWD_LOCAL_TO_REMOTE;
935    
936          shift_over_input(dlg, type, IDC_SSHRTLFROMPORT, IDC_SSHLTRFROMPORT);          shift_over_input(dlg, type, IDC_SSHRTLFROMPORT, IDC_SSHLTRFROMPORT);
937          shift_over_input(dlg, type, IDC_SSHRTLTOHOST, IDC_SSHLTRTOHOST);          shift_over_input(dlg, type, IDC_SSHRTLTOHOST, IDC_SSHLTRTOHOST);
938          shift_over_input(dlg, type, IDC_SSHRTLTOPORT, IDC_SSHLTRTOPORT);          shift_over_input(dlg, type, IDC_SSHRTLTOPORT, IDC_SSHLTRTOPORT);
939    
940          if (IsDlgButtonChecked(GetParent(dlg),IDC_CHECKIDENTITY)) {          if (IsDlgButtonChecked(GetParent(dlg),IDC_CHECKIDENTITY)) {
941                  if (type == FWD_LOCAL_TO_REMOTE) {                  if (type == FWD_LOCAL_TO_REMOTE) {
942                          EnableWindow(GetDlgItem(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY), TRUE);                          EnableWindow(GetDlgItem(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY), TRUE);
943                  }                  }
944                  else {                  else {
945                          EnableWindow(GetDlgItem(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY), FALSE);                          EnableWindow(GetDlgItem(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY), FALSE);
946                  }                  }
947          }          }
948  }  }
949    
950  static void setup_edit_controls(HWND dlg, FWDRequestSpec FAR * spec,  static void setup_edit_controls(HWND dlg, FWDRequestSpec FAR * spec,
951                                  WORD radio_item, WORD from_port_item,                                  WORD radio_item, WORD from_port_item,
952                                  WORD to_host_item, WORD to_port_item)                                  WORD to_host_item, WORD to_port_item)
953  {  {
954          CheckDlgButton(dlg, radio_item, TRUE);          CheckDlgButton(dlg, radio_item, TRUE);
955          SetFocus(GetDlgItem(dlg, radio_item));          SetFocus(GetDlgItem(dlg, radio_item));
956          SetDlgItemText(dlg, from_port_item, spec->from_port_name);          SetDlgItemText(dlg, from_port_item, spec->from_port_name);
957          SetDlgItemText(dlg, to_port_item, spec->to_port_name);          SetDlgItemText(dlg, to_port_item, spec->to_port_name);
958          if (strcmp(spec->to_host, "localhost") != 0) {          if (strcmp(spec->to_host, "localhost") != 0) {
959                  SetDlgItemText(dlg, to_host_item, spec->to_host);                  SetDlgItemText(dlg, to_host_item, spec->to_host);
960          }          }
961    
962          set_dir_options_status(dlg);          set_dir_options_status(dlg);
963  }  }
964    
965  static void init_fwd_edit_dlg(PTInstVar pvar, FWDRequestSpec FAR * spec, HWND dlg)  static void init_fwd_edit_dlg(PTInstVar pvar, FWDRequestSpec FAR * spec, HWND dlg)
966  {  {
967          char uimsg[MAX_UIMSG];          char uimsg[MAX_UIMSG];
968    
969          GetWindowText(dlg, uimsg, sizeof(uimsg));          GetWindowText(dlg, uimsg, sizeof(uimsg));
970          UTIL_get_lang_msg("DLG_FWD_TITLE", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_TITLE", pvar, uimsg);
971          SetWindowText(dlg, pvar->ts->UIMsg);          SetWindowText(dlg, pvar->ts->UIMsg);
972          GetDlgItemText(dlg, IDD_SSHFWDBANNER, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDD_SSHFWDBANNER, uimsg, sizeof(uimsg));
973          UTIL_get_lang_msg("DLG_FWD_BANNER", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_BANNER", pvar, uimsg);
974          SetDlgItemText(dlg, IDD_SSHFWDBANNER, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDD_SSHFWDBANNER, pvar->ts->UIMsg);
975          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE, uimsg, sizeof(uimsg));
976          UTIL_get_lang_msg("DLG_FWD_LOCAL_PORT", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_LOCAL_PORT", pvar, uimsg);
977          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE, pvar->ts->UIMsg);
978          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_HOST, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_HOST, uimsg, sizeof(uimsg));
979          UTIL_get_lang_msg("DLG_FWD_LOCAL_REMOTE", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_LOCAL_REMOTE", pvar, uimsg);
980          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_HOST, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_HOST, pvar->ts->UIMsg);
981          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_PORT, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_PORT, uimsg, sizeof(uimsg));
982          UTIL_get_lang_msg("DLG_FWD_LOCAL_REMOTE_PORT", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_LOCAL_REMOTE_PORT", pvar, uimsg);
983          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_PORT, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_PORT, pvar->ts->UIMsg);
984          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, uimsg, sizeof(uimsg));
985          UTIL_get_lang_msg("DLG_FWD_LOCAL_CHECKIDENTITY", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_LOCAL_CHECKIDENTITY", pvar, uimsg);
986          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, pvar->ts->UIMsg);
987          GetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL, uimsg, sizeof(uimsg));
988          UTIL_get_lang_msg("DLG_FWD_REMOTE_PORT", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_REMOTE_PORT", pvar, uimsg);
989          SetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL, pvar->ts->UIMsg);
990          GetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_HOST, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_HOST, uimsg, sizeof(uimsg));
991          UTIL_get_lang_msg("DLG_FWD_REMOTE_LOCAL", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_REMOTE_LOCAL", pvar, uimsg);
992          SetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_HOST, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_HOST, pvar->ts->UIMsg);
993          GetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_PORT, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_PORT, uimsg, sizeof(uimsg));
994          UTIL_get_lang_msg("DLG_FWD_REMOTE_LOCAL_PORT", pvar, uimsg);          UTIL_get_lang_msg("DLG_FWD_REMOTE_LOCAL_PORT", pvar, uimsg);
995          SetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_PORT, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDC_SSHFWDREMOTETOLOCAL_PORT, pvar->ts->UIMsg);
996          GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDOK, uimsg, sizeof(uimsg));
997          UTIL_get_lang_msg("BTN_OK", pvar, uimsg);          UTIL_get_lang_msg("BTN_OK", pvar, uimsg);
998          SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDOK, pvar->ts->UIMsg);
999          GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));          GetDlgItemText(dlg, IDCANCEL, uimsg, sizeof(uimsg));
1000          UTIL_get_lang_msg("BTN_CANCEL", pvar, uimsg);          UTIL_get_lang_msg("BTN_CANCEL", pvar, uimsg);
1001          SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);          SetDlgItemText(dlg, IDCANCEL, pvar->ts->UIMsg);
1002    
1003          switch (spec->type) {          switch (spec->type) {
1004          case FWD_REMOTE_TO_LOCAL:          case FWD_REMOTE_TO_LOCAL:
1005                  setup_edit_controls(dlg, spec, IDC_SSHFWDREMOTETOLOCAL,                  setup_edit_controls(dlg, spec, IDC_SSHFWDREMOTETOLOCAL,
1006                                      IDC_SSHRTLFROMPORT, IDC_SSHRTLTOHOST,                                      IDC_SSHRTLFROMPORT, IDC_SSHRTLTOHOST,
1007                                      IDC_SSHRTLTOPORT);                                      IDC_SSHRTLTOPORT);
1008                  break;                  break;
1009          case FWD_LOCAL_TO_REMOTE:          case FWD_LOCAL_TO_REMOTE:
1010                  setup_edit_controls(dlg, spec, IDC_SSHFWDLOCALTOREMOTE,                  setup_edit_controls(dlg, spec, IDC_SSHFWDLOCALTOREMOTE,
1011                                      IDC_SSHLTRFROMPORT, IDC_SSHLTRTOHOST,                                      IDC_SSHLTRFROMPORT, IDC_SSHLTRTOHOST,
1012                                      IDC_SSHLTRTOPORT);                                      IDC_SSHLTRTOPORT);
1013                  if (!spec->check_identity) {                  if (!spec->check_identity) {
1014                          CheckDlgButton(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, TRUE);                          CheckDlgButton(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, TRUE);
1015                  }                  }
1016                  break;                  break;
1017          }          }
1018    
1019          if (!IsDlgButtonChecked(GetParent(dlg),IDC_CHECKIDENTITY)) {          if (!IsDlgButtonChecked(GetParent(dlg),IDC_CHECKIDENTITY)) {
1020                  CheckDlgButton(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, FALSE);                  CheckDlgButton(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, FALSE);
1021                  EnableWindow(GetDlgItem(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY), FALSE);                  EnableWindow(GetDlgItem(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY), FALSE);
1022          }          }
1023    
1024          fill_service_names(dlg, IDC_SSHRTLFROMPORT);          fill_service_names(dlg, IDC_SSHRTLFROMPORT);
1025          fill_service_names(dlg, IDC_SSHLTRFROMPORT);          fill_service_names(dlg, IDC_SSHLTRFROMPORT);
1026          fill_service_names(dlg, IDC_SSHRTLTOPORT);          fill_service_names(dlg, IDC_SSHRTLTOPORT);
1027          fill_service_names(dlg, IDC_SSHLTRTOPORT);          fill_service_names(dlg, IDC_SSHLTRTOPORT);
1028  }  }
1029    
1030  static void grab_control_text(HWND dlg, int type, WORD rtl_item,  static void grab_control_text(HWND dlg, int type, WORD rtl_item,
1031                                WORD ltr_item, char FAR * buf, int bufsize)                                WORD ltr_item, char FAR * buf, int bufsize)
1032  {  {
1033          GetDlgItemText(dlg, type == FWD_REMOTE_TO_LOCAL ? rtl_item : ltr_item,          GetDlgItemText(dlg, type == FWD_REMOTE_TO_LOCAL ? rtl_item : ltr_item,
1034                         buf, bufsize);                         buf, bufsize);
1035          buf[bufsize - 1] = 0;          buf[bufsize - 1] = 0;
1036  }  }
1037    
1038  static BOOL end_fwd_edit_dlg(PTInstVar pvar, FWDRequestSpec FAR * spec,  static BOOL end_fwd_edit_dlg(PTInstVar pvar, FWDRequestSpec FAR * spec,
1039                               HWND dlg)                               HWND dlg)
1040  {  {
1041          FWDRequestSpec new_spec;          FWDRequestSpec new_spec;
1042          int type = IsDlgButtonChecked(dlg, IDC_SSHFWDREMOTETOLOCAL)          int type = IsDlgButtonChecked(dlg, IDC_SSHFWDREMOTETOLOCAL)
1043                  ? FWD_REMOTE_TO_LOCAL : FWD_LOCAL_TO_REMOTE;                  ? FWD_REMOTE_TO_LOCAL : FWD_LOCAL_TO_REMOTE;
1044          char buf[1024];          char buf[1024];
1045    
1046          new_spec.type = type;          new_spec.type = type;
1047          grab_control_text(dlg, type, IDC_SSHRTLFROMPORT, IDC_SSHLTRFROMPORT,          grab_control_text(dlg, type, IDC_SSHRTLFROMPORT, IDC_SSHLTRFROMPORT,
1048                            new_spec.from_port_name,                            new_spec.from_port_name,
1049                            sizeof(new_spec.from_port_name));                            sizeof(new_spec.from_port_name));
1050          grab_control_text(dlg, type, IDC_SSHRTLTOHOST, IDC_SSHLTRTOHOST,          grab_control_text(dlg, type, IDC_SSHRTLTOHOST, IDC_SSHLTRTOHOST,
1051                            new_spec.to_host, sizeof(new_spec.to_host));                            new_spec.to_host, sizeof(new_spec.to_host));
1052          if (new_spec.to_host[0] == 0) {          if (new_spec.to_host[0] == 0) {
1053                  strncpy_s(new_spec.to_host, sizeof(new_spec.to_host), "localhost", _TRUNCATE);                  strncpy_s(new_spec.to_host, sizeof(new_spec.to_host), "localhost", _TRUNCATE);
1054          }          }
1055          grab_control_text(dlg, type, IDC_SSHRTLTOPORT, IDC_SSHLTRTOPORT,          grab_control_text(dlg, type, IDC_SSHRTLTOPORT, IDC_SSHLTRTOPORT,
1056                            new_spec.to_port_name,                            new_spec.to_port_name,
1057                            sizeof(new_spec.to_port_name));                            sizeof(new_spec.to_port_name));
1058    
1059          new_spec.from_port = parse_port_from_buf(new_spec.from_port_name);          new_spec.from_port = parse_port_from_buf(new_spec.from_port_name);
1060          if (new_spec.from_port < 0) {          if (new_spec.from_port < 0) {
1061                  UTIL_get_lang_msg("MSG_INVALID_PORT_ERROR", pvar,                  UTIL_get_lang_msg("MSG_INVALID_PORT_ERROR", pvar,
1062                                    "Port \"%s\" is not a valid port number.\n"                                    "Port \"%s\" is not a valid port number.\n"
1063                                    "Either choose a port name from the list, or enter a number between 1 and 65535.");                                    "Either choose a port name from the list, or enter a number between 1 and 65535.");
1064                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,
1065                              pvar->ts->UIMsg, new_spec.to_port_name);                              pvar->ts->UIMsg, new_spec.to_port_name);
1066                  notify_nonfatal_error(pvar, buf);                  notify_nonfatal_error(pvar, buf);
1067                  return FALSE;                  return FALSE;
1068          }          }
1069    
1070          new_spec.to_port = parse_port_from_buf(new_spec.to_port_name);          new_spec.to_port = parse_port_from_buf(new_spec.to_port_name);
1071          if (new_spec.to_port < 0) {          if (new_spec.to_port < 0) {
1072                  UTIL_get_lang_msg("MSG_INVALID_PORT_ERROR", pvar,                  UTIL_get_lang_msg("MSG_INVALID_PORT_ERROR", pvar,
1073                                    "Port \"%s\" is not a valid port number.\n"                                    "Port \"%s\" is not a valid port number.\n"
1074                                    "Either choose a port name from the list, or enter a number between 1 and 65535.");                                    "Either choose a port name from the list, or enter a number between 1 and 65535.");
1075                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,                  _snprintf_s(buf, sizeof(buf), _TRUNCATE,
1076                              pvar->ts->UIMsg, new_spec.to_port_name);                              pvar->ts->UIMsg, new_spec.to_port_name);
1077                  notify_nonfatal_error(pvar, buf);                  notify_nonfatal_error(pvar, buf);
1078                  return FALSE;                  return FALSE;
1079          }          }
1080    
1081          new_spec.check_identity = TRUE;          new_spec.check_identity = TRUE;
1082          if (type == FWD_LOCAL_TO_REMOTE) {          if (type == FWD_LOCAL_TO_REMOTE) {
1083                  if (IsDlgButtonChecked(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY)) {                  if (IsDlgButtonChecked(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY)) {
1084                          new_spec.check_identity = FALSE;                          new_spec.check_identity = FALSE;
1085                  }                  }
1086          }          }
1087    
1088          *spec = new_spec;          *spec = new_spec;
1089    
1090          EndDialog(dlg, 1);          EndDialog(dlg, 1);
1091          return TRUE;          return TRUE;
1092  }  }
1093    
1094  static BOOL CALLBACK fwd_edit_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,  static BOOL CALLBACK fwd_edit_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1095                                         LPARAM lParam)                                         LPARAM lParam)
1096  {  {
1097          FWDEditClosure FAR *closure;          FWDEditClosure FAR *closure;
1098          PTInstVar pvar;          PTInstVar pvar;
1099          LOGFONT logfont;          LOGFONT logfont;
1100          HFONT font;          HFONT font;
1101    
1102          switch (msg) {          switch (msg) {
1103          case WM_INITDIALOG:          case WM_INITDIALOG:
1104                  closure = (FWDEditClosure FAR *) lParam;                  closure = (FWDEditClosure FAR *) lParam;
1105                  SetWindowLong(dlg, DWL_USER, lParam);                  SetWindowLong(dlg, DWL_USER, lParam);
1106    
1107                  pvar = closure->pvar;                  pvar = closure->pvar;
1108                  init_fwd_edit_dlg(pvar, closure->spec, dlg);                  init_fwd_edit_dlg(pvar, closure->spec, dlg);
1109    
1110                  font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);                  font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);
1111                  GetObject(font, sizeof(LOGFONT), &logfont);                  GetObject(font, sizeof(LOGFONT), &logfont);
1112                  if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgFwdEditFont, pvar)) {                  if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgFwdEditFont, pvar)) {
1113                          SendDlgItemMessage(dlg, IDD_SSHFWDBANNER, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDD_SSHFWDBANNER, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1114                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1115                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE_HOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE_HOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1116                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE_PORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE_PORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1117                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDLOCALTOREMOTE_CHECKIDENTITY, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1118                          SendDlgItemMessage(dlg, IDC_SSHFWDREMOTETOLOCAL, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDREMOTETOLOCAL, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1119                          SendDlgItemMessage(dlg, IDC_SSHFWDREMOTETOLOCAL_HOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDREMOTETOLOCAL_HOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1120                          SendDlgItemMessage(dlg, IDC_SSHFWDREMOTETOLOCAL_PORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDREMOTETOLOCAL_PORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1121                          SendDlgItemMessage(dlg, IDC_SSHLTRFROMPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHLTRFROMPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1122                          SendDlgItemMessage(dlg, IDC_SSHLTRTOHOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHLTRTOHOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1123                          SendDlgItemMessage(dlg, IDC_SSHLTRTOPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHLTRTOPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1124                          SendDlgItemMessage(dlg, IDC_SSHRTLFROMPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHRTLFROMPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1125                          SendDlgItemMessage(dlg, IDC_SSHRTLTOHOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHRTLTOHOST, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1126                          SendDlgItemMessage(dlg, IDC_SSHRTLTOPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHRTLTOPORT, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1127                          SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1128                          SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgFwdEditFont, MAKELPARAM(TRUE,0));
1129                  }                  }
1130                  else {                  else {
1131                          DlgFwdEditFont = NULL;                          DlgFwdEditFont = NULL;
1132                  }                  }
1133                  return FALSE;                   /* because we set the focus */                  return FALSE;                   /* because we set the focus */
1134    
1135          case WM_COMMAND:          case WM_COMMAND:
1136                  closure = (FWDEditClosure FAR *) GetWindowLong(dlg, DWL_USER);                  closure = (FWDEditClosure FAR *) GetWindowLong(dlg, DWL_USER);
1137    
1138                  switch (LOWORD(wParam)) {                  switch (LOWORD(wParam)) {
1139                  case IDOK:                  case IDOK:
1140    
1141                          if (DlgFwdEditFont != NULL) {                          if (DlgFwdEditFont != NULL) {
1142                                  DeleteObject(DlgFwdEditFont);                                  DeleteObject(DlgFwdEditFont);
1143                          }                          }
1144    
1145                          return end_fwd_edit_dlg(closure->pvar, closure->spec, dlg);                          return end_fwd_edit_dlg(closure->pvar, closure->spec, dlg);
1146    
1147                  case IDCANCEL:                  case IDCANCEL:
1148                          EndDialog(dlg, 0);                          EndDialog(dlg, 0);
1149    
1150                          if (DlgFwdEditFont != NULL) {                          if (DlgFwdEditFont != NULL) {
1151                                  DeleteObject(DlgFwdEditFont);                                  DeleteObject(DlgFwdEditFont);
1152                          }                          }
1153    
1154                          return TRUE;                          return TRUE;
1155    
1156                  case IDC_SSHFWDLOCALTOREMOTE:                  case IDC_SSHFWDLOCALTOREMOTE:
1157                  case IDC_SSHFWDREMOTETOLOCAL:                  case IDC_SSHFWDREMOTETOLOCAL:
1158                          set_dir_options_status(dlg);                          set_dir_options_status(dlg);
1159                          return TRUE;                          return TRUE;
1160    
1161                  default:                  default:
1162                          return FALSE;                          return FALSE;
1163                  }                  }
1164    
1165          default:          default:
1166                  return FALSE;                  return FALSE;
1167          }          }
1168  }  }
1169    
1170  static void add_forwarding_entry(PTInstVar pvar, HWND dlg)  static void add_forwarding_entry(PTInstVar pvar, HWND dlg)
1171  {  {
1172          FWDRequestSpec new_spec;          FWDRequestSpec new_spec;
1173          int result;          int result;
1174          FWDEditClosure closure = { &new_spec, pvar };          FWDEditClosure closure = { &new_spec, pvar };
1175    
1176          new_spec.type = FWD_LOCAL_TO_REMOTE;          new_spec.type = FWD_LOCAL_TO_REMOTE;
1177          new_spec.from_port_name[0] = 0;          new_spec.from_port_name[0] = 0;
1178          new_spec.to_host[0] = 0;          new_spec.to_host[0] = 0;
1179          new_spec.to_port_name[0] = 0;          new_spec.to_port_name[0] = 0;
1180          new_spec.check_identity = 1;          new_spec.check_identity = 1;
1181    
1182          result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHFWDEDIT),          result = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHFWDEDIT),
1183                                  dlg, fwd_edit_dlg_proc, (LPARAM) & closure);                                  dlg, fwd_edit_dlg_proc, (LPARAM) & closure);
1184    
1185          if (result == -1) {          if (result == -1) {
1186                  UTIL_get_lang_msg("MSG_CREATEWINDOW_FWDEDIT_ERROR", pvar,                  UTIL_get_lang_msg("MSG_CREATEWINDOW_FWDEDIT_ERROR", pvar,
1187                                    "Unable to display forwarding edit dialog box.");                                    "Unable to display forwarding edit dialog box.");
1188                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1189          } else if (result) {          } else if (result) {
1190                  int index = add_spec_to_listbox(dlg, &new_spec, pvar);                  int index = add_spec_to_listbox(dlg, &new_spec, pvar);
1191    
1192                  if (index >= 0) {                  if (index >= 0) {
1193                          SendMessage(GetDlgItem(dlg, IDC_SSHFWDLIST), LB_SETCURSEL,                          SendMessage(GetDlgItem(dlg, IDC_SSHFWDLIST), LB_SETCURSEL,
1194                                      index, 0);                                      index, 0);
1195                  }                  }
1196                  update_listbox_selection(dlg);                  update_listbox_selection(dlg);
1197          }          }
1198  }  }
1199    
1200  static void edit_forwarding_entry(PTInstVar pvar, HWND dlg)  static void edit_forwarding_entry(PTInstVar pvar, HWND dlg)
1201  {  {
1202          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);
1203          int cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0);          int cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0);
1204    
1205          if (cursel >= 0) {          if (cursel >= 0) {
1206                  FWDRequestSpec FAR *spec = (FWDRequestSpec FAR *)                  FWDRequestSpec FAR *spec = (FWDRequestSpec FAR *)
1207                          SendMessage(listbox, LB_GETITEMDATA, cursel, 0);                          SendMessage(listbox, LB_GETITEMDATA, cursel, 0);
1208    
1209                  if (spec != NULL) {                  if (spec != NULL) {
1210                          FWDEditClosure closure = { spec, pvar };                          FWDEditClosure closure = { spec, pvar };
1211    
1212                          int result =                          int result =
1213                                  DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHFWDEDIT),                                  DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHFWDEDIT),
1214                                                 dlg, fwd_edit_dlg_proc, (LPARAM) & closure);                                                 dlg, fwd_edit_dlg_proc, (LPARAM) & closure);
1215    
1216                          if (result == -1) {                          if (result == -1) {
1217                                  UTIL_get_lang_msg("MSG_CREATEWINDOW_FWDEDIT_ERROR", pvar,                                  UTIL_get_lang_msg("MSG_CREATEWINDOW_FWDEDIT_ERROR", pvar,
1218                                                    "Unable to display forwarding edit dialog box.");                                                    "Unable to display forwarding edit dialog box.");
1219                                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);                                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1220                          } else if (result) {                          } else if (result) {
1221                                  SendMessage(listbox, LB_DELETESTRING, cursel, 0);                                  SendMessage(listbox, LB_DELETESTRING, cursel, 0);
1222    
1223                                  cursel = add_spec_to_listbox(dlg, spec, pvar);                                  cursel = add_spec_to_listbox(dlg, spec, pvar);
1224                                  free(spec);                                  free(spec);
1225                                  if (cursel >= 0) {                                  if (cursel >= 0) {
1226                                          SendMessage(GetDlgItem(dlg, IDC_SSHFWDLIST),                                          SendMessage(GetDlgItem(dlg, IDC_SSHFWDLIST),
1227                                                      LB_SETCURSEL, cursel, 0);                                                      LB_SETCURSEL, cursel, 0);
1228                                  }                                  }
1229                                  update_listbox_selection(dlg);                                  update_listbox_selection(dlg);
1230                          }                          }
1231                  }                  }
1232          }          }
1233  }  }
1234    
1235  static void remove_forwarding_entry(HWND dlg)  static void remove_forwarding_entry(HWND dlg)
1236  {  {
1237          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);          HWND listbox = GetDlgItem(dlg, IDC_SSHFWDLIST);
1238          int cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0);          int cursel = SendMessage(listbox, LB_GETCURSEL, 0, 0);
1239    
1240          if (cursel >= 0) {          if (cursel >= 0) {
1241                  free_listbox_spec(listbox, cursel);                  free_listbox_spec(listbox, cursel);
1242                  SendMessage(listbox, LB_DELETESTRING, cursel, 0);                  SendMessage(listbox, LB_DELETESTRING, cursel, 0);
1243                  init_listbox_selection(dlg);                  init_listbox_selection(dlg);
1244          }          }
1245  }  }
1246    
1247  static BOOL CALLBACK fwd_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,  static BOOL CALLBACK fwd_dlg_proc(HWND dlg, UINT msg, WPARAM wParam,
1248                                    LPARAM lParam)                                    LPARAM lParam)
1249  {  {
1250          PTInstVar pvar;          PTInstVar pvar;
1251          LOGFONT logfont;          LOGFONT logfont;
1252          HFONT font;          HFONT font;
1253    
1254          switch (msg) {          switch (msg) {
1255          case WM_INITDIALOG:          case WM_INITDIALOG:
1256                  pvar = (PTInstVar) lParam;                  pvar = (PTInstVar) lParam;
1257                  SetWindowLong(dlg, DWL_USER, lParam);                  SetWindowLong(dlg, DWL_USER, lParam);
1258    
1259                  init_fwd_dlg(pvar, dlg);                  init_fwd_dlg(pvar, dlg);
1260    
1261                  font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);                  font = (HFONT)SendMessage(dlg, WM_GETFONT, 0, 0);
1262                  GetObject(font, sizeof(LOGFONT), &logfont);                  GetObject(font, sizeof(LOGFONT), &logfont);
1263                  if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgFwdFont, pvar)) {                  if (UTIL_get_lang_font("DLG_TAHOMA_FONT", dlg, &logfont, &DlgFwdFont, pvar)) {
1264                          SendDlgItemMessage(dlg, IDC_PORTFORWARD, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_PORTFORWARD, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1265                          SendDlgItemMessage(dlg, IDC_SSHFWDLIST, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDLIST, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1266                          SendDlgItemMessage(dlg, IDC_ADD, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_ADD, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1267                          SendDlgItemMessage(dlg, IDC_EDIT, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_EDIT, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1268                          SendDlgItemMessage(dlg, IDC_REMOVE, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_REMOVE, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1269                          SendDlgItemMessage(dlg, IDC_CHECKIDENTITY, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_CHECKIDENTITY, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1270                          SendDlgItemMessage(dlg, IDC_XFORWARD, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_XFORWARD, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1271                          SendDlgItemMessage(dlg, IDC_SSHFWDX11, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDC_SSHFWDX11, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1272                          SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDOK, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1273                          SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));                          SendDlgItemMessage(dlg, IDCANCEL, WM_SETFONT, (WPARAM)DlgFwdFont, MAKELPARAM(TRUE,0));
1274                  }                  }
1275                  else {                  else {
1276                          DlgFwdFont = NULL;                          DlgFwdFont = NULL;
1277                  }                  }
1278    
1279                  return TRUE;                    /* because we do not set the focus */                  return TRUE;                    /* because we do not set the focus */
1280    
1281          case WM_COMMAND:          case WM_COMMAND:
1282                  pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);                  pvar = (PTInstVar) GetWindowLong(dlg, DWL_USER);
1283    
1284                  switch (LOWORD(wParam)) {                  switch (LOWORD(wParam)) {
1285                  case IDOK:                  case IDOK:
1286    
1287                          if (DlgFwdFont != NULL) {                          if (DlgFwdFont != NULL) {
1288                                  DeleteObject(DlgFwdFont);                                  DeleteObject(DlgFwdFont);
1289                          }                          }
1290    
1291                          return end_fwd_dlg(pvar, dlg);                          return end_fwd_dlg(pvar, dlg);
1292    
1293                  case IDCANCEL:                  case IDCANCEL:
1294                          free_all_listbox_specs(dlg);                          free_all_listbox_specs(dlg);
1295                          EndDialog(dlg, 0);                          EndDialog(dlg, 0);
1296    
1297                          if (DlgFwdFont != NULL) {                          if (DlgFwdFont != NULL) {
1298                                  DeleteObject(DlgFwdFont);                                  DeleteObject(DlgFwdFont);
1299                          }                          }
1300    
1301                          return TRUE;                          return TRUE;
1302    
1303                  case IDC_ADD:                  case IDC_ADD:
1304                          add_forwarding_entry(pvar, dlg);                          add_forwarding_entry(pvar, dlg);
1305                          return TRUE;                          return TRUE;
1306    
1307                  case IDC_EDIT:                  case IDC_EDIT:
1308                          edit_forwarding_entry(pvar, dlg);                          edit_forwarding_entry(pvar, dlg);
1309                          return TRUE;                          return TRUE;
1310    
1311                  case IDC_REMOVE:                  case IDC_REMOVE:
1312                          remove_forwarding_entry(dlg);                          remove_forwarding_entry(dlg);
1313                          return TRUE;                          return TRUE;
1314    
1315                  case IDC_SSHFWDLIST:                  case IDC_SSHFWDLIST:
1316                          update_listbox_selection(dlg);                          update_listbox_selection(dlg);
1317                          return TRUE;                          return TRUE;
1318    
1319                  default:                  default:
1320                          return FALSE;                          return FALSE;
1321                  }                  }
1322    
1323          default:          default:
1324                  return FALSE;                  return FALSE;
1325          }          }
1326  }  }
1327    
1328  void FWDUI_do_forwarding_dialog(PTInstVar pvar)  void FWDUI_do_forwarding_dialog(PTInstVar pvar)
1329  {  {
1330          HWND cur_active = GetActiveWindow();          HWND cur_active = GetActiveWindow();
1331    
1332          if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHFWDSETUP),          if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SSHFWDSETUP),
1333                                 cur_active != NULL ? cur_active                                 cur_active != NULL ? cur_active
1334                                                    : pvar->NotificationWindow,                                                    : pvar->NotificationWindow,
1335                                 fwd_dlg_proc, (LPARAM) pvar) == -1) {                                 fwd_dlg_proc, (LPARAM) pvar) == -1) {
1336                  UTIL_get_lang_msg("MSG_CREATEWINDOW_FWDSETUP_ERROR", pvar,                  UTIL_get_lang_msg("MSG_CREATEWINDOW_FWDSETUP_ERROR", pvar,
1337                                    "Unable to display forwarding setup dialog box.");                                    "Unable to display forwarding setup dialog box.");
1338                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);                  notify_nonfatal_error(pvar, pvar->ts->UIMsg);
1339          }          }
1340  }  }

Legend:
Removed from v.3226  
changed lines
  Added in v.3227

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