[Webfunds-commits] java/webfunds/sox MailItem.java
Ian Grigg
iang@cypherpunks.ai
Sun, 4 Jun 2000 20:53:40 -0400 (AST)
iang 00/06/04 20:53:40
Modified: webfunds/sox MailItem.java
Log:
fixed initial construction bug, also commented the difficult area
of the wire format not being the same as the other formats.
Revision Changes Path
1.4 +26 -46 java/webfunds/sox/MailItem.java
Index: MailItem.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/sox/MailItem.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MailItem.java 2000/04/25 03:40:24 1.3
+++ MailItem.java 2000/06/05 00:53:40 1.4
@@ -1,5 +1,5 @@
/*
- * $Id: MailItem.java,v 1.3 2000/04/25 03:40:24 iang Exp $
+ * $Id: MailItem.java,v 1.4 2000/06/05 00:53:40 iang Exp $
*
* Copyright (c) Systemics Ltd 1995-1999 on behalf of
* the WebFunds Development Team. All Rights Reserved.
@@ -8,6 +8,7 @@
import java.io.*;
+import webfunds.utils.Hex;
/**
* This class holds an item of mail.
@@ -80,6 +81,9 @@
buf[i+2] = b[i];
buf[0] = (byte)0;
buf[1] = (byte)type;
+
+ this.type = type;
+ version = VERSION;
}
public void setMsg(int type, Encodable obj)
@@ -117,16 +121,18 @@
if (oldBuf == null)
throw new SOXPacketException ("null mail oldBuf");
int len = oldBuf.length;
+//System.err.println("()()()()()()()()()() len == " + len);
if (len <= 2)
throw new SOXPacketException ("mail buf too short: (" + len +
- ") <<" + webfunds.utils.Hex.data2hex(oldBuf) + ">>");
+ ") <<" + Hex.data2hex(oldBuf) + ">>");
//
// First and foremost, a block of data for signing.
// Now for the proper recovery part.
// Version can be '0' for MailItem or '2' for Old Receipt.
//
- int v = oldBuf[0];
+ int v = oldBuf[0] & 0xFF;
+//System.err.println("{}{}{}{}{}{}{}{}{}{} v == " + v + " len == " + len);
if (v != VERSION && v != RECEIPT_OLD_VERSION)
{
throw new SOXPacketException("Invalid version in MailItem: "
@@ -139,11 +145,12 @@
// The old receipt form is sent just as is, without being
// wrapped up in a MailItem.
//
- if (v == RECEIPT_OLD_VERSION)
+ if (v == RECEIPT_OLD_VERSION) // 2
{
version = -1;
type = RECEIPT;
msg = oldBuf;
+//System.err.println("[][][][][][][][][][] self = " + toString());
return ;
}
@@ -153,6 +160,7 @@
msg = new byte[len - 2];
for (int i = 2; i < len; i++) // copy all but first two bytes
msg[i - 2] = oldBuf[i];
+//System.err.println("{}{}{}{}{}{}{}{}{}{} self = " + toString());
}
@@ -164,11 +172,16 @@
throws IOException
{
DataOutputStream dos = new DataOutputStream(os);
-System.err.println("OUT <<" + webfunds.utils.Hex.data2hex(buf) + ">>");
writeByteArray(dos, buf);
}
+ /**
+ * Careful of this conversion - as we are coding the
+ * mail item into an array, the on-the-wire format
+ * is not the same as the passed around internal
+ * mail item. A conversion is needed at the boundary.
+ */
public void decode(InputStream is)
throws SOXPacketException
{
@@ -182,43 +195,6 @@
}
init(bbb);
-// if (buf == null)
-// throw new SOXPacketException ("null mail buf");
-// int len = buf.length;
-// if (len <= 2)
-// throw new SOXPacketException ("mail buf too short: (" + len +
-// ") <<" + webfunds.utils.Hex.data2hex(buf) + ">>");
-//
-// //
-// // First and foremost, a block of data for signing.
-// // Now for the proper recovery part.
-// // Version can be '0' for MailItem or '2' for Old Receipt.
-// //
-// int v = buf[0];
-// if (v != VERSION && v != RECEIPT_OLD_VERSION)
-// {
-// throw new SOXPacketException("Invalid version in MailItem: "
-// + v + " != " + VERSION);
-// }
-//
-// //
-// // The old receipt form is sent just as is, without being
-// // wrapped up in a MailItem.
-// //
-// if (v == RECEIPT_OLD_VERSION)
-// {
-// version = -1;
-// type = RECEIPT;
-// msg = buf;
-// return ;
-// }
-//
-// version = v;
-// type = buf[1] & 0xFF; // second byte is type of mail
-//
-// msg = new byte[len - 2];
-// for (int i = 2; i < len; i++) // copy all but first two bytes
-// msg[i - 2] = buf[i];
}
@@ -242,7 +218,11 @@
{
if (null == buf || buf.length == 0)
return "<No Mail Item>";
- return "Type: " + type + " Item: " + webfunds.utils.Hex.data2hex(msg);
+ String s = "";
+ s += "V" + version;
+ s += " Type: " + type;
+ s += "Item: " + Hex.quick(msg);
+ return s ;
}
/**
@@ -255,19 +235,19 @@
int xx = Utils.exampleByte() & 0xFF;
if ((xx & 0x03) == 0x03)
{
-System.err.println("trying OLD");
+//System.err.println("trying OLD");
xx >>= 2;
// Receipt rec = Receipt.example();
byte b[] = new byte[(xx & 0x07) + 3];
b[0] = RECEIPT_OLD_VERSION;
-System.err.println(" ... " + webfunds.utils.Hex.data2hex(b));
+//System.err.println(" ... " + Hex.data2hex(b));
mi = new MailItem();
try {
mi.init(b);
} catch (SOXPacketException ex) {
throw new RuntimeException("SOXPE OLD example " + ex);
}
-System.err.println(" done " + mi);
+//System.err.println(" done " + mi);
return mi ;
}