comparison src/com/five_ten_sg/connectbot/transport/TN5250.java @ 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
comparison
equal deleted inserted replaced
11:f3b3bbd227b8 12:6aaefb22d876
23 import java.net.Socket; 23 import java.net.Socket;
24 import java.net.SocketException; 24 import java.net.SocketException;
25 import java.util.List; 25 import java.util.List;
26 import java.util.Map; 26 import java.util.Map;
27 27
28 import org.tn5250j.framework.tn5250.Screen5250;
29 import org.tn5250j.framework.tn5250.tnvt;
30
28 import com.five_ten_sg.connectbot.bean.HostBean; 31 import com.five_ten_sg.connectbot.bean.HostBean;
29 import com.five_ten_sg.connectbot.bean.PortForwardBean; 32 import com.five_ten_sg.connectbot.bean.PortForwardBean;
30 import com.five_ten_sg.connectbot.service.TerminalBridge; 33 import com.five_ten_sg.connectbot.service.TerminalBridge;
31 import com.five_ten_sg.connectbot.service.TerminalManager; 34 import com.five_ten_sg.connectbot.service.TerminalManager;
32 import com.five_ten_sg.connectbot.util.HostDatabase; 35 import com.five_ten_sg.connectbot.util.HostDatabase;
33 36
34 import android.content.Context; 37 import android.content.Context;
35 import android.net.Uri; 38 import android.net.Uri;
36 39
37 import org.tn5250j.framework.tn5250.tnvt;
38 40
39 41
40 /** 42 /**
41 * @author Carl Byington 43 * @author Carl Byington
42 * 44 *
55 private int width; 57 private int width;
56 private int height; 58 private int height;
57 59
58 private boolean connected = false; 60 private boolean connected = false;
59 61
62 static final Pattern hostmask;
63 static {
64 hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE);
65 }
66
67
60 public TN5250() { 68 public TN5250() {
61 super(); 69 super();
62 } 70 }
63 71
64 public TN5250(HostBean host, TerminalBridge bridge, TerminalManager manager) { 72 public TN5250(HostBean host, TerminalBridge bridge, TerminalManager manager) {
72 */ 80 */
73 public static String getProtocolName() { 81 public static String getProtocolName() {
74 return PROTOCOL; 82 return PROTOCOL;
75 } 83 }
76 84
77 /** 85 public Uri getUri(String input) {
78 * Encode the current transport into a URI that can be passed via intent calls. 86 Matcher matcher = hostmask.matcher(input);
79 * @return URI to host 87
80 */ 88 if (!matcher.matches())
81 public static Uri getUri(String input) { 89 return null;
82 return null; 90
91 StringBuilder sb = new StringBuilder();
92 sb.append(PROTOCOL)
93 .append("://")
94 .append(matcher.group(1));
95 String portString = matcher.group(3);
96 int port = DEFAULT_PORT;
97
98 if (portString != null) {
99 try {
100 port = Integer.parseInt(portString);
101
102 if (port < 1 || port > 65535) {
103 port = DEFAULT_PORT;
104 }
105 }
106 catch (NumberFormatException nfe) {
107 // Keep the default port
108 }
109 }
110
111 if (port != DEFAULT_PORT) {
112 sb.append(':');
113 sb.append(port);
114 }
115
116 sb.append("/#")
117 .append(Uri.encode(input));
118 Uri uri = Uri.parse(sb.toString());
119 return uri;
83 } 120 }
84 121
85 /** 122 /**
86 * Causes transport to connect to the target host. After connecting but before a 123 * Causes transport to connect to the target host. After connecting but before a
87 * session is started, must call back to {@link TerminalBridge#onConnected()}. 124 * session is started, must call back to {@link TerminalBridge#onConnected()}.
371 408
372 return host; 409 return host;
373 } 410 }
374 411
375 412
376 public static String getFormatHint(Context context) { 413 public String getFormatHint(Context context) {
377 return String.format("%s:%s", 414 return String.format("%s:%s",
378 context.getString(R.string.format_hostname), 415 context.getString(R.string.format_hostname),
379 context.getString(R.string.format_port)); 416 context.getString(R.string.format_port));
380 } 417 }
381 418