Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 17c93c58 authored by rswindell's avatar rswindell
Browse files

Add an "expand_cr" to telnet_expand(), taken from syncterm/telnet_io.c.

Now, it assumes the CR is bare (not followed by LF or NUL), so that should
probably be fixed. But for now, just copied pretty much as is from telnet_io.c
so I can eliminate another version of this function.
parent 6c95c1ab
......@@ -2183,7 +2183,7 @@ void passthru_thread(void* arg)
BYTE* bp = (BYTE*)inbuf;
if(!(sbbs->telnet_mode&TELNET_MODE_OFF))
rd = telnet_expand((BYTE*)inbuf, rd, telnet_buf, sizeof(telnet_buf), &bp);
rd = telnet_expand((BYTE*)inbuf, rd, telnet_buf, sizeof(telnet_buf), /* expand_cr */false, &bp);
if(!RingBufWrite(&sbbs->outbuf, bp, rd)) {
lprintf(LOG_ERR,"Cannot pass from passthru socket to outbuf");
......
......@@ -154,17 +154,25 @@ uchar telnet_opt_nak(uchar cmd)
// 'result' may point to either inbuf (if there were no IACs) or outbuf
// Returns the final byte count of the result
/*****************************************************************************/
size_t telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf, size_t outlen, uchar** result)
size_t telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf, size_t outlen, bool expand_cr, uchar** result)
{
BYTE* first_iac = (BYTE*)memchr(inbuf, TELNET_IAC, inlen);
BYTE* first_cr=NULL;
if(expand_cr)
first_cr = (BYTE*)memchr(inbuf, '\r', inlen);
if(first_iac == NULL) { /* Nothing to expand */
if(first_iac == NULL && first_cr==NULL) { /* Nothing to expand */
if(result != NULL)
*result = (uchar*)inbuf;
return inlen;
}
size_t o = first_iac - inbuf;
size_t o;
if(first_iac != NULL && (first_cr == NULL || first_iac < first_cr))
o = first_iac - inbuf;
else
o = first_cr - inbuf;
memcpy(outbuf, inbuf, o);
for(size_t i = o; i < inlen && o < outlen; i++) {
......@@ -173,6 +181,8 @@ size_t telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf, size_t out
if(o >= outlen)
break;
outbuf[o++] = inbuf[i];
if(expand_cr && inbuf[i] == '\r' && o < outlen)
outbuf[o++] = '\n'; // See RFC5198
}
if(result != NULL)
*result = outbuf;
......
......@@ -38,6 +38,7 @@
#ifndef _TELNET_H
#define _TELNET_H
#include <stdbool.h>
#include "gen_defs.h" /* uchar */
/* commands */
......@@ -165,7 +166,8 @@ DLLEXPORT const char* telnet_cmd_desc(uchar cmd);
DLLEXPORT const char* telnet_opt_desc(uchar opt);
DLLEXPORT uchar telnet_opt_ack(uchar cmd);
DLLEXPORT uchar telnet_opt_nak(uchar cmd);
DLLEXPORT size_t telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf, size_t outlen, uchar** result);
DLLEXPORT size_t telnet_expand(const uchar* inbuf, size_t inlen, uchar* outbuf, size_t outlen
,bool expand_cr, uchar** result);
#ifdef __cplusplus
}
......
......@@ -901,7 +901,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
} else if(telnet_mode&TELNET_MODE_OFF) {
bp=buf;
} else {
rd = telnet_expand(buf, rd, telnet_buf, sizeof(telnet_buf), &bp);
rd = telnet_expand(buf, rd, telnet_buf, sizeof(telnet_buf), /* expand_cr: */false, &bp);
}
if(rd>RingBufFree(&outbuf)) {
lprintf(LOG_ERR,"output buffer overflow");
......@@ -969,7 +969,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
} else if(telnet_mode&TELNET_MODE_OFF) {
bp=buf;
} else {
rd = telnet_expand(buf, rd, telnet_buf, sizeof(telnet_buf), &bp);
rd = telnet_expand(buf, rd, telnet_buf, sizeof(telnet_buf), /* expand_cr: */false, &bp);
}
if(rd>RingBufFree(&outbuf)) {
lprintf(LOG_ERR,"output buffer overflow");
......@@ -1919,7 +1919,7 @@ int sbbs_t::external(const char* cmdline, long mode, const char* startup_dir)
output_len=rd;
}
else
output_len = telnet_expand(buf, rd, output_buf, sizeof(output_buf), &bp);
output_len = telnet_expand(buf, rd, output_buf, sizeof(output_buf), /* expand_cr: */false, &bp);
} else {
if ((mode & EX_STDIO) != EX_STDIO) {
/* LF to CRLF expansion */
......
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