1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 09:58:01 +00:00

Hammer out some char * vs unsigned char * problems. In general, I've kept

any buffers used internally by telnet.c as unsigned char, and cast to/from
char * when interacting with the rest of PuTTY.  Not actually tested, since
I'm some way from actually being able to link this yet.

Also clean up a couple of style warnings from Apple's compilers.

[originally from svn r2447]
This commit is contained in:
Ben Harris 2003-01-04 16:42:53 +00:00
parent f10bd67f3a
commit 1e158ceb91

View File

@ -209,7 +209,7 @@ typedef struct telnet_tag {
int bufsize; int bufsize;
int in_synch; int in_synch;
int sb_opt, sb_len; int sb_opt, sb_len;
char *sb_buf; unsigned char *sb_buf;
int sb_size; int sb_size;
enum { enum {
@ -254,7 +254,7 @@ static void send_opt(Telnet telnet, int cmd, int option)
b[0] = IAC; b[0] = IAC;
b[1] = cmd; b[1] = cmd;
b[2] = option; b[2] = option;
telnet->bufsize = sk_write(telnet->s, b, 3); telnet->bufsize = sk_write(telnet->s, (char *)b, 3);
log_option(telnet, "client", cmd, option); log_option(telnet, "client", cmd, option);
} }
@ -386,11 +386,11 @@ static void process_subneg(Telnet telnet)
b[1] = SB; b[1] = SB;
b[2] = TELOPT_TSPEED; b[2] = TELOPT_TSPEED;
b[3] = TELQUAL_IS; b[3] = TELQUAL_IS;
strcpy(b + 4, cfg.termspeed); strcpy((char *)(b + 4), cfg.termspeed);
n = 4 + strlen(cfg.termspeed); n = 4 + strlen(cfg.termspeed);
b[n] = IAC; b[n] = IAC;
b[n + 1] = SE; b[n + 1] = SE;
telnet->bufsize = sk_write(telnet->s, b, n + 2); telnet->bufsize = sk_write(telnet->s, (char *)b, n + 2);
logevent(telnet->frontend, "server:\tSB TSPEED SEND"); logevent(telnet->frontend, "server:\tSB TSPEED SEND");
logbuf = dupprintf("client:\tSB TSPEED IS %s", cfg.termspeed); logbuf = dupprintf("client:\tSB TSPEED IS %s", cfg.termspeed);
logevent(telnet->frontend, logbuf); logevent(telnet->frontend, logbuf);
@ -412,7 +412,7 @@ static void process_subneg(Telnet telnet)
'a' : cfg.termtype[n]); 'a' : cfg.termtype[n]);
b[n + 4] = IAC; b[n + 4] = IAC;
b[n + 5] = SE; b[n + 5] = SE;
telnet->bufsize = sk_write(telnet->s, b, n + 6); telnet->bufsize = sk_write(telnet->s, (char *)b, n + 6);
b[n + 4] = 0; b[n + 4] = 0;
logevent(telnet->frontend, "server:\tSB TTYPE SEND"); logevent(telnet->frontend, "server:\tSB TTYPE SEND");
logbuf = dupprintf("client:\tSB TTYPE IS %s", b + 4); logbuf = dupprintf("client:\tSB TTYPE IS %s", b + 4);
@ -490,7 +490,7 @@ static void process_subneg(Telnet telnet)
} }
b[n++] = IAC; b[n++] = IAC;
b[n++] = SE; b[n++] = SE;
telnet->bufsize = sk_write(telnet->s, b, n); telnet->bufsize = sk_write(telnet->s, (char *)b, n);
logbuf = dupprintf("client:\tSB %s IS %s", telopt(telnet->sb_opt), logbuf = dupprintf("client:\tSB %s IS %s", telopt(telnet->sb_opt),
n == 6 ? "<nothing>" : "<stuff>"); n == 6 ? "<nothing>" : "<stuff>");
logevent(telnet->frontend, logbuf); logevent(telnet->frontend, logbuf);
@ -584,7 +584,7 @@ static void do_telnet_read(Telnet telnet, char *buf, int len)
else { else {
subneg_addchar: subneg_addchar:
if (telnet->sb_len >= telnet->sb_size) { if (telnet->sb_len >= telnet->sb_size) {
char *newbuf; unsigned char *newbuf;
telnet->sb_size += SB_DELTA; telnet->sb_size += SB_DELTA;
newbuf = (telnet->sb_buf ? newbuf = (telnet->sb_buf ?
srealloc(telnet->sb_buf, telnet->sb_size) : srealloc(telnet->sb_buf, telnet->sb_size) :
@ -687,7 +687,7 @@ static char *telnet_init(void *frontend_handle, void **backend_handle,
sfree(buf); sfree(buf);
} }
addr = name_lookup(host, port, realhost); addr = name_lookup(host, port, realhost);
if ((err = sk_addr_error(addr))) if ((err = sk_addr_error(addr)) != NULL)
return err; return err;
if (port < 0) if (port < 0)
@ -705,7 +705,7 @@ static char *telnet_init(void *frontend_handle, void **backend_handle,
} }
telnet->s = new_connection(addr, *realhost, port, 0, 1, telnet->s = new_connection(addr, *realhost, port, 0, 1,
nodelay, (Plug) telnet); nodelay, (Plug) telnet);
if ((err = sk_socket_error(telnet->s))) if ((err = sk_socket_error(telnet->s)) != NULL)
return err; return err;
sk_addr_free(addr); sk_addr_free(addr);
@ -743,7 +743,7 @@ static char *telnet_init(void *frontend_handle, void **backend_handle,
static int telnet_send(void *handle, char *buf, int len) static int telnet_send(void *handle, char *buf, int len)
{ {
Telnet telnet = (Telnet) handle; Telnet telnet = (Telnet) handle;
char *p; unsigned char *p, *end;
static unsigned char iac[2] = { IAC, IAC }; static unsigned char iac[2] = { IAC, IAC };
static unsigned char cr[2] = { CR, NUL }; static unsigned char cr[2] = { CR, NUL };
#if 0 #if 0
@ -753,17 +753,18 @@ static int telnet_send(void *handle, char *buf, int len)
if (telnet->s == NULL) if (telnet->s == NULL)
return 0; return 0;
p = buf; p = (unsigned char *)buf;
while (p < buf + len) { end = (unsigned char *)(buf + len);
char *q = p; while (p < end) {
unsigned char *q = p;
while (p < buf + len && iswritable((unsigned char) *p)) while (p < end && iswritable(*p))
p++; p++;
telnet->bufsize = sk_write(telnet->s, q, p - q); telnet->bufsize = sk_write(telnet->s, (char *)q, p - q);
while (p < buf + len && !iswritable((unsigned char) *p)) { while (p < end && !iswritable(*p)) {
telnet->bufsize = telnet->bufsize =
sk_write(telnet->s, (unsigned char) *p == IAC ? iac : cr, 2); sk_write(telnet->s, (char *)(*p == IAC ? iac : cr), 2);
p++; p++;
} }
} }
@ -809,7 +810,7 @@ static void telnet_size(void *handle, int width, int height)
if (b[n-1] == IAC) b[n++] = IAC; /* duplicate any IAC byte occurs */ if (b[n-1] == IAC) b[n++] = IAC; /* duplicate any IAC byte occurs */
b[n++] = IAC; b[n++] = IAC;
b[n++] = SE; b[n++] = SE;
telnet->bufsize = sk_write(telnet->s, b, n); telnet->bufsize = sk_write(telnet->s, (char *)b, n);
logbuf = dupprintf("client:\tSB NAWS %d,%d", logbuf = dupprintf("client:\tSB NAWS %d,%d",
telnet->term_width, telnet->term_height); telnet->term_width, telnet->term_height);
logevent(telnet->frontend, logbuf); logevent(telnet->frontend, logbuf);
@ -831,51 +832,51 @@ static void telnet_special(void *handle, Telnet_Special code)
switch (code) { switch (code) {
case TS_AYT: case TS_AYT:
b[1] = AYT; b[1] = AYT;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_BRK: case TS_BRK:
b[1] = BREAK; b[1] = BREAK;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_EC: case TS_EC:
b[1] = EC; b[1] = EC;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_EL: case TS_EL:
b[1] = EL; b[1] = EL;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_GA: case TS_GA:
b[1] = GA; b[1] = GA;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_NOP: case TS_NOP:
b[1] = NOP; b[1] = NOP;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_ABORT: case TS_ABORT:
b[1] = ABORT; b[1] = ABORT;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_AO: case TS_AO:
b[1] = AO; b[1] = AO;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_IP: case TS_IP:
b[1] = IP; b[1] = IP;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_SUSP: case TS_SUSP:
b[1] = SUSP; b[1] = SUSP;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_EOR: case TS_EOR:
b[1] = EOR; b[1] = EOR;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_EOF: case TS_EOF:
b[1] = xEOF; b[1] = xEOF;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
break; break;
case TS_EOL: case TS_EOL:
/* In BINARY mode, CR-LF becomes just CR. */ /* In BINARY mode, CR-LF becomes just CR. */
@ -886,8 +887,8 @@ static void telnet_special(void *handle, Telnet_Special code)
break; break;
case TS_SYNCH: case TS_SYNCH:
b[1] = DM; b[1] = DM;
telnet->bufsize = sk_write(telnet->s, b, 1); telnet->bufsize = sk_write(telnet->s, (char *)b, 1);
telnet->bufsize = sk_write_oob(telnet->s, b + 1, 1); telnet->bufsize = sk_write_oob(telnet->s, (char *)(b + 1), 1);
break; break;
case TS_RECHO: case TS_RECHO:
if (telnet->opt_states[o_echo.index] == INACTIVE || if (telnet->opt_states[o_echo.index] == INACTIVE ||
@ -905,7 +906,7 @@ static void telnet_special(void *handle, Telnet_Special code)
case TS_PING: case TS_PING:
if (telnet->opt_states[o_they_sga.index] == ACTIVE) { if (telnet->opt_states[o_they_sga.index] == ACTIVE) {
b[1] = NOP; b[1] = NOP;
telnet->bufsize = sk_write(telnet->s, b, 2); telnet->bufsize = sk_write(telnet->s, (char *)b, 2);
} }
break; break;
} }