add AUTO_CRLF flag

This commit is contained in:
Sean Middleditch 2009-03-16 16:47:27 -04:00
parent a7a6b31e1c
commit c337ba6bca
3 changed files with 29 additions and 1 deletions

12
README
View File

@ -75,7 +75,17 @@ IIa. Initialization
The flags parameter can be any of the following flag constants
bit-or'd together, or 0 to leave all options disabled.
LIBTELNET_FLAG_PROXY - operate in proxy mode
LIBTELNET_FLAG_PROXY
Operate in proxy mode. This disables the RFC1143 support and
enables automatic detection of COMPRESS2 streams.
LIBTELNET_FLAG_AUTO_CRLF
Automatically translate C newlines (\n) into the TELNET
newline marker, CRLF (\r\n). This also translates the C
carriage return (\r) into the TELNET-correct CRNUL (\r\0).
Note that this only affects data that is sent. Received
data is untranslated, even with this flag set.
boid libtelnet_free(libtelnet_t *telnet);
Releases any internal memory allocated by libtelnet. This must

View File

@ -794,7 +794,10 @@ void libtelnet_send_negotiate(libtelnet_t *telnet, unsigned char cmd,
/* send non-command data (escapes IAC bytes) */
void libtelnet_send_data(libtelnet_t *telnet, unsigned char *buffer,
unsigned int size) {
static unsigned char CRLF[] = { '\r', '\n' };
static unsigned char CRNUL[] = { '\r', '\0' };
unsigned int i, l;
for (l = i = 0; i != size; ++i) {
/* dump prior portion of text, send escaped bytes */
if (buffer[i] == LIBTELNET_IAC) {
@ -805,6 +808,20 @@ void libtelnet_send_data(libtelnet_t *telnet, unsigned char *buffer,
/* send escape */
libtelnet_send_command(telnet, LIBTELNET_IAC);
/* automatic translation of \n -> CRLF and \r -> CRNUL */
} else if (telnet->flags & LIBTELNET_FLAG_AUTO_CRLF &&
(buffer[i] == '\r' || buffer[i] == '\n')) {
/* dump prior text if any */
if (i != l)
_send(telnet, buffer + l, i - l);
l = i + 1;
/* translate */
if (buffer[i] == '\r')
_send(telnet, CRNUL, 2);
else
_send(telnet, CRLF, 2);
}
}

View File

@ -92,6 +92,7 @@ typedef enum libtelnet_event_type_t libtelnet_event_type_t;
/* libtelnet feature flags */
#define LIBTELNET_FLAG_PROXY (1<<0)
#define LIBTELNET_FLAG_AUTO_CRLF (1<<1)
#define LIBTELNET_PFLAG_DEFLATE (1<<7)