Skip to content
Snippets Groups Projects
Commit aaf100da authored by Henrik (Grubba) Grubbström's avatar Henrik (Grubba) Grubbström
Browse files

Cosmetic fixes.

Rev: lib/modules/Protocols.pmod/TELNET.pmod:1.31
parent a1368cd8
No related branches found
No related tags found
No related merge requests found
// //
// $Id: TELNET.pmod,v 1.30 2008/12/06 16:50:43 grubba Exp $ // $Id: TELNET.pmod,v 1.31 2008/12/06 17:07:31 grubba Exp $
// //
// The TELNET protocol as described by RFC 764 and others. // The TELNET protocol as described by RFC 764 and others.
// //
...@@ -422,7 +422,8 @@ class protocol ...@@ -422,7 +422,8 @@ class protocol
if (sizeof(to_send)) if (sizeof(to_send))
{ {
DWRITE(sprintf("TELNET: We now have data to send! (%d bytes)\n", sizeof(to_send))); DWRITE(sprintf("TELNET: We now have data to send! (%d bytes)\n",
sizeof(to_send)));
if (to_send[0] == 242) { if (to_send[0] == 242) {
// DataMark needs extra quoting... Stupid. // DataMark needs extra quoting... Stupid.
DWRITE("TELNET: Found datamark @ offset 0!\n"); DWRITE("TELNET: Found datamark @ offset 0!\n");
...@@ -472,20 +473,21 @@ class protocol ...@@ -472,20 +473,21 @@ class protocol
//! @param option //! @param option
//! The option to disable. //! The option to disable.
#define CONTROL(OPTIONS,DO,DONT,WILL,WONT,YES,NO) \ #define CONTROL(OPTIONS,DO,DONT,WILL,WONT,YES,NO) \
void send_##DO(int option) \ void send_##DO(int option) \
{ \ { \
if ((option < 0) || (option > 255)) { \ if ((option < 0) || (option > 255)) { \
error( "Bad TELNET option #%d\n", option); \ error( "Bad TELNET option #%d\n", option); \
} \ } \
DWRITE(sprintf("TELNET: send_" #DO "(%s) state is %d\n",lookup_telopt[option] || (string)option,OPTIONS##_options[option])); \ DWRITE(sprintf("TELNET: send_" #DO "(%s) state is %d\n", \
switch(OPTIONS##_options[option]) \ lookup_telopt[option] || (string)option, \
{ \ OPTIONS##_options[option])); \
switch(OPTIONS##_options[option]) { \
case NO: \ case NO: \
case UNKNOWN: \ case UNKNOWN: \
OPTIONS##_options[option]= WANT | YES; \ OPTIONS##_options[option]= WANT | YES; \
DWRITE(sprintf("TELNET: => " #DO " %s\n",lookup_telopt[option] || (string)option)); \ DWRITE(sprintf("TELNET: => " #DO " %s\n", \
lookup_telopt[option] || (string)option)); \
to_send += sprintf("%c%c%c",IAC,DO,option); \ to_send += sprintf("%c%c%c",IAC,DO,option); \
break; \ break; \
\ \
...@@ -500,7 +502,8 @@ class protocol ...@@ -500,7 +502,8 @@ class protocol
break; \ break; \
\ \
default: \ default: \
error("TELNET: Strange remote_options[%d]=%d\n",option,remote_options[option]); \ error("TELNET: Strange remote_options[%d]=%d\n", \
option, remote_options[option]); \
/* ERROR: weird state! */ \ /* ERROR: weird state! */ \
break; \ break; \
} \ } \
...@@ -651,16 +654,7 @@ class protocol ...@@ -651,16 +654,7 @@ class protocol
protected void got_data(mixed ignored, string line) protected void got_data(mixed ignored, string line)
{ {
#ifdef TELNET_DEBUG #ifdef TELNET_DEBUG
werror("TELNET: got_data(\"%s\")\n",Array.map(values(line),lambda(int s) { werror("TELNET: got_data(%O)\n",line);
switch(s)
{
case ' '..'z':
return sprintf("%c",s);
default:
return sprintf("\\0x%02x",s);
}
})*"");
#endif #endif
if (sizeof(line) && (line[0] == DM)) { if (sizeof(line) && (line[0] == DM)) {
...@@ -679,7 +673,8 @@ class protocol ...@@ -679,7 +673,8 @@ class protocol
string part = a[i]; string part = a[i];
if (sizeof(part)) { if (sizeof(part)) {
DWRITE(sprintf("TELNET: Code %s\n", lookup_telnetcodes[part[0]] || (string)part[0])); DWRITE(sprintf("TELNET: Code %s\n",
lookup_telnetcodes[part[0]] || (string)part[0]));
switch (part[0]) { switch (part[0]) {
default: default:
...@@ -713,15 +708,16 @@ class protocol ...@@ -713,15 +708,16 @@ class protocol
#endif #endif
#define HANDLE(OPTIONS,WILL,WONT,DO,DONT) \ #define HANDLE(OPTIONS,WILL,WONT,DO,DONT) \
case WILL:{ \ case WILL: \
{ \
int option = a[i][1]; \ int option = a[i][1]; \
int state = OPTIONS##_options[option]; \ int state = OPTIONS##_options[option]; \
a[i] = a[i][2..]; \ a[i] = a[i][2..]; \
\ \
DWRITE(sprintf(#WILL " %s, state 0x%04x\n", lookup_telopt[option], state)); \ DWRITE(sprintf(#WILL " %s, state 0x%04x\n", \
lookup_telopt[option], state)); \
\ \
switch(state) \ switch(state) { \
{ \
case NO: \ case NO: \
case UNKNOWN: \ case UNKNOWN: \
if (WILL##_callback(option)) \ if (WILL##_callback(option)) \
...@@ -758,16 +754,20 @@ class protocol ...@@ -758,16 +754,20 @@ class protocol
option,remote_options[option]); \ option,remote_options[option]); \
/* Weird state ! */ \ /* Weird state ! */ \
} \ } \
DWRITE(sprintf("TELNET: => " #WILL " %s, state 0x%04x\n", lookup_telopt[option], state)); \ DWRITE(sprintf("TELNET: => " #WILL " %s, state 0x%04x\n", \
lookup_telopt[option], state)); \
set_##OPTIONS##_option(option,state); \ set_##OPTIONS##_option(option,state); \
break;} \ break; \
} \
\ \
case WONT:{ \ case WONT: \
{ \
int option = a[i][1]; \ int option = a[i][1]; \
int state = OPTIONS##_options[option]; \ int state = OPTIONS##_options[option]; \
a[i] = a[i][2..]; \ a[i] = a[i][2..]; \
\ \
DWRITE(sprintf(#WONT " %s, state 0x%04x\n", lookup_telopt[option], state)); \ DWRITE(sprintf(#WONT " %s, state 0x%04x\n", \
lookup_telopt[option], state)); \
\ \
switch(state) \ switch(state) \
{ \ { \
...@@ -801,11 +801,11 @@ class protocol ...@@ -801,11 +801,11 @@ class protocol
/* Weird state */ \ /* Weird state */ \
} \ } \
\ \
DWRITE(sprintf("TELNET: => " #WONT " %s, state 0x%04x\n", lookup_telopt[option], state)); \ DWRITE(sprintf("TELNET: => " #WONT " %s, state 0x%04x\n", \
lookup_telopt[option], state)); \
set_##OPTIONS##_option(option,state); \ set_##OPTIONS##_option(option,state); \
}break } \
break
HANDLE(remote,WILL,WONT,DO,DONT); HANDLE(remote,WILL,WONT,DO,DONT);
HANDLE(local,DO,DONT,WILL,WONT); HANDLE(local,DO,DONT,WILL,WONT);
...@@ -832,16 +832,7 @@ class protocol ...@@ -832,16 +832,7 @@ class protocol
if ((!synch)) { if ((!synch)) {
#ifdef TELNET_DEBUG #ifdef TELNET_DEBUG
werror("TELNET: calling read_callback(X,\"%s\")\n",Array.map(values(line),lambda(int s) { werror("TELNET: calling read_callback(X,%O)\n", line);
switch(s)
{
case ' '..'z':
return sprintf("%c",s);
default:
return sprintf("\\0x%02x",s);
}
})*"");
#endif #endif
call_read_cb(line); call_read_cb(line);
} }
...@@ -878,7 +869,7 @@ class protocol ...@@ -878,7 +869,7 @@ class protocol
//! @param r_cb //! @param r_cb
//! Function to call when data has arrived. //! Function to call when data has arrived.
//! @param w_cb //! @param w_cb
//! Function to call when data can be sent. //! Function to call when the send buffer is empty.
//! @param c_cb //! @param c_cb
//! Function to call when the connection is closed. //! Function to call when the connection is closed.
//! @param callbacks //! @param callbacks
...@@ -910,7 +901,8 @@ class protocol ...@@ -910,7 +901,8 @@ class protocol
read_cb = r_cb; read_cb = r_cb;
write_cb = w_cb; write_cb = w_cb;
close_cb = c_cb; close_cb = c_cb;
DWRITE(sprintf("TELNET: set_nonblocking(): Calling fd->set_nonblocking() %O %O\n", DWRITE(sprintf("TELNET: set_nonblocking(): "
"Calling fd->set_nonblocking() %O %O\n",
w_cb, w_cb || send_data)); w_cb, w_cb || send_data));
fd->set_nonblocking(got_data, w_cb && send_data, close_cb, got_oob); fd->set_nonblocking(got_data, w_cb && send_data, close_cb, got_oob);
nonblocking_write = !!w_cb; nonblocking_write = !!w_cb;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment