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

Bug 494108 - [telnet] Telnet line-ending should be configurable

This commit is contained in:
Anton Leherbauer 2016-06-30 13:28:09 +02:00
parent 159afcfd92
commit 092e089d40
12 changed files with 125 additions and 60 deletions

View file

@ -8,7 +8,7 @@ Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400",
org.eclipse.core.runtime;bundle-version="3.8.0",
org.eclipse.equinox.security;bundle-version="1.1.100",
org.eclipse.tm.terminal.view.core;bundle-version="4.0.0";resolution:=optional,
org.eclipse.tm.terminal.view.core;bundle-version="4.1.0";resolution:=optional,
org.eclipse.tm.terminal.view.ui;bundle-version="4.1.0";resolution:=optional,
org.eclipse.tm.terminal.control;bundle-version="4.0.0",
org.eclipse.ui;bundle-version="3.8.0"

View file

@ -1,11 +1,11 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Copyright (c) 2006, 2016 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
*******************************************************************************/
@ -14,9 +14,13 @@ package org.eclipse.tm.terminal.connector.telnet.connector;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
public interface ITelnetSettings {
static final String EOL_CRNUL = "CR+NUL"; //$NON-NLS-1$
static final String EOL_CRLF = "CR+LF"; //$NON-NLS-1$
String getHost();
int getNetworkPort();
int getTimeout();
String getEndOfLine();
String getSummary();
void load(ISettingsStore store);
void save(ISettingsStore store);

View file

@ -34,6 +34,32 @@ import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl;
public class TelnetConnector extends TerminalConnectorImpl {
static final class TelnetOutputStream extends FilterOutputStream {
final static byte CR = 13;
final static byte LF = 10;
final static byte NUL = 0;
final static byte[] CRNUL = { CR, NUL };
final static byte[] CRLF = { CR, LF };
final byte[] EOL;
public TelnetOutputStream(OutputStream outputStream, String endOfLine) {
super(outputStream);
if (ITelnetSettings.EOL_CRLF.equals(endOfLine))
EOL = CRLF;
else
EOL = CRNUL;
}
@Override
public void write(int b) throws IOException {
if (b == CR)
out.write(EOL);
else
out.write(b);
}
}
private OutputStream fOutputStream;
private InputStream fInputStream;
private Socket fSocket;
@ -115,25 +141,8 @@ public class TelnetConnector extends TerminalConnectorImpl {
fOutputStream = null;
return;
}
// send LF after CR (telnet end-of-line sequence - RFC 854)
fOutputStream = new FilterOutputStream(outputStream) {
final byte CR = 13;
final byte LF = 10;
final byte[] CRLF = { CR, LF };
int last = -1;
@Override
public void write(int b) throws IOException {
if (b == LF && last == CR) {
last = b;
return;
}
last = b;
if (b == CR)
out.write(CRLF);
else
out.write(b);
}
};
// translate CR to telnet end-of-line sequence - RFC 854
fOutputStream = new TelnetOutputStream(outputStream, fSettings.getEndOfLine());
}
Socket getSocket() {
return fSocket;

View file

@ -1,11 +1,11 @@
/*******************************************************************************
* Copyright (c) 2006, 2015 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Copyright (c) 2006, 2016 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
*******************************************************************************/
@ -21,5 +21,6 @@ public class TelnetMessages extends NLS {
public static String HOST;
public static String CONNECTION_CLOSED_BY_FOREIGN_HOST;
public static String TIMEOUT;
public static String END_OF_LINE;
}

View file

@ -1,5 +1,5 @@
###############################################################################
# Copyright (c) 2005, 2015 Wind River Systems, Inc. and others.
# Copyright (c) 2005, 2016 Wind River Systems, Inc. and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@ -18,3 +18,4 @@ PORT = Port
HOST = Host
CONNECTION_CLOSED_BY_FOREIGN_HOST= Connection closed by foreign host.
TIMEOUT = Timeout (sec)
END_OF_LINE = End of Line

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2015 Wind River Systems, Inc. and others.
* Copyright (c) 2003, 2016 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -11,7 +11,7 @@
* Helmut Haigermoser and Ted Williams.
*
* Contributors:
* Michael Scharf (Wind River) - extracted from TerminalSettings
* Michael Scharf (Wind River) - extracted from TerminalSettings
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
*******************************************************************************/
package org.eclipse.tm.terminal.connector.telnet.connector;
@ -22,6 +22,7 @@ public class TelnetSettings implements ITelnetSettings {
protected String fHost;
protected String fNetworkPort;
protected String fTimeout;
protected String fEndOfLine = EOL_CRNUL;
private final TelnetProperties fProperties=new TelnetProperties();
@Override
public String getHost() {
@ -59,6 +60,7 @@ public class TelnetSettings implements ITelnetSettings {
fHost = store.get("Host", fProperties.getDefaultHost());//$NON-NLS-1$
fNetworkPort = store.get("NetworkPort", fProperties.getDefaultNetworkPort());//$NON-NLS-1$
fTimeout = store.get("Timeout","10");//$NON-NLS-1$ //$NON-NLS-2$
fEndOfLine = store.get("EndOfLine", EOL_CRNUL);//$NON-NLS-1$
}
@Override
@ -66,6 +68,7 @@ public class TelnetSettings implements ITelnetSettings {
store.put("Host", fHost);//$NON-NLS-1$
store.put("NetworkPort", fNetworkPort);//$NON-NLS-1$
store.put("Timeout", fTimeout);//$NON-NLS-1$
store.put("EndOfLine", fEndOfLine);//$NON-NLS-1$
}
public TelnetProperties getProperties() {
@ -86,4 +89,13 @@ public class TelnetSettings implements ITelnetSettings {
public void setTimeout(String timeout) {
fTimeout = timeout;
}
public void setEndOfLine(String eol) {
fEndOfLine = EOL_CRLF.equals(eol) ? EOL_CRLF : EOL_CRNUL;
}
@Override
public String getEndOfLine() {
return fEndOfLine;
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2003, 2015 Wind River Systems, Inc. and others.
* Copyright (c) 2003, 2016 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -18,6 +18,7 @@
*******************************************************************************/
package org.eclipse.tm.terminal.connector.telnet.connector;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@ -41,6 +42,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
/* default */ Text fHostText;
/* default */ Combo fNetworkPortCombo;
/* default */ Text fTimeout;
/* default */ Combo fEndOfLineCombo;
private final TelnetSettings fTerminalSettings;
public TelnetSettingsPage(TelnetSettings settings) {
@ -51,6 +53,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
fTerminalSettings.setHost(fHostText.getText());
fTerminalSettings.setTimeout(fTimeout.getText());
fTerminalSettings.setNetworkPort(getNetworkPort());
fTerminalSettings.setEndOfLine(getEndOfLine());
}
@Override
@ -59,6 +62,7 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
setHost(fTerminalSettings.getHost());
setTimeout(fTerminalSettings.getTimeoutString());
setNetworkPort(fTerminalSettings.getNetworkPortString());
setEndOfLine(fTerminalSettings.getEndOfLine());
}
}
private void setHost(String strHost) {
@ -96,7 +100,13 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
private NetworkPortMap getNetworkPortMap() {
return fTerminalSettings.getProperties().getNetworkPortMap();
}
private void setEndOfLine(String eol) {
int idx = fEndOfLineCombo.indexOf(eol);
fEndOfLineCombo.select(idx >= 0 ? idx : 0);
}
private String getEndOfLine() {
return fEndOfLineCombo.getText();
}
@Override
public boolean validateSettings() {
String message = null;
@ -210,6 +220,18 @@ public class TelnetSettingsPage extends AbstractSettingsPage {
});
createControlDecoration(fTimeout);
new Label(composite, SWT.RIGHT).setText(TelnetMessages.END_OF_LINE + ":"); //$NON-NLS-1$
gridData = new GridData(GridData.FILL_HORIZONTAL);
fEndOfLineCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
fEndOfLineCombo.setLayoutData(gridData);
fEndOfLineCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
fireListeners(fEndOfLineCombo);
}
});
loadCombo(fEndOfLineCombo, Arrays.asList(ITelnetSettings.EOL_CRNUL, ITelnetSettings.EOL_CRLF));
loadSettings();
}
private void loadCombo(Combo ctlCombo, List<String> table) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2015 Wind River Systems, Inc. and others. All rights reserved.
* Copyright (c) 2011, 2016 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@ -104,6 +104,10 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
value = v != null ? v.toString() : null;
if (value != null) telnetSettings.setTimeout(value);
v = data.get(ITerminalsConnectorConstants.PROP_TELNET_EOL);
value = v != null ? v.toString() : null;
if (value != null) telnetSettings.setEndOfLine(value);
value = (String)data.get(ITerminalsConnectorConstants.PROP_ENCODING);
if (value != null) setEncoding(value);
@ -124,6 +128,7 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
data.put(ITerminalsConnectorConstants.PROP_IP_HOST,telnetSettings.getHost());
data.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.valueOf(telnetSettings.getNetworkPort()));
data.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.valueOf(telnetSettings.getTimeout()));
data.put(ITerminalsConnectorConstants.PROP_TELNET_EOL, telnetSettings.getEndOfLine());
data.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
}
@ -144,6 +149,9 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
if (hostSettings.get(ITerminalsConnectorConstants.PROP_TIMEOUT) != null) {
telnetSettings.setTimeout(hostSettings.get(ITerminalsConnectorConstants.PROP_TIMEOUT));
}
if (hostSettings.get(ITerminalsConnectorConstants.PROP_TELNET_EOL) != null) {
telnetSettings.setEndOfLine(hostSettings.get(ITerminalsConnectorConstants.PROP_TELNET_EOL));
}
if (hostSettings.get(ITerminalsConnectorConstants.PROP_ENCODING) != null) {
setEncoding(hostSettings.get(ITerminalsConnectorConstants.PROP_ENCODING));
}
@ -164,24 +172,20 @@ public class TelnetWizardConfigurationPanel extends AbstractExtendedConfiguratio
protected void saveSettingsForHost(boolean add){
String host = getHostFromSettings();
if(host != null && host.length() != 0) {
if (hostSettingsMap.containsKey(host)) {
Map<String, String> hostSettings=hostSettingsMap.get(host);
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost());
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(telnetSettings.getNetworkPort()));
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(telnetSettings.getTimeout()));
if (getEncoding() != null) {
hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
}
} else if (add) {
Map<String, String> hostSettings=new HashMap<String, String>();
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost());
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(telnetSettings.getNetworkPort()));
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(telnetSettings.getTimeout()));
if (getEncoding() != null) {
hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
}
Map<String, String> hostSettings = hostSettingsMap.get(host);
if (hostSettings == null && !add) {
hostSettings=new HashMap<String, String>();
hostSettingsMap.put(host, hostSettings);
}
if (hostSettings != null) {
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_HOST, telnetSettings.getHost());
hostSettings.put(ITerminalsConnectorConstants.PROP_IP_PORT, Integer.toString(telnetSettings.getNetworkPort()));
hostSettings.put(ITerminalsConnectorConstants.PROP_TIMEOUT, Integer.toString(telnetSettings.getTimeout()));
hostSettings.put(ITerminalsConnectorConstants.PROP_TELNET_EOL, telnetSettings.getEndOfLine());
if (getEncoding() != null) {
hostSettings.put(ITerminalsConnectorConstants.PROP_ENCODING, getEncoding());
}
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011, 2015 Wind River Systems, Inc. and others. All rights reserved.
* Copyright (c) 2011, 2016 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@ -134,6 +134,7 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate {
String port = value != null ? value.toString() : null;
value = properties.get(ITerminalsConnectorConstants.PROP_TIMEOUT);
String timeout = value != null ? value.toString() : null;
String endOfLine = (String)properties.get(ITerminalsConnectorConstants.PROP_TELNET_EOL);
int portOffset = 0;
if (properties.get(ITerminalsConnectorConstants.PROP_IP_PORT_OFFSET) instanceof Integer) {
@ -156,6 +157,7 @@ public class TelnetLauncherDelegate extends AbstractLauncherDelegate {
if (timeout != null) {
telnetSettings.setTimeout(timeout);
}
telnetSettings.setEndOfLine(endOfLine);
// And save the settings to the store
telnetSettings.save(store);

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.tm.terminal.view.core;singleton:=true
Bundle-Version: 4.0.0.qualifier
Bundle-Version: 4.1.0.qualifier
Bundle-Activator: org.eclipse.tm.terminal.view.core.activator.CoreBundleActivator
Bundle-Vendor: %providerName
Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400",

View file

@ -11,7 +11,7 @@
<relativePath>../../admin/pom-build.xml</relativePath>
</parent>
<version>4.0.0-SNAPSHOT</version>
<version>4.1.0-SNAPSHOT</version>
<artifactId>org.eclipse.tm.terminal.view.core</artifactId>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 - 2015 Wind River Systems, Inc. and others. All rights reserved.
* Copyright (c) 2011, 2016 Wind River Systems, Inc. and others. All rights reserved.
* This program and the accompanying materials are made available under the terms
* of the Eclipse Public License v1.0 which accompanies this distribution, and is
* available at http://www.eclipse.org/legal/epl-v10.html
@ -319,4 +319,14 @@ public interface ITerminalsConnectorConstants {
* Property Type: {@link String}
*/
public static final String PROP_SERIAL_FLOW_CONTROL = "serial.flowcontrol"; //$NON-NLS-1$
// ***** Telnet specific properties *****
/**
* The end-of-line sequence to be sent to the server on "Enter".
* <p>
* Property Type: {@link String}
*/
public static final String PROP_TELNET_EOL = "telnet.eol"; //$NON-NLS-1$
}