home *** CD-ROM | disk | FTP | other *** search
- package sun.net.www.protocol.gopher;
-
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PipedInputStream;
- import java.io.PipedOutputStream;
- import java.io.PrintStream;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.security.AccessController;
- import sun.net.NetworkClient;
- import sun.net.www.MessageHeader;
- import sun.net.www.URLConnection;
- import sun.security.action.GetBooleanAction;
- import sun.security.action.GetIntegerAction;
- import sun.security.action.GetPropertyAction;
-
- public class GopherClient extends NetworkClient implements Runnable {
- public static boolean useGopherProxy;
- public static String gopherProxyHost;
- public static int gopherProxyPort;
- // $FF: renamed from: os java.io.PipedOutputStream
- PipedOutputStream field_0;
- // $FF: renamed from: u java.net.URL
- URL field_1;
- int gtype;
- String gkey;
- URLConnection connection;
-
- GopherClient(URLConnection var1) {
- this.connection = var1;
- }
-
- public static boolean getUseGopherProxy() {
- return (Boolean)AccessController.doPrivileged(new GetBooleanAction("gopherProxySet"));
- }
-
- public static String getGopherProxyHost() {
- String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("gopherProxyHost"));
- if ("".equals(var0)) {
- var0 = null;
- }
-
- return var0;
- }
-
- public static int getGopherProxyPort() {
- return (Integer)AccessController.doPrivileged(new GetIntegerAction("gopherProxyPort", 80));
- }
-
- InputStream openStream(URL var1) throws IOException {
- this.field_1 = var1;
- this.field_0 = this.field_0;
- int var2 = 0;
- String var3 = var1.getFile();
- int var4 = var3.length();
-
- char var5;
- for(var5 = 49; var2 < var4 && (var5 = var3.charAt(var2)) == '/'; ++var2) {
- }
-
- this.gtype = var5 == 47 ? 49 : var5;
- if (var2 < var4) {
- ++var2;
- }
-
- this.gkey = var3.substring(var2);
-
- try {
- ((NetworkClient)this).openServer(var1.getHost(), var1.getPort() <= 0 ? 70 : var1.getPort());
- } catch (UnknownHostException var8) {
- ((NetworkClient)this).openServer("sun-barr.ebay.sun.com", 3666);
- super.serverOutput.print(var1.getHost() + " " + (var1.getPort() <= 0 ? 70 : var1.getPort()) + "\n");
- super.serverOutput.flush();
- var2 = 0;
-
- while((var5 = super.serverInput.read()) >= 0) {
- if (var5 == 10) {
- ++var2;
- if (var2 >= 2) {
- break;
- }
- }
- }
-
- if (var5 < 0) {
- ((NetworkClient)this).closeServer();
- throw new UnknownHostException(var1.getHost());
- }
- }
-
- MessageHeader var6 = new MessageHeader();
- switch (this.gtype) {
- case 48:
- case 55:
- var6.add("content-type", "text/plain");
- break;
- case 49:
- var6.add("content-type", "text/html");
- break;
- case 73:
- case 103:
- var6.add("content-type", "image/gif");
- break;
- default:
- var6.add("content-type", "content/unknown");
- }
-
- if (this.gtype != 55) {
- super.serverOutput.print(this.decodePercent(this.gkey) + "\r\n");
- super.serverOutput.flush();
- } else if ((var2 = this.gkey.indexOf(63)) >= 0) {
- super.serverOutput.print(this.decodePercent(this.gkey.substring(0, var2) + "\t" + this.gkey.substring(var2 + 1) + "\r\n"));
- super.serverOutput.flush();
- var6.add("content-type", "text/html");
- } else {
- var6.add("content-type", "text/html");
- }
-
- this.connection.setProperties(var6);
- if (var6.findValue("content-type") == "text/html") {
- this.field_0 = new PipedOutputStream();
- PipedInputStream var7 = new PipedInputStream();
- var7.connect(this.field_0);
- (new Thread(this)).start();
- return var7;
- } else {
- return new GopherInputStream(this, super.serverInput);
- }
- }
-
- private String decodePercent(String var1) {
- if (var1 != null && var1.indexOf(37) >= 0) {
- int var2 = var1.length();
- char[] var3 = new char[var2];
- int var4 = 0;
-
- for(int var5 = 0; var5 < var2; ++var5) {
- int var6 = var1.charAt(var5);
- if (var6 == 37 && var5 + 2 < var2) {
- int var7 = var1.charAt(var5 + 1);
- int var8 = var1.charAt(var5 + 2);
- if (48 <= var7 && var7 <= 57) {
- var7 -= 48;
- } else if (97 <= var7 && var7 <= 102) {
- var7 = var7 - 97 + 10;
- } else if (65 <= var7 && var7 <= 70) {
- var7 = var7 - 65 + 10;
- } else {
- var7 = -1;
- }
-
- if (48 <= var8 && var8 <= 57) {
- var8 -= 48;
- } else if (97 <= var8 && var8 <= 102) {
- var8 = var8 - 97 + 10;
- } else if (65 <= var8 && var8 <= 70) {
- var8 = var8 - 65 + 10;
- } else {
- var8 = -1;
- }
-
- if (var7 >= 0 && var8 >= 0) {
- var6 = var7 << 4 | var8;
- var5 += 2;
- }
- }
-
- var3[var4++] = (char)var6;
- }
-
- return new String(var3, 0, var4);
- } else {
- return var1;
- }
- }
-
- private String encodePercent(String var1) {
- if (var1 == null) {
- return var1;
- } else {
- int var2 = var1.length();
- char[] var3 = null;
- int var4 = 0;
-
- for(int var5 = 0; var5 < var2; ++var5) {
- char var6 = var1.charAt(var5);
- if (var6 > ' ' && var6 != '"' && var6 != '%') {
- if (var3 != null) {
- if (var4 >= var3.length) {
- char[] var10 = new char[var4 + 10];
- System.arraycopy(var3, 0, var10, 0, var4);
- var3 = var10;
- }
-
- var3[var4] = (char)var6;
- }
-
- ++var4;
- } else {
- if (var3 == null) {
- var3 = var1.toCharArray();
- }
-
- if (var4 + 3 >= var3.length) {
- char[] var7 = new char[var4 + 10];
- System.arraycopy(var3, 0, var7, 0, var4);
- var3 = var7;
- }
-
- var3[var4] = '%';
- int var8 = var6 >> 4 & 15;
- var3[var4 + 1] = var8 < 10 ? (char)(48 + var8) : (char)(55 + var8);
- var8 = var6 & 15;
- var3[var4 + 2] = var8 < 10 ? (char)(48 + var8) : (char)(55 + var8);
- var4 += 3;
- }
- }
-
- return var3 == null ? var1 : new String(var3, 0, var4);
- }
- }
-
- public void run() {
- int var1 = -1;
-
- try {
- if (this.gtype == 55 && (var1 = this.gkey.indexOf(63)) < 0) {
- PrintStream var27 = new PrintStream(this.field_0);
- var27.print("<html><head><title>Searchable Gopher Index</title></head>\n<body><h1>Searchable Gopher Index</h1><isindex>\n</body></html>\n");
- } else if (this.gtype != 49 && this.gtype != 55) {
- byte[] var26 = new byte[2048];
-
- int var29;
- try {
- while((var29 = super.serverInput.read(var26)) >= 0) {
- this.field_0.write(var26, 0, var29);
- }
- } catch (Exception var23) {
- }
- } else {
- PrintStream var2 = new PrintStream(this.field_0);
- Object var3 = null;
- String var28;
- if (this.gtype == 55) {
- var28 = "Results of searching for \"" + this.gkey.substring(var1 + 1) + "\" on " + this.field_1.getHost();
- } else {
- var28 = "Gopher directory " + this.gkey + " from " + this.field_1.getHost();
- }
-
- var2.print("<html><head><title>");
- var2.print(var28);
- var2.print("</title></head>\n<body>\n<H1>");
- var2.print(var28);
- var2.print("</h1><dl compact>\n");
- DataInputStream var4 = new DataInputStream(super.serverInput);
-
- String var5;
- while((var5 = var4.readLine()) != null) {
- int var6;
- for(var6 = var5.length(); var6 > 0 && var5.charAt(var6 - 1) <= ' '; --var6) {
- }
-
- if (var6 > 0) {
- char var7 = var5.charAt(0);
- int var8 = var5.indexOf(9);
- int var9 = var8 > 0 ? var5.indexOf(9, var8 + 1) : -1;
- int var10 = var9 > 0 ? var5.indexOf(9, var9 + 1) : -1;
- if (var10 >= 0) {
- String var11 = var10 + 1 < var6 ? ":" + var5.substring(var10 + 1, var6) : "";
- String var12 = var9 + 1 < var10 ? var5.substring(var9 + 1, var10) : this.field_1.getHost();
- var2.print("<dt><a href=\"gopher://" + var12 + var11 + "/" + var5.substring(0, 1) + this.encodePercent(var5.substring(var8 + 1, var9)) + "\">\n");
- var2.print("<img align=middle border=0 width=25 height=32 src=");
- switch (var7) {
- case '0':
- var2.print(System.getProperty("java.net.ftp.imagepath.text"));
- break;
- case '1':
- var2.print(System.getProperty("java.net.ftp.imagepath.directory"));
- break;
- case 'g':
- var2.print(System.getProperty("java.net.ftp.imagepath.gif"));
- break;
- default:
- var2.print(System.getProperty("java.net.ftp.imagepath.file"));
- }
-
- var2.print(".gif align=middle><dd>\n");
- var2.print(var5.substring(1, var8) + "</a>\n");
- }
- }
- }
-
- var2.print("</dl></body>\n");
- var2.close();
- }
- } catch (IOException var24) {
- } finally {
- try {
- ((NetworkClient)this).closeServer();
- this.field_0.close();
- } catch (IOException var22) {
- }
-
- }
-
- }
-
- static {
- Boolean var0 = (Boolean)AccessController.doPrivileged(new GetBooleanAction("gopherProxySet"));
- useGopherProxy = var0;
- gopherProxyHost = (String)AccessController.doPrivileged(new GetPropertyAction("gopherProxyHost"));
- gopherProxyPort = (Integer)AccessController.doPrivileged(new GetIntegerAction("gopherProxyPort", 80));
- }
- }
-