#define SB_DELTA 1024
-static void c_write1(Telnet telnet, int c)
+static void c_write(Telnet telnet, char *buf, int len)
{
int backlog;
- char cc = (char) c;
- backlog = from_backend(telnet->frontend, 0, &cc, 1);
+ backlog = from_backend(telnet->frontend, 0, buf, len);
sk_set_frozen(telnet->s, backlog > TELNET_MAX_BACKLOG);
}
static void do_telnet_read(Telnet telnet, char *buf, int len)
{
+ char *outbuf = NULL;
+ int outbuflen = 0, outbufsize = 0;
+
+#define ADDTOBUF(c) do { \
+ if (outbuflen >= outbufsize) { \
+ outbufsize = outbuflen + 256; \
+ outbuf = sresize(outbuf, outbufsize, char); \
+ } \
+ outbuf[outbuflen++] = (c); \
+} while (0)
while (len--) {
int c = (unsigned char) *buf++;
telnet->state = SEENIAC;
else {
if (!telnet->in_synch)
- c_write1(telnet, c);
+ ADDTOBUF(c);
#if 1
/* I can't get the F***ing winsock to insert the urgent IAC
} else {
/* ignore everything else; print it if it's IAC */
if (c == IAC) {
- c_write1(telnet, c);
+ ADDTOBUF(c);
}
telnet->state = TOP_LEVEL;
}
break;
}
}
+
+ if (outbuflen)
+ c_write(telnet, outbuf, outbuflen);
+ sfree(outbuf);
}
static void telnet_log(Plug plug, int type, SockAddr addr, int port,