diff options
-rw-r--r-- | common/sys/telnet.c | 36 | ||||
-rw-r--r-- | include/cmsys.h | 18 | ||||
-rw-r--r-- | include/proto.h | 2 | ||||
-rw-r--r-- | mbbsd/mbbsd.c | 21 | ||||
-rw-r--r-- | mbbsd/telnet.c | 20 |
5 files changed, 59 insertions, 38 deletions
diff --git a/common/sys/telnet.c b/common/sys/telnet.c index 14b39c39..b0c5f1d7 100644 --- a/common/sys/telnet.c +++ b/common/sys/telnet.c @@ -46,9 +46,9 @@ void telnet_ctx_init(TelnetCtx *ctx, const struct TelnetCallback *callback, int ctx->fd = fd; } -void telnet_ctx_set_ccctx(TelnetCtx *ctx, void *ccctx) +void telnet_ctx_set_cc_arg(TelnetCtx *ctx, void *cc_arg) { - ctx->ccctx = ccctx; + ctx->cc_arg = cc_arg; } /* We are the boss. We don't respect to client. @@ -119,15 +119,15 @@ telnet_handler(TelnetCtx *ctx, unsigned char c) } /* hash client telnet sequences */ - if (ctx->ccctx && ctx->callback->update_client_code) { + if (ctx->cc_arg && ctx->callback->update_client_code) { void (*cb)(void *, unsigned char) = ctx->callback->update_client_code; if(ctx->iac_state == IAC_WAIT_SE) { // skip suboption } else { if(ctx->iac_quote) - cb(ctx->ccctx, IAC); - cb(ctx->ccctx, c); + cb(ctx->cc_arg, IAC); + cb(ctx->cc_arg, c); } } @@ -301,38 +301,38 @@ telnet_handler(TelnetCtx *ctx, unsigned char c) int w = (ctx->iac_buf[1] << 8) + (ctx->iac_buf[2]); int h = (ctx->iac_buf[3] << 8) + (ctx->iac_buf[4]); if (ctx->callback->term_resize) - ctx->callback->term_resize(w, h); - if (ctx->ccctx && + ctx->callback->term_resize(ctx->resize_arg, w, h); + if (ctx->cc_arg && ctx->callback->update_client_code) { void (*cb)(void *, unsigned char) = ctx->callback->update_client_code; - cb(ctx->ccctx, ctx->iac_buf[0]); + cb(ctx->cc_arg, ctx->iac_buf[0]); if(w==80 && h==24) - cb(ctx->ccctx, 1); + cb(ctx->cc_arg, 1); else if(w==80) - cb(ctx->ccctx, 2); + cb(ctx->cc_arg, 2); else if(h==24) - cb(ctx->ccctx, 3); + cb(ctx->cc_arg, 3); else - cb(ctx->ccctx, 4); - cb(ctx->ccctx, IAC); - cb(ctx->ccctx, SE); + cb(ctx->cc_arg, 4); + cb(ctx->cc_arg, IAC); + cb(ctx->cc_arg, SE); } } break; default: - if (ctx->ccctx && + if (ctx->cc_arg && ctx->callback->update_client_code) { void (*cb)(void *, unsigned char) = ctx->callback->update_client_code; int i; for(i=0;i<ctx->iac_buflen;i++) - cb(ctx->ccctx, ctx->iac_buf[i]); - cb(ctx->ccctx, IAC); - cb(ctx->ccctx, SE); + cb(ctx->cc_arg, ctx->iac_buf[i]); + cb(ctx->cc_arg, IAC); + cb(ctx->cc_arg, SE); } break; } diff --git a/include/cmsys.h b/include/cmsys.h index 833dc7aa..040f1995 100644 --- a/include/cmsys.h +++ b/include/cmsys.h @@ -70,7 +70,6 @@ extern int file_exist_record(const char *file, const char *key); extern int file_find_record(const char *file, const char *key); extern int file_delete_record(const char *file, const char *key, int case_sensitive); - /* lock.c */ extern void PttLock(int fd, int start, int size, int mode); @@ -81,6 +80,8 @@ extern int tobindex (const char *addr, int qlen, int (*setsock)(int), int do_lis extern int toconnect(const char *addr); extern int toread (int fd, void *buf, int len); extern int towrite (int fd, const void *buf, int len); +extern int send_remote_fd(int tunnel, int fd); +extern int recv_remote_fd(int tunnel); /* sort.c */ extern int cmp_int(const void *a, const void *b); @@ -175,14 +176,12 @@ extern void Vector_sublist(const struct Vector *src, struct Vector *dst, const c extern int Vector_remove(struct Vector *self, const char *name); extern int Vector_search(const struct Vector *self, const char *name); -extern int send_remote_fd(int tunnel, int fd); -extern int recv_remote_fd(int tunnel); - /* telnet.c */ struct TelnetCallback { - void (*term_resize)(int w, int h); - void (*update_client_code)(void *ccctx, unsigned char seq); + void (*term_resize) (void *resize_arg, int w, int h); + void (*update_client_code) (void *cc_arg, unsigned char seq); }; + #define TELNET_IAC_MAXLEN (16) struct TelnetCtx { @@ -196,13 +195,16 @@ struct TelnetCtx { unsigned int iac_buflen; const struct TelnetCallback *callback; - void *ccctx; // client code detection contex + + // callback parameters + void *resize_arg; // term_resize + void *cc_arg; // update_client_code }; typedef struct TelnetCtx TelnetCtx; extern TelnetCtx *telnet_create_contex(void); extern void telnet_ctx_init(TelnetCtx *ctx, const struct TelnetCallback *callback, int fd); -extern void telnet_ctx_set_ccctx(TelnetCtx *ctx, void *ccctx); +extern void telnet_ctx_set_cc_arg(TelnetCtx *ctx, void *cc_arg); extern void telnet_send_init_cmds(int fd); extern ssize_t telnet_process(TelnetCtx *ctx, unsigned char *buf, size_t size); diff --git a/include/proto.h b/include/proto.h index 793c6a11..8add528e 100644 --- a/include/proto.h +++ b/include/proto.h @@ -420,7 +420,7 @@ int more(const char *fpath, int promptend); /* piaip's new pager, pmore.c */ int pmore(const char *fpath, int promptend); /* piaip's new telnet, telnet.c */ -extern void telnet_init(void); +extern void telnet_init(int do_init_cmd); extern ssize_t tty_read(unsigned char *buf, size_t max); extern void telnet_turnoff_client_detect(void); diff --git a/mbbsd/mbbsd.c b/mbbsd/mbbsd.c index a66767a9..ff9188d8 100644 --- a/mbbsd/mbbsd.c +++ b/mbbsd/mbbsd.c @@ -47,6 +47,7 @@ struct ProgramOption { bool daemon_mode; bool tunnel_mode; enum TermMode term_mode; + int term_width, term_height; int nport; int port[MAX_BINDPORT]; int flag_listenfd; @@ -1386,10 +1387,18 @@ do_aloha(const char *hello) } static void -do_term_init(enum TermMode term_mode) +do_term_init(enum TermMode term_mode, int w, int h) { term_init(); initscr(); + + // if the terminal was already determined, resize for it. + if ((w && (w != t_columns)) || + (h && (h != t_lines )) ) + { + term_resize(w, h); + } + if (term_mode == TermMode_TTY) raise(SIGWINCH); } @@ -1737,7 +1746,8 @@ main(int argc, char *argv[], char *envp[]) return 0; } - do_term_init(option->term_mode); + do_term_init(option->term_mode, + option->term_width, option->term_height); start_client(option); free_program_option(option); @@ -1867,8 +1877,9 @@ tunnel_login(char *argv0, struct ProgramOption *option) strlcpy(option->flag_user, dat.userid, sizeof(option->flag_user)); if (dat.encoding) set_converting_type(dat.encoding); - resizeterm(dat.t_lines, dat.t_cols); - telnet_init(); + option->term_width = dat.t_cols; + option->term_height = dat.t_lines; + telnet_init(0); return 1; } @@ -1996,7 +2007,7 @@ daemon_login(char *argv0, struct ProgramOption *option) sleep(10); exit(0); } - telnet_init(); + telnet_init(1); return 1; } diff --git a/mbbsd/telnet.c b/mbbsd/telnet.c index 45f000a7..f348f08c 100644 --- a/mbbsd/telnet.c +++ b/mbbsd/telnet.c @@ -6,14 +6,21 @@ static char raw_connection = 0; #ifdef DETECT_CLIENT extern void UpdateClientCode(unsigned char c); -void telnet_cb_update_client_code(void *ccctx, unsigned char c) +static void +telnet_cb_update_client_code(void *cc_arg, unsigned char c) { UpdateClientCode(c); } #endif +static void +telnet_cb_resize_term(void *resize_arg, int w, int h) +{ + term_resize(w, h); +} + const static struct TelnetCallback telnet_callback = { - term_resize, + telnet_cb_resize_term, #ifdef DETECT_CLIENT telnet_cb_update_client_code, #else @@ -22,16 +29,17 @@ const static struct TelnetCallback telnet_callback = { }; void -telnet_init(void) +telnet_init(int do_init_cmd) { int fd = 0; TelnetCtx *ctx = &telnet_ctx; raw_connection = 1; telnet_ctx_init(ctx, &telnet_callback, fd); #ifdef DETECT_CLIENT - telnet_ctx_set_ccctx(ctx, (void*)1); + telnet_ctx_set_cc_arg(ctx, (void*)1); #endif - telnet_send_init_cmds(fd); + if (do_init_cmd) + telnet_send_init_cmds(fd); } /* tty_read @@ -58,7 +66,7 @@ void telnet_turnoff_client_detect(void) { TelnetCtx *ctx = &telnet_ctx; - telnet_ctx_set_ccctx(ctx, NULL); + telnet_ctx_set_cc_arg(ctx, NULL); } // vim: sw=4 |