1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 18:56:02 +02:00

[178606] fix endless loop in readUntil()

This commit is contained in:
Martin Oberhuber 2007-05-11 10:15:19 +00:00
parent a2ef23d04a
commit 72a0e2e522

View file

@ -10,6 +10,7 @@
* David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies * David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies
* Sheldon D'souza (Celunite) - adapted from SshConnectorService * Sheldon D'souza (Celunite) - adapted from SshConnectorService
* Martin Oberhuber (Wind River) - apply refactorings for StandardConnectorService * Martin Oberhuber (Wind River) - apply refactorings for StandardConnectorService
* Martin Oberhuber (Wind River) - [178606] fix endless loop in readUntil()
*******************************************************************************/ *******************************************************************************/
package org.eclipse.rse.internal.connectorservice.telnet; package org.eclipse.rse.internal.connectorservice.telnet;
@ -54,7 +55,7 @@ public class TelnetConnectorService extends StandardConnectorService implements
private PrintStream out; private PrintStream out;
private static final String PROMPT = "$"; //$NON-NLS-1$ private static final String PROMPT = "$"; //$NON-NLS-1$
private static final String ARM_PROMT = "#"; //$NON-NLS-1$ private static final String ARM_PROMT = "#"; //$NON-NLS-1$
private static final boolean arm_flag = true; private static final boolean arm_flag = false;
public TelnetConnectorService(IHost host) { public TelnetConnectorService(IHost host) {
super(TelnetConnectorResources.TelnetConnectorService_Name, TelnetConnectorResources.TelnetConnectorService_Description, host, 0); super(TelnetConnectorResources.TelnetConnectorService_Name, TelnetConnectorResources.TelnetConnectorService_Description, host, 0);
@ -85,9 +86,10 @@ public class TelnetConnectorService extends StandardConnectorService implements
in = fTelnetClient.getInputStream(); in = fTelnetClient.getInputStream();
out = new PrintStream( fTelnetClient.getOutputStream() ); out = new PrintStream( fTelnetClient.getOutputStream() );
if( !arm_flag ) { if( !arm_flag ) {
readUntil( "login: "); //$NON-NLS-1$ //FIXME Bug 186536: Strings for "Login" and "Password" should be configurable
readUntil( "ogin: "); //$NON-NLS-1$
write( user ); write( user );
readUntil( "Password: "); //$NON-NLS-1$ readUntil( "assword: "); //$NON-NLS-1$
write( password ); write( password );
readUntil( PROMPT ); readUntil( PROMPT );
}else { }else {
@ -109,29 +111,29 @@ public class TelnetConnectorService extends StandardConnectorService implements
} }
public String readUntil( String pattern ) { public String readUntil(String pattern) {
try { try {
char lastChar = pattern.charAt( pattern.length() - 1 ); char lastChar = pattern.charAt(pattern.length() - 1);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
boolean found = false; int ch = (char) in.read();
char ch = ( char )in.read(); while (ch >= 0) {
while( true ) { char tch = (char) ch;
System.out.print( ch ); if (Activator.isTracingOn())
sb.append( ch ); System.out.print(tch);
if( ch == lastChar ) { sb.append(tch);
if( sb.toString().endsWith( pattern ) ) { if (tch == lastChar) {
return sb.toString(); if (sb.toString().endsWith(pattern)) {
} return sb.toString();
} }
ch = ( char )in.read(); }
} ch = in.read();
} }
catch( Exception e ) { } catch (Exception e) {
e.printStackTrace(); SystemBasePlugin.logError(e.getMessage()==null ? e.getClass().getName() : e.getMessage(), e);
} }
return null; return null;
} }
public void write( String value ) { public void write( String value ) {
try { try {
out.println( value ); out.println( value );