Security implemented + Partial publish
diff --git a/js/encoding/BinaryXMLDecoder.js b/js/encoding/BinaryXMLDecoder.js
index 1175f28..c41d549 100644
--- a/js/encoding/BinaryXMLDecoder.js
+++ b/js/encoding/BinaryXMLDecoder.js
@@ -451,16 +451,24 @@
BinaryXMLDecoder.prototype.readEndElement = function(){
- try {
+ //try {
+ if(LOG>4)console.log('this.offset is '+this.offset);
+
var next = this.istream[this.offset];
+
this.offset++;
//read();
+
+ if(LOG>4)console.log('XML_CLOSE IS '+XML_CLOSE);
+ if(LOG>4)console.log('next is '+next);
+
if (next != XML_CLOSE) {
+ console.log("Expected end element, got: " + next);
throw new ContentDecodingException("Expected end element, got: " + next);
}
- } catch ( e) {
- throw new ContentDecodingException(e);
- }
+ //} catch ( e) {
+ //throw new ContentDecodingException(e);
+ //}
};
@@ -491,9 +499,25 @@
startTag) {
//byte []
- byteTimestamp = this.readBinaryElement(startTag);
+ var byteTimestamp = this.readBinaryElement(startTag);
+
+ //var lontimestamp = DataUtils.byteArrayToUnsignedLong(byteTimestamp);
+
+ var byteTimestamp = DataUtils.toHex(byteTimestamp);
+
+
+ var byteTimestamp = parseInt(byteTimestamp, 16);
+
+ lontimestamp = (byteTimestamp/ 4096) * 1000;
+
+ //if(lontimestamp<0) lontimestamp = - lontimestamp;
+
+ if(LOG>3) console.log('DECODED DATE WITH VALUE');
+ if(LOG>3) console.log(lontimestamp);
+
+
//CCNTime
- timestamp = new CCNTime(byteTimestamp);
+ timestamp = new CCNTime(lontimestamp);
//timestamp.setDateBinary(byteTimestamp);
if (null == timestamp) {
@@ -544,6 +568,8 @@
} while (more);
+ if(LOG>3)console.log('TYPE is '+ type + ' VAL is '+ val);
+
return new TypeAndVal(type, val);
};
@@ -608,7 +634,7 @@
};
-
+var count =0;
//String
BinaryXMLDecoder.prototype.decodeUString = function(
@@ -617,7 +643,12 @@
//int
byteLength) {
- if(null == byteLength){
+ /*
+ console.log('COUNT IS '+count);
+ console.log('INPUT BYTELENGTH IS '+byteLength);
+ count++;
+ if(null == byteLength|| undefined == byteLength){
+ console.log("!!!!");
tv = this.decodeTypeAndVal(this.istream);
var valval ;
if(typeof tv.val() == 'string'){
@@ -626,18 +657,82 @@
else
valval = (tv.val());
+ if(LOG>4) console.log('valval is ' + valval);
byteLength= this.decodeUString(this.istream, valval);
+
+ //if(LOG>4) console.log('byte Length found in type val is '+ byteLength.charCodeAt(0));
+ byteLength = parseInt(byteLength);
+
+
+ //byteLength = byteLength.charCodeAt(0);
+ //if(LOG>4) console.log('byte Length found in type val is '+ byteLength);
}
-
+ if(LOG>4)console.log('byteLength is '+byteLength);
+ if(LOG>4)console.log('type of byteLength is '+typeof byteLength);
+
stringBytes = this.decodeBlob(this.istream, byteLength);
+ //console.log('String bytes are '+ stringBytes);
+ //console.log('stringBytes);
+
+ if(LOG>4)console.log('byteLength is '+byteLength);
+ if(LOG>4)console.log('this.offset is '+this.offset);
+
tempBuffer = this.istream.slice(this.offset, this.offset+byteLength);
+ if(LOG>4)console.log('TEMPBUFFER IS' + tempBuffer);
+ if(LOG>4)console.log( tempBuffer);
+
+ if(LOG>4)console.log('ADDING to offset value' + byteLength);
this.offset+= byteLength;
- console.log('read the String' + tempBuffer.toString('ascii'));
- return tempBuffer.toString('ascii');//DataUtils.getUTF8StringFromBytes(stringBytes);
+ //if(LOG>3)console.log('read the String' + tempBuffer.toString('ascii'));
+ //return tempBuffer.toString('ascii');//
+
+
+ //if(LOG>3)console.log( 'STRING READ IS '+ DataUtils.getUTF8StringFromBytes(stringBytes) ) ;
+ //if(LOG>3)console.log( 'STRING READ IS '+ DataUtils.getUTF8StringFromBytes(tempBuffer) ) ;
+ //if(LOG>3)console.log(DataUtils.getUTF8StringFromBytes(tempBuffer) ) ;
+ //return DataUtils.getUTF8StringFromBytes(tempBuffer);
+
+ if(LOG>3)console.log( 'STRING READ IS '+ DataUtils.toString(stringBytes) ) ;
+ if(LOG>3)console.log( 'TYPE OF STRING READ IS '+ typeof DataUtils.toString(stringBytes) ) ;
+
+ return DataUtils.toString(stringBytes);*/
+
+ if(null == byteLength ){
+ var tempStreamPosition = this.offset;
+
+ //TypeAndVal
+ tv = this.decodeTypeAndVal(istream);
+
+ if(LOG>3)console.log('TV is '+tv);
+ if(LOG>3)console.log(tv);
+
+ if(LOG>3)console.log('Type of TV is '+typeof tv);
+
+ if ((null == tv) || (XML_UDATA != tv.type())) { // if we just have closers left, will get back null
+ //if (Log.isLoggable(Log.FAC_ENCODING, Level.FINEST))
+ //Log.finest(Log.FAC_ENCODING, "Expected UDATA, got " + ((null == tv) ? " not a tag " : tv.type()) + ", assuming elided 0-length blob.");
+
+ this.offset = tempStreamPosition;
+
+ return "";
+ }
+
+ return this.decodeUString(istream, tv.val());
+ }
+ else{
+ //byte []
+ stringBytes = this.decodeBlob(istream, byteLength);
+
+ //return DataUtils.getUTF8StringFromBytes(stringBytes);
+ return DataUtils.toString(stringBytes);
+
+ }
};
+
+
//OBject containg a pair of type and value
var TypeAndVal = function TypeAndVal(_type,_val) {
this.t = _type;
@@ -651,4 +746,43 @@
TypeAndVal.prototype.val = function(){
return this.v;
};
-//TODO
\ No newline at end of file
+//TODO
+
+
+
+
+
+
+BinaryXMLDecoder.prototype.readIntegerElement =function(
+ //String
+ startTag) {
+
+ //String
+ if(LOG>4) console.log('READING INTEGER '+ startTag);
+ if(LOG>4) console.log('TYPE OF '+ typeof startTag);
+
+ //try {
+
+ strVal = this.readUTF8Element(startTag);
+
+ //}
+ //catch (e) {
+ //throw new Exception("Cannot parse " + startTag + ": " + strVal);
+ //}
+
+ return parseInt(strVal);
+};
+
+
+BinaryXMLDecoder.prototype.readUTF8Element =function(
+ //String
+ startTag,
+ //TreeMap<String, String>
+ attributes) {
+ //throws ContentDecodingException
+
+ this.readStartElement(startTag, attributes); // can't use getElementText, can't get attributes
+ //String
+ strElementText = this.readUString();
+ return strElementText;
+};
diff --git a/js/encoding/BinaryXMLEncoder.js b/js/encoding/BinaryXMLEncoder.js
index a633aa8..16759b1 100644
--- a/js/encoding/BinaryXMLEncoder.js
+++ b/js/encoding/BinaryXMLEncoder.js
@@ -51,7 +51,7 @@
};
BinaryXMLEncoder.prototype.writeUString = function(/*String*/ utf8Content){
- this.encodeUString(this.ostream, utf8Content);
+ this.encodeUString(this.ostream, utf8Content, XML_UDATA);
};
BinaryXMLEncoder.prototype.writeBlob = function(/*byte []*/ binaryContent
@@ -149,22 +149,35 @@
Content,
//TreeMap<String, String>
attributes) {
+
this.writeStartElement(tag, attributes);
// Will omit if 0-length
if(typeof Content === 'number') {
- if(LOG>4) console.log('GOING TO WRITE THE NUMBER ' +Content );
- this.writeBlob(Content.toString());
+ if(LOG>4) console.log('GOING TO WRITE THE NUMBER .charCodeAt(0) ' +Content.toString().charCodeAt(0) );
+ if(LOG>4) console.log('GOING TO WRITE THE NUMBER ' +Content.toString() );
+ if(LOG>4) console.log('type of number is ' +typeof Content.toString() );
+
+
+
+ this.writeUString(Content.toString());
//whatever
}
+ else if(typeof Content === 'string'){
+ if(LOG>4) console.log('GOING TO WRITE THE STRING ' +Content );
+ if(LOG>4) console.log('type of STRING is ' +typeof Content );
+
+ this.writeUString(Content);
+ }
+
else{
//else if(typeof Content === 'string'){
//console.log('went here');
//this.writeBlob(Content);
//}
-
+ if(LOG>4) console.log('GOING TO WRITE A BLOB ' +Content );
//else if(typeof Content === 'object'){
this.writeBlob(Content);
//}
@@ -189,7 +202,9 @@
//byte []
buf) {
- console.log('Encoding type '+ type+ ' and value '+ val);
+ if(LOG>4)console.log('Encoding type '+ type+ ' and value '+ val);
+
+ if(LOG>4) console.log('OFFSET IS ' + this.offset );
if ((type > XML_UDATA) || (type < 0) || (val < 0)) {
throw new Exception("Tag and value must be positive, and tag valid.");
@@ -248,12 +263,22 @@
//byte [] data utils
/*custom*/
//byte[]
- strBytes = new Array(ustring.Length);
- var i = 0;
- for( ;i<ustring.lengh;i++) //in InStr.ToCharArray())
+
+ if(LOG>3) console.log("The string to write is ");
+
+ if(LOG>3) console.log(ustring);
+
+ //COPY THE STRING TO AVOID PROBLEMS
+ strBytes = new Array(ustring.length);
+
+ var i = 0;
+
+ for( ; i<ustring.length; i++) //in InStr.ToCharArray())
{
- strBytes[i] = ustring[i];
+ if(LOG>3)console.log("ustring[" + i + '] = ' + ustring[i]);
+ strBytes[i] = ustring.charCodeAt(i);
}
+
//strBytes = DataUtils.getBytesFromUTF8String(ustring);
this.encodeTypeAndVal(type,
@@ -261,7 +286,10 @@
(strBytes.length-1) :
strBytes.length), ostream);
-
+ if(LOG>3) console.log("THE string to write is ");
+
+ if(LOG>3) console.log(strBytes);
+
this.writeString(strBytes,this.offset);
this.offset+= strBytes.length;
@@ -286,12 +314,21 @@
return;
}
+ if(LOG>4) console.log('LENGTH OF XML_BLOB IS '+length);
+
+ blobCopy = new Array(blob.Length);
+ var i = 0;
+ for( ;i<blob.length;i++) //in InStr.ToCharArray())
+ {
+ blobCopy[i] = blob[i];
+ }
+
this.encodeTypeAndVal(XML_BLOB, length, ostream,offset);
if (null != blob) {
- this.writeString(blob,this.offset);
+ this.writeBlobArray(blobCopy,this.offset);
this.offset += length;
}
};
@@ -324,7 +361,29 @@
tag,
//CCNTime
dateTime) {
- this.writeElement(tag, dateTime.toBinaryTime());
+
+ if(LOG>4)console.log('ENCODING DATE with LONG VALUE');
+ if(LOG>4)console.log(dateTime.msec);
+
+ //var binarydate = DataUtils.unsignedLongToByteArray( Math.round((dateTime.msec/1000) * 4096) );
+
+
+ //parse to hex
+ var binarydate = Math.round((dateTime.msec/1000) * 4096).toString(16) ;
+
+ //HACK
+ var binarydate = DataUtils.toNumbers( '0'.concat(binarydate,'0')) ;
+
+
+ if(LOG>4)console.log('ENCODING DATE with BINARY VALUE');
+ if(LOG>4)console.log(binarydate);
+
+ if(LOG>4)console.log('ENCODING DATE with BINARY VALUE(HEX)');
+ if(LOG>4)console.log(DataUtils.toHex(binarydate));
+
+
+ this.writeElement(tag, binarydate);
+
};
BinaryXMLEncoder.prototype.writeString = function(
@@ -336,16 +395,27 @@
if(typeof input === 'string'){
//console.log('went here');
if(LOG>4) console.log('GOING TO WRITE A STRING');
-
+ if(LOG>4) console.log(input);
+
for (var i = 0; i < input.length; i++) {
+ if(LOG>4) console.log('input.charCodeAt(i)=' + input.charCodeAt(i));
this.ostream[this.offset+i] = (input.charCodeAt(i));
}
}
+ else{
+
+ if(LOG>4) console.log('GOING TO WRITE A STRING IN BINARY FORM');
+ if(LOG>4) console.log(input);
+
+ this.writeBlobArray(input);
+
+ }
+ /*
else if(typeof input === 'object'){
- this.writeBlobArray(input);
+
}
-
+ */
};
BinaryXMLEncoder.prototype.writeBlobArray = function(
diff --git a/js/encoding/DataUtils.js b/js/encoding/DataUtils.js
index 5386698..1f998af 100644
--- a/js/encoding/DataUtils.js
+++ b/js/encoding/DataUtils.js
@@ -15,12 +15,16 @@
*
*/
- var keyStr = "ABCDEFGHIJKLMNOP" +
+DataUtils.keyStr = "ABCDEFGHIJKLMNOP" +
"QRSTUVWXYZabcdef" +
"ghijklmnopqrstuv" +
"wxyz0123456789+/" +
"=";
+
+/**
+ * Raw String to Base 64
+ */
DataUtils.stringtoBase64=function stringtoBase64(input) {
input = escape(input);
var output = "";
@@ -45,10 +49,10 @@
}
output = output +
- keyStr.charAt(enc1) +
- keyStr.charAt(enc2) +
- keyStr.charAt(enc3) +
- keyStr.charAt(enc4);
+ DataUtils.keyStr.charAt(enc1) +
+ DataUtils.keyStr.charAt(enc2) +
+ DataUtils.keyStr.charAt(enc3) +
+ DataUtils.keyStr.charAt(enc4);
chr1 = chr2 = chr3 = "";
enc1 = enc2 = enc3 = enc4 = "";
} while (i < input.length);
@@ -56,6 +60,9 @@
return output;
}
+/**
+ * Base 64 to Raw String
+ */
DataUtils.base64toString = function base64toString(input) {
var output = "";
var chr1, chr2, chr3 = "";
@@ -69,13 +76,14 @@
"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" +
"Expect errors in decoding.");
}
+
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
do {
- enc1 = keyStr.indexOf(input.charAt(i++));
- enc2 = keyStr.indexOf(input.charAt(i++));
- enc3 = keyStr.indexOf(input.charAt(i++));
- enc4 = keyStr.indexOf(input.charAt(i++));
+ enc1 = DataUtils.keyStr.indexOf(input.charAt(i++));
+ enc2 = DataUtils.keyStr.indexOf(input.charAt(i++));
+ enc3 = DataUtils.keyStr.indexOf(input.charAt(i++));
+ enc4 = DataUtils.keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
@@ -99,39 +107,94 @@
};
//byte []
-DataUtils.prototype.unsignedLongToByteArray= function( value) {
+
+/**
+ * NOT WORKING!!!!!
+ *
+ * Unsiged Long Number to Byte Array
+ */
+
+ /*
+DataUtils.unsignedLongToByteArray= function( value) {
+
+ if(LOG>4)console.log('INPUT IS '+value);
+
if( 0 == value )
return [0];
if( 0 <= value && value <= 0x00FF ) {
//byte []
- bb = new Array[1];
+ var bb = new Array(1);
bb[0] = (value & 0x00FF);
return bb;
}
-
+ if(LOG>4) console.log('type of value is '+typeof value);
+ if(LOG>4) console.log('value is '+value);
//byte []
- out = null;
+ var out = null;
//int
var offset = -1;
for(var i = 7; i >=0; --i) {
//byte
- b = ((value >> (i * 8)) & 0xFF);
+ console.log(i);
+ console.log('value is '+value);
+ console.log('(value >> (i * 8)) '+ (value >> (i * 8)) );
+ console.log(' ((value >> (i * 8)) & 0xFF) '+ ((value >> (i * 8)) & 0xFF) );
+
+ var b = ((value >> (i * 8)) & 0xFF) ;
+
+ if(LOG>4) console.log('b is '+b);
+
if( out == null && b != 0 ) {
- out = new byte[i+1];
+ //out = new byte[i+1];
+ out = new Array(i+1);
offset = i;
}
+
if( out != null )
out[ offset - i ] = b;
}
+ if(LOG>4)console.log('OUTPUT IS ');
+ if(LOG>4)console.log(out);
return out;
}
+*/
+
+/**
+ * NOT WORKING!!!!!
+ *
+ * Unsiged Long Number to Byte Array
+ *//*
+DataUtils.byteArrayToUnsignedLong = function(//final byte []
+ src) {
+ if(LOG>4) console.log('INPUT IS ');
+ if(LOG>4) console.log(src);
+
+ var value = 0;
+ for(var i = 0; i < src.length; i++) {
+ value = value << 8;
+ // Java will assume the byte is signed, so extend it and trim it.
+
+
+ var b = ((src[i]) & 0xFF );
+ value |= b;
+ }
+
+ if(LOG>4) console.log('OUTPUT IS ');
+
+ if(LOG>4) console.log(value);
+
+ return value;
+ }*/
-var utf8 = {}
-
-utf8.toByteArray = function(str) {
+/**
+ * Hex String to Byte Array
+ */
+ //THIS IS NOT WORKING
+/*
+DataUtils.HexStringtoByteArray = function(str) {
var byteArray = [];
for (var i = 0; i < str.length; i++)
if (str.charCodeAt(i) <= 0x7F)
@@ -143,8 +206,12 @@
}
return byteArray;
};
-
-utf8.parse = function(byteArray) {
+*/
+
+/**
+ * Byte Array to Hex String
+ */
+DataUtils.byteArrayToHexString = function(byteArray) {
var str = '';
for (var i = 0; i < byteArray.length; i++)
str += byteArray[i] <= 0x7F?
@@ -155,17 +222,24 @@
};
+/**
+ * Byte array to Hex String
+ */
//http://ejohn.org/blog/numbers-hex-and-colors/
-function toHex(arguments){
+DataUtils.toHex = function(arguments){
+ if(LOG>4) console.log('ABOUT TO CONVERT '+ arguments);
//console.log(arguments);
var ret = "";
for ( var i = 0; i < arguments.length; i++ )
ret += (arguments[i] < 16 ? "0" : "") + arguments[i].toString(16);
- return ret.toUpperCase();
+ return ret; //.toUpperCase();
}
+/**
+ * Byte array to raw string
+ */
//DOES NOT SEEM TO WORK
-function toString(arguments){
+DataUtils.toString = function(arguments){
//console.log(arguments);
var ret = "";
for ( var i = 0; i < arguments.length; i++ )
@@ -173,7 +247,10 @@
return ret;
}
-function toNumbers( str ){
+/**
+ * Hex String to byte array
+ */
+DataUtils.toNumbers=function( str ){
if(typeof str =='string'){
var ret = [];
str.replace(/(..)/g, function(str){
@@ -183,9 +260,115 @@
}
}
-function toNumbersFromString( str ){
+/**
+ * Raw String to Byte Array
+ */
+DataUtils.toNumbersFromString = function( str ){
var bytes = new Array(str.length);
for(var i=0;i<str.length;i++)
bytes[i] = str.charCodeAt(i);
return bytes;
-}
\ No newline at end of file
+}
+
+DataUtils.encodeUtf8 = function (string) {
+ string = string.replace(/\r\n/g,"\n");
+ var utftext = "";
+
+ for (var n = 0; n < string.length; n++) {
+
+ var c = string.charCodeAt(n);
+
+ if (c < 128) {
+ utftext += String.fromCharCode(c);
+ }
+ else if((c > 127) && (c < 2048)) {
+ utftext += String.fromCharCode((c >> 6) | 192);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+ else {
+ utftext += String.fromCharCode((c >> 12) | 224);
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
+ utftext += String.fromCharCode((c & 63) | 128);
+ }
+
+ }
+
+ return utftext;
+ };
+
+ // public method for url decoding
+DataUtils.decodeUtf8 = function (utftext) {
+ var string = "";
+ var i = 0;
+ var c = c1 = c2 = 0;
+
+ while ( i < utftext.length ) {
+
+ c = utftext.charCodeAt(i);
+
+ if (c < 128) {
+ string += String.fromCharCode(c);
+ i++;
+ }
+ else if((c > 191) && (c < 224)) {
+ c2 = utftext.charCodeAt(i+1);
+ string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
+ i += 2;
+ }
+ else {
+ c2 = utftext.charCodeAt(i+1);
+ c3 = utftext.charCodeAt(i+2);
+ string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
+ i += 3;
+ }
+
+ }
+
+ return string;
+ };
+
+ test = function(){
+ console.log(DataUtils.decodeUtf8("HELLO.~"));
+ return DataUtils.decodeUtf8("HELLO.~");
+ }
+
+//NOT WORKING
+/*
+DataUtils.getUTF8StringFromBytes = function(bytes) {
+
+ bytes = toString(bytes);
+
+ var ix = 0;
+
+ if( bytes.slice(0,3) == "\xEF\xBB\xBF") {
+ ix = 3;
+ }
+
+ var string = "";
+ for( ; ix < bytes.length; ix++ ) {
+ var byte1 = bytes[ix].charCodeAt(0);
+ if( byte1 < 0x80 ) {
+ string += String.fromCharCode(byte1);
+ } else if( byte1 >= 0xC2 && byte1 < 0xE0 ) {
+ var byte2 = bytes[++ix].charCodeAt(0);
+ string += String.fromCharCode(((byte1&0x1F)<<6) + (byte2&0x3F));
+ } else if( byte1 >= 0xE0 && byte1 < 0xF0 ) {
+ var byte2 = bytes[++ix].charCodeAt(0);
+ var byte3 = bytes[++ix].charCodeAt(0);
+ string += String.fromCharCode(((byte1&0xFF)<<12) + ((byte2&0x3F)<<6) + (byte3&0x3F));
+ } else if( byte1 >= 0xF0 && byte1 < 0xF5) {
+ var byte2 = bytes[++ix].charCodeAt(0);
+ var byte3 = bytes[++ix].charCodeAt(0);
+ var byte4 = bytes[++ix].charCodeAt(0);
+ var codepoint = ((byte1&0x07)<<18) + ((byte2&0x3F)<<12)+ ((byte3&0x3F)<<6) + (byte4&0x3F);
+ codepoint -= 0x10000;
+ string += String.fromCharCode(
+ (codepoint>>10) + 0xD800,
+ (codepoint&0x3FF) + 0xDC00
+ );
+ }
+ }
+
+ return string;
+}*/
+
diff --git a/js/encoding/EncodingUtils.js b/js/encoding/EncodingUtils.js
new file mode 100644
index 0000000..503cd66
--- /dev/null
+++ b/js/encoding/EncodingUtils.js
@@ -0,0 +1,120 @@
+
+
+
+
+function encodeToHexInterest(int){
+
+ var enc = new BinaryXMLEncoder();
+
+ int.encode(enc);
+
+ var hex = DataUtils.toHex(enc.getReducedOstream());
+
+ return hex;
+
+
+}
+
+
+function encodeToHexContentObject(co){
+ var enc = new BinaryXMLEncoder();
+
+ co.encode(enc);
+
+ var hex = DataUtils.toHex(enc.getReducedOstream());
+
+ return hex;
+
+
+}
+
+function encodeToBinaryContentObject(co){
+ var enc = new BinaryXMLEncoder();
+
+ co.encode(enc);
+
+ var hex = enc.getReducedOstream();
+
+ return hex;
+
+
+}
+
+function encodeForwardingEntry(co){
+ var enc = new BinaryXMLEncoder();
+
+ co.encode(enc);
+
+ var bytes = enc.getReducedOstream();
+
+ return bytes;
+
+
+}
+
+
+
+function decodeHexFaceInstance(result){
+
+ var numbers = DataUtils.toNumbers(result);
+
+
+ decoder = new BinaryXMLDecoder(numbers);
+
+ if(LOG>3)console.log('DECODING HEX FACE INSTANCE \n'+numbers);
+
+ i = new FaceInstance();
+
+ i.decode(decoder);
+
+ return i;
+
+}
+
+function decodeHexInterest(result){
+ var numbers = DataUtils.toNumbers(result);
+
+
+ decoder = new BinaryXMLDecoder(numbers);
+ if(LOG>3)console.log('DECODING HEX INTERST \n'+numbers);
+
+ i = new Interest();
+
+ i.decode(decoder);
+
+ return i;
+
+}
+
+
+
+function decodeHexContentObject(result){
+ var numbers = DataUtils.toNumbers(result);
+
+ decoder = new BinaryXMLDecoder(numbers);
+ if(LOG>3)console.log('DECODED HEX CONTENT OBJECT \n'+numbers);
+
+ co = new ContentObject();
+
+ co.decode(decoder);
+
+ return co;
+
+}
+
+
+
+function decodeHexForwardingEntry(result){
+ var numbers = DataUtils.toNumbers(result);
+
+ decoder = new BinaryXMLDecoder(numbers);
+
+ if(LOG>3)console.log('DECODED HEX FORWARDING ENTRY \n'+numbers);
+
+ co = new ForwardingEntry();
+
+ co.decode(decoder);
+
+ return co;
+
+}
\ No newline at end of file
diff --git a/js/encoding/TextXMLCodec.js b/js/encoding/TextXMLCodec.js
index 716aa6d..37cbe04 100644
--- a/js/encoding/TextXMLCodec.js
+++ b/js/encoding/TextXMLCodec.js
@@ -22,38 +22,3 @@
};
-//returns a string
-
-TextXMLCodec.protpotype.codecName = function() { return this.CODEC_NAME; } ;
-
-//returns a string
-TextXMLCodec.protottype.encodeBinaryElement = function(/*byte []*/ element) {
- if ((null == element) || (0 == element.length))
- return new String("");
- return new String(DataUtils.base64Encode(element));
- };
-
-/* returns a string */
-TextXMLCodec.prototype.encodeBinaryElement = function(/*byte []*/ element, /*int*/ offset, /*int*/ length) {
- if ((null == element) || (0 == element.length))
- return new String("");
- ByteBuffer bbuf = ByteBuffer.wrap(element, offset, length);
- return new String(DataUtils.base64Encode(bbuf.array()));
- };
-
-/*returns a byte array*/
-TextXMLCodec.prototype.decodeBinaryElement = function(/*String*/ element) {
- if ((null == element) || (0 == element.length()))
- return new byte[0];
- return DataUtils.base64Decode(element.getBytes());
- };
-
-
-/*
- Decode Data
-*/
-
-
-/*
- Encode Date
-*/
\ No newline at end of file
diff --git a/js/encoding/TextXMLDecoder.js b/js/encoding/TextXMLDecoder.js
index 6af8be3..006ce83 100644
--- a/js/encoding/TextXMLDecoder.js
+++ b/js/encoding/TextXMLDecoder.js
@@ -12,221 +12,3 @@
};
-
-exports.TextXMLDecoder = TextXMLDecoder;
-
-
-exports.prototype.initializeDecoding = function(){
- try {
- XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
- factory.setNamespaceAware(true);
- _reader = factory.newPullParser();
- _reader.setInput(_istream, null);
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- }
-};
-
-exports.prototype.readStartDocument = function(){
- try {
- int event = _reader.getEventType();
- _reader.next();
- if (event != XmlPullParser.START_DOCUMENT) {
- throw new ContentDecodingException("Expected start document, got: " + XmlPullParser.TYPES[event]);
- }
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- }
-};
-
-public void readEndDocument() throws ContentDecodingException {
- int event;
- try {
- event = _reader.getEventType();
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- }
- if (event != XmlPullParser.END_DOCUMENT) {
- throw new ContentDecodingException("Expected end document, got: " + XmlPullParser.TYPES[event]);
- }
-};
-
-exports.prototype.readStartElement = function(/*String*/ startTag,
- TreeMap<String, String> attributes) throws ContentDecodingException {
-
- int event = readToNextTag(XmlPullParser.START_TAG);
- if (event != XmlPullParser.START_TAG) {
- throw new ContentDecodingException("Expected start element, got: " + XmlPullParser.TYPES[event]);
- }
- // Use getLocalPart to strip namespaces.
- // Assumes we are working with a global default namespace of CCN.
- if (!startTag.equals(_reader.getName())) {
- // Coming back with namespace decoration doesn't match
- throw new ContentDecodingException("Expected start element: " + startTag + " got: " + _reader.getName());
- }
- if (null != attributes) {
- // we might be expecting attributes
- for (int i=0; i < _reader.getAttributeCount(); ++i) {
- // may need fancier namespace handling.
- attributes.put(_reader.getAttributeName(i), _reader.getAttributeValue(i));
- }
- }
- try {
- _reader.next();
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage());
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage());
- }
-}
-
- public void readStartElement(long startTagLong,
- TreeMap<String, String> attributes) throws ContentDecodingException {
-
- String startTag = tagToString(startTagLong);
-
- int event = readToNextTag(XmlPullParser.START_TAG);
- if (event != XmlPullParser.START_TAG) {
- throw new ContentDecodingException("Expected start element, got: " + XmlPullParser.TYPES[event]);
- }
- // Use getLocalPart to strip namespaces.
- // Assumes we are working with a global default namespace of CCN.
- if (!startTag.equals(_reader.getName())) {
- // Coming back with namespace decoration doesn't match
- throw new ContentDecodingException("Expected start element: " + startTag + " got: " + _reader.getName());
- }
- if (null != attributes) {
- // we might be expecting attributes
- for (int i=0; i < _reader.getAttributeCount(); ++i) {
- // may need fancier namespace handling.
- attributes.put(_reader.getAttributeName(i), _reader.getAttributeValue(i));
- }
- }
- try {
- _reader.next();
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage());
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage());
- }
- }
- public String peekStartElementAsString() throws ContentDecodingException {
- int event = readToNextTag(XmlPullParser.START_TAG);
- if (event != XmlPullParser.START_TAG) {
- return null;
- }
- return _reader.getName();
- }
-
- public Long peekStartElementAsLong() throws ContentDecodingException {
- String strTag = peekStartElementAsString();
- if (null == strTag) {
- return null; // e.g. hit an end tag...
- }
- return stringToTag(strTag);
- }
-
- /**
- * Helper method to decode text (UTF-8) and binary elements. Consumes the end element,
- * behavior which other decoders are forced to match.
- * @return the read data, as a String
- * @throws ContentDecodingException if there is a problem decoding the data
- */
- public String readUString() throws ContentDecodingException {
- StringBuffer buf = new StringBuffer();
- try {
- int event = _reader.getEventType();;
- // Handles empty text element.
- while (event == XmlPullParser.TEXT) {
- buf.append(_reader.getText());
- event = _reader.next();
- }
- if (event == XmlPullParser.START_TAG) {
- throw new ContentDecodingException("readElementText expects start element to have been previously consumed, got: " + XmlPullParser.TYPES[event]);
- } else if (event != XmlPullParser.END_TAG) {
- throw new ContentDecodingException("Expected end of text element, got: " + XmlPullParser.TYPES[event]);
- }
- readEndElement();
- return buf.toString();
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- }
- }
-
- public void readEndElement() throws ContentDecodingException {
- int event = readToNextTag(XmlPullParser.END_TAG);
- if (event != XmlPullParser.END_TAG) {
- throw new ContentDecodingException("Expected end element, got: " + XmlPullParser.TYPES[event]);
- }
- try {
- _reader.next();
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage());
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage());
- }
- }
-
- /**
- * Read a BLOB. Consumes the end element, so force other versions
- * to match.
- */
- public byte [] readBlob() throws ContentDecodingException {
- try {
- String strElementText = readUString();
- // readEndElement(); // readElementText consumes end element
- return TextXMLCodec.decodeBinaryElement(strElementText);
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage(),e);
- }
- }
-
- public CCNTime readDateTime(String startTag) throws ContentDecodingException {
- String strTimestamp = readUTF8Element(startTag);
- CCNTime timestamp;
- try {
- timestamp = TextXMLCodec.parseDateTime(strTimestamp);
- } catch (ParseException e) {
- timestamp = null;
- }
- if (null == timestamp) {
- throw new ContentDecodingException("Cannot parse timestamp: " + strTimestamp);
- }
- return timestamp;
- }
-
- public CCNTime readDateTime(long startTag) throws ContentDecodingException {
- String strTimestamp = readUTF8Element(startTag);
- CCNTime timestamp;
- try {
- timestamp = TextXMLCodec.parseDateTime(strTimestamp);
- } catch (ParseException e) {
- timestamp = null;
- }
- if (null == timestamp) {
- throw new ContentDecodingException("Cannot parse timestamp: " + strTimestamp);
- }
- return timestamp;
- }
-
- private int readToNextTag(int type) throws ContentDecodingException {
- int event;
- try {
- event = _reader.getEventType();
- if (event == type)
- return event;
- if (event == XmlPullParser.TEXT || event == XmlPullParser.COMMENT)
- event = _reader.next();
- } catch (IOException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- } catch (XmlPullParserException e) {
- throw new ContentDecodingException(e.getMessage(), e);
- }
- return event;
- }
-
-};
diff --git a/js/encoding/TextXMLEncoder.js b/js/encoding/TextXMLEncoder.js
index 495984b..2c8a828 100644
--- a/js/encoding/TextXMLEncoder.js
+++ b/js/encoding/TextXMLEncoder.js
@@ -17,93 +17,4 @@
this.ostream = new String();
};
-exports.TextXMLEncoder = TextXMLEncoder;
-TextXMLEncoder.prototype.beginEncoding = function(/*OutputStream*/ ostream){
- if (null == ostream)
- throw new IllegalArgumentException("TextXMLEncoder: output stream cannot be null!");
-
-
- /*Start by encoing the begining*/
- //this.IStream = ostream;
- this.ostream.write('<?xml version="1.0" encoding="UTF-8"?>');
-};
-
-TextXMLEncoder.prototype.endEncoding =function() {
- this.IStream.end();
-}
-
-
-TextXMLEncoder.prorotype.writeStartElement(/*String*/ tag, /*TreeMap<String, String>*/ attributes) {
-
-
- this.ostream.write('<'+tab);
-
- if (null != attributes) {
-
- for(var i=0; i<attributes.length;i++){
- this.ostream.write(' '+attributes[i].key +'='+attributes[i].value);
- }
-
- // keySet of a TreeMap is ordered
- }
- this.ostream.write('>');
-};
-
-TextXMLEncoder.prototype.writeUString = function(/*String*/ utf8Content) {
-
- this.ostream.write(utf8Content);
-
-};
-
-
-TextXMLEncoder.prototype.writeBlob = function(/*byte []*/ binaryContent, /*int*/ offset, /*int*/ length) {
-
- this.ostream.write(TextXMLCodec.encodeBinaryElement(binaryContent, offset, length));
-
-};
-
-TextXMLEncoder.prototype.writeElement = function(/*String*/ tag, /*byte[]*/ binaryContent,
- /*TreeMap<String, String>*/ attributes) {
-
- /*if (null == attributes) {
-
- attributes = new TreeMap<String,String>();
- }*/
- if (!attributes.containsKey(TextXMLCodec.BINARY_ATTRIBUTE)) {
- attributes.put(TextXMLCodec.BINARY_ATTRIBUTE, TextXMLCodec.BINARY_ATTRIBUTE_VALUE);
- }
- super.writeElement(tag, binaryContent, attributes);
-}
-
-
-TextXMLEncoder.prototype.writeEndElement(tag) {
-
- this.ostream.write('<'+tab+'>');
-
- };
-
-
-//returns number long
-stringToTag = function(/*String*/ tagName) {
-
- if (null == tagName) {
- return null;
- }
- Long tagVal = null;
- if (null != _dictionaryStack) {
- for (/*XMLDictionary*/ dictionary in _dictionaryStack) {
- tagVal = dictionary.stringToTag(tagName);
- if (null != tagVal) {
- return tagVal;
- }
- }
- }
-
-
- if (XMLDictionaryStack.isUnknownTag(tagName)) {
- return XMLDictionaryStack.decodeUnknownTag(tagName);
- }
- return null;
-};
-