1 /* Copyright (c) 2008, 2009
2 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
3 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
4 * Micah Cowan (micah@cowan.name)
5 * Sadrul Habib Chowdhury (sadrul@users.sourceforge.net)
6 * Copyright (c) 1993-2002, 2003, 2005, 2006, 2007
7 * Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
8 * Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
9 * Copyright (c) 1987 Oliver Laumann
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3, or (at your option)
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, see
23 * http://www.gnu.org/licenses/, or contact Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
26 ****************************************************************
29 #include <sys/types.h>
34 # include <sys/ioctl.h>
41 #include "logfile.h" /* logfopen() */
43 extern struct display
*displays
, *display
;
44 extern struct win
*windows
, *fore
, *wtab
[], *console_window
;
45 extern char *ShellArgs
[];
46 extern char *ShellProg
;
47 extern char screenterm
[];
48 extern char *screenlogfile
;
49 extern char HostName
[];
51 extern int SilenceWait
;
52 extern int real_uid
, real_gid
, eff_uid
, eff_gid
;
53 extern char Termcap
[];
55 extern int visual_bell
, maxwin
;
56 extern struct event logflushev
;
57 extern int log_flush
, logtstamp_after
;
58 extern int ZombieKey_destroy
, ZombieKey_resurrect
, ZombieKey_onerror
;
59 extern struct layer
*flayer
;
60 extern int maxusercount
;
61 extern int pty_preopen
;
63 extern int zmodem_mode
;
64 extern struct mchar mchar_blank
;
65 extern char *zmodem_sendcmd
;
66 extern char *zmodem_recvcmd
;
69 #if defined(TIOCSWINSZ) || defined(TIOCGWINSZ)
70 extern struct winsize glwz
;
74 extern int separate_sids
;
77 static void WinProcess
__P((char **, int *));
78 static void WinRedisplayLine
__P((int, int, int, int));
79 static void WinClearLine
__P((int, int, int, int));
80 static int WinRewrite
__P((int, int, int, struct mchar
*, int));
81 static int WinResize
__P((int, int));
82 static void WinRestore
__P((void));
83 static int DoAutolf
__P((char *, int *, int));
84 static void ZombieProcess
__P((char **, int *));
85 static void win_readev_fn
__P((struct event
*, char *));
86 static void win_writeev_fn
__P((struct event
*, char *));
87 static int muchpending
__P((struct win
*, struct event
*));
89 static void paste_slowev_fn
__P((struct event
*, char *));
92 static void pseu_readev_fn
__P((struct event
*, char *));
93 static void pseu_writeev_fn
__P((struct event
*, char *));
95 static void win_silenceev_fn
__P((struct event
*, char *));
97 static int OpenDevice
__P((char **, int, int *, char **));
98 static int ForkWindow
__P((struct win
*, char **, char *));
100 static void zmodem_found
__P((struct win
*, int, char *, int));
101 static void zmodem_fin
__P((char *, int, char *));
102 static int zmodem_parse
__P((struct win
*, char *, int));
107 int VerboseCreate
= 0; /* XXX move this to user.h */
109 char DefaultShell
[] = "/bin/sh";
110 static char DefaultPath
[] = ":/usr/ucb:/bin:/usr/bin";
112 /* keep this in sync with the structure definition in window.h */
113 struct NewWindow nwin_undef
=
117 (char **)0, /* args */
119 (char *)0, /* term */
134 (char *)0, /* hstatus */
135 (char *)0 /* charset */
138 struct NewWindow nwin_default
=
142 ShellArgs
, /* args */
144 screenterm
, /* term */
146 1*FLOW_NOW
, /* flowflag */
147 LOGINDEFAULT
, /* lflag */
148 DEFAULTHISTHEIGHT
, /* histheight */
149 MON_OFF
, /* monitor */
150 WLOCK_OFF
, /* wlock */
159 (char *)0, /* hstatus */
160 (char *)0 /* charset */
163 struct NewWindow nwin_options
;
165 static int const_IOSIZE
= IOSIZE
;
166 static int const_one
= 1;
169 nwin_compose(def
, new, res
)
170 struct NewWindow
*def
, *new, *res
;
172 #define COMPOSE(x) res->x = new->x != nwin_undef.x ? new->x : def->x
197 /*****************************************************************
199 * The window layer functions
202 struct LayFuncs WinLf
=
214 DoAutolf(buf
, lenp
, fr
)
223 for (p
= buf
; len
> 0; p
++, len
--)
234 bcopy(p
, p
+ 1, len
++);
242 WinProcess(bufpp
, lenp
)
246 int l2
= 0, f
, *ilen
, l
= *lenp
, trunc
;
249 debug1("WinProcess: %d bytes\n", *lenp
);
250 fore
= (struct win
*)flayer
->l_data
;
252 if (fore
->w_type
== W_TYPE_GROUP
)
258 if (fore
->w_ptyfd
< 0) /* zombie? */
260 ZombieProcess(bufpp
, lenp
);
264 /* a pending writelock is this:
265 * fore->w_wlock == WLOCK_AUTO, fore->w_wlockuse = NULL
266 * The user who wants to use this window next, will get the lock, if he can.
268 if (display
&& fore
->w_wlock
== WLOCK_AUTO
&&
269 !fore
->w_wlockuser
&& !AclCheckPermWin(D_user
, ACL_WRITE
, fore
))
271 fore
->w_wlockuser
= D_user
;
272 debug2("window %d: pending writelock grabbed by user %s\n",
273 fore
->w_number
, fore
->w_wlockuser
->u_name
);
275 /* if w_wlock is set, only one user may write, else we check acls */
276 if (display
&& ((fore
->w_wlock
== WLOCK_OFF
) ?
277 AclCheckPermWin(D_user
, ACL_WRITE
, fore
) :
278 (D_user
!= fore
->w_wlockuser
)))
280 debug2("window %d, user %s: ", fore
->w_number
, D_user
->u_name
);
281 debug2("writelock %d (wlockuser %s)\n", fore
->w_wlock
,
282 fore
->w_wlockuser
? fore
->w_wlockuser
->u_name
: "NULL");
283 /* XXX FIXME only display !*/
284 WBell(fore
, visual_bell
);
289 #endif /* MULTIUSER */
291 #ifdef BUILTIN_TELNET
292 if (fore
->w_type
== W_TYPE_TELNET
&& TelIsline(fore
) && *bufpp
!= fore
->w_telbuf
)
294 TelProcessLine(bufpp
, lenp
);
302 /* we send the user input to our pseudowin */
303 ibuf
= fore
->w_pwin
->p_inbuf
; ilen
= &fore
->w_pwin
->p_inlen
;
304 f
= sizeof(fore
->w_pwin
->p_inbuf
) - *ilen
;
309 /* we send the user input to the window */
310 ibuf
= fore
->w_inbuf
; ilen
= &fore
->w_inlen
;
311 f
= sizeof(fore
->w_inbuf
) - *ilen
;
316 #ifdef BUILTIN_TELNET
323 bcopy(*bufpp
, ibuf
+ *ilen
, l2
);
324 if (fore
->w_autolf
&& (trunc
= DoAutolf(ibuf
+ *ilen
, &l2
, f
- l2
)))
326 #ifdef BUILTIN_TELNET
327 if (fore
->w_type
== W_TYPE_TELNET
&& (trunc
= DoTelnet(ibuf
+ *ilen
, &l2
, f
- l2
)))
331 continue; /* need exact value */
342 ZombieProcess(bufpp
, lenp
)
347 char *buf
= *bufpp
, b1
[10], b2
[10];
349 debug1("ZombieProcess: %d bytes\n", *lenp
);
350 fore
= (struct win
*)flayer
->l_data
;
352 ASSERT(fore
->w_ptyfd
< 0);
355 for (; l
-- > 0; buf
++)
357 if (*(unsigned char *)buf
== ZombieKey_destroy
)
359 debug1("Turning undead: %d\n", fore
->w_number
);
363 if (*(unsigned char *)buf
== ZombieKey_resurrect
)
365 debug1("Resurrecting Zombie: %d\n", fore
->w_number
);
366 WriteString(fore
, "\r\n", 2);
371 b1
[AddXChar(b1
, ZombieKey_destroy
)] = '\0';
372 b2
[AddXChar(b2
, ZombieKey_resurrect
)] = '\0';
373 Msg(0, "Press %s to destroy or %s to resurrect window", b1
, b2
);
377 WinRedisplayLine(y
, from
, to
, isblank
)
378 int y
, from
, to
, isblank
;
380 debug3("WinRedisplayLine %d %d %d\n", y
, from
, to
);
383 fore
= (struct win
*)flayer
->l_data
;
384 if (from
== 0 && y
> 0 && fore
->w_mlines
[y
- 1].image
[fore
->w_width
] == 0)
385 LCDisplayLineWrap(&fore
->w_layer
, &fore
->w_mlines
[y
], y
, from
, to
, isblank
);
387 LCDisplayLine(&fore
->w_layer
, &fore
->w_mlines
[y
], y
, from
, to
, isblank
);
391 WinRewrite(y
, x1
, x2
, rend
, doit
)
395 register int cost
, dx
;
396 register unsigned char *p
, *i
;
398 register unsigned char *f
;
401 register unsigned char *c
;
403 register unsigned char *cx
;
407 debug3("WinRewrite %d, %d-%d\n", y
, x1
, x2
);
408 fore
= (struct win
*)flayer
->l_data
;
412 i
= fore
->w_mlines
[y
].image
+ x1
;
417 p
= fore
->w_mlines
[y
].attr
+ x1
;
419 f
= fore
->w_mlines
[y
].font
+ x1
;
421 if (is_dw_font(rend
->font
))
425 if (fore
->w_encoding
&& fore
->w_encoding
!= UTF8
&& D_encoding
== UTF8
&& ContainsSpecialDeffont(fore
->w_mlines
+ y
, x1
, x2
, fore
->w_encoding
))
430 c
= fore
->w_mlines
[y
].color
+ x1
;
432 cx
= fore
->w_mlines
[y
].colorx
+ x1
;
436 cost
= dx
= x2
- x1
+ 1;
439 if (*p
++ != rend
->attr
)
442 if (*f
++ != rend
->font
)
446 if (*c
++ != rend
->color
)
449 if (*cx
++ != rend
->colorx
)
458 WinClearLine(y
, xs
, xe
, bce
)
461 fore
= (struct win
*)flayer
->l_data
;
462 debug3("WinClearLine %d %d-%d\n", y
, xs
, xe
);
463 LClearLine(flayer
, y
, xs
, xe
, bce
, &fore
->w_mlines
[y
]);
470 fore
= (struct win
*)flayer
->l_data
;
471 ChangeWindowSize(fore
, wi
, he
, fore
->w_histheight
);
479 fore
= (struct win
*)flayer
->l_data
;
480 debug1("WinRestore: win %p\n", fore
);
481 for (cv
= flayer
->l_cvlist
; cv
; cv
= cv
->c_next
)
483 display
= cv
->c_display
;
486 /* ChangeScrollRegion(fore->w_top, fore->w_bot); */
487 KeypadMode(fore
->w_keypad
);
488 CursorkeysMode(fore
->w_cursorkeys
);
489 SetFlow(fore
->w_flow
& FLOW_NOW
);
490 InsertMode(fore
->w_insert
);
491 ReverseVideo(fore
->w_revvid
);
492 CursorVisibility(fore
->w_curinv
? -1 : fore
->w_curvvis
);
493 MouseMode(fore
->w_mouse
);
497 /*****************************************************************/
501 * DoStartLog constructs a path for the "want to be logfile" in buf and
504 * returns 0 on success.
507 DoStartLog(w
, buf
, bufsize
)
516 strncpy(buf
, MakeWinMsg(screenlogfile
, w
, '%'), bufsize
- 1);
517 buf
[bufsize
- 1] = 0;
519 debug2("DoStartLog: win %d, file %s\n", w
->w_number
, buf
);
521 if (w
->w_log
!= NULL
)
524 if ((w
->w_log
= logfopen(buf
, islogfile(buf
) ? NULL
: secfopen(buf
, "a"))) == NULL
)
526 if (!logflushev
.queued
)
528 n
= log_flush
? log_flush
: (logtstamp_after
+ 4) / 5;
531 SetTimeout(&logflushev
, n
* 1000);
539 * Umask & wlock are set for the user of the display,
540 * The display d (if specified) switches to that window.
544 struct NewWindow
*newwin
;
546 register struct win
**pp
, *p
;
549 struct NewWindow nwin
;
553 extern struct acluser
*users
;
556 debug1("NewWindow: StartAt %d\n", newwin
->StartAt
);
557 debug1("NewWindow: aka %s\n", newwin
->aka
?newwin
->aka
:"NULL");
558 debug1("NewWindow: dir %s\n", newwin
->dir
?newwin
->dir
:"NULL");
559 debug1("NewWindow: term %s\n", newwin
->term
?newwin
->term
:"NULL");
561 nwin_compose(&nwin_default
, newwin
, &nwin
);
562 debug1("NWin: aka %s\n", nwin
.aka
? nwin
.aka
: "NULL");
563 debug1("NWin: wlock %d\n", nwin
.wlock
);
564 debug1("NWin: Lflag %d\n", nwin
.Lflag
);
566 startat
= nwin
.StartAt
< maxwin
? nwin
.StartAt
: 0;
573 if (++pp
== wtab
+ maxwin
)
576 while (pp
!= wtab
+ startat
);
579 Msg(0, "No more windows.");
583 #if defined(USRLIMIT) && defined(UTMPOK)
585 * Count current number of users, if logging windows in.
587 if (nwin
.lflag
&& CountUsers() >= USRLIMIT
)
589 Msg(0, "User limit reached. Window will not be logged in.");
594 debug1("Makewin creating %d\n", n
);
596 if ((f
= OpenDevice(nwin
.args
, nwin
.lflag
, &type
, &TtyName
)) < 0)
598 if (type
== W_TYPE_GROUP
)
601 if ((p
= (struct win
*)calloc(1, sizeof(struct win
))) == 0)
609 if (type
!= W_TYPE_PTY
)
615 /* save the command line so that zombies can be resurrected */
616 for (i
= 0; nwin
.args
[i
] && i
< MAXARGS
- 1; i
++)
617 p
->w_cmdargs
[i
] = SaveStr(nwin
.args
[i
]);
620 p
->w_dir
= SaveStr(nwin
.dir
);
622 p
->w_term
= SaveStr(nwin
.term
);
626 if (fore
&& fore
->w_type
== W_TYPE_GROUP
)
628 else if (fore
&& fore
->w_group
)
629 p
->w_group
= fore
->w_group
;
632 * This is dangerous: without a display we use creators umask
633 * This is intended to be usefull for detached startup.
634 * But is still better than default bits with a NULL user.
636 if (NewWindowAcl(p
, display
? D_user
: users
))
644 p
->w_layer
.l_next
= 0;
645 p
->w_layer
.l_bottom
= &p
->w_layer
;
646 p
->w_layer
.l_layfn
= &WinLf
;
647 p
->w_layer
.l_data
= (char *)p
;
648 p
->w_savelayer
= &p
->w_layer
;
653 if (display
&& !AclCheckPermWin(D_user
, ACL_WRITE
, p
))
654 p
->w_wlockuser
= D_user
;
655 p
->w_wlock
= nwin
.wlock
;
658 p
->w_aflag
= nwin
.aflag
;
659 p
->w_flow
= nwin
.flowflag
| ((nwin
.flowflag
& FLOW_AUTOFLAG
) ? (FLOW_AUTO
|FLOW_NOW
) : FLOW_AUTO
);
661 nwin
.aka
= Filename(nwin
.args
[0]);
662 strncpy(p
->w_akabuf
, nwin
.aka
, sizeof(p
->w_akabuf
) - 1);
663 if ((nwin
.aka
= rindex(p
->w_akabuf
, '|')) != NULL
)
667 p
->w_title
= nwin
.aka
;
668 p
->w_akachange
= nwin
.aka
+ strlen(nwin
.aka
);
671 p
->w_title
= p
->w_akachange
= p
->w_akabuf
;
673 p
->w_hstatus
= SaveStr(nwin
.hstatus
);
674 p
->w_monitor
= nwin
.monitor
;
676 if (p
->w_monitor
== MON_ON
)
678 /* always tell all users */
679 for (i
= 0; i
< maxusercount
; i
++)
680 ACLBYTE(p
->w_mon_notify
, i
) |= ACLBIT(i
);
684 * defsilence by Lloyd Zusman (zusman_lloyd@jpmorgan.com)
686 p
->w_silence
= nwin
.silence
;
687 p
->w_silencewait
= SilenceWait
;
689 if (p
->w_silence
== SILENCE_ON
)
691 /* always tell all users */
692 for (i
= 0; i
< maxusercount
; i
++)
693 ACLBYTE(p
->w_lio_notify
, i
) |= ACLBIT(i
);
697 p
->w_slowpaste
= nwin
.slow
;
703 strncpy(p
->w_tty
, TtyName
, MAXSTR
- 1);
706 /* XXX Fixme display resize */
707 if (ChangeWindowSize(p
, display
? D_defwidth
: 80,
708 display
? D_defheight
: 24,
715 if (ChangeWindowSize(p
, display
? D_forecv
->c_xe
- D_forecv
->c_xs
+ 1: 80,
716 display
? D_forecv
->c_ye
- D_forecv
->c_ys
+ 1 : 24,
724 p
->w_encoding
= nwin
.encoding
;
725 ResetWindow(p
); /* sets w_wrap, w_c1, w_gr, w_bce */
729 SetCharsets(p
, nwin
.charset
);
732 if (VerboseCreate
&& type
!= W_TYPE_GROUP
)
734 struct display
*d
= display
; /* WriteString zaps display */
736 WriteString(p
, ":screen (", 9);
737 WriteString(p
, p
->w_title
, strlen(p
->w_title
));
738 WriteString(p
, "):", 2);
739 for (f
= 0; p
->w_cmdargs
[f
]; f
++)
741 WriteString(p
, " ", 1);
742 WriteString(p
, p
->w_cmdargs
[f
], strlen(p
->w_cmdargs
[f
]));
744 WriteString(p
, "\r\n", 2);
754 #ifdef BUILTIN_TELNET
755 if (type
== W_TYPE_TELNET
)
765 if (type
== W_TYPE_PTY
)
767 p
->w_pid
= ForkWindow(p
, nwin
.args
, TtyName
);
776 * Place the new window at the head of the most-recently-used list.
778 if (display
&& D_fore
)
784 if (type
== W_TYPE_GROUP
)
787 Activate(p
->w_norefresh
);
788 WindowChanged((struct win
*)0, 'w');
789 WindowChanged((struct win
*)0, 'W');
790 WindowChanged((struct win
*)0, 0);
794 p
->w_lflag
= nwin
.lflag
;
796 p
->w_slot
= (slot_t
)-1;
798 debug1("MakeWindow will %slog in.\n", nwin
.lflag
?"":"not ");
800 # else /* LOGOUTOK */
801 debug1("MakeWindow will log in, LOGOUTOK undefined in config.h%s.\n",
802 nwin
.lflag
?"":" (although lflag=0)");
803 # endif /* LOGOUTOK */
805 p
->w_slot
= (slot_t
)0;
806 if (display
|| (p
->w_lflag
& 2))
810 CarefulUtmp(); /* If all 've been zombies, we've had no slot */
817 DoStartLog(p
, buf
, sizeof(buf
));
820 p
->w_readev
.fd
= p
->w_writeev
.fd
= p
->w_ptyfd
;
821 p
->w_readev
.type
= EV_READ
;
822 p
->w_writeev
.type
= EV_WRITE
;
823 p
->w_readev
.data
= p
->w_writeev
.data
= (char *)p
;
824 p
->w_readev
.handler
= win_readev_fn
;
825 p
->w_writeev
.handler
= win_writeev_fn
;
826 p
->w_writeev
.condpos
= &p
->w_inlen
;
828 evenq(&p
->w_writeev
);
830 p
->w_paster
.pa_slowev
.type
= EV_TIMEOUT
;
831 p
->w_paster
.pa_slowev
.data
= (char *)&p
->w_paster
;
832 p
->w_paster
.pa_slowev
.handler
= paste_slowev_fn
;
834 p
->w_silenceev
.type
= EV_TIMEOUT
;
835 p
->w_silenceev
.data
= (char *)p
;
836 p
->w_silenceev
.handler
= win_silenceev_fn
;
837 if (p
->w_silence
> 0)
839 debug("New window has silence enabled.\n");
840 SetTimeout(&p
->w_silenceev
, p
->w_silencewait
* 1000);
841 evenq(&p
->w_silenceev
);
845 Activate(p
->w_norefresh
);
846 WindowChanged((struct win
*)0, 'w');
847 WindowChanged((struct win
*)0, 'W');
848 WindowChanged((struct win
*)0, 0);
853 * Resurrect a window from Zombie state.
854 * The command vector is therefore stored in the window structure.
855 * Note: The terminaltype defaults to screenterm again, the current
856 * working directory is lost.
865 lflag
= nwin_default
.lflag
;
866 if ((f
= OpenDevice(p
->w_cmdargs
, lflag
, &p
->w_type
, &TtyName
)) < 0)
869 strncpy(p
->w_tty
, *TtyName
? TtyName
: p
->w_title
, MAXSTR
- 1);
874 evenq(&p
->w_writeev
);
878 struct display
*d
= display
; /* WriteString zaps display */
880 WriteString(p
, ":screen (", 9);
881 WriteString(p
, p
->w_title
, strlen(p
->w_title
));
882 WriteString(p
, "):", 2);
883 for (f
= 0; p
->w_cmdargs
[f
]; f
++)
885 WriteString(p
, " ", 1);
886 WriteString(p
, p
->w_cmdargs
[f
], strlen(p
->w_cmdargs
[f
]));
888 WriteString(p
, "\r\n", 2);
894 #ifdef BUILTIN_TELNET
895 if (p
->w_type
== W_TYPE_TELNET
)
902 if (p
->w_type
== W_TYPE_PTY
)
904 p
->w_pid
= ForkWindow(p
, p
->w_cmdargs
, TtyName
);
910 if (p
->w_slot
== (slot_t
)0 && (display
|| (p
->w_lflag
& 2)))
913 CarefulUtmp(); /* If all 've been zombies, we've had no slot */
916 WindowChanged(p
, 'f');
926 if (wp
->w_type
== W_TYPE_PTY
)
929 (void)chmod(wp
->w_tty
, 0666);
930 (void)chown(wp
->w_tty
, 0, 0);
935 evdeq(&wp
->w_readev
);
936 evdeq(&wp
->w_writeev
);
937 #ifdef BUILTIN_TELNET
938 evdeq(&wp
->w_telconnev
);
940 wp
->w_readev
.fd
= wp
->w_writeev
.fd
= -1;
949 struct canvas
*cv
, *ncv
;
952 debug1("FreeWindow %d\n", wp
? wp
->w_number
: -1);
962 if (wp
== console_window
)
964 TtyGrabConsole(-1, -1, "free");
967 if (wp
->w_log
!= NULL
)
968 logfclose(wp
->w_log
);
969 ChangeWindowSize(wp
, 0, 0, 0);
971 if (wp
->w_type
== W_TYPE_GROUP
)
974 for (win
= windows
; win
; win
= win
->w_next
)
975 if (win
->w_group
== wp
)
976 win
->w_group
= wp
->w_group
;
981 for (i
= 0; wp
->w_cmdargs
[i
]; i
++)
982 free(wp
->w_cmdargs
[i
]);
987 for (d
= displays
; d
; d
= d
->d_next
)
989 if (d
->d_other
== wp
)
990 d
->d_other
= d
->d_fore
&& d
->d_fore
->w_next
!= wp
? d
->d_fore
->w_next
: wp
->w_next
;
993 for (cv
= d
->d_cvlist
; cv
; cv
= cv
->c_next
)
995 for (l
= cv
->c_layer
; l
; l
= l
->l_next
)
996 if (l
->l_layfn
== &WinLf
)
1000 if ((struct win
*)l
->l_data
!= wp
)
1002 if (cv
->c_layer
== wp
->w_savelayer
)
1003 wp
->w_savelayer
= 0;
1004 KillLayerChain(cv
->c_layer
);
1007 if (wp
->w_savelayer
)
1008 KillLayerChain(wp
->w_savelayer
);
1009 for (cv
= wp
->w_layer
.l_cvlist
; cv
; cv
= ncv
)
1012 cv
->c_layer
= &cv
->c_blank
;
1013 cv
->c_blank
.l_cvlist
= cv
;
1015 cv
->c_xoff
= cv
->c_xs
;
1016 cv
->c_yoff
= cv
->c_ys
;
1017 RethinkViewportOffsets(cv
);
1019 wp
->w_layer
.l_cvlist
= 0;
1020 if (flayer
== &wp
->w_layer
)
1025 #endif /* MULTIUSER */
1026 evdeq(&wp
->w_readev
); /* just in case */
1027 evdeq(&wp
->w_writeev
); /* just in case */
1028 evdeq(&wp
->w_silenceev
);
1030 FreePaster(&wp
->w_paster
);
1036 OpenDevice(args
, lflag
, typep
, namep
)
1042 char *arg
= args
[0];
1048 if (strcmp(arg
, "//group") == 0)
1050 *typep
= W_TYPE_GROUP
;
1054 #ifdef BUILTIN_TELNET
1055 if (strcmp(arg
, "//telnet") == 0)
1057 f
= TelOpen(args
+ 1);
1059 *typep
= W_TYPE_TELNET
;
1064 if (strncmp(arg
, "//", 2) == 0)
1066 Msg(0, "Invalid argument '%s'", arg
);
1069 else if ((stat(arg
, &st
)) == 0 && S_ISCHR(st
.st_mode
))
1071 if (access(arg
, R_OK
| W_OK
) == -1)
1073 Msg(errno
, "Cannot access line '%s' for R/W", arg
);
1076 debug("OpenDevice: OpenTTY\n");
1077 if ((f
= OpenTTY(arg
, args
[1])) < 0)
1080 *typep
= W_TYPE_PLAIN
;
1085 *typep
= W_TYPE_PTY
;
1089 Msg(0, "No more PTYs.");
1095 if (ioctl(f
, TIOCPKT
, (char *)&flag
))
1097 Msg(errno
, "TIOCPKT ioctl");
1102 #endif /* TIOCPKT */
1104 debug1("fcntl(%d, F_SETFL, FNBLOCK)\n", f
);
1105 (void) fcntl(f
, F_SETFL
, FNBLOCK
);
1108 * Tenebreux (zeus@ns.acadiacom.net) has Linux 1.3.70 where select
1109 * gets confused in the following condition:
1110 * Open a pty-master side, request a flush on it, then set packet
1111 * mode and call select(). Select will return a possible read, where
1112 * the one byte response to the flush can be found. Select will
1113 * thereafter return a possible read, which yields I/O error.
1115 * If we request another flush *after* switching into packet mode,
1116 * this I/O error does not occur. We receive a single response byte
1117 * although we send two flush requests now.
1119 * Maybe we should not flush at all.
1123 if (*typep
== W_TYPE_PTY
|| *typep
== W_TYPE_PLAIN
)
1124 tcflush(f
, TCIOFLUSH
);
1127 if (*typep
!= W_TYPE_PTY
)
1132 if (chown(*namep
, real_uid
, PTYGROUP
) && !eff_uid
)
1134 if (chown(*namep
, real_uid
, real_gid
) && !eff_uid
)
1137 Msg(errno
, "chown tty");
1142 if (chmod(*namep
, lflag
? TtyMode
: (TtyMode
& ~022)) && !eff_uid
)
1144 if (chmod(*namep
, TtyMode
) && !eff_uid
)
1147 Msg(errno
, "chmod tty");
1156 * Fields w_width, w_height, aflag, number (and w_tty)
1157 * are read from struct win *win. No fields written.
1158 * If pwin is nonzero, filedescriptors are distributed
1159 * between win->w_tty and open(ttyn)
1163 ForkWindow(win
, args
, ttyn
)
1170 char shellbuf
[7 + MAXPATHLEN
];
1173 char libuf
[20], cobuf
[20];
1176 int w
= win
->w_width
;
1177 int h
= win
->w_height
;
1179 int i
, pat
, wfdused
;
1180 struct pseudowin
*pwin
= win
->w_pwin
;
1187 debug("pre-opening slave...\n");
1188 if ((slave
= open(ttyn
, O_RDWR
|O_NOCTTY
)) == -1)
1195 debug("forking...\n");
1204 switch (pid
= fork())
1210 signal(SIGHUP
, SIG_DFL
);
1211 signal(SIGINT
, SIG_DFL
);
1212 signal(SIGQUIT
, SIG_DFL
);
1213 signal(SIGTERM
, SIG_DFL
);
1215 signal(SIGTTIN
, SIG_DFL
);
1216 signal(SIGTTOU
, SIG_DFL
);
1219 signal(SIGPIPE
, SIG_DFL
);
1222 signal(SIGXFSZ
, SIG_DFL
);
1225 displays
= 0; /* beware of Panic() */
1226 if (setgid(real_gid
) || setuid(real_uid
))
1227 Panic(errno
, "Setuid/gid");
1231 if (!pwin
) /* ignore directory if pseudo */
1233 if (win
->w_dir
&& *win
->w_dir
&& chdir(win
->w_dir
))
1234 Panic(errno
, "Cannot chdir to %s", win
->w_dir
);
1244 if (dfp
&& dfp
!= stderr
)
1252 closeallfiles(win
->w_ptyfd
);
1256 closeallfiles(win
->w_ptyfd
);
1258 if (dfp
) /* do not produce child debug, when debug is "off" */
1262 sprintf(buf
, "%s/screen.child", DEBUGDIR
);
1263 if ((dfp
= fopen(buf
, "a")) == 0)
1266 (void) chmod(buf
, 0666);
1268 debug1("=== ForkWindow: pid %d\n", (int)getpid());
1270 /* Close the three /dev/null descriptors */
1276 * distribute filedescriptors between the ttys
1279 pat
= pwin
? pwin
->p_fdpat
:
1280 ((F_PFRONT
<<(F_PSHIFT
*2)) | (F_PFRONT
<<F_PSHIFT
) | F_PFRONT
);
1281 debug1("Using window pattern 0x%x\n", pat
);
1283 for(i
= 0; i
< 3; i
++)
1285 if (pat
& F_PFRONT
<< F_PSHIFT
* i
)
1291 newfd
= open(ttyn
, O_RDWR
);
1293 newfd
= open(ttyn
, O_RDWR
|O_NOCTTY
);
1295 newfd
= open(ttyn
, O_RDWR
);
1298 Panic(errno
, "Cannot open %s", ttyn
);
1312 * the pseudo window process should not be surprised with a
1313 * nonblocking filedescriptor. Poor Backend!
1315 debug1("Clearing NBLOCK on window-fd(%d)\n", win
->w_ptyfd
);
1316 if (fcntl(win
->w_ptyfd
, F_SETFL
, 0))
1317 Msg(errno
, "Warning: clear NBLOCK fcntl failed");
1322 newfd
= open(ttyn
, O_RDWR
);
1324 newfd
= open(ttyn
, O_RDWR
|O_NOCTTY
);
1326 newfd
= open(ttyn
, O_RDWR
);
1329 Panic(errno
, "Cannot open %s", ttyn
);
1332 #endif /* PSEUDOS */
1333 close(win
->w_ptyfd
);
1338 struct mode fakemode
, *modep
;
1341 Msg(errno
, "fgtty");
1344 debug("ForkWindow: using display tty mode for new child.\n");
1349 debug("No display - creating tty setting\n");
1356 /* We only want echo if the users input goes to the pseudo
1357 * and the pseudo's stdout is not send to the window.
1360 if (pwin
&& (!(pat
& F_UWP
) || (pat
& F_PBACK
<< F_PSHIFT
)))
1362 debug1("clearing echo on pseudywin fd (pat %x)\n", pat
);
1363 # if defined(POSIX) || defined(TERMIO)
1364 modep
->tio
.c_lflag
&= ~ECHO
;
1365 modep
->tio
.c_iflag
&= ~ICRNL
;
1367 modep
->m_ttyb
.sg_flags
&= ~ECHO
;
1371 SetTTY(newfd
, modep
);
1375 (void) ioctl(newfd
, TIOCSWINSZ
, (char *)&glwz
);
1377 /* Always turn off nonblocking mode */
1378 (void)fcntl(newfd
, F_SETFL
, 0);
1381 sprintf(libuf
, "LINES=%d", h
);
1382 sprintf(cobuf
, "COLUMNS=%d", w
);
1387 NewEnv
[2] = MakeTermcap(display
== 0 || win
->w_aflag
);
1390 NewEnv
[2] = MakeTermcap(1);
1392 NewEnv
[2] = Termcap
;
1394 strcpy(shellbuf
, "SHELL=");
1395 strncpy(shellbuf
+ 6, ShellProg
+ (*ShellProg
== '-'), sizeof(shellbuf
) - 7);
1396 shellbuf
[sizeof(shellbuf
) - 1] = 0;
1397 NewEnv
[4] = shellbuf
;
1398 debug1("ForkWindow: NewEnv[4] = '%s'\n", shellbuf
);
1399 if (win
->w_term
&& *win
->w_term
&& strcmp(screenterm
, win
->w_term
) &&
1400 (strlen(win
->w_term
) < 20))
1404 sprintf(tebuf
, "TERM=%s", win
->w_term
);
1405 debug2("Makewindow %d with %s\n", win
->w_number
, tebuf
);
1406 tl
= strlen(win
->w_term
);
1408 if ((s1
= index(NewEnv
[2], '|')))
1410 if ((s2
= index(++s1
, '|')))
1412 if (strlen(NewEnv
[2]) - (s2
- s1
) + tl
< 1024)
1414 bcopy(s2
, s1
+ tl
, strlen(s2
) + 1);
1415 bcopy(win
->w_term
, s1
, tl
);
1420 sprintf(ebuf
, "WINDOW=%d", win
->w_number
);
1426 proc
= DefaultShell
;
1427 debug1("calling execvpe %s\n", proc
);
1428 execvpe(proc
, args
, NewEnv
);
1429 debug1("exec error: %d\n", errno
);
1430 Panic(errno
, "Cannot exec '%s'", proc
);
1440 execvpe(prog
, args
, env
)
1441 char *prog
, **args
, **env
;
1443 register char *path
= NULL
, *p
;
1445 char *shargs
[MAXARGS
+ 1];
1446 register int i
, eaccess
= 0;
1448 if (rindex(prog
, '/'))
1450 if (!path
&& !(path
= getenv("PATH")))
1454 for (p
= buf
; *path
&& *path
!= ':'; path
++)
1455 if (p
- buf
< (int)sizeof(buf
) - 2)
1459 if (p
- buf
+ strlen(prog
) >= sizeof(buf
) - 1)
1462 execve(buf
, args
, env
);
1466 shargs
[0] = DefaultShell
;
1468 for (i
= 1; (shargs
[i
+ 1] = args
[i
]) != NULL
; ++i
)
1470 execve(DefaultShell
, shargs
, env
);
1493 int i
, r
= 0, l
= 0;
1495 extern struct display
*display
;
1496 extern struct win
*windows
;
1497 struct pseudowin
*pwin
;
1500 if ((w
= display
? fore
: windows
) == NULL
)
1502 if (!*av
|| w
->w_pwin
)
1504 Msg(0, "Filter running: %s", w
->w_pwin
? w
->w_pwin
->p_cmd
: "(none)");
1509 Msg(0, "You feel dead inside.");
1512 if (!(pwin
= (struct pseudowin
*)calloc(1, sizeof(struct pseudowin
))))
1518 /* allow ^a:!!./ttytest as a short form for ^a:exec !.. ./ttytest */
1519 for (s
= *av
; *s
== ' '; s
++)
1521 for (p
= s
; *p
== ':' || *p
== '.' || *p
== '!'; p
++)
1524 while (*p
&& p
> s
&& p
[-1] == '.')
1537 for (i
= 0; i
< 3; i
++)
1539 *t
= (s
< p
) ? *s
++ : '.';
1544 l
|= F_PFRONT
<< (i
* F_PSHIFT
);
1547 l
|= F_PBACK
<< (i
* F_PSHIFT
);
1550 l
|= F_PBOTH
<< (i
* F_PSHIFT
);
1558 if ((l
& F_PMASK
) == F_PFRONT
)
1561 l
^= F_PFRONT
| F_PBACK
;
1568 debug1("winexec: '%#x'\n", pwin
->p_fdpat
);
1571 for (pp
= av
; *pp
; pp
++)
1574 while (*p
&& l
-- > 0)
1581 debug1("%s\n", pwin
->p_cmd
);
1583 if ((pwin
->p_ptyfd
= OpenDevice(av
, 0, &type
, &t
)) < 0)
1588 strncpy(pwin
->p_tty
, t
, MAXSTR
- 1);
1590 if (type
!= W_TYPE_PTY
)
1593 Msg(0, "Cannot only use commands as pseudo win.");
1596 if (!(pwin
->p_fdpat
& F_PFRONT
))
1597 evdeq(&w
->w_readev
);
1602 if (ioctl(pwin
->p_ptyfd
, TIOCPKT
, (char *)&flag
))
1604 Msg(errno
, "TIOCPKT pwin ioctl");
1608 if (w
->w_type
== W_TYPE_PTY
&& !(pwin
->p_fdpat
& F_PFRONT
))
1610 if (ioctl(w
->w_ptyfd
, TIOCPKT
, (char *)&flag
))
1612 Msg(errno
, "TIOCPKT win ioctl");
1618 #endif /* TIOCPKT */
1620 pwin
->p_readev
.fd
= pwin
->p_writeev
.fd
= pwin
->p_ptyfd
;
1621 pwin
->p_readev
.type
= EV_READ
;
1622 pwin
->p_writeev
.type
= EV_WRITE
;
1623 pwin
->p_readev
.data
= pwin
->p_writeev
.data
= (char *)w
;
1624 pwin
->p_readev
.handler
= pseu_readev_fn
;
1625 pwin
->p_writeev
.handler
= pseu_writeev_fn
;
1626 pwin
->p_writeev
.condpos
= &pwin
->p_inlen
;
1627 if (pwin
->p_fdpat
& (F_PFRONT
<< F_PSHIFT
* 2 | F_PFRONT
<< F_PSHIFT
))
1628 evenq(&pwin
->p_readev
);
1629 evenq(&pwin
->p_writeev
);
1630 r
= pwin
->p_pid
= ForkWindow(w
, av
, t
);
1640 struct pseudowin
*pwin
= w
->w_pwin
;
1643 if (fcntl(w
->w_ptyfd
, F_SETFL
, FNBLOCK
))
1644 Msg(errno
, "Warning: FreePseudowin: NBLOCK fcntl failed");
1646 if (w
->w_type
== W_TYPE_PTY
&& !(pwin
->p_fdpat
& F_PFRONT
))
1649 if (ioctl(w
->w_ptyfd
, TIOCPKT
, (char *)&flag
))
1650 Msg(errno
, "Warning: FreePseudowin: TIOCPKT win ioctl");
1653 /* should be able to use CloseDevice() here */
1654 (void)chmod(pwin
->p_tty
, 0666);
1655 (void)chown(pwin
->p_tty
, 0, 0);
1656 if (pwin
->p_ptyfd
>= 0)
1657 close(pwin
->p_ptyfd
);
1658 evdeq(&pwin
->p_readev
);
1659 evdeq(&pwin
->p_writeev
);
1660 if (w
->w_readev
.condneg
== &pwin
->p_inlen
)
1661 w
->w_readev
.condpos
= w
->w_readev
.condneg
= 0;
1662 evenq(&w
->w_readev
);
1667 #endif /* PSEUDOS */
1672 * returns 0, if the lock really has been released
1675 ReleaseAutoWritelock(dis
, w
)
1676 struct display
*dis
;
1679 debug2("ReleaseAutoWritelock: user %s, window %d\n",
1680 dis
->d_user
->u_name
, w
->w_number
);
1682 /* release auto writelock when user has no other display here */
1683 if (w
->w_wlock
== WLOCK_AUTO
&& w
->w_wlockuser
== dis
->d_user
)
1687 for (d
= displays
; d
; d
= d
->d_next
)
1688 if (( d
!= dis
) && (d
->d_fore
== w
) && (d
->d_user
== dis
->d_user
))
1690 debug3("%s %s autolock on win %d\n",
1691 dis
->d_user
->u_name
, d
? "keeps" : "releases", w
->w_number
);
1694 w
->w_wlockuser
= NULL
;
1702 * returns 0, if the lock really could be obtained
1705 ObtainAutoWritelock(d
, w
)
1709 if ((w
->w_wlock
== WLOCK_AUTO
) &&
1710 !AclCheckPermWin(d
->d_user
, ACL_WRITE
, w
) &&
1713 debug2("%s obtained auto writelock for exported window %d\n",
1714 d
->d_user
->u_name
, w
->w_number
);
1715 w
->w_wlockuser
= d
->d_user
;
1721 #endif /* MULTIUSER */
1725 /********************************************************************/
1729 paste_slowev_fn(ev
, data
)
1733 struct paster
*pa
= (struct paster
*)data
;
1737 flayer
= pa
->pa_pastelayer
;
1739 pa
->pa_pastelen
= 0;
1740 if (!pa
->pa_pastelen
)
1742 p
= Layer2Window(flayer
);
1743 DoProcess(p
, &pa
->pa_pasteptr
, &l
, pa
);
1744 pa
->pa_pastelen
-= 1 - l
;
1745 if (pa
->pa_pastelen
> 0)
1747 SetTimeout(&pa
->pa_slowev
, p
->w_slowpaste
);
1748 evenq(&pa
->pa_slowev
);
1760 for (cv
= p
->w_layer
.l_cvlist
; cv
; cv
= cv
->c_lnext
)
1762 display
= cv
->c_display
;
1763 if (D_status
== STATUS_ON_WIN
&& !D_status_bell
)
1765 /* wait 'til status is gone */
1766 debug("BLOCKING because of status\n");
1767 ev
->condpos
= &const_one
;
1768 ev
->condneg
= &D_status
;
1771 debug2("muchpending %s %d: ", D_usertty
, D_blocked
);
1772 debug3("%d %d %d\n", D_obufp
- D_obuf
, D_obufmax
, D_blocked_fuzz
);
1775 if (D_obufp
- D_obuf
> D_obufmax
+ D_blocked_fuzz
)
1777 if (D_nonblock
== 0)
1779 debug1("obuf is full, stopping output to display %s\n", D_usertty
);
1783 debug("BLOCKING because of full obuf\n");
1784 ev
->condpos
= &D_obuffree
;
1785 ev
->condneg
= &D_obuflenmax
;
1786 if (D_nonblock
> 0 && !D_blockedev
.queued
)
1788 debug1("created timeout of %g secs\n", D_nonblock
/1000.);
1789 SetTimeout(&D_blockedev
, D_nonblock
);
1790 evenq(&D_blockedev
);
1799 win_readev_fn(ev
, data
)
1803 struct win
*p
= (struct win
*)data
;
1804 char buf
[IOSIZE
], *bp
;
1814 wtop
= p
->w_pwin
&& W_WTOP(p
);
1817 ASSERT(sizeof(p
->w_pwin
->p_inbuf
) == IOSIZE
);
1818 size
= IOSIZE
- p
->w_pwin
->p_inlen
;
1821 ev
->condpos
= &const_IOSIZE
;
1822 ev
->condneg
= &p
->w_pwin
->p_inlen
;
1827 if (p
->w_layer
.l_cvlist
&& muchpending(p
, ev
))
1834 ev
->condpos
= &const_one
;
1835 ev
->condneg
= &p
->w_blocked
;
1839 ev
->condpos
= ev
->condneg
= 0;
1841 if ((len
= p
->w_outlen
))
1844 WriteString(p
, p
->w_outbuf
, len
);
1848 debug1("going to read from window fd %d\n", ev
->fd
);
1849 if ((len
= read(ev
->fd
, buf
, size
)) < 0)
1851 if (errno
== EINTR
|| errno
== EAGAIN
)
1853 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
1854 if (errno
== EWOULDBLOCK
)
1857 debug2("Window %d: read error (errno %d) - killing window\n", p
->w_number
, errno
);
1859 WindowDied(p
, (union wait
)0, 0);
1861 WindowDied(p
, 0, 0);
1867 debug1("Window %d: EOF - killing window\n", p
->w_number
);
1869 WindowDied(p
, (union wait
)0, 0);
1871 WindowDied(p
, 0, 0);
1875 debug1(" -> %d bytes\n", len
);
1877 if (p
->w_type
== W_TYPE_PTY
)
1881 debug1("PAKET %x\n", buf
[0]);
1882 if (buf
[0] & TIOCPKT_NOSTOP
)
1884 if (buf
[0] & TIOCPKT_DOSTOP
)
1891 #ifdef BUILTIN_TELNET
1892 if (p
->w_type
== W_TYPE_TELNET
)
1893 len
= TelIn(p
, bp
, len
, buf
+ sizeof(buf
) - (bp
+ len
));
1898 if (zmodem_mode
&& zmodem_parse(p
, bp
, len
))
1904 debug("sending input to pwin\n");
1905 bcopy(bp
, p
->w_pwin
->p_inbuf
+ p
->w_pwin
->p_inlen
, len
);
1906 p
->w_pwin
->p_inlen
+= len
;
1909 WriteString(p
, bp
, len
);
1915 win_writeev_fn(ev
, data
)
1919 struct win
*p
= (struct win
*)data
;
1923 debug2("writing %d bytes to win %d\n", p
->w_inlen
, p
->w_number
);
1924 if ((len
= write(ev
->fd
, p
->w_inbuf
, p
->w_inlen
)) <= 0)
1925 len
= p
->w_inlen
; /* dead window */
1926 if ((p
->w_inlen
-= len
))
1927 bcopy(p
->w_inbuf
+ len
, p
->w_inbuf
, p
->w_inlen
);
1930 if (p
->w_paster
.pa_pastelen
&& !p
->w_slowpaste
)
1932 struct paster
*pa
= &p
->w_paster
;
1933 flayer
= pa
->pa_pastelayer
;
1935 DoProcess(p
, &pa
->pa_pasteptr
, &pa
->pa_pastelen
, pa
);
1946 pseu_readev_fn(ev
, data
)
1950 struct win
*p
= (struct win
*)data
;
1952 int size
, ptow
, len
;
1959 ASSERT(sizeof(p
->w_inbuf
) == IOSIZE
);
1960 size
= IOSIZE
- p
->w_inlen
;
1963 ev
->condpos
= &const_IOSIZE
;
1964 ev
->condneg
= &p
->w_inlen
;
1968 if (p
->w_layer
.l_cvlist
&& muchpending(p
, ev
))
1972 ev
->condpos
= &const_one
;
1973 ev
->condneg
= &p
->w_blocked
;
1977 ev
->condpos
= ev
->condneg
= 0;
1979 if ((len
= p
->w_outlen
))
1982 WriteString(p
, p
->w_outbuf
, len
);
1986 if ((len
= read(ev
->fd
, buf
, size
)) <= 0)
1988 if (errno
== EINTR
|| errno
== EAGAIN
)
1990 #if defined(EWOULDBLOCK) && (EWOULDBLOCK != EAGAIN)
1991 if (errno
== EWOULDBLOCK
)
1994 debug2("Window %d: pseudowin read error (errno %d) -- removing pseudowin\n", p
->w_number
, len
? errno
: 0);
1998 /* no packet mode on pseudos! */
2001 bcopy(buf
, p
->w_inbuf
+ p
->w_inlen
, len
);
2004 WriteString(p
, buf
, len
);
2009 pseu_writeev_fn(ev
, data
)
2013 struct win
*p
= (struct win
*)data
;
2014 struct pseudowin
*pw
= p
->w_pwin
;
2018 if (pw
->p_inlen
== 0)
2020 if ((len
= write(ev
->fd
, pw
->p_inbuf
, pw
->p_inlen
)) <= 0)
2021 len
= pw
->p_inlen
; /* dead pseudo */
2022 if ((p
->w_pwin
->p_inlen
-= len
))
2023 bcopy(p
->w_pwin
->p_inbuf
+ len
, p
->w_pwin
->p_inbuf
, p
->w_pwin
->p_inlen
);
2027 #endif /* PSEUDOS */
2030 win_silenceev_fn(ev
, data
)
2034 struct win
*p
= (struct win
*)data
;
2036 debug1("FOUND silence win %d\n", p
->w_number
);
2037 for (display
= displays
; display
; display
= display
->d_next
)
2039 for (cv
= D_cvlist
; cv
; cv
= cv
->c_next
)
2040 if (cv
->c_layer
->l_bottom
== &p
->w_layer
)
2043 continue; /* user already sees window */
2045 if (!(ACLBYTE(p
->w_lio_notify
, D_user
->u_id
) & ACLBIT(D_user
->u_id
)))
2048 Msg(0, "Window %d: silence for %d seconds", p
->w_number
, p
->w_silencewait
);
2055 zmodem_parse(p
, bp
, len
)
2062 for (i
= 0; i
< len
; i
++, b2
++)
2064 if (p
->w_zauto
== 0)
2066 for (; i
< len
; i
++, b2
++)
2071 if (i
> 1 && b2
[-1] == '*' && b2
[-2] == '*')
2075 if (p
->w_zauto
> 5 || *b2
== "**\030B00"[p
->w_zauto
] || (p
->w_zauto
== 5 && *b2
== '1') || (p
->w_zauto
== 5 && p
->w_zdisplay
&& *b2
== '8'))
2077 if (++p
->w_zauto
< 6)
2079 if (p
->w_zauto
== 6)
2084 WriteString(p
, bp
, i
+ 1 - 6);
2085 WriteString(p
, "\r\n", 2);
2086 zmodem_found(p
, *b2
== '1', b2
+ 1, len
- i
- 1);
2089 else if (p
->w_zauto
== 7 || *b2
== '8')
2091 int se
= p
->w_zdisplay
->d_blocked
== 2 ? 'O' : '\212';
2092 for (; i
< len
; i
++, b2
++)
2099 D_readev
.condpos
= D_readev
.condneg
= 0;
2103 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2110 p
->w_zauto
= *b2
== '*' ? (p
->w_zauto
== 2 ? 2 : 1) : 0;
2112 if (p
->w_zauto
== 0 && bp
[len
- 1] == '*')
2113 p
->w_zauto
= len
> 1 && bp
[len
- 2] == '*' ? 2 : 1;
2116 display
= p
->w_zdisplay
;
2125 zmodem_fin(buf
, len
, data
)
2134 RcLine(buf
, strlen(buf
) + 1);
2137 s
= "\030\030\030\030\030\030\030\030\030\030";
2144 zmodem_found(p
, send
, bp
, len
)
2152 extern int zmodem_mode
;
2154 /* check for abort sequence */
2156 for (i
= 0; i
< len
; i
++)
2161 if (zmodem_mode
== 3 || (zmodem_mode
== 1 && p
->w_type
!= W_TYPE_PLAIN
))
2163 struct display
*d
, *olddisplay
;
2165 olddisplay
= display
;
2167 if (!d
|| d
->d_fore
!= p
)
2168 for (d
= displays
; d
; d
= d
->d_next
)
2171 if (!d
&& p
->w_layer
.l_cvlist
)
2172 d
= p
->w_layer
.l_cvlist
->c_display
;
2179 p
->w_zdisplay
= display
;
2180 D_blocked
= 2 + send
;
2181 flayer
= &p
->w_layer
;
2184 evdeq(&D_blockedev
);
2185 D_readev
.condpos
= &const_IOSIZE
;
2186 D_readev
.condneg
= &p
->w_inlen
;
2189 SetRendition(&mchar_blank
);
2190 AddStr("Zmodem active\r\n\r\n");
2191 AddStr(send
? "**\030B01" : "**\030B00");
2194 display
= olddisplay
;
2197 flayer
= &p
->w_layer
;
2198 Input(":", 100, INP_COOKED
, zmodem_fin
, NULL
, 0);
2199 s
= send
? zmodem_sendcmd
: zmodem_recvcmd
;
2209 struct display
*olddisplay
= display
;
2210 struct layer
*oldflayer
= flayer
;
2213 if (p
->w_savelayer
&& p
->w_savelayer
->l_next
)
2215 if (oldflayer
== p
->w_savelayer
)
2216 oldflayer
= flayer
->l_next
;
2217 flayer
= p
->w_savelayer
;
2222 LRefreshAll(&p
->w_layer
, 0);
2228 D_readev
.condpos
= D_readev
.condneg
= 0;
2229 Activate(D_fore
? D_fore
->w_norefresh
: 0);
2231 display
= olddisplay
;