]>
git.saurik.com Git - apple/network_cmds.git/blob - telnet.tproj/tn3270.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright (c) 1988, 1993
26 * The Regents of the University of California. All rights reserved.
28 * Redistribution and use in source and binary forms, with or without
29 * modification, are permitted provided that the following conditions
31 * 1. Redistributions of source code must retain the above copyright
32 * notice, this list of conditions and the following disclaimer.
33 * 2. Redistributions in binary form must reproduce the above copyright
34 * notice, this list of conditions and the following disclaimer in the
35 * documentation and/or other materials provided with the distribution.
36 * 3. All advertising materials mentioning features or use of this software
37 * must display the following acknowledgement:
38 * This product includes software developed by the University of
39 * California, Berkeley and its contributors.
40 * 4. Neither the name of the University nor the names of its contributors
41 * may be used to endorse or promote products derived from this software
42 * without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 static char sccsid
[] = "@(#)tn3270.c 8.2 (Berkeley) 5/30/95";
61 #include <sys/types.h>
62 #include <arpa/telnet.h>
73 #include "../ctlr/screen.h"
74 #include "../general/globals.h"
76 #include "../sys_curses/telextrn.h"
77 #include "../ctlr/externs.h"
79 #if defined(unix) || defined(__APPLE__)
81 HaveInput
, /* There is input available to scan */
82 cursesdata
, /* Do we dump curses data? */
83 sigiocount
; /* Number of times we got a SIGIO */
86 char *transcom
= 0; /* transparent mode command (default: none) */
87 #endif /* defined(unix) || defined(__APPLE__) */
89 char Ibuf
[8*BUFSIZ
], *Ifrontp
, *Ibackp
;
91 static char sb_terminal
[] = { IAC
, SB
,
92 TELOPT_TTYPE
, TELQUAL_IS
,
93 'I', 'B', 'M', '-', '3', '2', '7', '8', '-', '2',
95 #define SBTERMMODEL 13
98 Sent3270TerminalType
; /* Have we said we are a 3270? */
100 #endif /* defined(TN3270) */
107 #if defined(unix) || defined(__APPLE__)
110 #endif /* defined(unix) || defined(__APPLE__) */
111 Sent3270TerminalType
= 0;
112 Ifrontp
= Ibackp
= Ibuf
;
113 init_ctlr(); /* Initialize some things */
117 #endif /* defined(TN3270) */
124 * DataToNetwork - queue up some data to go to network. If "done" is set,
125 * then when last byte is queued, we add on an IAC EOR sequence (so,
126 * don't call us with "done" until you want that done...)
128 * We actually do send all the data to the network buffer, since our
129 * only client needs for us to do that.
133 DataToNetwork(buffer
, count
, done
)
134 register char *buffer
; /* where the data is */
135 register int count
; /* how much to send */
136 int done
; /* is this the last of a logical block */
138 register int loop
, c
;
144 /* If not enough room for EORs, IACs, etc., wait */
150 while (NETROOM() < 6) {
152 (void) select(net
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
153 (struct timeval
*) 0);
157 c
= ring_empty_count(&netoring
);
163 if (((unsigned char)*buffer
) == IAC
) {
170 ring_supply_data(&netoring
, buffer
-c
, c
);
182 netflush(); /* try to move along as quickly as ... */
184 return(origCount
- count
);
188 #if defined(unix) || defined(__APPLE__)
190 inputAvailable(signo
)
196 #endif /* defined(unix) || defined(__APPLE__) */
206 * The following routines are places where the various tn3270
207 * routines make calls into telnet.c.
211 * DataToTerminal - queue up some data to go to terminal.
213 * Note: there are people who call us and depend on our processing
214 * *all* the data at one time (thus the select).
218 DataToTerminal(buffer
, count
)
219 register char *buffer
; /* where the data is */
220 register int count
; /* how much to send */
228 if (TTYROOM() == 0) {
229 #if defined(unix) || defined(__APPLE__)
233 #endif /* defined(unix) || defined(__APPLE__) */
235 while (TTYROOM() == 0) {
236 #if defined(unix) || defined(__APPLE__)
238 (void) select(tout
+1, (fd_set
*) 0, &o
, (fd_set
*) 0,
239 (struct timeval
*) 0);
240 #endif /* defined(unix) || defined(__APPLE__) */
248 ring_supply_data(&ttyoring
, buffer
, c
);
257 * Push3270 - Try to send data along the 3270 output (to screen) direction.
263 int save
= ring_full_count(&netiring
);
266 if (Ifrontp
+save
> Ibuf
+sizeof Ibuf
) {
267 if (Ibackp
!= Ibuf
) {
268 memmove(Ibuf
, Ibackp
, Ifrontp
-Ibackp
);
269 Ifrontp
-= (Ibackp
-Ibuf
);
273 if (Ifrontp
+save
< Ibuf
+sizeof Ibuf
) {
277 return save
!= ring_full_count(&netiring
);
282 * Finish3270 - get the last dregs of 3270 data out to the terminal
289 while (Push3270() || !DoTerminalOutput()) {
290 #if defined(unix) || defined(__APPLE__)
292 #endif /* defined(unix) || defined(__APPLE__) */
298 /* StringToTerminal - output a null terminated string to the terminal */
308 (void) DataToTerminal(s
, count
); /* we know it always goes... */
313 #if ((!defined(NOT43)) || defined(PUTCHAR))
314 /* _putchar - output a single character to the terminal. This name is so that
315 * curses(3x) can call us to send out data.
322 #if defined(sun) /* SunOS 4.0 bug */
324 #endif /* defined(sun) */
329 (void) DataToTerminal(&c
, 1);
334 #endif /* ((!defined(NOT43)) || defined(PUTCHAR)) */
339 if (Sent3270TerminalType
&& my_want_state_is_will(TELOPT_BINARY
)
340 && my_want_state_is_do(TELOPT_BINARY
) && !donebinarytoggle
) {
343 Init3270(); /* Initialize 3270 functions */
344 /* initialize terminal key mapping */
345 InitTerminal(); /* Start terminal going */
352 Stop3270(); /* Tell 3270 we aren't here anymore */
361 * Send a response to a terminal type negotiation.
363 * Return '0' if no more responses to send; '1' if a response sent.
370 * Try to send a 3270 type terminal name. Decide which one based
371 * on the format of our screen, and (in the future) color
374 InitTerminal(); /* Sets MaxNumberColumns, MaxNumberLines */
375 if ((MaxNumberLines
>= 24) && (MaxNumberColumns
>= 80)) {
376 Sent3270TerminalType
= 1;
377 if ((MaxNumberLines
>= 27) && (MaxNumberColumns
>= 132)) {
379 MaxNumberColumns
= 132;
380 sb_terminal
[SBTERMMODEL
] = '5';
381 } else if (MaxNumberLines
>= 43) {
383 MaxNumberColumns
= 80;
384 sb_terminal
[SBTERMMODEL
] = '4';
385 } else if (MaxNumberLines
>= 32) {
387 MaxNumberColumns
= 80;
388 sb_terminal
[SBTERMMODEL
] = '3';
391 MaxNumberColumns
= 80;
392 sb_terminal
[SBTERMMODEL
] = '2';
394 NumberLines
= 24; /* before we start out... */
396 ScreenSize
= NumberLines
*NumberColumns
;
397 if ((MaxNumberLines
*MaxNumberColumns
) > MAXSCREENSIZE
) {
398 ExitString("Programming error: MAXSCREENSIZE too small.\n",
402 printsub('>', sb_terminal
+2, sizeof sb_terminal
-2);
403 ring_supply_data(&netoring
, sb_terminal
, sizeof sb_terminal
);
410 #if defined(unix) || defined(__APPLE__)
412 settranscom(argc
, argv
)
418 if (argc
== 1 && transcom
) {
425 (void) strcpy(transcom
, argv
[1]);
426 for (i
= 2; i
< argc
; ++i
) {
427 (void) strcat(transcom
, " ");
428 (void) strcat(transcom
, argv
[i
]);
432 #endif /* defined(unix) || defined(__APPLE__) */
434 #endif /* defined(TN3270) */