Skip to content
Snippets Groups Projects
Commit 5f101ad7 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add Telnet Gateway "Raw TCP" (TG_RAW) and "Expand Bare-LF to CRLF" TG_EXPANDLF

The expansion of LF to CRLF (with TG_EXPANDLF) is on receive.

For Nelgin
parent 399523ec
No related branches found
No related tags found
1 merge request!455Update branch with changes from master
Pipeline #6559 passed
......@@ -463,6 +463,8 @@ var TG_NOTERMTYPE =(1<<8); /* Request client "DONT TERM_TYPE" */
var TG_SENDPASS =(1<<9); /* DEPRECATED */
var TG_NOLF =(1<<10); /* Do not send line-feeds */
var TG_RLOGINSWAP =(1<<11); /* Swap the RLogin alias/real-names */
var TG_RAW =(1<<12); /* Connecting to a raw TCP server */
var TG_EXPANDLF =(1<<13); /* Expand incoming LF to CRLF */
/********************************************/
/********************************************/
......
......@@ -790,6 +790,8 @@ enum { /* readmail and delmailidx which types */
#define TG_SENDPASS (1<<9) /* Send password instead of real name (RLogin) - DEPRECATED (it sent the password as the server user name) */
#define TG_NOLF (1<<10) /* Do not send line-feeds (opposite of TG_CRLF) */
#define TG_RLOGINSWAP (1<<11) /* Swap the RLogin alias/real-names */
#define TG_RAW (1<<12) /* Connecting to a raw TCP server */
#define TG_EXPANDLF (1<<13) /* Expand incoming LF to CRLF */
enum { /* Values for 'mode' in listfileinfo */
FI_INFO /* Just list file information */
......
......@@ -215,6 +215,23 @@ struct TelnetProxy
}
}; // struct TelnetProxy
/*****************************************************************************/
// Expands Sole-LF to CR/LF
/*****************************************************************************/
static uint8_t* expand_lf(uint8_t* inbuf, size_t inlen, uint8_t* outbuf, size_t& outlen)
{
size_t i, j;
if(outlen < 1 || outbuf == nullptr)
return nullptr;
for(i = j = 0; i < inlen && j < (outlen - 1); ++i) {
if(inbuf[i] == '\n' && (i == 0 || inbuf[i - 1] != '\r'))
outbuf[j++] = '\r';
outbuf[j++] = inbuf[i];
}
outlen = j;
return outbuf;
}
bool sbbs_t::telnet_gate(char* destaddr, uint mode, unsigned timeout, str_list_t send_strings, char* client_user_name, char* server_user_name, char* term_type)
{
......@@ -316,7 +333,7 @@ bool sbbs_t::telnet_gate(char* destaddr, uint mode, unsigned timeout, str_list_t
if(sendsocket(remote_socket,(char*)buf,l) != (ssize_t)l)
lprintf(LOG_WARNING, "Error %d sending %lu bytes to server: %s", ERROR_VALUE, l, destaddr);
mode|=TG_NOLF; /* Send LF (to remote host) when Telnet client sends CRLF (when not in binary mode) */
} else {
} else if(!(mode & TG_RAW)) {
proxy = new TelnetProxy(remote_socket, this);
if(!(mode & TG_ECHO))
proxy->request_opt(TELNET_DO, TELNET_ECHO);
......@@ -434,9 +451,15 @@ bool sbbs_t::telnet_gate(char* destaddr, uint mode, unsigned timeout, str_list_t
break;
}
uint8_t* p = buf;
if(!(mode & (TG_RLOGIN | TG_PASSTHRU)))
if(!(mode & (TG_RLOGIN | TG_PASSTHRU | TG_RAW)))
p = proxy->recv(buf, rd, rd);
RingBufWrite(&outbuf,p,rd);
if(mode & TG_EXPANDLF) {
uint8_t expanded_buf[sizeof(buf) * 2];
size_t expanded_len = sizeof(expanded_buf);
expand_lf(p, rd, expanded_buf, expanded_len);
RingBufWrite(&outbuf, expanded_buf, expanded_len);
} else
RingBufWrite(&outbuf,p,rd);
}
console&=~CON_RAW_IN;
telnet_mode&=~TELNET_MODE_GATE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment