Skip to content

Commit

Permalink
make linux/unix default terminal resize callback
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Nov 30, 2023
1 parent 11a18f0 commit 56666e2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
31 changes: 15 additions & 16 deletions apps/wolfsshd/wolfsshd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1148,21 +1148,9 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
return ret;
}
#else
static int Unix_TermResize(WOLFSSH* ssh, word32 w, word32 h, word32 wp,
word32 hp, void* ctx)
{
struct winsize s;

memset(&s, 0, sizeof s);
s.ws_row = h;
s.ws_col = w;
printf("Resetting terminal size\n");
ioctl(*((int*)ctx), TIOCSWINSZ, &s);
(void)wp;
(void)hp;
(void)ssh;
return 0;
}
#if defined(HAVE_SYS_IOCTL_H)
#include <sys/ioctl.h>
#endif

/* handles creating a new shell env. and maintains SSH connection for incoming
* user input as well as output of the shell.
Expand Down Expand Up @@ -1329,7 +1317,18 @@ static int SHELL_Subsystem(WOLFSSHD_CONNECTION* conn, WOLFSSH* ssh,
return WS_FATAL_ERROR;
}

wolfSSH_SetTerminalResizeCb(ssh, Unix_TermResize);
/* set initial size of terminal based on saved size */
#if defined(HAVE_SYS_IOCTL_H)
{
struct winsize s;

WMEMSET(&s, 0, sizeof s);
s.ws_row = ssh->curX;
s.ws_col = ssh->curY;
ioctl(childFd, TIOCSWINSZ, &s);
}
#endif

wolfSSH_SetTerminalResizeCtx(ssh, (void*)&childFd);
while (ChildRunning) {
byte tmp[2];
Expand Down
37 changes: 31 additions & 6 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,9 @@ void CtxResourceFree(WOLFSSH_CTX* ctx)
#ifdef WOLFSSH_TERM
/* default terminal resize handling callbacks */

#if defined(USE_WINDOWS_API) && defined(WOLFSSH_SSHD)
static int WS_WindowsTermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP,
#ifdef WOLFSSH_SSHD
#if defined(USE_WINDOWS_API)
static int WS_TermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP,
word32 rowP, void* usrCtx)
{
HPCON* term = (HPCON*)usrCtx;
Expand All @@ -667,7 +668,31 @@ static int WS_WindowsTermResize(WOLFSSH* ssh, word32 col, word32 row, word32 col

return ret;
}
#elif defined(HAVE_SYS_IOCTL_H)

#include <sys/ioctl.h>
static int WS_TermResize(WOLFSSH* ssh, word32 col, word32 row, word32 colP,
word32 rowP, void* usrCtx)
{
struct winsize s;
int ret = WS_SUCCESS;
int* fd = (int*)usrCtx;

WMEMSET(&s, 0, sizeof s);
s.ws_row = col;
s.ws_col = row;
s.ws_xpixel = colP;
s.ws_ypixel = rowP;

ioctl(*fd, TIOCSWINSZ, &s);
(void)ssh;
return ret;
}
#else
#define WS_RESIZE_DEFUALT
#warning no default terminal resize callback
#endif
#endif /* WOLFSSH_SSHD */

#endif /* WOLFSSH_TERM */

Expand Down Expand Up @@ -763,10 +788,10 @@ WOLFSSH* SshInit(WOLFSSH* ssh, WOLFSSH_CTX* ctx)
ssh->agentEnabled = ctx->agentEnabled;
#endif

#ifdef WOLFSSH_TERM
#if defined(USE_WINDOWS_API) && defined(WOLFSSH_SSHD)
ssh->termResizeCb = WS_WindowsTermResize;
#endif
#if defined(WOLFSSH_TERM) && defined(WOLFSSH_SSHD)
#ifndef WS_RESIZE_DEFUALT
ssh->termResizeCb = WS_TermResize;
#endif
#endif

if (BufferInit(&ssh->inputBuffer, 0, ctx->heap) != WS_SUCCESS ||
Expand Down

0 comments on commit 56666e2

Please sign in to comment.