Commit 45722259 authored by deuce's avatar deuce
Browse files

Remove more thread-unsafe global usage from telnet_io.

Extract the term size method used by SSH and pty into a function, and remove
the need to change the video mode.
parent 1036eac7
......@@ -18,6 +18,7 @@
#include "window.h"
#include "term.h"
#include "menu.h"
#include "vidmodes.h"
struct sort_order_info {
char *name;
......@@ -1996,3 +1997,30 @@ get_emulation_str(cterm_emulation_t emu)
}
}
void
get_term_size(struct bbslist *bbs, int *cols, int *rows)
{
int cmode = find_vmode(screen_to_ciolib(bbs->screen_mode));
if(vparams[cmode].cols < 80) {
if (cols)
*cols=40;
}
else {
if(vparams[cmode].cols < 132) {
if (cols)
*cols=80;
}
else {
if (cols)
*cols=132;
}
}
if (rows) {
*rows=vparams[cmode].rows;
if(!bbs->nostatus)
(*rows)--;
if(*rows<24)
*rows=24;
}
}
......@@ -107,5 +107,6 @@ int edit_list(struct bbslist **list, struct bbslist *item,char *listpath,int isd
int get_rate_num(int rate);
cterm_emulation_t get_emulation(struct bbslist *bbs);
const char *get_emulation_str(cterm_emulation_t emu);
void get_term_size(struct bbslist *bbs, int *cols, int *rows);
#endif
......@@ -389,10 +389,9 @@ int pty_connect(struct bbslist *bbs)
{
struct winsize ws;
struct termios ts;
struct text_info ti;
char *termcap;
int cols, rows;
/* Init ti */
ts.c_iflag = TTYDEF_IFLAG;
ts.c_oflag = TTYDEF_OFLAG;
ts.c_lflag = TTYDEF_LFLAG;
......@@ -400,30 +399,13 @@ int pty_connect(struct bbslist *bbs)
memcpy(ts.c_cc,ttydefchars,sizeof(ts.c_cc));
cfsetspeed(&ts, 115200);
/* Horrible way to determine the screen size */
textmode(screen_to_ciolib(bbs->screen_mode));
gettextinfo(&ti);
if(ti.screenwidth < 80)
ws.ws_col=40;
else {
if(ti.screenwidth < 132)
ws.ws_col=80;
else
ws.ws_col=132;
}
ws.ws_row=ti.screenheight;
if(!bbs->nostatus)
ws.ws_row--;
if(ws.ws_row<24)
ws.ws_row=24;
get_term_size(bbs, &cols, &rows);
ws.ws_col = cols;
ws.ws_row = rows;
child_pid = forkpty(&master, NULL, &ts, &ws);
switch(child_pid) {
case -1:
load_font_files();
textmode(ti.currmode);
settitle("SyncTERM");
return(-1);
case 0: /* Child */
setenv("TERM",settings.TERM,1);
......@@ -467,25 +449,15 @@ int pty_connect(struct bbslist *bbs)
exit(1);
}
if(!create_conn_buf(&conn_inbuf, BUFFER_SIZE)) {
load_font_files();
textmode(ti.currmode);
settitle("SyncTERM");
if(!create_conn_buf(&conn_inbuf, BUFFER_SIZE))
return(-1);
}
if(!create_conn_buf(&conn_outbuf, BUFFER_SIZE)) {
destroy_conn_buf(&conn_inbuf);
load_font_files();
textmode(ti.currmode);
settitle("SyncTERM");
return(-1);
}
if(!(conn_api.rd_buf=(unsigned char *)malloc(BUFFER_SIZE))) {
destroy_conn_buf(&conn_inbuf);
destroy_conn_buf(&conn_outbuf);
load_font_files();
textmode(ti.currmode);
settitle("SyncTERM");
return(-1);
}
conn_api.rd_buf_size=BUFFER_SIZE;
......@@ -493,9 +465,6 @@ int pty_connect(struct bbslist *bbs)
free(conn_api.rd_buf);
destroy_conn_buf(&conn_inbuf);
destroy_conn_buf(&conn_outbuf);
load_font_files();
textmode(ti.currmode);
settitle("SyncTERM");
return(-1);
}
conn_api.wr_buf_size=BUFFER_SIZE;
......
......@@ -30,7 +30,7 @@ void telnet_input_thread(void *args)
size_t buffer;
char rbuf[BUFFER_SIZE];
char *buf;
cterm_emulation_t emu = *(cterm_emulation_t *)args;
struct bbslist *bbs = args;
SetThreadName("Telnet Input");
conn_api.input_thread_running=1;
......@@ -59,7 +59,7 @@ void telnet_input_thread(void *args)
break;
}
if(rd>0)
buf=(char *)telnet_interpret(conn_api.rd_buf, rd, (BYTE *)rbuf, &rd, emu);
buf=(char *)telnet_interpret(conn_api.rd_buf, rd, (BYTE *)rbuf, &rd, bbs);
buffered=0;
while(buffered < rd) {
pthread_mutex_lock(&(conn_inbuf.mutex));
......@@ -130,8 +130,6 @@ void telnet_output_thread(void *args)
int telnet_connect(struct bbslist *bbs)
{
cterm_emulation_t *emu;
init_uifc(TRUE, TRUE);
telnet_log_level = bbs->telnet_loglevel;
......@@ -165,10 +163,8 @@ int telnet_connect(struct bbslist *bbs)
memset(telnet_local_option,0,sizeof(telnet_local_option));
memset(telnet_remote_option,0,sizeof(telnet_remote_option));
emu = malloc(sizeof(cterm_emulation_t));
*emu = get_emulation(bbs);
_beginthread(telnet_output_thread, 0, NULL);
_beginthread(telnet_input_thread, 0, emu);
_beginthread(telnet_input_thread, 0, bbs);
uifc.pop(NULL);
......
......@@ -146,7 +146,6 @@ int ssh_connect(struct bbslist *bbs)
char password[MAX_PASSWD_LEN+1];
char username[MAX_USER_LEN+1];
int rows,cols;
struct text_info ti;
const char *term;
init_uifc(TRUE, TRUE);
......@@ -240,23 +239,7 @@ int ssh_connect(struct bbslist *bbs)
term = get_emulation_str(get_emulation(bbs));
status=cl.SetAttributeString(ssh_session, CRYPT_SESSINFO_SSH_TERMINAL, term, strlen(term));
/* Horrible way to determine the screen size */
textmode(screen_to_ciolib(bbs->screen_mode));
gettextinfo(&ti);
if(ti.screenwidth < 80)
cols=40;
else {
if(ti.screenwidth < 132)
cols=80;
else
cols=132;
}
rows=ti.screenheight;
if(!bbs->nostatus)
rows--;
if(rows<24)
rows=24;
get_term_size(bbs, &cols, &rows);
uifc.pop(NULL);
uifc.pop("Setting Terminal Width");
......
......@@ -1569,7 +1569,11 @@ int main(int argc, char **argv)
while((!quitting) && (bbs!=NULL || (bbs=show_bbslist(last_bbs, FALSE))!=NULL)) {
gettextinfo(&txtinfo); /* Current mode may have changed while in show_bbslist() */
FREE_AND_NULL(last_bbs);
if(!conn_connect(bbs)) {
if(conn_connect(bbs)) {
load_font_files();
textmode(txtinfo.currmode);
settitle("SyncTERM");
} else {
/* ToDo: Update the entry with new lastconnected */
/* ToDo: Disallow duplicate entries */
bbs->connected=time(NULL);
......
......@@ -5,8 +5,6 @@
#include <stdlib.h>
#include <string.h>
#include "term.h"
#include "genwrap.h"
#include "sockwrap.h"
#ifndef TELNET_NO_DLL
......@@ -90,7 +88,7 @@ void request_telnet_opt(uchar cmd, uchar opt)
send_telnet_cmd(cmd,opt);
}
BYTE* telnet_interpret(BYTE* inbuf, int inlen, BYTE* outbuf, int *outlen, cterm_emulation_t emu)
BYTE* telnet_interpret(BYTE* inbuf, int inlen, BYTE* outbuf, int *outlen, struct bbslist *bbs)
{
BYTE command;
BYTE option;
......@@ -158,12 +156,13 @@ BYTE* telnet_interpret(BYTE* inbuf, int inlen, BYTE* outbuf, int *outlen, cterm_
/* sub-option terminated */
if(option==TELNET_TERM_TYPE && telnet_cmd[3]==TELNET_TERM_SEND) {
char buf[32];
const char *emu = get_emulation_str(get_emulation(bbs));
int len=sprintf(buf,"%c%c%c%c%s%c%c"
,TELNET_IAC,TELNET_SB
,TELNET_TERM_TYPE,TELNET_TERM_IS
,get_emulation_str(emu)
,emu
,TELNET_IAC,TELNET_SE);
lprintf(LOG_INFO,"TX: Terminal Type is %s", get_emulation_str(emu));
lprintf(LOG_INFO,"TX: Terminal Type is %s", emu);
putcom(buf,len);
request_telnet_opt(TELNET_WILL, TELNET_NEGOTIATE_WINDOW_SIZE);
}
......@@ -197,18 +196,21 @@ BYTE* telnet_interpret(BYTE* inbuf, int inlen, BYTE* outbuf, int *outlen, cterm_
}
if(command==TELNET_DO && option==TELNET_NEGOTIATE_WINDOW_SIZE) {
int rows, cols;
BYTE buf[32];
get_term_size(bbs, &cols, &rows);
buf[0]=TELNET_IAC;
buf[1]=TELNET_SB;
buf[2]=TELNET_NEGOTIATE_WINDOW_SIZE;
buf[3]=(term.width>>8)&0xff;
buf[4]=term.width&0xff;
buf[5]=(term.height>>8)&0xff;
buf[6]=term.height&0xff;
buf[3]=(cols>>8)&0xff;
buf[4]=cols&0xff;
buf[5]=(rows>>8)&0xff;
buf[6]=rows&0xff;
buf[7]=TELNET_IAC;
buf[8]=TELNET_SE;
lprintf(LOG_INFO,"TX: Window Size is %u x %u"
,term.width, term.height);
,cols, rows);
putcom((char *)buf,9);
}
......
......@@ -10,11 +10,12 @@
#endif
#include <cterm.h>
#include "telnet.h"
#include "bbslist.h"
extern uchar telnet_local_option[0x100];
extern uchar telnet_remote_option[0x100];
BYTE* telnet_interpret(BYTE* inbuf, int inlen, BYTE* outbuf, int *outlen, cterm_emulation_t emu);
BYTE* telnet_interpret(BYTE* inbuf, int inlen, BYTE* outbuf, int *outlen, struct bbslist *bbs);
BYTE* telnet_expand(BYTE* inbuf, size_t inlen, BYTE* outbuf, size_t *newlen);
void request_telnet_opt(uchar cmd, uchar opt);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment