From: adam Date: Sat, 3 Jul 2004 18:49:45 +0000 (+0000) Subject: bogus patch X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=c099a298576b1083c6be3259442900056032f0b1;p=org.ibex.mail.git bogus patch darcs-hash:20040703184945-5007d-e0168ad3872fea92ae8be47149427e44517d3461.gz --- diff --git a/Makefile b/Makefile index 508dffa..70fe175 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ dist-clean: rm -rf .configure* .install* build .compile .build* sources := $(shell find src -name \*.java) -#sources += upstream/org.ibex.crypto/src/org/ibex/crypto/Base36.java +sources += upstream/org.ibex.crypto/src/org/ibex/crypto/Base36.java upstream/org.ibex.crypto/src/org/ibex/crypto/Base36.java: .download_org.ibex.crypto diff --git a/src/org/ibex/io/Connection.java b/src/org/ibex/io/Connection.java new file mode 100644 index 0000000..bb7907b --- /dev/null +++ b/src/org/ibex/io/Connection.java @@ -0,0 +1,20 @@ +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [LGPL] +package org.ibex.io; + +import java.net.*; +import java.io.*; +import org.ibex.util.*; + +/** a stream backed by a socket */ +public class Connection extends Stream { + private final Socket s; + public final String vhost; + public Connection(Socket s, String vhost) { super(s); this.vhost = vhost; this.s = s; } + public int getLocalPort() { return s.getLocalPort(); } + public int getRemotePort() { return s.getPort(); } + public InetAddress getRemoteAddress() { return ((InetSocketAddress)s.getRemoteSocketAddress()).getAddress(); } + public String getRemoteHostname() { return getRemoteAddress().getHostName(); } + public String getVirtualHost() { return vhost; } + public void setTimeout(int ms) { try { s.setSoTimeout(ms); } catch (Exception e){throw new StreamException(e); }} + public void setTcpNoDelay(boolean delay) { try { s.setTcpNoDelay(delay);}catch(Exception e){throw new StreamException(e); }} +} diff --git a/src/org/ibex/io/Stream.java b/src/org/ibex/io/Stream.java new file mode 100644 index 0000000..a1bf021 --- /dev/null +++ b/src/org/ibex/io/Stream.java @@ -0,0 +1,200 @@ +// Copyright 2004 Adam Megacz, see the COPYING file for licensing [LGPL] +package org.ibex.io; + +import java.io.*; +import java.net.*; +import java.util.zip.*; +import org.ibex.util.*; +import org.ibex.net.*; + +/** plays the role of InputStream, OutputStream, Reader and Writer, with logging and unchecked exceptions */ +public class Stream { + + protected final In in; + protected final Out out; + private StringBuffer log = loggingEnabled ? new StringBuffer(16 * 1024) : null; + private String newLine = "\r\n"; + + public static boolean loggingEnabled = System.getProperty("ibex.io.stream.logEnabled", "true") != null; + + public Stream(InputStream in) { this.in = new Stream.In(in); this.out = null; } + public Stream( OutputStream out) { this.in = null; this.out = new Stream.Out(out); } + public Stream(InputStream in, OutputStream out) { this.in = new Stream.In(in); this.out = new Stream.Out(out); } + public Stream(String s) { this(new ByteArrayInputStream(s.getBytes())); } + public Stream(Socket s) { + try { this.in = new Stream.In(s.getInputStream()); } catch (IOException e) { throw new StreamException(e); } + try { this.out = new Stream.Out(s.getOutputStream()); } catch (IOException e) { throw new StreamException(e); } + } + + private static int ioe(Exception e) { throw new StreamException(e); } + public static class StreamException extends RuntimeException { + public StreamException(Exception e) { super(e); } + public StreamException(String s) { super(s); } + } + public static class EOF extends StreamException { public EOF() { super("End of stream"); } } + public static class Closed extends StreamException { public Closed(String s) { super(s); } } + + + public char peekc() { flush(); return in.getc(true); } + public char getc() { flush(); char ret = in.getc(false); log(ret); return ret; } + public String readln() { flush(); String s = in.readln(); log(s); log('\n'); return s; } + public int read(byte[] b, int off, int len) { + flush(); + int ret = in.readBytes(b, off, len); + if (log != null) log("\n[read " + ret + " bytes of binary data ]\n"); + nnl = false; + return ret; + } + public int read(char[] c, int off, int len) { + flush(); + int ret = in.read(c, off, len); + if (log != null && ret != -1) log(new String(c, off, ret)); + return ret; + } + + public void unread(String s) { in.unread(s); } + + public void println() { println(""); } + public void println(String s) { logWrite(s); out.write(s); out.write(newLine); } + + public void flush() { if (out != null) try { out.w.flush(); } catch(IOException e) { ioe(e); } } + public void close() { in.close(); out.close(); } + public void setNewline(String s) { newLine = s; } + + + /** dumps the connection log into a file */ + public String dumpLog() { String ret = log.toString(); log = new StringBuffer(16 * 1024); return ret; } + private void log(String s) { if(log==null) return; if (!nnl) Log.note("\n[read ] "); Log.note(s + "\n"); nnl=false; } + private void logWrite(String s) { if(log==null) return; if (nnl) Log.note("\n"); Log.note("[write] "+s+"\n"); nnl=false; } + private void log(char c) { if(log==null) return; if (c == '\r') return; if (!nnl) Log.note("[read ] "); Log.note(c+""); nnl = c != '\n'; } + private boolean nnl = false; + + private static class Out extends BufferedOutputStream { + private Writer w = new BufferedWriter(new OutputStreamWriter(this)); + public Out(OutputStream out) { super(out); } + public void close() { try { super.close(); } catch (Exception e) { Log.error(this, e); } } + public void write(String s) { try { w.write(s); } catch (IOException e) { ioe(e); } } + } + + private static class In extends InputStream { + public Reader reader = new InputStreamReader(this); + private final InputStream orig; + public In(InputStream in) { orig = in; } + + char[] cbuf = new char[8192]; + int cstart = 0; + int cend = 0; + + byte[] buf = new byte[8192]; + int start = 0; + int end = 0; + + boolean flushing = false; + + public int available() { return flushing ? 0 : (end - start); } + public void close() { try { orig.close(); } catch (Exception e) { Log.error(this, e); } } + + public char getc(boolean peek) { try { + if (cstart == cend) { + cstart = 0; + cend = reader.read(cbuf, 0, cbuf.length); + if (cend == -1) { cend = cstart; throw new EOF(); } + } + return peek ? cbuf[cstart] : cbuf[cstart++]; + } catch (IOException e) { return (char)ioe(e); } } + + public String readln() { try { + while(true) { + for(int i=cstart; i 0 && cbuf[begin+len-1] == '\r') { len--; } + return new String(cbuf, begin, len); + } + ensurec(256); + int numread = reader.read(cbuf, cend, cbuf.length - cend); + if (numread == -1) { + if (cstart == cend) return null; + String ret = new String(cbuf, cstart, cend-cstart); + cstart = cend = 0; + return ret; + } + cend += numread; + } + } catch (IOException e) { ioe(e); return null; } } + + public int read(char[] c, int pos, int len) { try { + if (cstart == cend) { + cstart = 0; + cend = reader.read(cbuf, 0, cbuf.length); + if (cend == -1) { cend = cstart; return -1; } + } + if (len > cend - cstart) len = cend - cstart; + System.arraycopy(cbuf, cstart, c, pos, len); + cstart += len; + return len; + } catch (IOException e) { ioe(e); return -1; } } + + public int readBytes(byte[] b, int pos, int len) { flushchars(); return read(b, pos, len); } + public int read() { byte[] b = new byte[1]; if (read(b, 0, 1) == -1) return -1; return (int)b[0]; } + public int read(byte[] b, int pos, int len) { try { + if (start == end) { + start = 0; + end = orig.read(buf, 0, buf.length); + if (end == -1) { end = start; return -1; } + } + if (len > end - start) len = end - start; + System.arraycopy(buf, start, b, pos, len); + start += len; + return len; + } catch (IOException e) { ioe(e); return -1; } } + + private void growc(int s){char[] cbuf2=new char[cbuf.length+s*2];System.arraycopy(cbuf,0,cbuf2,0,cbuf.length);cbuf=cbuf2; } + private void shiftc() { + char[] cbuf2 = new char[cbuf.length]; + System.arraycopy(cbuf, cstart, cbuf2, 0, cend-cstart); + cend -= cstart; + cstart = 0; + cbuf = cbuf2; + } + private void ensurec(int space) { if (cend-cstart+space>cbuf.length) growc(space); if (cend+space>cbuf.length) shiftc(); } + + private void growb(int s) { byte[] buf2 = new byte[buf.length+s*2]; System.arraycopy(buf,0,buf2,0,buf.length); buf=buf2; } + private void shiftb() { System.arraycopy(buf, start, buf, 0, end-start); end -= start; start = 0; } + private void ensureb(int space) { if (end-start+space>buf.length) growb(space); if (end+space>buf.length) shiftb(); } + private void ensureb2(int space) { if (end-start+space>buf.length) growb(space); if (start/*.jar for a + * class implementing this interface; instances must + * have public constructors + */ +public interface Listener { + + public void accept(Connection c); + +} diff --git a/src/org/ibex/jinetd/Loader.java b/src/org/ibex/jinetd/Loader.java new file mode 100644 index 0000000..a94365e --- /dev/null +++ b/src/org/ibex/jinetd/Loader.java @@ -0,0 +1,186 @@ +package org.ibex.jinetd; +import org.ibex.util.*; +import java.io.*; +import java.util.*; +import java.util.zip.*; + +/** represents a file or directory which is scanned for updates */ +public class Loader extends Watcher { + + public Loader(String path) { super(path); } + + private TreeClassLoader classloader = new TreeClassLoader(); + public ClassLoader getClassLoader() { + ClassLoader classloader = this.classloader; + if (classloader == null) { + classloader = this.classloader = new TreeClassLoader(); + Log.warn(this, "getting classloader..."); + try { + compileSource(); + } catch (Exception e) { + Log.error(this, e); + } + } + return classloader; + } + + private void fill(Vec vec, File dir) { + if (!dir.exists()) return; + if (!dir.isDirectory()) { + if (!dir.getPath().endsWith(".java")) return; + vec.addElement(dir.getAbsolutePath()); + } else { + String[] list = dir.list(); + for(int i=0; i"; } - public static class Malformed extends RuntimeException { public Malformed(String s) { super(s); } } + public String coerceToString() { return toString(); } + public static class Malformed extends Message.Malformed { public Malformed(String s) { super(s); } } + + public boolean isLocal() { + InetAddress[] mx = SMTP.getMailExchangerIPs(host); + for(int i=0; i= 100) Log.warn(SMTP.Outgoing.class, "Message with " + m.traces.length + " trace hops; dropping\n" + m.summary()); else synchronized(Outgoing.class) { @@ -104,12 +104,12 @@ public class SMTP { InetAddress[] mx = getMailExchangerIPs(m.envelopeTo.host); if (mx.length == 0) { Log.warn(SMTP.Outgoing.class, "could not resolve " + m.envelopeTo.host + "; bouncing it\n" + m.summary()); - send(m.bounce("could not resolve " + m.envelopeTo.host)); + accept(m.bounce("could not resolve " + m.envelopeTo.host)); return true; } if (new Date().getTime() - m.arrival.getTime() > 1000 * 60 * 60 * 24 * 5) { Log.warn(SMTP.Outgoing.class, "could not send message after 5 days; bouncing it\n" + m.summary()); - send(m.bounce("could not send for 5 days")); + accept(m.bounce("could not send for 5 days")); return true; } for(int i=0; i