[Webfunds-commits] java/webfunds/sox DepositRequest.java MailRequest.java RegisterRequest.java Request.java TimeSyncRequest.java DepositReply.java MailReply.java RegisterReply.java Reply.java TimeSyncReply.java SubAccount.java ValueAccount.java
Ian Grigg
iang@cypherpunks.ai
Sun, 24 Sep 2000 19:32:06 -0400 (AST)
iang 00/09/24 19:32:06
Modified: webfunds/sox DepositRequest.java MailRequest.java
RegisterRequest.java Request.java
TimeSyncRequest.java DepositReply.java
MailReply.java RegisterReply.java Reply.java
TimeSyncReply.java SubAccount.java
ValueAccount.java
Log:
These changes are incompatible with prior code, but should not change
the data formats (intended to permit Reply version changes, see long
note in archives for explanation).
1. Reply constructors now require the Request, not the requestId.
2. Reply test code and example code now needs to have a Request first.
3. Eliminated some more IOExceptions...
Revision Changes Path
1.24 +8 -7 java/webfunds/sox/DepositRequest.java
Index: DepositRequest.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/DepositRequest.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- DepositRequest.java 2000/08/16 19:51:19 1.23
+++ DepositRequest.java 2000/09/24 23:32:04 1.24
@@ -1,5 +1,5 @@
/*
- * $Id: DepositRequest.java,v 1.23 2000/08/16 19:51:19 iang Exp $
+ * $Id: DepositRequest.java,v 1.24 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -163,11 +163,12 @@
* Get a Reply with Errors set.
*/
public Reply errorReply(int e)
- { return new DepositReply(requestId, e); }
+ { return new DepositReply(this, e); }
public DepositReply goodReply(MailItem mail)
- { return new DepositReply(requestId, mail); }
+ { return new DepositReply(this, mail); }
+
/**
* Create an unsigned deposit request
* This constructor is the one usually called by SOX clients.
@@ -215,7 +216,7 @@
* @excep IOException The input stream returned EOF?
*/
public DepositRequest(InputStream is)
- throws SOXPacketException, IOException
+ throws SOXPacketException
{
super(is);
}
@@ -348,7 +349,7 @@
public String vString()
{
- return "V" + version + " " + super.getRequestVersion() + ")";
+ return "V" + version;
}
public static DepositRequest example()
@@ -450,7 +451,7 @@
throws Exception
{
DepositRequest b = null;
- b = new DepositRequest(System.in);
+ b = new DepositRequest(System.in);
System.err.println("Read: " + b);
b.encode(System.out);
}
@@ -459,7 +460,7 @@
throws Exception
{
DepositRequest b = null;
- b = new DepositRequest(System.in);
+ b = new DepositRequest(System.in);
System.err.println("Read: " + b);
}
}
1.11 +123 -10 java/webfunds/sox/MailRequest.java
Index: MailRequest.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/MailRequest.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- MailRequest.java 2000/04/20 00:03:07 1.10
+++ MailRequest.java 2000/09/24 23:32:04 1.11
@@ -1,5 +1,5 @@
/*
- * $Id: MailRequest.java,v 1.10 2000/04/20 00:03:07 iang Exp $
+ * $Id: MailRequest.java,v 1.11 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -29,7 +29,7 @@
* This one is extended from Reply.
*/
public Reply errorReply(int e)
- { return new MailReply(requestId, e); }
+ { return new MailReply(this, e); }
//
// Currently, the Reply doesn't have a version number.
// So, to change the format of the Reply, Request also must be
@@ -37,9 +37,10 @@
// to use.
//
public MailReply goodReply(MailItem[] newMailItems)
- { return new MailReply(requestId, newMailItems); }
+ { return new MailReply(this, newMailItems); }
+
public MailRequest(String requestId, AccountId acc, MailId[] mails)
{
super(requestId, acc);
@@ -47,10 +48,10 @@
}
public MailRequest(byte[] data)
- throws SOXPacketException
- {
- super(data);
- }
+ throws SOXPacketException { super(data); }
+
+ public MailRequest(InputStream is)
+ throws SOXPacketException { super(is); }
public MailId[] getMailIds()
{
@@ -104,15 +105,127 @@
}
}
+
+
+////// Self-Test //////////////////////////////////
+
public String toString()
{
String s = "MailRequest V" + version + ": ";
s += super.toString();
for(int i = 0; i < mails.length; i++)
- {
- s += mails[i] + "\n";
- }
+ s += " " + mails[i] + "\n";
return s;
}
+ public static MailRequest example()
+ {
+ String reqId = Utils.exampleString();
+ int n = Utils.exampleByte() & 0x07;
+ MailId[] mails = new MailId[n];
+ AccountId acc = AccountId.example();
+
+ for (int i = 0; i < n; i++)
+ mails[i] = MailId.example();
+
+ MailRequest req = new MailRequest(reqId, acc, mails);
+
+ return req ;
+ }
+
+ public static void main(String[] args)
+ {
+ int num = 2000;
+ String type = "-c";
+ if (args.length > 0)
+ {
+ int a = 0;
+ if (args[a].startsWith("-"))
+ {
+ type = args[a++];
+ }
+
+ if (a < args.length)
+ {
+ Integer i = null;
+ try {
+ i = new Integer(args[a]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ num = i.intValue();
+ }
+ }
+
+ try {
+ if (type.equals("-t") || type.equals("-i"))
+ {
+ while (true)
+ {
+ if (type.equals("-t"))
+ readWrite();
+ else if (type.equals("-i"))
+ input();
+ }
+ }
+ else
+ {
+ for (int i = 0; i < num; i++)
+ {
+ if (type.equals("-c"))
+ cycle();
+ else if (type.equals("-o"))
+ output();
+ }
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.out.flush(); // last buffered lump still there
+ System.out.close();
+ System.exit(0);
+ }
+
+ protected static void cycle()
+ throws Exception
+ {
+ MailRequest p = example();
+ System.err.println("Writing: " + p);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ p.encode(baos);
+ byte[] buf = baos.toByteArray();
+
+ MailRequest q = new MailRequest(buf);
+ if (!p.equals(q))
+ {
+ throw new RuntimeException("FAILED:\n\n"+q+"\n\n"+p+"\nEND\n");
+ }
+ }
+
+ protected static void output()
+ throws Exception
+ {
+ MailRequest b = example();
+ b.encode(System.out);
+ }
+
+ protected static void readWrite()
+ throws Exception
+ {
+ MailRequest b = null;
+ b = new MailRequest(System.in);
+ System.err.println("Read: " + b);
+ b.encode(System.out);
+ }
+
+ protected static void input()
+ throws Exception
+ {
+ MailRequest b = null;
+ b = new MailRequest(System.in);
+ System.err.println("Read: " + b);
+ }
}
1.17 +83 -15 java/webfunds/sox/RegisterRequest.java
Index: RegisterRequest.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/RegisterRequest.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- RegisterRequest.java 2000/07/21 21:31:18 1.16
+++ RegisterRequest.java 2000/09/24 23:32:04 1.17
@@ -1,4 +1,4 @@
-/* $Id: RegisterRequest.java,v 1.16 2000/07/21 21:31:18 gelderen Exp $
+/* $Id: RegisterRequest.java,v 1.17 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Inc. 1995-2000 on behalf of
* The WebFunds Development Team. All Rights Reserved.
@@ -15,7 +15,7 @@
* A Request class that registers a client key with an issuer,
* by means of the "Register" request
*
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
*/
public class RegisterRequest
extends Request
@@ -48,11 +48,12 @@
* Get a Reply with Errors set.
*/
public Reply errorReply(int e)
- { return new RegisterReply(requestId, e); }
+ { return new RegisterReply(this, e); }
public RegisterReply goodReply(AccountId id)
- { return new RegisterReply(requestId, id); }
+ { return new RegisterReply(this, id); }
+
public RegisterRequest(String requestId, AccountId acc, PublicKey key)
throws SOXKeyException
{
@@ -76,11 +77,11 @@
}
public RegisterRequest(byte[] data)
- throws SOXPacketException
- {
- super(data);
- }
+ throws SOXPacketException { super(data); }
+ public RegisterRequest(InputStream is)
+ throws SOXPacketException { super(is); }
+
public void encode(OutputStream os)
throws IOException
{
@@ -141,9 +142,9 @@
public String toString()
{
- String s = "Register request V" + version + ": ";
+ String s = "SOX RegisterRequest V" + version + " ";
s += super.toString();
- s += "version " + version + " Key: " + key;
+ s += "\tKey: " + key;
return s;
}
@@ -225,20 +226,63 @@
public static void main(String[] args)
{
- args = null;
+ int num = 2000;
+ String type = "-c";
+ if (args.length > 0)
+ {
+ int a = 0;
+ if (args[a].startsWith("-"))
+ {
+ type = args[a++];
+ }
+
+ if (a < args.length)
+ {
+ Integer i = null;
+ try {
+ i = new Integer(args[a]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ num = i.intValue();
+ }
+ }
+
try {
- for (int i = 0; i < 20; i++)
- tryit(example());
- } catch (Exception e) {
+ if (type.equals("-t") || type.equals("-i"))
+ {
+ while (true)
+ {
+ if (type.equals("-t"))
+ readWrite();
+ else if (type.equals("-i"))
+ input();
+ }
+ }
+ else
+ {
+ for (int i = 0; i < num; i++)
+ {
+ if (type.equals("-c"))
+ cycle();
+ else if (type.equals("-o"))
+ output();
+ }
+ }
+ } catch(Exception e) {
e.printStackTrace();
System.exit(1);
}
+ System.out.flush(); // last buffered lump still there
+ System.out.close();
System.exit(0);
}
- protected static void tryit(RegisterRequest p)
+ protected static void cycle()
throws Exception
{
+ RegisterRequest p = example();
System.err.println("Writing: " + p);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -250,5 +294,29 @@
{
throw new RuntimeException("FAILED:\n\n"+q+"\n\n"+p+"\nEND\n");
}
+ }
+
+ protected static void output()
+ throws Exception
+ {
+ RegisterRequest b = example();
+ b.encode(System.out);
+ }
+
+ protected static void readWrite()
+ throws Exception
+ {
+ RegisterRequest b = null;
+ b = new RegisterRequest(System.in);
+ System.err.println("Read: " + b);
+ b.encode(System.out);
+ }
+
+ protected static void input()
+ throws Exception
+ {
+ RegisterRequest b = null;
+ b = new RegisterRequest(System.in);
+ System.err.println("Read: " + b);
}
}
1.19 +32 -18 java/webfunds/sox/Request.java
Index: Request.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Request.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Request.java 2000/08/16 19:51:19 1.18
+++ Request.java 2000/09/24 23:32:04 1.19
@@ -1,5 +1,5 @@
/*
- * $Id: Request.java,v 1.18 2000/08/16 19:51:19 iang Exp $
+ * $Id: Request.java,v 1.19 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -21,16 +21,20 @@
extends Encodable
{
/**
- * The version of the encoded :
+ * The version of the encoded :
*
* 1 was pre-dawn-of-time, may have been SOX-1
* 2 - original SOX-2, as delivered
* 3 - all daughter requests add their own version bytes
* 4 - use me next
*
- * To change the version, add a REQ_reason_for_change constant
- * with the REQ_not_used_yet number (and advance this one).
- * Set req_version to the new reason request version number.
+ * Note that Requests and their Replies have the same version number.
+ * Changes in the Reply format imply changes in the below number.
+ * How the client works out what version the server is at is unknown...
+ *
+ * To change the version, add a REQ_reason_for_change constant
+ * with the REQ_not_used_yet number (and advance this one).
+ * Set req_version to the new reason request version number.
*/
public static final int REQ_VERSION = 3, // old name, deprecated
REQ_ORIGINAL = 2, // change 1 ==> 2 was pre-dawn
@@ -38,14 +42,18 @@
REQ_SUBS_ADD_V = 3, // daughters add versions!
REQ_not_used_yet = 4; // use me next...
- // public static final int versionOld = 2; // old name, deprecated
-
/**
* Initialised to the current best version from the REQ_* constants.
*/
protected int req_version = REQ_SUBS_ADD_V; // for new versions, change this
public int getRequestVersion() { return req_version; }
+ /**
+ * Set the version number of this request.
+ * Not currently used, but something is needed.
+ * Will be used once we figure out what the server is set to...
+ */
+ public void setRequestVersion(int v) { req_version = v; }
/**
* Returns the name of the packet as it goes on the wire.
@@ -178,9 +186,13 @@
* @excep IOException An I/O Error has occurred
*/
public Request(InputStream is)
- throws SOXPacketException, IOException
+ throws SOXPacketException
{
- decode(is);
+ try {
+ decode(is);
+ } catch (IOException ex) {
+ throw new SOXPacketException(SOXException.BAD_PACKET, "IOEx: "+ex);
+ }
}
/**
@@ -322,25 +334,27 @@
{
Date dat = new Date();
dat.setTime(timestamp);
- String retval = "SOX Request V" + req_version + " id:"+requestId+"\n";
- retval += "\tAccount: "+account;
- retval += "\tTimestamp: "+dat;
+ String s = "(v" + req_version + " id:"+requestId+")\n";
+
+ s += "\tAccount: "+account;
+ s += "\tTimestamp: "+dat;
if (sig != null)
- retval += "\tSignature: "+sig;
- retval += "\n";
- return retval;
+ s += "\tSignature: "+sig;
+ s += "\n";
+
+ return s;
}
public boolean equals(java.lang.Object obj)
{
if (!(obj instanceof Request))
- {
return false;
- }
Request other = (Request)obj;
- // easy - timestamp and request id
+ // easy parts first
+ if (other.getRequestVersion() != req_version)
+ return false;
if (other.getTimestamp() != timestamp)
return false;
String hisRid = other.getRequestId();
1.10 +9 -5 java/webfunds/sox/TimeSyncRequest.java
Index: TimeSyncRequest.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/TimeSyncRequest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TimeSyncRequest.java 2000/03/29 01:00:18 1.9
+++ TimeSyncRequest.java 2000/09/24 23:32:04 1.10
@@ -1,5 +1,5 @@
/*
- * $Id: TimeSyncRequest.java,v 1.9 2000/03/29 01:00:18 iang Exp $
+ * $Id: TimeSyncRequest.java,v 1.10 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -36,12 +36,16 @@
public long getTime() { return time; }
/**
- * Get a Reply with Errors set.
+ * Requests and Replies are Yin and Yang. Each knows about the other.
+ *
+ * Get a Reply with Errors set.
*/
public Reply errorReply(int e)
- { return new TimeSyncReply(requestId, e); }
- public TimeSyncReply errorReply(long diff)
- { return new TimeSyncReply(requestId, diff); }
+ { return new TimeSyncReply(this, e); }
+ /** Get a good Reply with the Diff set. */
+ public TimeSyncReply goodReply(long diff)
+ { return new TimeSyncReply(this, diff); }
+
/**
1.22 +205 -20 java/webfunds/sox/DepositReply.java
Index: DepositReply.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/DepositReply.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- DepositReply.java 2000/03/28 23:36:18 1.21
+++ DepositReply.java 2000/09/24 23:32:04 1.22
@@ -1,5 +1,5 @@
/*
- * $Id: DepositReply.java,v 1.21 2000/03/28 23:36:18 iang Exp $
+ * $Id: DepositReply.java,v 1.22 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -10,7 +10,7 @@
/**
* A deposit reply.
- * This should change to being en extension of MailReply
+ * This might want to change to being an extension of MailReply
* in the next change.
*/
public class DepositReply
@@ -56,20 +56,22 @@
}
/**
- * Create a Good DepositReply - Deprecated
- */
- public DepositReply(String requestId, byte[] receipt)
+ * Create a Good DepositReply - Deprecated ???
+ * Hence the odd calling sequence, it is a hack for old receipt code.
+ * This isn't used AFAIK.
+ public DepositReply(byte[] receipt, DepositRequest request)
{
- super(requestId);
+ super(request);
this.receipt_data = receipt;
}
+ */
/**
* Create a Good DepositReply with a MailItem
*/
- public DepositReply(String requestId, MailItem mail)
+ public DepositReply(DepositRequest request, MailItem mail)
{
- super(requestId);
+ super(request);
if (!mail.isReceipt())
throw new RuntimeException("only receipt is supported: " + mail);
this.receipt_data = mail.getMessage();
@@ -78,21 +80,20 @@
/**
* Create a Bad DepositReply - required by DepositRequest
*/
- public DepositReply(String requestId, int errNum)
+ public DepositReply(DepositRequest request, int errNum)
{
- super(requestId, errNum);
+ super(request, errNum);
this.receipt_data = new byte[0];
}
- /**
- * Create from data, invokes this.encode.
- */
- public DepositReply(byte[] data)
- throws SOXPacketException
- {
- super(data);
- }
+ public DepositReply(DepositRequest request, byte[] data)
+ throws SOXPacketException { super(request, data); }
+
+ public DepositReply(DepositRequest request, InputStream is)
+ throws SOXPacketException { super(request, is); }
+
+
public void encode(OutputStream os)
throws IOException
{
@@ -113,10 +114,194 @@
}
}
+
+
+
+////// Self-Test //////////////////////////////////
+
public String toString()
{
- String s = "Deposit reply";
- s += super.toString();
+ if (errorNumber != 0)
+ return "DepositReply in error: " + super.toString();
+
+ String s = "SOX DepositReply ";
+ MailItem[] mails = getMailItems();
+ int len = (mails == null) ? 0 : mails.length;
+ s += "num = " + len + " mails";
+ for (int i = 0; i < len; i++)
+ s += "\n " + mails[i].toString();
return s;
+ }
+
+ public boolean equals(java.lang.Object obj)
+ {
+ if (obj == null || !(obj instanceof DepositReply))
+ return false;
+
+ DepositReply other = (DepositReply)obj;
+
+ if (!super.equals(other))
+ return false;
+
+ MailItem[] mails = this.getMailItems();
+ MailItem[] others = other.getMailItems();
+
+ if (others == null && (mails != null))
+ return false ;
+ if (mails == null && (others != null))
+ return false ;
+
+ if (others.length != mails.length)
+ return false ;
+
+ for (int i = 0; i < mails.length; i++)
+ {
+ if (!mails[i].equals(others[i]))
+ return false ;
+ }
+
+ return true;
+ }
+
+ public static DepositReply example(DepositRequest req)
+ {
+ int b = Utils.exampleByte() & 0x0FF;
+ String s = webfunds.utils.Hex.data2hex(Utils.exampleData(b));
+
+ if ((b & 0x07) == 0x07) // return error reply!
+ {
+ int errno = Utils.exampleByte() & 0x0FF;
+ b >>= 3;
+ DepositReply obj = new DepositReply(req, b);
+ return obj;
+ }
+
+ Receipt r = Receipt.example();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try {
+ r.encode(baos);
+ } catch (IOException ex) {
+ throw new RuntimeException("IOEx: " + ex);
+ }
+ byte[] buf = baos.toByteArray();
+
+ DepositReply obj;
+ try {
+ obj = new DepositReply(req, buf);
+ } catch (SOXPacketException ex) {
+ throw new RuntimeException("SOXPEx: " + ex);
+ }
+ return obj;
+ }
+
+ public static DepositReply example()
+ {
+ return example(DepositRequest.example());
+ }
+
+ public static void main(String[] args)
+ {
+ int num = 200;
+ String type = "-c";
+ if (args.length > 0)
+ {
+ int a = 0;
+ if (args[a].startsWith("-"))
+ {
+ type = args[a++];
+ }
+
+ if (a < args.length)
+ {
+ Integer i = null;
+ try {
+ i = new Integer(args[a]);
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ num = i.intValue();
+ }
+ }
+
+ try {
+ if (type.equals("-t") || type.equals("-i"))
+ {
+ while (true)
+ {
+ if (type.equals("-t"))
+ readWrite();
+ else if (type.equals("-i"))
+ input();
+ }
+ }
+ else
+ {
+ for (int i = 0; i < num; i++)
+ {
+ if (type.equals("-c"))
+ cycle();
+ else if (type.equals("-o"))
+ output();
+ }
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ System.out.flush(); // last buffered lump still there
+ System.out.close();
+ System.exit(0);
+ }
+
+ protected static void cycle()
+ throws Exception
+ {
+ DepositRequest r = DepositRequest.example();
+ DepositReply p = example(r);
+ System.err.println("Writing: " + p);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ p.encode(baos);
+ byte[] buf = baos.toByteArray();
+
+ DepositReply q = new DepositReply(r, buf);
+ if (!p.equals(q))
+ {
+ throw new RuntimeException("FAILED:\n\n"+q+"\n\n"+p+"\nEND\n");
+ }
+ }
+
+ protected static void output()
+ throws Exception
+ {
+ DepositRequest r = DepositRequest.example();
+ r.encode(System.out);
+ DepositReply b = example(r);
+ b.encode(System.out);
+ }
+
+ protected static void readWrite()
+ throws Exception
+ {
+ DepositRequest r = null;
+ r = new DepositRequest(System.in);
+ r.encode(System.out);
+
+ DepositReply b = null;
+ b = new DepositReply(r, System.in);
+ System.err.println("Write: " + b);
+ b.encode(System.out);
+ }
+
+ protected static void input()
+ throws Exception
+ {
+ DepositRequest r = null;
+ r = new DepositRequest(System.in);
+
+ DepositReply b = null;
+ b = new DepositReply(r, System.in);
+ System.err.println("Read: " + b);
}
}
1.15 +40 -21 java/webfunds/sox/MailReply.java
Index: MailReply.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/MailReply.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- MailReply.java 2000/06/11 22:28:13 1.14
+++ MailReply.java 2000/09/24 23:32:04 1.15
@@ -1,5 +1,5 @@
/*
- * $Id: MailReply.java,v 1.14 2000/06/11 22:28:13 iang Exp $
+ * $Id: MailReply.java,v 1.15 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -40,10 +40,10 @@
////// Construction ///////////////////////////////////
- public MailReply(String requestId, byte[][] newMails)
+ public MailReply(Request request, byte[][] newMails)
throws SOXPacketException
{
- super(requestId);
+ super(request);
int len = (newMails == null) ? 0 : newMails.length;
@@ -57,25 +57,29 @@
}
}
- public MailReply(String requestId, MailItem[] newMailItems)
+ public MailReply(Request request, MailItem[] newMailItems)
{
- super(requestId);
+ super(request);
mails = (newMailItems == null) ? (new MailItem[0]) : newMailItems;
}
- public MailReply(String requestId, int errno)
+ public MailReply(Request request, int errno)
{
- super(requestId, errno);
+ super(request, errno);
// this.newMails = new byte[0][];
mails = new MailItem[0]; // helps equals()
}
- public MailReply(byte[] data) throws SOXPacketException { super(data); }
- public MailReply(InputStream is) throws SOXPacketException { super(is); }
+ public MailReply(Request request, byte[] data)
+ throws SOXPacketException { super(request, data); }
+ public MailReply(Request request, InputStream is)
+ throws SOXPacketException { super(request, is); }
+
+
////// Encoding ///////////////////////////////////
public void encode(OutputStream os)
@@ -133,12 +137,12 @@
public String toString()
{
- String s;
if (errorNumber != 0)
return "MailReply in error: " + super.toString();
+ String s = "SOX MailReply ";
int len = (mails == null) ? 0 : mails.length;
- s = "MailReply num = " + len + " mails";
+ s += "num = " + len + " mails";
for (int i = 0; i < len; i++)
s += "\n " + mails[i].toString();
return s;
@@ -173,7 +177,7 @@
return true;
}
- public static MailReply example()
+ public static MailReply example(MailRequest req)
{
int b = Utils.exampleByte() & 0x0FF;
String s = webfunds.utils.Hex.data2hex(Utils.exampleData(b));
@@ -182,7 +186,7 @@
{
int errno = Utils.exampleByte() & 0x0FF;
b >>= 3;
- MailReply obj = new MailReply(s, b);
+ MailReply obj = new MailReply(req, b);
return obj;
}
@@ -191,13 +195,18 @@
for (int i = 0; i < b; i++)
mi[i] = MailItem.example();
- MailReply obj = new MailReply(s, mi);
+ MailReply obj = new MailReply(req, mi);
return obj;
}
+ public static MailReply example()
+ {
+ return example(MailRequest.example());
+ }
+
public static void main(String[] args)
{
- int num = 20;
+ int num = 200;
String type = "-c";
if (args.length > 0)
{
@@ -253,14 +262,15 @@
protected static void cycle()
throws Exception
{
- MailReply p = example();
+ MailRequest r = MailRequest.example();
+ MailReply p = example(r);
System.err.println("Writing: " + p);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
p.encode(baos);
byte[] buf = baos.toByteArray();
- MailReply q = new MailReply(buf);
+ MailReply q = new MailReply(r, buf);
if (!p.equals(q))
{
throw new RuntimeException("FAILED:\n\n"+q+"\n\n"+p+"\nEND\n");
@@ -270,24 +280,33 @@
protected static void output()
throws Exception
{
- MailReply b = example();
+ MailRequest r = MailRequest.example();
+ r.encode(System.out);
+ MailReply b = example(r);
b.encode(System.out);
}
protected static void readWrite()
throws Exception
{
+ MailRequest r = null;
+ r = new MailRequest(System.in);
+ r.encode(System.out);
+
MailReply b = null;
- b = new MailReply(System.in);
- System.err.println("Read: " + b);
+ b = new MailReply(r, System.in);
+ System.err.println("Write: " + b);
b.encode(System.out);
}
protected static void input()
throws Exception
{
+ MailRequest r = null;
+ r = new MailRequest(System.in);
+
MailReply b = null;
- b = new MailReply(System.in);
+ b = new MailReply(r, System.in);
System.err.println("Read: " + b);
}
}
1.11 +13 -10 java/webfunds/sox/RegisterReply.java
Index: RegisterReply.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/RegisterReply.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- RegisterReply.java 2000/03/22 08:51:28 1.10
+++ RegisterReply.java 2000/09/24 23:32:04 1.11
@@ -1,5 +1,5 @@
/*
- * $Id: RegisterReply.java,v 1.10 2000/03/22 08:51:28 iang Exp $
+ * $Id: RegisterReply.java,v 1.11 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -25,28 +25,31 @@
/**
* Create a Register reply
*/
- public RegisterReply(String requestId, AccountId id)
+ public RegisterReply(RegisterRequest request, AccountId id)
{
- super(requestId);
+ super(request);
accId = id;
}
/**
* Create a Register reply
*/
- public RegisterReply(String requestId, int errNum)
+ public RegisterReply(RegisterRequest request, int errNum)
{
- super(requestId, errNum);
+ super(request, errNum);
accId = new AccountId(); // is null, BEARER, but can encode
}
- /**
- * Create a Register reply
- */
- public RegisterReply(byte[] data)
+ public RegisterReply(RegisterRequest request, byte[] data)
+ throws SOXPacketException
+ {
+ super(request, data);
+ }
+
+ public RegisterReply(RegisterRequest request, InputStream is)
throws SOXPacketException
{
- super(data);
+ super(request, is);
}
public void encode(OutputStream os)
1.17 +49 -29 java/webfunds/sox/Reply.java
Index: Reply.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/Reply.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Reply.java 2000/06/10 20:17:56 1.16
+++ Reply.java 2000/09/24 23:32:04 1.17
@@ -1,5 +1,5 @@
/*
- * $Id: Reply.java,v 1.16 2000/06/10 20:17:56 iang Exp $
+ * $Id: Reply.java,v 1.17 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -18,6 +18,11 @@
extends Encodable
{
/**
+ * Initialised to the Request version number.
+ */
+ protected int req_version = 0;
+
+ /**
* An identifier for the request, used to pair up
* replys with requests when used over connectionless
* transport layers.
@@ -78,52 +83,66 @@
public int getErrorNumber() { return errorNumber; }
/**
- * Create a reply, with an error number.
+ * Create a reply, with an error number.
*
- * @param requestId the identifier of the request to which this is a reply
- * @param errNum the error number
+ * @param request the request to which this is a reply
+ * @param errNum the error number
*/
- protected Reply(String requestId, int errNum) // Hmm, congests space
+ protected Reply(Request request, int errNum) // Hmm, congests space
{
- this.requestId = requestId;
+ this.requestId = request.getRequestId();
+ this.req_version = request.getRequestVersion();
this.errorNumber = errNum;
- //this.errorText = Errors.errorString(errNum);
}
/**
- * Create a reply
+ * Create a reply
*
- * @param requestId the identifier of the request to which this is a reply
+ * @param request the request to which this is a reply
*/
- protected Reply(String requestId)
+ protected Reply(Request request)
{
- this.requestId = requestId;
+ this.requestId = request.getRequestId();
+ this.req_version = request.getRequestVersion();
}
/**
- * Construct a reply object from a byte array
- * that was previously returned from the encode()
- * method of a reply object. This is the usual
- * method of constructing a reply object for SOX clients,
- * and is done using data received from the server.
+ * Construct a reply object from a byte array
+ * that was previously returned from the encode()
+ * method of a reply object. This is the usual
+ * method of constructing a reply object for SOX clients,
+ * and is done using data received from the server.
+ *
+ * The reply is expected to be for the supplied request
+ * and is required so that the correct version of the reply
+ * can be invoked.
*
- * @param replyData the previously encoded reply
- * @excep SOXPacketException The reply data is badly formatted
+ * @param request the request that elicited this reply
+ * @param replyData the previously encoded reply
+ * @excep SOXPacketException The reply data is badly formatted
*/
- protected Reply(byte[] replyData)
+ protected Reply(Request request, byte[] replyData)
throws SOXPacketException
{
+ req_version = request.getRequestVersion();
+ // now, we can test version to see what format data follows
decode(replyData);
}
- protected Reply(InputStream is)
+ /**
+ * Construct a reply object from an input stream
+ * that was previously constructed from the encode()
+ * output of a reply object. This is only currently
+ * used by testing routines.
+ *
+ * @param replyData the previously encoded reply
+ * @excep SOXPacketException The reply data is badly formatted
+ */
+ protected Reply(Request request, InputStream is)
throws SOXPacketException
{
-// try {
- decode(is);
-// } catch (IOException ex) {
-// throw new SOXPacketException("IOEx: " + ex);
-// }
+ req_version = request.getRequestVersion();
+ decode(is);
}
/**
@@ -181,11 +200,10 @@
*/
public String toString()
{
- String retval = "SOX Reply\n";
- retval += "Request id: "+requestId+"\n";
+ String s = "SOX Reply V" + req_version + " id=" + requestId;
if (errorNumber != 0)
- retval += "Error " + errorNumber + ": " + errorText;
- return retval;
+ s += "\n Error " + errorNumber + ": " + errorText;
+ return s;
}
public boolean equals(java.lang.Object obj)
@@ -207,6 +225,8 @@
return false;
}
+ if (req_version != other.req_version)
+ return false ;
if (errorNumber != other.getErrorNumber())
return false ;
1.9 +16 -9 java/webfunds/sox/TimeSyncReply.java
Index: TimeSyncReply.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/TimeSyncReply.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- TimeSyncReply.java 2000/03/22 08:51:28 1.8
+++ TimeSyncReply.java 2000/09/24 23:32:04 1.9
@@ -1,5 +1,5 @@
/*
- * $Id: TimeSyncReply.java,v 1.8 2000/03/22 08:51:28 iang Exp $
+ * $Id: TimeSyncReply.java,v 1.9 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -21,29 +21,36 @@
/**
* Create a TimeSync reply
- * @requestId the identifier of the request to which this is a reply
+ * @request the request to which this is a reply is made
* @param the difference between the request's time and the issuer's time
*/
- public TimeSyncReply(String requestId, long diff)
+ public TimeSyncReply(Request request, long diff)
{
- super(requestId);
+ super(request);
this.diff = diff;
}
/**
- * Create a Register reply
+ * Create a TimeSyncReply reply
*/
- public TimeSyncReply(String requestId, int errNum)
+ public TimeSyncReply(Request request, int errNum)
{
- super(requestId, errNum);
+ super(request, errNum);
diff = (long)3759843; // some useless number
}
- public TimeSyncReply(byte[] data)
+
+ public TimeSyncReply(TimeSyncRequest request, byte[] data)
+ throws SOXPacketException
+ {
+ super(request, data);
+ }
+
+ public TimeSyncReply(TimeSyncRequest request, InputStream is)
throws SOXPacketException
{
- super(data);
+ super(request, is);
}
public void encode(OutputStream os)
1.27 +3 -10 java/webfunds/sox/SubAccount.java
Index: SubAccount.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/SubAccount.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- SubAccount.java 2000/09/03 16:55:04 1.26
+++ SubAccount.java 2000/09/24 23:32:04 1.27
@@ -1,4 +1,4 @@
-/* $Id: SubAccount.java,v 1.26 2000/09/03 16:55:04 iang Exp $
+/* $Id: SubAccount.java,v 1.27 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Inc. 1995-2000 on behalf of
* The WebFunds Development Team. All Rights Reserved.
@@ -238,17 +238,10 @@
throw new SOXKeyException("register(): verify failed, fatal.");
}
-// try {
-// req.setSignature(Crypto.sign(acct.getKey(), req.encode()));
-// } catch (java.security.KeyException kex) {
-// kex.printStackTrace(System.err);
-// throw new SOXKeyException("KeyException: " + kex);
-// }
-
byte[] replyBuf = requestExtra(req);
try {
- reply = new RegisterReply(replyBuf);
+ reply = new RegisterReply(req, replyBuf);
} catch (SOXPacketException ex) {
ex.printStackTrace(System.err);
throw new SOXSubAccountException(SOXSubAccountException.BAD_PACKET,
@@ -329,7 +322,7 @@
MailReply reply;
try {
- reply = new MailReply(replyBuf);
+ reply = new MailReply(req, replyBuf);
} catch (SOXPacketException ex) {
ex.printStackTrace(System.err);
throw new SOXSubAccountException(SOXSubAccountException.BAD_PACKET,
1.19 +3 -2 java/webfunds/sox/ValueAccount.java
Index: ValueAccount.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/ValueAccount.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ValueAccount.java 2000/07/18 22:21:04 1.18
+++ ValueAccount.java 2000/09/24 23:32:04 1.19
@@ -1,5 +1,5 @@
/*
- * $Id: ValueAccount.java,v 1.18 2000/07/18 22:21:04 iang Exp $
+ * $Id: ValueAccount.java,v 1.19 2000/09/24 23:32:04 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -179,7 +179,8 @@
DepositReply reply;
try {
- reply = new DepositReply(replyBuf);
+ // there is another (req & byte[]) constructor, watch out
+ reply = new DepositReply(req, replyBuf);
} catch (SOXPacketException ex) {
ex.printStackTrace(System.err);
throw new SOXSubAccountException("SOXPacketException: " + ex);