Skip to content
Browse files

Added the module and a test.

  • Loading branch information...
1 parent 10b0ca3 commit 7a788e0a9be7cd38e57ad161c5545d4633fcc72b @Mithgol committed May 18, 2012
Showing with 216 additions and 10 deletions.
  1. +26 −10 .gitignore
  2. +167 −0 index.js
  3. +11 −0 package.json
  4. BIN test/BLOG-MTW.jhr
  5. +12 −0 test/test.js
View
36 .gitignore
@@ -1,15 +1,31 @@
-lib-cov
-*.seed
-*.log
-*.csv
-*.dat
-*.out
-*.pid
+# Packages
+*.7z
+*.dmg
*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases
+*.log
+*.sql
+*.sqlite
-pids
-logs
-results
+# Windows image file caches
+Thumbs.db
+# Folder config file
+Desktop.ini
+
+# Other OS generated files
+.DS_Store*
+ehthumbs.db
+Icon?
+
+# Node.js modules
node_modules
+
+# NPM error logs
npm-debug.log
View
167 index.js
@@ -0,0 +1,167 @@
+var fs = require('fs');
+var jParser = require('jParser');
+var util = require('util');
+
+var ulong = 'uint32';
+var ushort = 'uint16';
+
+var NOP = function(){};
+var lastGood = {};
+
+var JAM = function(echotag){
+ if (!(this instanceof JAM)) return new JAM(echotag);
+
+ this.echotag = echotag;
+
+ // Buffers:
+ this.JHR = null;
+ /*
+ this.JDT = null;
+ this.JDX = null;
+ this.JLR = null;
+ */
+}
+
+JAM.prototype.readJHR = function(callback){ // (err)
+ if (this.JHR !== null) callback(null);
+
+ fs.readFile(this.echotag+'.JHR', function (err, data) {
+ if (err) callback(err);
+
+ this.JHR = data;
+ callback(null);
+ });
+}
+
+JAM.prototype.FixedHeaderInfoStruct = function(callback){ // err, struct
+ this.readJHR(function(err){
+ if (err) callback(err);
+
+ var thisJAM = this;
+
+ var parser = new jParser(this.JHR, {
+ 'reserved1000uchar': function(){
+ this.skip(1000);
+ return true;
+ },
+ 'JAM0' : ['string', 4],
+ 'FixedHeaderInfoStruct': {
+ 'Signature': 'JAM0',
+ 'datecreated': ulong,
+ 'modcounter': ulong,
+ 'activemsgs': ulong,
+ 'passwordcrc': ulong,
+ 'basemsgnum': ulong,
+ 'RESERVED': 'reserved1000uchar',
+ },
+ 'SubField': {
+ 'LoID': ushort,
+ 'HiID': ushort,
+ 'datlen': ulong,
+ 'Buffer': ['string', function(){ return this.current.datlen }]
+ /*
+ 'type': function(){
+ switch( this.current.LoID ){
+ case 0: return 'OADDRESS'; break;
+ case 1: return 'DADDRESS'; break;
+ case 2: return 'SENDERNAME'; break;
+ case 3: return 'RECEIVERNAME'; break;
+ case 4: return 'MSGID'; break;
+ case 5: return 'REPLYID'; break;
+ case 6: return 'SUBJECT'; break;
+ case 7: return 'PID'; break;
+ case 8: return 'TRACE'; break;
+ case 9: return 'ENCLOSEDFILE'; break;
+ case 10: return 'ENCLOSEDFILEWALIAS'; break;
+ case 11: return 'ENCLOSEDFREQ'; break;
+ case 12: return 'ENCLOSEDFILEWCARD'; break;
+ case 13: return 'ENCLOSEDINDIRECTFILE'; break;
+ case 1000: return 'EMBINDAT'; break;
+ case 2000: return 'FTSKLUDGE'; break;
+ case 2001: return 'SEENBY2D'; break;
+ case 2002: return 'PATH2D'; break;
+ case 2003: return 'FLAGS'; break;
+ case 2004: return 'TZUTCINFO'; break;
+ default: return 'UNKNOWN'; break;
+ }
+ }
+ */
+ },
+ 'MessageHeader': {
+ 'Signature': 'JAM0',
+ 'Revision': ushort,
+ 'ReservedWord': ushort,
+ 'SubfieldLen': ulong,
+ 'TimesRead': ulong,
+ 'MSGIDcrc': ulong,
+ 'REPLYcrc': ulong,
+ 'ReplyTo': ulong,
+ 'Reply1st': ulong,
+ 'Replynext': ulong,
+ 'DateWritten': ulong,
+ 'DateReceived': ulong,
+ 'DateProcessed': ulong,
+ 'MessageNumber': ulong,
+ 'Attribute': ulong,
+ 'Attribute2': ulong,
+ 'Offset': ulong,
+ 'TxtLen': ulong,
+ 'PasswordCRC': ulong,
+ 'Cost': ulong,
+ 'Subfields': ['string', function(){ return this.current.SubfieldLen; } ],
+ /*
+ 'Subfields': function(){
+ var final = this.tell() + this.current.SubfieldLen;
+ var sfArray = [];
+ while (this.tell() < final) {
+ sfArray.push( this.parse('SubField') );
+ }
+ return sfArray;
+ },
+ */
+ 'AfterSubfields': function(){
+ var initial = this.tell();
+ var bytesLeft = thisJAM.JHR.length - initial - 4;
+ var seekJump = 0;
+ var sigFound = false;
+ var raw = this;
+ if (bytesLeft <= 0) return 0;
+ do {
+ this.seek(initial + seekJump, function(){
+ var moveSIG = raw.parse('JAM0');
+ if (moveSIG === 'JAM\0') {
+ sigFound = true;
+ /*
+ if (seekJump > 0){
+ console.log(
+ 'initial = ' + initial +
+ ', seekJump = ' + seekJump +
+ ', moveSIG = ' + moveSIG
+ );
+ }
+ */
+ }
+ });
+ seekJump++;
+ } while (!sigFound && (seekJump < bytesLeft) );
+ this.skip(seekJump-1);
+ return seekJump-1;
+ }
+ },
+ 'JHR': {
+ 'FixedHeader': 'FixedHeaderInfoStruct',
+ 'MessageHeaders': function(){
+ var mhArray = [];
+ while (this.tell() < thisJAM.JHR.length - 69) {
+ mhArray.push( this.parse('MessageHeader') );
+ }
+ return mhArray;
+ }
+ }
+ });
+
+ callback(null, parser.parse('JHR'));
+ });
+}
+
+module.exports = JAM;
View
11 package.json
@@ -0,0 +1,11 @@
+{
+"name": "FidoJAM",
+"main": "index.js",
+"version": "0.0.1",
+"description": "Fidonet JAM message base parser",
+"keywords": ["Fidonet", "Fido", "JAM"],
+"author": { "name": "Mithgol the Webmaster" },
+"dependencies": {
+ "jParser": ">=1.0.1"
+}
+}
View
BIN test/BLOG-MTW.jhr
Binary file not shown.
View
12 test/test.js
@@ -0,0 +1,12 @@
+var JAM = require('./');
+var util = require('util');
+
+console.log( new Date().toLocaleString() );
+
+var blog = JAM('blog-MtW');
+
+blog.FixedHeaderInfoStruct(function(err,data){
+ if (err) throw err;
+ //console.log( util.inspect(data, false, Infinity, false) );
+ console.log( new Date().toLocaleString() );
+});

0 comments on commit 7a788e0

Please sign in to comment.
Something went wrong with that request. Please try again.