Mercurial > 510Connectbot
changeset 12:6aaefb22d876 tn5250
adding tn5250 files
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 22 May 2014 18:41:36 -0700 |
parents | f3b3bbd227b8 |
children | b39bcf616a6f |
files | src/com/five_ten_sg/connectbot/transport/Local.java src/com/five_ten_sg/connectbot/transport/SSH.java src/com/five_ten_sg/connectbot/transport/TN5250.java src/com/five_ten_sg/connectbot/transport/Telnet.java |
diffstat | 4 files changed, 51 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/transport/Local.java Thu May 22 18:26:27 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/transport/Local.java Thu May 22 18:41:36 2014 -0700 @@ -187,7 +187,7 @@ os.write(c); } - public static Uri getUri(String input) { + public Uri getUri(String input) { Uri uri = Uri.parse(DEFAULT_URI); if (input != null && input.length() > 0) { @@ -220,13 +220,10 @@ selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment()); } - public static String getFormatHint(Context context) { + public String getFormatHint(Context context) { return context.getString(R.string.hostpref_nickname_title); } - /* (non-Javadoc) - * @see com.five_ten_sg.connectbot.transport.AbsTransport#usesNetwork() - */ @Override public boolean usesNetwork() { return false;
--- a/src/com/five_ten_sg/connectbot/transport/SSH.java Thu May 22 18:26:27 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/transport/SSH.java Thu May 22 18:41:36 2014 -0700 @@ -897,7 +897,7 @@ } } - public static Uri getUri(String input) { + public Uri getUri(String input) { Matcher matcher = hostmask.matcher(input); if (!matcher.matches()) @@ -1000,7 +1000,7 @@ this.httpproxy = httpproxy; } - public static String getFormatHint(Context context) { + public String getFormatHint(Context context) { return String.format("%s@%s:%s", context.getString(R.string.format_username), context.getString(R.string.format_hostname),
--- a/src/com/five_ten_sg/connectbot/transport/TN5250.java Thu May 22 18:26:27 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/transport/TN5250.java Thu May 22 18:41:36 2014 -0700 @@ -25,6 +25,9 @@ import java.util.List; import java.util.Map; +import org.tn5250j.framework.tn5250.Screen5250; +import org.tn5250j.framework.tn5250.tnvt; + import com.five_ten_sg.connectbot.bean.HostBean; import com.five_ten_sg.connectbot.bean.PortForwardBean; import com.five_ten_sg.connectbot.service.TerminalBridge; @@ -34,7 +37,6 @@ import android.content.Context; import android.net.Uri; -import org.tn5250j.framework.tn5250.tnvt; /** @@ -57,6 +59,12 @@ private boolean connected = false; + static final Pattern hostmask; + static { + hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE); + } + + public TN5250() { super(); } @@ -74,12 +82,41 @@ return PROTOCOL; } - /** - * Encode the current transport into a URI that can be passed via intent calls. - * @return URI to host - */ - public static Uri getUri(String input) { - return null; + public Uri getUri(String input) { + Matcher matcher = hostmask.matcher(input); + + if (!matcher.matches()) + return null; + + StringBuilder sb = new StringBuilder(); + sb.append(PROTOCOL) + .append("://") + .append(matcher.group(1)); + String portString = matcher.group(3); + int port = DEFAULT_PORT; + + if (portString != null) { + try { + port = Integer.parseInt(portString); + + if (port < 1 || port > 65535) { + port = DEFAULT_PORT; + } + } + catch (NumberFormatException nfe) { + // Keep the default port + } + } + + if (port != DEFAULT_PORT) { + sb.append(':'); + sb.append(port); + } + + sb.append("/#") + .append(Uri.encode(input)); + Uri uri = Uri.parse(sb.toString()); + return uri; } /** @@ -373,7 +410,7 @@ } - public static String getFormatHint(Context context) { + public String getFormatHint(Context context) { return String.format("%s:%s", context.getString(R.string.format_hostname), context.getString(R.string.format_port));
--- a/src/com/five_ten_sg/connectbot/transport/Telnet.java Thu May 22 18:26:27 2014 -0700 +++ b/src/com/five_ten_sg/connectbot/transport/Telnet.java Thu May 22 18:41:36 2014 -0700 @@ -263,7 +263,7 @@ } } - public static Uri getUri(String input) { + public Uri getUri(String input) { Matcher matcher = hostmask.matcher(input); if (!matcher.matches()) @@ -337,7 +337,7 @@ selection.put(HostDatabase.FIELD_HOST_PORT, Integer.toString(port)); } - public static String getFormatHint(Context context) { + public String getFormatHint(Context context) { return String.format("%s:%s", context.getString(R.string.format_hostname), context.getString(R.string.format_port));