Skip to content

Commit a68542f

Browse files
committed
NET-180 Telnet EOR is "consumed" by TelnetInputStream when in BINARY transmission
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/NET_2_0@963152 13f79535-47bb-0310-9956-ffa450edef68
1 parent 444d7f1 commit a68542f

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/main/java/org/apache/commons/net/telnet/Telnet.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,25 @@ void _setWantDont(int option)
405405
_options[option] &= ~_REQUESTED_DO_MASK;
406406
}
407407

408+
/**
409+
* Processes a COMMAND.
410+
*
411+
* @param command - option code to be set.
412+
**/
413+
void _processCommand(int command)
414+
{
415+
if (debugoptions)
416+
{
417+
System.err.println("RECEIVED COMMAND: " + command);
418+
}
419+
420+
if (__notifhand != null)
421+
{
422+
__notifhand.receivedNegotiation(
423+
TelnetNotificationHandler.RECEIVED_COMMAND, command);
424+
}
425+
}
426+
408427
/**
409428
* Processes a DO request.
410429
*

src/main/java/org/apache/commons/net/telnet/TelnetInputStream.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,9 @@ private int __read(boolean mayBlock) throws IOException
212212
__receiveState = _STATE_DATA;
213213
break; // exit to enclosing switch to return IAC from read
214214
default:
215-
__receiveState = _STATE_DATA;
216-
continue; // move on the next char, i.e. ignore IAC+unknown
215+
__receiveState = _STATE_DATA;
216+
__client._processCommand(ch); // Notify the user
217+
continue; // move on the next char
217218
}
218219
break; // exit and return from read
219220
case _STATE_WILL:
@@ -382,7 +383,7 @@ public int read() throws IOException
382383
__readIsWaiting = true;
383384
int ch;
384385
boolean mayBlock = true; // block on the first read only
385-
386+
386387
do
387388
{
388389
try
@@ -421,7 +422,7 @@ public int read() throws IOException
421422
if (__isClosed)
422423
return EOF;
423424
}
424-
425+
425426
// Reads should not block on subsequent iterations. Potentially, this could happen if the
426427
// remaining buffered socket data consists entirely of Telnet command sequence and no "user" data.
427428
mayBlock = false;

src/main/java/org/apache/commons/net/telnet/TelnetNotificationHandler.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,18 @@ public interface TelnetNotificationHandler
5353
public static final int RECEIVED_WONT = 4;
5454

5555
/***
56-
* Callback method called when TelnetClient receives an option
57-
* negotiation command.
56+
* The remote party sent a COMMAND.
57+
***/
58+
public static final int RECEIVED_COMMAND = 5;
59+
60+
/***
61+
* Callback method called when TelnetClient receives an
62+
* command or option negotiation command
5863
* <p>
59-
* @param negotiation_code - type of negotiation command received
60-
* (RECEIVED_DO, RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT)
64+
* @param negotiation_code - type of (negotiation) command received
65+
* (RECEIVED_DO, RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT, RECEIVED_COMMAND)
6166
* <p>
62-
* @param option_code - code of the option negotiated
67+
* @param option_code - code of the option negotiated, or the command code itself (e.g. NOP).
6368
* <p>
6469
***/
6570
public void receivedNegotiation(int negotiation_code, int option_code);

0 commit comments

Comments
 (0)