Permalink
Browse files

constant var names should be uppercase

  • Loading branch information...
1 parent 9e51a18 commit 78b18fb968f7817048be9bbf349f85e453afa0db @mscdex committed Mar 11, 2013
Showing with 31 additions and 30 deletions.
  1. +31 −30 lib/nntp.js
View
@@ -9,16 +9,16 @@ var tls = require('tls'),
util = require('util'),
SBMH = require('streamsearch'),
inherits = util.inherits,
- reCRLF = /\r\n/g,
- reListActive = /^(.+)\s+(\d+)\s+(\d+)\s+(.+)$/,
- reGroupDesc = /^([^\s]+)\s+(.+)$/,
- reStat = /^(\d+)\s+(.+)$/,
- reGroup = /^(\d+)\s+(\d+)\s+(\d+)\s/,
- reHdr = /^([^:]+):[ \t]?(.+)?$/,
- respsML = [100, 101, 215, 220, 221, 222, 224, 225, 230, 231],
- respsHaveArgs = [111, 211, 220, 221, 222, 223, 401],
- bytesCRLF = new Buffer([13, 10]),
- bytesMLTerm = new Buffer([13, 10, 46, 13, 10]),
+ RE_CRLF = /\r\n/g,
+ RE_LIST_ACTIVE = /^(.+)\s+(\d+)\s+(\d+)\s+(.+)$/,
+ RE_GROUP_DESC = /^([^\s]+)\s+(.+)$/,
+ RE_STAT = /^(\d+)\s+(.+)$/,
+ RE_GROUP = /^(\d+)\s+(\d+)\s+(\d+)\s/,
+ RE_HDR = /^([^:]+):[ \t]?(.+)?$/,
+ RES_CODE_ML = [100, 101, 215, 220, 221, 222, 224, 225, 230, 231],
+ RES_CODE_ARGS = [111, 211, 220, 221, 222, 223, 401],
+ B_CRLF = new Buffer([13, 10]),
+ B_ML_TERM = new Buffer([13, 10, 46, 13, 10]),
TYPE = {
CONNECTION: 0,
GROUP: 1,
@@ -62,9 +62,9 @@ var tls = require('tls'),
};
function NNTP() {
- this._sbmhML = new SBMH(bytesMLTerm);
+ this._sbmhML = new SBMH(B_ML_TERM);
this._sbmhML.maxMatches = 1;
- this._sbmhCRLF = new SBMH(bytesCRLF);
+ this._sbmhCRLF = new SBMH(B_CRLF);
this._sbmhCRLF.maxMatches = 1;
this._socket = undefined;
@@ -242,7 +242,7 @@ NNTP.prototype.connect = function(options) {
if (code === 211)
isML = (self._curReq.cmd !== 'GROUP');
else
- isML = (respsML.indexOf(code) > -1);
+ isML = (RES_CODE_ML.indexOf(code) > -1);
sbmh = (isML ? self._sbmhML : self._sbmhCRLF);
sbmh.reset();
bufSize = 0;
@@ -321,7 +321,7 @@ NNTP.prototype.stat = function(id, cb) {
this._send('STAT', id, function(err, code, r, type) {
if (err)
return cb(err);
- var m = reStat.exec(self._buffer.trim());
+ var m = RE_STAT.exec(self._buffer.trim());
// article number, message id
cb(undefined, parseInt(m[1], 10), m[2]);
});
@@ -332,8 +332,9 @@ NNTP.prototype.group = function(group, cb) {
this._send('GROUP', group, function(err, code, r, type) {
if (err)
return cb(err);
+
// est. article count, low mark, high mark
- var m = reGroup.exec(self._buffer.trim());
+ var m = RE_GROUP.exec(self._buffer.trim());
cb(undefined, parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10));
});
};
@@ -343,7 +344,7 @@ NNTP.prototype.next = function(cb) {
this._send('NEXT', undefined, function(err, code, r, type) {
if (err)
return cb(err);
- var m = reStat.exec(self._buffer.trim());
+ var m = RE_STAT.exec(self._buffer.trim());
// article number, message id
cb(undefined, parseInt(m[1], 10), m[2]);
});
@@ -354,7 +355,7 @@ NNTP.prototype.prev = function(cb) {
this._send('LAST', undefined, function(err, code, r, type) {
if (err)
return cb(err);
- var m = reStat.exec(self._buffer.trim());
+ var m = RE_STAT.exec(self._buffer.trim());
// article number, message id
cb(undefined, parseInt(m[1], 10), m[2]);
});
@@ -372,7 +373,7 @@ NNTP.prototype.headers = function(what, cb) {
if (err)
return cb(err);
- var list = self._buffer.split(reCRLF),
+ var list = self._buffer.split(RE_CRLF),
info = list.shift().trim(),
headers = {}, m;
@@ -385,7 +386,7 @@ NNTP.prototype.headers = function(what, cb) {
// it, so we follow the RFC and include the leading whitespace ...
headers[h][headers[h].length - 1] += list[i];
} else {
- m = reHdr.exec(list[i]);
+ m = RE_HDR.exec(list[i]);
h = m[1].toLowerCase();
if (m[2]) {
if (headers[h] === undefined)
@@ -397,7 +398,7 @@ NNTP.prototype.headers = function(what, cb) {
}
}
- m = reStat.exec(info);
+ m = RE_STAT.exec(info);
// article number, message id, headers
cb(undefined, parseInt(m[1], 10), m[2], headers);
});
@@ -439,10 +440,10 @@ NNTP.prototype.body = function(what, cb) {
if (idxCRLF > -1) {
body = self._buffer.substring(idxCRLF + 2);
- m = reStat.exec(self._buffer.substring(0, idxCRLF).trim());
+ m = RE_STAT.exec(self._buffer.substring(0, idxCRLF).trim());
} else {
// empty body
- m = reStat.exec(self._buffer.trim());
+ m = RE_STAT.exec(self._buffer.trim());
}
// article number, message id, string body
@@ -486,7 +487,7 @@ NNTP.prototype.article = function(what, cb) {
headers = {}, body, info, sheaders;
sheaders = self._buffer.substring(0, idxDCRLF);
- list = sheaders.split(reCRLF);
+ list = sheaders.split(RE_CRLF);
info = list.shift().trim();
for (var i = 0, h, len = list.length; i < len; ++i) {
if (list[i].length === 0)
@@ -499,7 +500,7 @@ NNTP.prototype.article = function(what, cb) {
else
headers[h] += m[1];
} else {
- m = reHdr.exec(list[i]);
+ m = RE_HDR.exec(list[i]);
h = m[1].toLowerCase();
if (m[2]) {
if (headers[h] === undefined)
@@ -515,7 +516,7 @@ NNTP.prototype.article = function(what, cb) {
body = self._buffer.substring(idxDCRLF + 4);
- m = reStat.exec(info);
+ m = RE_STAT.exec(info);
// article number, message id, headers, string body
cb(undefined, parseInt(m[1], 10), m[2], headers, body);
@@ -554,7 +555,7 @@ NNTP.prototype.newNews = function(search, date8, time6, cb) {
function(err, code, r, type) {
if (err)
return cb(err);
- var list = self._buffer.split(reCRLF);
+ var list = self._buffer.split(RE_CRLF);
list.shift(); // remove initial response line
cb(undefined, list);
}
@@ -573,10 +574,10 @@ NNTP.prototype.groups = function(search, cb) {
this._send('LIST', 'ACTIVE' + search, function(err, code, r, type) {
if (err)
return cb(err);
- var list = self._buffer.split(reCRLF);
+ var list = self._buffer.split(RE_CRLF);
list.shift(); // remove initial response line
for (var i = 0, m, len = list.length; i < len; ++i) {
- m = reListActive.exec(list[i]);
+ m = RE_LIST_ACTIVE.exec(list[i]);
// short name, low mark, high mark, status
list[i] = [ m[1], parseInt(m[3], 10), parseInt(m[2], 10), m[4] ];
}
@@ -605,10 +606,10 @@ NNTP.prototype.groupsDesc = function(search, cb) {
self._bufferEnc = undefined;
if (err)
return cb(err);
- var list = self._buffer.split(reCRLF);
+ var list = self._buffer.split(RE_CRLF);
list.shift(); // remove initial response line
for (var i = 0, m, len = list.length; i < len; ++i) {
- m = reGroupDesc.exec(list[i]);
+ m = RE_GROUP_DESC.exec(list[i]);
// short name, description
list[i] = [ m[1], m[2] ];
}

0 comments on commit 78b18fb

Please sign in to comment.